]> git.proxmox.com Git - ovs.git/blob - lib/tc.h
ovs-tc: allow offloading of ingress mirred TC actions to datapath
[ovs.git] / lib / tc.h
1 /*
2 * Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Nicira, Inc.
3 * Copyright (c) 2016 Mellanox Technologies, Ltd.
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
21 #include <sys/types.h>
22 #include <netinet/in.h> /* Must happen before linux/pkt_cls.h - Glibc #20215 */
23 #include <linux/pkt_cls.h>
24 #include <linux/pkt_sched.h>
25
26 #include "netlink-socket.h"
27 #include "odp-netlink.h"
28 #include "openvswitch/ofpbuf.h"
29 #include "openvswitch/flow.h"
30 #include "openvswitch/tun-metadata.h"
31
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
39
40 #define TC_INGRESS_PARENT TC_H_MAKE(TC_H_CLSACT, TC_H_MIN_INGRESS)
41
42 #define TC_POLICY_DEFAULT "none"
43
44 enum tc_flower_reserved_prio {
45 TC_RESERVED_PRIORITY_NONE,
46 TC_RESERVED_PRIORITY_POLICE,
47 __TC_RESERVED_PRIORITY_MAX
48 };
49 #define TC_RESERVED_PRIORITY_MAX (__TC_RESERVED_PRIORITY_MAX -1)
50
51 /* Returns tc handle 'major':'minor'. */
52 static inline unsigned int
53 tc_make_handle(unsigned int major, unsigned int minor)
54 {
55 return TC_H_MAKE(major << 16, minor);
56 }
57
58 /* Returns the major number from 'handle'. */
59 static inline unsigned int
60 tc_get_major(unsigned int handle)
61 {
62 return TC_H_MAJ(handle) >> 16;
63 }
64
65 /* Returns the minor number from 'handle'. */
66 static inline unsigned int
67 tc_get_minor(unsigned int handle)
68 {
69 return TC_H_MIN(handle);
70 }
71
72 struct tcmsg *tc_make_request(int ifindex, int type,
73 unsigned int flags, struct ofpbuf *);
74 int tc_transact(struct ofpbuf *request, struct ofpbuf **replyp);
75 int tc_add_del_ingress_qdisc(int ifindex, bool add, uint32_t block_id);
76
77 struct tc_cookie {
78 const void *data;
79 size_t len;
80 };
81
82 struct tc_flower_key {
83 ovs_be16 eth_type;
84 uint8_t ip_proto;
85
86 struct eth_addr dst_mac;
87 struct eth_addr src_mac;
88
89 ovs_be32 mpls_lse;
90 ovs_be16 tcp_src;
91 ovs_be16 tcp_dst;
92 ovs_be16 tcp_flags;
93
94 ovs_be16 udp_src;
95 ovs_be16 udp_dst;
96
97 ovs_be16 sctp_src;
98 ovs_be16 sctp_dst;
99
100 uint16_t vlan_id[FLOW_MAX_VLAN_HEADERS];
101 uint8_t vlan_prio[FLOW_MAX_VLAN_HEADERS];
102
103 ovs_be16 encap_eth_type[FLOW_MAX_VLAN_HEADERS];
104
105 uint8_t flags;
106 uint8_t ip_ttl;
107 uint8_t ip_tos;
108
109 struct {
110 ovs_be32 ipv4_src;
111 ovs_be32 ipv4_dst;
112 uint8_t rewrite_ttl;
113 uint8_t rewrite_tos;
114 } ipv4;
115 struct {
116 struct in6_addr ipv6_src;
117 struct in6_addr ipv6_dst;
118 uint8_t rewrite_hlimit;
119 uint8_t rewrite_tclass;
120 } ipv6;
121
122 struct {
123 struct {
124 ovs_be32 ipv4_src;
125 ovs_be32 ipv4_dst;
126 } ipv4;
127 struct {
128 struct in6_addr ipv6_src;
129 struct in6_addr ipv6_dst;
130 } ipv6;
131 uint8_t tos;
132 uint8_t ttl;
133 ovs_be16 tp_src;
134 ovs_be16 tp_dst;
135 ovs_be64 id;
136 struct tun_metadata metadata;
137 } tunnel;
138 };
139
140 enum tc_action_type {
141 TC_ACT_OUTPUT,
142 TC_ACT_ENCAP,
143 TC_ACT_PEDIT,
144 TC_ACT_VLAN_POP,
145 TC_ACT_VLAN_PUSH,
146 };
147
148 struct tc_action {
149 union {
150 struct {
151 int ifindex_out;
152 bool ingress;
153 } out;
154
155 struct {
156 ovs_be16 vlan_push_tpid;
157 uint16_t vlan_push_id;
158 uint8_t vlan_push_prio;
159 } vlan;
160
161 struct {
162 bool id_present;
163 ovs_be64 id;
164 ovs_be16 tp_src;
165 ovs_be16 tp_dst;
166 uint8_t tos;
167 uint8_t ttl;
168 uint8_t no_csum;
169 struct {
170 ovs_be32 ipv4_src;
171 ovs_be32 ipv4_dst;
172 } ipv4;
173 struct {
174 struct in6_addr ipv6_src;
175 struct in6_addr ipv6_dst;
176 } ipv6;
177 struct tun_metadata data;
178 } encap;
179 };
180
181 enum tc_action_type type;
182 };
183
184 enum tc_offloaded_state {
185 TC_OFFLOADED_STATE_UNDEFINED,
186 TC_OFFLOADED_STATE_IN_HW,
187 TC_OFFLOADED_STATE_NOT_IN_HW,
188 };
189
190 struct tc_flower {
191 uint32_t handle;
192 uint32_t prio;
193
194 struct tc_flower_key key;
195 struct tc_flower_key mask;
196
197 int action_count;
198 struct tc_action actions[TCA_ACT_MAX_PRIO];
199
200 struct ovs_flow_stats stats;
201 uint64_t lastused;
202
203 struct {
204 bool rewrite;
205 struct tc_flower_key key;
206 struct tc_flower_key mask;
207 } rewrite;
208
209 uint32_t csum_update_flags;
210
211 bool tunnel;
212
213 struct tc_cookie act_cookie;
214
215 bool needs_full_ip_proto_mask;
216
217 enum tc_offloaded_state offloaded_state;
218 };
219
220 /* assert that if we overflow with a masked write of uint32_t to the last byte
221 * of flower.rewrite we overflow inside struct flower.
222 * shouldn't happen unless someone moves rewrite to the end of flower */
223 BUILD_ASSERT_DECL(offsetof(struct tc_flower, rewrite)
224 + MEMBER_SIZEOF(struct tc_flower, rewrite)
225 + sizeof(uint32_t) - 2 < sizeof(struct tc_flower));
226
227 int tc_replace_flower(int ifindex, uint16_t prio, uint32_t handle,
228 struct tc_flower *flower, uint32_t block_id);
229 int tc_del_filter(int ifindex, int prio, int handle, uint32_t block_id);
230 int tc_get_flower(int ifindex, int prio, int handle,
231 struct tc_flower *flower, uint32_t block_id);
232 int tc_flush(int ifindex, uint32_t block_id);
233 int tc_dump_flower_start(int ifindex, struct nl_dump *dump, uint32_t block_id);
234 int parse_netlink_to_tc_flower(struct ofpbuf *reply,
235 struct tc_flower *flower);
236 void tc_set_policy(const char *policy);
237
238 #endif /* tc.h */