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.
40 #include <vnet/vnet.h>
41 #include <vnet/ip/ip.h>
42 #include <vppinfra/bitmap.h>
45 compare_interface_names (void *a1, void *a2)
50 return vnet_hw_interface_compare (vnet_get_main (), *hi1, *hi2);
54 show_or_clear_hw_interfaces (vlib_main_t * vm,
55 unformat_input_t * input,
56 vlib_cli_command_t * cmd)
58 clib_error_t *error = 0;
59 vnet_main_t *vnm = vnet_get_main ();
60 vnet_interface_main_t *im = &vnm->interface_main;
61 vnet_hw_interface_t *hi;
62 u32 hw_if_index, *hw_if_indices = 0;
63 int i, verbose = -1, is_show, show_bond = 0;
65 is_show = strstr (cmd->path, "show") != 0;
66 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
68 /* See if user wants to show a specific interface. */
70 (input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
71 vec_add1 (hw_if_indices, hw_if_index);
73 /* See if user wants to show an interface with a specific hw_if_index. */
74 else if (unformat (input, "%u", &hw_if_index))
75 vec_add1 (hw_if_indices, hw_if_index);
77 else if (unformat (input, "verbose"))
78 verbose = 1; /* this is also the default */
80 else if (unformat (input, "detail"))
83 else if (unformat (input, "brief"))
86 else if (unformat (input, "bond"))
90 verbose = 0; /* default to brief for link bonding */
95 error = clib_error_return (0, "unknown input `%U'",
96 format_unformat_error, input);
101 /* Gather interfaces. */
102 if (vec_len (hw_if_indices) == 0)
103 pool_foreach (hi, im->hw_interfaces,
104 vec_add1 (hw_if_indices, hi - im->hw_interfaces));
107 verbose = 1; /* default to verbose (except bond) */
112 vec_sort_with_function (hw_if_indices, compare_interface_names);
114 vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm, 0, verbose);
115 for (i = 0; i < vec_len (hw_if_indices); i++)
117 hi = vnet_get_hw_interface (vnm, hw_if_indices[i]);
118 if (show_bond == 0) /* show all interfaces */
119 vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm,
121 else if ((hi->bond_info) &&
122 (hi->bond_info != VNET_HW_INTERFACE_BOND_INFO_SLAVE))
123 { /* show only bonded interface and all its slave interfaces */
125 vnet_hw_interface_t *shi;
126 vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm,
130 clib_bitmap_foreach (hw_idx, hi->bond_info,
132 shi = vnet_get_hw_interface(vnm, hw_idx);
133 vlib_cli_output (vm, "%U\n",
134 format_vnet_hw_interface, vnm, shi, verbose);
142 for (i = 0; i < vec_len (hw_if_indices); i++)
144 vnet_device_class_t *dc;
146 hi = vnet_get_hw_interface (vnm, hw_if_indices[i]);
147 dc = vec_elt_at_index (im->device_classes, hi->dev_class_index);
149 if (dc->clear_counters)
150 dc->clear_counters (hi->dev_instance);
155 vec_free (hw_if_indices);
160 VLIB_CLI_COMMAND (show_hw_interfaces_command, static) = {
161 .path = "show hardware-interfaces",
162 .short_help = "show hardware-interfaces [brief|verbose|detail] [bond] [<if-name1> <if-name2> ...]",
163 .function = show_or_clear_hw_interfaces,
168 VLIB_CLI_COMMAND (clear_hw_interface_counters_command, static) = {
169 .path = "clear hardware-interfaces",
170 .short_help = "Clear hardware interfaces statistics",
171 .function = show_or_clear_hw_interfaces,
176 sw_interface_name_compare (void *a1, void *a2)
178 vnet_sw_interface_t *si1 = a1;
179 vnet_sw_interface_t *si2 = a2;
181 return vnet_sw_interface_compare (vnet_get_main (),
182 si1->sw_if_index, si2->sw_if_index);
185 static clib_error_t *
186 show_sw_interfaces (vlib_main_t * vm,
187 unformat_input_t * input, vlib_cli_command_t * cmd)
189 clib_error_t *error = 0;
190 vnet_main_t *vnm = vnet_get_main ();
191 vnet_interface_main_t *im = &vnm->interface_main;
192 vnet_sw_interface_t *si, *sorted_sis = 0;
193 u8 show_addresses = 0;
195 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
199 /* See if user wants to show specific interface */
201 (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
203 si = pool_elt_at_index (im->sw_interfaces, sw_if_index);
204 vec_add1 (sorted_sis, si[0]);
206 else if (unformat (input, "address") || unformat (input, "addr"))
210 error = clib_error_return (0, "unknown input `%U'",
211 format_unformat_error, input);
217 vlib_cli_output (vm, "%U\n", format_vnet_sw_interface, vnm, 0);
219 if (vec_len (sorted_sis) == 0) /* Get all interfaces */
221 /* Gather interfaces. */
223 vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
224 _vec_len (sorted_sis) = 0;
225 pool_foreach (si, im->sw_interfaces, (
227 vec_add1 (sorted_sis, si[0]);
232 vec_sort_with_function (sorted_sis, sw_interface_name_compare);
237 vec_foreach (si, sorted_sis)
239 l2input_main_t *l2m = &l2input_main;
240 ip4_main_t *im4 = &ip4_main;
241 ip6_main_t *im6 = &ip6_main;
242 ip_lookup_main_t *lm4 = &im4->lookup_main;
243 ip_lookup_main_t *lm6 = &im6->lookup_main;
244 ip_interface_address_t *ia = 0;
247 u32 fib_index4 = 0, fib_index6 = 0;
250 l2_input_config_t *config;
252 if (vec_len (im4->fib_index_by_sw_if_index) > si->sw_if_index)
253 fib_index4 = vec_elt (im4->fib_index_by_sw_if_index,
256 if (vec_len (im6->fib_index_by_sw_if_index) > si->sw_if_index)
257 fib_index6 = vec_elt (im6->fib_index_by_sw_if_index,
260 fib4 = vec_elt_at_index (im4->fibs, fib_index4);
261 fib6 = vec_elt_at_index (im6->fibs, fib_index6);
263 if (si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)
265 (vm, "%U (%s): \n unnumbered, use %U",
266 format_vnet_sw_if_index_name,
267 vnm, si->sw_if_index,
268 (si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? "up" : "dn",
269 format_vnet_sw_if_index_name, vnm, si->unnumbered_sw_if_index);
273 vlib_cli_output (vm, "%U (%s):",
274 format_vnet_sw_if_index_name,
275 vnm, si->sw_if_index,
276 (si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP)
280 /* Display any L2 addressing info */
281 vec_validate (l2m->configs, si->sw_if_index);
282 config = vec_elt_at_index (l2m->configs, si->sw_if_index);
285 u32 bd_id = l2input_main.bd_configs[config->bd_index].bd_id;
286 vlib_cli_output (vm, " l2 bridge bd_id %d%s%d", bd_id,
287 config->bvi ? " bvi shg " : " shg ",
290 else if (config->xconnect)
292 vlib_cli_output (vm, " l2 xconnect %U",
293 format_vnet_sw_if_index_name,
294 vnm, config->output_sw_if_index);
297 /* Display any IP4 addressing info */
299 foreach_ip_interface_address (lm4, ia, si->sw_if_index,
300 1 /* honor unnumbered */,
302 r4 = ip_interface_address_get_address (lm4, ia);
305 vlib_cli_output (vm, " %U/%d table %d",
306 format_ip4_address, r4,
312 vlib_cli_output (vm, " %U/%d",
313 format_ip4_address, r4,
319 /* Display any IP6 addressing info */
321 foreach_ip_interface_address (lm6, ia, si->sw_if_index,
322 1 /* honor unnumbered */,
324 r6 = ip_interface_address_get_address (lm6, ia);
327 vlib_cli_output (vm, " %U/%d table %d",
328 format_ip6_address, r6,
334 vlib_cli_output (vm, " %U/%d",
335 format_ip6_address, r6,
344 vec_foreach (si, sorted_sis)
346 vlib_cli_output (vm, "%U\n", format_vnet_sw_interface, vnm, si);
351 vec_free (sorted_sis);
356 VLIB_CLI_COMMAND (show_sw_interfaces_command, static) = {
357 .path = "show interfaces",
358 .short_help = "show interfaces [address|addr] [<if-name1> <if-name2> ...]",
359 .function = show_sw_interfaces,
363 /* Root of all interface commands. */
365 VLIB_CLI_COMMAND (vnet_cli_interface_command, static) = {
367 .short_help = "Interface commands",
372 VLIB_CLI_COMMAND (vnet_cli_set_interface_command, static) = {
373 .path = "set interface",
374 .short_help = "Interface commands",
378 static clib_error_t *
379 clear_interface_counters (vlib_main_t * vm,
380 unformat_input_t * input, vlib_cli_command_t * cmd)
382 vnet_main_t *vnm = vnet_get_main ();
383 vnet_interface_main_t *im = &vnm->interface_main;
384 vlib_simple_counter_main_t *sm;
385 vlib_combined_counter_main_t *cm;
386 static vnet_main_t **my_vnet_mains;
387 int i, j, n_counters;
389 vec_reset_length (my_vnet_mains);
391 for (i = 0; i < vec_len (vnet_mains); i++)
394 vec_add1 (my_vnet_mains, vnet_mains[i]);
397 if (vec_len (vnet_mains) == 0)
398 vec_add1 (my_vnet_mains, vnm);
400 n_counters = vec_len (im->combined_sw_if_counters);
402 for (j = 0; j < n_counters; j++)
404 for (i = 0; i < vec_len (my_vnet_mains); i++)
406 im = &my_vnet_mains[i]->interface_main;
407 cm = im->combined_sw_if_counters + j;
408 vlib_clear_combined_counters (cm);
412 n_counters = vec_len (im->sw_if_counters);
414 for (j = 0; j < n_counters; j++)
416 for (i = 0; i < vec_len (my_vnet_mains); i++)
418 im = &my_vnet_mains[i]->interface_main;
419 sm = im->sw_if_counters + j;
420 vlib_clear_simple_counters (sm);
428 VLIB_CLI_COMMAND (clear_interface_counters_command, static) = {
429 .path = "clear interfaces",
430 .short_help = "Clear interfaces statistics",
431 .function = clear_interface_counters,
436 * The following subinterface syntax is supported. The first two are for
437 * backwards compatability:
440 * - a subinterface with the name <intf-name>.<id>. The subinterface
441 * is a single dot1q vlan with vlan id <id> and exact-match semantics.
443 * <intf-name> <min_id>-<max_id>
444 * - a set of the above subinterfaces, repeating for each id
445 * in the range <min_id> to <max_id>
447 * In the following, exact-match semantics (i.e. the number of vlan tags on the
448 * packet must match the number of tags in the configuration) are used only if
449 * the keyword exact-match is present. Non-exact match is the default.
451 * <intf-name> <id> dot1q <outer_id> [exact-match]
452 * - a subinterface with the name <intf-name>.<id>. The subinterface
453 * is a single dot1q vlan with vlan id <outer_id>.
455 * <intf-name> <id> dot1q any [exact-match]
456 * - a subinterface with the name <intf-name>.<id>. The subinterface
457 * is a single dot1q vlan with any vlan id.
459 * <intf-name> <id> dot1q <outer_id> inner-dot1q <inner_id> [exact-match]
460 * - a subinterface with the name <intf-name>.<id>. The subinterface
461 * is a double dot1q vlan with outer vlan id <outer_id> and inner vlan id
464 * <intf-name> <id> dot1q <outer_id> inner-dot1q any [exact-match]
465 * - a subinterface with the name <intf-name>.<id>. The subinterface
466 * is a double dot1q vlan with outer vlan id <id> and any inner vlan id.
468 * <intf-name> <id> dot1q any inner-dot1q any [exact-match]
470 * - a subinterface with the name <intf-name>.<id>. The subinterface
471 * is a double dot1q vlan with any outer vlan id and any inner vlan id.
473 * For each of the above CLI, there is a duplicate that uses the keyword
474 * "dot1ad" in place of the first "dot1q". These interfaces use ethertype
475 * 0x88ad in place of 0x8100 for the outer ethertype. Note that for double-
476 * tagged packets the inner ethertype is always 0x8100. Also note that
477 * the dot1q and dot1ad naming spaces are independent, so it is legal to
478 * have both "Gig3/0/0.1 dot1q 100" and "Gig3/0/0.2 dot1ad 100". For example:
480 * <intf-name> <id> dot1ad <outer_id> inner-dot1q <inner_id> [exact-match]
481 * - a subinterface with the name <intf-name>.<id>. The subinterface
482 * is a double dot1ad vlan with outer vlan id <outer_id> and inner vlan
485 * <intf-name> <id> untagged
486 * - a subinterface with the name <intf-name>.<id>. The subinterface
487 * has no vlan tags. Only one can be specified per interface.
489 * <intf-name> <id> default
490 * - a subinterface with the name <intf-name>.<id>. This is associated
491 * with a packet that did not match any other configured subinterface
492 * on this interface. Only one can be specified per interface.
495 static clib_error_t *
496 parse_vlan_sub_interfaces (unformat_input_t * input,
497 vnet_sw_interface_t * template)
499 clib_error_t *error = 0;
500 u32 inner_vlan, outer_vlan;
502 if (unformat (input, "any inner-dot1q any"))
504 template->sub.eth.flags.two_tags = 1;
505 template->sub.eth.flags.outer_vlan_id_any = 1;
506 template->sub.eth.flags.inner_vlan_id_any = 1;
508 else if (unformat (input, "any"))
510 template->sub.eth.flags.one_tag = 1;
511 template->sub.eth.flags.outer_vlan_id_any = 1;
513 else if (unformat (input, "%d inner-dot1q any", &outer_vlan))
515 template->sub.eth.flags.two_tags = 1;
516 template->sub.eth.flags.inner_vlan_id_any = 1;
517 template->sub.eth.outer_vlan_id = outer_vlan;
519 else if (unformat (input, "%d inner-dot1q %d", &outer_vlan, &inner_vlan))
521 template->sub.eth.flags.two_tags = 1;
522 template->sub.eth.outer_vlan_id = outer_vlan;
523 template->sub.eth.inner_vlan_id = inner_vlan;
525 else if (unformat (input, "%d", &outer_vlan))
527 template->sub.eth.flags.one_tag = 1;
528 template->sub.eth.outer_vlan_id = outer_vlan;
532 error = clib_error_return (0, "expected dot1q config, got `%U'",
533 format_unformat_error, input);
537 if (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
539 if (unformat (input, "exact-match"))
541 template->sub.eth.flags.exact_match = 1;
549 static clib_error_t *
550 create_sub_interfaces (vlib_main_t * vm,
551 unformat_input_t * input, vlib_cli_command_t * cmd)
553 vnet_main_t *vnm = vnet_get_main ();
554 clib_error_t *error = 0;
555 u32 hw_if_index, sw_if_index;
556 vnet_hw_interface_t *hi;
557 u32 id, id_min, id_max;
558 vnet_sw_interface_t template;
561 if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
563 error = clib_error_return (0, "unknown interface `%U'",
564 format_unformat_error, input);
568 memset (&template, 0, sizeof (template));
569 template.sub.eth.raw_flags = 0;
571 if (unformat (input, "%d default", &id_min))
574 template.sub.eth.flags.default_sub = 1;
576 else if (unformat (input, "%d untagged", &id_min))
579 template.sub.eth.flags.no_tags = 1;
580 template.sub.eth.flags.exact_match = 1;
582 else if (unformat (input, "%d dot1q", &id_min))
584 /* parse dot1q config */
586 error = parse_vlan_sub_interfaces (input, &template);
590 else if (unformat (input, "%d dot1ad", &id_min))
592 /* parse dot1ad config */
594 template.sub.eth.flags.dot1ad = 1;
595 error = parse_vlan_sub_interfaces (input, &template);
599 else if (unformat (input, "%d-%d", &id_min, &id_max))
601 template.sub.eth.flags.one_tag = 1;
602 template.sub.eth.outer_vlan_id = id_min;
603 template.sub.eth.flags.exact_match = 1;
607 else if (unformat (input, "%d", &id_min))
610 template.sub.eth.flags.one_tag = 1;
611 template.sub.eth.outer_vlan_id = id_min;
612 template.sub.eth.flags.exact_match = 1;
617 error = clib_error_return (0, "expected ID or ID MIN-MAX, got `%U'",
618 format_unformat_error, input);
622 hi = vnet_get_hw_interface (vnm, hw_if_index);
624 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE)
627 clib_error_return (0,
628 "not allowed as %v belong to a BondEthernet interface",
633 for (id = id_min; id <= id_max; id++)
636 vnet_interface_main_t *im = &vnm->interface_main;
637 u64 sup_and_sub_key = ((u64) (hi->sw_if_index) << 32) | (u64) id;
640 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
644 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
645 hi->sw_if_index, id);
649 kp = clib_mem_alloc (sizeof (*kp));
650 *kp = sup_and_sub_key;
652 template.type = VNET_SW_INTERFACE_TYPE_SUB;
653 template.sup_sw_if_index = hi->sw_if_index;
654 template.sub.id = id;
655 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
659 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
660 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
661 vlib_cli_output (vm, "%U\n", format_vnet_sw_if_index_name,
662 vnet_get_main (), sw_if_index);
670 VLIB_CLI_COMMAND (create_sub_interfaces_command, static) = {
671 .path = "create sub-interface",
672 .short_help = "create sub-interfaces <nn>[-<nn>] [dot1q|dot1ad|default|untagged]",
673 .function = create_sub_interfaces,
677 static clib_error_t *
678 set_state (vlib_main_t * vm,
679 unformat_input_t * input, vlib_cli_command_t * cmd)
681 vnet_main_t *vnm = vnet_get_main ();
683 u32 sw_if_index, flags;
686 if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
688 error = clib_error_return (0, "unknown interface `%U'",
689 format_unformat_error, input);
693 if (!unformat (input, "%U", unformat_vnet_sw_interface_flags, &flags))
695 error = clib_error_return (0, "unknown flags `%U'",
696 format_unformat_error, input);
700 error = vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
709 VLIB_CLI_COMMAND (set_state_command, static) = {
710 .path = "set interface state",
711 .short_help = "Set interface state",
712 .function = set_state,
716 static clib_error_t *
717 set_unnumbered (vlib_main_t * vm,
718 unformat_input_t * input, vlib_cli_command_t * cmd)
720 vnet_main_t *vnm = vnet_get_main ();
721 u32 unnumbered_sw_if_index;
722 u32 inherit_from_sw_if_index;
723 vnet_sw_interface_t *si;
727 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
730 if (unformat (input, "%U use %U",
731 unformat_vnet_sw_interface, vnm, &unnumbered_sw_if_index,
732 unformat_vnet_sw_interface, vnm,
733 &inherit_from_sw_if_index))
735 else if (unformat (input, "del %U",
736 unformat_vnet_sw_interface,
737 vnm, &unnumbered_sw_if_index))
741 if (is_set || is_del)
744 return clib_error_return
745 (0, "parse error '%U'", format_unformat_error, input);
749 si = vnet_get_sw_interface (vnm, unnumbered_sw_if_index);
752 si->flags &= ~(VNET_SW_INTERFACE_FLAG_UNNUMBERED);
753 si->unnumbered_sw_if_index = (u32) ~ 0;
757 si->flags |= VNET_SW_INTERFACE_FLAG_UNNUMBERED;
758 si->unnumbered_sw_if_index = inherit_from_sw_if_index;
765 VLIB_CLI_COMMAND (set_unnumbered_command, static) = {
766 .path = "set interface unnumbered",
767 .short_help = "set interface unnumbered [<intfc> use <intfc>][del <intfc>]",
768 .function = set_unnumbered,
774 static clib_error_t *
775 set_hw_class (vlib_main_t * vm,
776 unformat_input_t * input, vlib_cli_command_t * cmd)
778 vnet_main_t *vnm = vnet_get_main ();
779 vnet_interface_main_t *im = &vnm->interface_main;
781 u32 hw_if_index, hw_class_index;
784 if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
786 error = clib_error_return (0, "unknown hardware interface `%U'",
787 format_unformat_error, input);
791 if (!unformat_user (input, unformat_hash_string,
792 im->hw_interface_class_by_name, &hw_class_index))
794 error = clib_error_return (0, "unknown hardware class `%U'",
795 format_unformat_error, input);
799 error = vnet_hw_interface_set_class (vnm, hw_if_index, hw_class_index);
808 VLIB_CLI_COMMAND (set_hw_class_command, static) = {
809 .path = "set interface hw-class",
810 .short_help = "Set interface hardware class",
811 .function = set_hw_class,
815 static clib_error_t *
816 vnet_interface_cli_init (vlib_main_t * vm)
821 VLIB_INIT_FUNCTION (vnet_interface_cli_init);
823 static clib_error_t *
824 renumber_interface_command_fn (vlib_main_t * vm,
825 unformat_input_t * input,
826 vlib_cli_command_t * cmd)
829 u32 new_dev_instance;
830 vnet_main_t *vnm = vnet_get_main ();
833 if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
834 return clib_error_return (0, "unknown hardware interface `%U'",
835 format_unformat_error, input);
837 if (!unformat (input, "%d", &new_dev_instance))
838 return clib_error_return (0, "new dev instance missing");
840 rv = vnet_interface_name_renumber (hw_if_index, new_dev_instance);
848 return clib_error_return (0, "vnet_interface_name_renumber returned %d",
858 VLIB_CLI_COMMAND (renumber_interface_command, static) = {
859 .path = "renumber interface",
860 .short_help = "renumber interface <if-name> <new-dev-instance>",
861 .function = renumber_interface_command_fn,
865 static clib_error_t *
866 promiscuous_cmd (vlib_main_t * vm,
867 unformat_input_t * input, vlib_cli_command_t * cmd)
869 vnet_main_t *vnm = vnet_get_main ();
871 u32 flags = ETHERNET_INTERFACE_FLAG_ACCEPT_ALL;
872 ethernet_main_t *em = ðernet_main;
873 ethernet_interface_t *eif;
875 if (unformat (input, "on %U",
876 unformat_vnet_hw_interface, vnm, &hw_if_index))
878 else if (unformat (input, "off %U",
879 unformat_ethernet_interface, vnm, &hw_if_index))
882 return clib_error_return (0, "unknown input `%U'",
883 format_unformat_error, input);
885 eif = ethernet_get_interface (em, hw_if_index);
887 return clib_error_return (0, "not supported");
889 ethernet_set_flags (vnm, hw_if_index, flags);
894 VLIB_CLI_COMMAND (set_interface_promiscuous_cmd, static) = {
895 .path = "set interface promiscuous",
896 .short_help = "set interface promiscuous [on | off] <intfc>",
897 .function = promiscuous_cmd,
901 static clib_error_t *
902 mtu_cmd (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd)
904 vnet_main_t *vnm = vnet_get_main ();
905 u32 hw_if_index, mtu;
906 u32 flags = ETHERNET_INTERFACE_FLAG_MTU;
907 ethernet_main_t *em = ðernet_main;
909 if (unformat (input, "%d %U", &mtu,
910 unformat_vnet_hw_interface, vnm, &hw_if_index))
912 vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, hw_if_index);
913 ethernet_interface_t *eif = ethernet_get_interface (em, hw_if_index);
916 return clib_error_return (0, "not supported");
918 if (mtu < hi->min_supported_packet_bytes)
919 return clib_error_return (0, "Invalid mtu (%d): "
920 "must be >= min pkt bytes (%d)", mtu,
921 hi->min_supported_packet_bytes);
923 if (mtu > hi->max_supported_packet_bytes)
924 return clib_error_return (0, "Invalid mtu (%d): must be <= (%d)", mtu,
925 hi->max_supported_packet_bytes);
927 if (hi->max_packet_bytes != mtu)
929 hi->max_packet_bytes = mtu;
930 ethernet_set_flags (vnm, hw_if_index, flags);
934 return clib_error_return (0, "unknown input `%U'",
935 format_unformat_error, input);
940 VLIB_CLI_COMMAND (set_interface_mtu_cmd, static) = {
941 .path = "set interface mtu",
942 .short_help = "set interface mtu <value> <intfc>",
948 * fd.io coding-style-patch-verification: ON
951 * eval: (c-set-style "gnu")