2 * Copyright (c) 2016 Mellanox Technologies, Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include "netdev-tc-offloads.h"
21 #include <linux/if_ether.h>
25 #include "openvswitch/hmap.h"
26 #include "openvswitch/match.h"
27 #include "openvswitch/ofpbuf.h"
28 #include "openvswitch/thread.h"
29 #include "openvswitch/types.h"
30 #include "openvswitch/util.h"
31 #include "openvswitch/vlog.h"
32 #include "netdev-linux.h"
34 #include "netlink-socket.h"
35 #include "odp-netlink.h"
38 #include "unaligned.h"
41 VLOG_DEFINE_THIS_MODULE(netdev_tc_offloads
);
43 static struct vlog_rate_limit error_rl
= VLOG_RATE_LIMIT_INIT(60, 5);
45 static struct hmap ufid_tc
= HMAP_INITIALIZER(&ufid_tc
);
46 static bool multi_mask_per_prio
= false;
47 static bool block_support
= false;
49 struct netlink_field
{
55 static struct netlink_field set_flower_map
[][3] = {
56 [OVS_KEY_ATTR_IPV4
] = {
57 { offsetof(struct ovs_key_ipv4
, ipv4_src
),
58 offsetof(struct tc_flower_key
, ipv4
.ipv4_src
),
59 MEMBER_SIZEOF(struct tc_flower_key
, ipv4
.ipv4_src
)
61 { offsetof(struct ovs_key_ipv4
, ipv4_dst
),
62 offsetof(struct tc_flower_key
, ipv4
.ipv4_dst
),
63 MEMBER_SIZEOF(struct tc_flower_key
, ipv4
.ipv4_dst
)
65 { offsetof(struct ovs_key_ipv4
, ipv4_ttl
),
66 offsetof(struct tc_flower_key
, ipv4
.rewrite_ttl
),
67 MEMBER_SIZEOF(struct tc_flower_key
, ipv4
.rewrite_ttl
)
70 [OVS_KEY_ATTR_IPV6
] = {
71 { offsetof(struct ovs_key_ipv6
, ipv6_src
),
72 offsetof(struct tc_flower_key
, ipv6
.ipv6_src
),
73 MEMBER_SIZEOF(struct tc_flower_key
, ipv6
.ipv6_src
)
75 { offsetof(struct ovs_key_ipv6
, ipv6_dst
),
76 offsetof(struct tc_flower_key
, ipv6
.ipv6_dst
),
77 MEMBER_SIZEOF(struct tc_flower_key
, ipv6
.ipv6_dst
)
80 [OVS_KEY_ATTR_ETHERNET
] = {
81 { offsetof(struct ovs_key_ethernet
, eth_src
),
82 offsetof(struct tc_flower_key
, src_mac
),
83 MEMBER_SIZEOF(struct tc_flower_key
, src_mac
)
85 { offsetof(struct ovs_key_ethernet
, eth_dst
),
86 offsetof(struct tc_flower_key
, dst_mac
),
87 MEMBER_SIZEOF(struct tc_flower_key
, dst_mac
)
90 [OVS_KEY_ATTR_ETHERTYPE
] = {
92 offsetof(struct tc_flower_key
, eth_type
),
93 MEMBER_SIZEOF(struct tc_flower_key
, eth_type
)
96 [OVS_KEY_ATTR_TCP
] = {
97 { offsetof(struct ovs_key_tcp
, tcp_src
),
98 offsetof(struct tc_flower_key
, tcp_src
),
99 MEMBER_SIZEOF(struct tc_flower_key
, tcp_src
)
101 { offsetof(struct ovs_key_tcp
, tcp_dst
),
102 offsetof(struct tc_flower_key
, tcp_dst
),
103 MEMBER_SIZEOF(struct tc_flower_key
, tcp_dst
)
106 [OVS_KEY_ATTR_UDP
] = {
107 { offsetof(struct ovs_key_udp
, udp_src
),
108 offsetof(struct tc_flower_key
, udp_src
),
109 MEMBER_SIZEOF(struct tc_flower_key
, udp_src
)
111 { offsetof(struct ovs_key_udp
, udp_dst
),
112 offsetof(struct tc_flower_key
, udp_dst
),
113 MEMBER_SIZEOF(struct tc_flower_key
, udp_dst
)
118 static struct ovs_mutex ufid_lock
= OVS_MUTEX_INITIALIZER
;
121 * struct ufid_tc_data - data entry for ufid_tc hmap.
122 * @ufid_node: Element in @ufid_tc hash table by ufid key.
123 * @tc_node: Element in @ufid_tc hash table by prio/handle/ifindex key.
124 * @ufid: ufid assigned to the flow
127 * @ifindex: netdev ifindex.
128 * @netdev: netdev associated with the tc rule
130 struct ufid_tc_data
{
131 struct hmap_node ufid_node
;
132 struct hmap_node tc_node
;
137 struct netdev
*netdev
;
140 /* Remove matching ufid entry from ufid_tc hashmap. */
142 del_ufid_tc_mapping(const ovs_u128
*ufid
)
144 size_t ufid_hash
= hash_bytes(ufid
, sizeof *ufid
, 0);
145 struct ufid_tc_data
*data
;
147 ovs_mutex_lock(&ufid_lock
);
148 HMAP_FOR_EACH_WITH_HASH(data
, ufid_node
, ufid_hash
, &ufid_tc
) {
149 if (ovs_u128_equals(*ufid
, data
->ufid
)) {
155 ovs_mutex_unlock(&ufid_lock
);
159 hmap_remove(&ufid_tc
, &data
->ufid_node
);
160 hmap_remove(&ufid_tc
, &data
->tc_node
);
161 netdev_close(data
->netdev
);
163 ovs_mutex_unlock(&ufid_lock
);
166 /* Add ufid entry to ufid_tc hashmap.
167 * If entry exists already it will be replaced. */
169 add_ufid_tc_mapping(const ovs_u128
*ufid
, int prio
, int handle
,
170 struct netdev
*netdev
, int ifindex
)
172 size_t ufid_hash
= hash_bytes(ufid
, sizeof *ufid
, 0);
173 size_t tc_hash
= hash_int(hash_int(prio
, handle
), ifindex
);
174 struct ufid_tc_data
*new_data
= xzalloc(sizeof *new_data
);
176 del_ufid_tc_mapping(ufid
);
178 new_data
->ufid
= *ufid
;
179 new_data
->prio
= prio
;
180 new_data
->handle
= handle
;
181 new_data
->netdev
= netdev_ref(netdev
);
182 new_data
->ifindex
= ifindex
;
184 ovs_mutex_lock(&ufid_lock
);
185 hmap_insert(&ufid_tc
, &new_data
->ufid_node
, ufid_hash
);
186 hmap_insert(&ufid_tc
, &new_data
->tc_node
, tc_hash
);
187 ovs_mutex_unlock(&ufid_lock
);
190 /* Get ufid from ufid_tc hashmap.
192 * If netdev output param is not NULL then the function will return
193 * associated netdev on success and a refcount is taken on that netdev.
194 * The caller is then responsible to close the netdev.
196 * Returns handle if successful and fill prio and netdev for that ufid.
197 * Otherwise returns 0.
200 get_ufid_tc_mapping(const ovs_u128
*ufid
, int *prio
, struct netdev
**netdev
)
202 size_t ufid_hash
= hash_bytes(ufid
, sizeof *ufid
, 0);
203 struct ufid_tc_data
*data
;
206 ovs_mutex_lock(&ufid_lock
);
207 HMAP_FOR_EACH_WITH_HASH(data
, ufid_node
, ufid_hash
, &ufid_tc
) {
208 if (ovs_u128_equals(*ufid
, data
->ufid
)) {
213 *netdev
= netdev_ref(data
->netdev
);
215 handle
= data
->handle
;
219 ovs_mutex_unlock(&ufid_lock
);
224 /* Find ufid entry in ufid_tc hashmap using prio, handle and netdev.
225 * The result is saved in ufid.
227 * Returns true on success.
230 find_ufid(int prio
, int handle
, struct netdev
*netdev
, ovs_u128
*ufid
)
232 int ifindex
= netdev_get_ifindex(netdev
);
233 struct ufid_tc_data
*data
;
234 size_t tc_hash
= hash_int(hash_int(prio
, handle
), ifindex
);
236 ovs_mutex_lock(&ufid_lock
);
237 HMAP_FOR_EACH_WITH_HASH(data
, tc_node
, tc_hash
, &ufid_tc
) {
238 if (data
->prio
== prio
&& data
->handle
== handle
239 && data
->ifindex
== ifindex
) {
244 ovs_mutex_unlock(&ufid_lock
);
246 return (data
!= NULL
);
249 struct prio_map_data
{
250 struct hmap_node node
;
251 struct tc_flower_key mask
;
256 /* Get free prio for tc flower
257 * If prio is already allocated for mask/eth_type combination then return it.
258 * If not assign new prio.
260 * Return prio on success or 0 if we are out of prios.
263 get_prio_for_tc_flower(struct tc_flower
*flower
)
265 static struct hmap prios
= HMAP_INITIALIZER(&prios
);
266 static struct ovs_mutex prios_lock
= OVS_MUTEX_INITIALIZER
;
267 static uint16_t last_prio
= 0;
268 size_t key_len
= sizeof(struct tc_flower_key
);
269 size_t hash
= hash_int((OVS_FORCE
uint32_t) flower
->key
.eth_type
, 0);
270 struct prio_map_data
*data
;
271 struct prio_map_data
*new_data
;
273 if (!multi_mask_per_prio
) {
274 hash
= hash_bytes(&flower
->mask
, key_len
, hash
);
277 /* We can use the same prio for same mask/eth combination but must have
278 * different prio if not. Flower classifier will reject same prio for
279 * different mask combination unless multi mask per prio is supported. */
280 ovs_mutex_lock(&prios_lock
);
281 HMAP_FOR_EACH_WITH_HASH(data
, node
, hash
, &prios
) {
282 if ((multi_mask_per_prio
283 || !memcmp(&flower
->mask
, &data
->mask
, key_len
))
284 && data
->protocol
== flower
->key
.eth_type
) {
285 ovs_mutex_unlock(&prios_lock
);
290 if (last_prio
== UINT16_MAX
) {
291 /* last_prio can overflow if there will be many different kinds of
292 * flows which shouldn't happen organically. */
293 ovs_mutex_unlock(&prios_lock
);
297 new_data
= xzalloc(sizeof *new_data
);
298 memcpy(&new_data
->mask
, &flower
->mask
, key_len
);
299 new_data
->prio
= ++last_prio
;
300 new_data
->protocol
= flower
->key
.eth_type
;
301 hmap_insert(&prios
, &new_data
->node
, hash
);
302 ovs_mutex_unlock(&prios_lock
);
304 return new_data
->prio
;
308 get_block_id_from_netdev(struct netdev
*netdev
)
311 return netdev_get_block_id(netdev
);
318 netdev_tc_flow_flush(struct netdev
*netdev
)
320 int ifindex
= netdev_get_ifindex(netdev
);
321 uint32_t block_id
= 0;
324 VLOG_ERR_RL(&error_rl
, "flow_flush: failed to get ifindex for %s: %s",
325 netdev_get_name(netdev
), ovs_strerror(-ifindex
));
329 block_id
= get_block_id_from_netdev(netdev
);
331 return tc_flush(ifindex
, block_id
);
335 netdev_tc_flow_dump_create(struct netdev
*netdev
,
336 struct netdev_flow_dump
**dump_out
)
338 struct netdev_flow_dump
*dump
;
339 uint32_t block_id
= 0;
342 ifindex
= netdev_get_ifindex(netdev
);
344 VLOG_ERR_RL(&error_rl
, "dump_create: failed to get ifindex for %s: %s",
345 netdev_get_name(netdev
), ovs_strerror(-ifindex
));
349 block_id
= get_block_id_from_netdev(netdev
);
350 dump
= xzalloc(sizeof *dump
);
351 dump
->nl_dump
= xzalloc(sizeof *dump
->nl_dump
);
352 dump
->netdev
= netdev_ref(netdev
);
353 tc_dump_flower_start(ifindex
, dump
->nl_dump
, block_id
);
361 netdev_tc_flow_dump_destroy(struct netdev_flow_dump
*dump
)
363 nl_dump_done(dump
->nl_dump
);
364 netdev_close(dump
->netdev
);
371 parse_flower_rewrite_to_netlink_action(struct ofpbuf
*buf
,
372 struct tc_flower
*flower
)
374 char *mask
= (char *) &flower
->rewrite
.mask
;
375 char *data
= (char *) &flower
->rewrite
.key
;
377 for (int type
= 0; type
< ARRAY_SIZE(set_flower_map
); type
++) {
380 int len
= ovs_flow_key_attr_lens
[type
].len
;
386 for (int j
= 0; j
< ARRAY_SIZE(set_flower_map
[type
]); j
++) {
387 struct netlink_field
*f
= &set_flower_map
[type
][j
];
393 if (!is_all_zeros(mask
+ f
->flower_offset
, f
->size
)) {
395 nested
= nl_msg_start_nested(buf
,
396 OVS_ACTION_ATTR_SET_MASKED
);
397 put
= nl_msg_put_unspec_zero(buf
, type
, len
* 2);
400 memcpy(put
+ f
->offset
, data
+ f
->flower_offset
, f
->size
);
401 memcpy(put
+ len
+ f
->offset
,
402 mask
+ f
->flower_offset
, f
->size
);
407 nl_msg_end_nested(buf
, nested
);
413 parse_tc_flower_to_match(struct tc_flower
*flower
,
415 struct nlattr
**actions
,
416 struct dpif_flow_stats
*stats
,
417 struct dpif_flow_attrs
*attrs
,
421 struct tc_flower_key
*key
= &flower
->key
;
422 struct tc_flower_key
*mask
= &flower
->mask
;
423 odp_port_t outport
= 0;
424 struct tc_action
*action
;
429 match_init_catchall(match
);
430 match_set_dl_src_masked(match
, key
->src_mac
, mask
->src_mac
);
431 match_set_dl_dst_masked(match
, key
->dst_mac
, mask
->dst_mac
);
433 if (eth_type_vlan(key
->eth_type
)) {
434 match
->flow
.vlans
[0].tpid
= key
->eth_type
;
435 match
->wc
.masks
.vlans
[0].tpid
= OVS_BE16_MAX
;
436 match_set_dl_vlan(match
, htons(key
->vlan_id
[0]), 0);
437 match_set_dl_vlan_pcp(match
, key
->vlan_prio
[0], 0);
439 if (eth_type_vlan(key
->encap_eth_type
[0])) {
440 match_set_dl_vlan(match
, htons(key
->vlan_id
[1]), 1);
441 match_set_dl_vlan_pcp(match
, key
->vlan_prio
[1], 1);
442 match_set_dl_type(match
, key
->encap_eth_type
[1]);
443 match
->flow
.vlans
[1].tpid
= key
->encap_eth_type
[0];
444 match
->wc
.masks
.vlans
[1].tpid
= OVS_BE16_MAX
;
446 match_set_dl_type(match
, key
->encap_eth_type
[0]);
448 flow_fix_vlan_tpid(&match
->flow
);
450 match_set_dl_type(match
, key
->eth_type
);
453 if (is_ip_any(&match
->flow
)) {
455 match_set_nw_proto(match
, key
->ip_proto
);
458 match_set_nw_tos_masked(match
, key
->ip_tos
, mask
->ip_tos
);
459 match_set_nw_ttl_masked(match
, key
->ip_ttl
, mask
->ip_ttl
);
463 uint8_t flags_mask
= 0;
465 if (mask
->flags
& TCA_FLOWER_KEY_FLAGS_IS_FRAGMENT
) {
466 if (key
->flags
& TCA_FLOWER_KEY_FLAGS_IS_FRAGMENT
) {
467 flags
|= FLOW_NW_FRAG_ANY
;
469 flags_mask
|= FLOW_NW_FRAG_ANY
;
472 if (mask
->flags
& TCA_FLOWER_KEY_FLAGS_FRAG_IS_FIRST
) {
473 if (!(key
->flags
& TCA_FLOWER_KEY_FLAGS_FRAG_IS_FIRST
)) {
474 flags
|= FLOW_NW_FRAG_LATER
;
476 flags_mask
|= FLOW_NW_FRAG_LATER
;
479 match_set_nw_frag_masked(match
, flags
, flags_mask
);
482 match_set_nw_src_masked(match
, key
->ipv4
.ipv4_src
, mask
->ipv4
.ipv4_src
);
483 match_set_nw_dst_masked(match
, key
->ipv4
.ipv4_dst
, mask
->ipv4
.ipv4_dst
);
485 match_set_ipv6_src_masked(match
,
486 &key
->ipv6
.ipv6_src
, &mask
->ipv6
.ipv6_src
);
487 match_set_ipv6_dst_masked(match
,
488 &key
->ipv6
.ipv6_dst
, &mask
->ipv6
.ipv6_dst
);
490 if (key
->ip_proto
== IPPROTO_TCP
) {
491 match_set_tp_dst_masked(match
, key
->tcp_dst
, mask
->tcp_dst
);
492 match_set_tp_src_masked(match
, key
->tcp_src
, mask
->tcp_src
);
493 match_set_tcp_flags_masked(match
, key
->tcp_flags
, mask
->tcp_flags
);
494 } else if (key
->ip_proto
== IPPROTO_UDP
) {
495 match_set_tp_dst_masked(match
, key
->udp_dst
, mask
->udp_dst
);
496 match_set_tp_src_masked(match
, key
->udp_src
, mask
->udp_src
);
497 } else if (key
->ip_proto
== IPPROTO_SCTP
) {
498 match_set_tp_dst_masked(match
, key
->sctp_dst
, mask
->sctp_dst
);
499 match_set_tp_src_masked(match
, key
->sctp_src
, mask
->sctp_src
);
503 if (flower
->tunnel
) {
504 match_set_tun_id(match
, flower
->key
.tunnel
.id
);
505 if (flower
->key
.tunnel
.ipv4
.ipv4_dst
) {
506 match_set_tun_src(match
, flower
->key
.tunnel
.ipv4
.ipv4_src
);
507 match_set_tun_dst(match
, flower
->key
.tunnel
.ipv4
.ipv4_dst
);
508 } else if (!is_all_zeros(&flower
->key
.tunnel
.ipv6
.ipv6_dst
,
509 sizeof flower
->key
.tunnel
.ipv6
.ipv6_dst
)) {
510 match_set_tun_ipv6_src(match
, &flower
->key
.tunnel
.ipv6
.ipv6_src
);
511 match_set_tun_ipv6_dst(match
, &flower
->key
.tunnel
.ipv6
.ipv6_dst
);
513 if (flower
->key
.tunnel
.tos
) {
514 match_set_tun_tos(match
, flower
->key
.tunnel
.tos
);
516 if (flower
->key
.tunnel
.ttl
) {
517 match_set_tun_ttl(match
, flower
->key
.tunnel
.ttl
);
519 if (flower
->key
.tunnel
.tp_dst
) {
520 match_set_tun_tp_dst(match
, flower
->key
.tunnel
.tp_dst
);
524 act_off
= nl_msg_start_nested(buf
, OVS_FLOW_ATTR_ACTIONS
);
526 action
= flower
->actions
;
527 for (i
= 0; i
< flower
->action_count
; i
++, action
++) {
528 switch (action
->type
) {
529 case TC_ACT_VLAN_POP
: {
530 nl_msg_put_flag(buf
, OVS_ACTION_ATTR_POP_VLAN
);
533 case TC_ACT_VLAN_PUSH
: {
534 struct ovs_action_push_vlan
*push
;
536 push
= nl_msg_put_unspec_zero(buf
, OVS_ACTION_ATTR_PUSH_VLAN
,
538 push
->vlan_tpid
= action
->vlan
.vlan_push_tpid
;
539 push
->vlan_tci
= htons(action
->vlan
.vlan_push_id
540 | (action
->vlan
.vlan_push_prio
<< 13)
545 parse_flower_rewrite_to_netlink_action(buf
, flower
);
549 size_t set_offset
= nl_msg_start_nested(buf
, OVS_ACTION_ATTR_SET
);
550 size_t tunnel_offset
=
551 nl_msg_start_nested(buf
, OVS_KEY_ATTR_TUNNEL
);
553 nl_msg_put_be64(buf
, OVS_TUNNEL_KEY_ATTR_ID
, action
->encap
.id
);
554 if (action
->encap
.ipv4
.ipv4_src
) {
555 nl_msg_put_be32(buf
, OVS_TUNNEL_KEY_ATTR_IPV4_SRC
,
556 action
->encap
.ipv4
.ipv4_src
);
558 if (action
->encap
.ipv4
.ipv4_dst
) {
559 nl_msg_put_be32(buf
, OVS_TUNNEL_KEY_ATTR_IPV4_DST
,
560 action
->encap
.ipv4
.ipv4_dst
);
562 if (!is_all_zeros(&action
->encap
.ipv6
.ipv6_src
,
563 sizeof action
->encap
.ipv6
.ipv6_src
)) {
564 nl_msg_put_in6_addr(buf
, OVS_TUNNEL_KEY_ATTR_IPV6_SRC
,
565 &action
->encap
.ipv6
.ipv6_src
);
567 if (!is_all_zeros(&action
->encap
.ipv6
.ipv6_dst
,
568 sizeof action
->encap
.ipv6
.ipv6_dst
)) {
569 nl_msg_put_in6_addr(buf
, OVS_TUNNEL_KEY_ATTR_IPV6_DST
,
570 &action
->encap
.ipv6
.ipv6_dst
);
572 if (action
->encap
.tos
) {
573 nl_msg_put_u8(buf
, OVS_TUNNEL_KEY_ATTR_TOS
,
576 if (action
->encap
.ttl
) {
577 nl_msg_put_u8(buf
, OVS_TUNNEL_KEY_ATTR_TTL
,
580 nl_msg_put_be16(buf
, OVS_TUNNEL_KEY_ATTR_TP_DST
,
581 action
->encap
.tp_dst
);
583 nl_msg_end_nested(buf
, tunnel_offset
);
584 nl_msg_end_nested(buf
, set_offset
);
587 case TC_ACT_OUTPUT
: {
588 if (action
->ifindex_out
) {
589 outport
= netdev_ifindex_to_odp_port(action
->ifindex_out
);
594 nl_msg_put_u32(buf
, OVS_ACTION_ATTR_OUTPUT
, odp_to_u32(outport
));
600 nl_msg_end_nested(buf
, act_off
);
602 *actions
= ofpbuf_at_assert(buf
, act_off
, sizeof(struct nlattr
));
605 memset(stats
, 0, sizeof *stats
);
606 stats
->n_packets
= get_32aligned_u64(&flower
->stats
.n_packets
);
607 stats
->n_bytes
= get_32aligned_u64(&flower
->stats
.n_bytes
);
608 stats
->used
= flower
->lastused
;
611 attrs
->offloaded
= (flower
->offloaded_state
== TC_OFFLOADED_STATE_IN_HW
)
612 || (flower
->offloaded_state
== TC_OFFLOADED_STATE_UNDEFINED
);
613 attrs
->dp_layer
= "tc";
619 netdev_tc_flow_dump_next(struct netdev_flow_dump
*dump
,
621 struct nlattr
**actions
,
622 struct dpif_flow_stats
*stats
,
623 struct dpif_flow_attrs
*attrs
,
625 struct ofpbuf
*rbuffer
,
626 struct ofpbuf
*wbuffer
)
628 struct ofpbuf nl_flow
;
630 while (nl_dump_next(dump
->nl_dump
, &nl_flow
, rbuffer
)) {
631 struct tc_flower flower
;
632 struct netdev
*netdev
= dump
->netdev
;
634 if (parse_netlink_to_tc_flower(&nl_flow
, &flower
)) {
638 if (parse_tc_flower_to_match(&flower
, match
, actions
, stats
, attrs
,
643 if (flower
.act_cookie
.len
) {
644 *ufid
= *((ovs_u128
*) flower
.act_cookie
.data
);
645 } else if (!find_ufid(flower
.prio
, flower
.handle
, netdev
, ufid
)) {
649 match
->wc
.masks
.in_port
.odp_port
= u32_to_odp(UINT32_MAX
);
650 match
->flow
.in_port
.odp_port
= dump
->port
;
659 parse_put_flow_set_masked_action(struct tc_flower
*flower
,
660 struct tc_action
*action
,
661 const struct nlattr
*set
,
665 static struct vlog_rate_limit rl
= VLOG_RATE_LIMIT_INIT(5, 20);
666 uint64_t set_stub
[1024 / 8];
667 struct ofpbuf set_buf
= OFPBUF_STUB_INITIALIZER(set_stub
);
668 char *set_data
, *set_mask
;
669 char *key
= (char *) &flower
->rewrite
.key
;
670 char *mask
= (char *) &flower
->rewrite
.mask
;
671 const struct nlattr
*attr
;
675 /* copy so we can set attr mask to 0 for used ovs key struct members */
676 attr
= ofpbuf_put(&set_buf
, set
, set_len
);
678 type
= nl_attr_type(attr
);
679 size
= nl_attr_get_size(attr
) / 2;
680 set_data
= CONST_CAST(char *, nl_attr_get(attr
));
681 set_mask
= set_data
+ size
;
683 if (type
>= ARRAY_SIZE(set_flower_map
)
684 || !set_flower_map
[type
][0].size
) {
685 VLOG_DBG_RL(&rl
, "unsupported set action type: %d", type
);
686 ofpbuf_uninit(&set_buf
);
690 for (i
= 0; i
< ARRAY_SIZE(set_flower_map
[type
]); i
++) {
691 struct netlink_field
*f
= &set_flower_map
[type
][i
];
697 /* copy masked value */
698 for (j
= 0; j
< f
->size
; j
++) {
699 char maskval
= hasmask
? set_mask
[f
->offset
+ j
] : 0xFF;
701 key
[f
->flower_offset
+ j
] = maskval
& set_data
[f
->offset
+ j
];
702 mask
[f
->flower_offset
+ j
] = maskval
;
706 /* set its mask to 0 to show it's been used. */
708 memset(set_mask
+ f
->offset
, 0, f
->size
);
712 if (!is_all_zeros(&flower
->rewrite
, sizeof flower
->rewrite
)) {
713 if (flower
->rewrite
.rewrite
== false) {
714 flower
->rewrite
.rewrite
= true;
715 action
->type
= TC_ACT_PEDIT
;
716 flower
->action_count
++;
720 if (hasmask
&& !is_all_zeros(set_mask
, size
)) {
721 VLOG_DBG_RL(&rl
, "unsupported sub attribute of set action type %d",
723 ofpbuf_uninit(&set_buf
);
727 ofpbuf_uninit(&set_buf
);
732 parse_put_flow_set_action(struct tc_flower
*flower
, struct tc_action
*action
,
733 const struct nlattr
*set
, size_t set_len
)
735 const struct nlattr
*tunnel
;
736 const struct nlattr
*tun_attr
;
737 size_t tun_left
, tunnel_len
;
739 if (nl_attr_type(set
) != OVS_KEY_ATTR_TUNNEL
) {
740 return parse_put_flow_set_masked_action(flower
, action
, set
,
744 tunnel
= nl_attr_get(set
);
745 tunnel_len
= nl_attr_get_size(set
);
747 action
->type
= TC_ACT_ENCAP
;
748 flower
->action_count
++;
749 NL_ATTR_FOR_EACH_UNSAFE(tun_attr
, tun_left
, tunnel
, tunnel_len
) {
750 switch (nl_attr_type(tun_attr
)) {
751 case OVS_TUNNEL_KEY_ATTR_ID
: {
752 action
->encap
.id
= nl_attr_get_be64(tun_attr
);
755 case OVS_TUNNEL_KEY_ATTR_IPV4_SRC
: {
756 action
->encap
.ipv4
.ipv4_src
= nl_attr_get_be32(tun_attr
);
759 case OVS_TUNNEL_KEY_ATTR_IPV4_DST
: {
760 action
->encap
.ipv4
.ipv4_dst
= nl_attr_get_be32(tun_attr
);
763 case OVS_TUNNEL_KEY_ATTR_TOS
: {
764 action
->encap
.tos
= nl_attr_get_u8(tun_attr
);
767 case OVS_TUNNEL_KEY_ATTR_TTL
: {
768 action
->encap
.ttl
= nl_attr_get_u8(tun_attr
);
771 case OVS_TUNNEL_KEY_ATTR_IPV6_SRC
: {
772 action
->encap
.ipv6
.ipv6_src
=
773 nl_attr_get_in6_addr(tun_attr
);
776 case OVS_TUNNEL_KEY_ATTR_IPV6_DST
: {
777 action
->encap
.ipv6
.ipv6_dst
=
778 nl_attr_get_in6_addr(tun_attr
);
781 case OVS_TUNNEL_KEY_ATTR_TP_SRC
: {
782 action
->encap
.tp_src
= nl_attr_get_be16(tun_attr
);
785 case OVS_TUNNEL_KEY_ATTR_TP_DST
: {
786 action
->encap
.tp_dst
= nl_attr_get_be16(tun_attr
);
796 test_key_and_mask(struct match
*match
)
798 static struct vlog_rate_limit rl
= VLOG_RATE_LIMIT_INIT(5, 20);
799 const struct flow
*key
= &match
->flow
;
800 struct flow
*mask
= &match
->wc
.masks
;
802 if (mask
->pkt_mark
) {
803 VLOG_DBG_RL(&rl
, "offloading attribute pkt_mark isn't supported");
807 if (mask
->recirc_id
&& key
->recirc_id
) {
808 VLOG_DBG_RL(&rl
, "offloading attribute recirc_id isn't supported");
814 VLOG_DBG_RL(&rl
, "offloading attribute dp_hash isn't supported");
819 VLOG_DBG_RL(&rl
, "offloading attribute conj_id isn't supported");
823 if (mask
->skb_priority
) {
824 VLOG_DBG_RL(&rl
, "offloading attribute skb_priority isn't supported");
828 if (mask
->actset_output
) {
830 "offloading attribute actset_output isn't supported");
834 if (mask
->ct_state
) {
835 VLOG_DBG_RL(&rl
, "offloading attribute ct_state isn't supported");
840 VLOG_DBG_RL(&rl
, "offloading attribute ct_zone isn't supported");
845 VLOG_DBG_RL(&rl
, "offloading attribute ct_mark isn't supported");
849 if (mask
->packet_type
&& key
->packet_type
) {
850 VLOG_DBG_RL(&rl
, "offloading attribute packet_type isn't supported");
853 mask
->packet_type
= 0;
855 if (!ovs_u128_is_zero(mask
->ct_label
)) {
856 VLOG_DBG_RL(&rl
, "offloading attribute ct_label isn't supported");
860 for (int i
= 0; i
< FLOW_N_REGS
; i
++) {
863 "offloading attribute regs[%d] isn't supported", i
);
868 if (mask
->metadata
) {
869 VLOG_DBG_RL(&rl
, "offloading attribute metadata isn't supported");
874 VLOG_DBG_RL(&rl
, "offloading attribute nw_tos isn't supported");
878 for (int i
= 0; i
< FLOW_MAX_MPLS_LABELS
; i
++) {
879 if (mask
->mpls_lse
[i
]) {
880 VLOG_DBG_RL(&rl
, "offloading attribute mpls_lse isn't supported");
885 if (key
->dl_type
== htons(ETH_TYPE_IP
) &&
886 key
->nw_proto
== IPPROTO_ICMP
) {
889 "offloading attribute icmp_type isn't supported");
894 "offloading attribute icmp_code isn't supported");
897 } else if (key
->dl_type
== htons(ETH_TYPE_IP
) &&
898 key
->nw_proto
== IPPROTO_IGMP
) {
901 "offloading attribute igmp_type isn't supported");
906 "offloading attribute igmp_code isn't supported");
909 } else if (key
->dl_type
== htons(ETH_TYPE_IPV6
) &&
910 key
->nw_proto
== IPPROTO_ICMPV6
) {
913 "offloading attribute icmp_type isn't supported");
918 "offloading attribute icmp_code isn't supported");
923 if (!is_all_zeros(mask
, sizeof *mask
)) {
924 VLOG_DBG_RL(&rl
, "offloading isn't supported, unknown attribute");
932 netdev_tc_flow_put(struct netdev
*netdev
, struct match
*match
,
933 struct nlattr
*actions
, size_t actions_len
,
934 const ovs_u128
*ufid
, struct offload_info
*info
,
935 struct dpif_flow_stats
*stats OVS_UNUSED
)
937 static struct vlog_rate_limit rl
= VLOG_RATE_LIMIT_INIT(5, 20);
938 struct tc_flower flower
;
939 const struct flow
*key
= &match
->flow
;
940 struct flow
*mask
= &match
->wc
.masks
;
941 const struct flow_tnl
*tnl
= &match
->flow
.tunnel
;
942 struct tc_action
*action
;
943 uint32_t block_id
= 0;
951 ifindex
= netdev_get_ifindex(netdev
);
953 VLOG_ERR_RL(&error_rl
, "flow_put: failed to get ifindex for %s: %s",
954 netdev_get_name(netdev
), ovs_strerror(-ifindex
));
958 memset(&flower
, 0, sizeof flower
);
960 if (flow_tnl_dst_is_set(&key
->tunnel
)) {
962 "tunnel: id %#" PRIx64
" src " IP_FMT
963 " dst " IP_FMT
" tp_src %d tp_dst %d",
965 IP_ARGS(tnl
->ip_src
), IP_ARGS(tnl
->ip_dst
),
966 ntohs(tnl
->tp_src
), ntohs(tnl
->tp_dst
));
967 flower
.key
.tunnel
.id
= tnl
->tun_id
;
968 flower
.key
.tunnel
.ipv4
.ipv4_src
= tnl
->ip_src
;
969 flower
.key
.tunnel
.ipv4
.ipv4_dst
= tnl
->ip_dst
;
970 flower
.key
.tunnel
.ipv6
.ipv6_src
= tnl
->ipv6_src
;
971 flower
.key
.tunnel
.ipv6
.ipv6_dst
= tnl
->ipv6_dst
;
972 flower
.key
.tunnel
.tos
= tnl
->ip_tos
;
973 flower
.key
.tunnel
.ttl
= tnl
->ip_ttl
;
974 flower
.key
.tunnel
.tp_src
= tnl
->tp_src
;
975 flower
.key
.tunnel
.tp_dst
= tnl
->tp_dst
;
976 flower
.tunnel
= true;
978 memset(&mask
->tunnel
, 0, sizeof mask
->tunnel
);
980 flower
.key
.eth_type
= key
->dl_type
;
981 flower
.mask
.eth_type
= mask
->dl_type
;
983 if (mask
->vlans
[0].tci
) {
984 ovs_be16 vid_mask
= mask
->vlans
[0].tci
& htons(VLAN_VID_MASK
);
985 ovs_be16 pcp_mask
= mask
->vlans
[0].tci
& htons(VLAN_PCP_MASK
);
986 ovs_be16 cfi
= mask
->vlans
[0].tci
& htons(VLAN_CFI
);
988 if (cfi
&& key
->vlans
[0].tci
& htons(VLAN_CFI
)
989 && (!vid_mask
|| vid_mask
== htons(VLAN_VID_MASK
))
990 && (!pcp_mask
|| pcp_mask
== htons(VLAN_PCP_MASK
))
991 && (vid_mask
|| pcp_mask
)) {
993 flower
.key
.vlan_id
[0] = vlan_tci_to_vid(key
->vlans
[0].tci
);
994 VLOG_DBG_RL(&rl
, "vlan_id[0]: %d\n", flower
.key
.vlan_id
[0]);
997 flower
.key
.vlan_prio
[0] = vlan_tci_to_pcp(key
->vlans
[0].tci
);
998 VLOG_DBG_RL(&rl
, "vlan_prio[0]: %d\n",
999 flower
.key
.vlan_prio
[0]);
1001 flower
.key
.encap_eth_type
[0] = flower
.key
.eth_type
;
1002 flower
.key
.eth_type
= key
->vlans
[0].tpid
;
1003 } else if (mask
->vlans
[0].tci
== htons(0xffff) &&
1004 ntohs(key
->vlans
[0].tci
) == 0) {
1005 /* exact && no vlan */
1012 if (mask
->vlans
[1].tci
) {
1013 ovs_be16 vid_mask
= mask
->vlans
[1].tci
& htons(VLAN_VID_MASK
);
1014 ovs_be16 pcp_mask
= mask
->vlans
[1].tci
& htons(VLAN_PCP_MASK
);
1015 ovs_be16 cfi
= mask
->vlans
[1].tci
& htons(VLAN_CFI
);
1017 if (cfi
&& key
->vlans
[1].tci
& htons(VLAN_CFI
)
1018 && (!vid_mask
|| vid_mask
== htons(VLAN_VID_MASK
))
1019 && (!pcp_mask
|| pcp_mask
== htons(VLAN_PCP_MASK
))
1020 && (vid_mask
|| pcp_mask
)) {
1022 flower
.key
.vlan_id
[1] = vlan_tci_to_vid(key
->vlans
[1].tci
);
1023 VLOG_DBG_RL(&rl
, "vlan_id[1]: %d", flower
.key
.vlan_id
[1]);
1026 flower
.key
.vlan_prio
[1] = vlan_tci_to_pcp(key
->vlans
[1].tci
);
1027 VLOG_DBG_RL(&rl
, "vlan_prio[1]: %d", flower
.key
.vlan_prio
[1]);
1029 flower
.key
.encap_eth_type
[1] = flower
.key
.encap_eth_type
[0];
1030 flower
.key
.encap_eth_type
[0] = key
->vlans
[1].tpid
;
1031 } else if (mask
->vlans
[1].tci
== htons(0xffff) &&
1032 ntohs(key
->vlans
[1].tci
) == 0) {
1033 /* exact && no vlan */
1039 memset(mask
->vlans
, 0, sizeof mask
->vlans
);
1041 flower
.key
.dst_mac
= key
->dl_dst
;
1042 flower
.mask
.dst_mac
= mask
->dl_dst
;
1043 flower
.key
.src_mac
= key
->dl_src
;
1044 flower
.mask
.src_mac
= mask
->dl_src
;
1045 memset(&mask
->dl_dst
, 0, sizeof mask
->dl_dst
);
1046 memset(&mask
->dl_src
, 0, sizeof mask
->dl_src
);
1048 mask
->in_port
.odp_port
= 0;
1050 if (is_ip_any(key
)) {
1051 flower
.key
.ip_proto
= key
->nw_proto
;
1052 flower
.mask
.ip_proto
= mask
->nw_proto
;
1054 flower
.key
.ip_tos
= key
->nw_tos
;
1055 flower
.mask
.ip_tos
= mask
->nw_tos
;
1057 flower
.key
.ip_ttl
= key
->nw_ttl
;
1058 flower
.mask
.ip_ttl
= mask
->nw_ttl
;
1061 if (mask
->nw_frag
& FLOW_NW_FRAG_ANY
) {
1062 flower
.mask
.flags
|= TCA_FLOWER_KEY_FLAGS_IS_FRAGMENT
;
1064 if (key
->nw_frag
& FLOW_NW_FRAG_ANY
) {
1065 flower
.key
.flags
|= TCA_FLOWER_KEY_FLAGS_IS_FRAGMENT
;
1067 if (mask
->nw_frag
& FLOW_NW_FRAG_LATER
) {
1068 flower
.mask
.flags
|= TCA_FLOWER_KEY_FLAGS_FRAG_IS_FIRST
;
1070 if (!(key
->nw_frag
& FLOW_NW_FRAG_LATER
)) {
1071 flower
.key
.flags
|= TCA_FLOWER_KEY_FLAGS_FRAG_IS_FIRST
;
1079 if (key
->nw_proto
== IPPROTO_TCP
) {
1080 flower
.key
.tcp_dst
= key
->tp_dst
;
1081 flower
.mask
.tcp_dst
= mask
->tp_dst
;
1082 flower
.key
.tcp_src
= key
->tp_src
;
1083 flower
.mask
.tcp_src
= mask
->tp_src
;
1084 flower
.key
.tcp_flags
= key
->tcp_flags
;
1085 flower
.mask
.tcp_flags
= mask
->tcp_flags
;
1088 mask
->tcp_flags
= 0;
1089 } else if (key
->nw_proto
== IPPROTO_UDP
) {
1090 flower
.key
.udp_dst
= key
->tp_dst
;
1091 flower
.mask
.udp_dst
= mask
->tp_dst
;
1092 flower
.key
.udp_src
= key
->tp_src
;
1093 flower
.mask
.udp_src
= mask
->tp_src
;
1096 } else if (key
->nw_proto
== IPPROTO_SCTP
) {
1097 flower
.key
.sctp_dst
= key
->tp_dst
;
1098 flower
.mask
.sctp_dst
= mask
->tp_dst
;
1099 flower
.key
.sctp_src
= key
->tp_src
;
1100 flower
.mask
.sctp_src
= mask
->tp_src
;
1105 if (key
->dl_type
== htons(ETH_P_IP
)) {
1106 flower
.key
.ipv4
.ipv4_src
= key
->nw_src
;
1107 flower
.mask
.ipv4
.ipv4_src
= mask
->nw_src
;
1108 flower
.key
.ipv4
.ipv4_dst
= key
->nw_dst
;
1109 flower
.mask
.ipv4
.ipv4_dst
= mask
->nw_dst
;
1112 } else if (key
->dl_type
== htons(ETH_P_IPV6
)) {
1113 flower
.key
.ipv6
.ipv6_src
= key
->ipv6_src
;
1114 flower
.mask
.ipv6
.ipv6_src
= mask
->ipv6_src
;
1115 flower
.key
.ipv6
.ipv6_dst
= key
->ipv6_dst
;
1116 flower
.mask
.ipv6
.ipv6_dst
= mask
->ipv6_dst
;
1117 memset(&mask
->ipv6_src
, 0, sizeof mask
->ipv6_src
);
1118 memset(&mask
->ipv6_dst
, 0, sizeof mask
->ipv6_dst
);
1122 err
= test_key_and_mask(match
);
1127 NL_ATTR_FOR_EACH(nla
, left
, actions
, actions_len
) {
1128 if (flower
.action_count
>= TCA_ACT_MAX_PRIO
) {
1129 VLOG_DBG_RL(&rl
, "Can only support %d actions", flower
.action_count
);
1132 action
= &flower
.actions
[flower
.action_count
];
1133 if (nl_attr_type(nla
) == OVS_ACTION_ATTR_OUTPUT
) {
1134 odp_port_t port
= nl_attr_get_odp_port(nla
);
1135 struct netdev
*outdev
= netdev_ports_get(port
, info
->dpif_class
);
1137 action
->ifindex_out
= netdev_get_ifindex(outdev
);
1138 action
->type
= TC_ACT_OUTPUT
;
1139 flower
.action_count
++;
1140 netdev_close(outdev
);
1141 } else if (nl_attr_type(nla
) == OVS_ACTION_ATTR_PUSH_VLAN
) {
1142 const struct ovs_action_push_vlan
*vlan_push
= nl_attr_get(nla
);
1144 action
->vlan
.vlan_push_tpid
= vlan_push
->vlan_tpid
;
1145 action
->vlan
.vlan_push_id
= vlan_tci_to_vid(vlan_push
->vlan_tci
);
1146 action
->vlan
.vlan_push_prio
= vlan_tci_to_pcp(vlan_push
->vlan_tci
);
1147 action
->type
= TC_ACT_VLAN_PUSH
;
1148 flower
.action_count
++;
1149 } else if (nl_attr_type(nla
) == OVS_ACTION_ATTR_POP_VLAN
) {
1150 action
->type
= TC_ACT_VLAN_POP
;
1151 flower
.action_count
++;
1152 } else if (nl_attr_type(nla
) == OVS_ACTION_ATTR_SET
) {
1153 const struct nlattr
*set
= nl_attr_get(nla
);
1154 const size_t set_len
= nl_attr_get_size(nla
);
1156 err
= parse_put_flow_set_action(&flower
, action
, set
, set_len
);
1160 if (action
->type
== TC_ACT_ENCAP
) {
1161 action
->encap
.tp_dst
= info
->tp_dst_port
;
1163 } else if (nl_attr_type(nla
) == OVS_ACTION_ATTR_SET_MASKED
) {
1164 const struct nlattr
*set
= nl_attr_get(nla
);
1165 const size_t set_len
= nl_attr_get_size(nla
);
1167 err
= parse_put_flow_set_masked_action(&flower
, action
, set
,
1173 VLOG_DBG_RL(&rl
, "unsupported put action type: %d",
1179 block_id
= get_block_id_from_netdev(netdev
);
1180 handle
= get_ufid_tc_mapping(ufid
, &prio
, NULL
);
1181 if (handle
&& prio
) {
1182 VLOG_DBG_RL(&rl
, "updating old handle: %d prio: %d", handle
, prio
);
1183 tc_del_filter(ifindex
, prio
, handle
, block_id
);
1187 prio
= get_prio_for_tc_flower(&flower
);
1189 VLOG_ERR_RL(&rl
, "couldn't get tc prio: %s", ovs_strerror(ENOSPC
));
1194 flower
.act_cookie
.data
= ufid
;
1195 flower
.act_cookie
.len
= sizeof *ufid
;
1197 err
= tc_replace_flower(ifindex
, prio
, handle
, &flower
, block_id
);
1199 add_ufid_tc_mapping(ufid
, flower
.prio
, flower
.handle
, netdev
, ifindex
);
1206 netdev_tc_flow_get(struct netdev
*netdev OVS_UNUSED
,
1207 struct match
*match
,
1208 struct nlattr
**actions
,
1209 const ovs_u128
*ufid
,
1210 struct dpif_flow_stats
*stats
,
1211 struct dpif_flow_attrs
*attrs
,
1214 static struct vlog_rate_limit rl
= VLOG_RATE_LIMIT_INIT(5, 20);
1216 struct tc_flower flower
;
1217 uint32_t block_id
= 0;
1224 handle
= get_ufid_tc_mapping(ufid
, &prio
, &dev
);
1229 ifindex
= netdev_get_ifindex(dev
);
1231 VLOG_ERR_RL(&error_rl
, "flow_get: failed to get ifindex for %s: %s",
1232 netdev_get_name(dev
), ovs_strerror(-ifindex
));
1237 VLOG_DBG_RL(&rl
, "flow get (dev %s prio %d handle %d)",
1238 netdev_get_name(dev
), prio
, handle
);
1239 block_id
= get_block_id_from_netdev(netdev
);
1240 err
= tc_get_flower(ifindex
, prio
, handle
, &flower
, block_id
);
1243 VLOG_ERR_RL(&error_rl
, "flow get failed (dev %s prio %d handle %d): %s",
1244 netdev_get_name(dev
), prio
, handle
, ovs_strerror(err
));
1248 in_port
= netdev_ifindex_to_odp_port(ifindex
);
1249 parse_tc_flower_to_match(&flower
, match
, actions
, stats
, attrs
, buf
);
1251 match
->wc
.masks
.in_port
.odp_port
= u32_to_odp(UINT32_MAX
);
1252 match
->flow
.in_port
.odp_port
= in_port
;
1258 netdev_tc_flow_del(struct netdev
*netdev OVS_UNUSED
,
1259 const ovs_u128
*ufid
,
1260 struct dpif_flow_stats
*stats
)
1262 struct tc_flower flower
;
1263 uint32_t block_id
= 0;
1270 handle
= get_ufid_tc_mapping(ufid
, &prio
, &dev
);
1275 ifindex
= netdev_get_ifindex(dev
);
1277 VLOG_ERR_RL(&error_rl
, "flow_del: failed to get ifindex for %s: %s",
1278 netdev_get_name(dev
), ovs_strerror(-ifindex
));
1283 block_id
= get_block_id_from_netdev(netdev
);
1286 memset(stats
, 0, sizeof *stats
);
1287 if (!tc_get_flower(ifindex
, prio
, handle
, &flower
, block_id
)) {
1288 stats
->n_packets
= get_32aligned_u64(&flower
.stats
.n_packets
);
1289 stats
->n_bytes
= get_32aligned_u64(&flower
.stats
.n_bytes
);
1290 stats
->used
= flower
.lastused
;
1294 error
= tc_del_filter(ifindex
, prio
, handle
, block_id
);
1295 del_ufid_tc_mapping(ufid
);
1303 probe_multi_mask_per_prio(int ifindex
)
1305 struct tc_flower flower
;
1309 error
= tc_add_del_ingress_qdisc(ifindex
, true, block_id
);
1314 memset(&flower
, 0, sizeof flower
);
1316 flower
.key
.eth_type
= htons(ETH_P_IP
);
1317 flower
.mask
.eth_type
= OVS_BE16_MAX
;
1318 memset(&flower
.key
.dst_mac
, 0x11, sizeof flower
.key
.dst_mac
);
1319 memset(&flower
.mask
.dst_mac
, 0xff, sizeof flower
.mask
.dst_mac
);
1321 error
= tc_replace_flower(ifindex
, 1, 1, &flower
, block_id
);
1326 memset(&flower
.key
.src_mac
, 0x11, sizeof flower
.key
.src_mac
);
1327 memset(&flower
.mask
.src_mac
, 0xff, sizeof flower
.mask
.src_mac
);
1329 error
= tc_replace_flower(ifindex
, 1, 2, &flower
, block_id
);
1330 tc_del_filter(ifindex
, 1, 1, block_id
);
1336 tc_del_filter(ifindex
, 1, 2, block_id
);
1338 multi_mask_per_prio
= true;
1339 VLOG_INFO("probe tc: multiple masks on single tc prio is supported.");
1342 tc_add_del_ingress_qdisc(ifindex
, false, block_id
);
1346 probe_tc_block_support(int ifindex
)
1348 uint32_t block_id
= 1;
1351 error
= tc_add_del_ingress_qdisc(ifindex
, true, block_id
);
1356 tc_add_del_ingress_qdisc(ifindex
, false, block_id
);
1358 block_support
= true;
1359 VLOG_INFO("probe tc: block offload is supported.");
1363 netdev_tc_init_flow_api(struct netdev
*netdev
)
1365 static struct ovsthread_once multi_mask_once
= OVSTHREAD_ONCE_INITIALIZER
;
1366 static struct ovsthread_once block_once
= OVSTHREAD_ONCE_INITIALIZER
;
1367 uint32_t block_id
= 0;
1371 ifindex
= netdev_get_ifindex(netdev
);
1373 VLOG_ERR_RL(&error_rl
, "init: failed to get ifindex for %s: %s",
1374 netdev_get_name(netdev
), ovs_strerror(-ifindex
));
1378 if (ovsthread_once_start(&block_once
)) {
1379 probe_tc_block_support(ifindex
);
1380 ovsthread_once_done(&block_once
);
1383 if (ovsthread_once_start(&multi_mask_once
)) {
1384 probe_multi_mask_per_prio(ifindex
);
1385 ovsthread_once_done(&multi_mask_once
);
1388 block_id
= get_block_id_from_netdev(netdev
);
1389 error
= tc_add_del_ingress_qdisc(ifindex
, true, block_id
);
1391 if (error
&& error
!= EEXIST
) {
1392 VLOG_ERR("failed adding ingress qdisc required for offloading: %s",
1393 ovs_strerror(error
));
1397 VLOG_INFO("added ingress qdisc to %s", netdev_get_name(netdev
));