]> git.proxmox.com Git - mirror_frr.git/blob - lib/tc.h
Merge pull request #11908 from sigeryang/tc-state-mgmt
[mirror_frr.git] / lib / tc.h
1 /*
2 * Traffic Control (TC) main header
3 * Copyright (C) 2022 Shichu Yang
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the Free
7 * Software Foundation; either version 2 of the License, or (at your option)
8 * any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; see the file COPYING; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 #ifndef _TC_H
21 #define _TC_H
22
23 #include <zebra.h>
24 #include "stream.h"
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29
30 #define TC_STR "Traffic Control\n"
31
32 /* qdisc definitions */
33
34 /* qdisc kind (same as class kinds) */
35 enum tc_qdisc_kind {
36 TC_QDISC_UNSPEC,
37 TC_QDISC_HTB,
38 TC_QDISC_NOQUEUE,
39 };
40
41 struct tc_qdisc_htb {
42 /* currently no members */
43 };
44
45 struct tc_qdisc {
46 ifindex_t ifindex;
47
48 enum tc_qdisc_kind kind;
49 union {
50 struct tc_qdisc_htb htb;
51 } u;
52 };
53
54 /* class definitions */
55
56 /* since classes share the same kinds of qdisc, duplicates omitted */
57 struct tc_class_htb {
58 uint64_t rate;
59 uint64_t ceil;
60 };
61
62 struct tc_class {
63 ifindex_t ifindex;
64 uint32_t handle;
65
66 enum tc_qdisc_kind kind;
67 union {
68 struct tc_class_htb htb;
69 } u;
70 };
71
72 /* filter definitions */
73
74 /* filter kinds */
75 enum tc_filter_kind {
76 TC_FILTER_UNSPEC,
77 TC_FILTER_BPF,
78 TC_FILTER_FLOW,
79 TC_FILTER_FLOWER,
80 TC_FILTER_U32,
81 };
82
83 struct tc_bpf {
84 /* TODO: fill in */
85 };
86
87 struct tc_flow {
88 /* TODO: fill in */
89 };
90
91 struct tc_flower {
92 uint32_t classid;
93
94 #define TC_FLOWER_IP_PROTOCOL (1 << 0)
95 #define TC_FLOWER_SRC_IP (1 << 1)
96 #define TC_FLOWER_DST_IP (1 << 2)
97 #define TC_FLOWER_SRC_PORT (1 << 3)
98 #define TC_FLOWER_DST_PORT (1 << 4)
99 #define TC_FLOWER_DSFIELD (1 << 5)
100
101 uint32_t filter_bm;
102
103 uint8_t ip_proto;
104
105 struct prefix src_ip;
106 struct prefix dst_ip;
107
108 uint16_t src_port_min;
109 uint16_t src_port_max;
110 uint16_t dst_port_min;
111 uint16_t dst_port_max;
112
113 uint8_t dsfield;
114 uint8_t dsfield_mask;
115 };
116
117 struct tc_u32 {
118 /* TODO: fill in */
119 };
120
121 struct tc_filter {
122 ifindex_t ifindex;
123 uint32_t handle;
124
125 uint32_t priority;
126 uint16_t protocol;
127
128 enum tc_filter_kind kind;
129
130 union {
131 struct tc_bpf bpf;
132 struct tc_flow flow;
133 struct tc_flower flower;
134 struct tc_u32 u32;
135 } u;
136 };
137
138 extern int tc_getrate(const char *str, uint64_t *rate);
139
140 extern int zapi_tc_qdisc_encode(uint8_t cmd, struct stream *s,
141 struct tc_qdisc *qdisc);
142 extern int zapi_tc_class_encode(uint8_t cmd, struct stream *s,
143 struct tc_class *class);
144 extern int zapi_tc_filter_encode(uint8_t cmd, struct stream *s,
145 struct tc_filter *filter);
146
147 #ifdef __cplusplus
148 }
149 #endif
150
151 #endif /* _TC_H */