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