blob: 627af6f2b0dd38525283b8c28e022ac790c3a9f1 [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
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 */
Chris Luke16bcf7d2016-09-01 14:31:46 -040039/**
40 * @file
Billy McFalle9bac692017-08-11 14:05:11 -040041 * @brief Interface CLI.
42 *
43 * Source code for several CLI interface commands.
44 *
Chris Luke16bcf7d2016-09-01 14:31:46 -040045 */
Ed Warnickecb9cada2015-12-08 15:45:58 -070046#include <vnet/vnet.h>
47#include <vnet/ip/ip.h>
John Lobcebbb92016-04-05 15:47:43 -040048#include <vppinfra/bitmap.h>
Neale Ranns0bfe5d82016-08-25 15:29:12 +010049#include <vnet/fib/ip4_fib.h>
50#include <vnet/fib/ip6_fib.h>
Eyal Bari942402b2017-07-26 11:57:04 +030051#include <vnet/l2/l2_output.h>
52#include <vnet/l2/l2_input.h>
Neale Rannsba4a5bf2020-01-09 06:43:14 +000053#include <vnet/classify/vnet_classify.h>
Damjan Marion94100532020-11-06 23:25:57 +010054#include <vnet/interface/rx_queue_funcs.h>
Mohsin Kazmi005605f2021-05-24 18:33:50 +020055#include <vnet/interface/tx_queue_funcs.h>
Mohsin Kazmi0d05c0d2021-11-09 17:44:10 +000056#include <vnet/hash/hash.h>
Dave Barachba868bb2016-08-08 09:51:21 -040057static int
58compare_interface_names (void *a1, void *a2)
Ed Warnickecb9cada2015-12-08 15:45:58 -070059{
Dave Barachba868bb2016-08-08 09:51:21 -040060 u32 *hi1 = a1;
61 u32 *hi2 = a2;
Ed Warnickecb9cada2015-12-08 15:45:58 -070062
Dave Barachba868bb2016-08-08 09:51:21 -040063 return vnet_hw_interface_compare (vnet_get_main (), *hi1, *hi2);
Ed Warnickecb9cada2015-12-08 15:45:58 -070064}
65
66static clib_error_t *
67show_or_clear_hw_interfaces (vlib_main_t * vm,
68 unformat_input_t * input,
Benoît Ganne17814d72020-07-24 09:57:11 +020069 vlib_cli_command_t * cmd, int is_show)
Ed Warnickecb9cada2015-12-08 15:45:58 -070070{
Dave Barachba868bb2016-08-08 09:51:21 -040071 clib_error_t *error = 0;
Vratko Polak34149772022-03-31 12:32:10 +020072 unformat_input_t _line_input, *line_input = &_line_input;
Dave Barachba868bb2016-08-08 09:51:21 -040073 vnet_main_t *vnm = vnet_get_main ();
74 vnet_interface_main_t *im = &vnm->interface_main;
75 vnet_hw_interface_t *hi;
76 u32 hw_if_index, *hw_if_indices = 0;
Benoît Ganne17814d72020-07-24 09:57:11 +020077 int i, verbose = -1, show_bond = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070078
Vratko Polak34149772022-03-31 12:32:10 +020079 if (!unformat_user (input, unformat_line_input, line_input))
Mohammed Hawari83caa622022-08-08 10:31:11 +020080 goto skip_unformat;
Vratko Polak34149772022-03-31 12:32:10 +020081
82 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -070083 {
84 /* See if user wants to show a specific interface. */
Vratko Polak34149772022-03-31 12:32:10 +020085 if (unformat (line_input, "%U", unformat_vnet_hw_interface, vnm,
86 &hw_if_index))
Dave Barachba868bb2016-08-08 09:51:21 -040087 vec_add1 (hw_if_indices, hw_if_index);
John Lobcebbb92016-04-05 15:47:43 -040088
Sean Hope679ea792016-02-22 15:12:01 -050089 /* See if user wants to show an interface with a specific hw_if_index. */
Vratko Polak34149772022-03-31 12:32:10 +020090 else if (unformat (line_input, "%u", &hw_if_index))
Dave Barachba868bb2016-08-08 09:51:21 -040091 vec_add1 (hw_if_indices, hw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -070092
Vratko Polak34149772022-03-31 12:32:10 +020093 else if (unformat (line_input, "verbose"))
Dave Barachba868bb2016-08-08 09:51:21 -040094 verbose = 1; /* this is also the default */
Ed Warnickecb9cada2015-12-08 15:45:58 -070095
Vratko Polak34149772022-03-31 12:32:10 +020096 else if (unformat (line_input, "detail"))
Ed Warnickecb9cada2015-12-08 15:45:58 -070097 verbose = 2;
98
Vratko Polak34149772022-03-31 12:32:10 +020099 else if (unformat (line_input, "brief"))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700100 verbose = 0;
101
Vratko Polak34149772022-03-31 12:32:10 +0200102 else if (unformat (line_input, "bond"))
Dave Barachba868bb2016-08-08 09:51:21 -0400103 {
104 show_bond = 1;
105 if (verbose < 0)
106 verbose = 0; /* default to brief for link bonding */
107 }
John Lobcebbb92016-04-05 15:47:43 -0400108
Ed Warnickecb9cada2015-12-08 15:45:58 -0700109 else
110 {
111 error = clib_error_return (0, "unknown input `%U'",
Vratko Polak34149772022-03-31 12:32:10 +0200112 format_unformat_error, line_input);
113 unformat_free (line_input);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700114 goto done;
115 }
116 }
Dave Barachba868bb2016-08-08 09:51:21 -0400117
Vratko Polak34149772022-03-31 12:32:10 +0200118 unformat_free (line_input);
119
Mohammed Hawari83caa622022-08-08 10:31:11 +0200120skip_unformat:
Ed Warnickecb9cada2015-12-08 15:45:58 -0700121 /* Gather interfaces. */
122 if (vec_len (hw_if_indices) == 0)
Damjan Marionb2c31b62020-12-13 21:47:40 +0100123 pool_foreach (hi, im->hw_interfaces)
124 vec_add1 (hw_if_indices, hi - im->hw_interfaces);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700125
Dave Barachba868bb2016-08-08 09:51:21 -0400126 if (verbose < 0)
127 verbose = 1; /* default to verbose (except bond) */
John Lobcebbb92016-04-05 15:47:43 -0400128
Ed Warnickecb9cada2015-12-08 15:45:58 -0700129 if (is_show)
130 {
131 /* Sort by name. */
132 vec_sort_with_function (hw_if_indices, compare_interface_names);
133
134 vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm, 0, verbose);
135 for (i = 0; i < vec_len (hw_if_indices); i++)
136 {
137 hi = vnet_get_hw_interface (vnm, hw_if_indices[i]);
Dave Barachba868bb2016-08-08 09:51:21 -0400138 if (show_bond == 0) /* show all interfaces */
139 vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm,
140 hi, verbose);
141 else if ((hi->bond_info) &&
John Lobcebbb92016-04-05 15:47:43 -0400142 (hi->bond_info != VNET_HW_INTERFACE_BOND_INFO_SLAVE))
Dave Barachba868bb2016-08-08 09:51:21 -0400143 { /* show only bonded interface and all its slave interfaces */
John Lobcebbb92016-04-05 15:47:43 -0400144 int hw_idx;
Dave Barachba868bb2016-08-08 09:51:21 -0400145 vnet_hw_interface_t *shi;
146 vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm,
John Lobcebbb92016-04-05 15:47:43 -0400147 hi, verbose);
Dave Barachba868bb2016-08-08 09:51:21 -0400148
149 /* *INDENT-OFF* */
Damjan Marionf0ca1e82020-12-13 23:26:56 +0100150 clib_bitmap_foreach (hw_idx, hi->bond_info)
151 {
Dave Barachba868bb2016-08-08 09:51:21 -0400152 shi = vnet_get_hw_interface(vnm, hw_idx);
153 vlib_cli_output (vm, "%U\n",
154 format_vnet_hw_interface, vnm, shi, verbose);
Damjan Marionf0ca1e82020-12-13 23:26:56 +0100155 }
Dave Barachba868bb2016-08-08 09:51:21 -0400156 /* *INDENT-ON* */
John Lobcebbb92016-04-05 15:47:43 -0400157 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700158 }
159 }
160 else
161 {
162 for (i = 0; i < vec_len (hw_if_indices); i++)
163 {
Dave Barachba868bb2016-08-08 09:51:21 -0400164 vnet_device_class_t *dc;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700165
166 hi = vnet_get_hw_interface (vnm, hw_if_indices[i]);
167 dc = vec_elt_at_index (im->device_classes, hi->dev_class_index);
Dave Barachba868bb2016-08-08 09:51:21 -0400168
Ed Warnickecb9cada2015-12-08 15:45:58 -0700169 if (dc->clear_counters)
170 dc->clear_counters (hi->dev_instance);
171 }
172 }
173
Dave Barachba868bb2016-08-08 09:51:21 -0400174done:
Ed Warnickecb9cada2015-12-08 15:45:58 -0700175 vec_free (hw_if_indices);
176 return error;
177}
178
Benoît Ganne17814d72020-07-24 09:57:11 +0200179static clib_error_t *
180show_hw_interfaces (vlib_main_t * vm,
181 unformat_input_t * input, vlib_cli_command_t * cmd)
182{
183 return show_or_clear_hw_interfaces (vm, input, cmd, 1 /* is_show */ );
184}
185
186static clib_error_t *
187clear_hw_interfaces (vlib_main_t * vm,
188 unformat_input_t * input, vlib_cli_command_t * cmd)
189{
190 return show_or_clear_hw_interfaces (vm, input, cmd, 0 /* is_show */ );
191}
192
193
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700194/*?
Billy McFalle9bac692017-08-11 14:05:11 -0400195 * Display more detailed information about all or a list of given interfaces.
196 * The verboseness of the output can be controlled by the following optional
197 * parameters:
198 * - brief: Only show name, index and state (default for bonded interfaces).
199 * - verbose: Also display additional attributes (default for all other interfaces).
200 * - detail: Also display all remaining attributes and extended statistics.
201 *
202 * To limit the output of the command to bonded interfaces and their slave
203 * interfaces, use the '<em>bond</em>' optional parameter.
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700204 *
205 * @cliexpar
Billy McFalle9bac692017-08-11 14:05:11 -0400206 * Example of how to display default data for all interfaces:
207 * @cliexstart{show hardware-interfaces}
208 * Name Idx Link Hardware
209 * GigabitEthernet7/0/0 1 up GigabitEthernet7/0/0
210 * Ethernet address ec:f4:bb:c0:bc:fc
211 * Intel e1000
212 * carrier up full duplex speed 1000 mtu 9216
213 * rx queues 1, rx desc 1024, tx queues 3, tx desc 1024
214 * cpu socket 0
215 * GigabitEthernet7/0/1 2 up GigabitEthernet7/0/1
216 * Ethernet address ec:f4:bb:c0:bc:fd
217 * Intel e1000
218 * carrier up full duplex speed 1000 mtu 9216
219 * rx queues 1, rx desc 1024, tx queues 3, tx desc 1024
220 * cpu socket 0
221 * VirtualEthernet0/0/0 3 up VirtualEthernet0/0/0
222 * Ethernet address 02:fe:a5:a9:8b:8e
223 * VirtualEthernet0/0/1 4 up VirtualEthernet0/0/1
224 * Ethernet address 02:fe:c0:4e:3b:b0
225 * VirtualEthernet0/0/2 5 up VirtualEthernet0/0/2
226 * Ethernet address 02:fe:1f:73:92:81
227 * VirtualEthernet0/0/3 6 up VirtualEthernet0/0/3
228 * Ethernet address 02:fe:f2:25:c4:68
229 * local0 0 down local0
230 * local
231 * @cliexend
232 * Example of how to display '<em>verbose</em>' data for an interface by name and
233 * software index (where 2 is the software index):
234 * @cliexstart{show hardware-interfaces GigabitEthernet7/0/0 2 verbose}
235 * Name Idx Link Hardware
236 * GigabitEthernet7/0/0 1 up GigabitEthernet7/0/0
237 * Ethernet address ec:f4:bb:c0:bc:fc
238 * Intel e1000
239 * carrier up full duplex speed 1000 mtu 9216
240 * rx queues 1, rx desc 1024, tx queues 3, tx desc 1024
241 * cpu socket 0
242 * GigabitEthernet7/0/1 2 down GigabitEthernet7/0/1
243 * Ethernet address ec:f4:bb:c0:bc:fd
244 * Intel e1000
245 * carrier up full duplex speed 1000 mtu 9216
246 * rx queues 1, rx desc 1024, tx queues 3, tx desc 1024
247 * cpu socket 0
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700248 * @cliexend
249 ?*/
Billy McFalle9bac692017-08-11 14:05:11 -0400250/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700251VLIB_CLI_COMMAND (show_hw_interfaces_command, static) = {
252 .path = "show hardware-interfaces",
Billy McFalle9bac692017-08-11 14:05:11 -0400253 .short_help = "show hardware-interfaces [brief|verbose|detail] [bond] "
254 "[<interface> [<interface> [..]]] [<sw_idx> [<sw_idx> [..]]]",
Benoît Ganne17814d72020-07-24 09:57:11 +0200255 .function = show_hw_interfaces,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700256};
Dave Barachba868bb2016-08-08 09:51:21 -0400257/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700258
Billy McFalle9bac692017-08-11 14:05:11 -0400259
260/*?
261 * Clear the extended statistics for all or a list of given interfaces
262 * (statistics associated with the '<em>show hardware-interfaces</em>' command).
263 *
264 * @cliexpar
265 * Example of how to clear the extended statistics for all interfaces:
266 * @cliexcmd{clear hardware-interfaces}
267 * Example of how to clear the extended statistics for an interface by
268 * name and software index (where 2 is the software index):
269 * @cliexcmd{clear hardware-interfaces GigabitEthernet7/0/0 2}
270 ?*/
Dave Barachba868bb2016-08-08 09:51:21 -0400271/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700272VLIB_CLI_COMMAND (clear_hw_interface_counters_command, static) = {
273 .path = "clear hardware-interfaces",
Billy McFalle9bac692017-08-11 14:05:11 -0400274 .short_help = "clear hardware-interfaces "
275 "[<interface> [<interface> [..]]] [<sw_idx> [<sw_idx> [..]]]",
Benoît Ganne17814d72020-07-24 09:57:11 +0200276 .function = clear_hw_interfaces,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700277};
Dave Barachba868bb2016-08-08 09:51:21 -0400278/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700279
Dave Barachba868bb2016-08-08 09:51:21 -0400280static int
281sw_interface_name_compare (void *a1, void *a2)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700282{
283 vnet_sw_interface_t *si1 = a1;
284 vnet_sw_interface_t *si2 = a2;
285
Dave Barachba868bb2016-08-08 09:51:21 -0400286 return vnet_sw_interface_compare (vnet_get_main (),
287 si1->sw_if_index, si2->sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700288}
289
290static clib_error_t *
291show_sw_interfaces (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -0400292 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700293{
Dave Barachba868bb2016-08-08 09:51:21 -0400294 clib_error_t *error = 0;
295 vnet_main_t *vnm = vnet_get_main ();
Dave Barach525c9d02018-05-26 10:48:55 -0400296 unformat_input_t _linput, *linput = &_linput;
Dave Barachba868bb2016-08-08 09:51:21 -0400297 vnet_interface_main_t *im = &vnm->interface_main;
298 vnet_sw_interface_t *si, *sorted_sis = 0;
Damjan Marion22311502016-10-28 20:30:15 +0200299 u32 sw_if_index = ~(u32) 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700300 u8 show_addresses = 0;
Damjan Marion22311502016-10-28 20:30:15 +0200301 u8 show_features = 0;
Dave Barach7be864a2016-11-28 11:41:35 -0500302 u8 show_tag = 0;
Jon Loeliger9485d992019-11-08 15:05:23 -0600303 u8 show_vtr = 0;
Dave Barach525c9d02018-05-26 10:48:55 -0400304 int verbose = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700305
Dave Barach525c9d02018-05-26 10:48:55 -0400306 /*
307 * Get a line of input. Won't work if the user typed
308 * "show interface" and nothing more.
309 */
310 if (unformat_user (input, unformat_line_input, linput))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700311 {
Dave Barach525c9d02018-05-26 10:48:55 -0400312 while (unformat_check_input (linput) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700313 {
Dave Barach525c9d02018-05-26 10:48:55 -0400314 /* See if user wants to show specific interface */
315 if (unformat
316 (linput, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
317 {
318 si = pool_elt_at_index (im->sw_interfaces, sw_if_index);
319 vec_add1 (sorted_sis, si[0]);
320 }
321 else if (unformat (linput, "address") || unformat (linput, "addr"))
322 show_addresses = 1;
323 else if (unformat (linput, "features") || unformat (linput, "feat"))
324 show_features = 1;
325 else if (unformat (linput, "tag"))
326 show_tag = 1;
Jon Loeliger9485d992019-11-08 15:05:23 -0600327 else if (unformat (linput, "vtr"))
328 show_vtr = 1;
Dave Barach525c9d02018-05-26 10:48:55 -0400329 else if (unformat (linput, "verbose"))
330 verbose = 1;
Neale Rannse619ada2021-09-22 10:49:43 +0000331 else if (unformat (linput, "%d", &sw_if_index))
332 {
333 if (!pool_is_free_index (im->sw_interfaces, sw_if_index))
334 {
335 si = pool_elt_at_index (im->sw_interfaces, sw_if_index);
336 vec_add1 (sorted_sis, si[0]);
337 }
338 else
339 {
340 vec_free (sorted_sis);
341 error = clib_error_return (0, "unknown interface index `%d'",
342 sw_if_index);
343 goto done;
344 }
345 }
Dave Barach525c9d02018-05-26 10:48:55 -0400346 else
347 {
Dave Barach8fdde3c2019-05-17 10:46:40 -0400348 vec_free (sorted_sis);
Dave Barach525c9d02018-05-26 10:48:55 -0400349 error = clib_error_return (0, "unknown input `%U'",
350 format_unformat_error, linput);
351 goto done;
352 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700353 }
Dave Barach525c9d02018-05-26 10:48:55 -0400354 unformat_free (linput);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700355 }
Jon Loeliger9485d992019-11-08 15:05:23 -0600356 if (show_features || show_tag || show_vtr)
Damjan Marion22311502016-10-28 20:30:15 +0200357 {
358 if (sw_if_index == ~(u32) 0)
Dave Barach8fdde3c2019-05-17 10:46:40 -0400359 {
360 vec_free (sorted_sis);
361 return clib_error_return (0, "Interface not specified...");
362 }
Dave Barach7be864a2016-11-28 11:41:35 -0500363 }
Damjan Marion22311502016-10-28 20:30:15 +0200364
Dave Barach7be864a2016-11-28 11:41:35 -0500365 if (show_features)
366 {
Dave Barach525c9d02018-05-26 10:48:55 -0400367 vnet_interface_features_show (vm, sw_if_index, verbose);
Neale Ranns47a3d992020-09-29 15:38:51 +0000368 vlib_cli_output (vm, "%U", format_l2_input_features, sw_if_index, 1);
Eyal Bari942402b2017-07-26 11:57:04 +0300369
370 l2_output_config_t *l2_output = l2output_intf_config (sw_if_index);
371 vlib_cli_output (vm, "\nl2-output:");
372 if (l2_output->out_vtr_flag)
373 vlib_cli_output (vm, "%10s (%s)", "VTR", "--internal--");
374 vlib_cli_output (vm, "%U", format_l2_output_features,
Neale Ranns5d9df1d2018-11-09 08:19:27 -0800375 l2_output->feature_bitmap, 1);
Dave Barach8fdde3c2019-05-17 10:46:40 -0400376 vec_free (sorted_sis);
Damjan Marion22311502016-10-28 20:30:15 +0200377 return 0;
378 }
Dave Barach7be864a2016-11-28 11:41:35 -0500379 if (show_tag)
380 {
381 u8 *tag;
382 tag = vnet_get_sw_interface_tag (vnm, sw_if_index);
383 vlib_cli_output (vm, "%U: %s",
384 format_vnet_sw_if_index_name, vnm, sw_if_index,
385 tag ? (char *) tag : "(none)");
Dave Barach8fdde3c2019-05-17 10:46:40 -0400386 vec_free (sorted_sis);
Dave Barach7be864a2016-11-28 11:41:35 -0500387 return 0;
388 }
Damjan Marion22311502016-10-28 20:30:15 +0200389
Jon Loeliger9485d992019-11-08 15:05:23 -0600390 /*
391 * Show vlan tag rewrite data for one interface.
392 */
393 if (show_vtr)
394 {
395 u32 vtr_op = L2_VTR_DISABLED;
396 u32 push_dot1q = 0, tag1 = 0, tag2 = 0;
397
398 if (l2vtr_get (vm, vnm, sw_if_index,
399 &vtr_op, &push_dot1q, &tag1, &tag2) != 0)
400 {
401 vlib_cli_output (vm, "%U: Problem getting vlan tag-rewrite data",
402 format_vnet_sw_if_index_name, vnm, sw_if_index);
403 return 0;
404 }
405 vlib_cli_output (vm, "%U: VTR %0U",
406 format_vnet_sw_if_index_name, vnm, sw_if_index,
407 format_vtr, vtr_op, push_dot1q, tag1, tag2);
408 return 0;
409 }
410
Ed Warnickecb9cada2015-12-08 15:45:58 -0700411 if (!show_addresses)
Dave Barachba868bb2016-08-08 09:51:21 -0400412 vlib_cli_output (vm, "%U\n", format_vnet_sw_interface, vnm, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700413
Dave Barachba868bb2016-08-08 09:51:21 -0400414 if (vec_len (sorted_sis) == 0) /* Get all interfaces */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700415 {
416 /* Gather interfaces. */
Dave Barachba868bb2016-08-08 09:51:21 -0400417 sorted_sis =
418 vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
Damjan Marion8bea5892022-04-04 22:40:45 +0200419 vec_set_len (sorted_sis, 0);
Dave Barach525c9d02018-05-26 10:48:55 -0400420 /* *INDENT-OFF* */
Damjan Marionb2c31b62020-12-13 21:47:40 +0100421 pool_foreach (si, im->sw_interfaces)
422 {
Dave Barach525c9d02018-05-26 10:48:55 -0400423 int visible = vnet_swif_is_api_visible (si);
424 if (visible)
Damjan Marionb2c31b62020-12-13 21:47:40 +0100425 vec_add1 (sorted_sis, si[0]);
426 }
Ole Troand7231612018-06-07 10:17:57 +0200427 /* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700428 /* Sort by name. */
429 vec_sort_with_function (sorted_sis, sw_interface_name_compare);
430 }
431
432 if (show_addresses)
433 {
434 vec_foreach (si, sorted_sis)
Dave Barachba868bb2016-08-08 09:51:21 -0400435 {
Dave Barachba868bb2016-08-08 09:51:21 -0400436 ip4_main_t *im4 = &ip4_main;
437 ip6_main_t *im6 = &ip6_main;
438 ip_lookup_main_t *lm4 = &im4->lookup_main;
439 ip_lookup_main_t *lm6 = &im6->lookup_main;
440 ip_interface_address_t *ia = 0;
Dave Barachba868bb2016-08-08 09:51:21 -0400441 u32 fib_index4 = 0, fib_index6 = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700442
Dave Barachba868bb2016-08-08 09:51:21 -0400443 if (vec_len (im4->fib_index_by_sw_if_index) > si->sw_if_index)
444 fib_index4 = vec_elt (im4->fib_index_by_sw_if_index,
445 si->sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700446
Dave Barachba868bb2016-08-08 09:51:21 -0400447 if (vec_len (im6->fib_index_by_sw_if_index) > si->sw_if_index)
448 fib_index6 = vec_elt (im6->fib_index_by_sw_if_index,
449 si->sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700450
John Lo4478d8e2018-01-12 17:15:25 -0500451 ip4_fib_t *fib4 = ip4_fib_get (fib_index4);
452 ip6_fib_t *fib6 = ip6_fib_get (fib_index6);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700453
Dave Barachba868bb2016-08-08 09:51:21 -0400454 if (si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)
455 vlib_cli_output
456 (vm, "%U (%s): \n unnumbered, use %U",
John Lo4478d8e2018-01-12 17:15:25 -0500457 format_vnet_sw_if_index_name, vnm, si->sw_if_index,
Dave Barachba868bb2016-08-08 09:51:21 -0400458 (si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? "up" : "dn",
459 format_vnet_sw_if_index_name, vnm, si->unnumbered_sw_if_index);
Dave Barachba868bb2016-08-08 09:51:21 -0400460 else
John Lo4478d8e2018-01-12 17:15:25 -0500461 vlib_cli_output
462 (vm, "%U (%s):",
463 format_vnet_sw_if_index_name, vnm, si->sw_if_index,
464 (si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? "up" : "dn");
Ed Warnickecb9cada2015-12-08 15:45:58 -0700465
Eyal Bari942402b2017-07-26 11:57:04 +0300466 /* Display any L2 info */
Neale Ranns47a3d992020-09-29 15:38:51 +0000467 vlib_cli_output (vm, "%U", format_l2_input, si->sw_if_index);
Dave Barachba868bb2016-08-08 09:51:21 -0400468
John Lo4478d8e2018-01-12 17:15:25 -0500469 /* *INDENT-OFF* */
Dave Barachba868bb2016-08-08 09:51:21 -0400470 /* Display any IP4 addressing info */
John Lo4478d8e2018-01-12 17:15:25 -0500471 foreach_ip_interface_address (lm4, ia, si->sw_if_index,
472 1 /* honor unnumbered */,
473 ({
474 ip4_address_t *r4 = ip_interface_address_get_address (lm4, ia);
Neale Rannsd6953332021-08-10 07:39:18 +0000475 if (fib4->hash.table_id)
476 vlib_cli_output (
477 vm, " L3 %U/%d ip4 table-id %d fib-idx %d", format_ip4_address,
478 r4, ia->address_length, fib4->hash.table_id,
479 ip4_fib_index_from_table_id (fib4->hash.table_id));
John Lo4478d8e2018-01-12 17:15:25 -0500480 else
481 vlib_cli_output (vm, " L3 %U/%d",
482 format_ip4_address, r4, ia->address_length);
483 }));
484 /* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700485
John Lo4478d8e2018-01-12 17:15:25 -0500486 /* *INDENT-OFF* */
Dave Barachba868bb2016-08-08 09:51:21 -0400487 /* Display any IP6 addressing info */
John Lo4478d8e2018-01-12 17:15:25 -0500488 foreach_ip_interface_address (lm6, ia, si->sw_if_index,
489 1 /* honor unnumbered */,
490 ({
491 ip6_address_t *r6 = ip_interface_address_get_address (lm6, ia);
492 if (fib6->table_id)
493 vlib_cli_output (vm, " L3 %U/%d ip6 table-id %d fib-idx %d",
494 format_ip6_address, r6, ia->address_length,
495 fib6->table_id,
496 ip6_fib_index_from_table_id (fib6->table_id));
497 else
498 vlib_cli_output (vm, " L3 %U/%d",
499 format_ip6_address, r6, ia->address_length);
500 }));
501 /* *INDENT-ON* */
Ole Troand7231612018-06-07 10:17:57 +0200502 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700503 }
Ole Troand7231612018-06-07 10:17:57 +0200504 else
505 {
506 vec_foreach (si, sorted_sis)
507 {
508 vlib_cli_output (vm, "%U\n", format_vnet_sw_interface, vnm, si);
509 }
510 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700511
Dave Barachba868bb2016-08-08 09:51:21 -0400512done:
Ole Troand7231612018-06-07 10:17:57 +0200513 vec_free (sorted_sis);
514 return error;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700515}
516
Dave Barachba868bb2016-08-08 09:51:21 -0400517/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700518VLIB_CLI_COMMAND (show_sw_interfaces_command, static) = {
Dave Barach13ad1f02017-03-26 19:36:18 -0400519 .path = "show interface",
Mohsin Kazmi88d94142023-01-26 15:14:17 +0000520 .short_help = "show interface [address|addr|features|feat|vtr|tag] "
521 "[<interface> [<interface> [..]]] [verbose]",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700522 .function = show_sw_interfaces,
Steven Luongc5fa2b82019-04-25 11:19:49 -0700523 .is_mp_safe = 1,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700524};
Dave Barachba868bb2016-08-08 09:51:21 -0400525/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700526
527/* Root of all interface commands. */
Dave Barachba868bb2016-08-08 09:51:21 -0400528/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700529VLIB_CLI_COMMAND (vnet_cli_interface_command, static) = {
530 .path = "interface",
531 .short_help = "Interface commands",
532};
Dave Barachba868bb2016-08-08 09:51:21 -0400533/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700534
Dave Barachba868bb2016-08-08 09:51:21 -0400535/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700536VLIB_CLI_COMMAND (vnet_cli_set_interface_command, static) = {
537 .path = "set interface",
538 .short_help = "Interface commands",
539};
Dave Barachba868bb2016-08-08 09:51:21 -0400540/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700541
542static clib_error_t *
543clear_interface_counters (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -0400544 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700545{
Dave Barachba868bb2016-08-08 09:51:21 -0400546 vnet_main_t *vnm = vnet_get_main ();
547 vnet_interface_main_t *im = &vnm->interface_main;
548 vlib_simple_counter_main_t *sm;
549 vlib_combined_counter_main_t *cm;
Dave Barach8fdde3c2019-05-17 10:46:40 -0400550 int j, n_counters;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700551
552 n_counters = vec_len (im->combined_sw_if_counters);
553
554 for (j = 0; j < n_counters; j++)
555 {
Dave Barach8fdde3c2019-05-17 10:46:40 -0400556 im = &vnm->interface_main;
557 cm = im->combined_sw_if_counters + j;
558 vlib_clear_combined_counters (cm);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700559 }
560
561 n_counters = vec_len (im->sw_if_counters);
562
563 for (j = 0; j < n_counters; j++)
564 {
Dave Barach8fdde3c2019-05-17 10:46:40 -0400565 im = &vnm->interface_main;
566 sm = im->sw_if_counters + j;
567 vlib_clear_simple_counters (sm);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700568 }
569
570 return 0;
571}
572
Billy McFalle9bac692017-08-11 14:05:11 -0400573/*?
574 * Clear the statistics for all interfaces (statistics associated with the
575 * '<em>show interface</em>' command).
576 *
577 * @cliexpar
578 * Example of how to clear the statistics for all interfaces:
579 * @cliexcmd{clear interfaces}
580 ?*/
Dave Barachba868bb2016-08-08 09:51:21 -0400581/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700582VLIB_CLI_COMMAND (clear_interface_counters_command, static) = {
583 .path = "clear interfaces",
Billy McFalle9bac692017-08-11 14:05:11 -0400584 .short_help = "clear interfaces",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700585 .function = clear_interface_counters,
586};
Dave Barachba868bb2016-08-08 09:51:21 -0400587/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700588
Chris Luke16bcf7d2016-09-01 14:31:46 -0400589/**
590 * Parse subinterface names.
591 *
Dave Barachba868bb2016-08-08 09:51:21 -0400592 * The following subinterface syntax is supported. The first two are for
593 * backwards compatability:
594 *
595 * <intf-name> <id>
596 * - a subinterface with the name <intf-name>.<id>. The subinterface
597 * is a single dot1q vlan with vlan id <id> and exact-match semantics.
598 *
599 * <intf-name> <min_id>-<max_id>
600 * - a set of the above subinterfaces, repeating for each id
601 * in the range <min_id> to <max_id>
602 *
603 * In the following, exact-match semantics (i.e. the number of vlan tags on the
604 * packet must match the number of tags in the configuration) are used only if
605 * the keyword exact-match is present. Non-exact match is the default.
606 *
607 * <intf-name> <id> dot1q <outer_id> [exact-match]
608 * - a subinterface with the name <intf-name>.<id>. The subinterface
609 * is a single dot1q vlan with vlan id <outer_id>.
610 *
611 * <intf-name> <id> dot1q any [exact-match]
612 * - a subinterface with the name <intf-name>.<id>. The subinterface
613 * is a single dot1q vlan with any vlan id.
614 *
615 * <intf-name> <id> dot1q <outer_id> inner-dot1q <inner_id> [exact-match]
616 * - a subinterface with the name <intf-name>.<id>. The subinterface
617 * is a double dot1q vlan with outer vlan id <outer_id> and inner vlan id
618 * <inner_id>.
619 *
620 * <intf-name> <id> dot1q <outer_id> inner-dot1q any [exact-match]
621 * - a subinterface with the name <intf-name>.<id>. The subinterface
622 * is a double dot1q vlan with outer vlan id <id> and any inner vlan id.
623 *
624 * <intf-name> <id> dot1q any inner-dot1q any [exact-match]
625 *
626 * - a subinterface with the name <intf-name>.<id>. The subinterface
627 * is a double dot1q vlan with any outer vlan id and any inner vlan id.
628 *
629 * For each of the above CLI, there is a duplicate that uses the keyword
630 * "dot1ad" in place of the first "dot1q". These interfaces use ethertype
631 * 0x88ad in place of 0x8100 for the outer ethertype. Note that for double-
632 * tagged packets the inner ethertype is always 0x8100. Also note that
633 * the dot1q and dot1ad naming spaces are independent, so it is legal to
634 * have both "Gig3/0/0.1 dot1q 100" and "Gig3/0/0.2 dot1ad 100". For example:
635 *
636 * <intf-name> <id> dot1ad <outer_id> inner-dot1q <inner_id> [exact-match]
637 * - a subinterface with the name <intf-name>.<id>. The subinterface
638 * is a double dot1ad vlan with outer vlan id <outer_id> and inner vlan
639 * id <inner_id>.
640 *
641 * <intf-name> <id> untagged
642 * - a subinterface with the name <intf-name>.<id>. The subinterface
643 * has no vlan tags. Only one can be specified per interface.
644 *
645 * <intf-name> <id> default
646 * - a subinterface with the name <intf-name>.<id>. This is associated
647 * with a packet that did not match any other configured subinterface
648 * on this interface. Only one can be specified per interface.
649 */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700650
651static clib_error_t *
Dave Barachba868bb2016-08-08 09:51:21 -0400652parse_vlan_sub_interfaces (unformat_input_t * input,
653 vnet_sw_interface_t * template)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700654{
Dave Barachba868bb2016-08-08 09:51:21 -0400655 clib_error_t *error = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700656 u32 inner_vlan, outer_vlan;
657
Dave Barachba868bb2016-08-08 09:51:21 -0400658 if (unformat (input, "any inner-dot1q any"))
659 {
660 template->sub.eth.flags.two_tags = 1;
661 template->sub.eth.flags.outer_vlan_id_any = 1;
662 template->sub.eth.flags.inner_vlan_id_any = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700663 }
Dave Barachba868bb2016-08-08 09:51:21 -0400664 else if (unformat (input, "any"))
665 {
666 template->sub.eth.flags.one_tag = 1;
667 template->sub.eth.flags.outer_vlan_id_any = 1;
668 }
669 else if (unformat (input, "%d inner-dot1q any", &outer_vlan))
670 {
671 template->sub.eth.flags.two_tags = 1;
672 template->sub.eth.flags.inner_vlan_id_any = 1;
673 template->sub.eth.outer_vlan_id = outer_vlan;
674 }
675 else if (unformat (input, "%d inner-dot1q %d", &outer_vlan, &inner_vlan))
676 {
677 template->sub.eth.flags.two_tags = 1;
678 template->sub.eth.outer_vlan_id = outer_vlan;
679 template->sub.eth.inner_vlan_id = inner_vlan;
680 }
681 else if (unformat (input, "%d", &outer_vlan))
682 {
683 template->sub.eth.flags.one_tag = 1;
684 template->sub.eth.outer_vlan_id = outer_vlan;
685 }
686 else
687 {
688 error = clib_error_return (0, "expected dot1q config, got `%U'",
689 format_unformat_error, input);
690 goto done;
691 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700692
Dave Barachba868bb2016-08-08 09:51:21 -0400693 if (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
694 {
695 if (unformat (input, "exact-match"))
696 {
697 template->sub.eth.flags.exact_match = 1;
698 }
699 }
700
701done:
Ed Warnickecb9cada2015-12-08 15:45:58 -0700702 return error;
703}
704
705static clib_error_t *
706create_sub_interfaces (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -0400707 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700708{
Dave Barachba868bb2016-08-08 09:51:21 -0400709 vnet_main_t *vnm = vnet_get_main ();
710 clib_error_t *error = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700711 u32 hw_if_index, sw_if_index;
Dave Barachba868bb2016-08-08 09:51:21 -0400712 vnet_hw_interface_t *hi;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700713 u32 id, id_min, id_max;
714 vnet_sw_interface_t template;
715
716 hw_if_index = ~0;
Dave Barachba868bb2016-08-08 09:51:21 -0400717 if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700718 {
719 error = clib_error_return (0, "unknown interface `%U'",
720 format_unformat_error, input);
721 goto done;
722 }
723
Dave Barachb7b92992018-10-17 10:38:51 -0400724 clib_memset (&template, 0, sizeof (template));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700725 template.sub.eth.raw_flags = 0;
726
Dave Barachba868bb2016-08-08 09:51:21 -0400727 if (unformat (input, "%d default", &id_min))
728 {
729 id_max = id_min;
730 template.sub.eth.flags.default_sub = 1;
731 }
732 else if (unformat (input, "%d untagged", &id_min))
733 {
734 id_max = id_min;
735 template.sub.eth.flags.no_tags = 1;
736 template.sub.eth.flags.exact_match = 1;
737 }
738 else if (unformat (input, "%d dot1q", &id_min))
739 {
740 /* parse dot1q config */
741 id_max = id_min;
742 error = parse_vlan_sub_interfaces (input, &template);
743 if (error)
744 goto done;
745 }
746 else if (unformat (input, "%d dot1ad", &id_min))
747 {
748 /* parse dot1ad config */
749 id_max = id_min;
750 template.sub.eth.flags.dot1ad = 1;
751 error = parse_vlan_sub_interfaces (input, &template);
752 if (error)
753 goto done;
754 }
755 else if (unformat (input, "%d-%d", &id_min, &id_max))
756 {
757 template.sub.eth.flags.one_tag = 1;
Dave Barachba868bb2016-08-08 09:51:21 -0400758 template.sub.eth.flags.exact_match = 1;
759 if (id_min > id_max)
760 goto id_error;
761 }
762 else if (unformat (input, "%d", &id_min))
763 {
764 id_max = id_min;
765 template.sub.eth.flags.one_tag = 1;
766 template.sub.eth.outer_vlan_id = id_min;
767 template.sub.eth.flags.exact_match = 1;
768 }
769 else
770 {
Ed Warnickecb9cada2015-12-08 15:45:58 -0700771 id_error:
772 error = clib_error_return (0, "expected ID or ID MIN-MAX, got `%U'",
773 format_unformat_error, input);
774 goto done;
Dave Barachba868bb2016-08-08 09:51:21 -0400775 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700776
777 hi = vnet_get_hw_interface (vnm, hw_if_index);
John Lobcebbb92016-04-05 15:47:43 -0400778
Dave Barachba868bb2016-08-08 09:51:21 -0400779 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE)
780 {
781 error =
782 clib_error_return (0,
783 "not allowed as %v belong to a BondEthernet interface",
784 hi->name);
785 goto done;
786 }
John Lobcebbb92016-04-05 15:47:43 -0400787
Ed Warnickecb9cada2015-12-08 15:45:58 -0700788 for (id = id_min; id <= id_max; id++)
789 {
Dave Barachba868bb2016-08-08 09:51:21 -0400790 uword *p;
791 vnet_interface_main_t *im = &vnm->interface_main;
792 u64 sup_and_sub_key = ((u64) (hi->sw_if_index) << 32) | (u64) id;
793 u64 *kp;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700794
795 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
796 if (p)
Dave Barachba868bb2016-08-08 09:51:21 -0400797 {
798 if (CLIB_DEBUG > 0)
799 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
800 hi->sw_if_index, id);
801 continue;
802 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700803
Ed Warnickecb9cada2015-12-08 15:45:58 -0700804 template.type = VNET_SW_INTERFACE_TYPE_SUB;
Eyal Baric5b13602016-11-24 19:42:43 +0200805 template.flood_class = VNET_FLOOD_CLASS_NORMAL;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700806 template.sup_sw_if_index = hi->sw_if_index;
807 template.sub.id = id;
Eyal Baria4509cf2016-09-26 09:24:09 +0300808 if (id_min < id_max)
809 template.sub.eth.outer_vlan_id = id;
810
Ed Warnickecb9cada2015-12-08 15:45:58 -0700811 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
Dave Barachba868bb2016-08-08 09:51:21 -0400812 if (error)
813 goto done;
Dave Barach16ad6ae2016-07-28 17:55:30 -0400814
Jon Loeligerb22e1f02019-12-19 09:03:52 -0600815 kp = clib_mem_alloc (sizeof (*kp));
816 *kp = sup_and_sub_key;
817
Ed Warnickecb9cada2015-12-08 15:45:58 -0700818 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
819 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
Dave Barachba868bb2016-08-08 09:51:21 -0400820 vlib_cli_output (vm, "%U\n", format_vnet_sw_if_index_name,
821 vnet_get_main (), sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700822 }
823
Dave Barachba868bb2016-08-08 09:51:21 -0400824done:
Ed Warnickecb9cada2015-12-08 15:45:58 -0700825 return error;
826}
827
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700828/*?
Billy McFalle9bac692017-08-11 14:05:11 -0400829 * This command is used to add VLAN IDs to interfaces, also known as subinterfaces.
830 * The primary input to this command is the '<em>interface</em>' and '<em>subId</em>'
831 * (subinterface Id) parameters. If no additional VLAN ID is provide, the VLAN ID is
832 * assumed to be the '<em>subId</em>'. The VLAN ID and '<em>subId</em>' can be different,
833 * but this is not recommended.
834 *
835 * This command has several variations:
836 * - <b>create sub-interfaces <interface> <subId></b> - Create a subinterface to
837 * process packets with a given 802.1q VLAN ID (same value as the '<em>subId</em>').
838 *
839 * - <b>create sub-interfaces <interface> <subId> default</b> - Adding the
840 * '<em>default</em>' parameter indicates that packets with VLAN IDs that do not
841 * match any other subinterfaces should be sent to this subinterface.
842 *
843 * - <b>create sub-interfaces <interface> <subId> untagged</b> - Adding the
844 * '<em>untagged</em>' parameter indicates that packets no VLAN IDs should be sent
845 * to this subinterface.
846 *
847 * - <b>create sub-interfaces <interface> <subId>-<subId></b> - Create a range of
848 * subinterfaces to handle a range of VLAN IDs.
849 *
850 * - <b>create sub-interfaces <interface> <subId> dot1q|dot1ad <vlanId>|any [exact-match]</b> -
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -0700851 * Use this command to specify the outer VLAN ID, to either be explicit or to make the
Billy McFalle9bac692017-08-11 14:05:11 -0400852 * VLAN ID different from the '<em>subId</em>'.
853 *
854 * - <b>create sub-interfaces <interface> <subId> dot1q|dot1ad <vlanId>|any inner-dot1q
855 * <vlanId>|any [exact-match]</b> - Use this command to specify the outer VLAN ID and
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -0700856 * the inner VLAN ID.
Billy McFalle9bac692017-08-11 14:05:11 -0400857 *
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -0700858 * When '<em>dot1q</em>' or '<em>dot1ad</em>' is explicitly entered, subinterfaces
Billy McFalle9bac692017-08-11 14:05:11 -0400859 * can be configured as either exact-match or non-exact match. Non-exact match is the CLI
860 * default. If '<em>exact-match</em>' is specified, packets must have the same number of
861 * VLAN tags as the configuration. For non-exact-match, packets must at least that number
862 * of tags. L3 (routed) interfaces must be configured as exact-match. L2 interfaces are
863 * typically configured as non-exact-match. If '<em>dot1q</em>' or '<em>dot1ad</em>' is NOT
864 * entered, then the default behavior is exact-match.
865 *
866 * Use the '<em>show interface</em>' command to display all subinterfaces.
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700867 *
868 * @cliexpar
Billy McFalle9bac692017-08-11 14:05:11 -0400869 * @parblock
870 * Example of how to create a VLAN subinterface 11 to process packets on 802.1q VLAN ID 11:
871 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11}
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700872 *
Billy McFalle9bac692017-08-11 14:05:11 -0400873 * The previous example is shorthand and is equivalent to:
874 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11 dot1q 11 exact-match}
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700875 *
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700876 *
Billy McFalle9bac692017-08-11 14:05:11 -0400877 * Example of how to create a subinterface number that is different from the VLAN ID:
878 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11 dot1q 100}
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700879 *
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700880 *
Billy McFalle9bac692017-08-11 14:05:11 -0400881 * Examples of how to create q-in-q and q-in-any subinterfaces:
882 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11 dot1q 100 inner-dot1q 200}
883 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 12 dot1q 100 inner-dot1q any}
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700884 *
Billy McFalle9bac692017-08-11 14:05:11 -0400885 * Examples of how to create dot1ad interfaces:
886 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11 dot1ad 11}
887 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 12 dot1ad 100 inner-dot1q 200}
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700888 *
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700889 *
Billy McFalle9bac692017-08-11 14:05:11 -0400890 * Examples of '<em>exact-match</em>' versus non-exact match. A packet with
891 * outer VLAN 100 and inner VLAN 200 would match this interface, because the default
892 * is non-exact match:
893 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 5 dot1q 100}
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700894 *
Billy McFalle9bac692017-08-11 14:05:11 -0400895 * However, the same packet would NOT match this interface because '<em>exact-match</em>'
896 * is specified and only one VLAN is configured, but packet contains two VLANs:
897 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 5 dot1q 100 exact-match}
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700898 *
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700899 *
Billy McFalle9bac692017-08-11 14:05:11 -0400900 * Example of how to created a subinterface to process untagged packets:
901 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 5 untagged}
902 *
903 * Example of how to created a subinterface to process any packet with a VLAN ID that
904 * does not match any other subinterface:
905 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 7 default}
906 *
907 * When subinterfaces are created, they are in the down state. Example of how to
908 * enable a newly created subinterface:
909 * @cliexcmd{set interface GigabitEthernet2/0/0.7 up}
910 * @endparblock
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700911 ?*/
Billy McFalle9bac692017-08-11 14:05:11 -0400912/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700913VLIB_CLI_COMMAND (create_sub_interfaces_command, static) = {
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700914 .path = "create sub-interfaces",
Billy McFalle9bac692017-08-11 14:05:11 -0400915 .short_help = "create sub-interfaces <interface> "
916 "{<subId> [default|untagged]} | "
917 "{<subId>-<subId>} | "
918 "{<subId> dot1q|dot1ad <vlanId>|any [inner-dot1q <vlanId>|any] [exact-match]}",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700919 .function = create_sub_interfaces,
920};
Dave Barachba868bb2016-08-08 09:51:21 -0400921/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700922
923static clib_error_t *
924set_state (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -0400925 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700926{
Dave Barachba868bb2016-08-08 09:51:21 -0400927 vnet_main_t *vnm = vnet_get_main ();
928 clib_error_t *error;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700929 u32 sw_if_index, flags;
930
931 sw_if_index = ~0;
Dave Barachba868bb2016-08-08 09:51:21 -0400932 if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700933 {
934 error = clib_error_return (0, "unknown interface `%U'",
935 format_unformat_error, input);
936 goto done;
937 }
938
Dave Barachba868bb2016-08-08 09:51:21 -0400939 if (!unformat (input, "%U", unformat_vnet_sw_interface_flags, &flags))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700940 {
941 error = clib_error_return (0, "unknown flags `%U'",
942 format_unformat_error, input);
943 goto done;
944 }
945
946 error = vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
947 if (error)
948 goto done;
949
Dave Barachba868bb2016-08-08 09:51:21 -0400950done:
Ed Warnickecb9cada2015-12-08 15:45:58 -0700951 return error;
952}
953
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700954/*?
Billy McFalle9bac692017-08-11 14:05:11 -0400955 * This command is used to change the admin state (up/down) of an interface.
956 *
957 * If an interface is down, the optional '<em>punt</em>' flag can also be set.
958 * The '<em>punt</em>' flag implies the interface is disabled for forwarding
959 * but punt all traffic to slow-path. Use the '<em>enable</em>' flag to clear
960 * '<em>punt</em>' flag (interface is still down).
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700961 *
962 * @cliexpar
Nathan Skrzypczak2c77ae42021-09-29 15:36:51 +0200963 * Example of how to configure the admin state of an interface to
964 '<em>up</em>':
Billy McFalle9bac692017-08-11 14:05:11 -0400965 * @cliexcmd{set interface state GigabitEthernet2/0/0 up}
Nathan Skrzypczak2c77ae42021-09-29 15:36:51 +0200966 * Example of how to configure the admin state of an interface to
967 '<em>down</em>':
Billy McFalle9bac692017-08-11 14:05:11 -0400968 * @cliexcmd{set interface state GigabitEthernet2/0/0 down}
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700969 ?*/
Billy McFalle9bac692017-08-11 14:05:11 -0400970/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700971VLIB_CLI_COMMAND (set_state_command, static) = {
972 .path = "set interface state",
Billy McFalle9bac692017-08-11 14:05:11 -0400973 .short_help = "set interface state <interface> [up|down|punt|enable]",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700974 .function = set_state,
975};
Dave Barachba868bb2016-08-08 09:51:21 -0400976/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700977
978static clib_error_t *
979set_unnumbered (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -0400980 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700981{
Dave Barachba868bb2016-08-08 09:51:21 -0400982 vnet_main_t *vnm = vnet_get_main ();
Neale Ranns2ae2bc52018-03-16 03:22:39 -0700983 u32 unnumbered_sw_if_index = ~0;
984 u32 inherit_from_sw_if_index = ~0;
985 int enable = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700986
Igor Mikhailov (imichail)ab3e42b2016-09-25 15:11:53 -0700987 if (unformat (input, "%U use %U",
988 unformat_vnet_sw_interface, vnm, &unnumbered_sw_if_index,
989 unformat_vnet_sw_interface, vnm, &inherit_from_sw_if_index))
Neale Ranns2ae2bc52018-03-16 03:22:39 -0700990 enable = 1;
Igor Mikhailov (imichail)ab3e42b2016-09-25 15:11:53 -0700991 else if (unformat (input, "del %U",
992 unformat_vnet_sw_interface, vnm,
993 &unnumbered_sw_if_index))
Neale Ranns2ae2bc52018-03-16 03:22:39 -0700994 enable = 0;
Igor Mikhailov (imichail)ab3e42b2016-09-25 15:11:53 -0700995 else
996 return clib_error_return (0, "parse error '%U'",
997 format_unformat_error, input);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700998
Neale Ranns2ae2bc52018-03-16 03:22:39 -0700999 if (~0 == unnumbered_sw_if_index)
1000 return clib_error_return (0, "Specify the unnumbered interface");
1001 if (enable && ~0 == inherit_from_sw_if_index)
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -07001002 return clib_error_return (0, "When enabling unnumbered specify the"
Neale Ranns2ae2bc52018-03-16 03:22:39 -07001003 " IP enabled interface that it uses");
Neale Ranns898273f2017-03-18 02:57:38 -07001004
Stanislav Zaikin328b5da2021-07-15 16:27:29 +02001005 int rv = vnet_sw_interface_update_unnumbered (
1006 unnumbered_sw_if_index, inherit_from_sw_if_index, enable);
1007
1008 switch (rv)
1009 {
1010 case 0:
1011 break;
1012
1013 case VNET_API_ERROR_UNEXPECTED_INTF_STATE:
1014 return clib_error_return (
1015 0,
1016 "When enabling unnumbered both interfaces must be in the same tables");
1017
1018 default:
1019 return clib_error_return (
1020 0, "vnet_sw_interface_update_unnumbered returned %d", rv);
1021 }
Neale Ranns898273f2017-03-18 02:57:38 -07001022
Neale Ranns2ae2bc52018-03-16 03:22:39 -07001023 return (NULL);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001024}
1025
Dave Barachba868bb2016-08-08 09:51:21 -04001026/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001027VLIB_CLI_COMMAND (set_unnumbered_command, static) = {
1028 .path = "set interface unnumbered",
Billy McFalle9bac692017-08-11 14:05:11 -04001029 .short_help = "set interface unnumbered [<interface> use <interface> | del <interface>]",
Ed Warnickecb9cada2015-12-08 15:45:58 -07001030 .function = set_unnumbered,
1031};
Dave Barachba868bb2016-08-08 09:51:21 -04001032/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001033
1034
1035
1036static clib_error_t *
1037set_hw_class (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -04001038 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001039{
Dave Barachba868bb2016-08-08 09:51:21 -04001040 vnet_main_t *vnm = vnet_get_main ();
1041 vnet_interface_main_t *im = &vnm->interface_main;
1042 clib_error_t *error;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001043 u32 hw_if_index, hw_class_index;
1044
1045 hw_if_index = ~0;
Dave Barachba868bb2016-08-08 09:51:21 -04001046 if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
Ed Warnickecb9cada2015-12-08 15:45:58 -07001047 {
1048 error = clib_error_return (0, "unknown hardware interface `%U'",
1049 format_unformat_error, input);
1050 goto done;
1051 }
1052
Dave Barachba868bb2016-08-08 09:51:21 -04001053 if (!unformat_user (input, unformat_hash_string,
1054 im->hw_interface_class_by_name, &hw_class_index))
Ed Warnickecb9cada2015-12-08 15:45:58 -07001055 {
1056 error = clib_error_return (0, "unknown hardware class `%U'",
1057 format_unformat_error, input);
1058 goto done;
1059 }
1060
1061 error = vnet_hw_interface_set_class (vnm, hw_if_index, hw_class_index);
1062 if (error)
1063 goto done;
1064
Dave Barachba868bb2016-08-08 09:51:21 -04001065done:
Ed Warnickecb9cada2015-12-08 15:45:58 -07001066 return error;
1067}
1068
Dave Barachba868bb2016-08-08 09:51:21 -04001069/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001070VLIB_CLI_COMMAND (set_hw_class_command, static) = {
1071 .path = "set interface hw-class",
1072 .short_help = "Set interface hardware class",
1073 .function = set_hw_class,
1074};
Dave Barachba868bb2016-08-08 09:51:21 -04001075/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001076
Dave Barachba868bb2016-08-08 09:51:21 -04001077static clib_error_t *
1078vnet_interface_cli_init (vlib_main_t * vm)
1079{
1080 return 0;
1081}
Ed Warnickecb9cada2015-12-08 15:45:58 -07001082
1083VLIB_INIT_FUNCTION (vnet_interface_cli_init);
1084
Dave Barachba868bb2016-08-08 09:51:21 -04001085static clib_error_t *
Ed Warnickecb9cada2015-12-08 15:45:58 -07001086renumber_interface_command_fn (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -04001087 unformat_input_t * input,
1088 vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001089{
1090 u32 hw_if_index;
1091 u32 new_dev_instance;
Dave Barachba868bb2016-08-08 09:51:21 -04001092 vnet_main_t *vnm = vnet_get_main ();
Ed Warnickecb9cada2015-12-08 15:45:58 -07001093 int rv;
1094
Dave Barachba868bb2016-08-08 09:51:21 -04001095 if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
Ed Warnickecb9cada2015-12-08 15:45:58 -07001096 return clib_error_return (0, "unknown hardware interface `%U'",
Dave Barachba868bb2016-08-08 09:51:21 -04001097 format_unformat_error, input);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001098
Dave Barachba868bb2016-08-08 09:51:21 -04001099 if (!unformat (input, "%d", &new_dev_instance))
Ed Warnickecb9cada2015-12-08 15:45:58 -07001100 return clib_error_return (0, "new dev instance missing");
1101
1102 rv = vnet_interface_name_renumber (hw_if_index, new_dev_instance);
1103
1104 switch (rv)
1105 {
1106 case 0:
1107 break;
1108
1109 default:
1110 return clib_error_return (0, "vnet_interface_name_renumber returned %d",
Dave Barachba868bb2016-08-08 09:51:21 -04001111 rv);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001112
1113 }
1114
1115 return 0;
1116}
1117
1118
Dave Barachba868bb2016-08-08 09:51:21 -04001119/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001120VLIB_CLI_COMMAND (renumber_interface_command, static) = {
1121 .path = "renumber interface",
Billy McFalle9bac692017-08-11 14:05:11 -04001122 .short_help = "renumber interface <interface> <new-dev-instance>",
Ed Warnickecb9cada2015-12-08 15:45:58 -07001123 .function = renumber_interface_command_fn,
1124};
Dave Barachba868bb2016-08-08 09:51:21 -04001125/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001126
Damjan Marion8358ff92016-04-15 14:26:00 +02001127static clib_error_t *
1128promiscuous_cmd (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -04001129 unformat_input_t * input, vlib_cli_command_t * cmd)
Damjan Marion8358ff92016-04-15 14:26:00 +02001130{
Dave Barachba868bb2016-08-08 09:51:21 -04001131 vnet_main_t *vnm = vnet_get_main ();
Damjan Marion8358ff92016-04-15 14:26:00 +02001132 u32 hw_if_index;
1133 u32 flags = ETHERNET_INTERFACE_FLAG_ACCEPT_ALL;
Dave Barachba868bb2016-08-08 09:51:21 -04001134 ethernet_main_t *em = &ethernet_main;
1135 ethernet_interface_t *eif;
Damjan Marion8358ff92016-04-15 14:26:00 +02001136
1137 if (unformat (input, "on %U",
Dave Barachba868bb2016-08-08 09:51:21 -04001138 unformat_vnet_hw_interface, vnm, &hw_if_index))
Damjan Marion8358ff92016-04-15 14:26:00 +02001139 ;
1140 else if (unformat (input, "off %U",
Dave Barachba868bb2016-08-08 09:51:21 -04001141 unformat_ethernet_interface, vnm, &hw_if_index))
Damjan Marion8358ff92016-04-15 14:26:00 +02001142 flags = 0;
1143 else
1144 return clib_error_return (0, "unknown input `%U'",
Dave Barachba868bb2016-08-08 09:51:21 -04001145 format_unformat_error, input);
Damjan Marion8358ff92016-04-15 14:26:00 +02001146
1147 eif = ethernet_get_interface (em, hw_if_index);
1148 if (!eif)
1149 return clib_error_return (0, "not supported");
1150
1151 ethernet_set_flags (vnm, hw_if_index, flags);
1152 return 0;
1153}
1154
Dave Barachba868bb2016-08-08 09:51:21 -04001155/* *INDENT-OFF* */
Damjan Marion8358ff92016-04-15 14:26:00 +02001156VLIB_CLI_COMMAND (set_interface_promiscuous_cmd, static) = {
1157 .path = "set interface promiscuous",
Billy McFalle9bac692017-08-11 14:05:11 -04001158 .short_help = "set interface promiscuous [on|off] <interface>",
Damjan Marion8358ff92016-04-15 14:26:00 +02001159 .function = promiscuous_cmd,
1160};
Dave Barachba868bb2016-08-08 09:51:21 -04001161/* *INDENT-ON* */
Damjan Marion8358ff92016-04-15 14:26:00 +02001162
1163static clib_error_t *
1164mtu_cmd (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd)
1165{
Dave Barachba868bb2016-08-08 09:51:21 -04001166 vnet_main_t *vnm = vnet_get_main ();
Ole Troand7231612018-06-07 10:17:57 +02001167 u32 hw_if_index, sw_if_index, mtu;
Damjan Marionfe7d4a22018-04-13 19:43:39 +02001168 ethernet_main_t *em = &ethernet_main;
Ole Troand7231612018-06-07 10:17:57 +02001169 u32 mtus[VNET_N_MTU] = { 0, 0, 0, 0 };
Damjan Marion81bb6fc2022-01-16 22:47:55 +01001170 clib_error_t *err;
Damjan Marion8358ff92016-04-15 14:26:00 +02001171
Damjan Marionfe7d4a22018-04-13 19:43:39 +02001172 if (unformat (input, "%d %U", &mtu,
1173 unformat_vnet_hw_interface, vnm, &hw_if_index))
Damjan Marion8358ff92016-04-15 14:26:00 +02001174 {
Ole Troand7231612018-06-07 10:17:57 +02001175 /*
1176 * Change physical MTU on interface. Only supported for Ethernet
1177 * interfaces
1178 */
Damjan Marionfe7d4a22018-04-13 19:43:39 +02001179 ethernet_interface_t *eif = ethernet_get_interface (em, hw_if_index);
1180
1181 if (!eif)
1182 return clib_error_return (0, "not supported");
1183
Damjan Marion81bb6fc2022-01-16 22:47:55 +01001184 err = vnet_hw_interface_set_mtu (vnm, hw_if_index, mtu);
1185 if (err)
1186 return err;
Ole Troand7231612018-06-07 10:17:57 +02001187 goto done;
Damjan Marion8358ff92016-04-15 14:26:00 +02001188 }
Ole Troand7231612018-06-07 10:17:57 +02001189 else if (unformat (input, "packet %d %U", &mtu,
1190 unformat_vnet_sw_interface, vnm, &sw_if_index))
1191 /* Set default packet MTU (including L3 header */
1192 mtus[VNET_MTU_L3] = mtu;
1193 else if (unformat (input, "ip4 %d %U", &mtu,
1194 unformat_vnet_sw_interface, vnm, &sw_if_index))
1195 mtus[VNET_MTU_IP4] = mtu;
1196 else if (unformat (input, "ip6 %d %U", &mtu,
1197 unformat_vnet_sw_interface, vnm, &sw_if_index))
1198 mtus[VNET_MTU_IP6] = mtu;
1199 else if (unformat (input, "mpls %d %U", &mtu,
1200 unformat_vnet_sw_interface, vnm, &sw_if_index))
1201 mtus[VNET_MTU_MPLS] = mtu;
Damjan Marion8358ff92016-04-15 14:26:00 +02001202 else
Damjan Marionfe7d4a22018-04-13 19:43:39 +02001203 return clib_error_return (0, "unknown input `%U'",
1204 format_unformat_error, input);
Ole Troand7231612018-06-07 10:17:57 +02001205
1206 vnet_sw_interface_set_protocol_mtu (vnm, sw_if_index, mtus);
1207
1208done:
Damjan Marion8358ff92016-04-15 14:26:00 +02001209 return 0;
1210}
1211
Dave Barachba868bb2016-08-08 09:51:21 -04001212/* *INDENT-OFF* */
Damjan Marion8358ff92016-04-15 14:26:00 +02001213VLIB_CLI_COMMAND (set_interface_mtu_cmd, static) = {
1214 .path = "set interface mtu",
Ole Troand7231612018-06-07 10:17:57 +02001215 .short_help = "set interface mtu [packet|ip4|ip6|mpls] <value> <interface>",
Damjan Marion8358ff92016-04-15 14:26:00 +02001216 .function = mtu_cmd,
1217};
Dave Barachba868bb2016-08-08 09:51:21 -04001218/* *INDENT-ON* */
Damjan Marion8358ff92016-04-15 14:26:00 +02001219
Pavel Kotucekc631f2d2016-09-26 10:40:02 +02001220static clib_error_t *
Matthew Smithe0792fd2019-07-12 11:48:24 -05001221show_interface_sec_mac_addr_fn (vlib_main_t * vm, unformat_input_t * input,
1222 vlib_cli_command_t * cmd)
1223{
1224 vnet_main_t *vnm = vnet_get_main ();
1225 vnet_interface_main_t *im = &vnm->interface_main;
1226 ethernet_main_t *em = &ethernet_main;
1227 u32 sw_if_index = ~0;
1228 vnet_sw_interface_t *si, *sorted_sis = 0;
1229
1230 if (unformat (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
1231 {
1232 si = pool_elt_at_index (im->sw_interfaces, sw_if_index);
1233 vec_add1 (sorted_sis, si[0]);
1234 }
1235
1236 /* if an interface name was not passed, get all interfaces */
1237 if (vec_len (sorted_sis) == 0)
1238 {
1239 sorted_sis =
1240 vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
Damjan Marion8bea5892022-04-04 22:40:45 +02001241 vec_set_len (sorted_sis, 0);
Matthew Smithe0792fd2019-07-12 11:48:24 -05001242 /* *INDENT-OFF* */
Damjan Marionb2c31b62020-12-13 21:47:40 +01001243 pool_foreach (si, im->sw_interfaces)
1244 {
Matthew Smithe0792fd2019-07-12 11:48:24 -05001245 int visible = vnet_swif_is_api_visible (si);
1246 if (visible)
Damjan Marionb2c31b62020-12-13 21:47:40 +01001247 vec_add1 (sorted_sis, si[0]);
1248 }
Matthew Smithe0792fd2019-07-12 11:48:24 -05001249 /* *INDENT-ON* */
1250 /* Sort by name. */
1251 vec_sort_with_function (sorted_sis, sw_interface_name_compare);
1252 }
1253
1254 vec_foreach (si, sorted_sis)
1255 {
1256 vnet_sw_interface_t *sup_si;
1257 ethernet_interface_t *ei;
1258
1259 sup_si = vnet_get_sup_sw_interface (vnm, si->sw_if_index);
1260 ei = ethernet_get_interface (em, sup_si->hw_if_index);
1261
1262 vlib_cli_output (vm, "%U (%s):",
1263 format_vnet_sw_if_index_name, vnm, si->sw_if_index,
1264 (si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
1265 "up" : "dn");
1266
1267 if (ei && ei->secondary_addrs)
1268 {
Benoît Ganneb44c77d2020-10-20 16:24:17 +02001269 ethernet_interface_address_t *sec_addr;
Matthew Smithe0792fd2019-07-12 11:48:24 -05001270
1271 vec_foreach (sec_addr, ei->secondary_addrs)
1272 {
Benoît Ganneb44c77d2020-10-20 16:24:17 +02001273 vlib_cli_output (vm, " %U", format_mac_address_t, &sec_addr->mac);
Matthew Smithe0792fd2019-07-12 11:48:24 -05001274 }
1275 }
1276 }
1277
1278 vec_free (sorted_sis);
1279 return 0;
1280}
1281
1282/*?
1283 * This command is used to display interface secondary mac addresses.
1284 *
1285 * @cliexpar
1286 * Example of how to display interface secondary mac addresses:
1287 * @cliexstart{show interface secondary-mac-address}
1288 * @cliexend
1289?*/
1290/* *INDENT-OFF* */
1291VLIB_CLI_COMMAND (show_interface_sec_mac_addr, static) = {
1292 .path = "show interface secondary-mac-address",
1293 .short_help = "show interface secondary-mac-address [<interface>]",
1294 .function = show_interface_sec_mac_addr_fn,
1295};
1296/* *INDENT-ON* */
1297
1298static clib_error_t *
1299interface_add_del_mac_address (vlib_main_t * vm, unformat_input_t * input,
1300 vlib_cli_command_t * cmd)
1301{
1302 vnet_main_t *vnm = vnet_get_main ();
1303 vnet_sw_interface_t *si = NULL;
1304 clib_error_t *error = 0;
1305 u32 sw_if_index = ~0;
1306 u8 mac[6] = { 0 };
1307 u8 is_add, is_del;
1308
1309 is_add = is_del = 0;
1310
1311 if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
1312 {
1313 error = clib_error_return (0, "unknown interface `%U'",
1314 format_unformat_error, input);
1315 goto done;
1316 }
1317 if (!unformat_user (input, unformat_ethernet_address, mac))
1318 {
1319 error = clib_error_return (0, "expected mac address `%U'",
1320 format_unformat_error, input);
1321 goto done;
1322 }
1323
1324 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1325 {
1326 if (unformat (input, "add"))
1327 is_add = 1;
1328 else if (unformat (input, "del"))
1329 is_del = 1;
1330 else
1331 break;
1332 }
1333
1334 if (is_add == is_del)
1335 {
1336 error = clib_error_return (0, "must choose one of add or del");
1337 goto done;
1338 }
1339
1340 si = vnet_get_sw_interface (vnm, sw_if_index);
1341 error =
1342 vnet_hw_interface_add_del_mac_address (vnm, si->hw_if_index, mac, is_add);
1343
1344done:
1345 return error;
1346}
1347
1348/*?
1349 * The '<em>set interface secondary-mac-address </em>' command allows adding
1350 * or deleting extra MAC addresses on a given interface without changing the
1351 * default MAC address. This could allow packets sent to these MAC addresses
1352 * to be received without setting the interface to promiscuous mode.
1353 * Not all interfaces support this operation. The ones that do are mostly
1354 * hardware NICs, though virtio does also.
1355 *
1356 * @cliexpar
1357 * @parblock
1358 * Example of how to add a secondary MAC Address on an interface:
1359 * @cliexcmd{set interface secondary-mac-address GigabitEthernet0/8/0 aa:bb:cc:dd:ee:01 add}
1360 * Example of how to delete a secondary MAC address from an interface:
1361 * @cliexcmd{set interface secondary-mac-address GigabitEthernet0/8/0 aa:bb:cc:dd:ee:01 del}
1362 * @endparblock
1363?*/
1364/* *INDENT-OFF* */
1365VLIB_CLI_COMMAND (interface_add_del_mac_address_cmd, static) = {
1366 .path = "set interface secondary-mac-address",
1367 .short_help = "set interface secondary-mac-address <interface> <mac-address> [(add|del)]",
1368 .function = interface_add_del_mac_address,
1369};
1370/* *INDENT-ON* */
1371
1372static clib_error_t *
Pavel Kotucekc631f2d2016-09-26 10:40:02 +02001373set_interface_mac_address (vlib_main_t * vm, unformat_input_t * input,
1374 vlib_cli_command_t * cmd)
1375{
1376 vnet_main_t *vnm = vnet_get_main ();
Neale Rannsd867a7c2017-10-04 02:29:07 -07001377 vnet_sw_interface_t *si = NULL;
Pavel Kotucekc631f2d2016-09-26 10:40:02 +02001378 clib_error_t *error = 0;
1379 u32 sw_if_index = ~0;
John Lo62fcc0a2017-10-31 14:31:10 -04001380 u8 mac[6] = { 0 };
Pavel Kotucekc631f2d2016-09-26 10:40:02 +02001381
1382 if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
1383 {
1384 error = clib_error_return (0, "unknown interface `%U'",
1385 format_unformat_error, input);
1386 goto done;
1387 }
John Lo62fcc0a2017-10-31 14:31:10 -04001388 if (!unformat_user (input, unformat_ethernet_address, mac))
Pavel Kotucekc631f2d2016-09-26 10:40:02 +02001389 {
1390 error = clib_error_return (0, "expected mac address `%U'",
1391 format_unformat_error, input);
1392 goto done;
1393 }
Neale Rannsd867a7c2017-10-04 02:29:07 -07001394 si = vnet_get_sw_interface (vnm, sw_if_index);
1395 error = vnet_hw_interface_change_mac_address (vnm, si->hw_if_index, mac);
Pavel Kotucekc631f2d2016-09-26 10:40:02 +02001396done:
1397 return error;
1398}
1399
1400/*?
1401 * The '<em>set interface mac address </em>' command allows to set MAC address of given interface.
1402 * In case of NIC interfaces the one has to support MAC address change. A side effect of MAC address
1403 * change are changes of MAC addresses in FIB tables (ipv4 and ipv6).
1404 *
1405 * @cliexpar
1406 * @parblock
1407 * Example of how to change MAC Address of interface:
1408 * @cliexcmd{set interface mac address GigabitEthernet0/8/0 aa:bb:cc:dd:ee:01}
1409 * @cliexcmd{set interface mac address host-vpp0 aa:bb:cc:dd:ee:02}
1410 * @cliexcmd{set interface mac address tap-0 aa:bb:cc:dd:ee:03}
1411 * @cliexcmd{set interface mac address pg0 aa:bb:cc:dd:ee:04}
1412 * @endparblock
1413?*/
1414/* *INDENT-OFF* */
1415VLIB_CLI_COMMAND (set_interface_mac_address_cmd, static) = {
1416 .path = "set interface mac address",
Billy McFalle9bac692017-08-11 14:05:11 -04001417 .short_help = "set interface mac address <interface> <mac-address>",
Pavel Kotucekc631f2d2016-09-26 10:40:02 +02001418 .function = set_interface_mac_address,
1419};
1420/* *INDENT-ON* */
1421
Dave Barach7be864a2016-11-28 11:41:35 -05001422static clib_error_t *
1423set_tag (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd)
1424{
1425 vnet_main_t *vnm = vnet_get_main ();
1426 u32 sw_if_index = ~0;
1427 u8 *tag = 0;
1428
1429 if (!unformat (input, "%U %s", unformat_vnet_sw_interface,
1430 vnm, &sw_if_index, &tag))
1431 return clib_error_return (0, "unknown input `%U'",
1432 format_unformat_error, input);
1433
1434 vnet_set_sw_interface_tag (vnm, tag, sw_if_index);
1435
1436 return 0;
1437}
1438
1439/* *INDENT-OFF* */
1440VLIB_CLI_COMMAND (set_tag_command, static) = {
1441 .path = "set interface tag",
Billy McFalle9bac692017-08-11 14:05:11 -04001442 .short_help = "set interface tag <interface> <tag>",
Dave Barach7be864a2016-11-28 11:41:35 -05001443 .function = set_tag,
1444};
1445/* *INDENT-ON* */
1446
1447static clib_error_t *
1448clear_tag (vlib_main_t * vm, unformat_input_t * input,
1449 vlib_cli_command_t * cmd)
1450{
1451 vnet_main_t *vnm = vnet_get_main ();
1452 u32 sw_if_index = ~0;
1453
1454 if (!unformat (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
1455 return clib_error_return (0, "unknown input `%U'",
1456 format_unformat_error, input);
1457
1458 vnet_clear_sw_interface_tag (vnm, sw_if_index);
1459
1460 return 0;
1461}
1462
1463/* *INDENT-OFF* */
1464VLIB_CLI_COMMAND (clear_tag_command, static) = {
1465 .path = "clear interface tag",
Billy McFalle9bac692017-08-11 14:05:11 -04001466 .short_help = "clear interface tag <interface>",
Dave Barach7be864a2016-11-28 11:41:35 -05001467 .function = clear_tag,
1468};
1469/* *INDENT-ON* */
1470
Damjan Marion44036902017-04-28 12:29:15 +02001471static clib_error_t *
Neale Ranns1855b8e2018-07-11 10:31:26 -07001472set_ip_directed_broadcast (vlib_main_t * vm,
1473 unformat_input_t * input, vlib_cli_command_t * cmd)
1474{
1475 vnet_main_t *vnm = vnet_get_main ();
1476 u32 sw_if_index = ~0;
1477 u8 enable = 0;
1478
1479 if (!unformat (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index));
1480 else if (unformat (input, "enable"))
1481 enable = 1;
1482 else if (unformat (input, "disable"))
1483 enable = 0;
1484 else
1485 return clib_error_return (0, "unknown input: `%U'",
1486 format_unformat_error, input);
1487
1488 if (~0 == sw_if_index)
1489 return clib_error_return (0, "specify an interface: `%U'",
1490 format_unformat_error, input);
1491
1492 vnet_sw_interface_ip_directed_broadcast (vnm, sw_if_index, enable);
1493
1494 return 0;
1495}
1496
1497/*?
1498 * This command is used to enable/disable IP directed broadcast
1499 * If directed broadcast is enabled a packet sent to the interface's
1500 * subnet broadcast address will be sent L2 broadcast on the interface,
1501 * otherwise it is dropped.
1502 ?*/
1503/* *INDENT-OFF* */
1504VLIB_CLI_COMMAND (set_ip_directed_broadcast_command, static) = {
1505 .path = "set interface ip directed-broadcast",
1506 .short_help = "set interface enable <interface> <enable|disable>",
1507 .function = set_ip_directed_broadcast,
1508};
1509/* *INDENT-ON* */
1510
Stevenad8015b2017-10-29 22:10:46 -07001511clib_error_t *
1512set_hw_interface_change_rx_mode (vnet_main_t * vnm, u32 hw_if_index,
1513 u8 queue_id_valid, u32 queue_id,
Damjan Marioneabd4242020-10-07 20:59:07 +02001514 vnet_hw_if_rx_mode mode)
Stevenad8015b2017-10-29 22:10:46 -07001515{
1516 clib_error_t *error = 0;
1517 vnet_hw_interface_t *hw;
Damjan Marion94100532020-11-06 23:25:57 +01001518 u32 *queue_indices = 0;
Stevenad8015b2017-10-29 22:10:46 -07001519
1520 hw = vnet_get_hw_interface (vnm, hw_if_index);
1521
Damjan Marion94100532020-11-06 23:25:57 +01001522 if (queue_id_valid)
1523 {
1524 u32 queue_index;
1525 queue_index =
1526 vnet_hw_if_get_rx_queue_index_by_id (vnm, hw_if_index, queue_id);
1527 if (queue_index == ~0)
1528 return clib_error_return (0, "unknown queue %u on interface %s",
1529 queue_id, hw->name);
1530 vec_add1 (queue_indices, queue_index);
Stevenad8015b2017-10-29 22:10:46 -07001531 }
1532 else
Damjan Marion94100532020-11-06 23:25:57 +01001533 queue_indices = hw->rx_queue_indices;
Stevenad8015b2017-10-29 22:10:46 -07001534
Damjan Marion94100532020-11-06 23:25:57 +01001535 for (int i = 0; i < vec_len (queue_indices); i++)
1536 {
1537 int rv = vnet_hw_if_set_rx_queue_mode (vnm, queue_indices[i], mode);
1538 if (rv)
Wayne Morrison389aae52022-08-05 09:47:24 -04001539 {
1540 error = clib_error_return (
1541 0, "unable to set rx-mode on interface %v queue-id %u.\n",
1542 hw->name, queue_id);
1543 goto done;
1544 }
Damjan Marion94100532020-11-06 23:25:57 +01001545 }
1546
1547done:
1548 if (queue_indices != hw->rx_queue_indices)
1549 vec_free (queue_indices);
1550 vnet_hw_if_update_runtime_data (vnm, hw_if_index);
1551 return error;
Stevenad8015b2017-10-29 22:10:46 -07001552}
1553
Stevene3a395c2017-05-09 16:19:50 -07001554static clib_error_t *
Damjan Marion44036902017-04-28 12:29:15 +02001555set_interface_rx_mode (vlib_main_t * vm, unformat_input_t * input,
1556 vlib_cli_command_t * cmd)
1557{
1558 clib_error_t *error = 0;
1559 unformat_input_t _line_input, *line_input = &_line_input;
1560 vnet_main_t *vnm = vnet_get_main ();
Damjan Marion44036902017-04-28 12:29:15 +02001561 u32 hw_if_index = (u32) ~ 0;
1562 u32 queue_id = (u32) ~ 0;
Damjan Marioneabd4242020-10-07 20:59:07 +02001563 vnet_hw_if_rx_mode mode = VNET_HW_IF_RX_MODE_UNKNOWN;
Stevenad8015b2017-10-29 22:10:46 -07001564 u8 queue_id_valid = 0;
Dave Barach7be864a2016-11-28 11:41:35 -05001565
Damjan Marion44036902017-04-28 12:29:15 +02001566 if (!unformat_user (input, unformat_line_input, line_input))
1567 return 0;
1568
1569 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1570 {
1571 if (unformat
1572 (line_input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
1573 ;
1574 else if (unformat (line_input, "queue %d", &queue_id))
Stevenad8015b2017-10-29 22:10:46 -07001575 queue_id_valid = 1;
Damjan Marion44036902017-04-28 12:29:15 +02001576 else if (unformat (line_input, "polling"))
Damjan Marioneabd4242020-10-07 20:59:07 +02001577 mode = VNET_HW_IF_RX_MODE_POLLING;
Damjan Marion44036902017-04-28 12:29:15 +02001578 else if (unformat (line_input, "interrupt"))
Damjan Marioneabd4242020-10-07 20:59:07 +02001579 mode = VNET_HW_IF_RX_MODE_INTERRUPT;
Damjan Marion44036902017-04-28 12:29:15 +02001580 else if (unformat (line_input, "adaptive"))
Damjan Marioneabd4242020-10-07 20:59:07 +02001581 mode = VNET_HW_IF_RX_MODE_ADAPTIVE;
Damjan Marion44036902017-04-28 12:29:15 +02001582 else
1583 {
1584 error = clib_error_return (0, "parse error: '%U'",
1585 format_unformat_error, line_input);
1586 unformat_free (line_input);
1587 return error;
1588 }
1589 }
1590
1591 unformat_free (line_input);
1592
1593 if (hw_if_index == (u32) ~ 0)
1594 return clib_error_return (0, "please specify valid interface name");
1595
Damjan Marioneabd4242020-10-07 20:59:07 +02001596 if (mode == VNET_HW_IF_RX_MODE_UNKNOWN)
Damjan Marion44036902017-04-28 12:29:15 +02001597 return clib_error_return (0, "please specify valid rx-mode");
1598
Stevenad8015b2017-10-29 22:10:46 -07001599 error = set_hw_interface_change_rx_mode (vnm, hw_if_index, queue_id_valid,
1600 queue_id, mode);
Damjan Marion44036902017-04-28 12:29:15 +02001601
Stevene3a395c2017-05-09 16:19:50 -07001602 return (error);
Damjan Marion44036902017-04-28 12:29:15 +02001603}
1604
1605/*?
Billy McFalle9bac692017-08-11 14:05:11 -04001606 * This command is used to assign the RX packet processing mode (polling,
1607 * interrupt, adaptive) of the a given interface, and optionally a
1608 * given queue. If the '<em>queue</em>' is not provided, the '<em>mode</em>'
1609 * is applied to all queues of the interface. Not all interfaces support
1610 * all modes. To display the current rx-mode use the command
1611 * '<em>show interface rx-placement</em>'.
Damjan Marion44036902017-04-28 12:29:15 +02001612 *
1613 * @cliexpar
Billy McFalle9bac692017-08-11 14:05:11 -04001614 * Example of how to assign rx-mode to all queues on an interface:
1615 * @cliexcmd{set interface rx-mode VirtualEthernet0/0/12 polling}
1616 * Example of how to assign rx-mode to one queue of an interface:
1617 * @cliexcmd{set interface rx-mode VirtualEthernet0/0/12 queue 0 interrupt}
1618 * Example of how to display the rx-mode of all interfaces:
Damjan Marion44036902017-04-28 12:29:15 +02001619 * @cliexstart{show interface rx-placement}
1620 * Thread 1 (vpp_wk_0):
Billy McFalle9bac692017-08-11 14:05:11 -04001621 * node dpdk-input:
1622 * GigabitEthernet7/0/0 queue 0 (polling)
1623 * node vhost-user-input:
1624 * VirtualEthernet0/0/12 queue 0 (interrupt)
1625 * VirtualEthernet0/0/12 queue 2 (polling)
1626 * VirtualEthernet0/0/13 queue 0 (polling)
1627 * VirtualEthernet0/0/13 queue 2 (polling)
Damjan Marion44036902017-04-28 12:29:15 +02001628 * Thread 2 (vpp_wk_1):
Billy McFalle9bac692017-08-11 14:05:11 -04001629 * node dpdk-input:
1630 * GigabitEthernet7/0/1 queue 0 (polling)
1631 * node vhost-user-input:
1632 * VirtualEthernet0/0/12 queue 1 (polling)
1633 * VirtualEthernet0/0/12 queue 3 (polling)
1634 * VirtualEthernet0/0/13 queue 1 (polling)
1635 * VirtualEthernet0/0/13 queue 3 (polling)
Damjan Marion44036902017-04-28 12:29:15 +02001636 * @cliexend
Damjan Marion44036902017-04-28 12:29:15 +02001637?*/
1638/* *INDENT-OFF* */
Damjan Marionfe7d4a22018-04-13 19:43:39 +02001639VLIB_CLI_COMMAND (cmd_set_if_rx_mode,static) = {
Damjan Marion44036902017-04-28 12:29:15 +02001640 .path = "set interface rx-mode",
1641 .short_help = "set interface rx-mode <interface> [queue <n>] [polling | interrupt | adaptive]",
1642 .function = set_interface_rx_mode,
1643};
1644/* *INDENT-ON* */
1645
1646static clib_error_t *
1647show_interface_rx_placement_fn (vlib_main_t * vm, unformat_input_t * input,
1648 vlib_cli_command_t * cmd)
1649{
1650 u8 *s = 0;
1651 vnet_main_t *vnm = vnet_get_main ();
Mohammed Hawari9fecbe12020-12-11 19:36:37 +01001652 vnet_hw_if_rx_queue_t **all_queues = 0;
1653 vnet_hw_if_rx_queue_t **qptr;
1654 vnet_hw_if_rx_queue_t *q;
Nathan Skrzypczak455779f2021-02-15 14:48:33 +01001655 pool_foreach (q, vnm->interface_main.hw_if_rx_queues)
Mohammed Hawari9fecbe12020-12-11 19:36:37 +01001656 vec_add1 (all_queues, q);
1657 vec_sort_with_function (all_queues, vnet_hw_if_rxq_cmp_cli_api);
1658 u32 prev_node = ~0;
Damjan Marion44036902017-04-28 12:29:15 +02001659
Mohammed Hawari9fecbe12020-12-11 19:36:37 +01001660 vec_foreach (qptr, all_queues)
1661 {
1662 u32 current_thread = qptr[0]->thread_index;
1663 u32 hw_if_index = qptr[0]->hw_if_index;
1664 vnet_hw_interface_t *hw_if = vnet_get_hw_interface (vnm, hw_if_index);
1665 u32 current_node = hw_if->input_node_index;
1666 if (current_node != prev_node)
1667 s = format (s, " node %U:\n", format_vlib_node_name, vm, current_node);
1668 s = format (s, " %U queue %u (%U)\n", format_vnet_sw_if_index_name,
1669 vnm, hw_if->sw_if_index, qptr[0]->queue_id,
1670 format_vnet_hw_if_rx_mode, qptr[0]->mode);
1671 if (qptr == all_queues + vec_len (all_queues) - 1 ||
1672 current_thread != qptr[1]->thread_index)
1673 {
1674 vlib_cli_output (vm, "Thread %u (%s):\n%v", current_thread,
1675 vlib_worker_threads[current_thread].name, s);
1676 vec_reset_length (s);
1677 }
1678 prev_node = current_node;
1679 }
Damjan Marion44036902017-04-28 12:29:15 +02001680 vec_free (s);
Mohammed Hawari9fecbe12020-12-11 19:36:37 +01001681 vec_free (all_queues);
Damjan Marion44036902017-04-28 12:29:15 +02001682 return 0;
1683}
1684
Billy McFalle9bac692017-08-11 14:05:11 -04001685/*?
1686 * This command is used to display the interface and queue worker
1687 * thread placement.
1688 *
1689 * @cliexpar
1690 * Example of how to display the interface placement:
1691 * @cliexstart{show interface rx-placement}
1692 * Thread 1 (vpp_wk_0):
1693 * node dpdk-input:
1694 * GigabitEthernet7/0/0 queue 0 (polling)
1695 * node vhost-user-input:
1696 * VirtualEthernet0/0/12 queue 0 (polling)
1697 * VirtualEthernet0/0/12 queue 2 (polling)
1698 * VirtualEthernet0/0/13 queue 0 (polling)
1699 * VirtualEthernet0/0/13 queue 2 (polling)
1700 * Thread 2 (vpp_wk_1):
1701 * node dpdk-input:
1702 * GigabitEthernet7/0/1 queue 0 (polling)
1703 * node vhost-user-input:
1704 * VirtualEthernet0/0/12 queue 1 (polling)
1705 * VirtualEthernet0/0/12 queue 3 (polling)
1706 * VirtualEthernet0/0/13 queue 1 (polling)
1707 * VirtualEthernet0/0/13 queue 3 (polling)
1708 * @cliexend
1709?*/
Damjan Marion44036902017-04-28 12:29:15 +02001710/* *INDENT-OFF* */
1711VLIB_CLI_COMMAND (show_interface_rx_placement, static) = {
1712 .path = "show interface rx-placement",
1713 .short_help = "show interface rx-placement",
1714 .function = show_interface_rx_placement_fn,
1715};
1716/* *INDENT-ON* */
Mohsin Kazmi54f7c512018-08-23 18:28:11 +02001717clib_error_t *
1718set_hw_interface_rx_placement (u32 hw_if_index, u32 queue_id,
1719 u32 thread_index, u8 is_main)
Damjan Marion44036902017-04-28 12:29:15 +02001720{
Damjan Marion44036902017-04-28 12:29:15 +02001721 vnet_main_t *vnm = vnet_get_main ();
1722 vnet_device_main_t *vdm = &vnet_device_main;
Damjan Marion94100532020-11-06 23:25:57 +01001723 vnet_hw_interface_t *hw;
1724 u32 queue_index;
Damjan Marion44036902017-04-28 12:29:15 +02001725
Mohsin Kazmi54f7c512018-08-23 18:28:11 +02001726 if (is_main)
1727 thread_index = 0;
1728 else
1729 thread_index += vdm->first_worker_thread_index;
Damjan Marion44036902017-04-28 12:29:15 +02001730
1731 if (thread_index > vdm->last_worker_thread_index)
1732 return clib_error_return (0,
1733 "please specify valid worker thread or main");
1734
Damjan Marion94100532020-11-06 23:25:57 +01001735 hw = vnet_get_hw_interface (vnm, hw_if_index);
Damjan Marion44036902017-04-28 12:29:15 +02001736
Damjan Marion94100532020-11-06 23:25:57 +01001737 queue_index =
1738 vnet_hw_if_get_rx_queue_index_by_id (vnm, hw_if_index, queue_id);
1739 if (queue_index == ~0)
1740 return clib_error_return (0, "unknown queue %u on interface %s", queue_id,
1741 hw->name);
1742 vnet_hw_if_set_rx_queue_thread_index (vnm, queue_index, thread_index);
1743 vnet_hw_if_update_runtime_data (vnm, hw_if_index);
1744 return 0;
Mohsin Kazmi54f7c512018-08-23 18:28:11 +02001745}
1746
1747static clib_error_t *
Mohammed Hawari9fecbe12020-12-11 19:36:37 +01001748set_interface_rx_placement (vlib_main_t *vm, unformat_input_t *input,
1749 vlib_cli_command_t *cmd)
Mohsin Kazmi54f7c512018-08-23 18:28:11 +02001750{
1751 clib_error_t *error = 0;
1752 unformat_input_t _line_input, *line_input = &_line_input;
1753 vnet_main_t *vnm = vnet_get_main ();
1754 u32 hw_if_index = (u32) ~ 0;
1755 u32 queue_id = (u32) 0;
1756 u32 thread_index = (u32) ~ 0;
1757 u8 is_main = 0;
1758
1759 if (!unformat_user (input, unformat_line_input, line_input))
1760 return 0;
1761
1762 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1763 {
1764 if (unformat
1765 (line_input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
1766 ;
1767 else if (unformat (line_input, "queue %d", &queue_id))
1768 ;
1769 else if (unformat (line_input, "main", &thread_index))
1770 is_main = 1;
1771 else if (unformat (line_input, "worker %d", &thread_index))
1772 ;
1773 else
1774 {
1775 error = clib_error_return (0, "parse error: '%U'",
1776 format_unformat_error, line_input);
1777 unformat_free (line_input);
1778 return error;
1779 }
1780 }
1781
1782 unformat_free (line_input);
1783
1784 if (hw_if_index == (u32) ~ 0)
1785 return clib_error_return (0, "please specify valid interface name");
1786
1787 error = set_hw_interface_rx_placement (hw_if_index, queue_id, thread_index,
1788 is_main);
1789
1790 return (error);
Damjan Marion44036902017-04-28 12:29:15 +02001791}
1792
1793/*?
1794 * This command is used to assign a given interface, and optionally a
1795 * given queue, to a different thread. If the '<em>queue</em>' is not provided,
Billy McFalle9bac692017-08-11 14:05:11 -04001796 * it defaults to 0. The '<em>worker</em>' parameter is zero based and the index
1797 * in the thread name, for example, 0 in the thread name '<em>vpp_wk_0</em>'.
Damjan Marion44036902017-04-28 12:29:15 +02001798 *
1799 * @cliexpar
1800 * Example of how to display the interface placement:
Billy McFalle9bac692017-08-11 14:05:11 -04001801 * @cliexstart{show interface rx-placement}
Damjan Marion44036902017-04-28 12:29:15 +02001802 * Thread 1 (vpp_wk_0):
Billy McFalle9bac692017-08-11 14:05:11 -04001803 * node dpdk-input:
1804 * GigabitEthernet7/0/0 queue 0 (polling)
1805 * node vhost-user-input:
1806 * VirtualEthernet0/0/12 queue 0 (polling)
1807 * VirtualEthernet0/0/12 queue 2 (polling)
1808 * VirtualEthernet0/0/13 queue 0 (polling)
1809 * VirtualEthernet0/0/13 queue 2 (polling)
Damjan Marion44036902017-04-28 12:29:15 +02001810 * Thread 2 (vpp_wk_1):
Billy McFalle9bac692017-08-11 14:05:11 -04001811 * node dpdk-input:
1812 * GigabitEthernet7/0/1 queue 0 (polling)
1813 * node vhost-user-input:
1814 * VirtualEthernet0/0/12 queue 1 (polling)
1815 * VirtualEthernet0/0/12 queue 3 (polling)
1816 * VirtualEthernet0/0/13 queue 1 (polling)
1817 * VirtualEthernet0/0/13 queue 3 (polling)
Damjan Marion44036902017-04-28 12:29:15 +02001818 * @cliexend
Billy McFalle9bac692017-08-11 14:05:11 -04001819 * Example of how to assign a interface and queue to a worker thread:
1820 * @cliexcmd{set interface rx-placement VirtualEthernet0/0/12 queue 1 worker 0}
1821 * Example of how to display the interface placement:
1822 * @cliexstart{show interface rx-placement}
1823 * Thread 1 (vpp_wk_0):
1824 * node dpdk-input:
1825 * GigabitEthernet7/0/0 queue 0 (polling)
1826 * node vhost-user-input:
1827 * VirtualEthernet0/0/12 queue 0 (polling)
1828 * VirtualEthernet0/0/12 queue 1 (polling)
1829 * VirtualEthernet0/0/12 queue 2 (polling)
1830 * VirtualEthernet0/0/13 queue 0 (polling)
1831 * VirtualEthernet0/0/13 queue 2 (polling)
1832 * Thread 2 (vpp_wk_1):
1833 * node dpdk-input:
1834 * GigabitEthernet7/0/1 queue 0 (polling)
1835 * node vhost-user-input:
1836 * VirtualEthernet0/0/12 queue 3 (polling)
1837 * VirtualEthernet0/0/13 queue 1 (polling)
1838 * VirtualEthernet0/0/13 queue 3 (polling)
1839 * @cliexend
Damjan Marion44036902017-04-28 12:29:15 +02001840?*/
1841/* *INDENT-OFF* */
1842VLIB_CLI_COMMAND (cmd_set_if_rx_placement,static) = {
1843 .path = "set interface rx-placement",
Billy McFalle9bac692017-08-11 14:05:11 -04001844 .short_help = "set interface rx-placement <interface> [queue <n>] "
Damjan Marion6f9ac652017-06-15 19:01:31 +02001845 "[worker <n> | main]",
Damjan Marion44036902017-04-28 12:29:15 +02001846 .function = set_interface_rx_placement,
Damjan Marion6f9ac652017-06-15 19:01:31 +02001847 .is_mp_safe = 1,
Damjan Marion44036902017-04-28 12:29:15 +02001848};
Damjan Marion44036902017-04-28 12:29:15 +02001849/* *INDENT-ON* */
Dave Barach5ecd5a52019-02-25 15:27:28 -05001850
Mohsin Kazmi0d05c0d2021-11-09 17:44:10 +00001851int
Mohsin Kazmi005605f2021-05-24 18:33:50 +02001852set_hw_interface_tx_queue (u32 hw_if_index, u32 queue_id, uword *bitmap)
1853{
1854 vnet_main_t *vnm = vnet_get_main ();
Mohsin Kazmi0d05c0d2021-11-09 17:44:10 +00001855 vlib_thread_main_t *vtm = vlib_get_thread_main ();
Mohsin Kazmi005605f2021-05-24 18:33:50 +02001856 vnet_hw_if_tx_queue_t *txq;
1857 u32 queue_index;
1858 u32 thread_index;
1859
Mohsin Kazmi005605f2021-05-24 18:33:50 +02001860 /* highest set bit in bitmap should not exceed last worker thread index */
Steven Luong8e3f1092021-06-17 08:22:50 -07001861 thread_index = clib_bitmap_last_set (bitmap);
Mohsin Kazmi0d05c0d2021-11-09 17:44:10 +00001862 if ((thread_index != ~0) && (thread_index >= vtm->n_vlib_mains))
1863 return VNET_API_ERROR_INVALID_VALUE;
Mohsin Kazmi005605f2021-05-24 18:33:50 +02001864
1865 queue_index =
1866 vnet_hw_if_get_tx_queue_index_by_id (vnm, hw_if_index, queue_id);
1867 if (queue_index == ~0)
Mohsin Kazmi0d05c0d2021-11-09 17:44:10 +00001868 return VNET_API_ERROR_INVALID_QUEUE;
Mohsin Kazmi005605f2021-05-24 18:33:50 +02001869
1870 txq = vnet_hw_if_get_tx_queue (vnm, queue_index);
1871
1872 // free the existing bitmap
1873 if (clib_bitmap_count_set_bits (txq->threads))
1874 {
1875 txq->shared_queue = 0;
1876 clib_bitmap_free (txq->threads);
1877 }
1878
1879 clib_bitmap_foreach (thread_index, bitmap)
1880 vnet_hw_if_tx_queue_assign_thread (vnm, queue_index, thread_index);
1881
1882 vnet_hw_if_update_runtime_data (vnm, hw_if_index);
1883 return 0;
1884}
1885
1886static clib_error_t *
1887set_interface_tx_queue (vlib_main_t *vm, unformat_input_t *input,
1888 vlib_cli_command_t *cmd)
1889{
1890 clib_error_t *error = 0;
1891 unformat_input_t _line_input, *line_input = &_line_input;
1892 vnet_main_t *vnm = vnet_get_main ();
1893 u32 hw_if_index = (u32) ~0;
1894 u32 queue_id = (u32) 0;
1895 uword *bitmap = 0;
Mohsin Kazmi0d05c0d2021-11-09 17:44:10 +00001896 int rv = 0;
Mohsin Kazmi005605f2021-05-24 18:33:50 +02001897
1898 if (!unformat_user (input, unformat_line_input, line_input))
1899 return 0;
1900
1901 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1902 {
1903 if (unformat (line_input, "%U", unformat_vnet_hw_interface, vnm,
1904 &hw_if_index))
1905 ;
1906 else if (unformat (line_input, "queue %d", &queue_id))
1907 ;
1908 else if (unformat (line_input, "threads %U", unformat_bitmap_list,
1909 &bitmap))
1910 ;
1911 else
1912 {
1913 error = clib_error_return (0, "parse error: '%U'",
1914 format_unformat_error, line_input);
1915 unformat_free (line_input);
1916 return error;
1917 }
1918 }
1919
1920 unformat_free (line_input);
1921
1922 if (hw_if_index == (u32) ~0)
1923 {
1924 error = clib_error_return (0, "please specify valid interface name");
1925 goto error;
1926 }
1927
Mohsin Kazmi0d05c0d2021-11-09 17:44:10 +00001928 rv = set_hw_interface_tx_queue (hw_if_index, queue_id, bitmap);
1929
1930 switch (rv)
1931 {
1932 case VNET_API_ERROR_INVALID_VALUE:
1933 error = clib_error_return (
1934 0, "please specify valid thread(s) - last thread index %u",
1935 clib_bitmap_last_set (bitmap));
1936 break;
1937 case VNET_API_ERROR_INVALID_QUEUE:
1938 error = clib_error_return (
1939 0, "unknown queue %u on interface %s", queue_id,
1940 vnet_get_hw_interface (vnet_get_main (), hw_if_index)->name);
1941 break;
1942 default:
1943 break;
1944 }
Mohsin Kazmi005605f2021-05-24 18:33:50 +02001945
1946error:
1947 clib_bitmap_free (bitmap);
1948 return (error);
1949}
1950
1951VLIB_CLI_COMMAND (cmd_set_if_tx_queue, static) = {
1952 .path = "set interface tx-queue",
1953 .short_help = "set interface tx-queue <interface> queue <n> "
Steven Luong8e3f1092021-06-17 08:22:50 -07001954 "[threads <list>]",
Mohsin Kazmi005605f2021-05-24 18:33:50 +02001955 .function = set_interface_tx_queue,
1956 .is_mp_safe = 1,
1957};
1958
1959clib_error_t *
Chenmin Sunc4665092020-07-06 08:20:39 +08001960set_interface_rss_queues (vlib_main_t * vm, u32 hw_if_index,
1961 clib_bitmap_t * bitmap)
1962{
1963 vnet_main_t *vnm = vnet_get_main ();
1964 vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, hw_if_index);
1965
1966 return vnet_hw_interface_set_rss_queues (vnm, hi, bitmap);
1967}
1968
1969static clib_error_t *
1970set_interface_rss_queues_fn (vlib_main_t * vm,
1971 unformat_input_t * input,
1972 vlib_cli_command_t * cmd)
1973{
1974 clib_error_t *error = 0;
1975 unformat_input_t _line_input, *line_input = &_line_input;
1976 vnet_main_t *vnm = vnet_get_main ();
1977 u32 hw_if_index = (u32) ~ 0;
1978 clib_bitmap_t *bitmap = NULL;
1979
1980 if (!unformat_user (input, unformat_line_input, line_input))
1981 return 0;
1982
1983 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1984 {
1985 if (unformat
1986 (line_input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
1987 ;
1988 else
1989 if (unformat (line_input, "list %U", unformat_bitmap_list, &bitmap))
1990 ;
1991 else
1992 {
1993 error = clib_error_return (0, "parse error: '%U'",
1994 format_unformat_error, line_input);
1995 unformat_free (line_input);
1996 goto done;
1997 }
1998 }
1999
2000 unformat_free (line_input);
2001
2002 if (hw_if_index == (u32) ~ 0)
2003 {
2004 error = clib_error_return (0, "please specify valid interface name");
2005 goto done;
2006 }
2007
2008 if (bitmap == NULL)
2009 {
2010 error = clib_error_return (0, "please specify the valid rss queues");
2011 goto done;
2012 }
2013
2014 error = set_interface_rss_queues (vm, hw_if_index, bitmap);
2015
2016done:
2017 if (bitmap)
2018 clib_bitmap_free (bitmap);
2019
2020 return (error);
2021}
2022
2023/*?
2024 * This command is used to set the rss queues of a given interface
2025 * Not all the interfaces support this operation.
2026 * To display the current rss queues, use the command
2027 * '<em>show hardware-interfaces</em>'.
2028 *
2029 * @cliexpar
2030 * Example of how to set the rss queues to 0,2-5,7 of an interface:
2031 * @cliexstart{set interface rss queues VirtualFunctionEthernet18/1/0 list 0,2-5,7}
2032 * @cliexend
2033?*/
2034/* *INDENT-OFF* */
2035VLIB_CLI_COMMAND (cmd_set_interface_rss_queues,static) = {
2036 .path = "set interface rss queues",
2037 .short_help = "set interface rss queues <interface> <list <queue-list>>",
2038 .function = set_interface_rss_queues_fn,
2039};
2040/* *INDENT-ON* */
2041
Dave Barach33909772019-09-23 10:27:27 -04002042static u8 *
2043format_vnet_pcap (u8 * s, va_list * args)
2044{
2045 vnet_pcap_t *pp = va_arg (*args, vnet_pcap_t *);
2046 int type = va_arg (*args, int);
2047 int printed = 0;
2048
2049 if (type == 0)
2050 {
2051 if (pp->pcap_rx_enable)
2052 {
2053 s = format (s, "rx");
2054 printed = 1;
2055 }
2056 if (pp->pcap_tx_enable)
2057 {
2058 if (printed)
2059 s = format (s, " and ");
2060 s = format (s, "tx");
2061 printed = 1;
2062 }
2063 if (pp->pcap_drop_enable)
2064 {
2065 if (printed)
2066 s = format (s, " and ");
2067 s = format (s, "drop");
2068 printed = 1;
2069 }
2070 return s;
2071 }
2072 s = format (s, "unknown type %d!", type);
2073 return s;
2074}
2075
2076
Dave Barachb97641c2019-09-09 16:38:17 -04002077int
2078vnet_pcap_dispatch_trace_configure (vnet_pcap_dispatch_trace_args_t * a)
2079{
2080 vlib_main_t *vm = vlib_get_main ();
Damjan Marion8fb5add2021-03-04 18:41:59 +01002081 vnet_main_t *vnm = vnet_get_main ();
2082 vnet_pcap_t *pp = &vnm->pcap;
Dave Barachb97641c2019-09-09 16:38:17 -04002083 pcap_main_t *pm = &pp->pcap_main;
Dave Barachf5667c32019-09-25 11:27:46 -04002084 vnet_classify_main_t *cm = &vnet_classify_main;
Dave Barachb97641c2019-09-09 16:38:17 -04002085
2086 if (a->status)
2087 {
Dave Barach33909772019-09-23 10:27:27 -04002088 if (pp->pcap_rx_enable || pp->pcap_tx_enable || pp->pcap_drop_enable)
Dave Barachb97641c2019-09-09 16:38:17 -04002089 {
2090 vlib_cli_output
Dave Barach33909772019-09-23 10:27:27 -04002091 (vm, "pcap %U dispatch capture enabled: %d of %d pkts...",
2092 format_vnet_pcap, pp, 0 /* print type */ ,
Dave Barachb97641c2019-09-09 16:38:17 -04002093 pm->n_packets_captured, pm->n_packets_to_capture);
2094 vlib_cli_output (vm, "capture to file %s", pm->file_name);
2095 }
2096 else
Dave Barach33909772019-09-23 10:27:27 -04002097 vlib_cli_output (vm, "pcap dispatch capture disabled");
2098
Dave Barachb97641c2019-09-09 16:38:17 -04002099 return 0;
2100 }
2101
2102 /* Consistency checks */
2103
2104 /* Enable w/ capture already enabled not allowed */
Dave Barach33909772019-09-23 10:27:27 -04002105 if ((pp->pcap_rx_enable + pp->pcap_tx_enable + pp->pcap_drop_enable)
2106 && (a->rx_enable + a->tx_enable + a->drop_enable))
Dave Barachb97641c2019-09-09 16:38:17 -04002107 return VNET_API_ERROR_INVALID_VALUE;
2108
2109 /* Disable capture with capture already disabled, not interesting */
Mohammed Hawari9fecbe12020-12-11 19:36:37 +01002110 if (((pp->pcap_rx_enable + pp->pcap_tx_enable + pp->pcap_drop_enable) ==
2111 0) &&
2112 ((a->rx_enable + a->tx_enable + a->drop_enable == 0)))
Dave Barachb97641c2019-09-09 16:38:17 -04002113 return VNET_API_ERROR_VALUE_EXIST;
2114
2115 /* Change number of packets to capture while capturing */
Dave Barach33909772019-09-23 10:27:27 -04002116 if ((pp->pcap_rx_enable + pp->pcap_tx_enable + pp->pcap_drop_enable)
2117 && (a->rx_enable + a->tx_enable + a->drop_enable)
Dave Barachb97641c2019-09-09 16:38:17 -04002118 && (pm->n_packets_to_capture != a->packets_to_capture))
2119 return VNET_API_ERROR_INVALID_VALUE_2;
2120
Dave Barach33909772019-09-23 10:27:27 -04002121 /* Classify filter specified, but no classify filter configured */
Dave Barachf5667c32019-09-25 11:27:46 -04002122 if ((a->rx_enable + a->tx_enable + a->drop_enable) && a->filter &&
Benoît Ganne5943e362021-02-26 14:46:58 +01002123 (!cm->classify_table_index_by_sw_if_index ||
2124 cm->classify_table_index_by_sw_if_index[0] == ~0))
Dave Barach9137e542019-09-13 17:47:50 -04002125 return VNET_API_ERROR_NO_SUCH_LABEL;
2126
Dave Barach33909772019-09-23 10:27:27 -04002127 if (a->rx_enable + a->tx_enable + a->drop_enable)
Dave Barachb97641c2019-09-09 16:38:17 -04002128 {
Dave Barach586462f2020-08-05 16:12:35 -04002129 void *save_pcap_data;
2130
Dave Barach33909772019-09-23 10:27:27 -04002131 /* Sanity check max bytes per pkt */
2132 if (a->max_bytes_per_pkt < 32 || a->max_bytes_per_pkt > 9000)
2133 return VNET_API_ERROR_INVALID_MEMORY_SIZE;
2134
Dave Barachb97641c2019-09-09 16:38:17 -04002135 /* Clean up from previous run, if any */
Dave Barach586462f2020-08-05 16:12:35 -04002136 vec_reset_length (pm->pcap_data);
2137
2138 /* Throw away the data buffer? */
2139 if (a->free_data)
2140 vec_free (pm->pcap_data);
2141
2142 save_pcap_data = pm->pcap_data;
2143
Dave Barachb97641c2019-09-09 16:38:17 -04002144 memset (pm, 0, sizeof (*pm));
2145
Dave Barach586462f2020-08-05 16:12:35 -04002146 pm->pcap_data = save_pcap_data;
2147
Dave Barach11fb09e2020-08-06 12:10:09 -04002148 vec_validate_aligned (vnet_trace_placeholder, 2048,
2149 CLIB_CACHE_LINE_BYTES);
Dave Barachb97641c2019-09-09 16:38:17 -04002150 if (pm->lock == 0)
2151 clib_spinlock_init (&(pm->lock));
2152
2153 if (a->filename == 0)
Dave Barach33909772019-09-23 10:27:27 -04002154 {
2155 u8 *stem = 0;
2156
2157 if (a->rx_enable)
2158 stem = format (stem, "rx");
2159 if (a->tx_enable)
2160 stem = format (stem, "tx");
2161 if (a->drop_enable)
2162 stem = format (stem, "drop");
Benoît Ganne7d4a9972020-07-17 11:49:56 +02002163 a->filename = format (0, "/tmp/%v.pcap%c", stem, 0);
Dave Barach33909772019-09-23 10:27:27 -04002164 vec_free (stem);
2165 }
Dave Barachb97641c2019-09-09 16:38:17 -04002166
2167 pm->file_name = (char *) a->filename;
2168 pm->n_packets_captured = 0;
2169 pm->packet_type = PCAP_PACKET_TYPE_ethernet;
Dave Barach586462f2020-08-05 16:12:35 -04002170 /* Preallocate the data vector? */
2171 if (a->preallocate_data)
2172 {
2173 vec_validate
2174 (pm->pcap_data, a->packets_to_capture
2175 * ((sizeof (pcap_packet_header_t) + a->max_bytes_per_pkt)));
2176 vec_reset_length (pm->pcap_data);
2177 }
Dave Barachb97641c2019-09-09 16:38:17 -04002178 pm->n_packets_to_capture = a->packets_to_capture;
2179 pp->pcap_sw_if_index = a->sw_if_index;
Dave Barach9137e542019-09-13 17:47:50 -04002180 if (a->filter)
Jon Loeliger5c1e48c2020-10-15 14:41:36 -04002181 pp->filter_classify_table_index =
2182 cm->classify_table_index_by_sw_if_index[0];
Dave Barach9137e542019-09-13 17:47:50 -04002183 else
2184 pp->filter_classify_table_index = ~0;
Benoît Ganne5cfe4522021-03-03 17:37:25 +01002185 pp->pcap_error_index = a->drop_err;
Dave Barach33909772019-09-23 10:27:27 -04002186 pp->pcap_rx_enable = a->rx_enable;
2187 pp->pcap_tx_enable = a->tx_enable;
2188 pp->pcap_drop_enable = a->drop_enable;
2189 pp->max_bytes_per_pkt = a->max_bytes_per_pkt;
Dave Barachb97641c2019-09-09 16:38:17 -04002190 }
2191 else
2192 {
Dave Barach33909772019-09-23 10:27:27 -04002193 pp->pcap_rx_enable = 0;
2194 pp->pcap_tx_enable = 0;
2195 pp->pcap_drop_enable = 0;
Dave Barachf5667c32019-09-25 11:27:46 -04002196 pp->filter_classify_table_index = ~0;
Benoît Ganne5cfe4522021-03-03 17:37:25 +01002197 pp->pcap_error_index = ~0;
Dave Barachb97641c2019-09-09 16:38:17 -04002198 if (pm->n_packets_captured)
2199 {
2200 clib_error_t *error;
2201 pm->n_packets_to_capture = pm->n_packets_captured;
2202 vlib_cli_output (vm, "Write %d packets to %s, and stop capture...",
2203 pm->n_packets_captured, pm->file_name);
2204 error = pcap_write (pm);
Andrew Yourtchenko4da15062019-09-11 14:14:43 +00002205 if (pm->flags & PCAP_MAIN_INIT_DONE)
Dave Barachb97641c2019-09-09 16:38:17 -04002206 pcap_close (pm);
2207 /* Report I/O errors... */
2208 if (error)
2209 {
2210 clib_error_report (error);
2211 return VNET_API_ERROR_SYSCALL_ERROR_1;
2212 }
Dave Barach586462f2020-08-05 16:12:35 -04002213 vec_free (pm->file_name);
2214 if (a->free_data)
2215 vec_free (pm->pcap_data);
Dave Barachb97641c2019-09-09 16:38:17 -04002216 return 0;
2217 }
2218 else
2219 return VNET_API_ERROR_NO_SUCH_ENTRY;
2220 }
2221
2222 return 0;
2223}
2224
2225static clib_error_t *
Dave Barach33909772019-09-23 10:27:27 -04002226pcap_trace_command_fn (vlib_main_t * vm,
2227 unformat_input_t * input, vlib_cli_command_t * cmd)
Dave Barach5ecd5a52019-02-25 15:27:28 -05002228{
Dave Barach5ecd5a52019-02-25 15:27:28 -05002229 unformat_input_t _line_input, *line_input = &_line_input;
Dave Barachb97641c2019-09-09 16:38:17 -04002230 vnet_pcap_dispatch_trace_args_t _a, *a = &_a;
Dave Barach5ecd5a52019-02-25 15:27:28 -05002231 vnet_main_t *vnm = vnet_get_main ();
Dave Barachb97641c2019-09-09 16:38:17 -04002232 u8 *filename = 0;
2233 u32 max = 1000;
Dave Barach33909772019-09-23 10:27:27 -04002234 u32 max_bytes_per_pkt = 512;
Dave Barachb97641c2019-09-09 16:38:17 -04002235 int rv;
Dave Barach33909772019-09-23 10:27:27 -04002236 int rx_enable = 0;
2237 int tx_enable = 0;
Dave Barach586462f2020-08-05 16:12:35 -04002238 int preallocate_data = 0;
Dave Barach33909772019-09-23 10:27:27 -04002239 int drop_enable = 0;
Dave Barachb97641c2019-09-09 16:38:17 -04002240 int status = 0;
Dave Barach9137e542019-09-13 17:47:50 -04002241 int filter = 0;
Dave Barach586462f2020-08-05 16:12:35 -04002242 int free_data = 0;
Dave Barach4330c462020-06-10 17:07:32 -04002243 u32 sw_if_index = 0; /* default: any interface */
Benoît Ganne5cfe4522021-03-03 17:37:25 +01002244 vlib_error_t drop_err = ~0; /* default: any error */
Dave Barach5ecd5a52019-02-25 15:27:28 -05002245
2246 /* Get a line of input. */
2247 if (!unformat_user (input, unformat_line_input, line_input))
2248 return 0;
2249
2250 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2251 {
Dave Barach33909772019-09-23 10:27:27 -04002252 if (unformat (line_input, "rx"))
2253 rx_enable = 1;
2254 else if (unformat (line_input, "tx"))
2255 tx_enable = 1;
2256 else if (unformat (line_input, "drop"))
2257 drop_enable = 1;
2258 else if (unformat (line_input, "off"))
2259 rx_enable = tx_enable = drop_enable = 0;
2260 else if (unformat (line_input, "max-bytes-per-pkt %u",
2261 &max_bytes_per_pkt))
Dave Barachb97641c2019-09-09 16:38:17 -04002262 ;
2263 else if (unformat (line_input, "max %d", &max))
2264 ;
2265 else if (unformat (line_input, "packets-to-capture %d", &max))
2266 ;
2267 else if (unformat (line_input, "file %U", unformat_vlib_tmpfile,
2268 &filename))
2269 ;
2270 else if (unformat (line_input, "status %=", &status, 1))
2271 ;
2272 else if (unformat (line_input, "intfc %U",
2273 unformat_vnet_sw_interface, vnm, &sw_if_index))
2274 ;
Dave Barach586462f2020-08-05 16:12:35 -04002275 else if (unformat (line_input, "interface %U",
2276 unformat_vnet_sw_interface, vnm, &sw_if_index))
2277 ;
Benoît Ganne5cfe4522021-03-03 17:37:25 +01002278 else if (unformat (line_input, "error %U", unformat_vlib_error, vm,
2279 &drop_err))
2280 ;
Dave Barach586462f2020-08-05 16:12:35 -04002281 else if (unformat (line_input, "preallocate-data %=",
2282 &preallocate_data, 1))
2283 ;
2284 else if (unformat (line_input, "free-data %=", &free_data, 1))
2285 ;
2286 else if (unformat (line_input, "intfc any")
2287 || unformat (line_input, "interface any"))
Dave Barachb97641c2019-09-09 16:38:17 -04002288 sw_if_index = 0;
Dave Barach9137e542019-09-13 17:47:50 -04002289 else if (unformat (line_input, "filter"))
2290 filter = 1;
Dave Barach5ecd5a52019-02-25 15:27:28 -05002291 else
2292 {
Dave Barachb97641c2019-09-09 16:38:17 -04002293 return clib_error_return (0, "unknown input `%U'",
2294 format_unformat_error, line_input);
Dave Barach5ecd5a52019-02-25 15:27:28 -05002295 }
2296 }
Dave Barachb97641c2019-09-09 16:38:17 -04002297
Dave Barach5ecd5a52019-02-25 15:27:28 -05002298 unformat_free (line_input);
2299
Dave Barachb97641c2019-09-09 16:38:17 -04002300 /* no need for memset (a, 0, sizeof (*a)), set all fields here. */
2301 a->filename = filename;
Dave Barach33909772019-09-23 10:27:27 -04002302 a->rx_enable = rx_enable;
2303 a->tx_enable = tx_enable;
Dave Barach586462f2020-08-05 16:12:35 -04002304 a->preallocate_data = preallocate_data;
2305 a->free_data = free_data;
Dave Barach33909772019-09-23 10:27:27 -04002306 a->drop_enable = drop_enable;
Dave Barachb97641c2019-09-09 16:38:17 -04002307 a->status = status;
2308 a->packets_to_capture = max;
Dave Barachb97641c2019-09-09 16:38:17 -04002309 a->sw_if_index = sw_if_index;
Dave Barach9137e542019-09-13 17:47:50 -04002310 a->filter = filter;
Dave Barach33909772019-09-23 10:27:27 -04002311 a->max_bytes_per_pkt = max_bytes_per_pkt;
Benoît Ganne5cfe4522021-03-03 17:37:25 +01002312 a->drop_err = drop_err;
Dave Barach5ecd5a52019-02-25 15:27:28 -05002313
Dave Barachb97641c2019-09-09 16:38:17 -04002314 rv = vnet_pcap_dispatch_trace_configure (a);
2315
2316 switch (rv)
Dave Barach5ecd5a52019-02-25 15:27:28 -05002317 {
Dave Barachb97641c2019-09-09 16:38:17 -04002318 case 0:
2319 break;
Dave Barach5ecd5a52019-02-25 15:27:28 -05002320
Dave Barachb97641c2019-09-09 16:38:17 -04002321 case VNET_API_ERROR_INVALID_VALUE:
2322 return clib_error_return (0, "dispatch trace already enabled...");
Dave Barach5ecd5a52019-02-25 15:27:28 -05002323
Dave Barachb97641c2019-09-09 16:38:17 -04002324 case VNET_API_ERROR_VALUE_EXIST:
2325 return clib_error_return (0, "dispatch trace already disabled...");
Dave Barach5ecd5a52019-02-25 15:27:28 -05002326
Dave Barachb97641c2019-09-09 16:38:17 -04002327 case VNET_API_ERROR_INVALID_VALUE_2:
2328 return clib_error_return
2329 (0, "can't change number of records to capture while tracing...");
2330
2331 case VNET_API_ERROR_SYSCALL_ERROR_1:
2332 return clib_error_return (0, "I/O writing trace capture...");
2333
2334 case VNET_API_ERROR_NO_SUCH_ENTRY:
2335 return clib_error_return (0, "No packets captured...");
2336
Dave Barach33909772019-09-23 10:27:27 -04002337 case VNET_API_ERROR_INVALID_MEMORY_SIZE:
2338 return clib_error_return (0,
2339 "Max bytes per pkt must be > 32, < 9000...");
2340
Dave Barach9137e542019-09-13 17:47:50 -04002341 case VNET_API_ERROR_NO_SUCH_LABEL:
2342 return clib_error_return
2343 (0, "No classify filter configured, see 'classify filter...'");
2344
Dave Barachb97641c2019-09-09 16:38:17 -04002345 default:
2346 vlib_cli_output (vm, "WARNING: trace configure returned %d", rv);
2347 break;
Dave Barach5ecd5a52019-02-25 15:27:28 -05002348 }
Dave Barachb97641c2019-09-09 16:38:17 -04002349 return 0;
Dave Barach5ecd5a52019-02-25 15:27:28 -05002350}
2351
Dave Barach5ecd5a52019-02-25 15:27:28 -05002352/*?
2353 * This command is used to start or stop a packet capture, or show
Dave Barach33909772019-09-23 10:27:27 -04002354 * the status of packet capture.
Dave Barach5ecd5a52019-02-25 15:27:28 -05002355 *
2356 * This command has the following optional parameters:
2357 *
Dave Barach33909772019-09-23 10:27:27 -04002358 *
2359 * - <b>rx</b> - Capture received packets
2360 *
2361 * - <b>tx</b> - Capture transmitted packets
2362 *
2363 * - <b>drop</b> - Capture dropped packets
2364 *
2365 * - <b>off</b> - Stop capturing packets, write results to the specified file
Dave Barach5ecd5a52019-02-25 15:27:28 -05002366 *
2367 * - <b>max <nn></b> - Depth of local buffer. Once '<em>nn</em>' number
2368 * of packets have been received, buffer is flushed to file. Once another
2369 * '<em>nn</em>' number of packets have been received, buffer is flushed
2370 * to file, overwriting previous write. If not entered, value defaults
2371 * to 100. Can only be updated if packet capture is off.
2372 *
Dave Barach33909772019-09-23 10:27:27 -04002373 * - <b>max-bytes-per-pkt <nnnn></b> - Maximum number of bytes to capture
2374 * for each packet. Must be >= 32, <= 9000.
2375 *
Dave Barach586462f2020-08-05 16:12:35 -04002376 * - <b>preallocate-data</b> - Preallocate the data buffer, to avoid
2377 * vector expansion delays during pcap capture
2378 *
2379 * - <b>free-data</b> - Free the data buffer. Ordinarily it's a feature
2380 * to retain the data buffer so this option is seldom used.
2381 *
Dave Barach33909772019-09-23 10:27:27 -04002382 * - <b>intfc <interface-name>|any</b> - Used to specify a given interface,
Dave Barach5ecd5a52019-02-25 15:27:28 -05002383 * or use '<em>any</em>' to run packet capture on all interfaces.
2384 * '<em>any</em>' is the default if not provided. Settings from a previous
2385 * packet capture are preserved, so '<em>any</em>' can be used to reset
2386 * the interface setting.
2387 *
Nobuhiro MIKId346f392023-02-28 18:30:09 +09002388 * - <b>filter</b> - Use the pcap trace rx / tx / drop filter, which
Dave Barachf5667c32019-09-25 11:27:46 -04002389 * must be configured. Use <b>classify filter pcap...</b> to configure the
2390 * filter. The filter will only be executed if the per-interface or
2391 * any-interface tests fail.
2392 *
Benoît Ganne5cfe4522021-03-03 17:37:25 +01002393 * - <b>error <node>.<error></b> - filter packets based on a specific error.
Maxime Peimddc16cf2023-01-13 08:04:55 +00002394 * For example: error {ip4-udp-lookup}.{no_listener}
Benoît Ganne5cfe4522021-03-03 17:37:25 +01002395 *
Dave Barach5ecd5a52019-02-25 15:27:28 -05002396 * - <b>file <name></b> - Used to specify the output filename. The file will
2397 * be placed in the '<em>/tmp</em>' directory, so only the filename is
2398 * supported. Directory should not be entered. If file already exists, file
Dave Barach33909772019-09-23 10:27:27 -04002399 * will be overwritten. If no filename is provided, the file will be
2400 * named "/tmp/rx.pcap", "/tmp/tx.pcap", "/tmp/rxandtx.pcap", etc.
2401 * Can only be updated if packet capture is off.
Dave Barach5ecd5a52019-02-25 15:27:28 -05002402 *
2403 * - <b>status</b> - Displays the current status and configured attributes
2404 * associated with a packet capture. If packet capture is in progress,
2405 * '<em>status</em>' also will return the number of packets currently in
2406 * the local buffer. All additional attributes entered on command line
2407 * with '<em>status</em>' will be ignored and not applied.
2408 *
2409 * @cliexpar
2410 * Example of how to display the status of a tx packet capture when off:
Dave Barach33909772019-09-23 10:27:27 -04002411 * @cliexstart{pcap trace status}
Dave Barach5ecd5a52019-02-25 15:27:28 -05002412 * max is 100, for any interface to file /tmp/vpe.pcap
2413 * pcap tx capture is off...
2414 * @cliexend
2415 * Example of how to start a tx packet capture:
Benoît Ganne5cfe4522021-03-03 17:37:25 +01002416 * @cliexstart{pcap trace tx max 35 intfc GigabitEthernet0/8/0 file
Nathan Skrzypczak2c77ae42021-09-29 15:36:51 +02002417 * vppTest.pcap}
Dave Barach5ecd5a52019-02-25 15:27:28 -05002418 * @cliexend
2419 * Example of how to display the status of a tx packet capture in progress:
Dave Barach33909772019-09-23 10:27:27 -04002420 * @cliexstart{pcap trace status}
Dave Barach5ecd5a52019-02-25 15:27:28 -05002421 * max is 35, for interface GigabitEthernet0/8/0 to file /tmp/vppTest.pcap
2422 * pcap tx capture is on: 20 of 35 pkts...
2423 * @cliexend
2424 * Example of how to stop a tx packet capture:
Dave Barach33909772019-09-23 10:27:27 -04002425 * @cliexstart{pcap trace off}
Dave Barach5ecd5a52019-02-25 15:27:28 -05002426 * captured 21 pkts...
2427 * saved to /tmp/vppTest.pcap...
2428 * @cliexend
2429?*/
2430/* *INDENT-OFF* */
2431
2432VLIB_CLI_COMMAND (pcap_tx_trace_command, static) = {
Dave Barach33909772019-09-23 10:27:27 -04002433 .path = "pcap trace",
Dave Barach5ecd5a52019-02-25 15:27:28 -05002434 .short_help =
Dave Barach586462f2020-08-05 16:12:35 -04002435 "pcap trace [rx] [tx] [drop] [off] [max <nn>] [intfc <interface>|any]\n"
2436 " [file <name>] [status] [max-bytes-per-pkt <nnnn>][filter]\n"
2437 " [preallocate-data][free-data]",
Dave Barach33909772019-09-23 10:27:27 -04002438 .function = pcap_trace_command_fn,
Dave Barach5ecd5a52019-02-25 15:27:28 -05002439};
2440/* *INDENT-ON* */
2441
Steven Luongf49734d2021-07-26 13:38:05 -07002442static clib_error_t *
2443set_interface_name (vlib_main_t *vm, unformat_input_t *input,
2444 vlib_cli_command_t *cmd)
2445{
2446 clib_error_t *error = 0;
2447 unformat_input_t _line_input, *line_input = &_line_input;
2448 vnet_main_t *vnm = vnet_get_main ();
2449 u32 hw_if_index = ~0;
2450 char *name = 0;
2451
2452 if (!unformat_user (input, unformat_line_input, line_input))
2453 return 0;
2454
2455 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2456 {
2457 if (unformat (line_input, "%U %s", unformat_vnet_hw_interface, vnm,
2458 &hw_if_index, &name))
2459 ;
2460 else
2461 {
2462 error = clib_error_return (0, "parse error: '%U'",
2463 format_unformat_error, line_input);
2464 unformat_free (line_input);
2465 vec_free (name);
2466 return error;
2467 }
2468 }
2469
2470 unformat_free (line_input);
2471
2472 if (hw_if_index == (u32) ~0 || name == 0)
2473 {
2474 vec_free (name);
2475 error = clib_error_return (0, "please specify valid interface name");
2476 return error;
2477 }
2478
2479 error = vnet_rename_interface (vnm, hw_if_index, name);
2480 vec_free (name);
2481
2482 return (error);
2483}
2484
2485VLIB_CLI_COMMAND (cmd_set_if_name, static) = {
2486 .path = "set interface name",
2487 .short_help = "set interface name <interface-name> <new-interface-name>",
2488 .function = set_interface_name,
2489 .is_mp_safe = 1,
2490};
Mohsin Kazmi0d05c0d2021-11-09 17:44:10 +00002491
2492static clib_error_t *
2493set_interface_tx_hash_cmd (vlib_main_t *vm, unformat_input_t *input,
2494 vlib_cli_command_t *cmd)
2495{
2496 clib_error_t *error = 0;
2497 unformat_input_t _line_input, *line_input = &_line_input;
2498 vnet_main_t *vnm = vnet_get_main ();
2499 vnet_hw_interface_t *hi;
2500 u8 *hash_name = 0;
2501 u32 hw_if_index = (u32) ~0;
2502 vnet_hash_fn_t hf;
2503 vnet_hash_fn_type_t ftype;
2504
2505 if (!unformat_user (input, unformat_line_input, line_input))
2506 return 0;
2507
2508 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2509 {
2510 if (unformat (line_input, "%U", unformat_vnet_hw_interface, vnm,
2511 &hw_if_index))
2512 ;
2513 else if (unformat (line_input, "hash-name %s", &hash_name))
2514 ;
2515 else
2516 {
2517 error = clib_error_return (0, "parse error: '%U'",
2518 format_unformat_error, line_input);
2519 unformat_free (line_input);
2520 return error;
2521 }
2522 }
2523
2524 unformat_free (line_input);
2525
2526 if (hw_if_index == (u32) ~0)
2527 {
2528 error = clib_error_return (0, "please specify valid interface name");
2529 goto error;
2530 }
2531
Dave Barach9e0f9e22022-01-18 08:52:47 -05002532 if (hash_name == 0)
2533 {
2534 error = clib_error_return (0, "hash-name is required");
2535 goto error;
2536 }
2537
Mohsin Kazmi0d05c0d2021-11-09 17:44:10 +00002538 hi = vnet_get_hw_interface (vnm, hw_if_index);
2539 ftype =
2540 vnet_get_hw_interface_class (vnm, hi->hw_class_index)->tx_hash_fn_type;
2541 hf = vnet_hash_function_from_name ((const char *) hash_name, ftype);
2542
2543 if (!hf)
2544 {
2545 error = clib_error_return (0, "please specify valid hash name");
2546 goto error;
2547 }
2548
2549 hi->hf = hf;
2550error:
2551 vec_free (hash_name);
2552 return (error);
2553}
2554
2555VLIB_CLI_COMMAND (cmd_set_if_tx_hash, static) = {
2556 .path = "set interface tx-hash",
2557 .short_help = "set interface tx-hash <interface> hash-name <hash-name>",
2558 .function = set_interface_tx_hash_cmd,
2559};
2560
2561static clib_error_t *
2562show_tx_hash (vlib_main_t *vm, unformat_input_t *input,
2563 vlib_cli_command_t *cmd)
2564{
2565 clib_error_t *error = 0;
2566 unformat_input_t _line_input, *line_input = &_line_input;
2567 vnet_main_t *vnm = vnet_get_main ();
2568 vnet_hw_interface_t *hi;
2569 vnet_hash_function_registration_t *hash;
2570 u32 hw_if_index = (u32) ~0;
2571 vnet_hash_fn_type_t ftype;
2572
2573 if (!unformat_user (input, unformat_line_input, line_input))
2574 return 0;
2575
2576 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2577 {
2578 if (unformat (line_input, "%U", unformat_vnet_hw_interface, vnm,
2579 &hw_if_index))
2580 ;
2581 else
2582 {
2583 error = clib_error_return (0, "parse error: '%U'",
2584 format_unformat_error, line_input);
2585 unformat_free (line_input);
2586 goto error;
2587 }
2588 }
2589
2590 unformat_free (line_input);
2591
2592 if (hw_if_index == (u32) ~0)
2593 {
2594 error = clib_error_return (0, "please specify valid interface name");
2595 goto error;
2596 }
2597
2598 hi = vnet_get_hw_interface (vnm, hw_if_index);
2599 ftype =
2600 vnet_get_hw_interface_class (vnm, hi->hw_class_index)->tx_hash_fn_type;
2601
2602 if (hi->hf)
2603 {
2604 hash = vnet_hash_function_from_func (hi->hf, ftype);
2605 if (hash)
2606 vlib_cli_output (vm, "%U", format_vnet_hash, hash);
2607 else
2608 vlib_cli_output (vm, "no matching hash function found");
2609 }
2610 else
2611 vlib_cli_output (vm, "no hashing function set");
2612
2613error:
2614 return (error);
2615}
2616
2617VLIB_CLI_COMMAND (cmd_show_tx_hash, static) = {
2618 .path = "show interface tx-hash",
2619 .short_help = "show interface tx-hash [interface]",
2620 .function = show_tx_hash,
2621};
2622
Dave Barachba868bb2016-08-08 09:51:21 -04002623/*
2624 * fd.io coding-style-patch-verification: ON
2625 *
2626 * Local Variables:
2627 * eval: (c-set-style "gnu")
2628 * End:
2629 */