FD.io VPP  v16.06
Vector Packet Processing
interface_cli.c
Go to the documentation of this file.
1 /*
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:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
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.
14  */
15 /*
16  * interface_cli.c: interface CLI
17  *
18  * Copyright (c) 2008 Eliot Dresselhaus
19  *
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:
27  *
28  * The above copyright notice and this permission notice shall be
29  * included in all copies or substantial portions of the Software.
30  *
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.
38  */
39 
40 #include <vnet/vnet.h>
41 #include <vnet/ip/ip.h>
42 #include <vppinfra/bitmap.h>
43 
44 static int compare_interface_names (void *a1, void *a2)
45 {
46  u32 * hi1 = a1;
47  u32 * hi2 = a2;
48 
49  return vnet_hw_interface_compare (vnet_get_main(), *hi1, *hi2);
50 }
51 
52 static clib_error_t *
54  unformat_input_t * input,
55  vlib_cli_command_t * cmd)
56 {
57  clib_error_t * error = 0;
58  vnet_main_t * vnm = vnet_get_main();
61  u32 hw_if_index, * hw_if_indices = 0;
62  int i, verbose = -1, is_show, show_bond = 0;
63 
64  is_show = strstr (cmd->path, "show") != 0;
66  {
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);
70 
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);
74 
75  else if (unformat (input, "verbose"))
76  verbose = 1; /* this is also the default */
77 
78  else if (unformat (input, "detail"))
79  verbose = 2;
80 
81  else if (unformat (input, "brief"))
82  verbose = 0;
83 
84  else if (unformat (input, "bond"))
85  {
86  show_bond = 1;
87  if (verbose < 0) verbose = 0; /* default to brief for link bonding */
88  }
89 
90  else
91  {
92  error = clib_error_return (0, "unknown input `%U'",
93  format_unformat_error, input);
94  goto done;
95  }
96  }
97 
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));
102 
103  if (verbose < 0) verbose = 1; /* default to verbose (except bond) */
104 
105  if (is_show)
106  {
107  /* Sort by name. */
109 
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++)
112  {
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,
116  hi, verbose);
117  else if ((hi->bond_info) &&
119  { /* show only bonded interface and all its slave interfaces */
120  int hw_idx;
121  vnet_hw_interface_t * shi;
122  vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm,
123  hi, verbose);
124  clib_bitmap_foreach (hw_idx, hi->bond_info,
125  ({
126  shi = vnet_get_hw_interface(vnm, hw_idx);
127  vlib_cli_output (vm, "%U\n",
128  format_vnet_hw_interface, vnm, shi, verbose);
129  }));
130  }
131  }
132  }
133  else
134  {
135  for (i = 0; i < vec_len (hw_if_indices); i++)
136  {
137  vnet_device_class_t * dc;
138 
139  hi = vnet_get_hw_interface (vnm, hw_if_indices[i]);
141 
142  if (dc->clear_counters)
143  dc->clear_counters (hi->dev_instance);
144  }
145  }
146 
147  done:
148  vec_free (hw_if_indices);
149  return error;
150 }
151 
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,
156 };
157 
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,
162 };
163 
164 static int sw_interface_name_compare (void *a1, void *a2)
165 {
166  vnet_sw_interface_t *si1 = a1;
167  vnet_sw_interface_t *si2 = a2;
168 
170  si1->sw_if_index, si2->sw_if_index);
171 }
172 
173 static clib_error_t *
175  unformat_input_t * input,
176  vlib_cli_command_t * cmd)
177 {
178  clib_error_t * error = 0;
179  vnet_main_t * vnm = vnet_get_main();
181  vnet_sw_interface_t * si, * sorted_sis = 0;
182  u8 show_addresses = 0;
183 
185  {
186  u32 sw_if_index;
187 
188  /* See if user wants to show specific interface */
189  if (unformat (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
190  {
191  si = pool_elt_at_index (im->sw_interfaces, sw_if_index);
192  vec_add1 (sorted_sis, si[0]);
193  }
194 
195  else if (unformat (input, "address") || unformat (input, "addr"))
196  show_addresses = 1;
197 
198  else
199  {
200  error = clib_error_return (0, "unknown input `%U'",
201  format_unformat_error, input);
202  goto done;
203  }
204  }
205 
206  if (!show_addresses)
207  vlib_cli_output (vm, "%U\n", format_vnet_sw_interface, vnm, 0);
208 
209  if (vec_len (sorted_sis) == 0) /* Get all interfaces */
210  {
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]); }));
215 
216  /* Sort by name. */
218  }
219 
220  if (show_addresses)
221  {
222  vec_foreach (si, sorted_sis)
223  {
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;
230  ip4_address_t * r4;
231  ip6_address_t * r6;
232  u32 fib_index4 = 0, fib_index6 = 0;
233  ip4_fib_t * fib4;
234  ip6_fib_t * fib6;
235  l2_input_config_t * config;
236 
238  fib_index4 = vec_elt (im4->fib_index_by_sw_if_index,
239  si->sw_if_index);
240 
242  fib_index6 = vec_elt (im6->fib_index_by_sw_if_index,
243  si->sw_if_index);
244 
245  fib4 = vec_elt_at_index (im4->fibs, fib_index4);
246  fib6 = vec_elt_at_index (im6->fibs, fib_index6);
247 
250  (vm, "%U (%s): \n unnumbered, use %U",
252  vnm, si->sw_if_index,
253  (si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? "up" : "dn",
255  vnm, si->unnumbered_sw_if_index);
256 
257  else
258  {
259  vlib_cli_output (vm, "%U (%s):",
261  vnm, si->sw_if_index,
263  ? "up" : "dn");
264  }
265 
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);
269  if (config->bridge)
270  {
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);
274  }
275  else if (config->xconnect)
276  {
277  vlib_cli_output (vm, " l2 xconnect %U",
279  vnm, config->output_sw_if_index);
280  }
281 
282  /* Display any IP4 addressing info */
284  1 /* honor unnumbered */,
285  ({
286  r4 = ip_interface_address_get_address (lm4, ia);
287  if (fib4->table_id)
288  {
289  vlib_cli_output (vm, " %U/%d table %d",
290  format_ip4_address, r4,
291  ia->address_length,
292  fib4->table_id);
293  }
294  else
295  {
296  vlib_cli_output (vm, " %U/%d",
297  format_ip4_address, r4,
298  ia->address_length);
299  }
300  }));
301 
302  /* Display any IP6 addressing info */
304  1 /* honor unnumbered */,
305  ({
306  r6 = ip_interface_address_get_address (lm6, ia);
307  if (fib6->table_id)
308  {
309  vlib_cli_output (vm, " %U/%d table %d",
310  format_ip6_address, r6,
311  ia->address_length,
312  fib6->table_id);
313  }
314  else
315  {
316  vlib_cli_output (vm, " %U/%d",
317  format_ip6_address, r6,
318  ia->address_length);
319  }
320  }));
321  }
322  }
323  else
324  {
325  vec_foreach (si, sorted_sis)
326  {
327  vlib_cli_output (vm, "%U\n", format_vnet_sw_interface, vnm, si);
328  }
329  }
330 
331  done:
332  vec_free (sorted_sis);
333  return error;
334 }
335 
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,
340 };
341 
342 /* Root of all interface commands. */
343 VLIB_CLI_COMMAND (vnet_cli_interface_command, static) = {
344  .path = "interface",
345  .short_help = "Interface commands",
346 };
347 
348 VLIB_CLI_COMMAND (vnet_cli_set_interface_command, static) = {
349  .path = "set interface",
350  .short_help = "Interface commands",
351 };
352 
353 static clib_error_t *
355  unformat_input_t * input,
356  vlib_cli_command_t * cmd)
357 {
358  vnet_main_t * vnm = vnet_get_main();
362  static vnet_main_t ** my_vnet_mains;
363  int i, j, n_counters;
364 
365  vec_reset_length (my_vnet_mains);
366 
367  for (i = 0; i < vec_len (vnet_mains); i++)
368  {
369  if (vnet_mains[i])
370  vec_add1 (my_vnet_mains, vnet_mains[i]);
371  }
372 
373  if (vec_len (vnet_mains) == 0)
374  vec_add1 (my_vnet_mains, vnm);
375 
376  n_counters = vec_len (im->combined_sw_if_counters);
377 
378  for (j = 0; j < n_counters; j++)
379  {
380  for (i = 0; i < vec_len(my_vnet_mains); i++)
381  {
382  im = &my_vnet_mains[i]->interface_main;
383  cm = im->combined_sw_if_counters + j;
385  }
386  }
387 
388  n_counters = vec_len (im->sw_if_counters);
389 
390  for (j = 0; j < n_counters; j++)
391  {
392  for (i = 0; i < vec_len(my_vnet_mains); i++)
393  {
394  im = &my_vnet_mains[i]->interface_main;
395  sm = im->sw_if_counters + j;
397  }
398  }
399 
400  return 0;
401 }
402 
403 VLIB_CLI_COMMAND (clear_interface_counters_command, static) = {
404  .path = "clear interfaces",
405  .short_help = "Clear interfaces statistics",
406  .function = clear_interface_counters,
407 };
408 
409 // The following subinterface syntax is supported. The first two are for
410 // backwards compatability:
411 //
412 // <intf-name> <id>
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.
415 //
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>
419 //
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.
423 //
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>.
427 //
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.
431 //
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
435 // <inner_id>.
436 //
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.
440 //
441 // <intf-name> <id> dot1q any inner-dot1q any [exact-match]
442 //
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.
445 //
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:
452 //
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
456 // id <inner_id>.
457 //
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.
461 //
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.
466 
467 
468 static clib_error_t *
470  vnet_sw_interface_t * template)
471 {
472  clib_error_t * error = 0;
473  u32 inner_vlan, outer_vlan;
474 
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;
493  } else {
494  error = clib_error_return (0, "expected dot1q config, got `%U'",
495  format_unformat_error, input);
496  goto done;
497  }
498 
500  if (unformat (input, "exact-match")) {
501  template->sub.eth.flags.exact_match = 1;
502  }
503  }
504 
505  done:
506  return error;
507 }
508 
509 static clib_error_t *
511  unformat_input_t * input,
512  vlib_cli_command_t * cmd)
513 {
514  vnet_main_t * vnm = vnet_get_main();
515  clib_error_t * error = 0;
516  u32 hw_if_index, sw_if_index;
518  u32 id, id_min, id_max;
519  vnet_sw_interface_t template;
520 
521  hw_if_index = ~0;
522  if (! unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
523  {
524  error = clib_error_return (0, "unknown interface `%U'",
525  format_unformat_error, input);
526  goto done;
527  }
528 
529  memset (&template, 0, sizeof (template));
530  template.sub.eth.raw_flags = 0;
531 
532  if (unformat (input, "%d default", &id_min)) {
533  id_max = id_min;
534  template.sub.eth.flags.default_sub = 1;
535  } else if (unformat (input, "%d untagged", &id_min)) {
536  id_max = 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
541  id_max = id_min;
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
546  id_max = id_min;
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;
554  if (id_min > id_max)
555  goto id_error;
556  } else if (unformat (input, "%d", &id_min)) {
557  id_max = 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;
561  } else {
562  id_error:
563  error = clib_error_return (0, "expected ID or ID MIN-MAX, got `%U'",
564  format_unformat_error, input);
565  goto done;
566  }
567 
568  /*
569  if (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
570  error = clib_error_return (0, "unexpected text `%U'",
571  format_unformat_error, input);
572  goto done;
573  }
574  */
575 
576  hi = vnet_get_hw_interface (vnm, hw_if_index);
577 
579  error = clib_error_return (
580  0, "not allowed as %v belong to a BondEthernet interface", hi->name);
581  goto done;
582  }
583 
584  for (id = id_min; id <= id_max; id++)
585  {
586  uword * p;
588  u64 sup_and_sub_key = ((u64)(hi->sw_if_index) << 32) |
589  (u64) id;
590  u64 * kp;
591 
592  p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
593  if (p)
594  {
595  if (CLIB_DEBUG > 0)
596  clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
597  hi->sw_if_index, id);
598  continue;
599  }
600 
601  kp = clib_mem_alloc (sizeof (*kp));
602  *kp = sup_and_sub_key;
603 
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  }
612 
613  if (error)
614  goto done;
615 
616  done:
617  return error;
618 }
619 
620 VLIB_CLI_COMMAND (create_sub_interfaces_command, static) = {
621  .path = "create sub-interface",
622  .short_help = "create sub-interfaces <nn>[-<nn>] [dot1q|dot1ad|default|untagged]",
623  .function = create_sub_interfaces,
624 };
625 
626 static clib_error_t *
628  unformat_input_t * input,
629  vlib_cli_command_t * cmd)
630 {
631  vnet_main_t * vnm = vnet_get_main();
632  clib_error_t * error;
633  u32 sw_if_index, flags;
634 
635  sw_if_index = ~0;
636  if (! unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
637  {
638  error = clib_error_return (0, "unknown interface `%U'",
639  format_unformat_error, input);
640  goto done;
641  }
642 
643  if (! unformat (input, "%U", unformat_vnet_sw_interface_flags, &flags))
644  {
645  error = clib_error_return (0, "unknown flags `%U'",
646  format_unformat_error, input);
647  goto done;
648  }
649 
650  error = vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
651  if (error)
652  goto done;
653 
654  done:
655  return error;
656 }
657 
658 VLIB_CLI_COMMAND (set_state_command, static) = {
659  .path = "set interface state",
660  .short_help = "Set interface state",
661  .function = set_state,
662 };
663 
664 static clib_error_t *
666  unformat_input_t * input,
667  vlib_cli_command_t * cmd)
668 {
669  vnet_main_t * vnm = vnet_get_main();
670  u32 unnumbered_sw_if_index;
671  u32 inherit_from_sw_if_index;
672  vnet_sw_interface_t * si;
673  int is_set = 0;
674  int is_del = 0;
675 
677  {
678 
679  if (unformat (input, "%U use %U",
680  unformat_vnet_sw_interface, vnm, &unnumbered_sw_if_index,
681  unformat_vnet_sw_interface, vnm, &inherit_from_sw_if_index))
682  is_set = 1;
683  else if (unformat (input, "del %U",
685  vnm, &unnumbered_sw_if_index))
686  is_del = 1;
687  else
688  {
689  if (is_set || is_del)
690  break;
691  else
692  return clib_error_return
693  (0, "parse error '%U'", format_unformat_error, input);
694  }
695  }
696 
697  si = vnet_get_sw_interface (vnm, unnumbered_sw_if_index);
698  if (is_del) {
700  si->unnumbered_sw_if_index = (u32)~0;
701  } else {
703  si->unnumbered_sw_if_index = inherit_from_sw_if_index;
704  }
705 
706  return 0;
707 }
708 
709 VLIB_CLI_COMMAND (set_unnumbered_command, static) = {
710  .path = "set interface unnumbered",
711  .short_help = "set interface unnumbered [<intfc> use <intfc>][del <intfc>]",
712  .function = set_unnumbered,
713 };
714 
715 
716 
717 static clib_error_t *
719  unformat_input_t * input,
720  vlib_cli_command_t * cmd)
721 {
722  vnet_main_t * vnm = vnet_get_main();
724  clib_error_t * error;
725  u32 hw_if_index, hw_class_index;
726 
727  hw_if_index = ~0;
728  if (! unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
729  {
730  error = clib_error_return (0, "unknown hardware interface `%U'",
731  format_unformat_error, input);
732  goto done;
733  }
734 
735  if (! unformat_user (input, unformat_hash_string,
736  im->hw_interface_class_by_name, &hw_class_index))
737  {
738  error = clib_error_return (0, "unknown hardware class `%U'",
739  format_unformat_error, input);
740  goto done;
741  }
742 
743  error = vnet_hw_interface_set_class (vnm, hw_if_index, hw_class_index);
744  if (error)
745  goto done;
746 
747  done:
748  return error;
749 }
750 
751 VLIB_CLI_COMMAND (set_hw_class_command, static) = {
752  .path = "set interface hw-class",
753  .short_help = "Set interface hardware class",
754  .function = set_hw_class,
755 };
756 
758 { return 0; }
759 
761 
762 static clib_error_t *
764  unformat_input_t * input,
765  vlib_cli_command_t * cmd)
766 {
767  u32 hw_if_index;
768  u32 new_dev_instance;
769  vnet_main_t * vnm = vnet_get_main();
770  int rv;
771 
772  if (! unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
773  return clib_error_return (0, "unknown hardware interface `%U'",
774  format_unformat_error, input);
775 
776  if (! unformat (input, "%d", &new_dev_instance))
777  return clib_error_return (0, "new dev instance missing");
778 
779  rv = vnet_interface_name_renumber (hw_if_index, new_dev_instance);
780 
781  switch (rv)
782  {
783  case 0:
784  break;
785 
786  default:
787  return clib_error_return (0, "vnet_interface_name_renumber returned %d",
788  rv);
789 
790  }
791 
792  return 0;
793 }
794 
795 
796 VLIB_CLI_COMMAND (renumber_interface_command, static) = {
797  .path = "renumber interface",
798  .short_help = "renumber interface <if-name> <new-dev-instance>",
799  .function = renumber_interface_command_fn,
800 };
801 
802 static clib_error_t *
804  unformat_input_t * input,
805  vlib_cli_command_t * cmd)
806 {
807  vnet_main_t * vnm = vnet_get_main();
808  u32 hw_if_index;
811  ethernet_interface_t * eif;
812 
813  if (unformat (input, "on %U",
814  unformat_vnet_hw_interface, vnm, &hw_if_index))
815  ;
816  else if (unformat (input, "off %U",
817  unformat_ethernet_interface, vnm, &hw_if_index))
818  flags = 0;
819  else
820  return clib_error_return (0, "unknown input `%U'",
821  format_unformat_error, input);
822 
823  eif = ethernet_get_interface (em, hw_if_index);
824  if (!eif)
825  return clib_error_return (0, "not supported");
826 
827  ethernet_set_flags (vnm, hw_if_index, flags);
828  return 0;
829 }
830 
831 VLIB_CLI_COMMAND (set_interface_promiscuous_cmd, static) = {
832  .path = "set interface promiscuous",
833  .short_help = "set interface promiscuous [on | off] <intfc>",
834  .function = promiscuous_cmd,
835 };
836 
837 static clib_error_t *
839 {
840  vnet_main_t * vnm = vnet_get_main();
841  u32 hw_if_index, mtu;
844 
845  if (unformat (input, "%d %U", &mtu,
846  unformat_vnet_hw_interface, vnm, &hw_if_index))
847  {
848  vnet_hw_interface_t * hi = vnet_get_hw_interface (vnm, hw_if_index);
849  ethernet_interface_t * eif = ethernet_get_interface (em, hw_if_index);
850 
851  if (!eif)
852  return clib_error_return (0, "not supported");
853 
854  if (mtu < hi->min_supported_packet_bytes)
855  return clib_error_return (0, "Invalid mtu (%d): "
856  "must be >= min pkt bytes (%d)", mtu,
858 
859  if (mtu > hi->max_supported_packet_bytes)
860  return clib_error_return (0, "Invalid mtu (%d): must be <= (%d)", mtu,
862 
863  if (hi->max_packet_bytes != mtu)
864  {
865  hi->max_packet_bytes = mtu;
866  ethernet_set_flags (vnm, hw_if_index, flags);
867  }
868  }
869  else
870  return clib_error_return (0, "unknown input `%U'",
871  format_unformat_error, input);
872  return 0;
873 }
874 
875 VLIB_CLI_COMMAND (set_interface_mtu_cmd, static) = {
876  .path = "set interface mtu",
877  .short_help = "set interface mtu <value> <intfc>",
878  .function = mtu_cmd,
879 };
880 
unformat_function_t unformat_vnet_hw_interface
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:394
#define foreach_ip_interface_address(lm, a, sw_if_index, loop, body)
Definition: lookup.h:534
static clib_error_t * clear_interface_counters(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
#define VNET_SW_INTERFACE_FLAG_UNNUMBERED
Definition: interface.h:380
vmrglw vmrglh hi
format_function_t format_vnet_sw_interface
static clib_error_t * create_sub_interfaces(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
#define hash_set(h, key, value)
Definition: hash.h:237
l2_input_config_t * configs
Definition: l2_input.h:63
sll srl srl sll sra u16x4 i
Definition: vector_sse2.h:267
static clib_error_t * promiscuous_cmd(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
static clib_error_t * set_hw_class(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
uword unformat(unformat_input_t *i, char *fmt,...)
Definition: unformat.c:942
static int sw_interface_name_compare(void *a1, void *a2)
static clib_error_t * set_state(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
unformat_function_t unformat_hash_string
Definition: hash.h:638
vnet_interface_main_t interface_main
Definition: vnet.h:62
#define UNFORMAT_END_OF_INPUT
Definition: format.h:142
vnet_main_t ** vnet_mains
Definition: vnet.h:82
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:480
word vnet_sw_interface_compare(vnet_main_t *vnm, uword sw_if_index0, uword sw_if_index1)
Definition: interface.c:908
int vnet_interface_name_renumber(u32 sw_if_index, u32 new_show_dev_instance)
Definition: interface.c:1028
static clib_error_t * renumber_interface_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
#define hash_set_mem(h, key, value)
Definition: hash.h:257
ip_lookup_main_t lookup_main
Definition: ip4.h:129
uword * sub_interface_sw_if_index_by_id
Definition: interface.h:316
u32 * fib_index_by_sw_if_index
Definition: ip4.h:137
unformat_function_t unformat_vnet_sw_interface
struct _vnet_device_class vnet_device_class_t
format_function_t format_vnet_sw_if_index_name
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
always_inline uword unformat_check_input(unformat_input_t *i)
Definition: format.h:168
ethernet_main_t ethernet_main
Definition: ethernet.h:226
vnet_main_t * vnet_get_main(void)
Definition: misc.c:45
format_function_t format_vnet_hw_interface
uword flags
Definition: error.h:82
void vlib_clear_combined_counters(vlib_combined_counter_main_t *cm)
Definition: counter.c:65
#define pool_foreach(VAR, POOL, BODY)
Definition: pool.h:328
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:109
u32 output_sw_if_index
Definition: l2_input.h:33
#define vec_new(T, N)
Create new vector of given type and length (unspecified alignment, no header).
Definition: vec.h:268
vlib_combined_counter_main_t * combined_sw_if_counters
Definition: interface.h:458
static clib_error_t * parse_vlan_sub_interfaces(unformat_input_t *input, vnet_sw_interface_t *template)
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
always_inline uword pool_elts(void *v)
Definition: pool.h:97
#define clib_warning(format, args...)
Definition: error.h:59
unsigned long u64
Definition: types.h:89
uword unformat_user(unformat_input_t *input, unformat_function_t *func,...)
Definition: unformat.c:953
static clib_error_t * set_unnumbered(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
ip6_fib_t * fibs
Definition: ip6.h:143
static clib_error_t * mtu_cmd(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
u32 max_supported_packet_bytes
Definition: interface.h:299
vnet_hw_interface_t * hw_interfaces
Definition: interface.h:435
#define clib_bitmap_foreach(i, ai, body)
Definition: bitmap.h:308
#define pool_elt_at_index(p, i)
Definition: pool.h:346
uword * sw_if_index_by_sup_and_sub
Definition: interface.h:452
static clib_error_t * show_sw_interfaces(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
vlib_simple_counter_main_t * sw_if_counters
Definition: interface.h:457
word vnet_hw_interface_compare(vnet_main_t *vnm, uword hw_if_index0, uword hw_if_index1)
Definition: interface.c:922
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:538
static int compare_interface_names(void *a1, void *a2)
Definition: interface_cli.c:44
uword * hw_interface_class_by_name
Definition: interface.h:445
#define VNET_HW_INTERFACE_BOND_INFO_SLAVE
Definition: interface.h:327
always_inline void * clib_mem_alloc(uword size)
Definition: mem.h:109
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:298
Definition: ip6.h:62
Definition: ip4.h:47
#define ETHERNET_INTERFACE_FLAG_MTU
Definition: ethernet.h:86
#define ETHERNET_INTERFACE_FLAG_ACCEPT_ALL
Definition: ethernet.h:81
always_inline vnet_hw_interface_t * vnet_get_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
static clib_error_t * show_or_clear_hw_interfaces(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: interface_cli.c:53
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:150
#define VNET_SW_INTERFACE_FLAG_ADMIN_UP
Definition: interface.h:373
unsigned int u32
Definition: types.h:88
ip4_fib_t * fibs
Definition: ip4.h:132
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:87
ip6_main_t ip6_main
Definition: ip6_forward.c:2490
ip_lookup_main_t lookup_main
Definition: ip6.h:135
char * path
Definition: cli.h:91
uword unformat_ethernet_interface(unformat_input_t *input, va_list *args)
Definition: interface.c:136
u64 uword
Definition: types.h:112
#define vec_elt(v, i)
Get vector value at index i.
l2input_main_t l2input_main
Definition: l2_input.c:72
ethernet_interface_t * ethernet_get_interface(ethernet_main_t *em, u32 hw_if_index)
Definition: interface.c:451
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
unsigned char u8
Definition: types.h:56
always_inline vnet_sw_interface_t * vnet_get_sw_interface(vnet_main_t *vnm, u32 sw_if_index)
unformat_function_t unformat_vnet_sw_interface_flags
static clib_error_t * vnet_interface_cli_init(vlib_main_t *vm)
#define vec_sort_with_function(vec, f)
Sort a vector using the supplied element comparison function.
Definition: vec.h:898
vnet_sw_interface_t * sw_interfaces
Definition: interface.h:449
l2_bridge_domain_t * bd_configs
Definition: l2_input.h:66
#define hash_get_mem(h, key)
Definition: hash.h:251
u32 min_supported_packet_bytes
Definition: interface.h:296
void vlib_clear_simple_counters(vlib_simple_counter_main_t *cm)
Definition: counter.c:42
ip4_main_t ip4_main
Definition: ip4_forward.c:1394
#define vec_foreach(var, vec)
Vector iterator.
clib_error_t * vnet_sw_interface_set_flags(vnet_main_t *vnm, u32 sw_if_index, u32 flags)
Definition: interface.c:462
vnet_device_class_t * device_classes
Definition: interface.h:442
#define clib_error_return(e, args...)
Definition: error.h:112
struct _unformat_input_t unformat_input_t
clib_error_t * vnet_create_sw_interface(vnet_main_t *vnm, vnet_sw_interface_t *template, u32 *sw_if_index)
Definition: interface.c:513
u32 flags
Definition: vhost-user.h:73
u32 * fib_index_by_sw_if_index
Definition: ip6.h:148
u32 ethernet_set_flags(vnet_main_t *vnm, u32 hw_if_index, u32 flags)
Definition: interface.c:243
clib_error_t * vnet_hw_interface_set_class(vnet_main_t *vnm, u32 hw_if_index, u32 hw_class_index)
Definition: interface.c:874