blob: ce36e3d27fd8165788e17ce656235762ebe187e9 [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))
80 return 0;
81
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
Ed Warnickecb9cada2015-12-08 15:45:58 -0700120 /* Gather interfaces. */
121 if (vec_len (hw_if_indices) == 0)
Damjan Marionb2c31b62020-12-13 21:47:40 +0100122 pool_foreach (hi, im->hw_interfaces)
123 vec_add1 (hw_if_indices, hi - im->hw_interfaces);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700124
Dave Barachba868bb2016-08-08 09:51:21 -0400125 if (verbose < 0)
126 verbose = 1; /* default to verbose (except bond) */
John Lobcebbb92016-04-05 15:47:43 -0400127
Ed Warnickecb9cada2015-12-08 15:45:58 -0700128 if (is_show)
129 {
130 /* Sort by name. */
131 vec_sort_with_function (hw_if_indices, compare_interface_names);
132
133 vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm, 0, verbose);
134 for (i = 0; i < vec_len (hw_if_indices); i++)
135 {
136 hi = vnet_get_hw_interface (vnm, hw_if_indices[i]);
Dave Barachba868bb2016-08-08 09:51:21 -0400137 if (show_bond == 0) /* show all interfaces */
138 vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm,
139 hi, verbose);
140 else if ((hi->bond_info) &&
John Lobcebbb92016-04-05 15:47:43 -0400141 (hi->bond_info != VNET_HW_INTERFACE_BOND_INFO_SLAVE))
Dave Barachba868bb2016-08-08 09:51:21 -0400142 { /* show only bonded interface and all its slave interfaces */
John Lobcebbb92016-04-05 15:47:43 -0400143 int hw_idx;
Dave Barachba868bb2016-08-08 09:51:21 -0400144 vnet_hw_interface_t *shi;
145 vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm,
John Lobcebbb92016-04-05 15:47:43 -0400146 hi, verbose);
Dave Barachba868bb2016-08-08 09:51:21 -0400147
148 /* *INDENT-OFF* */
Damjan Marionf0ca1e82020-12-13 23:26:56 +0100149 clib_bitmap_foreach (hw_idx, hi->bond_info)
150 {
Dave Barachba868bb2016-08-08 09:51:21 -0400151 shi = vnet_get_hw_interface(vnm, hw_idx);
152 vlib_cli_output (vm, "%U\n",
153 format_vnet_hw_interface, vnm, shi, verbose);
Damjan Marionf0ca1e82020-12-13 23:26:56 +0100154 }
Dave Barachba868bb2016-08-08 09:51:21 -0400155 /* *INDENT-ON* */
John Lobcebbb92016-04-05 15:47:43 -0400156 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700157 }
158 }
159 else
160 {
161 for (i = 0; i < vec_len (hw_if_indices); i++)
162 {
Dave Barachba868bb2016-08-08 09:51:21 -0400163 vnet_device_class_t *dc;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700164
165 hi = vnet_get_hw_interface (vnm, hw_if_indices[i]);
166 dc = vec_elt_at_index (im->device_classes, hi->dev_class_index);
Dave Barachba868bb2016-08-08 09:51:21 -0400167
Ed Warnickecb9cada2015-12-08 15:45:58 -0700168 if (dc->clear_counters)
169 dc->clear_counters (hi->dev_instance);
170 }
171 }
172
Dave Barachba868bb2016-08-08 09:51:21 -0400173done:
Ed Warnickecb9cada2015-12-08 15:45:58 -0700174 vec_free (hw_if_indices);
175 return error;
176}
177
Benoît Ganne17814d72020-07-24 09:57:11 +0200178static clib_error_t *
179show_hw_interfaces (vlib_main_t * vm,
180 unformat_input_t * input, vlib_cli_command_t * cmd)
181{
182 return show_or_clear_hw_interfaces (vm, input, cmd, 1 /* is_show */ );
183}
184
185static clib_error_t *
186clear_hw_interfaces (vlib_main_t * vm,
187 unformat_input_t * input, vlib_cli_command_t * cmd)
188{
189 return show_or_clear_hw_interfaces (vm, input, cmd, 0 /* is_show */ );
190}
191
192
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700193/*?
Billy McFalle9bac692017-08-11 14:05:11 -0400194 * Display more detailed information about all or a list of given interfaces.
195 * The verboseness of the output can be controlled by the following optional
196 * parameters:
197 * - brief: Only show name, index and state (default for bonded interfaces).
198 * - verbose: Also display additional attributes (default for all other interfaces).
199 * - detail: Also display all remaining attributes and extended statistics.
200 *
201 * To limit the output of the command to bonded interfaces and their slave
202 * interfaces, use the '<em>bond</em>' optional parameter.
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700203 *
204 * @cliexpar
Billy McFalle9bac692017-08-11 14:05:11 -0400205 * Example of how to display default data for all interfaces:
206 * @cliexstart{show hardware-interfaces}
207 * Name Idx Link Hardware
208 * GigabitEthernet7/0/0 1 up GigabitEthernet7/0/0
209 * Ethernet address ec:f4:bb:c0:bc:fc
210 * Intel e1000
211 * carrier up full duplex speed 1000 mtu 9216
212 * rx queues 1, rx desc 1024, tx queues 3, tx desc 1024
213 * cpu socket 0
214 * GigabitEthernet7/0/1 2 up GigabitEthernet7/0/1
215 * Ethernet address ec:f4:bb:c0:bc:fd
216 * Intel e1000
217 * carrier up full duplex speed 1000 mtu 9216
218 * rx queues 1, rx desc 1024, tx queues 3, tx desc 1024
219 * cpu socket 0
220 * VirtualEthernet0/0/0 3 up VirtualEthernet0/0/0
221 * Ethernet address 02:fe:a5:a9:8b:8e
222 * VirtualEthernet0/0/1 4 up VirtualEthernet0/0/1
223 * Ethernet address 02:fe:c0:4e:3b:b0
224 * VirtualEthernet0/0/2 5 up VirtualEthernet0/0/2
225 * Ethernet address 02:fe:1f:73:92:81
226 * VirtualEthernet0/0/3 6 up VirtualEthernet0/0/3
227 * Ethernet address 02:fe:f2:25:c4:68
228 * local0 0 down local0
229 * local
230 * @cliexend
231 * Example of how to display '<em>verbose</em>' data for an interface by name and
232 * software index (where 2 is the software index):
233 * @cliexstart{show hardware-interfaces GigabitEthernet7/0/0 2 verbose}
234 * Name Idx Link Hardware
235 * GigabitEthernet7/0/0 1 up GigabitEthernet7/0/0
236 * Ethernet address ec:f4:bb:c0:bc:fc
237 * Intel e1000
238 * carrier up full duplex speed 1000 mtu 9216
239 * rx queues 1, rx desc 1024, tx queues 3, tx desc 1024
240 * cpu socket 0
241 * GigabitEthernet7/0/1 2 down GigabitEthernet7/0/1
242 * Ethernet address ec:f4:bb:c0:bc:fd
243 * Intel e1000
244 * carrier up full duplex speed 1000 mtu 9216
245 * rx queues 1, rx desc 1024, tx queues 3, tx desc 1024
246 * cpu socket 0
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700247 * @cliexend
248 ?*/
Billy McFalle9bac692017-08-11 14:05:11 -0400249/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700250VLIB_CLI_COMMAND (show_hw_interfaces_command, static) = {
251 .path = "show hardware-interfaces",
Billy McFalle9bac692017-08-11 14:05:11 -0400252 .short_help = "show hardware-interfaces [brief|verbose|detail] [bond] "
253 "[<interface> [<interface> [..]]] [<sw_idx> [<sw_idx> [..]]]",
Benoît Ganne17814d72020-07-24 09:57:11 +0200254 .function = show_hw_interfaces,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700255};
Dave Barachba868bb2016-08-08 09:51:21 -0400256/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700257
Billy McFalle9bac692017-08-11 14:05:11 -0400258
259/*?
260 * Clear the extended statistics for all or a list of given interfaces
261 * (statistics associated with the '<em>show hardware-interfaces</em>' command).
262 *
263 * @cliexpar
264 * Example of how to clear the extended statistics for all interfaces:
265 * @cliexcmd{clear hardware-interfaces}
266 * Example of how to clear the extended statistics for an interface by
267 * name and software index (where 2 is the software index):
268 * @cliexcmd{clear hardware-interfaces GigabitEthernet7/0/0 2}
269 ?*/
Dave Barachba868bb2016-08-08 09:51:21 -0400270/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700271VLIB_CLI_COMMAND (clear_hw_interface_counters_command, static) = {
272 .path = "clear hardware-interfaces",
Billy McFalle9bac692017-08-11 14:05:11 -0400273 .short_help = "clear hardware-interfaces "
274 "[<interface> [<interface> [..]]] [<sw_idx> [<sw_idx> [..]]]",
Benoît Ganne17814d72020-07-24 09:57:11 +0200275 .function = clear_hw_interfaces,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700276};
Dave Barachba868bb2016-08-08 09:51:21 -0400277/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700278
Dave Barachba868bb2016-08-08 09:51:21 -0400279static int
280sw_interface_name_compare (void *a1, void *a2)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700281{
282 vnet_sw_interface_t *si1 = a1;
283 vnet_sw_interface_t *si2 = a2;
284
Dave Barachba868bb2016-08-08 09:51:21 -0400285 return vnet_sw_interface_compare (vnet_get_main (),
286 si1->sw_if_index, si2->sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700287}
288
289static clib_error_t *
290show_sw_interfaces (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -0400291 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700292{
Dave Barachba868bb2016-08-08 09:51:21 -0400293 clib_error_t *error = 0;
294 vnet_main_t *vnm = vnet_get_main ();
Dave Barach525c9d02018-05-26 10:48:55 -0400295 unformat_input_t _linput, *linput = &_linput;
Dave Barachba868bb2016-08-08 09:51:21 -0400296 vnet_interface_main_t *im = &vnm->interface_main;
297 vnet_sw_interface_t *si, *sorted_sis = 0;
Damjan Marion22311502016-10-28 20:30:15 +0200298 u32 sw_if_index = ~(u32) 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700299 u8 show_addresses = 0;
Damjan Marion22311502016-10-28 20:30:15 +0200300 u8 show_features = 0;
Dave Barach7be864a2016-11-28 11:41:35 -0500301 u8 show_tag = 0;
Jon Loeliger9485d992019-11-08 15:05:23 -0600302 u8 show_vtr = 0;
Dave Barach525c9d02018-05-26 10:48:55 -0400303 int verbose = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700304
Dave Barach525c9d02018-05-26 10:48:55 -0400305 /*
306 * Get a line of input. Won't work if the user typed
307 * "show interface" and nothing more.
308 */
309 if (unformat_user (input, unformat_line_input, linput))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700310 {
Dave Barach525c9d02018-05-26 10:48:55 -0400311 while (unformat_check_input (linput) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700312 {
Dave Barach525c9d02018-05-26 10:48:55 -0400313 /* See if user wants to show specific interface */
314 if (unformat
315 (linput, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
316 {
317 si = pool_elt_at_index (im->sw_interfaces, sw_if_index);
318 vec_add1 (sorted_sis, si[0]);
319 }
320 else if (unformat (linput, "address") || unformat (linput, "addr"))
321 show_addresses = 1;
322 else if (unformat (linput, "features") || unformat (linput, "feat"))
323 show_features = 1;
324 else if (unformat (linput, "tag"))
325 show_tag = 1;
Jon Loeliger9485d992019-11-08 15:05:23 -0600326 else if (unformat (linput, "vtr"))
327 show_vtr = 1;
Dave Barach525c9d02018-05-26 10:48:55 -0400328 else if (unformat (linput, "verbose"))
329 verbose = 1;
Neale Rannse619ada2021-09-22 10:49:43 +0000330 else if (unformat (linput, "%d", &sw_if_index))
331 {
332 if (!pool_is_free_index (im->sw_interfaces, sw_if_index))
333 {
334 si = pool_elt_at_index (im->sw_interfaces, sw_if_index);
335 vec_add1 (sorted_sis, si[0]);
336 }
337 else
338 {
339 vec_free (sorted_sis);
340 error = clib_error_return (0, "unknown interface index `%d'",
341 sw_if_index);
342 goto done;
343 }
344 }
Dave Barach525c9d02018-05-26 10:48:55 -0400345 else
346 {
Dave Barach8fdde3c2019-05-17 10:46:40 -0400347 vec_free (sorted_sis);
Dave Barach525c9d02018-05-26 10:48:55 -0400348 error = clib_error_return (0, "unknown input `%U'",
349 format_unformat_error, linput);
350 goto done;
351 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700352 }
Dave Barach525c9d02018-05-26 10:48:55 -0400353 unformat_free (linput);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700354 }
Jon Loeliger9485d992019-11-08 15:05:23 -0600355 if (show_features || show_tag || show_vtr)
Damjan Marion22311502016-10-28 20:30:15 +0200356 {
357 if (sw_if_index == ~(u32) 0)
Dave Barach8fdde3c2019-05-17 10:46:40 -0400358 {
359 vec_free (sorted_sis);
360 return clib_error_return (0, "Interface not specified...");
361 }
Dave Barach7be864a2016-11-28 11:41:35 -0500362 }
Damjan Marion22311502016-10-28 20:30:15 +0200363
Dave Barach7be864a2016-11-28 11:41:35 -0500364 if (show_features)
365 {
Dave Barach525c9d02018-05-26 10:48:55 -0400366 vnet_interface_features_show (vm, sw_if_index, verbose);
Neale Ranns47a3d992020-09-29 15:38:51 +0000367 vlib_cli_output (vm, "%U", format_l2_input_features, sw_if_index, 1);
Eyal Bari942402b2017-07-26 11:57:04 +0300368
369 l2_output_config_t *l2_output = l2output_intf_config (sw_if_index);
370 vlib_cli_output (vm, "\nl2-output:");
371 if (l2_output->out_vtr_flag)
372 vlib_cli_output (vm, "%10s (%s)", "VTR", "--internal--");
373 vlib_cli_output (vm, "%U", format_l2_output_features,
Neale Ranns5d9df1d2018-11-09 08:19:27 -0800374 l2_output->feature_bitmap, 1);
Dave Barach8fdde3c2019-05-17 10:46:40 -0400375 vec_free (sorted_sis);
Damjan Marion22311502016-10-28 20:30:15 +0200376 return 0;
377 }
Dave Barach7be864a2016-11-28 11:41:35 -0500378 if (show_tag)
379 {
380 u8 *tag;
381 tag = vnet_get_sw_interface_tag (vnm, sw_if_index);
382 vlib_cli_output (vm, "%U: %s",
383 format_vnet_sw_if_index_name, vnm, sw_if_index,
384 tag ? (char *) tag : "(none)");
Dave Barach8fdde3c2019-05-17 10:46:40 -0400385 vec_free (sorted_sis);
Dave Barach7be864a2016-11-28 11:41:35 -0500386 return 0;
387 }
Damjan Marion22311502016-10-28 20:30:15 +0200388
Jon Loeliger9485d992019-11-08 15:05:23 -0600389 /*
390 * Show vlan tag rewrite data for one interface.
391 */
392 if (show_vtr)
393 {
394 u32 vtr_op = L2_VTR_DISABLED;
395 u32 push_dot1q = 0, tag1 = 0, tag2 = 0;
396
397 if (l2vtr_get (vm, vnm, sw_if_index,
398 &vtr_op, &push_dot1q, &tag1, &tag2) != 0)
399 {
400 vlib_cli_output (vm, "%U: Problem getting vlan tag-rewrite data",
401 format_vnet_sw_if_index_name, vnm, sw_if_index);
402 return 0;
403 }
404 vlib_cli_output (vm, "%U: VTR %0U",
405 format_vnet_sw_if_index_name, vnm, sw_if_index,
406 format_vtr, vtr_op, push_dot1q, tag1, tag2);
407 return 0;
408 }
409
Ed Warnickecb9cada2015-12-08 15:45:58 -0700410 if (!show_addresses)
Dave Barachba868bb2016-08-08 09:51:21 -0400411 vlib_cli_output (vm, "%U\n", format_vnet_sw_interface, vnm, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700412
Dave Barachba868bb2016-08-08 09:51:21 -0400413 if (vec_len (sorted_sis) == 0) /* Get all interfaces */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700414 {
415 /* Gather interfaces. */
Dave Barachba868bb2016-08-08 09:51:21 -0400416 sorted_sis =
417 vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
Damjan Marion8bea5892022-04-04 22:40:45 +0200418 vec_set_len (sorted_sis, 0);
Dave Barach525c9d02018-05-26 10:48:55 -0400419 /* *INDENT-OFF* */
Damjan Marionb2c31b62020-12-13 21:47:40 +0100420 pool_foreach (si, im->sw_interfaces)
421 {
Dave Barach525c9d02018-05-26 10:48:55 -0400422 int visible = vnet_swif_is_api_visible (si);
423 if (visible)
Damjan Marionb2c31b62020-12-13 21:47:40 +0100424 vec_add1 (sorted_sis, si[0]);
425 }
Ole Troand7231612018-06-07 10:17:57 +0200426 /* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700427 /* Sort by name. */
428 vec_sort_with_function (sorted_sis, sw_interface_name_compare);
429 }
430
431 if (show_addresses)
432 {
433 vec_foreach (si, sorted_sis)
Dave Barachba868bb2016-08-08 09:51:21 -0400434 {
Dave Barachba868bb2016-08-08 09:51:21 -0400435 ip4_main_t *im4 = &ip4_main;
436 ip6_main_t *im6 = &ip6_main;
437 ip_lookup_main_t *lm4 = &im4->lookup_main;
438 ip_lookup_main_t *lm6 = &im6->lookup_main;
439 ip_interface_address_t *ia = 0;
Dave Barachba868bb2016-08-08 09:51:21 -0400440 u32 fib_index4 = 0, fib_index6 = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700441
Dave Barachba868bb2016-08-08 09:51:21 -0400442 if (vec_len (im4->fib_index_by_sw_if_index) > si->sw_if_index)
443 fib_index4 = vec_elt (im4->fib_index_by_sw_if_index,
444 si->sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700445
Dave Barachba868bb2016-08-08 09:51:21 -0400446 if (vec_len (im6->fib_index_by_sw_if_index) > si->sw_if_index)
447 fib_index6 = vec_elt (im6->fib_index_by_sw_if_index,
448 si->sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700449
John Lo4478d8e2018-01-12 17:15:25 -0500450 ip4_fib_t *fib4 = ip4_fib_get (fib_index4);
451 ip6_fib_t *fib6 = ip6_fib_get (fib_index6);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700452
Dave Barachba868bb2016-08-08 09:51:21 -0400453 if (si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)
454 vlib_cli_output
455 (vm, "%U (%s): \n unnumbered, use %U",
John Lo4478d8e2018-01-12 17:15:25 -0500456 format_vnet_sw_if_index_name, vnm, si->sw_if_index,
Dave Barachba868bb2016-08-08 09:51:21 -0400457 (si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? "up" : "dn",
458 format_vnet_sw_if_index_name, vnm, si->unnumbered_sw_if_index);
Dave Barachba868bb2016-08-08 09:51:21 -0400459 else
John Lo4478d8e2018-01-12 17:15:25 -0500460 vlib_cli_output
461 (vm, "%U (%s):",
462 format_vnet_sw_if_index_name, vnm, si->sw_if_index,
463 (si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? "up" : "dn");
Ed Warnickecb9cada2015-12-08 15:45:58 -0700464
Eyal Bari942402b2017-07-26 11:57:04 +0300465 /* Display any L2 info */
Neale Ranns47a3d992020-09-29 15:38:51 +0000466 vlib_cli_output (vm, "%U", format_l2_input, si->sw_if_index);
Dave Barachba868bb2016-08-08 09:51:21 -0400467
John Lo4478d8e2018-01-12 17:15:25 -0500468 /* *INDENT-OFF* */
Dave Barachba868bb2016-08-08 09:51:21 -0400469 /* Display any IP4 addressing info */
John Lo4478d8e2018-01-12 17:15:25 -0500470 foreach_ip_interface_address (lm4, ia, si->sw_if_index,
471 1 /* honor unnumbered */,
472 ({
473 ip4_address_t *r4 = ip_interface_address_get_address (lm4, ia);
Neale Rannsd6953332021-08-10 07:39:18 +0000474 if (fib4->hash.table_id)
475 vlib_cli_output (
476 vm, " L3 %U/%d ip4 table-id %d fib-idx %d", format_ip4_address,
477 r4, ia->address_length, fib4->hash.table_id,
478 ip4_fib_index_from_table_id (fib4->hash.table_id));
John Lo4478d8e2018-01-12 17:15:25 -0500479 else
480 vlib_cli_output (vm, " L3 %U/%d",
481 format_ip4_address, r4, ia->address_length);
482 }));
483 /* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700484
John Lo4478d8e2018-01-12 17:15:25 -0500485 /* *INDENT-OFF* */
Dave Barachba868bb2016-08-08 09:51:21 -0400486 /* Display any IP6 addressing info */
John Lo4478d8e2018-01-12 17:15:25 -0500487 foreach_ip_interface_address (lm6, ia, si->sw_if_index,
488 1 /* honor unnumbered */,
489 ({
490 ip6_address_t *r6 = ip_interface_address_get_address (lm6, ia);
491 if (fib6->table_id)
492 vlib_cli_output (vm, " L3 %U/%d ip6 table-id %d fib-idx %d",
493 format_ip6_address, r6, ia->address_length,
494 fib6->table_id,
495 ip6_fib_index_from_table_id (fib6->table_id));
496 else
497 vlib_cli_output (vm, " L3 %U/%d",
498 format_ip6_address, r6, ia->address_length);
499 }));
500 /* *INDENT-ON* */
Ole Troand7231612018-06-07 10:17:57 +0200501 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700502 }
Ole Troand7231612018-06-07 10:17:57 +0200503 else
504 {
505 vec_foreach (si, sorted_sis)
506 {
507 vlib_cli_output (vm, "%U\n", format_vnet_sw_interface, vnm, si);
508 }
509 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700510
Dave Barachba868bb2016-08-08 09:51:21 -0400511done:
Ole Troand7231612018-06-07 10:17:57 +0200512 vec_free (sorted_sis);
513 return error;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700514}
515
Dave Barachba868bb2016-08-08 09:51:21 -0400516/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700517VLIB_CLI_COMMAND (show_sw_interfaces_command, static) = {
Dave Barach13ad1f02017-03-26 19:36:18 -0400518 .path = "show interface",
Jon Loeliger9485d992019-11-08 15:05:23 -0600519 .short_help = "show interface [address|addr|features|feat|vtr] [<interface> [<interface> [..]]] [verbose]",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700520 .function = show_sw_interfaces,
Steven Luongc5fa2b82019-04-25 11:19:49 -0700521 .is_mp_safe = 1,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700522};
Dave Barachba868bb2016-08-08 09:51:21 -0400523/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700524
525/* Root of all interface commands. */
Dave Barachba868bb2016-08-08 09:51:21 -0400526/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700527VLIB_CLI_COMMAND (vnet_cli_interface_command, static) = {
528 .path = "interface",
529 .short_help = "Interface commands",
530};
Dave Barachba868bb2016-08-08 09:51:21 -0400531/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700532
Dave Barachba868bb2016-08-08 09:51:21 -0400533/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700534VLIB_CLI_COMMAND (vnet_cli_set_interface_command, static) = {
535 .path = "set interface",
536 .short_help = "Interface commands",
537};
Dave Barachba868bb2016-08-08 09:51:21 -0400538/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700539
540static clib_error_t *
541clear_interface_counters (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -0400542 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700543{
Dave Barachba868bb2016-08-08 09:51:21 -0400544 vnet_main_t *vnm = vnet_get_main ();
545 vnet_interface_main_t *im = &vnm->interface_main;
546 vlib_simple_counter_main_t *sm;
547 vlib_combined_counter_main_t *cm;
Dave Barach8fdde3c2019-05-17 10:46:40 -0400548 int j, n_counters;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700549
550 n_counters = vec_len (im->combined_sw_if_counters);
551
552 for (j = 0; j < n_counters; j++)
553 {
Dave Barach8fdde3c2019-05-17 10:46:40 -0400554 im = &vnm->interface_main;
555 cm = im->combined_sw_if_counters + j;
556 vlib_clear_combined_counters (cm);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700557 }
558
559 n_counters = vec_len (im->sw_if_counters);
560
561 for (j = 0; j < n_counters; j++)
562 {
Dave Barach8fdde3c2019-05-17 10:46:40 -0400563 im = &vnm->interface_main;
564 sm = im->sw_if_counters + j;
565 vlib_clear_simple_counters (sm);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700566 }
567
568 return 0;
569}
570
Billy McFalle9bac692017-08-11 14:05:11 -0400571/*?
572 * Clear the statistics for all interfaces (statistics associated with the
573 * '<em>show interface</em>' command).
574 *
575 * @cliexpar
576 * Example of how to clear the statistics for all interfaces:
577 * @cliexcmd{clear interfaces}
578 ?*/
Dave Barachba868bb2016-08-08 09:51:21 -0400579/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700580VLIB_CLI_COMMAND (clear_interface_counters_command, static) = {
581 .path = "clear interfaces",
Billy McFalle9bac692017-08-11 14:05:11 -0400582 .short_help = "clear interfaces",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700583 .function = clear_interface_counters,
584};
Dave Barachba868bb2016-08-08 09:51:21 -0400585/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700586
Chris Luke16bcf7d2016-09-01 14:31:46 -0400587/**
588 * Parse subinterface names.
589 *
Dave Barachba868bb2016-08-08 09:51:21 -0400590 * The following subinterface syntax is supported. The first two are for
591 * backwards compatability:
592 *
593 * <intf-name> <id>
594 * - a subinterface with the name <intf-name>.<id>. The subinterface
595 * is a single dot1q vlan with vlan id <id> and exact-match semantics.
596 *
597 * <intf-name> <min_id>-<max_id>
598 * - a set of the above subinterfaces, repeating for each id
599 * in the range <min_id> to <max_id>
600 *
601 * In the following, exact-match semantics (i.e. the number of vlan tags on the
602 * packet must match the number of tags in the configuration) are used only if
603 * the keyword exact-match is present. Non-exact match is the default.
604 *
605 * <intf-name> <id> dot1q <outer_id> [exact-match]
606 * - a subinterface with the name <intf-name>.<id>. The subinterface
607 * is a single dot1q vlan with vlan id <outer_id>.
608 *
609 * <intf-name> <id> dot1q any [exact-match]
610 * - a subinterface with the name <intf-name>.<id>. The subinterface
611 * is a single dot1q vlan with any vlan id.
612 *
613 * <intf-name> <id> dot1q <outer_id> inner-dot1q <inner_id> [exact-match]
614 * - a subinterface with the name <intf-name>.<id>. The subinterface
615 * is a double dot1q vlan with outer vlan id <outer_id> and inner vlan id
616 * <inner_id>.
617 *
618 * <intf-name> <id> dot1q <outer_id> inner-dot1q any [exact-match]
619 * - a subinterface with the name <intf-name>.<id>. The subinterface
620 * is a double dot1q vlan with outer vlan id <id> and any inner vlan id.
621 *
622 * <intf-name> <id> dot1q any inner-dot1q any [exact-match]
623 *
624 * - a subinterface with the name <intf-name>.<id>. The subinterface
625 * is a double dot1q vlan with any outer vlan id and any inner vlan id.
626 *
627 * For each of the above CLI, there is a duplicate that uses the keyword
628 * "dot1ad" in place of the first "dot1q". These interfaces use ethertype
629 * 0x88ad in place of 0x8100 for the outer ethertype. Note that for double-
630 * tagged packets the inner ethertype is always 0x8100. Also note that
631 * the dot1q and dot1ad naming spaces are independent, so it is legal to
632 * have both "Gig3/0/0.1 dot1q 100" and "Gig3/0/0.2 dot1ad 100". For example:
633 *
634 * <intf-name> <id> dot1ad <outer_id> inner-dot1q <inner_id> [exact-match]
635 * - a subinterface with the name <intf-name>.<id>. The subinterface
636 * is a double dot1ad vlan with outer vlan id <outer_id> and inner vlan
637 * id <inner_id>.
638 *
639 * <intf-name> <id> untagged
640 * - a subinterface with the name <intf-name>.<id>. The subinterface
641 * has no vlan tags. Only one can be specified per interface.
642 *
643 * <intf-name> <id> default
644 * - a subinterface with the name <intf-name>.<id>. This is associated
645 * with a packet that did not match any other configured subinterface
646 * on this interface. Only one can be specified per interface.
647 */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700648
649static clib_error_t *
Dave Barachba868bb2016-08-08 09:51:21 -0400650parse_vlan_sub_interfaces (unformat_input_t * input,
651 vnet_sw_interface_t * template)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700652{
Dave Barachba868bb2016-08-08 09:51:21 -0400653 clib_error_t *error = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700654 u32 inner_vlan, outer_vlan;
655
Dave Barachba868bb2016-08-08 09:51:21 -0400656 if (unformat (input, "any inner-dot1q any"))
657 {
658 template->sub.eth.flags.two_tags = 1;
659 template->sub.eth.flags.outer_vlan_id_any = 1;
660 template->sub.eth.flags.inner_vlan_id_any = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700661 }
Dave Barachba868bb2016-08-08 09:51:21 -0400662 else if (unformat (input, "any"))
663 {
664 template->sub.eth.flags.one_tag = 1;
665 template->sub.eth.flags.outer_vlan_id_any = 1;
666 }
667 else if (unformat (input, "%d inner-dot1q any", &outer_vlan))
668 {
669 template->sub.eth.flags.two_tags = 1;
670 template->sub.eth.flags.inner_vlan_id_any = 1;
671 template->sub.eth.outer_vlan_id = outer_vlan;
672 }
673 else if (unformat (input, "%d inner-dot1q %d", &outer_vlan, &inner_vlan))
674 {
675 template->sub.eth.flags.two_tags = 1;
676 template->sub.eth.outer_vlan_id = outer_vlan;
677 template->sub.eth.inner_vlan_id = inner_vlan;
678 }
679 else if (unformat (input, "%d", &outer_vlan))
680 {
681 template->sub.eth.flags.one_tag = 1;
682 template->sub.eth.outer_vlan_id = outer_vlan;
683 }
684 else
685 {
686 error = clib_error_return (0, "expected dot1q config, got `%U'",
687 format_unformat_error, input);
688 goto done;
689 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700690
Dave Barachba868bb2016-08-08 09:51:21 -0400691 if (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
692 {
693 if (unformat (input, "exact-match"))
694 {
695 template->sub.eth.flags.exact_match = 1;
696 }
697 }
698
699done:
Ed Warnickecb9cada2015-12-08 15:45:58 -0700700 return error;
701}
702
703static clib_error_t *
704create_sub_interfaces (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -0400705 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700706{
Dave Barachba868bb2016-08-08 09:51:21 -0400707 vnet_main_t *vnm = vnet_get_main ();
708 clib_error_t *error = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700709 u32 hw_if_index, sw_if_index;
Dave Barachba868bb2016-08-08 09:51:21 -0400710 vnet_hw_interface_t *hi;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700711 u32 id, id_min, id_max;
712 vnet_sw_interface_t template;
713
714 hw_if_index = ~0;
Dave Barachba868bb2016-08-08 09:51:21 -0400715 if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700716 {
717 error = clib_error_return (0, "unknown interface `%U'",
718 format_unformat_error, input);
719 goto done;
720 }
721
Dave Barachb7b92992018-10-17 10:38:51 -0400722 clib_memset (&template, 0, sizeof (template));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700723 template.sub.eth.raw_flags = 0;
724
Dave Barachba868bb2016-08-08 09:51:21 -0400725 if (unformat (input, "%d default", &id_min))
726 {
727 id_max = id_min;
728 template.sub.eth.flags.default_sub = 1;
729 }
730 else if (unformat (input, "%d untagged", &id_min))
731 {
732 id_max = id_min;
733 template.sub.eth.flags.no_tags = 1;
734 template.sub.eth.flags.exact_match = 1;
735 }
736 else if (unformat (input, "%d dot1q", &id_min))
737 {
738 /* parse dot1q config */
739 id_max = id_min;
740 error = parse_vlan_sub_interfaces (input, &template);
741 if (error)
742 goto done;
743 }
744 else if (unformat (input, "%d dot1ad", &id_min))
745 {
746 /* parse dot1ad config */
747 id_max = id_min;
748 template.sub.eth.flags.dot1ad = 1;
749 error = parse_vlan_sub_interfaces (input, &template);
750 if (error)
751 goto done;
752 }
753 else if (unformat (input, "%d-%d", &id_min, &id_max))
754 {
755 template.sub.eth.flags.one_tag = 1;
Dave Barachba868bb2016-08-08 09:51:21 -0400756 template.sub.eth.flags.exact_match = 1;
757 if (id_min > id_max)
758 goto id_error;
759 }
760 else if (unformat (input, "%d", &id_min))
761 {
762 id_max = id_min;
763 template.sub.eth.flags.one_tag = 1;
764 template.sub.eth.outer_vlan_id = id_min;
765 template.sub.eth.flags.exact_match = 1;
766 }
767 else
768 {
Ed Warnickecb9cada2015-12-08 15:45:58 -0700769 id_error:
770 error = clib_error_return (0, "expected ID or ID MIN-MAX, got `%U'",
771 format_unformat_error, input);
772 goto done;
Dave Barachba868bb2016-08-08 09:51:21 -0400773 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700774
775 hi = vnet_get_hw_interface (vnm, hw_if_index);
John Lobcebbb92016-04-05 15:47:43 -0400776
Dave Barachba868bb2016-08-08 09:51:21 -0400777 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE)
778 {
779 error =
780 clib_error_return (0,
781 "not allowed as %v belong to a BondEthernet interface",
782 hi->name);
783 goto done;
784 }
John Lobcebbb92016-04-05 15:47:43 -0400785
Ed Warnickecb9cada2015-12-08 15:45:58 -0700786 for (id = id_min; id <= id_max; id++)
787 {
Dave Barachba868bb2016-08-08 09:51:21 -0400788 uword *p;
789 vnet_interface_main_t *im = &vnm->interface_main;
790 u64 sup_and_sub_key = ((u64) (hi->sw_if_index) << 32) | (u64) id;
791 u64 *kp;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700792
793 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
794 if (p)
Dave Barachba868bb2016-08-08 09:51:21 -0400795 {
796 if (CLIB_DEBUG > 0)
797 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
798 hi->sw_if_index, id);
799 continue;
800 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700801
Ed Warnickecb9cada2015-12-08 15:45:58 -0700802 template.type = VNET_SW_INTERFACE_TYPE_SUB;
Eyal Baric5b13602016-11-24 19:42:43 +0200803 template.flood_class = VNET_FLOOD_CLASS_NORMAL;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700804 template.sup_sw_if_index = hi->sw_if_index;
805 template.sub.id = id;
Eyal Baria4509cf2016-09-26 09:24:09 +0300806 if (id_min < id_max)
807 template.sub.eth.outer_vlan_id = id;
808
Ed Warnickecb9cada2015-12-08 15:45:58 -0700809 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
Dave Barachba868bb2016-08-08 09:51:21 -0400810 if (error)
811 goto done;
Dave Barach16ad6ae2016-07-28 17:55:30 -0400812
Jon Loeligerb22e1f02019-12-19 09:03:52 -0600813 kp = clib_mem_alloc (sizeof (*kp));
814 *kp = sup_and_sub_key;
815
Ed Warnickecb9cada2015-12-08 15:45:58 -0700816 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
817 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
Dave Barachba868bb2016-08-08 09:51:21 -0400818 vlib_cli_output (vm, "%U\n", format_vnet_sw_if_index_name,
819 vnet_get_main (), sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700820 }
821
Dave Barachba868bb2016-08-08 09:51:21 -0400822done:
Ed Warnickecb9cada2015-12-08 15:45:58 -0700823 return error;
824}
825
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700826/*?
Billy McFalle9bac692017-08-11 14:05:11 -0400827 * This command is used to add VLAN IDs to interfaces, also known as subinterfaces.
828 * The primary input to this command is the '<em>interface</em>' and '<em>subId</em>'
829 * (subinterface Id) parameters. If no additional VLAN ID is provide, the VLAN ID is
830 * assumed to be the '<em>subId</em>'. The VLAN ID and '<em>subId</em>' can be different,
831 * but this is not recommended.
832 *
833 * This command has several variations:
834 * - <b>create sub-interfaces <interface> <subId></b> - Create a subinterface to
835 * process packets with a given 802.1q VLAN ID (same value as the '<em>subId</em>').
836 *
837 * - <b>create sub-interfaces <interface> <subId> default</b> - Adding the
838 * '<em>default</em>' parameter indicates that packets with VLAN IDs that do not
839 * match any other subinterfaces should be sent to this subinterface.
840 *
841 * - <b>create sub-interfaces <interface> <subId> untagged</b> - Adding the
842 * '<em>untagged</em>' parameter indicates that packets no VLAN IDs should be sent
843 * to this subinterface.
844 *
845 * - <b>create sub-interfaces <interface> <subId>-<subId></b> - Create a range of
846 * subinterfaces to handle a range of VLAN IDs.
847 *
848 * - <b>create sub-interfaces <interface> <subId> dot1q|dot1ad <vlanId>|any [exact-match]</b> -
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -0700849 * Use this command to specify the outer VLAN ID, to either be explicit or to make the
Billy McFalle9bac692017-08-11 14:05:11 -0400850 * VLAN ID different from the '<em>subId</em>'.
851 *
852 * - <b>create sub-interfaces <interface> <subId> dot1q|dot1ad <vlanId>|any inner-dot1q
853 * <vlanId>|any [exact-match]</b> - Use this command to specify the outer VLAN ID and
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -0700854 * the inner VLAN ID.
Billy McFalle9bac692017-08-11 14:05:11 -0400855 *
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -0700856 * When '<em>dot1q</em>' or '<em>dot1ad</em>' is explicitly entered, subinterfaces
Billy McFalle9bac692017-08-11 14:05:11 -0400857 * can be configured as either exact-match or non-exact match. Non-exact match is the CLI
858 * default. If '<em>exact-match</em>' is specified, packets must have the same number of
859 * VLAN tags as the configuration. For non-exact-match, packets must at least that number
860 * of tags. L3 (routed) interfaces must be configured as exact-match. L2 interfaces are
861 * typically configured as non-exact-match. If '<em>dot1q</em>' or '<em>dot1ad</em>' is NOT
862 * entered, then the default behavior is exact-match.
863 *
864 * Use the '<em>show interface</em>' command to display all subinterfaces.
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700865 *
866 * @cliexpar
Billy McFalle9bac692017-08-11 14:05:11 -0400867 * @parblock
868 * Example of how to create a VLAN subinterface 11 to process packets on 802.1q VLAN ID 11:
869 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11}
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700870 *
Billy McFalle9bac692017-08-11 14:05:11 -0400871 * The previous example is shorthand and is equivalent to:
872 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11 dot1q 11 exact-match}
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700873 *
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700874 *
Billy McFalle9bac692017-08-11 14:05:11 -0400875 * Example of how to create a subinterface number that is different from the VLAN ID:
876 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11 dot1q 100}
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700877 *
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700878 *
Billy McFalle9bac692017-08-11 14:05:11 -0400879 * Examples of how to create q-in-q and q-in-any subinterfaces:
880 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11 dot1q 100 inner-dot1q 200}
881 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 12 dot1q 100 inner-dot1q any}
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700882 *
Billy McFalle9bac692017-08-11 14:05:11 -0400883 * Examples of how to create dot1ad interfaces:
884 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11 dot1ad 11}
885 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 12 dot1ad 100 inner-dot1q 200}
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700886 *
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700887 *
Billy McFalle9bac692017-08-11 14:05:11 -0400888 * Examples of '<em>exact-match</em>' versus non-exact match. A packet with
889 * outer VLAN 100 and inner VLAN 200 would match this interface, because the default
890 * is non-exact match:
891 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 5 dot1q 100}
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700892 *
Billy McFalle9bac692017-08-11 14:05:11 -0400893 * However, the same packet would NOT match this interface because '<em>exact-match</em>'
894 * is specified and only one VLAN is configured, but packet contains two VLANs:
895 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 5 dot1q 100 exact-match}
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700896 *
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700897 *
Billy McFalle9bac692017-08-11 14:05:11 -0400898 * Example of how to created a subinterface to process untagged packets:
899 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 5 untagged}
900 *
901 * Example of how to created a subinterface to process any packet with a VLAN ID that
902 * does not match any other subinterface:
903 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 7 default}
904 *
905 * When subinterfaces are created, they are in the down state. Example of how to
906 * enable a newly created subinterface:
907 * @cliexcmd{set interface GigabitEthernet2/0/0.7 up}
908 * @endparblock
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700909 ?*/
Billy McFalle9bac692017-08-11 14:05:11 -0400910/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700911VLIB_CLI_COMMAND (create_sub_interfaces_command, static) = {
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700912 .path = "create sub-interfaces",
Billy McFalle9bac692017-08-11 14:05:11 -0400913 .short_help = "create sub-interfaces <interface> "
914 "{<subId> [default|untagged]} | "
915 "{<subId>-<subId>} | "
916 "{<subId> dot1q|dot1ad <vlanId>|any [inner-dot1q <vlanId>|any] [exact-match]}",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700917 .function = create_sub_interfaces,
918};
Dave Barachba868bb2016-08-08 09:51:21 -0400919/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700920
921static clib_error_t *
922set_state (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -0400923 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700924{
Dave Barachba868bb2016-08-08 09:51:21 -0400925 vnet_main_t *vnm = vnet_get_main ();
926 clib_error_t *error;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700927 u32 sw_if_index, flags;
928
929 sw_if_index = ~0;
Dave Barachba868bb2016-08-08 09:51:21 -0400930 if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700931 {
932 error = clib_error_return (0, "unknown interface `%U'",
933 format_unformat_error, input);
934 goto done;
935 }
936
Dave Barachba868bb2016-08-08 09:51:21 -0400937 if (!unformat (input, "%U", unformat_vnet_sw_interface_flags, &flags))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700938 {
939 error = clib_error_return (0, "unknown flags `%U'",
940 format_unformat_error, input);
941 goto done;
942 }
943
944 error = vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
945 if (error)
946 goto done;
947
Dave Barachba868bb2016-08-08 09:51:21 -0400948done:
Ed Warnickecb9cada2015-12-08 15:45:58 -0700949 return error;
950}
951
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700952/*?
Billy McFalle9bac692017-08-11 14:05:11 -0400953 * This command is used to change the admin state (up/down) of an interface.
954 *
955 * If an interface is down, the optional '<em>punt</em>' flag can also be set.
956 * The '<em>punt</em>' flag implies the interface is disabled for forwarding
957 * but punt all traffic to slow-path. Use the '<em>enable</em>' flag to clear
958 * '<em>punt</em>' flag (interface is still down).
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700959 *
960 * @cliexpar
Nathan Skrzypczak2c77ae42021-09-29 15:36:51 +0200961 * Example of how to configure the admin state of an interface to
962 '<em>up</em>':
Billy McFalle9bac692017-08-11 14:05:11 -0400963 * @cliexcmd{set interface state GigabitEthernet2/0/0 up}
Nathan Skrzypczak2c77ae42021-09-29 15:36:51 +0200964 * Example of how to configure the admin state of an interface to
965 '<em>down</em>':
Billy McFalle9bac692017-08-11 14:05:11 -0400966 * @cliexcmd{set interface state GigabitEthernet2/0/0 down}
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700967 ?*/
Billy McFalle9bac692017-08-11 14:05:11 -0400968/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700969VLIB_CLI_COMMAND (set_state_command, static) = {
970 .path = "set interface state",
Billy McFalle9bac692017-08-11 14:05:11 -0400971 .short_help = "set interface state <interface> [up|down|punt|enable]",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700972 .function = set_state,
973};
Dave Barachba868bb2016-08-08 09:51:21 -0400974/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700975
976static clib_error_t *
977set_unnumbered (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -0400978 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700979{
Dave Barachba868bb2016-08-08 09:51:21 -0400980 vnet_main_t *vnm = vnet_get_main ();
Neale Ranns2ae2bc52018-03-16 03:22:39 -0700981 u32 unnumbered_sw_if_index = ~0;
982 u32 inherit_from_sw_if_index = ~0;
983 int enable = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700984
Igor Mikhailov (imichail)ab3e42b2016-09-25 15:11:53 -0700985 if (unformat (input, "%U use %U",
986 unformat_vnet_sw_interface, vnm, &unnumbered_sw_if_index,
987 unformat_vnet_sw_interface, vnm, &inherit_from_sw_if_index))
Neale Ranns2ae2bc52018-03-16 03:22:39 -0700988 enable = 1;
Igor Mikhailov (imichail)ab3e42b2016-09-25 15:11:53 -0700989 else if (unformat (input, "del %U",
990 unformat_vnet_sw_interface, vnm,
991 &unnumbered_sw_if_index))
Neale Ranns2ae2bc52018-03-16 03:22:39 -0700992 enable = 0;
Igor Mikhailov (imichail)ab3e42b2016-09-25 15:11:53 -0700993 else
994 return clib_error_return (0, "parse error '%U'",
995 format_unformat_error, input);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700996
Neale Ranns2ae2bc52018-03-16 03:22:39 -0700997 if (~0 == unnumbered_sw_if_index)
998 return clib_error_return (0, "Specify the unnumbered interface");
999 if (enable && ~0 == inherit_from_sw_if_index)
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -07001000 return clib_error_return (0, "When enabling unnumbered specify the"
Neale Ranns2ae2bc52018-03-16 03:22:39 -07001001 " IP enabled interface that it uses");
Neale Ranns898273f2017-03-18 02:57:38 -07001002
Stanislav Zaikin328b5da2021-07-15 16:27:29 +02001003 int rv = vnet_sw_interface_update_unnumbered (
1004 unnumbered_sw_if_index, inherit_from_sw_if_index, enable);
1005
1006 switch (rv)
1007 {
1008 case 0:
1009 break;
1010
1011 case VNET_API_ERROR_UNEXPECTED_INTF_STATE:
1012 return clib_error_return (
1013 0,
1014 "When enabling unnumbered both interfaces must be in the same tables");
1015
1016 default:
1017 return clib_error_return (
1018 0, "vnet_sw_interface_update_unnumbered returned %d", rv);
1019 }
Neale Ranns898273f2017-03-18 02:57:38 -07001020
Neale Ranns2ae2bc52018-03-16 03:22:39 -07001021 return (NULL);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001022}
1023
Dave Barachba868bb2016-08-08 09:51:21 -04001024/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001025VLIB_CLI_COMMAND (set_unnumbered_command, static) = {
1026 .path = "set interface unnumbered",
Billy McFalle9bac692017-08-11 14:05:11 -04001027 .short_help = "set interface unnumbered [<interface> use <interface> | del <interface>]",
Ed Warnickecb9cada2015-12-08 15:45:58 -07001028 .function = set_unnumbered,
1029};
Dave Barachba868bb2016-08-08 09:51:21 -04001030/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001031
1032
1033
1034static clib_error_t *
1035set_hw_class (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -04001036 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001037{
Dave Barachba868bb2016-08-08 09:51:21 -04001038 vnet_main_t *vnm = vnet_get_main ();
1039 vnet_interface_main_t *im = &vnm->interface_main;
1040 clib_error_t *error;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001041 u32 hw_if_index, hw_class_index;
1042
1043 hw_if_index = ~0;
Dave Barachba868bb2016-08-08 09:51:21 -04001044 if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
Ed Warnickecb9cada2015-12-08 15:45:58 -07001045 {
1046 error = clib_error_return (0, "unknown hardware interface `%U'",
1047 format_unformat_error, input);
1048 goto done;
1049 }
1050
Dave Barachba868bb2016-08-08 09:51:21 -04001051 if (!unformat_user (input, unformat_hash_string,
1052 im->hw_interface_class_by_name, &hw_class_index))
Ed Warnickecb9cada2015-12-08 15:45:58 -07001053 {
1054 error = clib_error_return (0, "unknown hardware class `%U'",
1055 format_unformat_error, input);
1056 goto done;
1057 }
1058
1059 error = vnet_hw_interface_set_class (vnm, hw_if_index, hw_class_index);
1060 if (error)
1061 goto done;
1062
Dave Barachba868bb2016-08-08 09:51:21 -04001063done:
Ed Warnickecb9cada2015-12-08 15:45:58 -07001064 return error;
1065}
1066
Dave Barachba868bb2016-08-08 09:51:21 -04001067/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001068VLIB_CLI_COMMAND (set_hw_class_command, static) = {
1069 .path = "set interface hw-class",
1070 .short_help = "Set interface hardware class",
1071 .function = set_hw_class,
1072};
Dave Barachba868bb2016-08-08 09:51:21 -04001073/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001074
Dave Barachba868bb2016-08-08 09:51:21 -04001075static clib_error_t *
1076vnet_interface_cli_init (vlib_main_t * vm)
1077{
1078 return 0;
1079}
Ed Warnickecb9cada2015-12-08 15:45:58 -07001080
1081VLIB_INIT_FUNCTION (vnet_interface_cli_init);
1082
Dave Barachba868bb2016-08-08 09:51:21 -04001083static clib_error_t *
Ed Warnickecb9cada2015-12-08 15:45:58 -07001084renumber_interface_command_fn (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -04001085 unformat_input_t * input,
1086 vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001087{
1088 u32 hw_if_index;
1089 u32 new_dev_instance;
Dave Barachba868bb2016-08-08 09:51:21 -04001090 vnet_main_t *vnm = vnet_get_main ();
Ed Warnickecb9cada2015-12-08 15:45:58 -07001091 int rv;
1092
Dave Barachba868bb2016-08-08 09:51:21 -04001093 if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
Ed Warnickecb9cada2015-12-08 15:45:58 -07001094 return clib_error_return (0, "unknown hardware interface `%U'",
Dave Barachba868bb2016-08-08 09:51:21 -04001095 format_unformat_error, input);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001096
Dave Barachba868bb2016-08-08 09:51:21 -04001097 if (!unformat (input, "%d", &new_dev_instance))
Ed Warnickecb9cada2015-12-08 15:45:58 -07001098 return clib_error_return (0, "new dev instance missing");
1099
1100 rv = vnet_interface_name_renumber (hw_if_index, new_dev_instance);
1101
1102 switch (rv)
1103 {
1104 case 0:
1105 break;
1106
1107 default:
1108 return clib_error_return (0, "vnet_interface_name_renumber returned %d",
Dave Barachba868bb2016-08-08 09:51:21 -04001109 rv);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001110
1111 }
1112
1113 return 0;
1114}
1115
1116
Dave Barachba868bb2016-08-08 09:51:21 -04001117/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001118VLIB_CLI_COMMAND (renumber_interface_command, static) = {
1119 .path = "renumber interface",
Billy McFalle9bac692017-08-11 14:05:11 -04001120 .short_help = "renumber interface <interface> <new-dev-instance>",
Ed Warnickecb9cada2015-12-08 15:45:58 -07001121 .function = renumber_interface_command_fn,
1122};
Dave Barachba868bb2016-08-08 09:51:21 -04001123/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001124
Damjan Marion8358ff92016-04-15 14:26:00 +02001125static clib_error_t *
1126promiscuous_cmd (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -04001127 unformat_input_t * input, vlib_cli_command_t * cmd)
Damjan Marion8358ff92016-04-15 14:26:00 +02001128{
Dave Barachba868bb2016-08-08 09:51:21 -04001129 vnet_main_t *vnm = vnet_get_main ();
Damjan Marion8358ff92016-04-15 14:26:00 +02001130 u32 hw_if_index;
1131 u32 flags = ETHERNET_INTERFACE_FLAG_ACCEPT_ALL;
Dave Barachba868bb2016-08-08 09:51:21 -04001132 ethernet_main_t *em = &ethernet_main;
1133 ethernet_interface_t *eif;
Damjan Marion8358ff92016-04-15 14:26:00 +02001134
1135 if (unformat (input, "on %U",
Dave Barachba868bb2016-08-08 09:51:21 -04001136 unformat_vnet_hw_interface, vnm, &hw_if_index))
Damjan Marion8358ff92016-04-15 14:26:00 +02001137 ;
1138 else if (unformat (input, "off %U",
Dave Barachba868bb2016-08-08 09:51:21 -04001139 unformat_ethernet_interface, vnm, &hw_if_index))
Damjan Marion8358ff92016-04-15 14:26:00 +02001140 flags = 0;
1141 else
1142 return clib_error_return (0, "unknown input `%U'",
Dave Barachba868bb2016-08-08 09:51:21 -04001143 format_unformat_error, input);
Damjan Marion8358ff92016-04-15 14:26:00 +02001144
1145 eif = ethernet_get_interface (em, hw_if_index);
1146 if (!eif)
1147 return clib_error_return (0, "not supported");
1148
1149 ethernet_set_flags (vnm, hw_if_index, flags);
1150 return 0;
1151}
1152
Dave Barachba868bb2016-08-08 09:51:21 -04001153/* *INDENT-OFF* */
Damjan Marion8358ff92016-04-15 14:26:00 +02001154VLIB_CLI_COMMAND (set_interface_promiscuous_cmd, static) = {
1155 .path = "set interface promiscuous",
Billy McFalle9bac692017-08-11 14:05:11 -04001156 .short_help = "set interface promiscuous [on|off] <interface>",
Damjan Marion8358ff92016-04-15 14:26:00 +02001157 .function = promiscuous_cmd,
1158};
Dave Barachba868bb2016-08-08 09:51:21 -04001159/* *INDENT-ON* */
Damjan Marion8358ff92016-04-15 14:26:00 +02001160
1161static clib_error_t *
1162mtu_cmd (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd)
1163{
Dave Barachba868bb2016-08-08 09:51:21 -04001164 vnet_main_t *vnm = vnet_get_main ();
Ole Troand7231612018-06-07 10:17:57 +02001165 u32 hw_if_index, sw_if_index, mtu;
Damjan Marionfe7d4a22018-04-13 19:43:39 +02001166 ethernet_main_t *em = &ethernet_main;
Ole Troand7231612018-06-07 10:17:57 +02001167 u32 mtus[VNET_N_MTU] = { 0, 0, 0, 0 };
Damjan Marion81bb6fc2022-01-16 22:47:55 +01001168 clib_error_t *err;
Damjan Marion8358ff92016-04-15 14:26:00 +02001169
Damjan Marionfe7d4a22018-04-13 19:43:39 +02001170 if (unformat (input, "%d %U", &mtu,
1171 unformat_vnet_hw_interface, vnm, &hw_if_index))
Damjan Marion8358ff92016-04-15 14:26:00 +02001172 {
Ole Troand7231612018-06-07 10:17:57 +02001173 /*
1174 * Change physical MTU on interface. Only supported for Ethernet
1175 * interfaces
1176 */
Damjan Marionfe7d4a22018-04-13 19:43:39 +02001177 ethernet_interface_t *eif = ethernet_get_interface (em, hw_if_index);
1178
1179 if (!eif)
1180 return clib_error_return (0, "not supported");
1181
Damjan Marion81bb6fc2022-01-16 22:47:55 +01001182 err = vnet_hw_interface_set_mtu (vnm, hw_if_index, mtu);
1183 if (err)
1184 return err;
Ole Troand7231612018-06-07 10:17:57 +02001185 goto done;
Damjan Marion8358ff92016-04-15 14:26:00 +02001186 }
Ole Troand7231612018-06-07 10:17:57 +02001187 else if (unformat (input, "packet %d %U", &mtu,
1188 unformat_vnet_sw_interface, vnm, &sw_if_index))
1189 /* Set default packet MTU (including L3 header */
1190 mtus[VNET_MTU_L3] = mtu;
1191 else if (unformat (input, "ip4 %d %U", &mtu,
1192 unformat_vnet_sw_interface, vnm, &sw_if_index))
1193 mtus[VNET_MTU_IP4] = mtu;
1194 else if (unformat (input, "ip6 %d %U", &mtu,
1195 unformat_vnet_sw_interface, vnm, &sw_if_index))
1196 mtus[VNET_MTU_IP6] = mtu;
1197 else if (unformat (input, "mpls %d %U", &mtu,
1198 unformat_vnet_sw_interface, vnm, &sw_if_index))
1199 mtus[VNET_MTU_MPLS] = mtu;
Damjan Marion8358ff92016-04-15 14:26:00 +02001200 else
Damjan Marionfe7d4a22018-04-13 19:43:39 +02001201 return clib_error_return (0, "unknown input `%U'",
1202 format_unformat_error, input);
Ole Troand7231612018-06-07 10:17:57 +02001203
1204 vnet_sw_interface_set_protocol_mtu (vnm, sw_if_index, mtus);
1205
1206done:
Damjan Marion8358ff92016-04-15 14:26:00 +02001207 return 0;
1208}
1209
Dave Barachba868bb2016-08-08 09:51:21 -04001210/* *INDENT-OFF* */
Damjan Marion8358ff92016-04-15 14:26:00 +02001211VLIB_CLI_COMMAND (set_interface_mtu_cmd, static) = {
1212 .path = "set interface mtu",
Ole Troand7231612018-06-07 10:17:57 +02001213 .short_help = "set interface mtu [packet|ip4|ip6|mpls] <value> <interface>",
Damjan Marion8358ff92016-04-15 14:26:00 +02001214 .function = mtu_cmd,
1215};
Dave Barachba868bb2016-08-08 09:51:21 -04001216/* *INDENT-ON* */
Damjan Marion8358ff92016-04-15 14:26:00 +02001217
Pavel Kotucekc631f2d2016-09-26 10:40:02 +02001218static clib_error_t *
Matthew Smithe0792fd2019-07-12 11:48:24 -05001219show_interface_sec_mac_addr_fn (vlib_main_t * vm, unformat_input_t * input,
1220 vlib_cli_command_t * cmd)
1221{
1222 vnet_main_t *vnm = vnet_get_main ();
1223 vnet_interface_main_t *im = &vnm->interface_main;
1224 ethernet_main_t *em = &ethernet_main;
1225 u32 sw_if_index = ~0;
1226 vnet_sw_interface_t *si, *sorted_sis = 0;
1227
1228 if (unformat (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
1229 {
1230 si = pool_elt_at_index (im->sw_interfaces, sw_if_index);
1231 vec_add1 (sorted_sis, si[0]);
1232 }
1233
1234 /* if an interface name was not passed, get all interfaces */
1235 if (vec_len (sorted_sis) == 0)
1236 {
1237 sorted_sis =
1238 vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
Damjan Marion8bea5892022-04-04 22:40:45 +02001239 vec_set_len (sorted_sis, 0);
Matthew Smithe0792fd2019-07-12 11:48:24 -05001240 /* *INDENT-OFF* */
Damjan Marionb2c31b62020-12-13 21:47:40 +01001241 pool_foreach (si, im->sw_interfaces)
1242 {
Matthew Smithe0792fd2019-07-12 11:48:24 -05001243 int visible = vnet_swif_is_api_visible (si);
1244 if (visible)
Damjan Marionb2c31b62020-12-13 21:47:40 +01001245 vec_add1 (sorted_sis, si[0]);
1246 }
Matthew Smithe0792fd2019-07-12 11:48:24 -05001247 /* *INDENT-ON* */
1248 /* Sort by name. */
1249 vec_sort_with_function (sorted_sis, sw_interface_name_compare);
1250 }
1251
1252 vec_foreach (si, sorted_sis)
1253 {
1254 vnet_sw_interface_t *sup_si;
1255 ethernet_interface_t *ei;
1256
1257 sup_si = vnet_get_sup_sw_interface (vnm, si->sw_if_index);
1258 ei = ethernet_get_interface (em, sup_si->hw_if_index);
1259
1260 vlib_cli_output (vm, "%U (%s):",
1261 format_vnet_sw_if_index_name, vnm, si->sw_if_index,
1262 (si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
1263 "up" : "dn");
1264
1265 if (ei && ei->secondary_addrs)
1266 {
Benoît Ganneb44c77d2020-10-20 16:24:17 +02001267 ethernet_interface_address_t *sec_addr;
Matthew Smithe0792fd2019-07-12 11:48:24 -05001268
1269 vec_foreach (sec_addr, ei->secondary_addrs)
1270 {
Benoît Ganneb44c77d2020-10-20 16:24:17 +02001271 vlib_cli_output (vm, " %U", format_mac_address_t, &sec_addr->mac);
Matthew Smithe0792fd2019-07-12 11:48:24 -05001272 }
1273 }
1274 }
1275
1276 vec_free (sorted_sis);
1277 return 0;
1278}
1279
1280/*?
1281 * This command is used to display interface secondary mac addresses.
1282 *
1283 * @cliexpar
1284 * Example of how to display interface secondary mac addresses:
1285 * @cliexstart{show interface secondary-mac-address}
1286 * @cliexend
1287?*/
1288/* *INDENT-OFF* */
1289VLIB_CLI_COMMAND (show_interface_sec_mac_addr, static) = {
1290 .path = "show interface secondary-mac-address",
1291 .short_help = "show interface secondary-mac-address [<interface>]",
1292 .function = show_interface_sec_mac_addr_fn,
1293};
1294/* *INDENT-ON* */
1295
1296static clib_error_t *
1297interface_add_del_mac_address (vlib_main_t * vm, unformat_input_t * input,
1298 vlib_cli_command_t * cmd)
1299{
1300 vnet_main_t *vnm = vnet_get_main ();
1301 vnet_sw_interface_t *si = NULL;
1302 clib_error_t *error = 0;
1303 u32 sw_if_index = ~0;
1304 u8 mac[6] = { 0 };
1305 u8 is_add, is_del;
1306
1307 is_add = is_del = 0;
1308
1309 if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
1310 {
1311 error = clib_error_return (0, "unknown interface `%U'",
1312 format_unformat_error, input);
1313 goto done;
1314 }
1315 if (!unformat_user (input, unformat_ethernet_address, mac))
1316 {
1317 error = clib_error_return (0, "expected mac address `%U'",
1318 format_unformat_error, input);
1319 goto done;
1320 }
1321
1322 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1323 {
1324 if (unformat (input, "add"))
1325 is_add = 1;
1326 else if (unformat (input, "del"))
1327 is_del = 1;
1328 else
1329 break;
1330 }
1331
1332 if (is_add == is_del)
1333 {
1334 error = clib_error_return (0, "must choose one of add or del");
1335 goto done;
1336 }
1337
1338 si = vnet_get_sw_interface (vnm, sw_if_index);
1339 error =
1340 vnet_hw_interface_add_del_mac_address (vnm, si->hw_if_index, mac, is_add);
1341
1342done:
1343 return error;
1344}
1345
1346/*?
1347 * The '<em>set interface secondary-mac-address </em>' command allows adding
1348 * or deleting extra MAC addresses on a given interface without changing the
1349 * default MAC address. This could allow packets sent to these MAC addresses
1350 * to be received without setting the interface to promiscuous mode.
1351 * Not all interfaces support this operation. The ones that do are mostly
1352 * hardware NICs, though virtio does also.
1353 *
1354 * @cliexpar
1355 * @parblock
1356 * Example of how to add a secondary MAC Address on an interface:
1357 * @cliexcmd{set interface secondary-mac-address GigabitEthernet0/8/0 aa:bb:cc:dd:ee:01 add}
1358 * Example of how to delete a secondary MAC address from an interface:
1359 * @cliexcmd{set interface secondary-mac-address GigabitEthernet0/8/0 aa:bb:cc:dd:ee:01 del}
1360 * @endparblock
1361?*/
1362/* *INDENT-OFF* */
1363VLIB_CLI_COMMAND (interface_add_del_mac_address_cmd, static) = {
1364 .path = "set interface secondary-mac-address",
1365 .short_help = "set interface secondary-mac-address <interface> <mac-address> [(add|del)]",
1366 .function = interface_add_del_mac_address,
1367};
1368/* *INDENT-ON* */
1369
1370static clib_error_t *
Pavel Kotucekc631f2d2016-09-26 10:40:02 +02001371set_interface_mac_address (vlib_main_t * vm, unformat_input_t * input,
1372 vlib_cli_command_t * cmd)
1373{
1374 vnet_main_t *vnm = vnet_get_main ();
Neale Rannsd867a7c2017-10-04 02:29:07 -07001375 vnet_sw_interface_t *si = NULL;
Pavel Kotucekc631f2d2016-09-26 10:40:02 +02001376 clib_error_t *error = 0;
1377 u32 sw_if_index = ~0;
John Lo62fcc0a2017-10-31 14:31:10 -04001378 u8 mac[6] = { 0 };
Pavel Kotucekc631f2d2016-09-26 10:40:02 +02001379
1380 if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
1381 {
1382 error = clib_error_return (0, "unknown interface `%U'",
1383 format_unformat_error, input);
1384 goto done;
1385 }
John Lo62fcc0a2017-10-31 14:31:10 -04001386 if (!unformat_user (input, unformat_ethernet_address, mac))
Pavel Kotucekc631f2d2016-09-26 10:40:02 +02001387 {
1388 error = clib_error_return (0, "expected mac address `%U'",
1389 format_unformat_error, input);
1390 goto done;
1391 }
Neale Rannsd867a7c2017-10-04 02:29:07 -07001392 si = vnet_get_sw_interface (vnm, sw_if_index);
1393 error = vnet_hw_interface_change_mac_address (vnm, si->hw_if_index, mac);
Pavel Kotucekc631f2d2016-09-26 10:40:02 +02001394done:
1395 return error;
1396}
1397
1398/*?
1399 * The '<em>set interface mac address </em>' command allows to set MAC address of given interface.
1400 * In case of NIC interfaces the one has to support MAC address change. A side effect of MAC address
1401 * change are changes of MAC addresses in FIB tables (ipv4 and ipv6).
1402 *
1403 * @cliexpar
1404 * @parblock
1405 * Example of how to change MAC Address of interface:
1406 * @cliexcmd{set interface mac address GigabitEthernet0/8/0 aa:bb:cc:dd:ee:01}
1407 * @cliexcmd{set interface mac address host-vpp0 aa:bb:cc:dd:ee:02}
1408 * @cliexcmd{set interface mac address tap-0 aa:bb:cc:dd:ee:03}
1409 * @cliexcmd{set interface mac address pg0 aa:bb:cc:dd:ee:04}
1410 * @endparblock
1411?*/
1412/* *INDENT-OFF* */
1413VLIB_CLI_COMMAND (set_interface_mac_address_cmd, static) = {
1414 .path = "set interface mac address",
Billy McFalle9bac692017-08-11 14:05:11 -04001415 .short_help = "set interface mac address <interface> <mac-address>",
Pavel Kotucekc631f2d2016-09-26 10:40:02 +02001416 .function = set_interface_mac_address,
1417};
1418/* *INDENT-ON* */
1419
Dave Barach7be864a2016-11-28 11:41:35 -05001420static clib_error_t *
1421set_tag (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd)
1422{
1423 vnet_main_t *vnm = vnet_get_main ();
1424 u32 sw_if_index = ~0;
1425 u8 *tag = 0;
1426
1427 if (!unformat (input, "%U %s", unformat_vnet_sw_interface,
1428 vnm, &sw_if_index, &tag))
1429 return clib_error_return (0, "unknown input `%U'",
1430 format_unformat_error, input);
1431
1432 vnet_set_sw_interface_tag (vnm, tag, sw_if_index);
1433
1434 return 0;
1435}
1436
1437/* *INDENT-OFF* */
1438VLIB_CLI_COMMAND (set_tag_command, static) = {
1439 .path = "set interface tag",
Billy McFalle9bac692017-08-11 14:05:11 -04001440 .short_help = "set interface tag <interface> <tag>",
Dave Barach7be864a2016-11-28 11:41:35 -05001441 .function = set_tag,
1442};
1443/* *INDENT-ON* */
1444
1445static clib_error_t *
1446clear_tag (vlib_main_t * vm, unformat_input_t * input,
1447 vlib_cli_command_t * cmd)
1448{
1449 vnet_main_t *vnm = vnet_get_main ();
1450 u32 sw_if_index = ~0;
1451
1452 if (!unformat (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
1453 return clib_error_return (0, "unknown input `%U'",
1454 format_unformat_error, input);
1455
1456 vnet_clear_sw_interface_tag (vnm, sw_if_index);
1457
1458 return 0;
1459}
1460
1461/* *INDENT-OFF* */
1462VLIB_CLI_COMMAND (clear_tag_command, static) = {
1463 .path = "clear interface tag",
Billy McFalle9bac692017-08-11 14:05:11 -04001464 .short_help = "clear interface tag <interface>",
Dave Barach7be864a2016-11-28 11:41:35 -05001465 .function = clear_tag,
1466};
1467/* *INDENT-ON* */
1468
Damjan Marion44036902017-04-28 12:29:15 +02001469static clib_error_t *
Neale Ranns1855b8e2018-07-11 10:31:26 -07001470set_ip_directed_broadcast (vlib_main_t * vm,
1471 unformat_input_t * input, vlib_cli_command_t * cmd)
1472{
1473 vnet_main_t *vnm = vnet_get_main ();
1474 u32 sw_if_index = ~0;
1475 u8 enable = 0;
1476
1477 if (!unformat (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index));
1478 else if (unformat (input, "enable"))
1479 enable = 1;
1480 else if (unformat (input, "disable"))
1481 enable = 0;
1482 else
1483 return clib_error_return (0, "unknown input: `%U'",
1484 format_unformat_error, input);
1485
1486 if (~0 == sw_if_index)
1487 return clib_error_return (0, "specify an interface: `%U'",
1488 format_unformat_error, input);
1489
1490 vnet_sw_interface_ip_directed_broadcast (vnm, sw_if_index, enable);
1491
1492 return 0;
1493}
1494
1495/*?
1496 * This command is used to enable/disable IP directed broadcast
1497 * If directed broadcast is enabled a packet sent to the interface's
1498 * subnet broadcast address will be sent L2 broadcast on the interface,
1499 * otherwise it is dropped.
1500 ?*/
1501/* *INDENT-OFF* */
1502VLIB_CLI_COMMAND (set_ip_directed_broadcast_command, static) = {
1503 .path = "set interface ip directed-broadcast",
1504 .short_help = "set interface enable <interface> <enable|disable>",
1505 .function = set_ip_directed_broadcast,
1506};
1507/* *INDENT-ON* */
1508
Stevenad8015b2017-10-29 22:10:46 -07001509clib_error_t *
1510set_hw_interface_change_rx_mode (vnet_main_t * vnm, u32 hw_if_index,
1511 u8 queue_id_valid, u32 queue_id,
Damjan Marioneabd4242020-10-07 20:59:07 +02001512 vnet_hw_if_rx_mode mode)
Stevenad8015b2017-10-29 22:10:46 -07001513{
1514 clib_error_t *error = 0;
1515 vnet_hw_interface_t *hw;
Damjan Marion94100532020-11-06 23:25:57 +01001516 u32 *queue_indices = 0;
Stevenad8015b2017-10-29 22:10:46 -07001517
1518 hw = vnet_get_hw_interface (vnm, hw_if_index);
1519
Damjan Marion94100532020-11-06 23:25:57 +01001520 if (queue_id_valid)
1521 {
1522 u32 queue_index;
1523 queue_index =
1524 vnet_hw_if_get_rx_queue_index_by_id (vnm, hw_if_index, queue_id);
1525 if (queue_index == ~0)
1526 return clib_error_return (0, "unknown queue %u on interface %s",
1527 queue_id, hw->name);
1528 vec_add1 (queue_indices, queue_index);
Stevenad8015b2017-10-29 22:10:46 -07001529 }
1530 else
Damjan Marion94100532020-11-06 23:25:57 +01001531 queue_indices = hw->rx_queue_indices;
Stevenad8015b2017-10-29 22:10:46 -07001532
Damjan Marion94100532020-11-06 23:25:57 +01001533 for (int i = 0; i < vec_len (queue_indices); i++)
1534 {
1535 int rv = vnet_hw_if_set_rx_queue_mode (vnm, queue_indices[i], mode);
1536 if (rv)
Wayne Morrison389aae52022-08-05 09:47:24 -04001537 {
1538 error = clib_error_return (
1539 0, "unable to set rx-mode on interface %v queue-id %u.\n",
1540 hw->name, queue_id);
1541 goto done;
1542 }
Damjan Marion94100532020-11-06 23:25:57 +01001543 }
1544
1545done:
1546 if (queue_indices != hw->rx_queue_indices)
1547 vec_free (queue_indices);
1548 vnet_hw_if_update_runtime_data (vnm, hw_if_index);
1549 return error;
Stevenad8015b2017-10-29 22:10:46 -07001550}
1551
Stevene3a395c2017-05-09 16:19:50 -07001552static clib_error_t *
Damjan Marion44036902017-04-28 12:29:15 +02001553set_interface_rx_mode (vlib_main_t * vm, unformat_input_t * input,
1554 vlib_cli_command_t * cmd)
1555{
1556 clib_error_t *error = 0;
1557 unformat_input_t _line_input, *line_input = &_line_input;
1558 vnet_main_t *vnm = vnet_get_main ();
Damjan Marion44036902017-04-28 12:29:15 +02001559 u32 hw_if_index = (u32) ~ 0;
1560 u32 queue_id = (u32) ~ 0;
Damjan Marioneabd4242020-10-07 20:59:07 +02001561 vnet_hw_if_rx_mode mode = VNET_HW_IF_RX_MODE_UNKNOWN;
Stevenad8015b2017-10-29 22:10:46 -07001562 u8 queue_id_valid = 0;
Dave Barach7be864a2016-11-28 11:41:35 -05001563
Damjan Marion44036902017-04-28 12:29:15 +02001564 if (!unformat_user (input, unformat_line_input, line_input))
1565 return 0;
1566
1567 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1568 {
1569 if (unformat
1570 (line_input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
1571 ;
1572 else if (unformat (line_input, "queue %d", &queue_id))
Stevenad8015b2017-10-29 22:10:46 -07001573 queue_id_valid = 1;
Damjan Marion44036902017-04-28 12:29:15 +02001574 else if (unformat (line_input, "polling"))
Damjan Marioneabd4242020-10-07 20:59:07 +02001575 mode = VNET_HW_IF_RX_MODE_POLLING;
Damjan Marion44036902017-04-28 12:29:15 +02001576 else if (unformat (line_input, "interrupt"))
Damjan Marioneabd4242020-10-07 20:59:07 +02001577 mode = VNET_HW_IF_RX_MODE_INTERRUPT;
Damjan Marion44036902017-04-28 12:29:15 +02001578 else if (unformat (line_input, "adaptive"))
Damjan Marioneabd4242020-10-07 20:59:07 +02001579 mode = VNET_HW_IF_RX_MODE_ADAPTIVE;
Damjan Marion44036902017-04-28 12:29:15 +02001580 else
1581 {
1582 error = clib_error_return (0, "parse error: '%U'",
1583 format_unformat_error, line_input);
1584 unformat_free (line_input);
1585 return error;
1586 }
1587 }
1588
1589 unformat_free (line_input);
1590
1591 if (hw_if_index == (u32) ~ 0)
1592 return clib_error_return (0, "please specify valid interface name");
1593
Damjan Marioneabd4242020-10-07 20:59:07 +02001594 if (mode == VNET_HW_IF_RX_MODE_UNKNOWN)
Damjan Marion44036902017-04-28 12:29:15 +02001595 return clib_error_return (0, "please specify valid rx-mode");
1596
Stevenad8015b2017-10-29 22:10:46 -07001597 error = set_hw_interface_change_rx_mode (vnm, hw_if_index, queue_id_valid,
1598 queue_id, mode);
Damjan Marion44036902017-04-28 12:29:15 +02001599
Stevene3a395c2017-05-09 16:19:50 -07001600 return (error);
Damjan Marion44036902017-04-28 12:29:15 +02001601}
1602
1603/*?
Billy McFalle9bac692017-08-11 14:05:11 -04001604 * This command is used to assign the RX packet processing mode (polling,
1605 * interrupt, adaptive) of the a given interface, and optionally a
1606 * given queue. If the '<em>queue</em>' is not provided, the '<em>mode</em>'
1607 * is applied to all queues of the interface. Not all interfaces support
1608 * all modes. To display the current rx-mode use the command
1609 * '<em>show interface rx-placement</em>'.
Damjan Marion44036902017-04-28 12:29:15 +02001610 *
1611 * @cliexpar
Billy McFalle9bac692017-08-11 14:05:11 -04001612 * Example of how to assign rx-mode to all queues on an interface:
1613 * @cliexcmd{set interface rx-mode VirtualEthernet0/0/12 polling}
1614 * Example of how to assign rx-mode to one queue of an interface:
1615 * @cliexcmd{set interface rx-mode VirtualEthernet0/0/12 queue 0 interrupt}
1616 * Example of how to display the rx-mode of all interfaces:
Damjan Marion44036902017-04-28 12:29:15 +02001617 * @cliexstart{show interface rx-placement}
1618 * Thread 1 (vpp_wk_0):
Billy McFalle9bac692017-08-11 14:05:11 -04001619 * node dpdk-input:
1620 * GigabitEthernet7/0/0 queue 0 (polling)
1621 * node vhost-user-input:
1622 * VirtualEthernet0/0/12 queue 0 (interrupt)
1623 * VirtualEthernet0/0/12 queue 2 (polling)
1624 * VirtualEthernet0/0/13 queue 0 (polling)
1625 * VirtualEthernet0/0/13 queue 2 (polling)
Damjan Marion44036902017-04-28 12:29:15 +02001626 * Thread 2 (vpp_wk_1):
Billy McFalle9bac692017-08-11 14:05:11 -04001627 * node dpdk-input:
1628 * GigabitEthernet7/0/1 queue 0 (polling)
1629 * node vhost-user-input:
1630 * VirtualEthernet0/0/12 queue 1 (polling)
1631 * VirtualEthernet0/0/12 queue 3 (polling)
1632 * VirtualEthernet0/0/13 queue 1 (polling)
1633 * VirtualEthernet0/0/13 queue 3 (polling)
Damjan Marion44036902017-04-28 12:29:15 +02001634 * @cliexend
Damjan Marion44036902017-04-28 12:29:15 +02001635?*/
1636/* *INDENT-OFF* */
Damjan Marionfe7d4a22018-04-13 19:43:39 +02001637VLIB_CLI_COMMAND (cmd_set_if_rx_mode,static) = {
Damjan Marion44036902017-04-28 12:29:15 +02001638 .path = "set interface rx-mode",
1639 .short_help = "set interface rx-mode <interface> [queue <n>] [polling | interrupt | adaptive]",
1640 .function = set_interface_rx_mode,
1641};
1642/* *INDENT-ON* */
1643
1644static clib_error_t *
1645show_interface_rx_placement_fn (vlib_main_t * vm, unformat_input_t * input,
1646 vlib_cli_command_t * cmd)
1647{
1648 u8 *s = 0;
1649 vnet_main_t *vnm = vnet_get_main ();
Mohammed Hawari9fecbe12020-12-11 19:36:37 +01001650 vnet_hw_if_rx_queue_t **all_queues = 0;
1651 vnet_hw_if_rx_queue_t **qptr;
1652 vnet_hw_if_rx_queue_t *q;
Nathan Skrzypczak455779f2021-02-15 14:48:33 +01001653 pool_foreach (q, vnm->interface_main.hw_if_rx_queues)
Mohammed Hawari9fecbe12020-12-11 19:36:37 +01001654 vec_add1 (all_queues, q);
1655 vec_sort_with_function (all_queues, vnet_hw_if_rxq_cmp_cli_api);
1656 u32 prev_node = ~0;
Damjan Marion44036902017-04-28 12:29:15 +02001657
Mohammed Hawari9fecbe12020-12-11 19:36:37 +01001658 vec_foreach (qptr, all_queues)
1659 {
1660 u32 current_thread = qptr[0]->thread_index;
1661 u32 hw_if_index = qptr[0]->hw_if_index;
1662 vnet_hw_interface_t *hw_if = vnet_get_hw_interface (vnm, hw_if_index);
1663 u32 current_node = hw_if->input_node_index;
1664 if (current_node != prev_node)
1665 s = format (s, " node %U:\n", format_vlib_node_name, vm, current_node);
1666 s = format (s, " %U queue %u (%U)\n", format_vnet_sw_if_index_name,
1667 vnm, hw_if->sw_if_index, qptr[0]->queue_id,
1668 format_vnet_hw_if_rx_mode, qptr[0]->mode);
1669 if (qptr == all_queues + vec_len (all_queues) - 1 ||
1670 current_thread != qptr[1]->thread_index)
1671 {
1672 vlib_cli_output (vm, "Thread %u (%s):\n%v", current_thread,
1673 vlib_worker_threads[current_thread].name, s);
1674 vec_reset_length (s);
1675 }
1676 prev_node = current_node;
1677 }
Damjan Marion44036902017-04-28 12:29:15 +02001678 vec_free (s);
Mohammed Hawari9fecbe12020-12-11 19:36:37 +01001679 vec_free (all_queues);
Damjan Marion44036902017-04-28 12:29:15 +02001680 return 0;
1681}
1682
Billy McFalle9bac692017-08-11 14:05:11 -04001683/*?
1684 * This command is used to display the interface and queue worker
1685 * thread placement.
1686 *
1687 * @cliexpar
1688 * Example of how to display the interface placement:
1689 * @cliexstart{show interface rx-placement}
1690 * Thread 1 (vpp_wk_0):
1691 * node dpdk-input:
1692 * GigabitEthernet7/0/0 queue 0 (polling)
1693 * node vhost-user-input:
1694 * VirtualEthernet0/0/12 queue 0 (polling)
1695 * VirtualEthernet0/0/12 queue 2 (polling)
1696 * VirtualEthernet0/0/13 queue 0 (polling)
1697 * VirtualEthernet0/0/13 queue 2 (polling)
1698 * Thread 2 (vpp_wk_1):
1699 * node dpdk-input:
1700 * GigabitEthernet7/0/1 queue 0 (polling)
1701 * node vhost-user-input:
1702 * VirtualEthernet0/0/12 queue 1 (polling)
1703 * VirtualEthernet0/0/12 queue 3 (polling)
1704 * VirtualEthernet0/0/13 queue 1 (polling)
1705 * VirtualEthernet0/0/13 queue 3 (polling)
1706 * @cliexend
1707?*/
Damjan Marion44036902017-04-28 12:29:15 +02001708/* *INDENT-OFF* */
1709VLIB_CLI_COMMAND (show_interface_rx_placement, static) = {
1710 .path = "show interface rx-placement",
1711 .short_help = "show interface rx-placement",
1712 .function = show_interface_rx_placement_fn,
1713};
1714/* *INDENT-ON* */
Mohsin Kazmi54f7c512018-08-23 18:28:11 +02001715clib_error_t *
1716set_hw_interface_rx_placement (u32 hw_if_index, u32 queue_id,
1717 u32 thread_index, u8 is_main)
Damjan Marion44036902017-04-28 12:29:15 +02001718{
Damjan Marion44036902017-04-28 12:29:15 +02001719 vnet_main_t *vnm = vnet_get_main ();
1720 vnet_device_main_t *vdm = &vnet_device_main;
Damjan Marion94100532020-11-06 23:25:57 +01001721 vnet_hw_interface_t *hw;
1722 u32 queue_index;
Damjan Marion44036902017-04-28 12:29:15 +02001723
Mohsin Kazmi54f7c512018-08-23 18:28:11 +02001724 if (is_main)
1725 thread_index = 0;
1726 else
1727 thread_index += vdm->first_worker_thread_index;
Damjan Marion44036902017-04-28 12:29:15 +02001728
1729 if (thread_index > vdm->last_worker_thread_index)
1730 return clib_error_return (0,
1731 "please specify valid worker thread or main");
1732
Damjan Marion94100532020-11-06 23:25:57 +01001733 hw = vnet_get_hw_interface (vnm, hw_if_index);
Damjan Marion44036902017-04-28 12:29:15 +02001734
Damjan Marion94100532020-11-06 23:25:57 +01001735 queue_index =
1736 vnet_hw_if_get_rx_queue_index_by_id (vnm, hw_if_index, queue_id);
1737 if (queue_index == ~0)
1738 return clib_error_return (0, "unknown queue %u on interface %s", queue_id,
1739 hw->name);
1740 vnet_hw_if_set_rx_queue_thread_index (vnm, queue_index, thread_index);
1741 vnet_hw_if_update_runtime_data (vnm, hw_if_index);
1742 return 0;
Mohsin Kazmi54f7c512018-08-23 18:28:11 +02001743}
1744
1745static clib_error_t *
Mohammed Hawari9fecbe12020-12-11 19:36:37 +01001746set_interface_rx_placement (vlib_main_t *vm, unformat_input_t *input,
1747 vlib_cli_command_t *cmd)
Mohsin Kazmi54f7c512018-08-23 18:28:11 +02001748{
1749 clib_error_t *error = 0;
1750 unformat_input_t _line_input, *line_input = &_line_input;
1751 vnet_main_t *vnm = vnet_get_main ();
1752 u32 hw_if_index = (u32) ~ 0;
1753 u32 queue_id = (u32) 0;
1754 u32 thread_index = (u32) ~ 0;
1755 u8 is_main = 0;
1756
1757 if (!unformat_user (input, unformat_line_input, line_input))
1758 return 0;
1759
1760 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1761 {
1762 if (unformat
1763 (line_input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
1764 ;
1765 else if (unformat (line_input, "queue %d", &queue_id))
1766 ;
1767 else if (unformat (line_input, "main", &thread_index))
1768 is_main = 1;
1769 else if (unformat (line_input, "worker %d", &thread_index))
1770 ;
1771 else
1772 {
1773 error = clib_error_return (0, "parse error: '%U'",
1774 format_unformat_error, line_input);
1775 unformat_free (line_input);
1776 return error;
1777 }
1778 }
1779
1780 unformat_free (line_input);
1781
1782 if (hw_if_index == (u32) ~ 0)
1783 return clib_error_return (0, "please specify valid interface name");
1784
1785 error = set_hw_interface_rx_placement (hw_if_index, queue_id, thread_index,
1786 is_main);
1787
1788 return (error);
Damjan Marion44036902017-04-28 12:29:15 +02001789}
1790
1791/*?
1792 * This command is used to assign a given interface, and optionally a
1793 * given queue, to a different thread. If the '<em>queue</em>' is not provided,
Billy McFalle9bac692017-08-11 14:05:11 -04001794 * it defaults to 0. The '<em>worker</em>' parameter is zero based and the index
1795 * in the thread name, for example, 0 in the thread name '<em>vpp_wk_0</em>'.
Damjan Marion44036902017-04-28 12:29:15 +02001796 *
1797 * @cliexpar
1798 * Example of how to display the interface placement:
Billy McFalle9bac692017-08-11 14:05:11 -04001799 * @cliexstart{show interface rx-placement}
Damjan Marion44036902017-04-28 12:29:15 +02001800 * Thread 1 (vpp_wk_0):
Billy McFalle9bac692017-08-11 14:05:11 -04001801 * node dpdk-input:
1802 * GigabitEthernet7/0/0 queue 0 (polling)
1803 * node vhost-user-input:
1804 * VirtualEthernet0/0/12 queue 0 (polling)
1805 * VirtualEthernet0/0/12 queue 2 (polling)
1806 * VirtualEthernet0/0/13 queue 0 (polling)
1807 * VirtualEthernet0/0/13 queue 2 (polling)
Damjan Marion44036902017-04-28 12:29:15 +02001808 * Thread 2 (vpp_wk_1):
Billy McFalle9bac692017-08-11 14:05:11 -04001809 * node dpdk-input:
1810 * GigabitEthernet7/0/1 queue 0 (polling)
1811 * node vhost-user-input:
1812 * VirtualEthernet0/0/12 queue 1 (polling)
1813 * VirtualEthernet0/0/12 queue 3 (polling)
1814 * VirtualEthernet0/0/13 queue 1 (polling)
1815 * VirtualEthernet0/0/13 queue 3 (polling)
Damjan Marion44036902017-04-28 12:29:15 +02001816 * @cliexend
Billy McFalle9bac692017-08-11 14:05:11 -04001817 * Example of how to assign a interface and queue to a worker thread:
1818 * @cliexcmd{set interface rx-placement VirtualEthernet0/0/12 queue 1 worker 0}
1819 * Example of how to display the interface placement:
1820 * @cliexstart{show interface rx-placement}
1821 * Thread 1 (vpp_wk_0):
1822 * node dpdk-input:
1823 * GigabitEthernet7/0/0 queue 0 (polling)
1824 * node vhost-user-input:
1825 * VirtualEthernet0/0/12 queue 0 (polling)
1826 * VirtualEthernet0/0/12 queue 1 (polling)
1827 * VirtualEthernet0/0/12 queue 2 (polling)
1828 * VirtualEthernet0/0/13 queue 0 (polling)
1829 * VirtualEthernet0/0/13 queue 2 (polling)
1830 * Thread 2 (vpp_wk_1):
1831 * node dpdk-input:
1832 * GigabitEthernet7/0/1 queue 0 (polling)
1833 * node vhost-user-input:
1834 * VirtualEthernet0/0/12 queue 3 (polling)
1835 * VirtualEthernet0/0/13 queue 1 (polling)
1836 * VirtualEthernet0/0/13 queue 3 (polling)
1837 * @cliexend
Damjan Marion44036902017-04-28 12:29:15 +02001838?*/
1839/* *INDENT-OFF* */
1840VLIB_CLI_COMMAND (cmd_set_if_rx_placement,static) = {
1841 .path = "set interface rx-placement",
Billy McFalle9bac692017-08-11 14:05:11 -04001842 .short_help = "set interface rx-placement <interface> [queue <n>] "
Damjan Marion6f9ac652017-06-15 19:01:31 +02001843 "[worker <n> | main]",
Damjan Marion44036902017-04-28 12:29:15 +02001844 .function = set_interface_rx_placement,
Damjan Marion6f9ac652017-06-15 19:01:31 +02001845 .is_mp_safe = 1,
Damjan Marion44036902017-04-28 12:29:15 +02001846};
Damjan Marion44036902017-04-28 12:29:15 +02001847/* *INDENT-ON* */
Dave Barach5ecd5a52019-02-25 15:27:28 -05001848
Mohsin Kazmi0d05c0d2021-11-09 17:44:10 +00001849int
Mohsin Kazmi005605f2021-05-24 18:33:50 +02001850set_hw_interface_tx_queue (u32 hw_if_index, u32 queue_id, uword *bitmap)
1851{
1852 vnet_main_t *vnm = vnet_get_main ();
Mohsin Kazmi0d05c0d2021-11-09 17:44:10 +00001853 vlib_thread_main_t *vtm = vlib_get_thread_main ();
Mohsin Kazmi005605f2021-05-24 18:33:50 +02001854 vnet_hw_if_tx_queue_t *txq;
1855 u32 queue_index;
1856 u32 thread_index;
1857
Mohsin Kazmi005605f2021-05-24 18:33:50 +02001858 /* highest set bit in bitmap should not exceed last worker thread index */
Steven Luong8e3f1092021-06-17 08:22:50 -07001859 thread_index = clib_bitmap_last_set (bitmap);
Mohsin Kazmi0d05c0d2021-11-09 17:44:10 +00001860 if ((thread_index != ~0) && (thread_index >= vtm->n_vlib_mains))
1861 return VNET_API_ERROR_INVALID_VALUE;
Mohsin Kazmi005605f2021-05-24 18:33:50 +02001862
1863 queue_index =
1864 vnet_hw_if_get_tx_queue_index_by_id (vnm, hw_if_index, queue_id);
1865 if (queue_index == ~0)
Mohsin Kazmi0d05c0d2021-11-09 17:44:10 +00001866 return VNET_API_ERROR_INVALID_QUEUE;
Mohsin Kazmi005605f2021-05-24 18:33:50 +02001867
1868 txq = vnet_hw_if_get_tx_queue (vnm, queue_index);
1869
1870 // free the existing bitmap
1871 if (clib_bitmap_count_set_bits (txq->threads))
1872 {
1873 txq->shared_queue = 0;
1874 clib_bitmap_free (txq->threads);
1875 }
1876
1877 clib_bitmap_foreach (thread_index, bitmap)
1878 vnet_hw_if_tx_queue_assign_thread (vnm, queue_index, thread_index);
1879
1880 vnet_hw_if_update_runtime_data (vnm, hw_if_index);
1881 return 0;
1882}
1883
1884static clib_error_t *
1885set_interface_tx_queue (vlib_main_t *vm, unformat_input_t *input,
1886 vlib_cli_command_t *cmd)
1887{
1888 clib_error_t *error = 0;
1889 unformat_input_t _line_input, *line_input = &_line_input;
1890 vnet_main_t *vnm = vnet_get_main ();
1891 u32 hw_if_index = (u32) ~0;
1892 u32 queue_id = (u32) 0;
1893 uword *bitmap = 0;
Mohsin Kazmi0d05c0d2021-11-09 17:44:10 +00001894 int rv = 0;
Mohsin Kazmi005605f2021-05-24 18:33:50 +02001895
1896 if (!unformat_user (input, unformat_line_input, line_input))
1897 return 0;
1898
1899 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1900 {
1901 if (unformat (line_input, "%U", unformat_vnet_hw_interface, vnm,
1902 &hw_if_index))
1903 ;
1904 else if (unformat (line_input, "queue %d", &queue_id))
1905 ;
1906 else if (unformat (line_input, "threads %U", unformat_bitmap_list,
1907 &bitmap))
1908 ;
1909 else
1910 {
1911 error = clib_error_return (0, "parse error: '%U'",
1912 format_unformat_error, line_input);
1913 unformat_free (line_input);
1914 return error;
1915 }
1916 }
1917
1918 unformat_free (line_input);
1919
1920 if (hw_if_index == (u32) ~0)
1921 {
1922 error = clib_error_return (0, "please specify valid interface name");
1923 goto error;
1924 }
1925
Mohsin Kazmi0d05c0d2021-11-09 17:44:10 +00001926 rv = set_hw_interface_tx_queue (hw_if_index, queue_id, bitmap);
1927
1928 switch (rv)
1929 {
1930 case VNET_API_ERROR_INVALID_VALUE:
1931 error = clib_error_return (
1932 0, "please specify valid thread(s) - last thread index %u",
1933 clib_bitmap_last_set (bitmap));
1934 break;
1935 case VNET_API_ERROR_INVALID_QUEUE:
1936 error = clib_error_return (
1937 0, "unknown queue %u on interface %s", queue_id,
1938 vnet_get_hw_interface (vnet_get_main (), hw_if_index)->name);
1939 break;
1940 default:
1941 break;
1942 }
Mohsin Kazmi005605f2021-05-24 18:33:50 +02001943
1944error:
1945 clib_bitmap_free (bitmap);
1946 return (error);
1947}
1948
1949VLIB_CLI_COMMAND (cmd_set_if_tx_queue, static) = {
1950 .path = "set interface tx-queue",
1951 .short_help = "set interface tx-queue <interface> queue <n> "
Steven Luong8e3f1092021-06-17 08:22:50 -07001952 "[threads <list>]",
Mohsin Kazmi005605f2021-05-24 18:33:50 +02001953 .function = set_interface_tx_queue,
1954 .is_mp_safe = 1,
1955};
1956
1957clib_error_t *
Chenmin Sunc4665092020-07-06 08:20:39 +08001958set_interface_rss_queues (vlib_main_t * vm, u32 hw_if_index,
1959 clib_bitmap_t * bitmap)
1960{
1961 vnet_main_t *vnm = vnet_get_main ();
1962 vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, hw_if_index);
1963
1964 return vnet_hw_interface_set_rss_queues (vnm, hi, bitmap);
1965}
1966
1967static clib_error_t *
1968set_interface_rss_queues_fn (vlib_main_t * vm,
1969 unformat_input_t * input,
1970 vlib_cli_command_t * cmd)
1971{
1972 clib_error_t *error = 0;
1973 unformat_input_t _line_input, *line_input = &_line_input;
1974 vnet_main_t *vnm = vnet_get_main ();
1975 u32 hw_if_index = (u32) ~ 0;
1976 clib_bitmap_t *bitmap = NULL;
1977
1978 if (!unformat_user (input, unformat_line_input, line_input))
1979 return 0;
1980
1981 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1982 {
1983 if (unformat
1984 (line_input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
1985 ;
1986 else
1987 if (unformat (line_input, "list %U", unformat_bitmap_list, &bitmap))
1988 ;
1989 else
1990 {
1991 error = clib_error_return (0, "parse error: '%U'",
1992 format_unformat_error, line_input);
1993 unformat_free (line_input);
1994 goto done;
1995 }
1996 }
1997
1998 unformat_free (line_input);
1999
2000 if (hw_if_index == (u32) ~ 0)
2001 {
2002 error = clib_error_return (0, "please specify valid interface name");
2003 goto done;
2004 }
2005
2006 if (bitmap == NULL)
2007 {
2008 error = clib_error_return (0, "please specify the valid rss queues");
2009 goto done;
2010 }
2011
2012 error = set_interface_rss_queues (vm, hw_if_index, bitmap);
2013
2014done:
2015 if (bitmap)
2016 clib_bitmap_free (bitmap);
2017
2018 return (error);
2019}
2020
2021/*?
2022 * This command is used to set the rss queues of a given interface
2023 * Not all the interfaces support this operation.
2024 * To display the current rss queues, use the command
2025 * '<em>show hardware-interfaces</em>'.
2026 *
2027 * @cliexpar
2028 * Example of how to set the rss queues to 0,2-5,7 of an interface:
2029 * @cliexstart{set interface rss queues VirtualFunctionEthernet18/1/0 list 0,2-5,7}
2030 * @cliexend
2031?*/
2032/* *INDENT-OFF* */
2033VLIB_CLI_COMMAND (cmd_set_interface_rss_queues,static) = {
2034 .path = "set interface rss queues",
2035 .short_help = "set interface rss queues <interface> <list <queue-list>>",
2036 .function = set_interface_rss_queues_fn,
2037};
2038/* *INDENT-ON* */
2039
Dave Barach33909772019-09-23 10:27:27 -04002040static u8 *
2041format_vnet_pcap (u8 * s, va_list * args)
2042{
2043 vnet_pcap_t *pp = va_arg (*args, vnet_pcap_t *);
2044 int type = va_arg (*args, int);
2045 int printed = 0;
2046
2047 if (type == 0)
2048 {
2049 if (pp->pcap_rx_enable)
2050 {
2051 s = format (s, "rx");
2052 printed = 1;
2053 }
2054 if (pp->pcap_tx_enable)
2055 {
2056 if (printed)
2057 s = format (s, " and ");
2058 s = format (s, "tx");
2059 printed = 1;
2060 }
2061 if (pp->pcap_drop_enable)
2062 {
2063 if (printed)
2064 s = format (s, " and ");
2065 s = format (s, "drop");
2066 printed = 1;
2067 }
2068 return s;
2069 }
2070 s = format (s, "unknown type %d!", type);
2071 return s;
2072}
2073
2074
Dave Barachb97641c2019-09-09 16:38:17 -04002075int
2076vnet_pcap_dispatch_trace_configure (vnet_pcap_dispatch_trace_args_t * a)
2077{
2078 vlib_main_t *vm = vlib_get_main ();
Damjan Marion8fb5add2021-03-04 18:41:59 +01002079 vnet_main_t *vnm = vnet_get_main ();
2080 vnet_pcap_t *pp = &vnm->pcap;
Dave Barachb97641c2019-09-09 16:38:17 -04002081 pcap_main_t *pm = &pp->pcap_main;
Dave Barachf5667c32019-09-25 11:27:46 -04002082 vnet_classify_main_t *cm = &vnet_classify_main;
Dave Barachb97641c2019-09-09 16:38:17 -04002083
2084 if (a->status)
2085 {
Dave Barach33909772019-09-23 10:27:27 -04002086 if (pp->pcap_rx_enable || pp->pcap_tx_enable || pp->pcap_drop_enable)
Dave Barachb97641c2019-09-09 16:38:17 -04002087 {
2088 vlib_cli_output
Dave Barach33909772019-09-23 10:27:27 -04002089 (vm, "pcap %U dispatch capture enabled: %d of %d pkts...",
2090 format_vnet_pcap, pp, 0 /* print type */ ,
Dave Barachb97641c2019-09-09 16:38:17 -04002091 pm->n_packets_captured, pm->n_packets_to_capture);
2092 vlib_cli_output (vm, "capture to file %s", pm->file_name);
2093 }
2094 else
Dave Barach33909772019-09-23 10:27:27 -04002095 vlib_cli_output (vm, "pcap dispatch capture disabled");
2096
Dave Barachb97641c2019-09-09 16:38:17 -04002097 return 0;
2098 }
2099
2100 /* Consistency checks */
2101
2102 /* Enable w/ capture already enabled not allowed */
Dave Barach33909772019-09-23 10:27:27 -04002103 if ((pp->pcap_rx_enable + pp->pcap_tx_enable + pp->pcap_drop_enable)
2104 && (a->rx_enable + a->tx_enable + a->drop_enable))
Dave Barachb97641c2019-09-09 16:38:17 -04002105 return VNET_API_ERROR_INVALID_VALUE;
2106
2107 /* Disable capture with capture already disabled, not interesting */
Mohammed Hawari9fecbe12020-12-11 19:36:37 +01002108 if (((pp->pcap_rx_enable + pp->pcap_tx_enable + pp->pcap_drop_enable) ==
2109 0) &&
2110 ((a->rx_enable + a->tx_enable + a->drop_enable == 0)))
Dave Barachb97641c2019-09-09 16:38:17 -04002111 return VNET_API_ERROR_VALUE_EXIST;
2112
2113 /* Change number of packets to capture while capturing */
Dave Barach33909772019-09-23 10:27:27 -04002114 if ((pp->pcap_rx_enable + pp->pcap_tx_enable + pp->pcap_drop_enable)
2115 && (a->rx_enable + a->tx_enable + a->drop_enable)
Dave Barachb97641c2019-09-09 16:38:17 -04002116 && (pm->n_packets_to_capture != a->packets_to_capture))
2117 return VNET_API_ERROR_INVALID_VALUE_2;
2118
Dave Barach33909772019-09-23 10:27:27 -04002119 /* Classify filter specified, but no classify filter configured */
Dave Barachf5667c32019-09-25 11:27:46 -04002120 if ((a->rx_enable + a->tx_enable + a->drop_enable) && a->filter &&
Benoît Ganne5943e362021-02-26 14:46:58 +01002121 (!cm->classify_table_index_by_sw_if_index ||
2122 cm->classify_table_index_by_sw_if_index[0] == ~0))
Dave Barach9137e542019-09-13 17:47:50 -04002123 return VNET_API_ERROR_NO_SUCH_LABEL;
2124
Dave Barach33909772019-09-23 10:27:27 -04002125 if (a->rx_enable + a->tx_enable + a->drop_enable)
Dave Barachb97641c2019-09-09 16:38:17 -04002126 {
Dave Barach586462f2020-08-05 16:12:35 -04002127 void *save_pcap_data;
2128
Dave Barach33909772019-09-23 10:27:27 -04002129 /* Sanity check max bytes per pkt */
2130 if (a->max_bytes_per_pkt < 32 || a->max_bytes_per_pkt > 9000)
2131 return VNET_API_ERROR_INVALID_MEMORY_SIZE;
2132
Dave Barachb97641c2019-09-09 16:38:17 -04002133 /* Clean up from previous run, if any */
Dave Barach586462f2020-08-05 16:12:35 -04002134 vec_reset_length (pm->pcap_data);
2135
2136 /* Throw away the data buffer? */
2137 if (a->free_data)
2138 vec_free (pm->pcap_data);
2139
2140 save_pcap_data = pm->pcap_data;
2141
Dave Barachb97641c2019-09-09 16:38:17 -04002142 memset (pm, 0, sizeof (*pm));
2143
Dave Barach586462f2020-08-05 16:12:35 -04002144 pm->pcap_data = save_pcap_data;
2145
Dave Barach11fb09e2020-08-06 12:10:09 -04002146 vec_validate_aligned (vnet_trace_placeholder, 2048,
2147 CLIB_CACHE_LINE_BYTES);
Dave Barachb97641c2019-09-09 16:38:17 -04002148 if (pm->lock == 0)
2149 clib_spinlock_init (&(pm->lock));
2150
2151 if (a->filename == 0)
Dave Barach33909772019-09-23 10:27:27 -04002152 {
2153 u8 *stem = 0;
2154
2155 if (a->rx_enable)
2156 stem = format (stem, "rx");
2157 if (a->tx_enable)
2158 stem = format (stem, "tx");
2159 if (a->drop_enable)
2160 stem = format (stem, "drop");
Benoît Ganne7d4a9972020-07-17 11:49:56 +02002161 a->filename = format (0, "/tmp/%v.pcap%c", stem, 0);
Dave Barach33909772019-09-23 10:27:27 -04002162 vec_free (stem);
2163 }
Dave Barachb97641c2019-09-09 16:38:17 -04002164
2165 pm->file_name = (char *) a->filename;
2166 pm->n_packets_captured = 0;
2167 pm->packet_type = PCAP_PACKET_TYPE_ethernet;
Dave Barach586462f2020-08-05 16:12:35 -04002168 /* Preallocate the data vector? */
2169 if (a->preallocate_data)
2170 {
2171 vec_validate
2172 (pm->pcap_data, a->packets_to_capture
2173 * ((sizeof (pcap_packet_header_t) + a->max_bytes_per_pkt)));
2174 vec_reset_length (pm->pcap_data);
2175 }
Dave Barachb97641c2019-09-09 16:38:17 -04002176 pm->n_packets_to_capture = a->packets_to_capture;
2177 pp->pcap_sw_if_index = a->sw_if_index;
Dave Barach9137e542019-09-13 17:47:50 -04002178 if (a->filter)
Jon Loeliger5c1e48c2020-10-15 14:41:36 -04002179 pp->filter_classify_table_index =
2180 cm->classify_table_index_by_sw_if_index[0];
Dave Barach9137e542019-09-13 17:47:50 -04002181 else
2182 pp->filter_classify_table_index = ~0;
Benoît Ganne5cfe4522021-03-03 17:37:25 +01002183 pp->pcap_error_index = a->drop_err;
Dave Barach33909772019-09-23 10:27:27 -04002184 pp->pcap_rx_enable = a->rx_enable;
2185 pp->pcap_tx_enable = a->tx_enable;
2186 pp->pcap_drop_enable = a->drop_enable;
2187 pp->max_bytes_per_pkt = a->max_bytes_per_pkt;
Dave Barachb97641c2019-09-09 16:38:17 -04002188 }
2189 else
2190 {
Dave Barach33909772019-09-23 10:27:27 -04002191 pp->pcap_rx_enable = 0;
2192 pp->pcap_tx_enable = 0;
2193 pp->pcap_drop_enable = 0;
Dave Barachf5667c32019-09-25 11:27:46 -04002194 pp->filter_classify_table_index = ~0;
Benoît Ganne5cfe4522021-03-03 17:37:25 +01002195 pp->pcap_error_index = ~0;
Dave Barachb97641c2019-09-09 16:38:17 -04002196 if (pm->n_packets_captured)
2197 {
2198 clib_error_t *error;
2199 pm->n_packets_to_capture = pm->n_packets_captured;
2200 vlib_cli_output (vm, "Write %d packets to %s, and stop capture...",
2201 pm->n_packets_captured, pm->file_name);
2202 error = pcap_write (pm);
Andrew Yourtchenko4da15062019-09-11 14:14:43 +00002203 if (pm->flags & PCAP_MAIN_INIT_DONE)
Dave Barachb97641c2019-09-09 16:38:17 -04002204 pcap_close (pm);
2205 /* Report I/O errors... */
2206 if (error)
2207 {
2208 clib_error_report (error);
2209 return VNET_API_ERROR_SYSCALL_ERROR_1;
2210 }
Dave Barach586462f2020-08-05 16:12:35 -04002211 vec_free (pm->file_name);
2212 if (a->free_data)
2213 vec_free (pm->pcap_data);
Dave Barachb97641c2019-09-09 16:38:17 -04002214 return 0;
2215 }
2216 else
2217 return VNET_API_ERROR_NO_SUCH_ENTRY;
2218 }
2219
2220 return 0;
2221}
2222
2223static clib_error_t *
Dave Barach33909772019-09-23 10:27:27 -04002224pcap_trace_command_fn (vlib_main_t * vm,
2225 unformat_input_t * input, vlib_cli_command_t * cmd)
Dave Barach5ecd5a52019-02-25 15:27:28 -05002226{
Dave Barach5ecd5a52019-02-25 15:27:28 -05002227 unformat_input_t _line_input, *line_input = &_line_input;
Dave Barachb97641c2019-09-09 16:38:17 -04002228 vnet_pcap_dispatch_trace_args_t _a, *a = &_a;
Dave Barach5ecd5a52019-02-25 15:27:28 -05002229 vnet_main_t *vnm = vnet_get_main ();
Dave Barachb97641c2019-09-09 16:38:17 -04002230 u8 *filename = 0;
2231 u32 max = 1000;
Dave Barach33909772019-09-23 10:27:27 -04002232 u32 max_bytes_per_pkt = 512;
Dave Barachb97641c2019-09-09 16:38:17 -04002233 int rv;
Dave Barach33909772019-09-23 10:27:27 -04002234 int rx_enable = 0;
2235 int tx_enable = 0;
Dave Barach586462f2020-08-05 16:12:35 -04002236 int preallocate_data = 0;
Dave Barach33909772019-09-23 10:27:27 -04002237 int drop_enable = 0;
Dave Barachb97641c2019-09-09 16:38:17 -04002238 int status = 0;
Dave Barach9137e542019-09-13 17:47:50 -04002239 int filter = 0;
Dave Barach586462f2020-08-05 16:12:35 -04002240 int free_data = 0;
Dave Barach4330c462020-06-10 17:07:32 -04002241 u32 sw_if_index = 0; /* default: any interface */
Benoît Ganne5cfe4522021-03-03 17:37:25 +01002242 vlib_error_t drop_err = ~0; /* default: any error */
Dave Barach5ecd5a52019-02-25 15:27:28 -05002243
2244 /* Get a line of input. */
2245 if (!unformat_user (input, unformat_line_input, line_input))
2246 return 0;
2247
2248 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2249 {
Dave Barach33909772019-09-23 10:27:27 -04002250 if (unformat (line_input, "rx"))
2251 rx_enable = 1;
2252 else if (unformat (line_input, "tx"))
2253 tx_enable = 1;
2254 else if (unformat (line_input, "drop"))
2255 drop_enable = 1;
2256 else if (unformat (line_input, "off"))
2257 rx_enable = tx_enable = drop_enable = 0;
2258 else if (unformat (line_input, "max-bytes-per-pkt %u",
2259 &max_bytes_per_pkt))
Dave Barachb97641c2019-09-09 16:38:17 -04002260 ;
2261 else if (unformat (line_input, "max %d", &max))
2262 ;
2263 else if (unformat (line_input, "packets-to-capture %d", &max))
2264 ;
2265 else if (unformat (line_input, "file %U", unformat_vlib_tmpfile,
2266 &filename))
2267 ;
2268 else if (unformat (line_input, "status %=", &status, 1))
2269 ;
2270 else if (unformat (line_input, "intfc %U",
2271 unformat_vnet_sw_interface, vnm, &sw_if_index))
2272 ;
Dave Barach586462f2020-08-05 16:12:35 -04002273 else if (unformat (line_input, "interface %U",
2274 unformat_vnet_sw_interface, vnm, &sw_if_index))
2275 ;
Benoît Ganne5cfe4522021-03-03 17:37:25 +01002276 else if (unformat (line_input, "error %U", unformat_vlib_error, vm,
2277 &drop_err))
2278 ;
Dave Barach586462f2020-08-05 16:12:35 -04002279 else if (unformat (line_input, "preallocate-data %=",
2280 &preallocate_data, 1))
2281 ;
2282 else if (unformat (line_input, "free-data %=", &free_data, 1))
2283 ;
2284 else if (unformat (line_input, "intfc any")
2285 || unformat (line_input, "interface any"))
Dave Barachb97641c2019-09-09 16:38:17 -04002286 sw_if_index = 0;
Dave Barach9137e542019-09-13 17:47:50 -04002287 else if (unformat (line_input, "filter"))
2288 filter = 1;
Dave Barach5ecd5a52019-02-25 15:27:28 -05002289 else
2290 {
Dave Barachb97641c2019-09-09 16:38:17 -04002291 return clib_error_return (0, "unknown input `%U'",
2292 format_unformat_error, line_input);
Dave Barach5ecd5a52019-02-25 15:27:28 -05002293 }
2294 }
Dave Barachb97641c2019-09-09 16:38:17 -04002295
Dave Barach5ecd5a52019-02-25 15:27:28 -05002296 unformat_free (line_input);
2297
Dave Barachb97641c2019-09-09 16:38:17 -04002298 /* no need for memset (a, 0, sizeof (*a)), set all fields here. */
2299 a->filename = filename;
Dave Barach33909772019-09-23 10:27:27 -04002300 a->rx_enable = rx_enable;
2301 a->tx_enable = tx_enable;
Dave Barach586462f2020-08-05 16:12:35 -04002302 a->preallocate_data = preallocate_data;
2303 a->free_data = free_data;
Dave Barach33909772019-09-23 10:27:27 -04002304 a->drop_enable = drop_enable;
Dave Barachb97641c2019-09-09 16:38:17 -04002305 a->status = status;
2306 a->packets_to_capture = max;
Dave Barachb97641c2019-09-09 16:38:17 -04002307 a->sw_if_index = sw_if_index;
Dave Barach9137e542019-09-13 17:47:50 -04002308 a->filter = filter;
Dave Barach33909772019-09-23 10:27:27 -04002309 a->max_bytes_per_pkt = max_bytes_per_pkt;
Benoît Ganne5cfe4522021-03-03 17:37:25 +01002310 a->drop_err = drop_err;
Dave Barach5ecd5a52019-02-25 15:27:28 -05002311
Dave Barachb97641c2019-09-09 16:38:17 -04002312 rv = vnet_pcap_dispatch_trace_configure (a);
2313
2314 switch (rv)
Dave Barach5ecd5a52019-02-25 15:27:28 -05002315 {
Dave Barachb97641c2019-09-09 16:38:17 -04002316 case 0:
2317 break;
Dave Barach5ecd5a52019-02-25 15:27:28 -05002318
Dave Barachb97641c2019-09-09 16:38:17 -04002319 case VNET_API_ERROR_INVALID_VALUE:
2320 return clib_error_return (0, "dispatch trace already enabled...");
Dave Barach5ecd5a52019-02-25 15:27:28 -05002321
Dave Barachb97641c2019-09-09 16:38:17 -04002322 case VNET_API_ERROR_VALUE_EXIST:
2323 return clib_error_return (0, "dispatch trace already disabled...");
Dave Barach5ecd5a52019-02-25 15:27:28 -05002324
Dave Barachb97641c2019-09-09 16:38:17 -04002325 case VNET_API_ERROR_INVALID_VALUE_2:
2326 return clib_error_return
2327 (0, "can't change number of records to capture while tracing...");
2328
2329 case VNET_API_ERROR_SYSCALL_ERROR_1:
2330 return clib_error_return (0, "I/O writing trace capture...");
2331
2332 case VNET_API_ERROR_NO_SUCH_ENTRY:
2333 return clib_error_return (0, "No packets captured...");
2334
Dave Barach33909772019-09-23 10:27:27 -04002335 case VNET_API_ERROR_INVALID_MEMORY_SIZE:
2336 return clib_error_return (0,
2337 "Max bytes per pkt must be > 32, < 9000...");
2338
Dave Barach9137e542019-09-13 17:47:50 -04002339 case VNET_API_ERROR_NO_SUCH_LABEL:
2340 return clib_error_return
2341 (0, "No classify filter configured, see 'classify filter...'");
2342
Dave Barachb97641c2019-09-09 16:38:17 -04002343 default:
2344 vlib_cli_output (vm, "WARNING: trace configure returned %d", rv);
2345 break;
Dave Barach5ecd5a52019-02-25 15:27:28 -05002346 }
Dave Barachb97641c2019-09-09 16:38:17 -04002347 return 0;
Dave Barach5ecd5a52019-02-25 15:27:28 -05002348}
2349
Dave Barach5ecd5a52019-02-25 15:27:28 -05002350/*?
2351 * This command is used to start or stop a packet capture, or show
Dave Barach33909772019-09-23 10:27:27 -04002352 * the status of packet capture.
Dave Barach5ecd5a52019-02-25 15:27:28 -05002353 *
2354 * This command has the following optional parameters:
2355 *
Dave Barach33909772019-09-23 10:27:27 -04002356 *
2357 * - <b>rx</b> - Capture received packets
2358 *
2359 * - <b>tx</b> - Capture transmitted packets
2360 *
2361 * - <b>drop</b> - Capture dropped packets
2362 *
2363 * - <b>off</b> - Stop capturing packets, write results to the specified file
Dave Barach5ecd5a52019-02-25 15:27:28 -05002364 *
2365 * - <b>max <nn></b> - Depth of local buffer. Once '<em>nn</em>' number
2366 * of packets have been received, buffer is flushed to file. Once another
2367 * '<em>nn</em>' number of packets have been received, buffer is flushed
2368 * to file, overwriting previous write. If not entered, value defaults
2369 * to 100. Can only be updated if packet capture is off.
2370 *
Dave Barach33909772019-09-23 10:27:27 -04002371 * - <b>max-bytes-per-pkt <nnnn></b> - Maximum number of bytes to capture
2372 * for each packet. Must be >= 32, <= 9000.
2373 *
Dave Barach586462f2020-08-05 16:12:35 -04002374 * - <b>preallocate-data</b> - Preallocate the data buffer, to avoid
2375 * vector expansion delays during pcap capture
2376 *
2377 * - <b>free-data</b> - Free the data buffer. Ordinarily it's a feature
2378 * to retain the data buffer so this option is seldom used.
2379 *
Dave Barach33909772019-09-23 10:27:27 -04002380 * - <b>intfc <interface-name>|any</b> - Used to specify a given interface,
Dave Barach5ecd5a52019-02-25 15:27:28 -05002381 * or use '<em>any</em>' to run packet capture on all interfaces.
2382 * '<em>any</em>' is the default if not provided. Settings from a previous
2383 * packet capture are preserved, so '<em>any</em>' can be used to reset
2384 * the interface setting.
2385 *
Dave Barachf5667c32019-09-25 11:27:46 -04002386 * - <b>filter</b> - Use the pcap rx / tx / drop trace filter, which
2387 * must be configured. Use <b>classify filter pcap...</b> to configure the
2388 * filter. The filter will only be executed if the per-interface or
2389 * any-interface tests fail.
2390 *
Benoît Ganne5cfe4522021-03-03 17:37:25 +01002391 * - <b>error <node>.<error></b> - filter packets based on a specific error.
2392 * For example: error {ip4-udp-lookup}.{No listener for dst port}
2393 *
Dave Barach5ecd5a52019-02-25 15:27:28 -05002394 * - <b>file <name></b> - Used to specify the output filename. The file will
2395 * be placed in the '<em>/tmp</em>' directory, so only the filename is
2396 * supported. Directory should not be entered. If file already exists, file
Dave Barach33909772019-09-23 10:27:27 -04002397 * will be overwritten. If no filename is provided, the file will be
2398 * named "/tmp/rx.pcap", "/tmp/tx.pcap", "/tmp/rxandtx.pcap", etc.
2399 * Can only be updated if packet capture is off.
Dave Barach5ecd5a52019-02-25 15:27:28 -05002400 *
2401 * - <b>status</b> - Displays the current status and configured attributes
2402 * associated with a packet capture. If packet capture is in progress,
2403 * '<em>status</em>' also will return the number of packets currently in
2404 * the local buffer. All additional attributes entered on command line
2405 * with '<em>status</em>' will be ignored and not applied.
2406 *
2407 * @cliexpar
2408 * Example of how to display the status of a tx packet capture when off:
Dave Barach33909772019-09-23 10:27:27 -04002409 * @cliexstart{pcap trace status}
Dave Barach5ecd5a52019-02-25 15:27:28 -05002410 * max is 100, for any interface to file /tmp/vpe.pcap
2411 * pcap tx capture is off...
2412 * @cliexend
2413 * Example of how to start a tx packet capture:
Benoît Ganne5cfe4522021-03-03 17:37:25 +01002414 * @cliexstart{pcap trace tx max 35 intfc GigabitEthernet0/8/0 file
Nathan Skrzypczak2c77ae42021-09-29 15:36:51 +02002415 * vppTest.pcap}
Dave Barach5ecd5a52019-02-25 15:27:28 -05002416 * @cliexend
2417 * Example of how to display the status of a tx packet capture in progress:
Dave Barach33909772019-09-23 10:27:27 -04002418 * @cliexstart{pcap trace status}
Dave Barach5ecd5a52019-02-25 15:27:28 -05002419 * max is 35, for interface GigabitEthernet0/8/0 to file /tmp/vppTest.pcap
2420 * pcap tx capture is on: 20 of 35 pkts...
2421 * @cliexend
2422 * Example of how to stop a tx packet capture:
Dave Barach33909772019-09-23 10:27:27 -04002423 * @cliexstart{pcap trace off}
Dave Barach5ecd5a52019-02-25 15:27:28 -05002424 * captured 21 pkts...
2425 * saved to /tmp/vppTest.pcap...
2426 * @cliexend
2427?*/
2428/* *INDENT-OFF* */
2429
2430VLIB_CLI_COMMAND (pcap_tx_trace_command, static) = {
Dave Barach33909772019-09-23 10:27:27 -04002431 .path = "pcap trace",
Dave Barach5ecd5a52019-02-25 15:27:28 -05002432 .short_help =
Dave Barach586462f2020-08-05 16:12:35 -04002433 "pcap trace [rx] [tx] [drop] [off] [max <nn>] [intfc <interface>|any]\n"
2434 " [file <name>] [status] [max-bytes-per-pkt <nnnn>][filter]\n"
2435 " [preallocate-data][free-data]",
Dave Barach33909772019-09-23 10:27:27 -04002436 .function = pcap_trace_command_fn,
Dave Barach5ecd5a52019-02-25 15:27:28 -05002437};
2438/* *INDENT-ON* */
2439
Steven Luongf49734d2021-07-26 13:38:05 -07002440static clib_error_t *
2441set_interface_name (vlib_main_t *vm, unformat_input_t *input,
2442 vlib_cli_command_t *cmd)
2443{
2444 clib_error_t *error = 0;
2445 unformat_input_t _line_input, *line_input = &_line_input;
2446 vnet_main_t *vnm = vnet_get_main ();
2447 u32 hw_if_index = ~0;
2448 char *name = 0;
2449
2450 if (!unformat_user (input, unformat_line_input, line_input))
2451 return 0;
2452
2453 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2454 {
2455 if (unformat (line_input, "%U %s", unformat_vnet_hw_interface, vnm,
2456 &hw_if_index, &name))
2457 ;
2458 else
2459 {
2460 error = clib_error_return (0, "parse error: '%U'",
2461 format_unformat_error, line_input);
2462 unformat_free (line_input);
2463 vec_free (name);
2464 return error;
2465 }
2466 }
2467
2468 unformat_free (line_input);
2469
2470 if (hw_if_index == (u32) ~0 || name == 0)
2471 {
2472 vec_free (name);
2473 error = clib_error_return (0, "please specify valid interface name");
2474 return error;
2475 }
2476
2477 error = vnet_rename_interface (vnm, hw_if_index, name);
2478 vec_free (name);
2479
2480 return (error);
2481}
2482
2483VLIB_CLI_COMMAND (cmd_set_if_name, static) = {
2484 .path = "set interface name",
2485 .short_help = "set interface name <interface-name> <new-interface-name>",
2486 .function = set_interface_name,
2487 .is_mp_safe = 1,
2488};
Mohsin Kazmi0d05c0d2021-11-09 17:44:10 +00002489
2490static clib_error_t *
2491set_interface_tx_hash_cmd (vlib_main_t *vm, unformat_input_t *input,
2492 vlib_cli_command_t *cmd)
2493{
2494 clib_error_t *error = 0;
2495 unformat_input_t _line_input, *line_input = &_line_input;
2496 vnet_main_t *vnm = vnet_get_main ();
2497 vnet_hw_interface_t *hi;
2498 u8 *hash_name = 0;
2499 u32 hw_if_index = (u32) ~0;
2500 vnet_hash_fn_t hf;
2501 vnet_hash_fn_type_t ftype;
2502
2503 if (!unformat_user (input, unformat_line_input, line_input))
2504 return 0;
2505
2506 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2507 {
2508 if (unformat (line_input, "%U", unformat_vnet_hw_interface, vnm,
2509 &hw_if_index))
2510 ;
2511 else if (unformat (line_input, "hash-name %s", &hash_name))
2512 ;
2513 else
2514 {
2515 error = clib_error_return (0, "parse error: '%U'",
2516 format_unformat_error, line_input);
2517 unformat_free (line_input);
2518 return error;
2519 }
2520 }
2521
2522 unformat_free (line_input);
2523
2524 if (hw_if_index == (u32) ~0)
2525 {
2526 error = clib_error_return (0, "please specify valid interface name");
2527 goto error;
2528 }
2529
Dave Barach9e0f9e22022-01-18 08:52:47 -05002530 if (hash_name == 0)
2531 {
2532 error = clib_error_return (0, "hash-name is required");
2533 goto error;
2534 }
2535
Mohsin Kazmi0d05c0d2021-11-09 17:44:10 +00002536 hi = vnet_get_hw_interface (vnm, hw_if_index);
2537 ftype =
2538 vnet_get_hw_interface_class (vnm, hi->hw_class_index)->tx_hash_fn_type;
2539 hf = vnet_hash_function_from_name ((const char *) hash_name, ftype);
2540
2541 if (!hf)
2542 {
2543 error = clib_error_return (0, "please specify valid hash name");
2544 goto error;
2545 }
2546
2547 hi->hf = hf;
2548error:
2549 vec_free (hash_name);
2550 return (error);
2551}
2552
2553VLIB_CLI_COMMAND (cmd_set_if_tx_hash, static) = {
2554 .path = "set interface tx-hash",
2555 .short_help = "set interface tx-hash <interface> hash-name <hash-name>",
2556 .function = set_interface_tx_hash_cmd,
2557};
2558
2559static clib_error_t *
2560show_tx_hash (vlib_main_t *vm, unformat_input_t *input,
2561 vlib_cli_command_t *cmd)
2562{
2563 clib_error_t *error = 0;
2564 unformat_input_t _line_input, *line_input = &_line_input;
2565 vnet_main_t *vnm = vnet_get_main ();
2566 vnet_hw_interface_t *hi;
2567 vnet_hash_function_registration_t *hash;
2568 u32 hw_if_index = (u32) ~0;
2569 vnet_hash_fn_type_t ftype;
2570
2571 if (!unformat_user (input, unformat_line_input, line_input))
2572 return 0;
2573
2574 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2575 {
2576 if (unformat (line_input, "%U", unformat_vnet_hw_interface, vnm,
2577 &hw_if_index))
2578 ;
2579 else
2580 {
2581 error = clib_error_return (0, "parse error: '%U'",
2582 format_unformat_error, line_input);
2583 unformat_free (line_input);
2584 goto error;
2585 }
2586 }
2587
2588 unformat_free (line_input);
2589
2590 if (hw_if_index == (u32) ~0)
2591 {
2592 error = clib_error_return (0, "please specify valid interface name");
2593 goto error;
2594 }
2595
2596 hi = vnet_get_hw_interface (vnm, hw_if_index);
2597 ftype =
2598 vnet_get_hw_interface_class (vnm, hi->hw_class_index)->tx_hash_fn_type;
2599
2600 if (hi->hf)
2601 {
2602 hash = vnet_hash_function_from_func (hi->hf, ftype);
2603 if (hash)
2604 vlib_cli_output (vm, "%U", format_vnet_hash, hash);
2605 else
2606 vlib_cli_output (vm, "no matching hash function found");
2607 }
2608 else
2609 vlib_cli_output (vm, "no hashing function set");
2610
2611error:
2612 return (error);
2613}
2614
2615VLIB_CLI_COMMAND (cmd_show_tx_hash, static) = {
2616 .path = "show interface tx-hash",
2617 .short_help = "show interface tx-hash [interface]",
2618 .function = show_tx_hash,
2619};
2620
Dave Barachba868bb2016-08-08 09:51:21 -04002621/*
2622 * fd.io coding-style-patch-verification: ON
2623 *
2624 * Local Variables:
2625 * eval: (c-set-style "gnu")
2626 * End:
2627 */