X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvnet%2Finterface_cli.c;h=c56eb9777cf3765fd927680b78474e582b574075;hb=b10561bbecb2870360a731b4696bff920150720d;hp=a2dfc2bb3ed409925b5a93b4f51e28bce3964832;hpb=9e0f9e235ad7dafcb481cf25f33eb52fdee8906b;p=vpp.git diff --git a/src/vnet/interface_cli.c b/src/vnet/interface_cli.c index a2dfc2bb3ed..c56eb9777cf 100644 --- a/src/vnet/interface_cli.c +++ b/src/vnet/interface_cli.c @@ -54,6 +54,9 @@ #include #include #include +#include +#include + static int compare_interface_names (void *a1, void *a2) { @@ -69,33 +72,37 @@ show_or_clear_hw_interfaces (vlib_main_t * vm, vlib_cli_command_t * cmd, int is_show) { clib_error_t *error = 0; + unformat_input_t _line_input, *line_input = &_line_input; vnet_main_t *vnm = vnet_get_main (); vnet_interface_main_t *im = &vnm->interface_main; vnet_hw_interface_t *hi; u32 hw_if_index, *hw_if_indices = 0; int i, verbose = -1, show_bond = 0; - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + if (!unformat_user (input, unformat_line_input, line_input)) + goto skip_unformat; + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { /* See if user wants to show a specific interface. */ - if (unformat - (input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index)) + if (unformat (line_input, "%U", unformat_vnet_hw_interface, vnm, + &hw_if_index)) vec_add1 (hw_if_indices, hw_if_index); /* See if user wants to show an interface with a specific hw_if_index. */ - else if (unformat (input, "%u", &hw_if_index)) + else if (unformat (line_input, "%u", &hw_if_index)) vec_add1 (hw_if_indices, hw_if_index); - else if (unformat (input, "verbose")) + else if (unformat (line_input, "verbose")) verbose = 1; /* this is also the default */ - else if (unformat (input, "detail")) + else if (unformat (line_input, "detail")) verbose = 2; - else if (unformat (input, "brief")) + else if (unformat (line_input, "brief")) verbose = 0; - else if (unformat (input, "bond")) + else if (unformat (line_input, "bond")) { show_bond = 1; if (verbose < 0) @@ -105,11 +112,15 @@ show_or_clear_hw_interfaces (vlib_main_t * vm, else { error = clib_error_return (0, "unknown input `%U'", - format_unformat_error, input); + format_unformat_error, line_input); + unformat_free (line_input); goto done; } } + unformat_free (line_input); + +skip_unformat: /* Gather interfaces. */ if (vec_len (hw_if_indices) == 0) pool_foreach (hi, im->hw_interfaces) @@ -138,14 +149,12 @@ show_or_clear_hw_interfaces (vlib_main_t * vm, vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm, hi, verbose); - /* *INDENT-OFF* */ clib_bitmap_foreach (hw_idx, hi->bond_info) { shi = vnet_get_hw_interface(vnm, hw_idx); vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm, shi, verbose); } - /* *INDENT-ON* */ } } } @@ -239,14 +248,12 @@ clear_hw_interfaces (vlib_main_t * vm, * cpu socket 0 * @cliexend ?*/ -/* *INDENT-OFF* */ VLIB_CLI_COMMAND (show_hw_interfaces_command, static) = { .path = "show hardware-interfaces", .short_help = "show hardware-interfaces [brief|verbose|detail] [bond] " "[ [ [..]]] [ [ [..]]]", .function = show_hw_interfaces, }; -/* *INDENT-ON* */ /*? @@ -260,14 +267,12 @@ VLIB_CLI_COMMAND (show_hw_interfaces_command, static) = { * name and software index (where 2 is the software index): * @cliexcmd{clear hardware-interfaces GigabitEthernet7/0/0 2} ?*/ -/* *INDENT-OFF* */ VLIB_CLI_COMMAND (clear_hw_interface_counters_command, static) = { .path = "clear hardware-interfaces", .short_help = "clear hardware-interfaces " "[ [ [..]]] [ [ [..]]]", .function = clear_hw_interfaces, }; -/* *INDENT-ON* */ static int sw_interface_name_compare (void *a1, void *a2) @@ -408,15 +413,13 @@ show_sw_interfaces (vlib_main_t * vm, /* Gather interfaces. */ sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces)); - _vec_len (sorted_sis) = 0; - /* *INDENT-OFF* */ + vec_set_len (sorted_sis, 0); pool_foreach (si, im->sw_interfaces) { int visible = vnet_swif_is_api_visible (si); if (visible) vec_add1 (sorted_sis, si[0]); } - /* *INDENT-ON* */ /* Sort by name. */ vec_sort_with_function (sorted_sis, sw_interface_name_compare); } @@ -458,7 +461,6 @@ show_sw_interfaces (vlib_main_t * vm, /* Display any L2 info */ vlib_cli_output (vm, "%U", format_l2_input, si->sw_if_index); - /* *INDENT-OFF* */ /* Display any IP4 addressing info */ foreach_ip_interface_address (lm4, ia, si->sw_if_index, 1 /* honor unnumbered */, @@ -473,9 +475,7 @@ show_sw_interfaces (vlib_main_t * vm, vlib_cli_output (vm, " L3 %U/%d", format_ip4_address, r4, ia->address_length); })); - /* *INDENT-ON* */ - /* *INDENT-OFF* */ /* Display any IP6 addressing info */ foreach_ip_interface_address (lm6, ia, si->sw_if_index, 1 /* honor unnumbered */, @@ -490,7 +490,6 @@ show_sw_interfaces (vlib_main_t * vm, vlib_cli_output (vm, " L3 %U/%d", format_ip6_address, r6, ia->address_length); })); - /* *INDENT-ON* */ } } else @@ -506,29 +505,24 @@ done: return error; } -/* *INDENT-OFF* */ VLIB_CLI_COMMAND (show_sw_interfaces_command, static) = { .path = "show interface", - .short_help = "show interface [address|addr|features|feat|vtr] [ [ [..]]] [verbose]", + .short_help = "show interface [address|addr|features|feat|vtr|tag] " + "[ [ [..]]] [verbose]", .function = show_sw_interfaces, .is_mp_safe = 1, }; -/* *INDENT-ON* */ /* Root of all interface commands. */ -/* *INDENT-OFF* */ VLIB_CLI_COMMAND (vnet_cli_interface_command, static) = { .path = "interface", .short_help = "Interface commands", }; -/* *INDENT-ON* */ -/* *INDENT-OFF* */ VLIB_CLI_COMMAND (vnet_cli_set_interface_command, static) = { .path = "set interface", .short_help = "Interface commands", }; -/* *INDENT-ON* */ static clib_error_t * clear_interface_counters (vlib_main_t * vm, @@ -569,13 +563,11 @@ clear_interface_counters (vlib_main_t * vm, * Example of how to clear the statistics for all interfaces: * @cliexcmd{clear interfaces} ?*/ -/* *INDENT-OFF* */ VLIB_CLI_COMMAND (clear_interface_counters_command, static) = { .path = "clear interfaces", .short_help = "clear interfaces", .function = clear_interface_counters, }; -/* *INDENT-ON* */ /** * Parse subinterface names. @@ -900,7 +892,6 @@ done: * @cliexcmd{set interface GigabitEthernet2/0/0.7 up} * @endparblock ?*/ -/* *INDENT-OFF* */ VLIB_CLI_COMMAND (create_sub_interfaces_command, static) = { .path = "create sub-interfaces", .short_help = "create sub-interfaces " @@ -909,7 +900,6 @@ VLIB_CLI_COMMAND (create_sub_interfaces_command, static) = { "{ dot1q|dot1ad |any [inner-dot1q |any] [exact-match]}", .function = create_sub_interfaces, }; -/* *INDENT-ON* */ static clib_error_t * set_state (vlib_main_t * vm, @@ -958,13 +948,11 @@ done: 'down': * @cliexcmd{set interface state GigabitEthernet2/0/0 down} ?*/ -/* *INDENT-OFF* */ VLIB_CLI_COMMAND (set_state_command, static) = { .path = "set interface state", .short_help = "set interface state [up|down|punt|enable]", .function = set_state, }; -/* *INDENT-ON* */ static clib_error_t * set_unnumbered (vlib_main_t * vm, @@ -1014,13 +1002,11 @@ set_unnumbered (vlib_main_t * vm, return (NULL); } -/* *INDENT-OFF* */ VLIB_CLI_COMMAND (set_unnumbered_command, static) = { .path = "set interface unnumbered", .short_help = "set interface unnumbered [ use | del ]", .function = set_unnumbered, }; -/* *INDENT-ON* */ @@ -1057,13 +1043,11 @@ done: return error; } -/* *INDENT-OFF* */ VLIB_CLI_COMMAND (set_hw_class_command, static) = { .path = "set interface hw-class", .short_help = "Set interface hardware class", .function = set_hw_class, }; -/* *INDENT-ON* */ static clib_error_t * vnet_interface_cli_init (vlib_main_t * vm) @@ -1107,13 +1091,11 @@ renumber_interface_command_fn (vlib_main_t * vm, } -/* *INDENT-OFF* */ VLIB_CLI_COMMAND (renumber_interface_command, static) = { .path = "renumber interface", .short_help = "renumber interface ", .function = renumber_interface_command_fn, }; -/* *INDENT-ON* */ static clib_error_t * promiscuous_cmd (vlib_main_t * vm, @@ -1143,13 +1125,11 @@ promiscuous_cmd (vlib_main_t * vm, return 0; } -/* *INDENT-OFF* */ VLIB_CLI_COMMAND (set_interface_promiscuous_cmd, static) = { .path = "set interface promiscuous", .short_help = "set interface promiscuous [on|off] ", .function = promiscuous_cmd, }; -/* *INDENT-ON* */ static clib_error_t * mtu_cmd (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) @@ -1200,13 +1180,11 @@ done: return 0; } -/* *INDENT-OFF* */ VLIB_CLI_COMMAND (set_interface_mtu_cmd, static) = { .path = "set interface mtu", .short_help = "set interface mtu [packet|ip4|ip6|mpls] ", .function = mtu_cmd, }; -/* *INDENT-ON* */ static clib_error_t * show_interface_sec_mac_addr_fn (vlib_main_t * vm, unformat_input_t * input, @@ -1229,15 +1207,13 @@ show_interface_sec_mac_addr_fn (vlib_main_t * vm, unformat_input_t * input, { sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces)); - _vec_len (sorted_sis) = 0; - /* *INDENT-OFF* */ + vec_set_len (sorted_sis, 0); pool_foreach (si, im->sw_interfaces) { int visible = vnet_swif_is_api_visible (si); if (visible) vec_add1 (sorted_sis, si[0]); } - /* *INDENT-ON* */ /* Sort by name. */ vec_sort_with_function (sorted_sis, sw_interface_name_compare); } @@ -1278,13 +1254,11 @@ show_interface_sec_mac_addr_fn (vlib_main_t * vm, unformat_input_t * input, * @cliexstart{show interface secondary-mac-address} * @cliexend ?*/ -/* *INDENT-OFF* */ VLIB_CLI_COMMAND (show_interface_sec_mac_addr, static) = { .path = "show interface secondary-mac-address", .short_help = "show interface secondary-mac-address []", .function = show_interface_sec_mac_addr_fn, }; -/* *INDENT-ON* */ static clib_error_t * interface_add_del_mac_address (vlib_main_t * vm, unformat_input_t * input, @@ -1352,13 +1326,11 @@ done: * @cliexcmd{set interface secondary-mac-address GigabitEthernet0/8/0 aa:bb:cc:dd:ee:01 del} * @endparblock ?*/ -/* *INDENT-OFF* */ VLIB_CLI_COMMAND (interface_add_del_mac_address_cmd, static) = { .path = "set interface secondary-mac-address", .short_help = "set interface secondary-mac-address [(add|del)]", .function = interface_add_del_mac_address, }; -/* *INDENT-ON* */ static clib_error_t * set_interface_mac_address (vlib_main_t * vm, unformat_input_t * input, @@ -1402,13 +1374,11 @@ done: * @cliexcmd{set interface mac address pg0 aa:bb:cc:dd:ee:04} * @endparblock ?*/ -/* *INDENT-OFF* */ VLIB_CLI_COMMAND (set_interface_mac_address_cmd, static) = { .path = "set interface mac address", .short_help = "set interface mac address ", .function = set_interface_mac_address, }; -/* *INDENT-ON* */ static clib_error_t * set_tag (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) @@ -1427,13 +1397,11 @@ set_tag (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) return 0; } -/* *INDENT-OFF* */ VLIB_CLI_COMMAND (set_tag_command, static) = { .path = "set interface tag", .short_help = "set interface tag ", .function = set_tag, }; -/* *INDENT-ON* */ static clib_error_t * clear_tag (vlib_main_t * vm, unformat_input_t * input, @@ -1451,13 +1419,11 @@ clear_tag (vlib_main_t * vm, unformat_input_t * input, return 0; } -/* *INDENT-OFF* */ VLIB_CLI_COMMAND (clear_tag_command, static) = { .path = "clear interface tag", .short_help = "clear interface tag ", .function = clear_tag, }; -/* *INDENT-ON* */ static clib_error_t * set_ip_directed_broadcast (vlib_main_t * vm, @@ -1491,13 +1457,11 @@ set_ip_directed_broadcast (vlib_main_t * vm, * subnet broadcast address will be sent L2 broadcast on the interface, * otherwise it is dropped. ?*/ -/* *INDENT-OFF* */ VLIB_CLI_COMMAND (set_ip_directed_broadcast_command, static) = { .path = "set interface ip directed-broadcast", .short_help = "set interface enable ", .function = set_ip_directed_broadcast, }; -/* *INDENT-ON* */ clib_error_t * set_hw_interface_change_rx_mode (vnet_main_t * vnm, u32 hw_if_index, @@ -1507,6 +1471,33 @@ set_hw_interface_change_rx_mode (vnet_main_t * vnm, u32 hw_if_index, clib_error_t *error = 0; vnet_hw_interface_t *hw; u32 *queue_indices = 0; + vnet_dev_port_t *port; + + port = vnet_dev_get_port_from_hw_if_index (hw_if_index); + + if (port) + { + vlib_main_t *vm = vlib_get_main (); + vnet_dev_rv_t rv; + + vnet_dev_port_cfg_change_req_t req = { + .type = mode == VNET_HW_IF_RX_MODE_POLLING ? + VNET_DEV_PORT_CFG_RXQ_INTR_MODE_DISABLE : + VNET_DEV_PORT_CFG_RXQ_INTR_MODE_ENABLE, + .queue_id = queue_id_valid ? queue_id : 0, + .all_queues = queue_id_valid ? 0 : 1, + }; + + if ((rv = vnet_dev_port_cfg_change_req_validate (vm, port, &req))) + return vnet_dev_port_err ( + vm, port, rv, "rx queue interupt mode enable/disable not supported"); + + if ((rv = vnet_dev_process_port_cfg_change_req (vm, port, &req))) + return vnet_dev_port_err ( + vm, port, rv, + "device failed to enable/disable queue interrupt mode"); + return 0; + } hw = vnet_get_hw_interface (vnm, hw_if_index); @@ -1527,7 +1518,12 @@ set_hw_interface_change_rx_mode (vnet_main_t * vnm, u32 hw_if_index, { int rv = vnet_hw_if_set_rx_queue_mode (vnm, queue_indices[i], mode); if (rv) - goto done; + { + error = clib_error_return ( + 0, "unable to set rx-mode on interface %v queue-id %u.\n", + hw->name, queue_id); + goto done; + } } done: @@ -1621,13 +1617,11 @@ set_interface_rx_mode (vlib_main_t * vm, unformat_input_t * input, * VirtualEthernet0/0/13 queue 3 (polling) * @cliexend ?*/ -/* *INDENT-OFF* */ VLIB_CLI_COMMAND (cmd_set_if_rx_mode,static) = { .path = "set interface rx-mode", .short_help = "set interface rx-mode [queue ] [polling | interrupt | adaptive]", .function = set_interface_rx_mode, }; -/* *INDENT-ON* */ static clib_error_t * show_interface_rx_placement_fn (vlib_main_t * vm, unformat_input_t * input, @@ -1693,13 +1687,11 @@ show_interface_rx_placement_fn (vlib_main_t * vm, unformat_input_t * input, * VirtualEthernet0/0/13 queue 3 (polling) * @cliexend ?*/ -/* *INDENT-OFF* */ VLIB_CLI_COMMAND (show_interface_rx_placement, static) = { .path = "show interface rx-placement", .short_help = "show interface rx-placement", .function = show_interface_rx_placement_fn, }; -/* *INDENT-ON* */ clib_error_t * set_hw_interface_rx_placement (u32 hw_if_index, u32 queue_id, u32 thread_index, u8 is_main) @@ -1824,7 +1816,6 @@ set_interface_rx_placement (vlib_main_t *vm, unformat_input_t *input, * VirtualEthernet0/0/13 queue 3 (polling) * @cliexend ?*/ -/* *INDENT-OFF* */ VLIB_CLI_COMMAND (cmd_set_if_rx_placement,static) = { .path = "set interface rx-placement", .short_help = "set interface rx-placement [queue ] " @@ -1832,7 +1823,6 @@ VLIB_CLI_COMMAND (cmd_set_if_rx_placement,static) = { .function = set_interface_rx_placement, .is_mp_safe = 1, }; -/* *INDENT-ON* */ int set_hw_interface_tx_queue (u32 hw_if_index, u32 queue_id, uword *bitmap) @@ -2017,13 +2007,11 @@ done: * @cliexstart{set interface rss queues VirtualFunctionEthernet18/1/0 list 0,2-5,7} * @cliexend ?*/ -/* *INDENT-OFF* */ VLIB_CLI_COMMAND (cmd_set_interface_rss_queues,static) = { .path = "set interface rss queues", .short_help = "set interface rss queues >", .function = set_interface_rss_queues_fn, }; -/* *INDENT-ON* */ static u8 * format_vnet_pcap (u8 * s, va_list * args) @@ -2371,13 +2359,13 @@ pcap_trace_command_fn (vlib_main_t * vm, * packet capture are preserved, so 'any' can be used to reset * the interface setting. * - * - filter - Use the pcap rx / tx / drop trace filter, which + * - filter - Use the pcap trace rx / tx / drop filter, which * must be configured. Use classify filter pcap... to configure the * filter. The filter will only be executed if the per-interface or * any-interface tests fail. * * - error . - filter packets based on a specific error. - * For example: error {ip4-udp-lookup}.{No listener for dst port} + * For example: error {ip4-udp-lookup}.{no_listener} * * - file - Used to specify the output filename. The file will * be placed in the '/tmp' directory, so only the filename is @@ -2413,7 +2401,6 @@ pcap_trace_command_fn (vlib_main_t * vm, * saved to /tmp/vppTest.pcap... * @cliexend ?*/ -/* *INDENT-OFF* */ VLIB_CLI_COMMAND (pcap_tx_trace_command, static) = { .path = "pcap trace", @@ -2423,7 +2410,72 @@ VLIB_CLI_COMMAND (pcap_tx_trace_command, static) = { " [preallocate-data][free-data]", .function = pcap_trace_command_fn, }; -/* *INDENT-ON* */ + +static clib_error_t * +set_pcap_filter_function (vlib_main_t *vm, unformat_input_t *input, + vlib_cli_command_t *cmd) +{ + vnet_pcap_t *pp = &vnet_get_main ()->pcap; + unformat_input_t _line_input, *line_input = &_line_input; + vlib_is_packet_traced_fn_t *res = 0; + clib_error_t *error = 0; + + if (!unformat_user (input, unformat_line_input, line_input)) + return 0; + + while (unformat_check_input (line_input) != (uword) UNFORMAT_END_OF_INPUT) + { + if (unformat (line_input, "%U", unformat_vlib_trace_filter_function, + &res)) + ; + else + { + error = clib_error_create ( + "expected valid trace filter function, got `%U'", + format_unformat_error, line_input); + goto done; + } + } + pp->current_filter_function = res; + +done: + unformat_free (line_input); + + return error; +} + +VLIB_CLI_COMMAND (set_pcap_filter_function_cli, static) = { + .path = "set pcap filter function", + .short_help = "set pcap filter function ", + .function = set_pcap_filter_function, +}; + +static clib_error_t * +show_pcap_filter_function (vlib_main_t *vm, unformat_input_t *input, + vlib_cli_command_t *cmd) +{ + vnet_pcap_t *pp = &vnet_get_main ()->pcap; + vlib_trace_filter_main_t *tfm = &vlib_trace_filter_main; + vlib_is_packet_traced_fn_t *current_trace_filter_fn = + pp->current_filter_function; + vlib_trace_filter_function_registration_t *reg = + tfm->trace_filter_registration; + + while (reg) + { + vlib_cli_output (vm, "%sname:%s description: %s priority: %u", + reg->function == current_trace_filter_fn ? "(*) " : "", + reg->name, reg->description, reg->priority); + reg = reg->next; + } + return 0; +} + +VLIB_CLI_COMMAND (show_pcap_filter_function_cli, static) = { + .path = "show pcap filter function", + .short_help = "show pcap filter function", + .function = show_pcap_filter_function, +}; static clib_error_t * set_interface_name (vlib_main_t *vm, unformat_input_t *input,