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>
44 static int compare_interface_names (void *a1, void *a2)
49 return vnet_hw_interface_compare (vnet_get_main(), *hi1, *hi2);
53 show_or_clear_hw_interfaces (vlib_main_t * vm,
54 unformat_input_t * input,
55 vlib_cli_command_t * cmd)
57 clib_error_t * error = 0;
58 vnet_main_t * vnm = vnet_get_main();
59 vnet_interface_main_t * im = &vnm->interface_main;
60 vnet_hw_interface_t * hi;
61 u32 hw_if_index, * hw_if_indices = 0;
62 int i, verbose = -1, is_show, show_bond = 0;
64 is_show = strstr (cmd->path, "show") != 0;
65 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
67 /* See if user wants to show a specific interface. */
68 if (unformat (input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
69 vec_add1 (hw_if_indices, hw_if_index);
71 /* See if user wants to show an interface with a specific hw_if_index. */
72 else if (unformat (input, "%u", &hw_if_index))
73 vec_add1 (hw_if_indices, hw_if_index);
75 else if (unformat (input, "verbose"))
76 verbose = 1; /* this is also the default */
78 else if (unformat (input, "detail"))
81 else if (unformat (input, "brief"))
84 else if (unformat (input, "bond"))
87 if (verbose < 0) verbose = 0; /* default to brief for link bonding */
92 error = clib_error_return (0, "unknown input `%U'",
93 format_unformat_error, input);
98 /* Gather interfaces. */
99 if (vec_len (hw_if_indices) == 0)
100 pool_foreach (hi, im->hw_interfaces,
101 vec_add1 (hw_if_indices, hi - im->hw_interfaces));
103 if (verbose < 0) verbose = 1; /* default to verbose (except bond) */
108 vec_sort_with_function (hw_if_indices, compare_interface_names);
110 vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm, 0, verbose);
111 for (i = 0; i < vec_len (hw_if_indices); i++)
113 hi = vnet_get_hw_interface (vnm, hw_if_indices[i]);
114 if (show_bond == 0) /* show all interfaces */
115 vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm,
117 else if ((hi->bond_info) &&
118 (hi->bond_info != VNET_HW_INTERFACE_BOND_INFO_SLAVE))
119 { /* show only bonded interface and all its slave interfaces */
121 vnet_hw_interface_t * shi;
122 vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm,
124 clib_bitmap_foreach (hw_idx, hi->bond_info,
126 shi = vnet_get_hw_interface(vnm, hw_idx);
127 vlib_cli_output (vm, "%U\n",
128 format_vnet_hw_interface, vnm, shi, verbose);
135 for (i = 0; i < vec_len (hw_if_indices); i++)
137 vnet_device_class_t * dc;
139 hi = vnet_get_hw_interface (vnm, hw_if_indices[i]);
140 dc = vec_elt_at_index (im->device_classes, hi->dev_class_index);
142 if (dc->clear_counters)
143 dc->clear_counters (hi->dev_instance);
148 vec_free (hw_if_indices);
152 VLIB_CLI_COMMAND (show_hw_interfaces_command, static) = {
153 .path = "show hardware-interfaces",
154 .short_help = "show hardware-interfaces [brief|verbose|detail] [bond] [<if-name1> <if-name2> ...]",
155 .function = show_or_clear_hw_interfaces,
158 VLIB_CLI_COMMAND (clear_hw_interface_counters_command, static) = {
159 .path = "clear hardware-interfaces",
160 .short_help = "Clear hardware interfaces statistics",
161 .function = show_or_clear_hw_interfaces,
164 static int sw_interface_name_compare (void *a1, void *a2)
166 vnet_sw_interface_t *si1 = a1;
167 vnet_sw_interface_t *si2 = a2;
169 return vnet_sw_interface_compare (vnet_get_main(),
170 si1->sw_if_index, si2->sw_if_index);
173 static clib_error_t *
174 show_sw_interfaces (vlib_main_t * vm,
175 unformat_input_t * input,
176 vlib_cli_command_t * cmd)
178 clib_error_t * error = 0;
179 vnet_main_t * vnm = vnet_get_main();
180 vnet_interface_main_t * im = &vnm->interface_main;
181 vnet_sw_interface_t * si, * sorted_sis = 0;
182 u8 show_addresses = 0;
184 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
188 /* See if user wants to show specific interface */
189 if (unformat (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
191 si = pool_elt_at_index (im->sw_interfaces, sw_if_index);
192 vec_add1 (sorted_sis, si[0]);
195 else if (unformat (input, "address") || unformat (input, "addr"))
200 error = clib_error_return (0, "unknown input `%U'",
201 format_unformat_error, input);
207 vlib_cli_output (vm, "%U\n", format_vnet_sw_interface, vnm, 0);
209 if (vec_len (sorted_sis) == 0) /* Get all interfaces */
211 /* Gather interfaces. */
212 sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
213 _vec_len (sorted_sis) = 0;
214 pool_foreach (si, im->sw_interfaces, ({ vec_add1 (sorted_sis, si[0]); }));
217 vec_sort_with_function (sorted_sis, sw_interface_name_compare);
222 vec_foreach (si, sorted_sis)
224 l2input_main_t * l2m = &l2input_main;
225 ip4_main_t * im4 = &ip4_main;
226 ip6_main_t * im6 = &ip6_main;
227 ip_lookup_main_t * lm4 = &im4->lookup_main;
228 ip_lookup_main_t * lm6 = &im6->lookup_main;
229 ip_interface_address_t * ia = 0;
232 u32 fib_index4 = 0, fib_index6 = 0;
235 l2_input_config_t * config;
237 if (vec_len (im4->fib_index_by_sw_if_index) > si->sw_if_index)
238 fib_index4 = vec_elt (im4->fib_index_by_sw_if_index,
241 if (vec_len (im6->fib_index_by_sw_if_index) > si->sw_if_index)
242 fib_index6 = vec_elt (im6->fib_index_by_sw_if_index,
245 fib4 = vec_elt_at_index (im4->fibs, fib_index4);
246 fib6 = vec_elt_at_index (im6->fibs, fib_index6);
248 if (si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)
250 (vm, "%U (%s): \n unnumbered, use %U",
251 format_vnet_sw_if_index_name,
252 vnm, si->sw_if_index,
253 (si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? "up" : "dn",
254 format_vnet_sw_if_index_name,
255 vnm, si->unnumbered_sw_if_index);
259 vlib_cli_output (vm, "%U (%s):",
260 format_vnet_sw_if_index_name,
261 vnm, si->sw_if_index,
262 (si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP)
266 /* Display any L2 addressing info */
267 vec_validate(l2m->configs, si->sw_if_index);
268 config = vec_elt_at_index(l2m->configs, si->sw_if_index);
271 u32 bd_id = l2input_main.bd_configs[config->bd_index].bd_id;
272 vlib_cli_output (vm, " l2 bridge bd_id %d%s%d", bd_id,
273 config->bvi ? " bvi shg " : " shg ", config->shg);
275 else if (config->xconnect)
277 vlib_cli_output (vm, " l2 xconnect %U",
278 format_vnet_sw_if_index_name,
279 vnm, config->output_sw_if_index);
282 /* Display any IP4 addressing info */
283 foreach_ip_interface_address (lm4, ia, si->sw_if_index,
284 1 /* honor unnumbered */,
286 r4 = ip_interface_address_get_address (lm4, ia);
289 vlib_cli_output (vm, " %U/%d table %d",
290 format_ip4_address, r4,
296 vlib_cli_output (vm, " %U/%d",
297 format_ip4_address, r4,
302 /* Display any IP6 addressing info */
303 foreach_ip_interface_address (lm6, ia, si->sw_if_index,
304 1 /* honor unnumbered */,
306 r6 = ip_interface_address_get_address (lm6, ia);
309 vlib_cli_output (vm, " %U/%d table %d",
310 format_ip6_address, r6,
316 vlib_cli_output (vm, " %U/%d",
317 format_ip6_address, r6,
325 vec_foreach (si, sorted_sis)
327 vlib_cli_output (vm, "%U\n", format_vnet_sw_interface, vnm, si);
332 vec_free (sorted_sis);
336 VLIB_CLI_COMMAND (show_sw_interfaces_command, static) = {
337 .path = "show interfaces",
338 .short_help = "show interfaces [address|addr] [<if-name1> <if-name2> ...]",
339 .function = show_sw_interfaces,
342 /* Root of all interface commands. */
343 VLIB_CLI_COMMAND (vnet_cli_interface_command, static) = {
345 .short_help = "Interface commands",
348 VLIB_CLI_COMMAND (vnet_cli_set_interface_command, static) = {
349 .path = "set interface",
350 .short_help = "Interface commands",
353 static clib_error_t *
354 clear_interface_counters (vlib_main_t * vm,
355 unformat_input_t * input,
356 vlib_cli_command_t * cmd)
358 vnet_main_t * vnm = vnet_get_main();
359 vnet_interface_main_t * im = &vnm->interface_main;
360 vlib_simple_counter_main_t * sm;
361 vlib_combined_counter_main_t * cm;
362 static vnet_main_t ** my_vnet_mains;
363 int i, j, n_counters;
365 vec_reset_length (my_vnet_mains);
367 for (i = 0; i < vec_len (vnet_mains); i++)
370 vec_add1 (my_vnet_mains, vnet_mains[i]);
373 if (vec_len (vnet_mains) == 0)
374 vec_add1 (my_vnet_mains, vnm);
376 n_counters = vec_len (im->combined_sw_if_counters);
378 for (j = 0; j < n_counters; j++)
380 for (i = 0; i < vec_len(my_vnet_mains); i++)
382 im = &my_vnet_mains[i]->interface_main;
383 cm = im->combined_sw_if_counters + j;
384 vlib_clear_combined_counters (cm);
388 n_counters = vec_len (im->sw_if_counters);
390 for (j = 0; j < n_counters; j++)
392 for (i = 0; i < vec_len(my_vnet_mains); i++)
394 im = &my_vnet_mains[i]->interface_main;
395 sm = im->sw_if_counters + j;
396 vlib_clear_simple_counters (sm);
403 VLIB_CLI_COMMAND (clear_interface_counters_command, static) = {
404 .path = "clear interfaces",
405 .short_help = "Clear interfaces statistics",
406 .function = clear_interface_counters,
409 // The following subinterface syntax is supported. The first two are for
410 // backwards compatability:
413 // - a subinterface with the name <intf-name>.<id>. The subinterface
414 // is a single dot1q vlan with vlan id <id> and exact-match semantics.
416 // <intf-name> <min_id>-<max_id>
417 // - a set of the above subinterfaces, repeating for each id
418 // in the range <min_id> to <max_id>
420 // In the following, exact-match semantics (i.e. the number of vlan tags on the
421 // packet must match the number of tags in the configuration) are used only if
422 // the keyword exact-match is present. Non-exact match is the default.
424 // <intf-name> <id> dot1q <outer_id> [exact-match]
425 // - a subinterface with the name <intf-name>.<id>. The subinterface
426 // is a single dot1q vlan with vlan id <outer_id>.
428 // <intf-name> <id> dot1q any [exact-match]
429 // - a subinterface with the name <intf-name>.<id>. The subinterface
430 // is a single dot1q vlan with any vlan id.
432 // <intf-name> <id> dot1q <outer_id> inner-dot1q <inner_id> [exact-match]
433 // - a subinterface with the name <intf-name>.<id>. The subinterface
434 // is a double dot1q vlan with outer vlan id <outer_id> and inner vlan id
437 // <intf-name> <id> dot1q <outer_id> inner-dot1q any [exact-match]
438 // - a subinterface with the name <intf-name>.<id>. The subinterface
439 // is a double dot1q vlan with outer vlan id <id> and any inner vlan id.
441 // <intf-name> <id> dot1q any inner-dot1q any [exact-match]
443 // - a subinterface with the name <intf-name>.<id>. The subinterface
444 // is a double dot1q vlan with any outer vlan id and any inner vlan id.
446 // For each of the above CLI, there is a duplicate that uses the keyword
447 // "dot1ad" in place of the first "dot1q". These interfaces use ethertype
448 // 0x88ad in place of 0x8100 for the outer ethertype. Note that for double-
449 // tagged packets the inner ethertype is always 0x8100. Also note that
450 // the dot1q and dot1ad naming spaces are independent, so it is legal to
451 // have both "Gig3/0/0.1 dot1q 100" and "Gig3/0/0.2 dot1ad 100". For example:
453 // <intf-name> <id> dot1ad <outer_id> inner-dot1q <inner_id> [exact-match]
454 // - a subinterface with the name <intf-name>.<id>. The subinterface
455 // is a double dot1ad vlan with outer vlan id <outer_id> and inner vlan
458 // <intf-name> <id> untagged
459 // - a subinterface with the name <intf-name>.<id>. The subinterface
460 // has no vlan tags. Only one can be specified per interface.
462 // <intf-name> <id> default
463 // - a subinterface with the name <intf-name>.<id>. This is associated
464 // with a packet that did not match any other configured subinterface
465 // on this interface. Only one can be specified per interface.
468 static clib_error_t *
469 parse_vlan_sub_interfaces (unformat_input_t * input,
470 vnet_sw_interface_t * template)
472 clib_error_t * error = 0;
473 u32 inner_vlan, outer_vlan;
475 if (unformat (input, "any inner-dot1q any")) {
476 template->sub.eth.flags.two_tags = 1;
477 template->sub.eth.flags.outer_vlan_id_any = 1;
478 template->sub.eth.flags.inner_vlan_id_any = 1;
479 } else if (unformat (input, "any")) {
480 template->sub.eth.flags.one_tag = 1;
481 template->sub.eth.flags.outer_vlan_id_any = 1;
482 } else if (unformat (input, "%d inner-dot1q any", &outer_vlan)) {
483 template->sub.eth.flags.two_tags = 1;
484 template->sub.eth.flags.inner_vlan_id_any = 1;
485 template->sub.eth.outer_vlan_id = outer_vlan;
486 } else if (unformat (input, "%d inner-dot1q %d", &outer_vlan, &inner_vlan)) {
487 template->sub.eth.flags.two_tags = 1;
488 template->sub.eth.outer_vlan_id = outer_vlan;
489 template->sub.eth.inner_vlan_id = inner_vlan;
490 } else if (unformat (input, "%d", &outer_vlan)) {
491 template->sub.eth.flags.one_tag = 1;
492 template->sub.eth.outer_vlan_id = outer_vlan;
494 error = clib_error_return (0, "expected dot1q config, got `%U'",
495 format_unformat_error, input);
499 if (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
500 if (unformat (input, "exact-match")) {
501 template->sub.eth.flags.exact_match = 1;
509 static clib_error_t *
510 create_sub_interfaces (vlib_main_t * vm,
511 unformat_input_t * input,
512 vlib_cli_command_t * cmd)
514 vnet_main_t * vnm = vnet_get_main();
515 clib_error_t * error = 0;
516 u32 hw_if_index, sw_if_index;
517 vnet_hw_interface_t * hi;
518 u32 id, id_min, id_max;
519 vnet_sw_interface_t template;
522 if (! unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
524 error = clib_error_return (0, "unknown interface `%U'",
525 format_unformat_error, input);
529 memset (&template, 0, sizeof (template));
530 template.sub.eth.raw_flags = 0;
532 if (unformat (input, "%d default", &id_min)) {
534 template.sub.eth.flags.default_sub = 1;
535 } else if (unformat (input, "%d untagged", &id_min)) {
537 template.sub.eth.flags.no_tags = 1;
538 template.sub.eth.flags.exact_match = 1;
539 } else if (unformat (input, "%d dot1q", &id_min)) {
540 // parse dot1q config
542 error = parse_vlan_sub_interfaces(input, &template);
543 if (error) goto done;
544 } else if (unformat (input, "%d dot1ad", &id_min)) {
545 // parse dot1ad config
547 template.sub.eth.flags.dot1ad = 1;
548 error = parse_vlan_sub_interfaces(input, &template);
549 if (error) goto done;
550 } else if (unformat (input, "%d-%d", &id_min, &id_max)) {
551 template.sub.eth.flags.one_tag = 1;
552 template.sub.eth.outer_vlan_id = id_min;
553 template.sub.eth.flags.exact_match = 1;
556 } else if (unformat (input, "%d", &id_min)) {
558 template.sub.eth.flags.one_tag = 1;
559 template.sub.eth.outer_vlan_id = id_min;
560 template.sub.eth.flags.exact_match = 1;
563 error = clib_error_return (0, "expected ID or ID MIN-MAX, got `%U'",
564 format_unformat_error, input);
569 if (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
570 error = clib_error_return (0, "unexpected text `%U'",
571 format_unformat_error, input);
576 hi = vnet_get_hw_interface (vnm, hw_if_index);
578 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE) {
579 error = clib_error_return (
580 0, "not allowed as %v belong to a BondEthernet interface", hi->name);
584 for (id = id_min; id <= id_max; id++)
587 vnet_interface_main_t * im = &vnm->interface_main;
588 u64 sup_and_sub_key = ((u64)(hi->sw_if_index) << 32) |
592 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
596 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
597 hi->sw_if_index, id);
601 kp = clib_mem_alloc (sizeof (*kp));
602 *kp = sup_and_sub_key;
604 template.type = VNET_SW_INTERFACE_TYPE_SUB;
605 template.sup_sw_if_index = hi->sw_if_index;
606 template.sub.id = id;
607 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
608 if (error) goto done;
609 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
610 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
611 vlib_cli_output(vm, "%U\n", format_vnet_sw_if_index_name, vnet_get_main(), sw_if_index);
621 VLIB_CLI_COMMAND (create_sub_interfaces_command, static) = {
622 .path = "create sub-interface",
623 .short_help = "create sub-interfaces <nn>[-<nn>] [dot1q|dot1ad|default|untagged]",
624 .function = create_sub_interfaces,
627 static clib_error_t *
628 set_state (vlib_main_t * vm,
629 unformat_input_t * input,
630 vlib_cli_command_t * cmd)
632 vnet_main_t * vnm = vnet_get_main();
633 clib_error_t * error;
634 u32 sw_if_index, flags;
637 if (! unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
639 error = clib_error_return (0, "unknown interface `%U'",
640 format_unformat_error, input);
644 if (! unformat (input, "%U", unformat_vnet_sw_interface_flags, &flags))
646 error = clib_error_return (0, "unknown flags `%U'",
647 format_unformat_error, input);
651 error = vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
659 VLIB_CLI_COMMAND (set_state_command, static) = {
660 .path = "set interface state",
661 .short_help = "Set interface state",
662 .function = set_state,
665 static clib_error_t *
666 set_unnumbered (vlib_main_t * vm,
667 unformat_input_t * input,
668 vlib_cli_command_t * cmd)
670 vnet_main_t * vnm = vnet_get_main();
671 u32 unnumbered_sw_if_index;
672 u32 inherit_from_sw_if_index;
673 vnet_sw_interface_t * si;
677 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
680 if (unformat (input, "%U use %U",
681 unformat_vnet_sw_interface, vnm, &unnumbered_sw_if_index,
682 unformat_vnet_sw_interface, vnm, &inherit_from_sw_if_index))
684 else if (unformat (input, "del %U",
685 unformat_vnet_sw_interface,
686 vnm, &unnumbered_sw_if_index))
690 if (is_set || is_del)
693 return clib_error_return
694 (0, "parse error '%U'", format_unformat_error, input);
698 si = vnet_get_sw_interface (vnm, unnumbered_sw_if_index);
700 si->flags &= ~(VNET_SW_INTERFACE_FLAG_UNNUMBERED);
701 si->unnumbered_sw_if_index = (u32)~0;
703 si->flags |= VNET_SW_INTERFACE_FLAG_UNNUMBERED;
704 si->unnumbered_sw_if_index = inherit_from_sw_if_index;
710 VLIB_CLI_COMMAND (set_unnumbered_command, static) = {
711 .path = "set interface unnumbered",
712 .short_help = "set interface unnumbered [<intfc> use <intfc>][del <intfc>]",
713 .function = set_unnumbered,
718 static clib_error_t *
719 set_hw_class (vlib_main_t * vm,
720 unformat_input_t * input,
721 vlib_cli_command_t * cmd)
723 vnet_main_t * vnm = vnet_get_main();
724 vnet_interface_main_t * im = &vnm->interface_main;
725 clib_error_t * error;
726 u32 hw_if_index, hw_class_index;
729 if (! unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
731 error = clib_error_return (0, "unknown hardware interface `%U'",
732 format_unformat_error, input);
736 if (! unformat_user (input, unformat_hash_string,
737 im->hw_interface_class_by_name, &hw_class_index))
739 error = clib_error_return (0, "unknown hardware class `%U'",
740 format_unformat_error, input);
744 error = vnet_hw_interface_set_class (vnm, hw_if_index, hw_class_index);
752 VLIB_CLI_COMMAND (set_hw_class_command, static) = {
753 .path = "set interface hw-class",
754 .short_help = "Set interface hardware class",
755 .function = set_hw_class,
758 static clib_error_t * vnet_interface_cli_init (vlib_main_t * vm)
761 VLIB_INIT_FUNCTION (vnet_interface_cli_init);
763 static clib_error_t *
764 renumber_interface_command_fn (vlib_main_t * vm,
765 unformat_input_t * input,
766 vlib_cli_command_t * cmd)
769 u32 new_dev_instance;
770 vnet_main_t * vnm = vnet_get_main();
773 if (! unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
774 return clib_error_return (0, "unknown hardware interface `%U'",
775 format_unformat_error, input);
777 if (! unformat (input, "%d", &new_dev_instance))
778 return clib_error_return (0, "new dev instance missing");
780 rv = vnet_interface_name_renumber (hw_if_index, new_dev_instance);
788 return clib_error_return (0, "vnet_interface_name_renumber returned %d",
797 VLIB_CLI_COMMAND (renumber_interface_command, static) = {
798 .path = "renumber interface",
799 .short_help = "renumber interface <if-name> <new-dev-instance>",
800 .function = renumber_interface_command_fn,
803 static clib_error_t *
804 promiscuous_cmd (vlib_main_t * vm,
805 unformat_input_t * input,
806 vlib_cli_command_t * cmd)
808 vnet_main_t * vnm = vnet_get_main();
810 u32 flags = ETHERNET_INTERFACE_FLAG_ACCEPT_ALL;
811 ethernet_main_t * em = ðernet_main;
812 ethernet_interface_t * eif;
814 if (unformat (input, "on %U",
815 unformat_vnet_hw_interface, vnm, &hw_if_index))
817 else if (unformat (input, "off %U",
818 unformat_ethernet_interface, vnm, &hw_if_index))
821 return clib_error_return (0, "unknown input `%U'",
822 format_unformat_error, input);
824 eif = ethernet_get_interface (em, hw_if_index);
826 return clib_error_return (0, "not supported");
828 ethernet_set_flags (vnm, hw_if_index, flags);
832 VLIB_CLI_COMMAND (set_interface_promiscuous_cmd, static) = {
833 .path = "set interface promiscuous",
834 .short_help = "set interface promiscuous [on | off] <intfc>",
835 .function = promiscuous_cmd,
838 static clib_error_t *
839 mtu_cmd (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd)
841 vnet_main_t * vnm = vnet_get_main();
842 u32 hw_if_index, mtu;
843 u32 flags = ETHERNET_INTERFACE_FLAG_MTU;
844 ethernet_main_t * em = ðernet_main;
846 if (unformat (input, "%d %U", &mtu,
847 unformat_vnet_hw_interface, vnm, &hw_if_index))
849 vnet_hw_interface_t * hi = vnet_get_hw_interface (vnm, hw_if_index);
850 ethernet_interface_t * eif = ethernet_get_interface (em, hw_if_index);
853 return clib_error_return (0, "not supported");
855 if (mtu < hi->min_supported_packet_bytes)
856 return clib_error_return (0, "Invalid mtu (%d): "
857 "must be >= min pkt bytes (%d)", mtu,
858 hi->min_supported_packet_bytes);
860 if (mtu > hi->max_supported_packet_bytes)
861 return clib_error_return (0, "Invalid mtu (%d): must be <= (%d)", mtu,
862 hi->max_supported_packet_bytes);
864 if (hi->max_packet_bytes != mtu)
866 hi->max_packet_bytes = mtu;
867 ethernet_set_flags (vnm, hw_if_index, flags);
871 return clib_error_return (0, "unknown input `%U'",
872 format_unformat_error, input);
876 VLIB_CLI_COMMAND (set_interface_mtu_cmd, static) = {
877 .path = "set interface mtu",
878 .short_help = "set interface mtu <value> <intfc>",