2 * Copyright (c) 2015 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
16 * interface_cli.c: interface CLI
18 * Copyright (c) 2008 Eliot Dresselhaus
20 * Permission is hereby granted, free of charge, to any person obtaining
21 * a copy of this software and associated documentation files (the
22 * "Software"), to deal in the Software without restriction, including
23 * without limitation the rights to use, copy, modify, merge, publish,
24 * distribute, sublicense, and/or sell copies of the Software, and to
25 * permit persons to whom the Software is furnished to do so, subject to
26 * the following conditions:
28 * The above copyright notice and this permission notice shall be
29 * included in all copies or substantial portions of the Software.
31 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
32 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
33 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
34 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
35 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
36 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
37 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
45 #include <vnet/vnet.h>
46 #include <vnet/ip/ip.h>
47 #include <vppinfra/bitmap.h>
50 compare_interface_names (void *a1, void *a2)
55 return vnet_hw_interface_compare (vnet_get_main (), *hi1, *hi2);
59 show_or_clear_hw_interfaces (vlib_main_t * vm,
60 unformat_input_t * input,
61 vlib_cli_command_t * cmd)
63 clib_error_t *error = 0;
64 vnet_main_t *vnm = vnet_get_main ();
65 vnet_interface_main_t *im = &vnm->interface_main;
66 vnet_hw_interface_t *hi;
67 u32 hw_if_index, *hw_if_indices = 0;
68 int i, verbose = -1, is_show, show_bond = 0;
70 is_show = strstr (cmd->path, "show") != 0;
71 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
73 /* See if user wants to show a specific interface. */
75 (input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
76 vec_add1 (hw_if_indices, hw_if_index);
78 /* See if user wants to show an interface with a specific hw_if_index. */
79 else if (unformat (input, "%u", &hw_if_index))
80 vec_add1 (hw_if_indices, hw_if_index);
82 else if (unformat (input, "verbose"))
83 verbose = 1; /* this is also the default */
85 else if (unformat (input, "detail"))
88 else if (unformat (input, "brief"))
91 else if (unformat (input, "bond"))
95 verbose = 0; /* default to brief for link bonding */
100 error = clib_error_return (0, "unknown input `%U'",
101 format_unformat_error, input);
106 /* Gather interfaces. */
107 if (vec_len (hw_if_indices) == 0)
108 pool_foreach (hi, im->hw_interfaces,
109 vec_add1 (hw_if_indices, hi - im->hw_interfaces));
112 verbose = 1; /* default to verbose (except bond) */
117 vec_sort_with_function (hw_if_indices, compare_interface_names);
119 vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm, 0, verbose);
120 for (i = 0; i < vec_len (hw_if_indices); i++)
122 hi = vnet_get_hw_interface (vnm, hw_if_indices[i]);
123 if (show_bond == 0) /* show all interfaces */
124 vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm,
126 else if ((hi->bond_info) &&
127 (hi->bond_info != VNET_HW_INTERFACE_BOND_INFO_SLAVE))
128 { /* show only bonded interface and all its slave interfaces */
130 vnet_hw_interface_t *shi;
131 vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm,
135 clib_bitmap_foreach (hw_idx, hi->bond_info,
137 shi = vnet_get_hw_interface(vnm, hw_idx);
138 vlib_cli_output (vm, "%U\n",
139 format_vnet_hw_interface, vnm, shi, verbose);
147 for (i = 0; i < vec_len (hw_if_indices); i++)
149 vnet_device_class_t *dc;
151 hi = vnet_get_hw_interface (vnm, hw_if_indices[i]);
152 dc = vec_elt_at_index (im->device_classes, hi->dev_class_index);
154 if (dc->clear_counters)
155 dc->clear_counters (hi->dev_instance);
160 vec_free (hw_if_indices);
166 * Displays various information about the state of the current terminal
170 * @cliexstart{show hardware}
172 * GigabitEthernet2/0/0 up GigabitEthernet2/0/0
173 * Ethernet address 00:50:56:b7:7c:83
174 * Intel 82545em_copper
175 * link up, media 1000T full-duplex, master,
176 * 0 unprocessed, 384 total buffers on rx queue 0 ring
177 * 237 buffers in driver rx cache
178 * rx total packets 1816
179 * rx total bytes 181084
180 * rx good packets 1816
181 * rx good bytes 181084
182 * rx 65 127 byte packets 1586
183 * rx 256 511 byte packets 230
184 * tx total packets 346
185 * tx total bytes 90224
186 * tx good packets 346
187 * tx good bytes 88840
188 * tx 64 byte packets 1
189 * tx 65 127 byte packets 115
190 * tx 256 511 byte packets 230
193 VLIB_CLI_COMMAND (show_hw_interfaces_command, static) = {
194 .path = "show hardware-interfaces",
195 .short_help = "show hardware-interfaces [brief|verbose|detail] [bond] [<if-name1> <if-name2> ...]",
196 .function = show_or_clear_hw_interfaces,
201 VLIB_CLI_COMMAND (clear_hw_interface_counters_command, static) = {
202 .path = "clear hardware-interfaces",
203 .short_help = "Clear hardware interfaces statistics",
204 .function = show_or_clear_hw_interfaces,
209 sw_interface_name_compare (void *a1, void *a2)
211 vnet_sw_interface_t *si1 = a1;
212 vnet_sw_interface_t *si2 = a2;
214 return vnet_sw_interface_compare (vnet_get_main (),
215 si1->sw_if_index, si2->sw_if_index);
218 static clib_error_t *
219 show_sw_interfaces (vlib_main_t * vm,
220 unformat_input_t * input, vlib_cli_command_t * cmd)
222 clib_error_t *error = 0;
223 vnet_main_t *vnm = vnet_get_main ();
224 vnet_interface_main_t *im = &vnm->interface_main;
225 vnet_sw_interface_t *si, *sorted_sis = 0;
226 u8 show_addresses = 0;
228 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
232 /* See if user wants to show specific interface */
234 (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
236 si = pool_elt_at_index (im->sw_interfaces, sw_if_index);
237 vec_add1 (sorted_sis, si[0]);
239 else if (unformat (input, "address") || unformat (input, "addr"))
243 error = clib_error_return (0, "unknown input `%U'",
244 format_unformat_error, input);
250 vlib_cli_output (vm, "%U\n", format_vnet_sw_interface, vnm, 0);
252 if (vec_len (sorted_sis) == 0) /* Get all interfaces */
254 /* Gather interfaces. */
256 vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
257 _vec_len (sorted_sis) = 0;
258 pool_foreach (si, im->sw_interfaces, (
260 vec_add1 (sorted_sis, si[0]);
265 vec_sort_with_function (sorted_sis, sw_interface_name_compare);
270 vec_foreach (si, sorted_sis)
272 l2input_main_t *l2m = &l2input_main;
273 ip4_main_t *im4 = &ip4_main;
274 ip6_main_t *im6 = &ip6_main;
275 ip_lookup_main_t *lm4 = &im4->lookup_main;
276 ip_lookup_main_t *lm6 = &im6->lookup_main;
277 ip_interface_address_t *ia = 0;
280 u32 fib_index4 = 0, fib_index6 = 0;
283 l2_input_config_t *config;
285 if (vec_len (im4->fib_index_by_sw_if_index) > si->sw_if_index)
286 fib_index4 = vec_elt (im4->fib_index_by_sw_if_index,
289 if (vec_len (im6->fib_index_by_sw_if_index) > si->sw_if_index)
290 fib_index6 = vec_elt (im6->fib_index_by_sw_if_index,
293 fib4 = vec_elt_at_index (im4->fibs, fib_index4);
294 fib6 = vec_elt_at_index (im6->fibs, fib_index6);
296 if (si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)
298 (vm, "%U (%s): \n unnumbered, use %U",
299 format_vnet_sw_if_index_name,
300 vnm, si->sw_if_index,
301 (si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? "up" : "dn",
302 format_vnet_sw_if_index_name, vnm, si->unnumbered_sw_if_index);
306 vlib_cli_output (vm, "%U (%s):",
307 format_vnet_sw_if_index_name,
308 vnm, si->sw_if_index,
309 (si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP)
313 /* Display any L2 addressing info */
314 vec_validate (l2m->configs, si->sw_if_index);
315 config = vec_elt_at_index (l2m->configs, si->sw_if_index);
318 u32 bd_id = l2input_main.bd_configs[config->bd_index].bd_id;
319 vlib_cli_output (vm, " l2 bridge bd_id %d%s%d", bd_id,
320 config->bvi ? " bvi shg " : " shg ",
323 else if (config->xconnect)
325 vlib_cli_output (vm, " l2 xconnect %U",
326 format_vnet_sw_if_index_name,
327 vnm, config->output_sw_if_index);
330 /* Display any IP4 addressing info */
332 foreach_ip_interface_address (lm4, ia, si->sw_if_index,
333 1 /* honor unnumbered */,
335 r4 = ip_interface_address_get_address (lm4, ia);
338 vlib_cli_output (vm, " %U/%d table %d",
339 format_ip4_address, r4,
345 vlib_cli_output (vm, " %U/%d",
346 format_ip4_address, r4,
352 /* Display any IP6 addressing info */
354 foreach_ip_interface_address (lm6, ia, si->sw_if_index,
355 1 /* honor unnumbered */,
357 r6 = ip_interface_address_get_address (lm6, ia);
360 vlib_cli_output (vm, " %U/%d table %d",
361 format_ip6_address, r6,
367 vlib_cli_output (vm, " %U/%d",
368 format_ip6_address, r6,
377 vec_foreach (si, sorted_sis)
379 vlib_cli_output (vm, "%U\n", format_vnet_sw_interface, vnm, si);
384 vec_free (sorted_sis);
389 VLIB_CLI_COMMAND (show_sw_interfaces_command, static) = {
390 .path = "show interfaces",
391 .short_help = "show interfaces [address|addr] [<if-name1> <if-name2> ...]",
392 .function = show_sw_interfaces,
396 /* Root of all interface commands. */
398 VLIB_CLI_COMMAND (vnet_cli_interface_command, static) = {
400 .short_help = "Interface commands",
405 VLIB_CLI_COMMAND (vnet_cli_set_interface_command, static) = {
406 .path = "set interface",
407 .short_help = "Interface commands",
411 static clib_error_t *
412 clear_interface_counters (vlib_main_t * vm,
413 unformat_input_t * input, vlib_cli_command_t * cmd)
415 vnet_main_t *vnm = vnet_get_main ();
416 vnet_interface_main_t *im = &vnm->interface_main;
417 vlib_simple_counter_main_t *sm;
418 vlib_combined_counter_main_t *cm;
419 static vnet_main_t **my_vnet_mains;
420 int i, j, n_counters;
422 vec_reset_length (my_vnet_mains);
424 for (i = 0; i < vec_len (vnet_mains); i++)
427 vec_add1 (my_vnet_mains, vnet_mains[i]);
430 if (vec_len (vnet_mains) == 0)
431 vec_add1 (my_vnet_mains, vnm);
433 n_counters = vec_len (im->combined_sw_if_counters);
435 for (j = 0; j < n_counters; j++)
437 for (i = 0; i < vec_len (my_vnet_mains); i++)
439 im = &my_vnet_mains[i]->interface_main;
440 cm = im->combined_sw_if_counters + j;
441 vlib_clear_combined_counters (cm);
445 n_counters = vec_len (im->sw_if_counters);
447 for (j = 0; j < n_counters; j++)
449 for (i = 0; i < vec_len (my_vnet_mains); i++)
451 im = &my_vnet_mains[i]->interface_main;
452 sm = im->sw_if_counters + j;
453 vlib_clear_simple_counters (sm);
461 VLIB_CLI_COMMAND (clear_interface_counters_command, static) = {
462 .path = "clear interfaces",
463 .short_help = "Clear interfaces statistics",
464 .function = clear_interface_counters,
469 * Parse subinterface names.
471 * The following subinterface syntax is supported. The first two are for
472 * backwards compatability:
475 * - a subinterface with the name <intf-name>.<id>. The subinterface
476 * is a single dot1q vlan with vlan id <id> and exact-match semantics.
478 * <intf-name> <min_id>-<max_id>
479 * - a set of the above subinterfaces, repeating for each id
480 * in the range <min_id> to <max_id>
482 * In the following, exact-match semantics (i.e. the number of vlan tags on the
483 * packet must match the number of tags in the configuration) are used only if
484 * the keyword exact-match is present. Non-exact match is the default.
486 * <intf-name> <id> dot1q <outer_id> [exact-match]
487 * - a subinterface with the name <intf-name>.<id>. The subinterface
488 * is a single dot1q vlan with vlan id <outer_id>.
490 * <intf-name> <id> dot1q any [exact-match]
491 * - a subinterface with the name <intf-name>.<id>. The subinterface
492 * is a single dot1q vlan with any vlan id.
494 * <intf-name> <id> dot1q <outer_id> inner-dot1q <inner_id> [exact-match]
495 * - a subinterface with the name <intf-name>.<id>. The subinterface
496 * is a double dot1q vlan with outer vlan id <outer_id> and inner vlan id
499 * <intf-name> <id> dot1q <outer_id> inner-dot1q any [exact-match]
500 * - a subinterface with the name <intf-name>.<id>. The subinterface
501 * is a double dot1q vlan with outer vlan id <id> and any inner vlan id.
503 * <intf-name> <id> dot1q any inner-dot1q any [exact-match]
505 * - a subinterface with the name <intf-name>.<id>. The subinterface
506 * is a double dot1q vlan with any outer vlan id and any inner vlan id.
508 * For each of the above CLI, there is a duplicate that uses the keyword
509 * "dot1ad" in place of the first "dot1q". These interfaces use ethertype
510 * 0x88ad in place of 0x8100 for the outer ethertype. Note that for double-
511 * tagged packets the inner ethertype is always 0x8100. Also note that
512 * the dot1q and dot1ad naming spaces are independent, so it is legal to
513 * have both "Gig3/0/0.1 dot1q 100" and "Gig3/0/0.2 dot1ad 100". For example:
515 * <intf-name> <id> dot1ad <outer_id> inner-dot1q <inner_id> [exact-match]
516 * - a subinterface with the name <intf-name>.<id>. The subinterface
517 * is a double dot1ad vlan with outer vlan id <outer_id> and inner vlan
520 * <intf-name> <id> untagged
521 * - a subinterface with the name <intf-name>.<id>. The subinterface
522 * has no vlan tags. Only one can be specified per interface.
524 * <intf-name> <id> default
525 * - a subinterface with the name <intf-name>.<id>. This is associated
526 * with a packet that did not match any other configured subinterface
527 * on this interface. Only one can be specified per interface.
530 static clib_error_t *
531 parse_vlan_sub_interfaces (unformat_input_t * input,
532 vnet_sw_interface_t * template)
534 clib_error_t *error = 0;
535 u32 inner_vlan, outer_vlan;
537 if (unformat (input, "any inner-dot1q any"))
539 template->sub.eth.flags.two_tags = 1;
540 template->sub.eth.flags.outer_vlan_id_any = 1;
541 template->sub.eth.flags.inner_vlan_id_any = 1;
543 else if (unformat (input, "any"))
545 template->sub.eth.flags.one_tag = 1;
546 template->sub.eth.flags.outer_vlan_id_any = 1;
548 else if (unformat (input, "%d inner-dot1q any", &outer_vlan))
550 template->sub.eth.flags.two_tags = 1;
551 template->sub.eth.flags.inner_vlan_id_any = 1;
552 template->sub.eth.outer_vlan_id = outer_vlan;
554 else if (unformat (input, "%d inner-dot1q %d", &outer_vlan, &inner_vlan))
556 template->sub.eth.flags.two_tags = 1;
557 template->sub.eth.outer_vlan_id = outer_vlan;
558 template->sub.eth.inner_vlan_id = inner_vlan;
560 else if (unformat (input, "%d", &outer_vlan))
562 template->sub.eth.flags.one_tag = 1;
563 template->sub.eth.outer_vlan_id = outer_vlan;
567 error = clib_error_return (0, "expected dot1q config, got `%U'",
568 format_unformat_error, input);
572 if (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
574 if (unformat (input, "exact-match"))
576 template->sub.eth.flags.exact_match = 1;
584 static clib_error_t *
585 create_sub_interfaces (vlib_main_t * vm,
586 unformat_input_t * input, vlib_cli_command_t * cmd)
588 vnet_main_t *vnm = vnet_get_main ();
589 clib_error_t *error = 0;
590 u32 hw_if_index, sw_if_index;
591 vnet_hw_interface_t *hi;
592 u32 id, id_min, id_max;
593 vnet_sw_interface_t template;
596 if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
598 error = clib_error_return (0, "unknown interface `%U'",
599 format_unformat_error, input);
603 memset (&template, 0, sizeof (template));
604 template.sub.eth.raw_flags = 0;
606 if (unformat (input, "%d default", &id_min))
609 template.sub.eth.flags.default_sub = 1;
611 else if (unformat (input, "%d untagged", &id_min))
614 template.sub.eth.flags.no_tags = 1;
615 template.sub.eth.flags.exact_match = 1;
617 else if (unformat (input, "%d dot1q", &id_min))
619 /* parse dot1q config */
621 error = parse_vlan_sub_interfaces (input, &template);
625 else if (unformat (input, "%d dot1ad", &id_min))
627 /* parse dot1ad config */
629 template.sub.eth.flags.dot1ad = 1;
630 error = parse_vlan_sub_interfaces (input, &template);
634 else if (unformat (input, "%d-%d", &id_min, &id_max))
636 template.sub.eth.flags.one_tag = 1;
637 template.sub.eth.outer_vlan_id = id_min;
638 template.sub.eth.flags.exact_match = 1;
642 else if (unformat (input, "%d", &id_min))
645 template.sub.eth.flags.one_tag = 1;
646 template.sub.eth.outer_vlan_id = id_min;
647 template.sub.eth.flags.exact_match = 1;
652 error = clib_error_return (0, "expected ID or ID MIN-MAX, got `%U'",
653 format_unformat_error, input);
657 hi = vnet_get_hw_interface (vnm, hw_if_index);
659 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE)
662 clib_error_return (0,
663 "not allowed as %v belong to a BondEthernet interface",
668 for (id = id_min; id <= id_max; id++)
671 vnet_interface_main_t *im = &vnm->interface_main;
672 u64 sup_and_sub_key = ((u64) (hi->sw_if_index) << 32) | (u64) id;
675 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
679 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
680 hi->sw_if_index, id);
684 kp = clib_mem_alloc (sizeof (*kp));
685 *kp = sup_and_sub_key;
687 template.type = VNET_SW_INTERFACE_TYPE_SUB;
688 template.sup_sw_if_index = hi->sw_if_index;
689 template.sub.id = id;
690 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
694 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
695 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
696 vlib_cli_output (vm, "%U\n", format_vnet_sw_if_index_name,
697 vnet_get_main (), sw_if_index);
706 * Create vlan subinterfaces
709 * @cliexstart{create sub-interfaces}
711 * To create a vlan subinterface 11 to process packets on 802.1q VLAN id 11, use:
713 * vpp# create sub GigabitEthernet2/0/0 11
715 * This shorthand is equivalent to:
716 * vpp# create sub GigabitEthernet2/0/0 11 dot1q 11 exact-match
718 * You can specify a subinterface number that is different from the vlan id:
719 * vpp# create sub GigabitEthernet2/0/0 11 dot1q 100
721 * You can create qinq and q-in-any interfaces:
722 * vpp# create sub GigabitEthernet2/0/0 11 dot1q 100 inner-dot1q 200
723 * vpp# create sub GigabitEthernet2/0/0 12 dot1q 100 inner-dot1q any
725 * You can also create dot1ad interfaces:
726 * vpp# create sub GigabitEthernet2/0/0 11 dot1ad 11
727 * vpp# create sub GigabitEthernet2/0/0 12 dot1q 100 inner-dot1q 200
729 * Subinterfaces can be configured as either exact-match or non-exact match.
730 * Non-exact match is the CLI default. If exact-match is specified,
731 * packets must have the same number of vlan tags as the configuration.
732 * For non-exact-match, packets must at least that number of tags.
733 * L3 (routed) interfaces must be configured as exact-match.
734 * L2 interfaces are typically configured as non-exact-match.
736 * For example, a packet with outer vlan 100 and inner 200 would match this interface:
737 * vpp# create sub GigabitEthernet2/0/0 5 dot1q 100
739 * but would not match this interface:
740 * vpp# create sub GigabitEthernet2/0/0 5 dot1q 100 exact-match
742 * There are two special subinterfaces that can be configured. Subinterface untagged has no vlan tags:
743 * vpp# create sub GigabitEthernet2/0/0 5 untagged
745 * The subinterface default matches any packet that does not match any other subinterface:
746 * vpp# create sub GigabitEthernet2/0/0 7 default
749 VLIB_CLI_COMMAND (create_sub_interfaces_command, static) = {
750 .path = "create sub-interfaces",
751 .short_help = "create sub-interfaces <nn>[-<nn>] [dot1q|dot1ad|default|untagged]",
752 .function = create_sub_interfaces,
756 static clib_error_t *
757 set_state (vlib_main_t * vm,
758 unformat_input_t * input, vlib_cli_command_t * cmd)
760 vnet_main_t *vnm = vnet_get_main ();
762 u32 sw_if_index, flags;
765 if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
767 error = clib_error_return (0, "unknown interface `%U'",
768 format_unformat_error, input);
772 if (!unformat (input, "%U", unformat_vnet_sw_interface_flags, &flags))
774 error = clib_error_return (0, "unknown flags `%U'",
775 format_unformat_error, input);
779 error = vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
790 * Interface admin up/down
793 * @cliexstart{set interface state}
794 * vpp# set interface state GigabitEthernet2/0/0 up
795 * vpp# set interface state GigabitEthernet2/0/0 down
798 VLIB_CLI_COMMAND (set_state_command, static) = {
799 .path = "set interface state",
800 .short_help = "Set interface state",
801 .function = set_state,
805 static clib_error_t *
806 set_unnumbered (vlib_main_t * vm,
807 unformat_input_t * input, vlib_cli_command_t * cmd)
809 vnet_main_t *vnm = vnet_get_main ();
810 u32 unnumbered_sw_if_index;
811 u32 inherit_from_sw_if_index;
812 vnet_sw_interface_t *si;
816 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
819 if (unformat (input, "%U use %U",
820 unformat_vnet_sw_interface, vnm, &unnumbered_sw_if_index,
821 unformat_vnet_sw_interface, vnm,
822 &inherit_from_sw_if_index))
824 else if (unformat (input, "del %U",
825 unformat_vnet_sw_interface,
826 vnm, &unnumbered_sw_if_index))
830 if (is_set || is_del)
833 return clib_error_return
834 (0, "parse error '%U'", format_unformat_error, input);
838 si = vnet_get_sw_interface (vnm, unnumbered_sw_if_index);
841 si->flags &= ~(VNET_SW_INTERFACE_FLAG_UNNUMBERED);
842 si->unnumbered_sw_if_index = (u32) ~ 0;
846 si->flags |= VNET_SW_INTERFACE_FLAG_UNNUMBERED;
847 si->unnumbered_sw_if_index = inherit_from_sw_if_index;
854 VLIB_CLI_COMMAND (set_unnumbered_command, static) = {
855 .path = "set interface unnumbered",
856 .short_help = "set interface unnumbered [<intfc> use <intfc>][del <intfc>]",
857 .function = set_unnumbered,
863 static clib_error_t *
864 set_hw_class (vlib_main_t * vm,
865 unformat_input_t * input, vlib_cli_command_t * cmd)
867 vnet_main_t *vnm = vnet_get_main ();
868 vnet_interface_main_t *im = &vnm->interface_main;
870 u32 hw_if_index, hw_class_index;
873 if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
875 error = clib_error_return (0, "unknown hardware interface `%U'",
876 format_unformat_error, input);
880 if (!unformat_user (input, unformat_hash_string,
881 im->hw_interface_class_by_name, &hw_class_index))
883 error = clib_error_return (0, "unknown hardware class `%U'",
884 format_unformat_error, input);
888 error = vnet_hw_interface_set_class (vnm, hw_if_index, hw_class_index);
897 VLIB_CLI_COMMAND (set_hw_class_command, static) = {
898 .path = "set interface hw-class",
899 .short_help = "Set interface hardware class",
900 .function = set_hw_class,
904 static clib_error_t *
905 vnet_interface_cli_init (vlib_main_t * vm)
910 VLIB_INIT_FUNCTION (vnet_interface_cli_init);
912 static clib_error_t *
913 renumber_interface_command_fn (vlib_main_t * vm,
914 unformat_input_t * input,
915 vlib_cli_command_t * cmd)
918 u32 new_dev_instance;
919 vnet_main_t *vnm = vnet_get_main ();
922 if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
923 return clib_error_return (0, "unknown hardware interface `%U'",
924 format_unformat_error, input);
926 if (!unformat (input, "%d", &new_dev_instance))
927 return clib_error_return (0, "new dev instance missing");
929 rv = vnet_interface_name_renumber (hw_if_index, new_dev_instance);
937 return clib_error_return (0, "vnet_interface_name_renumber returned %d",
947 VLIB_CLI_COMMAND (renumber_interface_command, static) = {
948 .path = "renumber interface",
949 .short_help = "renumber interface <if-name> <new-dev-instance>",
950 .function = renumber_interface_command_fn,
954 static clib_error_t *
955 promiscuous_cmd (vlib_main_t * vm,
956 unformat_input_t * input, vlib_cli_command_t * cmd)
958 vnet_main_t *vnm = vnet_get_main ();
960 u32 flags = ETHERNET_INTERFACE_FLAG_ACCEPT_ALL;
961 ethernet_main_t *em = ðernet_main;
962 ethernet_interface_t *eif;
964 if (unformat (input, "on %U",
965 unformat_vnet_hw_interface, vnm, &hw_if_index))
967 else if (unformat (input, "off %U",
968 unformat_ethernet_interface, vnm, &hw_if_index))
971 return clib_error_return (0, "unknown input `%U'",
972 format_unformat_error, input);
974 eif = ethernet_get_interface (em, hw_if_index);
976 return clib_error_return (0, "not supported");
978 ethernet_set_flags (vnm, hw_if_index, flags);
983 VLIB_CLI_COMMAND (set_interface_promiscuous_cmd, static) = {
984 .path = "set interface promiscuous",
985 .short_help = "set interface promiscuous [on | off] <intfc>",
986 .function = promiscuous_cmd,
990 static clib_error_t *
991 mtu_cmd (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd)
993 vnet_main_t *vnm = vnet_get_main ();
994 u32 hw_if_index, mtu;
995 u32 flags = ETHERNET_INTERFACE_FLAG_MTU;
996 ethernet_main_t *em = ðernet_main;
998 if (unformat (input, "%d %U", &mtu,
999 unformat_vnet_hw_interface, vnm, &hw_if_index))
1001 vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, hw_if_index);
1002 ethernet_interface_t *eif = ethernet_get_interface (em, hw_if_index);
1005 return clib_error_return (0, "not supported");
1007 if (mtu < hi->min_supported_packet_bytes)
1008 return clib_error_return (0, "Invalid mtu (%d): "
1009 "must be >= min pkt bytes (%d)", mtu,
1010 hi->min_supported_packet_bytes);
1012 if (mtu > hi->max_supported_packet_bytes)
1013 return clib_error_return (0, "Invalid mtu (%d): must be <= (%d)", mtu,
1014 hi->max_supported_packet_bytes);
1016 if (hi->max_packet_bytes != mtu)
1018 hi->max_packet_bytes = mtu;
1019 ethernet_set_flags (vnm, hw_if_index, flags);
1023 return clib_error_return (0, "unknown input `%U'",
1024 format_unformat_error, input);
1029 VLIB_CLI_COMMAND (set_interface_mtu_cmd, static) = {
1030 .path = "set interface mtu",
1031 .short_help = "set interface mtu <value> <intfc>",
1032 .function = mtu_cmd,
1037 * fd.io coding-style-patch-verification: ON
1040 * eval: (c-set-style "gnu")