31 #define FLOW_IS_L2_LAYER(f) \ 32 (f->type == VNET_FLOW_TYPE_ETHERNET) 35 #define FLOW_IS_VLAN_TAGGED(f) \ 36 ((f->type == VNET_FLOW_TYPE_IP4_N_TUPLE_TAGGED) || \ 37 (f->type == VNET_FLOW_TYPE_IP6_N_TUPLE_TAGGED)) 40 #define FLOW_IS_L4_LAYER(f) \ 41 ((f->type == VNET_FLOW_TYPE_IP4_N_TUPLE) || \ 42 (f->type == VNET_FLOW_TYPE_IP6_N_TUPLE)) 45 #define FLOW_IS_L4_TUNNEL_LAYER(f) \ 46 ((f->type >= VNET_FLOW_TYPE_IP4_VXLAN) || \ 47 (f->type <= VNET_FLOW_TYPE_IP6_GTPU_IP6)) 50 static const struct rte_flow_attr
ingress = {.ingress = 1 };
57 for (i = 0; i < 6; i++)
67 #define BIT_IS_SET(v, b) \ 74 if (n != -1 && BIT_IS_SET(type, n)) \ 82 static inline enum rte_eth_hash_function
85 enum rte_eth_hash_function rss_func;
89 case VNET_RSS_FUNC_DEFAULT:
90 rss_func = RTE_ETH_HASH_FUNCTION_DEFAULT;
92 case VNET_RSS_FUNC_TOEPLITZ:
93 rss_func = RTE_ETH_HASH_FUNCTION_TOEPLITZ;
95 case VNET_RSS_FUNC_SIMPLE_XOR:
96 rss_func = RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
98 case VNET_RSS_FUNC_SYMMETRIC_TOEPLITZ:
99 rss_func = RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ;
102 rss_func = RTE_ETH_HASH_FUNCTION_MAX;
112 struct rte_flow_item_eth eth[2] = { };
113 struct rte_flow_item_ipv4 ip4[2] = { };
114 struct rte_flow_item_ipv4 inner_ip4[2] = { };
115 struct rte_flow_item_ipv6 ip6[2] = { };
116 struct rte_flow_item_ipv6 inner_ip6[2] = { };
117 struct rte_flow_item_udp udp[2] = { };
118 struct rte_flow_item_tcp tcp[2] = { };
119 struct rte_flow_item_gtp gtp[2] = { };
120 struct rte_flow_item_l2tpv3oip l2tp[2] = { };
121 struct rte_flow_action_mark mark = { 0 };
122 struct rte_flow_action_queue queue = { 0 };
123 struct rte_flow_action_rss rss = { 0 };
124 struct rte_flow_item *item, *items = 0;
125 struct rte_flow_action *
action, *actions = 0;
131 raw_sz =
sizeof (
struct rte_flow_item_raw)
136 struct rte_flow_item_raw item;
137 u8 val[raw_sz + vxlan_hdr_sz];
145 return VNET_FLOW_ERROR_NOT_SUPPORTED;
150 item->type = RTE_FLOW_ITEM_TYPE_ETH;
151 if (f->
type == VNET_FLOW_TYPE_ETHERNET)
153 vnet_flow_ethernet_t *te = &f->ethernet;
162 sizeof (eth[0].dst));
163 clib_memset (ð[1].dst, 0xFF,
sizeof (eth[1].dst));
169 sizeof (eth[0].src));
170 clib_memset (ð[1].src, 0xFF,
sizeof (eth[1].src));
173 if (te->eth_hdr.type)
175 eth[0].type = clib_host_to_net_u16 (te->eth_hdr.type);
176 eth[1].type = clib_host_to_net_u16 (0xFFFF);
180 item->mask = eth + 1;
191 item->type = RTE_FLOW_ITEM_TYPE_VLAN;
201 if (f->
type == VNET_FLOW_TYPE_IP4_L2TPV3OIP)
203 vnet_flow_ip4_l2tpv3oip_t *l2tp = &f->ip4_l2tpv3oip;
204 item->
type = RTE_FLOW_ITEM_TYPE_IPV4;
206 if (!l2tp->src_addr.mask.as_u32 && !l2tp->dst_addr.mask.as_u32)
213 ip4[0].hdr.src_addr = l2tp->src_addr.addr.as_u32;
214 ip4[1].hdr.src_addr = l2tp->src_addr.mask.as_u32;
215 ip4[0].hdr.dst_addr = l2tp->dst_addr.addr.as_u32;
216 ip4[1].hdr.dst_addr = l2tp->dst_addr.mask.as_u32;
218 item->mask = ip4 + 1;
220 protocol = l2tp->protocol;
222 else if ((f->
type == VNET_FLOW_TYPE_IP6_N_TUPLE) ||
223 (f->
type == VNET_FLOW_TYPE_IP6_GTPC) ||
224 (f->
type == VNET_FLOW_TYPE_IP6_GTPU) ||
225 (f->
type == VNET_FLOW_TYPE_IP6_GTPU_IP4) ||
226 (f->
type == VNET_FLOW_TYPE_IP6_GTPU_IP6))
228 vnet_flow_ip6_n_tuple_t *t6 = &f->ip6_n_tuple;
229 item->
type = RTE_FLOW_ITEM_TYPE_IPV6;
244 item->mask = ip6 + 1;
247 src_port = t6->src_port.port;
249 src_port_mask = t6->src_port.mask;
250 dst_port_mask = t6->dst_port.mask;
251 protocol = t6->protocol;
253 else if ((f->
type == VNET_FLOW_TYPE_IP4_N_TUPLE) ||
254 (f->
type == VNET_FLOW_TYPE_IP4_GTPC) ||
255 (f->
type == VNET_FLOW_TYPE_IP4_GTPU) ||
256 (f->
type == VNET_FLOW_TYPE_IP4_GTPU_IP4) ||
257 (f->
type == VNET_FLOW_TYPE_IP4_GTPU_IP6))
259 vnet_flow_ip4_n_tuple_t *t4 = &f->ip4_n_tuple;
260 item->
type = RTE_FLOW_ITEM_TYPE_IPV4;
262 if (!t4->src_addr.mask.as_u32 && !t4->dst_addr.mask.as_u32)
269 ip4[0].hdr.src_addr = t4->src_addr.addr.as_u32;
270 ip4[1].hdr.src_addr = t4->src_addr.mask.as_u32;
271 ip4[0].hdr.dst_addr = t4->dst_addr.addr.as_u32;
272 ip4[1].hdr.dst_addr = t4->dst_addr.mask.as_u32;
274 item->mask = ip4 + 1;
277 src_port = t4->src_port.port;
279 src_port_mask = t4->src_port.mask;
280 dst_port_mask = t4->dst_port.mask;
281 protocol = t4->protocol;
283 else if (f->
type == VNET_FLOW_TYPE_IP4_VXLAN)
285 vnet_flow_ip4_vxlan_t *v4 = &f->ip4_vxlan;
286 ip4[0].hdr.src_addr = v4->src_addr.as_u32;
287 ip4[1].hdr.src_addr = -1;
288 ip4[0].hdr.dst_addr = v4->dst_addr.as_u32;
289 ip4[1].hdr.dst_addr = -1;
290 item->
type = RTE_FLOW_ITEM_TYPE_IPV4;
292 item->mask = ip4 + 1;
298 protocol = IP_PROTOCOL_UDP;
302 rv = VNET_FLOW_ERROR_NOT_SUPPORTED;
307 if (protocol == IP_PROTOCOL_UDP)
310 item->type = RTE_FLOW_ITEM_TYPE_UDP;
312 if ((src_port_mask == 0) && (dst_port_mask == 0))
319 udp[0].hdr.src_port = clib_host_to_net_u16 (src_port);
320 udp[1].hdr.src_port = clib_host_to_net_u16 (src_port_mask);
321 udp[0].hdr.dst_port = clib_host_to_net_u16 (
dst_port);
322 udp[1].hdr.dst_port = clib_host_to_net_u16 (dst_port_mask);
324 item->mask = udp + 1;
327 else if (protocol == IP_PROTOCOL_TCP)
330 item->type = RTE_FLOW_ITEM_TYPE_TCP;
332 if ((src_port_mask == 0) && (dst_port_mask == 0))
339 tcp[0].hdr.src_port = clib_host_to_net_u16 (src_port);
340 tcp[1].hdr.src_port = clib_host_to_net_u16 (src_port_mask);
341 tcp[0].hdr.dst_port = clib_host_to_net_u16 (
dst_port);
342 tcp[1].hdr.dst_port = clib_host_to_net_u16 (dst_port_mask);
344 item->mask = tcp + 1;
347 else if (protocol == IP_PROTOCOL_RESERVED)
349 rv = VNET_FLOW_ERROR_NOT_SUPPORTED;
354 if (f->
type == VNET_FLOW_TYPE_IP4_L2TPV3OIP)
357 item->type = RTE_FLOW_ITEM_TYPE_L2TPV3OIP;
359 vnet_flow_ip4_l2tpv3oip_t *tl2tp = &f->ip4_l2tpv3oip;
360 l2tp[0].session_id = clib_host_to_net_u32 (tl2tp->session_id);
361 l2tp[1].session_id = ~0;
364 item->mask = l2tp + 1;
366 if (f->
type == VNET_FLOW_TYPE_IP4_VXLAN)
368 u32 vni = f->ip4_vxlan.vni;
371 .vni_reserved = clib_host_to_net_u32 (vni << 8)
375 .vni_reserved = clib_host_to_net_u32 (((
u32) - 1) << 8)
379 raw[0].item.relative = 1;
380 raw[0].item.length = vxlan_hdr_sz;
383 raw[0].item.pattern = raw[0].val + raw_sz;
385 raw[1].item.pattern = raw[1].val + raw_sz;
388 item->type = RTE_FLOW_ITEM_TYPE_RAW;
390 item->mask = raw + 1;
392 else if (f->
type == VNET_FLOW_TYPE_IP4_GTPC)
394 vnet_flow_ip4_gtpc_t *gc = &f->ip4_gtpc;
395 gtp[0].teid = clib_host_to_net_u32 (gc->teid);
399 item->type = RTE_FLOW_ITEM_TYPE_GTPC;
401 item->mask = gtp + 1;
403 else if (f->
type == VNET_FLOW_TYPE_IP4_GTPU)
405 vnet_flow_ip4_gtpu_t *gu = &f->ip4_gtpu;
406 gtp[0].teid = clib_host_to_net_u32 (gu->teid);
410 item->type = RTE_FLOW_ITEM_TYPE_GTPU;
412 item->mask = gtp + 1;
414 else if ((f->
type == VNET_FLOW_TYPE_IP4_GTPU_IP4) ||
415 (f->
type == VNET_FLOW_TYPE_IP4_GTPU_IP6))
417 vnet_flow_ip4_gtpu_t *gu = &f->ip4_gtpu;
418 gtp[0].teid = clib_host_to_net_u32 (gu->teid);
422 item->type = RTE_FLOW_ITEM_TYPE_GTPU;
424 item->mask = gtp + 1;
427 if (f->
type == VNET_FLOW_TYPE_IP4_GTPU_IP4)
430 item->type = RTE_FLOW_ITEM_TYPE_IPV4;
432 vnet_flow_ip4_gtpu_ip4_t *gu4 = &f->ip4_gtpu_ip4;
433 if (!gu4->inner_src_addr.mask.as_u32 &&
434 !gu4->inner_dst_addr.mask.as_u32)
441 inner_ip4[0].hdr.src_addr = gu4->inner_src_addr.addr.as_u32;
442 inner_ip4[1].hdr.src_addr = gu4->inner_src_addr.mask.as_u32;
443 inner_ip4[0].hdr.dst_addr = gu4->inner_dst_addr.addr.as_u32;
444 inner_ip4[1].hdr.dst_addr = gu4->inner_dst_addr.mask.as_u32;
445 item->spec = inner_ip4;
446 item->mask = inner_ip4 + 1;
449 else if (f->
type == VNET_FLOW_TYPE_IP4_GTPU_IP6)
452 vnet_flow_ip4_gtpu_ip6_t *gu6 = &f->ip4_gtpu_ip6;
454 clib_memset (&zero_addr, 0,
sizeof (ip6_address_t));
457 item->type = RTE_FLOW_ITEM_TYPE_IPV6;
459 if (!
clib_memcmp (&gu6->inner_src_addr.mask, &zero_addr, 16) &&
460 !
clib_memcmp (&gu6->inner_dst_addr.mask, &zero_addr, 16))
468 &gu6->inner_src_addr.addr, 16);
470 &gu6->inner_src_addr.mask, 16);
472 &gu6->inner_dst_addr.addr, 16);
474 &gu6->inner_dst_addr.mask, 16);
475 item->spec = inner_ip6;
476 item->mask = inner_ip6 + 1;
480 else if (f->
type == VNET_FLOW_TYPE_IP6_GTPC)
482 vnet_flow_ip6_gtpc_t *gc = &f->ip6_gtpc;
483 gtp[0].teid = clib_host_to_net_u32 (gc->teid);
487 item->type = RTE_FLOW_ITEM_TYPE_GTPC;
489 item->mask = gtp + 1;
491 else if (f->
type == VNET_FLOW_TYPE_IP6_GTPU)
493 vnet_flow_ip6_gtpu_t *gu = &f->ip6_gtpu;
494 gtp[0].teid = clib_host_to_net_u32 (gu->teid);
498 item->type = RTE_FLOW_ITEM_TYPE_GTPU;
500 item->mask = gtp + 1;
502 else if ((f->
type == VNET_FLOW_TYPE_IP6_GTPU_IP4) ||
503 (f->
type == VNET_FLOW_TYPE_IP6_GTPU_IP6))
505 vnet_flow_ip6_gtpu_t *gu = &f->ip6_gtpu;
506 gtp[0].teid = clib_host_to_net_u32 (gu->teid);
510 item->type = RTE_FLOW_ITEM_TYPE_GTPU;
512 item->mask = gtp + 1;
515 if (f->
type == VNET_FLOW_TYPE_IP6_GTPU_IP4)
518 item->type = RTE_FLOW_ITEM_TYPE_IPV4;
520 vnet_flow_ip6_gtpu_ip4_t *gu4 = &f->ip6_gtpu_ip4;
522 if (!gu4->inner_src_addr.mask.as_u32 &&
523 !gu4->inner_dst_addr.mask.as_u32)
530 inner_ip4[0].hdr.src_addr = gu4->inner_src_addr.addr.as_u32;
531 inner_ip4[1].hdr.src_addr = gu4->inner_src_addr.mask.as_u32;
532 inner_ip4[0].hdr.dst_addr = gu4->inner_dst_addr.addr.as_u32;
533 inner_ip4[1].hdr.dst_addr = gu4->inner_dst_addr.mask.as_u32;
534 item->spec = inner_ip4;
535 item->mask = inner_ip4 + 1;
539 if (f->
type == VNET_FLOW_TYPE_IP6_GTPU_IP6)
542 vnet_flow_ip6_gtpu_ip6_t *gu6 = &f->ip6_gtpu_ip6;
544 clib_memset (&zero_addr, 0,
sizeof (ip6_address_t));
547 item->type = RTE_FLOW_ITEM_TYPE_IPV6;
549 if (!
clib_memcmp (&gu6->inner_src_addr.mask, &zero_addr, 16) &&
550 !
clib_memcmp (&gu6->inner_dst_addr.mask, &zero_addr, 16))
558 &gu6->inner_src_addr.addr, 16);
560 &gu6->inner_src_addr.mask, 16);
562 &gu6->inner_dst_addr.addr, 16);
564 &gu6->inner_dst_addr.mask, 16);
565 item->spec = inner_ip6;
566 item->mask = inner_ip6 + 1;
574 item->type = RTE_FLOW_ITEM_TYPE_END;
578 if (f->
actions & VNET_FLOW_ACTION_REDIRECT_TO_QUEUE)
582 action->type = RTE_FLOW_ACTION_TYPE_QUEUE;
583 action->conf = &queue;
586 if (f->
actions & VNET_FLOW_ACTION_DROP)
589 action->type = RTE_FLOW_ACTION_TYPE_DROP;
592 rv = VNET_FLOW_ERROR_INTERNAL;
598 if (f->
actions & VNET_FLOW_ACTION_RSS)
603 action->type = RTE_FLOW_ACTION_TYPE_RSS;
609 rss.types = rss_type;
611 RTE_ETH_HASH_FUNCTION_MAX)
613 rv = VNET_FLOW_ERROR_NOT_SUPPORTED;
619 rv = VNET_FLOW_ERROR_INTERNAL;
628 action->type = RTE_FLOW_ACTION_TYPE_PASSTHRU;
631 if (f->
actions & VNET_FLOW_ACTION_MARK)
635 action->type = RTE_FLOW_ACTION_TYPE_MARK;
636 action->conf = &mark;
640 action->type = RTE_FLOW_ACTION_TYPE_END;
648 rv = VNET_FLOW_ERROR_NOT_SUPPORTED;
649 else if (rv == -EEXIST)
650 rv = VNET_FLOW_ERROR_ALREADY_EXISTS;
652 rv = VNET_FLOW_ERROR_INTERNAL;
660 rv = VNET_FLOW_ERROR_NOT_SUPPORTED;
670 u32 flow_index,
uword * private_data)
697 return VNET_FLOW_ERROR_INTERNAL;
711 goto disable_rx_offload;
715 return VNET_FLOW_ERROR_NOT_SUPPORTED;
722 rv = VNET_FLOW_ERROR_NOT_SUPPORTED;
727 if (flow->
actions & (VNET_FLOW_ACTION_MARK |
728 VNET_FLOW_ACTION_REDIRECT_TO_NODE |
729 VNET_FLOW_ACTION_BUFFER_ADVANCE))
740 if (flow->
actions & VNET_FLOW_ACTION_MARK)
742 if (flow->
actions & VNET_FLOW_ACTION_REDIRECT_TO_NODE)
744 if (flow->
actions & VNET_FLOW_ACTION_BUFFER_ADVANCE)
750 if ((xd->
flags & DPDK_DEVICE_FLAG_RX_FLOW_OFFLOAD) == 0)
752 xd->
flags |= DPDK_DEVICE_FLAG_RX_FLOW_OFFLOAD;
758 case VNET_FLOW_TYPE_ETHERNET:
759 case VNET_FLOW_TYPE_IP4_N_TUPLE:
760 case VNET_FLOW_TYPE_IP6_N_TUPLE:
761 case VNET_FLOW_TYPE_IP4_VXLAN:
762 case VNET_FLOW_TYPE_IP4_GTPC:
763 case VNET_FLOW_TYPE_IP4_GTPU:
764 case VNET_FLOW_TYPE_IP4_GTPU_IP4:
765 case VNET_FLOW_TYPE_IP4_GTPU_IP6:
766 case VNET_FLOW_TYPE_IP6_GTPC:
767 case VNET_FLOW_TYPE_IP6_GTPU:
768 case VNET_FLOW_TYPE_IP6_GTPU_IP4:
769 case VNET_FLOW_TYPE_IP6_GTPU_IP6:
770 case VNET_FLOW_TYPE_IP4_L2TPV3OIP:
775 rv = VNET_FLOW_ERROR_NOT_SUPPORTED;
793 if ((xd->
flags & DPDK_DEVICE_FLAG_RX_FLOW_OFFLOAD) != 0
796 xd->
flags &= ~DPDK_DEVICE_FLAG_RX_FLOW_OFFLOAD;
806 u32 dev_instance = va_arg (*args,
u32);
807 u32 flow_index = va_arg (*args,
u32);
813 if (flow_index == ~0)
815 s =
format (s,
"%-25s: %U\n",
"supported flow actions",
817 s =
format (s,
"%-25s: %d\n",
"last DPDK error type",
819 s =
format (s,
"%-25s: %s\n",
"last DPDK error message",
826 return format (s,
"unknown flow");
volatile u32 main_loop_count
vnet_rss_function_t rss_fun
#define clib_memcpy_fast(a, b, c)
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
u32 supported_flow_actions
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
vl_api_ip_proto_t protocol
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
void dpdk_device_setup(dpdk_device_t *xd)
static const struct rte_flow_attr ingress
vl_api_fib_path_type_t type
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
static int dpdk_flow_add(dpdk_device_t *xd, vnet_flow_t *f, dpdk_flow_entry_t *fe)
#define pool_put(P, E)
Free an object E in pool P.
static void dpdk_flow_convert_rss_types(u64 type, u64 *dpdk_rss_type)
vnet_flow_t * vnet_get_flow(u32 flow_index)
static bool mac_address_is_all_zero(const u8 addr[6])
#define pool_get_aligned(P, E, A)
Allocate an object E from a pool P with alignment A.
format_function_t format_flow_actions
dpdk_flow_lookup_entry_t * flow_lookup_entries
u32 * parked_lookup_indexes
#define clib_memcmp(s1, s2, m1)
sll srl srl sll sra u16x4 i
u8 * format_dpdk_flow(u8 *s, va_list *args)
#define vec_free(V)
Free vector's memory (no header).
int dpdk_flow_ops_fn(vnet_main_t *vnm, vnet_flow_dev_op_t op, u32 dev_instance, u32 flow_index, uword *private_data)
#define pool_put_index(p, i)
Free pool element with given index.
dpdk_portid_t device_index
#define foreach_dpdk_rss_hf
#define FLOW_IS_VLAN_TAGGED(f)
vl_api_mac_event_action_t action
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
#define FLOW_IS_L2_LAYER(f)
u32 redirect_device_input_next_index
#define vec_foreach(var, vec)
Vector iterator.
dpdk_flow_entry_t * flow_entries
#define CLIB_CACHE_LINE_BYTES
struct rte_flow_error last_flow_error
const ip46_address_t zero_addr
CLIB vectors are ubiquitous dynamically resized arrays with by user defined "headers".
static enum rte_eth_hash_function dpdk_flow_convert_rss_func(vnet_rss_function_t func)
static uword pool_elts(void *v)
Number of active elements in a pool.