]> git.proxmox.com Git - mirror_ovs.git/blame - lib/tc.h
lib/tc: add geneve with option match offload
[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
39
40#define TC_INGRESS_PARENT TC_H_MAKE(TC_H_CLSACT, TC_H_MIN_INGRESS)
41
691d20cb
PB
42#define TC_POLICY_DEFAULT "none"
43
837f5250
RD
44/* Returns tc handle 'major':'minor'. */
45static inline unsigned int
46tc_make_handle(unsigned int major, unsigned int minor)
47{
48 return TC_H_MAKE(major << 16, minor);
49}
50
51/* Returns the major number from 'handle'. */
52static inline unsigned int
53tc_get_major(unsigned int handle)
54{
55 return TC_H_MAJ(handle) >> 16;
56}
57
58/* Returns the minor number from 'handle'. */
59static inline unsigned int
60tc_get_minor(unsigned int handle)
61{
62 return TC_H_MIN(handle);
63}
64
c1c5c723
PB
65struct tcmsg *tc_make_request(int ifindex, int type,
66 unsigned int flags, struct ofpbuf *);
67int tc_transact(struct ofpbuf *request, struct ofpbuf **replyp);
093c9458 68int tc_add_del_ingress_qdisc(int ifindex, bool add, uint32_t block_id);
c1c5c723 69
f98e418f
RD
70struct tc_cookie {
71 const void *data;
72 size_t len;
73};
74
75struct tc_flower_key {
76 ovs_be16 eth_type;
77 uint8_t ip_proto;
78
79 struct eth_addr dst_mac;
80 struct eth_addr src_mac;
81
34b16955 82 ovs_be32 mpls_lse;
2b1d9fa9
PB
83 ovs_be16 tcp_src;
84 ovs_be16 tcp_dst;
cd081043 85 ovs_be16 tcp_flags;
2b1d9fa9
PB
86
87 ovs_be16 udp_src;
88 ovs_be16 udp_dst;
89
90 ovs_be16 sctp_src;
91 ovs_be16 sctp_dst;
f98e418f 92
f9885dc5
JL
93 uint16_t vlan_id[FLOW_MAX_VLAN_HEADERS];
94 uint8_t vlan_prio[FLOW_MAX_VLAN_HEADERS];
f98e418f 95
f9885dc5 96 ovs_be16 encap_eth_type[FLOW_MAX_VLAN_HEADERS];
f98e418f 97
83e86606 98 uint8_t flags;
0b4b5203 99 uint8_t ip_ttl;
dfa2ccdb 100 uint8_t ip_tos;
0b4b5203 101
2b1d9fa9
PB
102 struct {
103 ovs_be32 ipv4_src;
104 ovs_be32 ipv4_dst;
8ada482b 105 uint8_t rewrite_ttl;
2b1d9fa9
PB
106 } ipv4;
107 struct {
108 struct in6_addr ipv6_src;
109 struct in6_addr ipv6_dst;
110 } ipv6;
105e8179
OG
111
112 struct {
113 struct {
114 ovs_be32 ipv4_src;
115 ovs_be32 ipv4_dst;
116 } ipv4;
117 struct {
118 struct in6_addr ipv6_src;
119 struct in6_addr ipv6_dst;
120 } ipv6;
121 uint8_t tos;
122 uint8_t ttl;
123 ovs_be16 tp_src;
124 ovs_be16 tp_dst;
125 ovs_be64 id;
a468645c 126 struct tun_metadata metadata;
105e8179 127 } tunnel;
f98e418f
RD
128};
129
0c70132c
CM
130enum tc_action_type {
131 TC_ACT_OUTPUT,
132 TC_ACT_ENCAP,
133 TC_ACT_PEDIT,
134 TC_ACT_VLAN_POP,
135 TC_ACT_VLAN_PUSH,
136};
137
138struct tc_action {
139 union {
140 int ifindex_out;
141
142 struct {
61e8655c 143 ovs_be16 vlan_push_tpid;
0c70132c
CM
144 uint16_t vlan_push_id;
145 uint8_t vlan_push_prio;
146 } vlan;
147
148 struct {
149 ovs_be64 id;
150 ovs_be16 tp_src;
151 ovs_be16 tp_dst;
4b12e454
OG
152 uint8_t tos;
153 uint8_t ttl;
0c70132c
CM
154 struct {
155 ovs_be32 ipv4_src;
156 ovs_be32 ipv4_dst;
157 } ipv4;
158 struct {
159 struct in6_addr ipv6_src;
160 struct in6_addr ipv6_dst;
161 } ipv6;
202469aa 162 struct tun_metadata data;
0c70132c
CM
163 } encap;
164 };
165
166 enum tc_action_type type;
167};
168
d63ca532
GT
169enum tc_offloaded_state {
170 TC_OFFLOADED_STATE_UNDEFINED,
171 TC_OFFLOADED_STATE_IN_HW,
172 TC_OFFLOADED_STATE_NOT_IN_HW,
173};
174
f98e418f
RD
175struct tc_flower {
176 uint32_t handle;
177 uint32_t prio;
178
179 struct tc_flower_key key;
180 struct tc_flower_key mask;
181
0c70132c
CM
182 int action_count;
183 struct tc_action actions[TCA_ACT_MAX_PRIO];
f98e418f
RD
184
185 struct ovs_flow_stats stats;
186 uint64_t lastused;
187
8ada482b
PB
188 struct {
189 bool rewrite;
190 struct tc_flower_key key;
191 struct tc_flower_key mask;
192 } rewrite;
193
194 uint32_t csum_update_flags;
195
105e8179 196 bool tunnel;
f98e418f
RD
197
198 struct tc_cookie act_cookie;
d6118e62
PB
199
200 bool needs_full_ip_proto_mask;
d63ca532
GT
201
202 enum tc_offloaded_state offloaded_state;
f98e418f
RD
203};
204
8ada482b
PB
205/* assert that if we overflow with a masked write of uint32_t to the last byte
206 * of flower.rewrite we overflow inside struct flower.
207 * shouldn't happen unless someone moves rewrite to the end of flower */
208BUILD_ASSERT_DECL(offsetof(struct tc_flower, rewrite)
209 + MEMBER_SIZEOF(struct tc_flower, rewrite)
210 + sizeof(uint32_t) - 2 < sizeof(struct tc_flower));
211
f98e418f 212int tc_replace_flower(int ifindex, uint16_t prio, uint32_t handle,
093c9458
JH
213 struct tc_flower *flower, uint32_t block_id);
214int tc_del_filter(int ifindex, int prio, int handle, uint32_t block_id);
f98e418f 215int tc_get_flower(int ifindex, int prio, int handle,
093c9458
JH
216 struct tc_flower *flower, uint32_t block_id);
217int tc_flush(int ifindex, uint32_t block_id);
218int tc_dump_flower_start(int ifindex, struct nl_dump *dump, uint32_t block_id);
f98e418f
RD
219int parse_netlink_to_tc_flower(struct ofpbuf *reply,
220 struct tc_flower *flower);
691d20cb 221void tc_set_policy(const char *policy);
f98e418f 222
c1c5c723 223#endif /* tc.h */