28 u32 port = 0, mask = 0;
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, tmp, flow_index = ~0;
284 flow.ip4_n_tuple.protocol = ~0;
292 else if (
unformat (line_input,
"del"))
294 else if (
unformat (line_input,
"enable"))
295 action = FLOW_ENABLE;
296 else if (
unformat (line_input,
"disable"))
297 action = FLOW_DISABLE;
298 else if (
unformat (line_input,
"src-ip %U",
300 &flow.ip4_n_tuple.src_addr))
302 else if (
unformat (line_input,
"dst-ip %U",
304 &flow.ip4_n_tuple.dst_addr))
307 &flow.ip4_n_tuple.src_port))
310 &flow.ip4_n_tuple.dst_port))
313 flow.ip4_n_tuple.protocol = prot;
314 else if (
unformat (line_input,
"proto %u", &tmp))
315 flow.ip4_n_tuple.protocol = tmp;
316 else if (
unformat (line_input,
"index %u", &flow_index))
320 flow.
actions |= VNET_FLOW_ACTION_REDIRECT_TO_NODE;
322 flow.
actions |= VNET_FLOW_ACTION_MARK;
323 else if (
unformat (line_input,
"buffer-advance %d",
325 flow.
actions |= VNET_FLOW_ACTION_BUFFER_ADVANCE;
336 if (hw_if_index == ~0 && (action == FLOW_ENABLE || action == FLOW_DISABLE))
339 if (flow_index == ~0 && (action == FLOW_ENABLE || action == FLOW_DISABLE ||
351 flow.
type = VNET_FLOW_TYPE_IP4_N_TUPLE;
376 .short_help =
"test flow add [src-ip <ip-addr/mask>] [dst-ip " 377 "<ip-addr/mask>] [src-port <port/mask>] [dst-port <port/mask>] " 387 char *type = va_arg (*args,
char *);
388 void *ptr = va_arg (*args,
void *);
390 if (strncmp (type,
"u8", 2) == 0)
391 return format (s,
"%d", *(
u8 *) ptr);
393 if (strncmp (type,
"u16", 3) == 0)
396 if (strncmp (type,
"u32", 3) == 0)
399 if (strncmp (type,
"ip4_address_t", 13) == 0)
402 if (strncmp (type,
"ip4_address_and_mask_t", 13) == 0)
405 if (strncmp (type,
"ip6_address_t", 13) == 0)
408 if (strncmp (type,
"ip6_address_and_mask_t", 13) == 0)
411 if (strncmp (type,
"ip_protocol_t", 13) == 0)
414 if (strncmp (type,
"ip_port_and_mask_t", 18) == 0)
417 s =
format (s,
"unknown type '%s'", type);
421 #define _fe(a,b) s2 = format (s2, "%s%s %U", s2 ? ", ":"", #b, \ 422 format_flow_match_element, #a, &f->b); 424 u8 * format_flow_match_##b (u8 * s, va_list * args) \ 426 vnet_flow_##b##_t *f = __builtin_va_arg (*args, vnet_flow_##b##_t *); \ 428 foreach_flow_entry_##b \ 429 s = format (s, "%v", s2);; \ 442 if (f->type == VNET_FLOW_TYPE_##a) \ 443 return format (s, "%U", format_flow_match_##b, &f->b); 458 s =
format (s,
"flow-index %u type %s active %u",
466 if (f->
actions & VNET_FLOW_ACTION_MARK)
469 if (f->
actions & VNET_FLOW_ACTION_REDIRECT_TO_NODE)
470 t =
format (t,
"%snext-node %U", t ?
", " :
"",
473 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 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
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)
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,...)