2 * Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Nicira, Inc.
3 * Copyright (c) 2016 Mellanox Technologies, Ltd.
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:
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
26 #include "netlink-socket.h"
27 #include "odp-netlink.h"
28 #include "openvswitch/ofpbuf.h"
29 #include "openvswitch/flow.h"
31 /* For backwards compatability with older kernels */
33 #define TC_H_CLSACT TC_H_INGRESS
35 #ifndef TC_H_MIN_INGRESS
36 #define TC_H_MIN_INGRESS 0xFFF2U
39 #define TC_INGRESS_PARENT TC_H_MAKE(TC_H_CLSACT, TC_H_MIN_INGRESS)
41 #define TC_POLICY_DEFAULT "none"
43 /* Returns tc handle 'major':'minor'. */
44 static inline unsigned int
45 tc_make_handle(unsigned int major
, unsigned int minor
)
47 return TC_H_MAKE(major
<< 16, minor
);
50 /* Returns the major number from 'handle'. */
51 static inline unsigned int
52 tc_get_major(unsigned int handle
)
54 return TC_H_MAJ(handle
) >> 16;
57 /* Returns the minor number from 'handle'. */
58 static inline unsigned int
59 tc_get_minor(unsigned int handle
)
61 return TC_H_MIN(handle
);
64 struct tcmsg
*tc_make_request(int ifindex
, int type
,
65 unsigned int flags
, struct ofpbuf
*);
66 int tc_transact(struct ofpbuf
*request
, struct ofpbuf
**replyp
);
67 int tc_add_del_ingress_qdisc(int ifindex
, bool add
, uint32_t block_id
);
74 struct tc_flower_key
{
78 struct eth_addr dst_mac
;
79 struct eth_addr src_mac
;
91 uint16_t vlan_id
[FLOW_MAX_VLAN_HEADERS
];
92 uint8_t vlan_prio
[FLOW_MAX_VLAN_HEADERS
];
94 ovs_be16 encap_eth_type
[FLOW_MAX_VLAN_HEADERS
];
106 struct in6_addr ipv6_src
;
107 struct in6_addr ipv6_dst
;
111 enum tc_action_type
{
124 ovs_be16 vlan_push_tpid
;
125 uint16_t vlan_push_id
;
126 uint8_t vlan_push_prio
;
138 struct in6_addr ipv6_src
;
139 struct in6_addr ipv6_dst
;
144 enum tc_action_type type
;
147 enum tc_offloaded_state
{
148 TC_OFFLOADED_STATE_UNDEFINED
,
149 TC_OFFLOADED_STATE_IN_HW
,
150 TC_OFFLOADED_STATE_NOT_IN_HW
,
157 struct tc_flower_key key
;
158 struct tc_flower_key mask
;
161 struct tc_action actions
[TCA_ACT_MAX_PRIO
];
163 struct ovs_flow_stats stats
;
168 struct tc_flower_key key
;
169 struct tc_flower_key mask
;
172 uint32_t csum_update_flags
;
181 struct in6_addr ipv6_src
;
182 struct in6_addr ipv6_dst
;
189 struct tc_cookie act_cookie
;
191 bool needs_full_ip_proto_mask
;
193 enum tc_offloaded_state offloaded_state
;
196 /* assert that if we overflow with a masked write of uint32_t to the last byte
197 * of flower.rewrite we overflow inside struct flower.
198 * shouldn't happen unless someone moves rewrite to the end of flower */
199 BUILD_ASSERT_DECL(offsetof(struct tc_flower
, rewrite
)
200 + MEMBER_SIZEOF(struct tc_flower
, rewrite
)
201 + sizeof(uint32_t) - 2 < sizeof(struct tc_flower
));
203 int tc_replace_flower(int ifindex
, uint16_t prio
, uint32_t handle
,
204 struct tc_flower
*flower
, uint32_t block_id
);
205 int tc_del_filter(int ifindex
, int prio
, int handle
, uint32_t block_id
);
206 int tc_get_flower(int ifindex
, int prio
, int handle
,
207 struct tc_flower
*flower
, uint32_t block_id
);
208 int tc_flush(int ifindex
, uint32_t block_id
);
209 int tc_dump_flower_start(int ifindex
, struct nl_dump
*dump
, uint32_t block_id
);
210 int parse_netlink_to_tc_flower(struct ofpbuf
*reply
,
211 struct tc_flower
*flower
);
212 void tc_set_policy(const char *policy
);