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>
48 #include <vnet/fib/ip4_fib.h>
49 #include <vnet/fib/ip6_fib.h>
52 compare_interface_names (void *a1, void *a2)
57 return vnet_hw_interface_compare (vnet_get_main (), *hi1, *hi2);
61 show_or_clear_hw_interfaces (vlib_main_t * vm,
62 unformat_input_t * input,
63 vlib_cli_command_t * cmd)
65 clib_error_t *error = 0;
66 vnet_main_t *vnm = vnet_get_main ();
67 vnet_interface_main_t *im = &vnm->interface_main;
68 vnet_hw_interface_t *hi;
69 u32 hw_if_index, *hw_if_indices = 0;
70 int i, verbose = -1, is_show, show_bond = 0;
72 is_show = strstr (cmd->path, "show") != 0;
73 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
75 /* See if user wants to show a specific interface. */
77 (input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
78 vec_add1 (hw_if_indices, hw_if_index);
80 /* See if user wants to show an interface with a specific hw_if_index. */
81 else if (unformat (input, "%u", &hw_if_index))
82 vec_add1 (hw_if_indices, hw_if_index);
84 else if (unformat (input, "verbose"))
85 verbose = 1; /* this is also the default */
87 else if (unformat (input, "detail"))
90 else if (unformat (input, "brief"))
93 else if (unformat (input, "bond"))
97 verbose = 0; /* default to brief for link bonding */
102 error = clib_error_return (0, "unknown input `%U'",
103 format_unformat_error, input);
108 /* Gather interfaces. */
109 if (vec_len (hw_if_indices) == 0)
110 pool_foreach (hi, im->hw_interfaces,
111 vec_add1 (hw_if_indices, hi - im->hw_interfaces));
114 verbose = 1; /* default to verbose (except bond) */
119 vec_sort_with_function (hw_if_indices, compare_interface_names);
121 vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm, 0, verbose);
122 for (i = 0; i < vec_len (hw_if_indices); i++)
124 hi = vnet_get_hw_interface (vnm, hw_if_indices[i]);
125 if (show_bond == 0) /* show all interfaces */
126 vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm,
128 else if ((hi->bond_info) &&
129 (hi->bond_info != VNET_HW_INTERFACE_BOND_INFO_SLAVE))
130 { /* show only bonded interface and all its slave interfaces */
132 vnet_hw_interface_t *shi;
133 vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm,
137 clib_bitmap_foreach (hw_idx, hi->bond_info,
139 shi = vnet_get_hw_interface(vnm, hw_idx);
140 vlib_cli_output (vm, "%U\n",
141 format_vnet_hw_interface, vnm, shi, verbose);
149 for (i = 0; i < vec_len (hw_if_indices); i++)
151 vnet_device_class_t *dc;
153 hi = vnet_get_hw_interface (vnm, hw_if_indices[i]);
154 dc = vec_elt_at_index (im->device_classes, hi->dev_class_index);
156 if (dc->clear_counters)
157 dc->clear_counters (hi->dev_instance);
162 vec_free (hw_if_indices);
168 * Displays various information about the state of the current terminal
172 * @cliexstart{show hardware}
174 * GigabitEthernet2/0/0 up GigabitEthernet2/0/0
175 * Ethernet address 00:50:56:b7:7c:83
176 * Intel 82545em_copper
177 * link up, media 1000T full-duplex, master,
178 * 0 unprocessed, 384 total buffers on rx queue 0 ring
179 * 237 buffers in driver rx cache
180 * rx total packets 1816
181 * rx total bytes 181084
182 * rx good packets 1816
183 * rx good bytes 181084
184 * rx 65 127 byte packets 1586
185 * rx 256 511 byte packets 230
186 * tx total packets 346
187 * tx total bytes 90224
188 * tx good packets 346
189 * tx good bytes 88840
190 * tx 64 byte packets 1
191 * tx 65 127 byte packets 115
192 * tx 256 511 byte packets 230
195 VLIB_CLI_COMMAND (show_hw_interfaces_command, static) = {
196 .path = "show hardware-interfaces",
197 .short_help = "show hardware-interfaces [brief|verbose|detail] [bond] [<if-name1> <if-name2> ...]",
198 .function = show_or_clear_hw_interfaces,
203 VLIB_CLI_COMMAND (clear_hw_interface_counters_command, static) = {
204 .path = "clear hardware-interfaces",
205 .short_help = "Clear hardware interfaces statistics",
206 .function = show_or_clear_hw_interfaces,
211 sw_interface_name_compare (void *a1, void *a2)
213 vnet_sw_interface_t *si1 = a1;
214 vnet_sw_interface_t *si2 = a2;
216 return vnet_sw_interface_compare (vnet_get_main (),
217 si1->sw_if_index, si2->sw_if_index);
220 static clib_error_t *
221 show_sw_interfaces (vlib_main_t * vm,
222 unformat_input_t * input, vlib_cli_command_t * cmd)
224 clib_error_t *error = 0;
225 vnet_main_t *vnm = vnet_get_main ();
226 vnet_interface_main_t *im = &vnm->interface_main;
227 vnet_sw_interface_t *si, *sorted_sis = 0;
228 u32 sw_if_index = ~(u32) 0;
229 u8 show_addresses = 0;
230 u8 show_features = 0;
232 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
234 /* See if user wants to show specific interface */
236 (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
238 si = pool_elt_at_index (im->sw_interfaces, sw_if_index);
239 vec_add1 (sorted_sis, si[0]);
241 else if (unformat (input, "address") || unformat (input, "addr"))
243 else if (unformat (input, "features") || unformat (input, "feat"))
247 error = clib_error_return (0, "unknown input `%U'",
248 format_unformat_error, input);
255 if (sw_if_index == ~(u32) 0)
256 return clib_error_return (0, "Interface not specified...");
258 vnet_interface_features_show (vm, sw_if_index);
263 vlib_cli_output (vm, "%U\n", format_vnet_sw_interface, vnm, 0);
265 if (vec_len (sorted_sis) == 0) /* Get all interfaces */
267 /* Gather interfaces. */
269 vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
270 _vec_len (sorted_sis) = 0;
271 pool_foreach (si, im->sw_interfaces, (
273 vec_add1 (sorted_sis, si[0]);
278 vec_sort_with_function (sorted_sis, sw_interface_name_compare);
283 vec_foreach (si, sorted_sis)
285 l2input_main_t *l2m = &l2input_main;
286 ip4_main_t *im4 = &ip4_main;
287 ip6_main_t *im6 = &ip6_main;
288 ip_lookup_main_t *lm4 = &im4->lookup_main;
289 ip_lookup_main_t *lm6 = &im6->lookup_main;
290 ip_interface_address_t *ia = 0;
293 u32 fib_index4 = 0, fib_index6 = 0;
296 l2_input_config_t *config;
298 if (vec_len (im4->fib_index_by_sw_if_index) > si->sw_if_index)
299 fib_index4 = vec_elt (im4->fib_index_by_sw_if_index,
302 if (vec_len (im6->fib_index_by_sw_if_index) > si->sw_if_index)
303 fib_index6 = vec_elt (im6->fib_index_by_sw_if_index,
306 fib4 = ip4_fib_get (fib_index4);
307 fib6 = ip6_fib_get (fib_index6);
309 if (si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)
311 (vm, "%U (%s): \n unnumbered, use %U",
312 format_vnet_sw_if_index_name,
313 vnm, si->sw_if_index,
314 (si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? "up" : "dn",
315 format_vnet_sw_if_index_name, vnm, si->unnumbered_sw_if_index);
319 vlib_cli_output (vm, "%U (%s):",
320 format_vnet_sw_if_index_name,
321 vnm, si->sw_if_index,
322 (si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP)
326 /* Display any L2 addressing info */
327 vec_validate (l2m->configs, si->sw_if_index);
328 config = vec_elt_at_index (l2m->configs, si->sw_if_index);
331 u32 bd_id = l2input_main.bd_configs[config->bd_index].bd_id;
332 vlib_cli_output (vm, " l2 bridge bd_id %d%s%d", bd_id,
333 config->bvi ? " bvi shg " : " shg ",
336 else if (config->xconnect)
338 vlib_cli_output (vm, " l2 xconnect %U",
339 format_vnet_sw_if_index_name,
340 vnm, config->output_sw_if_index);
343 /* Display any IP4 addressing info */
345 foreach_ip_interface_address (lm4, ia, si->sw_if_index,
346 1 /* honor unnumbered */,
348 r4 = ip_interface_address_get_address (lm4, ia);
351 vlib_cli_output (vm, " %U/%d table %d",
352 format_ip4_address, r4,
358 vlib_cli_output (vm, " %U/%d",
359 format_ip4_address, r4,
365 /* Display any IP6 addressing info */
367 foreach_ip_interface_address (lm6, ia, si->sw_if_index,
368 1 /* honor unnumbered */,
370 r6 = ip_interface_address_get_address (lm6, ia);
373 vlib_cli_output (vm, " %U/%d table %d",
374 format_ip6_address, r6,
380 vlib_cli_output (vm, " %U/%d",
381 format_ip6_address, r6,
390 vec_foreach (si, sorted_sis)
392 vlib_cli_output (vm, "%U\n", format_vnet_sw_interface, vnm, si);
397 vec_free (sorted_sis);
402 VLIB_CLI_COMMAND (show_sw_interfaces_command, static) = {
403 .path = "show interfaces",
404 .short_help = "show interfaces [address|addr|features|feat] [<if-name1> <if-name2> ...]",
405 .function = show_sw_interfaces,
409 /* Root of all interface commands. */
411 VLIB_CLI_COMMAND (vnet_cli_interface_command, static) = {
413 .short_help = "Interface commands",
418 VLIB_CLI_COMMAND (vnet_cli_set_interface_command, static) = {
419 .path = "set interface",
420 .short_help = "Interface commands",
424 static clib_error_t *
425 clear_interface_counters (vlib_main_t * vm,
426 unformat_input_t * input, vlib_cli_command_t * cmd)
428 vnet_main_t *vnm = vnet_get_main ();
429 vnet_interface_main_t *im = &vnm->interface_main;
430 vlib_simple_counter_main_t *sm;
431 vlib_combined_counter_main_t *cm;
432 static vnet_main_t **my_vnet_mains;
433 int i, j, n_counters;
435 vec_reset_length (my_vnet_mains);
437 for (i = 0; i < vec_len (vnet_mains); i++)
440 vec_add1 (my_vnet_mains, vnet_mains[i]);
443 if (vec_len (vnet_mains) == 0)
444 vec_add1 (my_vnet_mains, vnm);
446 n_counters = vec_len (im->combined_sw_if_counters);
448 for (j = 0; j < n_counters; j++)
450 for (i = 0; i < vec_len (my_vnet_mains); i++)
452 im = &my_vnet_mains[i]->interface_main;
453 cm = im->combined_sw_if_counters + j;
454 vlib_clear_combined_counters (cm);
458 n_counters = vec_len (im->sw_if_counters);
460 for (j = 0; j < n_counters; j++)
462 for (i = 0; i < vec_len (my_vnet_mains); i++)
464 im = &my_vnet_mains[i]->interface_main;
465 sm = im->sw_if_counters + j;
466 vlib_clear_simple_counters (sm);
474 VLIB_CLI_COMMAND (clear_interface_counters_command, static) = {
475 .path = "clear interfaces",
476 .short_help = "Clear interfaces statistics",
477 .function = clear_interface_counters,
482 * Parse subinterface names.
484 * The following subinterface syntax is supported. The first two are for
485 * backwards compatability:
488 * - a subinterface with the name <intf-name>.<id>. The subinterface
489 * is a single dot1q vlan with vlan id <id> and exact-match semantics.
491 * <intf-name> <min_id>-<max_id>
492 * - a set of the above subinterfaces, repeating for each id
493 * in the range <min_id> to <max_id>
495 * In the following, exact-match semantics (i.e. the number of vlan tags on the
496 * packet must match the number of tags in the configuration) are used only if
497 * the keyword exact-match is present. Non-exact match is the default.
499 * <intf-name> <id> dot1q <outer_id> [exact-match]
500 * - a subinterface with the name <intf-name>.<id>. The subinterface
501 * is a single dot1q vlan with vlan id <outer_id>.
503 * <intf-name> <id> dot1q any [exact-match]
504 * - a subinterface with the name <intf-name>.<id>. The subinterface
505 * is a single dot1q vlan with any vlan id.
507 * <intf-name> <id> dot1q <outer_id> inner-dot1q <inner_id> [exact-match]
508 * - a subinterface with the name <intf-name>.<id>. The subinterface
509 * is a double dot1q vlan with outer vlan id <outer_id> and inner vlan id
512 * <intf-name> <id> dot1q <outer_id> inner-dot1q any [exact-match]
513 * - a subinterface with the name <intf-name>.<id>. The subinterface
514 * is a double dot1q vlan with outer vlan id <id> and any inner vlan id.
516 * <intf-name> <id> dot1q any inner-dot1q any [exact-match]
518 * - a subinterface with the name <intf-name>.<id>. The subinterface
519 * is a double dot1q vlan with any outer vlan id and any inner vlan id.
521 * For each of the above CLI, there is a duplicate that uses the keyword
522 * "dot1ad" in place of the first "dot1q". These interfaces use ethertype
523 * 0x88ad in place of 0x8100 for the outer ethertype. Note that for double-
524 * tagged packets the inner ethertype is always 0x8100. Also note that
525 * the dot1q and dot1ad naming spaces are independent, so it is legal to
526 * have both "Gig3/0/0.1 dot1q 100" and "Gig3/0/0.2 dot1ad 100". For example:
528 * <intf-name> <id> dot1ad <outer_id> inner-dot1q <inner_id> [exact-match]
529 * - a subinterface with the name <intf-name>.<id>. The subinterface
530 * is a double dot1ad vlan with outer vlan id <outer_id> and inner vlan
533 * <intf-name> <id> untagged
534 * - a subinterface with the name <intf-name>.<id>. The subinterface
535 * has no vlan tags. Only one can be specified per interface.
537 * <intf-name> <id> default
538 * - a subinterface with the name <intf-name>.<id>. This is associated
539 * with a packet that did not match any other configured subinterface
540 * on this interface. Only one can be specified per interface.
543 static clib_error_t *
544 parse_vlan_sub_interfaces (unformat_input_t * input,
545 vnet_sw_interface_t * template)
547 clib_error_t *error = 0;
548 u32 inner_vlan, outer_vlan;
550 if (unformat (input, "any inner-dot1q any"))
552 template->sub.eth.flags.two_tags = 1;
553 template->sub.eth.flags.outer_vlan_id_any = 1;
554 template->sub.eth.flags.inner_vlan_id_any = 1;
556 else if (unformat (input, "any"))
558 template->sub.eth.flags.one_tag = 1;
559 template->sub.eth.flags.outer_vlan_id_any = 1;
561 else if (unformat (input, "%d inner-dot1q any", &outer_vlan))
563 template->sub.eth.flags.two_tags = 1;
564 template->sub.eth.flags.inner_vlan_id_any = 1;
565 template->sub.eth.outer_vlan_id = outer_vlan;
567 else if (unformat (input, "%d inner-dot1q %d", &outer_vlan, &inner_vlan))
569 template->sub.eth.flags.two_tags = 1;
570 template->sub.eth.outer_vlan_id = outer_vlan;
571 template->sub.eth.inner_vlan_id = inner_vlan;
573 else if (unformat (input, "%d", &outer_vlan))
575 template->sub.eth.flags.one_tag = 1;
576 template->sub.eth.outer_vlan_id = outer_vlan;
580 error = clib_error_return (0, "expected dot1q config, got `%U'",
581 format_unformat_error, input);
585 if (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
587 if (unformat (input, "exact-match"))
589 template->sub.eth.flags.exact_match = 1;
597 static clib_error_t *
598 create_sub_interfaces (vlib_main_t * vm,
599 unformat_input_t * input, vlib_cli_command_t * cmd)
601 vnet_main_t *vnm = vnet_get_main ();
602 clib_error_t *error = 0;
603 u32 hw_if_index, sw_if_index;
604 vnet_hw_interface_t *hi;
605 u32 id, id_min, id_max;
606 vnet_sw_interface_t template;
609 if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
611 error = clib_error_return (0, "unknown interface `%U'",
612 format_unformat_error, input);
616 memset (&template, 0, sizeof (template));
617 template.sub.eth.raw_flags = 0;
619 if (unformat (input, "%d default", &id_min))
622 template.sub.eth.flags.default_sub = 1;
624 else if (unformat (input, "%d untagged", &id_min))
627 template.sub.eth.flags.no_tags = 1;
628 template.sub.eth.flags.exact_match = 1;
630 else if (unformat (input, "%d dot1q", &id_min))
632 /* parse dot1q config */
634 error = parse_vlan_sub_interfaces (input, &template);
638 else if (unformat (input, "%d dot1ad", &id_min))
640 /* parse dot1ad config */
642 template.sub.eth.flags.dot1ad = 1;
643 error = parse_vlan_sub_interfaces (input, &template);
647 else if (unformat (input, "%d-%d", &id_min, &id_max))
649 template.sub.eth.flags.one_tag = 1;
650 template.sub.eth.flags.exact_match = 1;
654 else if (unformat (input, "%d", &id_min))
657 template.sub.eth.flags.one_tag = 1;
658 template.sub.eth.outer_vlan_id = id_min;
659 template.sub.eth.flags.exact_match = 1;
664 error = clib_error_return (0, "expected ID or ID MIN-MAX, got `%U'",
665 format_unformat_error, input);
669 hi = vnet_get_hw_interface (vnm, hw_if_index);
671 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE)
674 clib_error_return (0,
675 "not allowed as %v belong to a BondEthernet interface",
680 for (id = id_min; id <= id_max; id++)
683 vnet_interface_main_t *im = &vnm->interface_main;
684 u64 sup_and_sub_key = ((u64) (hi->sw_if_index) << 32) | (u64) id;
687 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
691 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
692 hi->sw_if_index, id);
696 kp = clib_mem_alloc (sizeof (*kp));
697 *kp = sup_and_sub_key;
699 template.type = VNET_SW_INTERFACE_TYPE_SUB;
700 template.flood_class = VNET_FLOOD_CLASS_NORMAL;
701 template.sup_sw_if_index = hi->sw_if_index;
702 template.sub.id = id;
704 template.sub.eth.outer_vlan_id = id;
706 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
710 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
711 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
712 vlib_cli_output (vm, "%U\n", format_vnet_sw_if_index_name,
713 vnet_get_main (), sw_if_index);
722 * Create vlan subinterfaces
725 * @cliexstart{create sub-interfaces}
727 * To create a vlan subinterface 11 to process packets on 802.1q VLAN id 11, use:
729 * vpp# create sub GigabitEthernet2/0/0 11
731 * This shorthand is equivalent to:
732 * vpp# create sub GigabitEthernet2/0/0 11 dot1q 11 exact-match
734 * You can specify a subinterface number that is different from the vlan id:
735 * vpp# create sub GigabitEthernet2/0/0 11 dot1q 100
737 * You can create qinq and q-in-any interfaces:
738 * vpp# create sub GigabitEthernet2/0/0 11 dot1q 100 inner-dot1q 200
739 * vpp# create sub GigabitEthernet2/0/0 12 dot1q 100 inner-dot1q any
741 * You can also create dot1ad interfaces:
742 * vpp# create sub GigabitEthernet2/0/0 11 dot1ad 11
743 * vpp# create sub GigabitEthernet2/0/0 12 dot1q 100 inner-dot1q 200
745 * Subinterfaces can be configured as either exact-match or non-exact match.
746 * Non-exact match is the CLI default. If exact-match is specified,
747 * packets must have the same number of vlan tags as the configuration.
748 * For non-exact-match, packets must at least that number of tags.
749 * L3 (routed) interfaces must be configured as exact-match.
750 * L2 interfaces are typically configured as non-exact-match.
752 * For example, a packet with outer vlan 100 and inner 200 would match this interface:
753 * vpp# create sub GigabitEthernet2/0/0 5 dot1q 100
755 * but would not match this interface:
756 * vpp# create sub GigabitEthernet2/0/0 5 dot1q 100 exact-match
758 * There are two special subinterfaces that can be configured. Subinterface untagged has no vlan tags:
759 * vpp# create sub GigabitEthernet2/0/0 5 untagged
761 * The subinterface default matches any packet that does not match any other subinterface:
762 * vpp# create sub GigabitEthernet2/0/0 7 default
765 VLIB_CLI_COMMAND (create_sub_interfaces_command, static) = {
766 .path = "create sub-interfaces",
767 .short_help = "create sub-interfaces <nn>[-<nn>] [dot1q|dot1ad|default|untagged]",
768 .function = create_sub_interfaces,
772 static clib_error_t *
773 set_state (vlib_main_t * vm,
774 unformat_input_t * input, vlib_cli_command_t * cmd)
776 vnet_main_t *vnm = vnet_get_main ();
778 u32 sw_if_index, flags;
781 if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
783 error = clib_error_return (0, "unknown interface `%U'",
784 format_unformat_error, input);
788 if (!unformat (input, "%U", unformat_vnet_sw_interface_flags, &flags))
790 error = clib_error_return (0, "unknown flags `%U'",
791 format_unformat_error, input);
795 error = vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
806 * Interface admin up/down
809 * @cliexstart{set interface state}
810 * vpp# set interface state GigabitEthernet2/0/0 up
811 * vpp# set interface state GigabitEthernet2/0/0 down
814 VLIB_CLI_COMMAND (set_state_command, static) = {
815 .path = "set interface state",
816 .short_help = "Set interface state",
817 .function = set_state,
821 static clib_error_t *
822 set_unnumbered (vlib_main_t * vm,
823 unformat_input_t * input, vlib_cli_command_t * cmd)
825 vnet_main_t *vnm = vnet_get_main ();
826 u32 unnumbered_sw_if_index;
827 u32 inherit_from_sw_if_index;
828 vnet_sw_interface_t *si;
832 if (unformat (input, "%U use %U",
833 unformat_vnet_sw_interface, vnm, &unnumbered_sw_if_index,
834 unformat_vnet_sw_interface, vnm, &inherit_from_sw_if_index))
836 else if (unformat (input, "del %U",
837 unformat_vnet_sw_interface, vnm,
838 &unnumbered_sw_if_index))
841 return clib_error_return (0, "parse error '%U'",
842 format_unformat_error, input);
844 si = vnet_get_sw_interface (vnm, unnumbered_sw_if_index);
847 si->flags &= ~(VNET_SW_INTERFACE_FLAG_UNNUMBERED);
848 si->unnumbered_sw_if_index = (u32) ~ 0;
849 ip4_sw_interface_enable_disable (unnumbered_sw_if_index, 0);
850 ip6_sw_interface_enable_disable (unnumbered_sw_if_index, 0);
854 si->flags |= VNET_SW_INTERFACE_FLAG_UNNUMBERED;
855 si->unnumbered_sw_if_index = inherit_from_sw_if_index;
856 ip4_sw_interface_enable_disable (unnumbered_sw_if_index, 1);
857 ip6_sw_interface_enable_disable (unnumbered_sw_if_index, 1);
864 VLIB_CLI_COMMAND (set_unnumbered_command, static) = {
865 .path = "set interface unnumbered",
866 .short_help = "set interface unnumbered [<intfc> use <intfc> | del <intfc>]",
867 .function = set_unnumbered,
873 static clib_error_t *
874 set_hw_class (vlib_main_t * vm,
875 unformat_input_t * input, vlib_cli_command_t * cmd)
877 vnet_main_t *vnm = vnet_get_main ();
878 vnet_interface_main_t *im = &vnm->interface_main;
880 u32 hw_if_index, hw_class_index;
883 if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
885 error = clib_error_return (0, "unknown hardware interface `%U'",
886 format_unformat_error, input);
890 if (!unformat_user (input, unformat_hash_string,
891 im->hw_interface_class_by_name, &hw_class_index))
893 error = clib_error_return (0, "unknown hardware class `%U'",
894 format_unformat_error, input);
898 error = vnet_hw_interface_set_class (vnm, hw_if_index, hw_class_index);
907 VLIB_CLI_COMMAND (set_hw_class_command, static) = {
908 .path = "set interface hw-class",
909 .short_help = "Set interface hardware class",
910 .function = set_hw_class,
914 static clib_error_t *
915 vnet_interface_cli_init (vlib_main_t * vm)
920 VLIB_INIT_FUNCTION (vnet_interface_cli_init);
922 static clib_error_t *
923 renumber_interface_command_fn (vlib_main_t * vm,
924 unformat_input_t * input,
925 vlib_cli_command_t * cmd)
928 u32 new_dev_instance;
929 vnet_main_t *vnm = vnet_get_main ();
932 if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
933 return clib_error_return (0, "unknown hardware interface `%U'",
934 format_unformat_error, input);
936 if (!unformat (input, "%d", &new_dev_instance))
937 return clib_error_return (0, "new dev instance missing");
939 rv = vnet_interface_name_renumber (hw_if_index, new_dev_instance);
947 return clib_error_return (0, "vnet_interface_name_renumber returned %d",
957 VLIB_CLI_COMMAND (renumber_interface_command, static) = {
958 .path = "renumber interface",
959 .short_help = "renumber interface <if-name> <new-dev-instance>",
960 .function = renumber_interface_command_fn,
964 static clib_error_t *
965 promiscuous_cmd (vlib_main_t * vm,
966 unformat_input_t * input, vlib_cli_command_t * cmd)
968 vnet_main_t *vnm = vnet_get_main ();
970 u32 flags = ETHERNET_INTERFACE_FLAG_ACCEPT_ALL;
971 ethernet_main_t *em = ðernet_main;
972 ethernet_interface_t *eif;
974 if (unformat (input, "on %U",
975 unformat_vnet_hw_interface, vnm, &hw_if_index))
977 else if (unformat (input, "off %U",
978 unformat_ethernet_interface, vnm, &hw_if_index))
981 return clib_error_return (0, "unknown input `%U'",
982 format_unformat_error, input);
984 eif = ethernet_get_interface (em, hw_if_index);
986 return clib_error_return (0, "not supported");
988 ethernet_set_flags (vnm, hw_if_index, flags);
993 VLIB_CLI_COMMAND (set_interface_promiscuous_cmd, static) = {
994 .path = "set interface promiscuous",
995 .short_help = "set interface promiscuous [on | off] <intfc>",
996 .function = promiscuous_cmd,
1000 static clib_error_t *
1001 mtu_cmd (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd)
1003 vnet_main_t *vnm = vnet_get_main ();
1004 u32 hw_if_index, mtu;
1005 u32 flags = ETHERNET_INTERFACE_FLAG_MTU;
1006 ethernet_main_t *em = ðernet_main;
1008 if (unformat (input, "%d %U", &mtu,
1009 unformat_vnet_hw_interface, vnm, &hw_if_index))
1011 vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, hw_if_index);
1012 ethernet_interface_t *eif = ethernet_get_interface (em, hw_if_index);
1015 return clib_error_return (0, "not supported");
1017 if (mtu < hi->min_supported_packet_bytes)
1018 return clib_error_return (0, "Invalid mtu (%d): "
1019 "must be >= min pkt bytes (%d)", mtu,
1020 hi->min_supported_packet_bytes);
1022 if (mtu > hi->max_supported_packet_bytes)
1023 return clib_error_return (0, "Invalid mtu (%d): must be <= (%d)", mtu,
1024 hi->max_supported_packet_bytes);
1026 if (hi->max_packet_bytes != mtu)
1028 hi->max_packet_bytes = mtu;
1029 ethernet_set_flags (vnm, hw_if_index, flags);
1033 return clib_error_return (0, "unknown input `%U'",
1034 format_unformat_error, input);
1039 VLIB_CLI_COMMAND (set_interface_mtu_cmd, static) = {
1040 .path = "set interface mtu",
1041 .short_help = "set interface mtu <value> <intfc>",
1042 .function = mtu_cmd,
1046 static clib_error_t *
1047 set_interface_mac_address (vlib_main_t * vm, unformat_input_t * input,
1048 vlib_cli_command_t * cmd)
1050 vnet_main_t *vnm = vnet_get_main ();
1051 clib_error_t *error = 0;
1052 u32 sw_if_index = ~0;
1055 if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
1057 error = clib_error_return (0, "unknown interface `%U'",
1058 format_unformat_error, input);
1061 if (!unformat_user (input, unformat_ethernet_address, &mac))
1063 error = clib_error_return (0, "expected mac address `%U'",
1064 format_unformat_error, input);
1067 error = vnet_hw_interface_change_mac_address (vnm, sw_if_index, mac);
1073 * The '<em>set interface mac address </em>' command allows to set MAC address of given interface.
1074 * In case of NIC interfaces the one has to support MAC address change. A side effect of MAC address
1075 * change are changes of MAC addresses in FIB tables (ipv4 and ipv6).
1079 * Example of how to change MAC Address of interface:
1080 * @cliexcmd{set interface mac address GigabitEthernet0/8/0 aa:bb:cc:dd:ee:01}
1081 * @cliexcmd{set interface mac address host-vpp0 aa:bb:cc:dd:ee:02}
1082 * @cliexcmd{set interface mac address tap-0 aa:bb:cc:dd:ee:03}
1083 * @cliexcmd{set interface mac address pg0 aa:bb:cc:dd:ee:04}
1087 VLIB_CLI_COMMAND (set_interface_mac_address_cmd, static) = {
1088 .path = "set interface mac address",
1089 .short_help = "set interface mac address <intfc> <mac-address>",
1090 .function = set_interface_mac_address,
1095 * fd.io coding-style-patch-verification: ON
1098 * eval: (c-set-style "gnu")