]> git.proxmox.com Git - mirror_ovs.git/blame - lib/tc.h
lib/tc: add geneve with option encap action 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;
126 } tunnel;
f98e418f
RD
127};
128
0c70132c
CM
129enum tc_action_type {
130 TC_ACT_OUTPUT,
131 TC_ACT_ENCAP,
132 TC_ACT_PEDIT,
133 TC_ACT_VLAN_POP,
134 TC_ACT_VLAN_PUSH,
135};
136
137struct tc_action {
138 union {
139 int ifindex_out;
140
141 struct {
61e8655c 142 ovs_be16 vlan_push_tpid;
0c70132c
CM
143 uint16_t vlan_push_id;
144 uint8_t vlan_push_prio;
145 } vlan;
146
147 struct {
148 ovs_be64 id;
149 ovs_be16 tp_src;
150 ovs_be16 tp_dst;
4b12e454
OG
151 uint8_t tos;
152 uint8_t ttl;
0c70132c
CM
153 struct {
154 ovs_be32 ipv4_src;
155 ovs_be32 ipv4_dst;
156 } ipv4;
157 struct {
158 struct in6_addr ipv6_src;
159 struct in6_addr ipv6_dst;
160 } ipv6;
202469aa 161 struct tun_metadata data;
0c70132c
CM
162 } encap;
163 };
164
165 enum tc_action_type type;
166};
167
d63ca532
GT
168enum tc_offloaded_state {
169 TC_OFFLOADED_STATE_UNDEFINED,
170 TC_OFFLOADED_STATE_IN_HW,
171 TC_OFFLOADED_STATE_NOT_IN_HW,
172};
173
f98e418f
RD
174struct tc_flower {
175 uint32_t handle;
176 uint32_t prio;
177
178 struct tc_flower_key key;
179 struct tc_flower_key mask;
180
0c70132c
CM
181 int action_count;
182 struct tc_action actions[TCA_ACT_MAX_PRIO];
f98e418f
RD
183
184 struct ovs_flow_stats stats;
185 uint64_t lastused;
186
8ada482b
PB
187 struct {
188 bool rewrite;
189 struct tc_flower_key key;
190 struct tc_flower_key mask;
191 } rewrite;
192
193 uint32_t csum_update_flags;
194
105e8179 195 bool tunnel;
f98e418f
RD
196
197 struct tc_cookie act_cookie;
d6118e62
PB
198
199 bool needs_full_ip_proto_mask;
d63ca532
GT
200
201 enum tc_offloaded_state offloaded_state;
f98e418f
RD
202};
203
8ada482b
PB
204/* assert that if we overflow with a masked write of uint32_t to the last byte
205 * of flower.rewrite we overflow inside struct flower.
206 * shouldn't happen unless someone moves rewrite to the end of flower */
207BUILD_ASSERT_DECL(offsetof(struct tc_flower, rewrite)
208 + MEMBER_SIZEOF(struct tc_flower, rewrite)
209 + sizeof(uint32_t) - 2 < sizeof(struct tc_flower));
210
f98e418f 211int tc_replace_flower(int ifindex, uint16_t prio, uint32_t handle,
093c9458
JH
212 struct tc_flower *flower, uint32_t block_id);
213int tc_del_filter(int ifindex, int prio, int handle, uint32_t block_id);
f98e418f 214int tc_get_flower(int ifindex, int prio, int handle,
093c9458
JH
215 struct tc_flower *flower, uint32_t block_id);
216int tc_flush(int ifindex, uint32_t block_id);
217int tc_dump_flower_start(int ifindex, struct nl_dump *dump, uint32_t block_id);
f98e418f
RD
218int parse_netlink_to_tc_flower(struct ofpbuf *reply,
219 struct tc_flower *flower);
691d20cb 220void tc_set_policy(const char *policy);
f98e418f 221
c1c5c723 222#endif /* tc.h */