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"
30 #include "openvswitch/tun-metadata.h"
32 /* For backwards compatability with older kernels */
34 #define TC_H_CLSACT TC_H_INGRESS
36 #ifndef TC_H_MIN_INGRESS
37 #define TC_H_MIN_INGRESS 0xFFF2U
39 #ifndef TC_H_MIN_EGRESS
40 #define TC_H_MIN_EGRESS 0xFFF3U
43 #define TC_INGRESS_PARENT TC_H_MAKE(TC_H_CLSACT, TC_H_MIN_INGRESS)
44 #define TC_EGRESS_PARENT TC_H_MAKE(TC_H_CLSACT, TC_H_MIN_EGRESS)
46 #define TC_POLICY_DEFAULT "none"
48 enum tc_flower_reserved_prio
{
49 TC_RESERVED_PRIORITY_NONE
,
50 TC_RESERVED_PRIORITY_POLICE
,
51 __TC_RESERVED_PRIORITY_MAX
53 #define TC_RESERVED_PRIORITY_MAX (__TC_RESERVED_PRIORITY_MAX -1)
60 /* Returns tc handle 'major':'minor'. */
61 static inline unsigned int
62 tc_make_handle(unsigned int major
, unsigned int minor
)
64 return TC_H_MAKE(major
<< 16, minor
);
67 /* Returns the major number from 'handle'. */
68 static inline unsigned int
69 tc_get_major(unsigned int handle
)
71 return TC_H_MAJ(handle
) >> 16;
74 /* Returns the minor number from 'handle'. */
75 static inline unsigned int
76 tc_get_minor(unsigned int handle
)
78 return TC_H_MIN(handle
);
81 struct tcmsg
*tc_make_request(int ifindex
, int type
,
82 unsigned int flags
, struct ofpbuf
*);
83 int tc_transact(struct ofpbuf
*request
, struct ofpbuf
**replyp
);
84 int tc_add_del_qdisc(int ifindex
, bool add
, uint32_t block_id
,
85 enum tc_qdisc_hook hook
);
92 struct tc_flower_key
{
96 struct eth_addr dst_mac
;
97 struct eth_addr src_mac
;
110 uint16_t vlan_id
[FLOW_MAX_VLAN_HEADERS
];
111 uint8_t vlan_prio
[FLOW_MAX_VLAN_HEADERS
];
113 ovs_be16 encap_eth_type
[FLOW_MAX_VLAN_HEADERS
];
139 struct in6_addr ipv6_src
;
140 struct in6_addr ipv6_dst
;
141 uint8_t rewrite_hlimit
;
142 uint8_t rewrite_tclass
;
151 struct in6_addr ipv6_src
;
152 struct in6_addr ipv6_dst
;
159 struct tun_metadata metadata
;
163 enum tc_action_type
{
193 ovs_be16 vlan_push_tpid
;
194 uint16_t vlan_push_id
;
195 uint8_t vlan_push_prio
;
219 struct in6_addr ipv6_src
;
220 struct in6_addr ipv6_dst
;
222 struct tun_metadata data
;
258 enum tc_action_type type
;
261 enum tc_offloaded_state
{
262 TC_OFFLOADED_STATE_UNDEFINED
,
263 TC_OFFLOADED_STATE_IN_HW
,
264 TC_OFFLOADED_STATE_NOT_IN_HW
,
267 #define TCA_ACT_MAX_NUM 16
270 enum tc_qdisc_hook hook
;
278 static inline struct tcf_id
279 tc_make_tcf_id(int ifindex
, uint32_t block_id
, uint16_t prio
,
280 enum tc_qdisc_hook hook
)
284 .block_id
= block_id
,
292 static inline struct tcf_id
293 tc_make_tcf_id_chain(int ifindex
, uint32_t block_id
, uint32_t chain
,
294 uint16_t prio
, enum tc_qdisc_hook hook
)
296 struct tcf_id id
= tc_make_tcf_id(ifindex
, block_id
, prio
, hook
);
304 is_tcf_id_eq(struct tcf_id
*id1
, struct tcf_id
*id2
)
306 return id1
->prio
== id2
->prio
307 && id1
->handle
== id2
->handle
308 && id1
->handle
== id2
->handle
309 && id1
->hook
== id2
->hook
310 && id1
->block_id
== id2
->block_id
311 && id1
->ifindex
== id2
->ifindex
312 && id1
->chain
== id2
->chain
;
316 struct tc_flower_key key
;
317 struct tc_flower_key mask
;
320 struct tc_action actions
[TCA_ACT_MAX_NUM
];
322 struct ovs_flow_stats stats
;
327 struct tc_flower_key key
;
328 struct tc_flower_key mask
;
331 uint32_t csum_update_flags
;
335 struct tc_cookie act_cookie
;
337 bool needs_full_ip_proto_mask
;
339 enum tc_offloaded_state offloaded_state
;
342 /* assert that if we overflow with a masked write of uint32_t to the last byte
343 * of flower.rewrite we overflow inside struct flower.
344 * shouldn't happen unless someone moves rewrite to the end of flower */
345 BUILD_ASSERT_DECL(offsetof(struct tc_flower
, rewrite
)
346 + MEMBER_SIZEOF(struct tc_flower
, rewrite
)
347 + sizeof(uint32_t) - 2 < sizeof(struct tc_flower
));
349 int tc_replace_flower(struct tcf_id
*id
, struct tc_flower
*flower
);
350 int tc_del_filter(struct tcf_id
*id
);
351 int tc_get_flower(struct tcf_id
*id
, struct tc_flower
*flower
);
352 int tc_dump_flower_start(struct tcf_id
*id
, struct nl_dump
*dump
, bool terse
);
353 int parse_netlink_to_tc_flower(struct ofpbuf
*reply
,
355 struct tc_flower
*flower
,
357 void tc_set_policy(const char *policy
);