32 else if (
unformat (input,
"%u/%u", &port, &mask))
34 else if (
unformat (input,
"%u/0x%x", &port, &mask))
36 else if (
unformat (input,
"%u", &port))
41 if (port > 0xffff || mask > 0xffff)
57 if (pm->
mask == 0xffff)
66 int error = va_arg (*args,
int);
69 return format (s,
"no error");
71 #define _(v,n,str) if (error == v) return format (s, #str); 75 return format (s,
"unknown error (%d)", error);
81 u32 actions = va_arg (*args,
u32);
84 #define _(a, b, c) if (actions & (1 << a)) \ 85 t = format (t, "%s%s", t ? " ":"", c); 96 u32 flow_index = va_arg (*args,
u32);
99 return format (s,
"not found");
108 t = format (t,
"%s%U", t ?
", " :
"",
109 format_vnet_hw_if_index_name, vnm, hw_if_index);
134 u32 index = ~0, hw_if_index;
141 if (
unformat (line_input,
"index %u", &index))
161 hi = vnet_get_hw_interface (vnm, hw_if_index);
162 dev_class = vnet_get_device_class (vnm, hi->dev_class_index);
163 vlib_cli_output (vm,
"interface %U\n",
164 format_vnet_hw_if_index_name, vnm, hw_if_index);
165 if (dev_class->format_flow)
166 vlib_cli_output (vm,
" %U\n", dev_class->format_flow,
167 hi->dev_instance, f->index, private_data);
177 vlib_cli_output (vm,
"%U\n", format_flow, f);
186 .path =
"show flow entry",
187 .short_help =
"show flow entry [index <index>]",
212 .path =
"show flow ranges",
213 .short_help =
"show flow ranges",
226 u32 hw_if_index = ~0;
242 if (hw_if_index == ~0)
247 if (dev_class->format_flow == 0)
256 .path =
"show flow interface",
257 .short_help =
"show flow interface <interface name>",
276 }
action = FLOW_UNKNOWN_ACTION;
277 u32 hw_if_index = ~0, flow_index = ~0;
279 u32 prot = 0, teid = 0;
281 bool is_gtpc_set =
false;
282 bool is_gtpu_set =
false;
285 bool outer_ip4_set =
false, inner_ip4_set =
false;
286 bool outer_ip6_set =
false, inner_ip6_set =
false;
298 bool ethernet_set =
false;
303 flow.ip4_n_tuple.protocol = ~0;
311 else if (
unformat (line_input,
"del"))
313 else if (
unformat (line_input,
"enable"))
314 action = FLOW_ENABLE;
315 else if (
unformat (line_input,
"disable"))
316 action = FLOW_DISABLE;
317 else if (
unformat (line_input,
"eth-type %U",
320 else if (
unformat (line_input,
"src-ip %U",
322 outer_ip4_set =
true;
323 else if (
unformat (line_input,
"dst-ip %U",
325 outer_ip4_set =
true;
326 else if (
unformat (line_input,
"ip6-src-ip %U",
328 outer_ip6_set =
true;
329 else if (
unformat (line_input,
"ip6-dst-ip %U",
331 outer_ip6_set =
true;
332 else if (
unformat (line_input,
"inner-src-ip %U",
334 inner_ip4_set =
true;
335 else if (
unformat (line_input,
"inner-dst-ip %U",
337 inner_ip4_set =
true;
338 else if (
unformat (line_input,
"inner-ip6-src-ip %U",
340 inner_ip6_set =
true;
341 else if (
unformat (line_input,
"inner-ip6-dst-ip %U",
343 inner_ip6_set =
true;
352 else if (
unformat (line_input,
"proto %u", &prot))
354 else if (
unformat (line_input,
"gtpc teid %u", &teid))
356 else if (
unformat (line_input,
"gtpu teid %u", &teid))
358 else if (
unformat (line_input,
"index %u", &flow_index))
362 flow.
actions |= VNET_FLOW_ACTION_REDIRECT_TO_NODE;
364 flow.
actions |= VNET_FLOW_ACTION_MARK;
365 else if (
unformat (line_input,
"buffer-advance %d",
367 flow.
actions |= VNET_FLOW_ACTION_BUFFER_ADVANCE;
368 else if (
unformat (line_input,
"redirect-to-queue %d",
370 flow.
actions |= VNET_FLOW_ACTION_REDIRECT_TO_QUEUE;
371 else if (
unformat (line_input,
"drop"))
372 flow.
actions |= VNET_FLOW_ACTION_DROP;
383 if (hw_if_index == ~0 && (action == FLOW_ENABLE || action == FLOW_DISABLE))
386 if (flow_index == ~0 && (action == FLOW_ENABLE || action == FLOW_DISABLE ||
397 if (ethernet_set ==
true)
398 outer_type = VNET_FLOW_TYPE_ETHERNET;
399 if (outer_ip4_set ==
true)
400 outer_type = VNET_FLOW_TYPE_IP4_N_TUPLE;
401 else if (outer_ip6_set ==
true)
402 outer_type = VNET_FLOW_TYPE_IP6_N_TUPLE;
403 if (inner_ip4_set ==
true)
404 inner_type = VNET_FLOW_TYPE_IP4_N_TUPLE;
405 else if (inner_ip6_set ==
true)
406 inner_type = VNET_FLOW_TYPE_IP6_N_TUPLE;
411 if (outer_type == VNET_FLOW_TYPE_ETHERNET)
412 type = VNET_FLOW_TYPE_ETHERNET;
413 else if (outer_type == VNET_FLOW_TYPE_IP4_N_TUPLE)
415 type = VNET_FLOW_TYPE_IP4_N_TUPLE;
420 type = VNET_FLOW_TYPE_IP4_GTPC;
421 else if (is_gtpu_set)
422 type = VNET_FLOW_TYPE_IP4_GTPU;
424 else if (inner_type == VNET_FLOW_TYPE_IP4_N_TUPLE)
427 type = VNET_FLOW_TYPE_IP4_GTPU_IP4;
429 else if (inner_type == VNET_FLOW_TYPE_IP6_N_TUPLE)
432 type = VNET_FLOW_TYPE_IP4_GTPU_IP6;
435 else if (outer_type == VNET_FLOW_TYPE_IP6_N_TUPLE)
437 type = VNET_FLOW_TYPE_IP6_N_TUPLE;
442 type = VNET_FLOW_TYPE_IP6_GTPC;
443 else if (is_gtpu_set)
444 type = VNET_FLOW_TYPE_IP6_GTPU;
446 else if (inner_type == VNET_FLOW_TYPE_IP4_N_TUPLE)
449 type = VNET_FLOW_TYPE_IP6_GTPU_IP4;
451 else if (inner_type == VNET_FLOW_TYPE_IP6_N_TUPLE)
454 type = VNET_FLOW_TYPE_IP6_GTPU_IP6;
461 case VNET_FLOW_TYPE_ETHERNET:
462 memset (&flow.ethernet, 0, sizeof (flow.ethernet));
463 flow.ethernet.eth_hdr.
type = eth_type;
466 case VNET_FLOW_TYPE_IP4_N_TUPLE:
467 case VNET_FLOW_TYPE_IP4_GTPC:
468 case VNET_FLOW_TYPE_IP4_GTPU:
469 case VNET_FLOW_TYPE_IP4_GTPU_IP4:
470 case VNET_FLOW_TYPE_IP4_GTPU_IP6:
479 flow.ip4_n_tuple.protocol = prot;
481 if (type == VNET_FLOW_TYPE_IP4_GTPC)
482 flow.ip4_gtpc.teid = teid;
483 else if (type == VNET_FLOW_TYPE_IP4_GTPU)
484 flow.ip4_gtpu.teid = teid;
485 else if (type == VNET_FLOW_TYPE_IP4_GTPU_IP4)
487 flow.ip4_gtpu_ip4.teid = teid;
488 clib_memcpy (&flow.ip4_gtpu_ip4.inner_src_addr, &inner_ip4s,
490 clib_memcpy (&flow.ip4_gtpu_ip4.inner_dst_addr, &inner_ip4d,
493 else if (type == VNET_FLOW_TYPE_IP4_GTPU_IP6)
495 flow.ip4_gtpu_ip6.teid = teid;
496 clib_memcpy (&flow.ip4_gtpu_ip6.inner_src_addr, &inner_ip6s,
498 clib_memcpy (&flow.ip4_gtpu_ip6.inner_dst_addr, &inner_ip6d,
504 if ((type != VNET_FLOW_TYPE_IP4_N_TUPLE) &&
505 (flow.ip4_n_tuple.protocol != IP_PROTOCOL_UDP))
507 "For GTP related flow, ip protocol must be UDP");
510 case VNET_FLOW_TYPE_IP6_N_TUPLE:
511 case VNET_FLOW_TYPE_IP6_GTPC:
512 case VNET_FLOW_TYPE_IP6_GTPU:
513 case VNET_FLOW_TYPE_IP6_GTPU_IP4:
514 case VNET_FLOW_TYPE_IP6_GTPU_IP6:
523 flow.ip6_n_tuple.protocol = prot;
525 if (type == VNET_FLOW_TYPE_IP6_GTPC)
526 flow.ip6_gtpc.teid = teid;
527 else if (type == VNET_FLOW_TYPE_IP6_GTPU)
528 flow.ip6_gtpu.teid = teid;
529 else if (type == VNET_FLOW_TYPE_IP6_GTPU_IP4)
531 flow.ip6_gtpu_ip4.teid = teid;
532 clib_memcpy (&flow.ip6_gtpu_ip4.inner_src_addr, &inner_ip4s,
534 clib_memcpy (&flow.ip6_gtpu_ip4.inner_dst_addr, &inner_ip4d,
537 else if (type == VNET_FLOW_TYPE_IP6_GTPU_IP6)
539 flow.ip6_gtpu_ip6.teid = teid;
540 clib_memcpy (&flow.ip6_gtpu_ip6.inner_src_addr, &inner_ip6s,
542 clib_memcpy (&flow.ip6_gtpu_ip6.inner_dst_addr, &inner_ip6d,
548 if ((type != VNET_FLOW_TYPE_IP4_N_TUPLE) &&
549 (flow.ip6_n_tuple.protocol != IP_PROTOCOL_UDP))
551 "For GTP related flow, ip protocol must be UDP");
561 printf (
"flow %u added\n", flow_index);
586 .short_help =
"test flow add [src-ip <ip-addr/mask>] [dst-ip " 587 "<ip-addr/mask>] [src-port <port/mask>] [dst-port <port/mask>] " 597 char *
type = va_arg (*args,
char *);
598 void *ptr = va_arg (*args,
void *);
600 if (strncmp (type,
"u8", 2) == 0)
601 return format (s,
"%d", *(
u8 *) ptr);
603 if (strncmp (type,
"u16", 3) == 0)
606 if (strncmp (type,
"u32", 3) == 0)
609 if (strncmp (type,
"ip4_address_t", 13) == 0)
612 if (strncmp (type,
"ip4_address_and_mask_t", 13) == 0)
615 if (strncmp (type,
"ip6_address_t", 13) == 0)
618 if (strncmp (type,
"ip6_address_and_mask_t", 13) == 0)
621 if (strncmp (type,
"ip_protocol_t", 13) == 0)
624 if (strncmp (type,
"ip_port_and_mask_t", 18) == 0)
627 s =
format (s,
"unknown type '%s'", type);
631 #define _fe(a,b) s2 = format (s2, "%s%s %U", s2 ? ", ":"", #b, \ 632 format_flow_match_element, #a, &f->b); 634 u8 * format_flow_match_##b (u8 * s, va_list * args) \ 636 vnet_flow_##b##_t *f = __builtin_va_arg (*args, vnet_flow_##b##_t *); \ 638 foreach_flow_entry_##b \ 639 s = format (s, "%v", s2);; \ 652 if (f->type == VNET_FLOW_TYPE_##a) \ 653 return format (s, "%U", format_flow_match_##b, &f->b); 668 s =
format (s,
"flow-index %u type %s active %u",
676 if (f->
actions & VNET_FLOW_ACTION_MARK)
679 if (f->
actions & VNET_FLOW_ACTION_REDIRECT_TO_NODE)
680 t =
format (t,
"%snext-node %U", t ?
", " :
"",
683 if (f->
actions & VNET_FLOW_ACTION_BUFFER_ADVANCE)
unformat_function_t unformat_vnet_hw_interface
format_function_t format_vlib_node_name
vnet_main_t * vnet_get_main(void)
u8 * format_flow_actions(u8 *s, va_list *args)
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
static vnet_hw_interface_t * vnet_get_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
static clib_error_t * test_flow(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd_arg)
vnet_flow_t * global_flow_pool
u8 * format_flow_error(u8 *s, va_list *args)
struct _vnet_device_class vnet_device_class_t
int vnet_flow_disable(vnet_main_t *vnm, u32 flow_index, u32 hw_if_index)
static clib_error_t * show_flow_entry(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd_arg)
#define clib_memcpy(d, s, n)
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
static vnet_device_class_t * vnet_get_device_class(vnet_main_t *vnm, u32 dev_class_index)
static format_function_t format_flow
#define hash_foreach(key_var, value_var, h, body)
static u8 * format_flow_match_element(u8 *s, va_list *args)
#define clib_error_return(e, args...)
vnet_flow_main_t flow_main
vnet_flow_range_t * ranges
vl_api_fib_path_type_t type
int vnet_flow_del(vnet_main_t *vnm, u32 flow_index)
static clib_error_t * show_flow_ranges(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd_arg)
enum ip_protocol ip_protocol_t
vnet_flow_t * vnet_get_flow(u32 flow_index)
u8 * format_ip_port_and_mask(u8 *s, va_list *args)
#define vec_free(V)
Free vector's memory (no header).
u8 * format_flow_enabled_hw(u8 *s, va_list *args)
#define VLIB_CLI_COMMAND(x,...)
static const char * flow_type_strings[]
static uword hash_elts(void *v)
uword unformat_ip_port_and_mask(unformat_input_t *input, va_list *args)
static foreach_flow_type u8 * format_flow_match(u8 *s, va_list *args)
int vnet_flow_add(vnet_main_t *vnm, vnet_flow_t *flow, u32 *flow_index)
static vlib_main_t * vlib_get_main(void)
static clib_error_t * show_flow_interface(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd_arg)
uword unformat_ethernet_type_host_byte_order(unformat_input_t *input, va_list *args)
int vnet_flow_enable(vnet_main_t *vnm, u32 flow_index, u32 hw_if_index)
unformat_function_t unformat_vlib_node
#define vec_foreach(var, vec)
Vector iterator.
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)