]> git.proxmox.com Git - mirror_ovs.git/blame - lib/tc.h
tc: Limit the max action number to 16
[mirror_ovs.git] / lib / tc.h
CommitLineData
c1c5c723
PB
1/*
2 * Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Nicira, Inc.
f98e418f 3 * Copyright (c) 2016 Mellanox Technologies, Ltd.
c1c5c723
PB
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef TC_H
19#define TC_H 1
20
b2befd5b 21#include <sys/types.h>
de4a611f 22#include <netinet/in.h> /* Must happen before linux/pkt_cls.h - Glibc #20215 */
c1c5c723
PB
23#include <linux/pkt_cls.h>
24#include <linux/pkt_sched.h>
ef3767f5
JS
25
26#include "netlink-socket.h"
f98e418f 27#include "odp-netlink.h"
c1c5c723 28#include "openvswitch/ofpbuf.h"
f9885dc5 29#include "openvswitch/flow.h"
202469aa 30#include "openvswitch/tun-metadata.h"
c1c5c723 31
f98e418f
RD
32/* For backwards compatability with older kernels */
33#ifndef TC_H_CLSACT
34#define TC_H_CLSACT TC_H_INGRESS
35#endif
36#ifndef TC_H_MIN_INGRESS
37#define TC_H_MIN_INGRESS 0xFFF2U
38#endif
95255018
JH
39#ifndef TC_H_MIN_EGRESS
40#define TC_H_MIN_EGRESS 0xFFF3U
41#endif
f98e418f
RD
42
43#define TC_INGRESS_PARENT TC_H_MAKE(TC_H_CLSACT, TC_H_MIN_INGRESS)
95255018 44#define TC_EGRESS_PARENT TC_H_MAKE(TC_H_CLSACT, TC_H_MIN_EGRESS)
f98e418f 45
691d20cb
PB
46#define TC_POLICY_DEFAULT "none"
47
e7f6ba22
PJV
48enum tc_flower_reserved_prio {
49 TC_RESERVED_PRIORITY_NONE,
50 TC_RESERVED_PRIORITY_POLICE,
51 __TC_RESERVED_PRIORITY_MAX
52};
53#define TC_RESERVED_PRIORITY_MAX (__TC_RESERVED_PRIORITY_MAX -1)
54
95255018
JH
55enum tc_qdisc_hook {
56 TC_INGRESS,
57 TC_EGRESS,
58};
59
837f5250
RD
60/* Returns tc handle 'major':'minor'. */
61static inline unsigned int
62tc_make_handle(unsigned int major, unsigned int minor)
63{
64 return TC_H_MAKE(major << 16, minor);
65}
66
67/* Returns the major number from 'handle'. */
68static inline unsigned int
69tc_get_major(unsigned int handle)
70{
71 return TC_H_MAJ(handle) >> 16;
72}
73
74/* Returns the minor number from 'handle'. */
75static inline unsigned int
76tc_get_minor(unsigned int handle)
77{
78 return TC_H_MIN(handle);
79}
80
c1c5c723
PB
81struct tcmsg *tc_make_request(int ifindex, int type,
82 unsigned int flags, struct ofpbuf *);
83int tc_transact(struct ofpbuf *request, struct ofpbuf **replyp);
95255018
JH
84int tc_add_del_qdisc(int ifindex, bool add, uint32_t block_id,
85 enum tc_qdisc_hook hook);
c1c5c723 86
f98e418f
RD
87struct tc_cookie {
88 const void *data;
89 size_t len;
90};
91
92struct tc_flower_key {
93 ovs_be16 eth_type;
94 uint8_t ip_proto;
95
96 struct eth_addr dst_mac;
97 struct eth_addr src_mac;
98
34b16955 99 ovs_be32 mpls_lse;
2b1d9fa9
PB
100 ovs_be16 tcp_src;
101 ovs_be16 tcp_dst;
cd081043 102 ovs_be16 tcp_flags;
2b1d9fa9
PB
103
104 ovs_be16 udp_src;
105 ovs_be16 udp_dst;
106
107 ovs_be16 sctp_src;
108 ovs_be16 sctp_dst;
f98e418f 109
f9885dc5
JL
110 uint16_t vlan_id[FLOW_MAX_VLAN_HEADERS];
111 uint8_t vlan_prio[FLOW_MAX_VLAN_HEADERS];
f98e418f 112
f9885dc5 113 ovs_be16 encap_eth_type[FLOW_MAX_VLAN_HEADERS];
f98e418f 114
83e86606 115 uint8_t flags;
0b4b5203 116 uint8_t ip_ttl;
dfa2ccdb 117 uint8_t ip_tos;
0b4b5203 118
2b1d9fa9
PB
119 struct {
120 ovs_be32 ipv4_src;
121 ovs_be32 ipv4_dst;
8ada482b 122 uint8_t rewrite_ttl;
95431229 123 uint8_t rewrite_tos;
2b1d9fa9
PB
124 } ipv4;
125 struct {
126 struct in6_addr ipv6_src;
127 struct in6_addr ipv6_dst;
46df7fac 128 uint8_t rewrite_hlimit;
dbcb014d 129 uint8_t rewrite_tclass;
2b1d9fa9 130 } ipv6;
105e8179
OG
131
132 struct {
133 struct {
134 ovs_be32 ipv4_src;
135 ovs_be32 ipv4_dst;
136 } ipv4;
137 struct {
138 struct in6_addr ipv6_src;
139 struct in6_addr ipv6_dst;
140 } ipv6;
141 uint8_t tos;
142 uint8_t ttl;
143 ovs_be16 tp_src;
144 ovs_be16 tp_dst;
145 ovs_be64 id;
a468645c 146 struct tun_metadata metadata;
105e8179 147 } tunnel;
f98e418f
RD
148};
149
0c70132c
CM
150enum tc_action_type {
151 TC_ACT_OUTPUT,
152 TC_ACT_ENCAP,
153 TC_ACT_PEDIT,
154 TC_ACT_VLAN_POP,
155 TC_ACT_VLAN_PUSH,
55412eac 156 TC_ACT_MPLS_POP,
283dcf85 157 TC_ACT_MPLS_PUSH,
a8f005cf 158 TC_ACT_MPLS_SET,
0c70132c
CM
159};
160
161struct tc_action {
162 union {
4aa2dc04
JH
163 struct {
164 int ifindex_out;
165 bool ingress;
166 } out;
0c70132c
CM
167
168 struct {
61e8655c 169 ovs_be16 vlan_push_tpid;
0c70132c
CM
170 uint16_t vlan_push_id;
171 uint8_t vlan_push_prio;
172 } vlan;
173
55412eac
JH
174 struct {
175 ovs_be16 proto;
283dcf85
JH
176 uint32_t label;
177 uint8_t tc;
178 uint8_t ttl;
179 uint8_t bos;
55412eac
JH
180 } mpls;
181
0c70132c 182 struct {
0227bf09 183 bool id_present;
0c70132c
CM
184 ovs_be64 id;
185 ovs_be16 tp_src;
186 ovs_be16 tp_dst;
4b12e454
OG
187 uint8_t tos;
188 uint8_t ttl;
d9677a1f 189 uint8_t no_csum;
0c70132c
CM
190 struct {
191 ovs_be32 ipv4_src;
192 ovs_be32 ipv4_dst;
193 } ipv4;
194 struct {
195 struct in6_addr ipv6_src;
196 struct in6_addr ipv6_dst;
197 } ipv6;
202469aa 198 struct tun_metadata data;
0c70132c
CM
199 } encap;
200 };
201
202 enum tc_action_type type;
203};
204
d63ca532
GT
205enum tc_offloaded_state {
206 TC_OFFLOADED_STATE_UNDEFINED,
207 TC_OFFLOADED_STATE_IN_HW,
208 TC_OFFLOADED_STATE_NOT_IN_HW,
209};
210
d0fbb09f
CM
211#define TCA_ACT_MAX_NUM 16
212
f98e418f
RD
213struct tc_flower {
214 uint32_t handle;
215 uint32_t prio;
216
217 struct tc_flower_key key;
218 struct tc_flower_key mask;
219
0c70132c 220 int action_count;
d0fbb09f 221 struct tc_action actions[TCA_ACT_MAX_NUM];
f98e418f
RD
222
223 struct ovs_flow_stats stats;
224 uint64_t lastused;
225
8ada482b
PB
226 struct {
227 bool rewrite;
228 struct tc_flower_key key;
229 struct tc_flower_key mask;
230 } rewrite;
231
232 uint32_t csum_update_flags;
233
105e8179 234 bool tunnel;
f98e418f
RD
235
236 struct tc_cookie act_cookie;
d6118e62
PB
237
238 bool needs_full_ip_proto_mask;
d63ca532
GT
239
240 enum tc_offloaded_state offloaded_state;
f98e418f
RD
241};
242
8ada482b
PB
243/* assert that if we overflow with a masked write of uint32_t to the last byte
244 * of flower.rewrite we overflow inside struct flower.
245 * shouldn't happen unless someone moves rewrite to the end of flower */
246BUILD_ASSERT_DECL(offsetof(struct tc_flower, rewrite)
247 + MEMBER_SIZEOF(struct tc_flower, rewrite)
248 + sizeof(uint32_t) - 2 < sizeof(struct tc_flower));
249
f98e418f 250int tc_replace_flower(int ifindex, uint16_t prio, uint32_t handle,
95255018
JH
251 struct tc_flower *flower, uint32_t block_id,
252 enum tc_qdisc_hook hook);
253int tc_del_filter(int ifindex, int prio, int handle, uint32_t block_id,
254 enum tc_qdisc_hook hook);
f98e418f 255int tc_get_flower(int ifindex, int prio, int handle,
95255018
JH
256 struct tc_flower *flower, uint32_t block_id,
257 enum tc_qdisc_hook hook);
258int tc_flush(int ifindex, uint32_t block_id, enum tc_qdisc_hook hook);
259int tc_dump_flower_start(int ifindex, struct nl_dump *dump, uint32_t block_id,
260 enum tc_qdisc_hook hook);
f98e418f
RD
261int parse_netlink_to_tc_flower(struct ofpbuf *reply,
262 struct tc_flower *flower);
691d20cb 263void tc_set_policy(const char *policy);
f98e418f 264
c1c5c723 265#endif /* tc.h */