blob: c56eb9777cf3765fd927680b78474e582b574075 [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>
Damjan Marionb8dd9812023-11-03 13:47:05 +000057#include <vnet/dev/dev.h>
58#include <vnet/dev/dev_funcs.h>
59
Dave Barachba868bb2016-08-08 09:51:21 -040060static int
61compare_interface_names (void *a1, void *a2)
Ed Warnickecb9cada2015-12-08 15:45:58 -070062{
Dave Barachba868bb2016-08-08 09:51:21 -040063 u32 *hi1 = a1;
64 u32 *hi2 = a2;
Ed Warnickecb9cada2015-12-08 15:45:58 -070065
Dave Barachba868bb2016-08-08 09:51:21 -040066 return vnet_hw_interface_compare (vnet_get_main (), *hi1, *hi2);
Ed Warnickecb9cada2015-12-08 15:45:58 -070067}
68
69static clib_error_t *
70show_or_clear_hw_interfaces (vlib_main_t * vm,
71 unformat_input_t * input,
Benoît Ganne17814d72020-07-24 09:57:11 +020072 vlib_cli_command_t * cmd, int is_show)
Ed Warnickecb9cada2015-12-08 15:45:58 -070073{
Dave Barachba868bb2016-08-08 09:51:21 -040074 clib_error_t *error = 0;
Vratko Polak34149772022-03-31 12:32:10 +020075 unformat_input_t _line_input, *line_input = &_line_input;
Dave Barachba868bb2016-08-08 09:51:21 -040076 vnet_main_t *vnm = vnet_get_main ();
77 vnet_interface_main_t *im = &vnm->interface_main;
78 vnet_hw_interface_t *hi;
79 u32 hw_if_index, *hw_if_indices = 0;
Benoît Ganne17814d72020-07-24 09:57:11 +020080 int i, verbose = -1, show_bond = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070081
Vratko Polak34149772022-03-31 12:32:10 +020082 if (!unformat_user (input, unformat_line_input, line_input))
Mohammed Hawari83caa622022-08-08 10:31:11 +020083 goto skip_unformat;
Vratko Polak34149772022-03-31 12:32:10 +020084
85 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -070086 {
87 /* See if user wants to show a specific interface. */
Vratko Polak34149772022-03-31 12:32:10 +020088 if (unformat (line_input, "%U", unformat_vnet_hw_interface, vnm,
89 &hw_if_index))
Dave Barachba868bb2016-08-08 09:51:21 -040090 vec_add1 (hw_if_indices, hw_if_index);
John Lobcebbb92016-04-05 15:47:43 -040091
Sean Hope679ea792016-02-22 15:12:01 -050092 /* See if user wants to show an interface with a specific hw_if_index. */
Vratko Polak34149772022-03-31 12:32:10 +020093 else if (unformat (line_input, "%u", &hw_if_index))
Dave Barachba868bb2016-08-08 09:51:21 -040094 vec_add1 (hw_if_indices, hw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -070095
Vratko Polak34149772022-03-31 12:32:10 +020096 else if (unformat (line_input, "verbose"))
Dave Barachba868bb2016-08-08 09:51:21 -040097 verbose = 1; /* this is also the default */
Ed Warnickecb9cada2015-12-08 15:45:58 -070098
Vratko Polak34149772022-03-31 12:32:10 +020099 else if (unformat (line_input, "detail"))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700100 verbose = 2;
101
Vratko Polak34149772022-03-31 12:32:10 +0200102 else if (unformat (line_input, "brief"))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700103 verbose = 0;
104
Vratko Polak34149772022-03-31 12:32:10 +0200105 else if (unformat (line_input, "bond"))
Dave Barachba868bb2016-08-08 09:51:21 -0400106 {
107 show_bond = 1;
108 if (verbose < 0)
109 verbose = 0; /* default to brief for link bonding */
110 }
John Lobcebbb92016-04-05 15:47:43 -0400111
Ed Warnickecb9cada2015-12-08 15:45:58 -0700112 else
113 {
114 error = clib_error_return (0, "unknown input `%U'",
Vratko Polak34149772022-03-31 12:32:10 +0200115 format_unformat_error, line_input);
116 unformat_free (line_input);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700117 goto done;
118 }
119 }
Dave Barachba868bb2016-08-08 09:51:21 -0400120
Vratko Polak34149772022-03-31 12:32:10 +0200121 unformat_free (line_input);
122
Mohammed Hawari83caa622022-08-08 10:31:11 +0200123skip_unformat:
Ed Warnickecb9cada2015-12-08 15:45:58 -0700124 /* Gather interfaces. */
125 if (vec_len (hw_if_indices) == 0)
Damjan Marionb2c31b62020-12-13 21:47:40 +0100126 pool_foreach (hi, im->hw_interfaces)
127 vec_add1 (hw_if_indices, hi - im->hw_interfaces);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700128
Dave Barachba868bb2016-08-08 09:51:21 -0400129 if (verbose < 0)
130 verbose = 1; /* default to verbose (except bond) */
John Lobcebbb92016-04-05 15:47:43 -0400131
Ed Warnickecb9cada2015-12-08 15:45:58 -0700132 if (is_show)
133 {
134 /* Sort by name. */
135 vec_sort_with_function (hw_if_indices, compare_interface_names);
136
137 vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm, 0, verbose);
138 for (i = 0; i < vec_len (hw_if_indices); i++)
139 {
140 hi = vnet_get_hw_interface (vnm, hw_if_indices[i]);
Dave Barachba868bb2016-08-08 09:51:21 -0400141 if (show_bond == 0) /* show all interfaces */
142 vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm,
143 hi, verbose);
144 else if ((hi->bond_info) &&
John Lobcebbb92016-04-05 15:47:43 -0400145 (hi->bond_info != VNET_HW_INTERFACE_BOND_INFO_SLAVE))
Dave Barachba868bb2016-08-08 09:51:21 -0400146 { /* show only bonded interface and all its slave interfaces */
John Lobcebbb92016-04-05 15:47:43 -0400147 int hw_idx;
Dave Barachba868bb2016-08-08 09:51:21 -0400148 vnet_hw_interface_t *shi;
149 vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm,
John Lobcebbb92016-04-05 15:47:43 -0400150 hi, verbose);
Dave Barachba868bb2016-08-08 09:51:21 -0400151
Damjan Marionf0ca1e82020-12-13 23:26:56 +0100152 clib_bitmap_foreach (hw_idx, hi->bond_info)
153 {
Dave Barachba868bb2016-08-08 09:51:21 -0400154 shi = vnet_get_hw_interface(vnm, hw_idx);
155 vlib_cli_output (vm, "%U\n",
156 format_vnet_hw_interface, vnm, shi, verbose);
Damjan Marionf0ca1e82020-12-13 23:26:56 +0100157 }
John Lobcebbb92016-04-05 15:47:43 -0400158 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700159 }
160 }
161 else
162 {
163 for (i = 0; i < vec_len (hw_if_indices); i++)
164 {
Dave Barachba868bb2016-08-08 09:51:21 -0400165 vnet_device_class_t *dc;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700166
167 hi = vnet_get_hw_interface (vnm, hw_if_indices[i]);
168 dc = vec_elt_at_index (im->device_classes, hi->dev_class_index);
Dave Barachba868bb2016-08-08 09:51:21 -0400169
Ed Warnickecb9cada2015-12-08 15:45:58 -0700170 if (dc->clear_counters)
171 dc->clear_counters (hi->dev_instance);
172 }
173 }
174
Dave Barachba868bb2016-08-08 09:51:21 -0400175done:
Ed Warnickecb9cada2015-12-08 15:45:58 -0700176 vec_free (hw_if_indices);
177 return error;
178}
179
Benoît Ganne17814d72020-07-24 09:57:11 +0200180static clib_error_t *
181show_hw_interfaces (vlib_main_t * vm,
182 unformat_input_t * input, vlib_cli_command_t * cmd)
183{
184 return show_or_clear_hw_interfaces (vm, input, cmd, 1 /* is_show */ );
185}
186
187static clib_error_t *
188clear_hw_interfaces (vlib_main_t * vm,
189 unformat_input_t * input, vlib_cli_command_t * cmd)
190{
191 return show_or_clear_hw_interfaces (vm, input, cmd, 0 /* is_show */ );
192}
193
194
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700195/*?
Billy McFalle9bac692017-08-11 14:05:11 -0400196 * Display more detailed information about all or a list of given interfaces.
197 * The verboseness of the output can be controlled by the following optional
198 * parameters:
199 * - brief: Only show name, index and state (default for bonded interfaces).
200 * - verbose: Also display additional attributes (default for all other interfaces).
201 * - detail: Also display all remaining attributes and extended statistics.
202 *
203 * To limit the output of the command to bonded interfaces and their slave
204 * interfaces, use the '<em>bond</em>' optional parameter.
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700205 *
206 * @cliexpar
Billy McFalle9bac692017-08-11 14:05:11 -0400207 * Example of how to display default data for all interfaces:
208 * @cliexstart{show hardware-interfaces}
209 * Name Idx Link Hardware
210 * GigabitEthernet7/0/0 1 up GigabitEthernet7/0/0
211 * Ethernet address ec:f4:bb:c0:bc:fc
212 * Intel e1000
213 * carrier up full duplex speed 1000 mtu 9216
214 * rx queues 1, rx desc 1024, tx queues 3, tx desc 1024
215 * cpu socket 0
216 * GigabitEthernet7/0/1 2 up GigabitEthernet7/0/1
217 * Ethernet address ec:f4:bb:c0:bc:fd
218 * Intel e1000
219 * carrier up full duplex speed 1000 mtu 9216
220 * rx queues 1, rx desc 1024, tx queues 3, tx desc 1024
221 * cpu socket 0
222 * VirtualEthernet0/0/0 3 up VirtualEthernet0/0/0
223 * Ethernet address 02:fe:a5:a9:8b:8e
224 * VirtualEthernet0/0/1 4 up VirtualEthernet0/0/1
225 * Ethernet address 02:fe:c0:4e:3b:b0
226 * VirtualEthernet0/0/2 5 up VirtualEthernet0/0/2
227 * Ethernet address 02:fe:1f:73:92:81
228 * VirtualEthernet0/0/3 6 up VirtualEthernet0/0/3
229 * Ethernet address 02:fe:f2:25:c4:68
230 * local0 0 down local0
231 * local
232 * @cliexend
233 * Example of how to display '<em>verbose</em>' data for an interface by name and
234 * software index (where 2 is the software index):
235 * @cliexstart{show hardware-interfaces GigabitEthernet7/0/0 2 verbose}
236 * Name Idx Link Hardware
237 * GigabitEthernet7/0/0 1 up GigabitEthernet7/0/0
238 * Ethernet address ec:f4:bb:c0:bc:fc
239 * Intel e1000
240 * carrier up full duplex speed 1000 mtu 9216
241 * rx queues 1, rx desc 1024, tx queues 3, tx desc 1024
242 * cpu socket 0
243 * GigabitEthernet7/0/1 2 down GigabitEthernet7/0/1
244 * Ethernet address ec:f4:bb:c0:bc:fd
245 * Intel e1000
246 * carrier up full duplex speed 1000 mtu 9216
247 * rx queues 1, rx desc 1024, tx queues 3, tx desc 1024
248 * cpu socket 0
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700249 * @cliexend
250 ?*/
Ed Warnickecb9cada2015-12-08 15:45:58 -0700251VLIB_CLI_COMMAND (show_hw_interfaces_command, static) = {
252 .path = "show hardware-interfaces",
Billy McFalle9bac692017-08-11 14:05:11 -0400253 .short_help = "show hardware-interfaces [brief|verbose|detail] [bond] "
254 "[<interface> [<interface> [..]]] [<sw_idx> [<sw_idx> [..]]]",
Benoît Ganne17814d72020-07-24 09:57:11 +0200255 .function = show_hw_interfaces,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700256};
257
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 ?*/
Ed Warnickecb9cada2015-12-08 15:45:58 -0700270VLIB_CLI_COMMAND (clear_hw_interface_counters_command, static) = {
271 .path = "clear hardware-interfaces",
Billy McFalle9bac692017-08-11 14:05:11 -0400272 .short_help = "clear hardware-interfaces "
273 "[<interface> [<interface> [..]]] [<sw_idx> [<sw_idx> [..]]]",
Benoît Ganne17814d72020-07-24 09:57:11 +0200274 .function = clear_hw_interfaces,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700275};
276
Dave Barachba868bb2016-08-08 09:51:21 -0400277static int
278sw_interface_name_compare (void *a1, void *a2)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700279{
280 vnet_sw_interface_t *si1 = a1;
281 vnet_sw_interface_t *si2 = a2;
282
Dave Barachba868bb2016-08-08 09:51:21 -0400283 return vnet_sw_interface_compare (vnet_get_main (),
284 si1->sw_if_index, si2->sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700285}
286
287static clib_error_t *
288show_sw_interfaces (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -0400289 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700290{
Dave Barachba868bb2016-08-08 09:51:21 -0400291 clib_error_t *error = 0;
292 vnet_main_t *vnm = vnet_get_main ();
Dave Barach525c9d02018-05-26 10:48:55 -0400293 unformat_input_t _linput, *linput = &_linput;
Dave Barachba868bb2016-08-08 09:51:21 -0400294 vnet_interface_main_t *im = &vnm->interface_main;
295 vnet_sw_interface_t *si, *sorted_sis = 0;
Damjan Marion22311502016-10-28 20:30:15 +0200296 u32 sw_if_index = ~(u32) 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700297 u8 show_addresses = 0;
Damjan Marion22311502016-10-28 20:30:15 +0200298 u8 show_features = 0;
Dave Barach7be864a2016-11-28 11:41:35 -0500299 u8 show_tag = 0;
Jon Loeliger9485d992019-11-08 15:05:23 -0600300 u8 show_vtr = 0;
Dave Barach525c9d02018-05-26 10:48:55 -0400301 int verbose = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700302
Dave Barach525c9d02018-05-26 10:48:55 -0400303 /*
304 * Get a line of input. Won't work if the user typed
305 * "show interface" and nothing more.
306 */
307 if (unformat_user (input, unformat_line_input, linput))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700308 {
Dave Barach525c9d02018-05-26 10:48:55 -0400309 while (unformat_check_input (linput) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700310 {
Dave Barach525c9d02018-05-26 10:48:55 -0400311 /* See if user wants to show specific interface */
312 if (unformat
313 (linput, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
314 {
315 si = pool_elt_at_index (im->sw_interfaces, sw_if_index);
316 vec_add1 (sorted_sis, si[0]);
317 }
318 else if (unformat (linput, "address") || unformat (linput, "addr"))
319 show_addresses = 1;
320 else if (unformat (linput, "features") || unformat (linput, "feat"))
321 show_features = 1;
322 else if (unformat (linput, "tag"))
323 show_tag = 1;
Jon Loeliger9485d992019-11-08 15:05:23 -0600324 else if (unformat (linput, "vtr"))
325 show_vtr = 1;
Dave Barach525c9d02018-05-26 10:48:55 -0400326 else if (unformat (linput, "verbose"))
327 verbose = 1;
Neale Rannse619ada2021-09-22 10:49:43 +0000328 else if (unformat (linput, "%d", &sw_if_index))
329 {
330 if (!pool_is_free_index (im->sw_interfaces, sw_if_index))
331 {
332 si = pool_elt_at_index (im->sw_interfaces, sw_if_index);
333 vec_add1 (sorted_sis, si[0]);
334 }
335 else
336 {
337 vec_free (sorted_sis);
338 error = clib_error_return (0, "unknown interface index `%d'",
339 sw_if_index);
340 goto done;
341 }
342 }
Dave Barach525c9d02018-05-26 10:48:55 -0400343 else
344 {
Dave Barach8fdde3c2019-05-17 10:46:40 -0400345 vec_free (sorted_sis);
Dave Barach525c9d02018-05-26 10:48:55 -0400346 error = clib_error_return (0, "unknown input `%U'",
347 format_unformat_error, linput);
348 goto done;
349 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700350 }
Dave Barach525c9d02018-05-26 10:48:55 -0400351 unformat_free (linput);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700352 }
Jon Loeliger9485d992019-11-08 15:05:23 -0600353 if (show_features || show_tag || show_vtr)
Damjan Marion22311502016-10-28 20:30:15 +0200354 {
355 if (sw_if_index == ~(u32) 0)
Dave Barach8fdde3c2019-05-17 10:46:40 -0400356 {
357 vec_free (sorted_sis);
358 return clib_error_return (0, "Interface not specified...");
359 }
Dave Barach7be864a2016-11-28 11:41:35 -0500360 }
Damjan Marion22311502016-10-28 20:30:15 +0200361
Dave Barach7be864a2016-11-28 11:41:35 -0500362 if (show_features)
363 {
Dave Barach525c9d02018-05-26 10:48:55 -0400364 vnet_interface_features_show (vm, sw_if_index, verbose);
Neale Ranns47a3d992020-09-29 15:38:51 +0000365 vlib_cli_output (vm, "%U", format_l2_input_features, sw_if_index, 1);
Eyal Bari942402b2017-07-26 11:57:04 +0300366
367 l2_output_config_t *l2_output = l2output_intf_config (sw_if_index);
368 vlib_cli_output (vm, "\nl2-output:");
369 if (l2_output->out_vtr_flag)
370 vlib_cli_output (vm, "%10s (%s)", "VTR", "--internal--");
371 vlib_cli_output (vm, "%U", format_l2_output_features,
Neale Ranns5d9df1d2018-11-09 08:19:27 -0800372 l2_output->feature_bitmap, 1);
Dave Barach8fdde3c2019-05-17 10:46:40 -0400373 vec_free (sorted_sis);
Damjan Marion22311502016-10-28 20:30:15 +0200374 return 0;
375 }
Dave Barach7be864a2016-11-28 11:41:35 -0500376 if (show_tag)
377 {
378 u8 *tag;
379 tag = vnet_get_sw_interface_tag (vnm, sw_if_index);
380 vlib_cli_output (vm, "%U: %s",
381 format_vnet_sw_if_index_name, vnm, sw_if_index,
382 tag ? (char *) tag : "(none)");
Dave Barach8fdde3c2019-05-17 10:46:40 -0400383 vec_free (sorted_sis);
Dave Barach7be864a2016-11-28 11:41:35 -0500384 return 0;
385 }
Damjan Marion22311502016-10-28 20:30:15 +0200386
Jon Loeliger9485d992019-11-08 15:05:23 -0600387 /*
388 * Show vlan tag rewrite data for one interface.
389 */
390 if (show_vtr)
391 {
392 u32 vtr_op = L2_VTR_DISABLED;
393 u32 push_dot1q = 0, tag1 = 0, tag2 = 0;
394
395 if (l2vtr_get (vm, vnm, sw_if_index,
396 &vtr_op, &push_dot1q, &tag1, &tag2) != 0)
397 {
398 vlib_cli_output (vm, "%U: Problem getting vlan tag-rewrite data",
399 format_vnet_sw_if_index_name, vnm, sw_if_index);
400 return 0;
401 }
402 vlib_cli_output (vm, "%U: VTR %0U",
403 format_vnet_sw_if_index_name, vnm, sw_if_index,
404 format_vtr, vtr_op, push_dot1q, tag1, tag2);
405 return 0;
406 }
407
Ed Warnickecb9cada2015-12-08 15:45:58 -0700408 if (!show_addresses)
Dave Barachba868bb2016-08-08 09:51:21 -0400409 vlib_cli_output (vm, "%U\n", format_vnet_sw_interface, vnm, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700410
Dave Barachba868bb2016-08-08 09:51:21 -0400411 if (vec_len (sorted_sis) == 0) /* Get all interfaces */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700412 {
413 /* Gather interfaces. */
Dave Barachba868bb2016-08-08 09:51:21 -0400414 sorted_sis =
415 vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
Damjan Marion8bea5892022-04-04 22:40:45 +0200416 vec_set_len (sorted_sis, 0);
Damjan Marionb2c31b62020-12-13 21:47:40 +0100417 pool_foreach (si, im->sw_interfaces)
418 {
Dave Barach525c9d02018-05-26 10:48:55 -0400419 int visible = vnet_swif_is_api_visible (si);
420 if (visible)
Damjan Marionb2c31b62020-12-13 21:47:40 +0100421 vec_add1 (sorted_sis, si[0]);
422 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700423 /* Sort by name. */
424 vec_sort_with_function (sorted_sis, sw_interface_name_compare);
425 }
426
427 if (show_addresses)
428 {
429 vec_foreach (si, sorted_sis)
Dave Barachba868bb2016-08-08 09:51:21 -0400430 {
Dave Barachba868bb2016-08-08 09:51:21 -0400431 ip4_main_t *im4 = &ip4_main;
432 ip6_main_t *im6 = &ip6_main;
433 ip_lookup_main_t *lm4 = &im4->lookup_main;
434 ip_lookup_main_t *lm6 = &im6->lookup_main;
435 ip_interface_address_t *ia = 0;
Dave Barachba868bb2016-08-08 09:51:21 -0400436 u32 fib_index4 = 0, fib_index6 = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700437
Dave Barachba868bb2016-08-08 09:51:21 -0400438 if (vec_len (im4->fib_index_by_sw_if_index) > si->sw_if_index)
439 fib_index4 = vec_elt (im4->fib_index_by_sw_if_index,
440 si->sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700441
Dave Barachba868bb2016-08-08 09:51:21 -0400442 if (vec_len (im6->fib_index_by_sw_if_index) > si->sw_if_index)
443 fib_index6 = vec_elt (im6->fib_index_by_sw_if_index,
444 si->sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700445
John Lo4478d8e2018-01-12 17:15:25 -0500446 ip4_fib_t *fib4 = ip4_fib_get (fib_index4);
447 ip6_fib_t *fib6 = ip6_fib_get (fib_index6);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700448
Dave Barachba868bb2016-08-08 09:51:21 -0400449 if (si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)
450 vlib_cli_output
451 (vm, "%U (%s): \n unnumbered, use %U",
John Lo4478d8e2018-01-12 17:15:25 -0500452 format_vnet_sw_if_index_name, vnm, si->sw_if_index,
Dave Barachba868bb2016-08-08 09:51:21 -0400453 (si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? "up" : "dn",
454 format_vnet_sw_if_index_name, vnm, si->unnumbered_sw_if_index);
Dave Barachba868bb2016-08-08 09:51:21 -0400455 else
John Lo4478d8e2018-01-12 17:15:25 -0500456 vlib_cli_output
457 (vm, "%U (%s):",
458 format_vnet_sw_if_index_name, vnm, si->sw_if_index,
459 (si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? "up" : "dn");
Ed Warnickecb9cada2015-12-08 15:45:58 -0700460
Eyal Bari942402b2017-07-26 11:57:04 +0300461 /* Display any L2 info */
Neale Ranns47a3d992020-09-29 15:38:51 +0000462 vlib_cli_output (vm, "%U", format_l2_input, si->sw_if_index);
Dave Barachba868bb2016-08-08 09:51:21 -0400463
464 /* Display any IP4 addressing info */
John Lo4478d8e2018-01-12 17:15:25 -0500465 foreach_ip_interface_address (lm4, ia, si->sw_if_index,
466 1 /* honor unnumbered */,
467 ({
468 ip4_address_t *r4 = ip_interface_address_get_address (lm4, ia);
Neale Rannsd6953332021-08-10 07:39:18 +0000469 if (fib4->hash.table_id)
470 vlib_cli_output (
471 vm, " L3 %U/%d ip4 table-id %d fib-idx %d", format_ip4_address,
472 r4, ia->address_length, fib4->hash.table_id,
473 ip4_fib_index_from_table_id (fib4->hash.table_id));
John Lo4478d8e2018-01-12 17:15:25 -0500474 else
475 vlib_cli_output (vm, " L3 %U/%d",
476 format_ip4_address, r4, ia->address_length);
477 }));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700478
Dave Barachba868bb2016-08-08 09:51:21 -0400479 /* Display any IP6 addressing info */
John Lo4478d8e2018-01-12 17:15:25 -0500480 foreach_ip_interface_address (lm6, ia, si->sw_if_index,
481 1 /* honor unnumbered */,
482 ({
483 ip6_address_t *r6 = ip_interface_address_get_address (lm6, ia);
484 if (fib6->table_id)
485 vlib_cli_output (vm, " L3 %U/%d ip6 table-id %d fib-idx %d",
486 format_ip6_address, r6, ia->address_length,
487 fib6->table_id,
488 ip6_fib_index_from_table_id (fib6->table_id));
489 else
490 vlib_cli_output (vm, " L3 %U/%d",
491 format_ip6_address, r6, ia->address_length);
492 }));
Ole Troand7231612018-06-07 10:17:57 +0200493 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700494 }
Ole Troand7231612018-06-07 10:17:57 +0200495 else
496 {
497 vec_foreach (si, sorted_sis)
498 {
499 vlib_cli_output (vm, "%U\n", format_vnet_sw_interface, vnm, si);
500 }
501 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700502
Dave Barachba868bb2016-08-08 09:51:21 -0400503done:
Ole Troand7231612018-06-07 10:17:57 +0200504 vec_free (sorted_sis);
505 return error;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700506}
507
508VLIB_CLI_COMMAND (show_sw_interfaces_command, static) = {
Dave Barach13ad1f02017-03-26 19:36:18 -0400509 .path = "show interface",
Mohsin Kazmi88d94142023-01-26 15:14:17 +0000510 .short_help = "show interface [address|addr|features|feat|vtr|tag] "
511 "[<interface> [<interface> [..]]] [verbose]",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700512 .function = show_sw_interfaces,
Steven Luongc5fa2b82019-04-25 11:19:49 -0700513 .is_mp_safe = 1,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700514};
515
516/* Root of all interface commands. */
517VLIB_CLI_COMMAND (vnet_cli_interface_command, static) = {
518 .path = "interface",
519 .short_help = "Interface commands",
520};
521
522VLIB_CLI_COMMAND (vnet_cli_set_interface_command, static) = {
523 .path = "set interface",
524 .short_help = "Interface commands",
525};
526
527static clib_error_t *
528clear_interface_counters (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -0400529 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700530{
Dave Barachba868bb2016-08-08 09:51:21 -0400531 vnet_main_t *vnm = vnet_get_main ();
532 vnet_interface_main_t *im = &vnm->interface_main;
533 vlib_simple_counter_main_t *sm;
534 vlib_combined_counter_main_t *cm;
Dave Barach8fdde3c2019-05-17 10:46:40 -0400535 int j, n_counters;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700536
537 n_counters = vec_len (im->combined_sw_if_counters);
538
539 for (j = 0; j < n_counters; j++)
540 {
Dave Barach8fdde3c2019-05-17 10:46:40 -0400541 im = &vnm->interface_main;
542 cm = im->combined_sw_if_counters + j;
543 vlib_clear_combined_counters (cm);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700544 }
545
546 n_counters = vec_len (im->sw_if_counters);
547
548 for (j = 0; j < n_counters; j++)
549 {
Dave Barach8fdde3c2019-05-17 10:46:40 -0400550 im = &vnm->interface_main;
551 sm = im->sw_if_counters + j;
552 vlib_clear_simple_counters (sm);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700553 }
554
555 return 0;
556}
557
Billy McFalle9bac692017-08-11 14:05:11 -0400558/*?
559 * Clear the statistics for all interfaces (statistics associated with the
560 * '<em>show interface</em>' command).
561 *
562 * @cliexpar
563 * Example of how to clear the statistics for all interfaces:
564 * @cliexcmd{clear interfaces}
565 ?*/
Ed Warnickecb9cada2015-12-08 15:45:58 -0700566VLIB_CLI_COMMAND (clear_interface_counters_command, static) = {
567 .path = "clear interfaces",
Billy McFalle9bac692017-08-11 14:05:11 -0400568 .short_help = "clear interfaces",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700569 .function = clear_interface_counters,
570};
571
Chris Luke16bcf7d2016-09-01 14:31:46 -0400572/**
573 * Parse subinterface names.
574 *
Dave Barachba868bb2016-08-08 09:51:21 -0400575 * The following subinterface syntax is supported. The first two are for
576 * backwards compatability:
577 *
578 * <intf-name> <id>
579 * - a subinterface with the name <intf-name>.<id>. The subinterface
580 * is a single dot1q vlan with vlan id <id> and exact-match semantics.
581 *
582 * <intf-name> <min_id>-<max_id>
583 * - a set of the above subinterfaces, repeating for each id
584 * in the range <min_id> to <max_id>
585 *
586 * In the following, exact-match semantics (i.e. the number of vlan tags on the
587 * packet must match the number of tags in the configuration) are used only if
588 * the keyword exact-match is present. Non-exact match is the default.
589 *
590 * <intf-name> <id> dot1q <outer_id> [exact-match]
591 * - a subinterface with the name <intf-name>.<id>. The subinterface
592 * is a single dot1q vlan with vlan id <outer_id>.
593 *
594 * <intf-name> <id> dot1q any [exact-match]
595 * - a subinterface with the name <intf-name>.<id>. The subinterface
596 * is a single dot1q vlan with any vlan id.
597 *
598 * <intf-name> <id> dot1q <outer_id> inner-dot1q <inner_id> [exact-match]
599 * - a subinterface with the name <intf-name>.<id>. The subinterface
600 * is a double dot1q vlan with outer vlan id <outer_id> and inner vlan id
601 * <inner_id>.
602 *
603 * <intf-name> <id> dot1q <outer_id> inner-dot1q any [exact-match]
604 * - a subinterface with the name <intf-name>.<id>. The subinterface
605 * is a double dot1q vlan with outer vlan id <id> and any inner vlan id.
606 *
607 * <intf-name> <id> dot1q any inner-dot1q any [exact-match]
608 *
609 * - a subinterface with the name <intf-name>.<id>. The subinterface
610 * is a double dot1q vlan with any outer vlan id and any inner vlan id.
611 *
612 * For each of the above CLI, there is a duplicate that uses the keyword
613 * "dot1ad" in place of the first "dot1q". These interfaces use ethertype
614 * 0x88ad in place of 0x8100 for the outer ethertype. Note that for double-
615 * tagged packets the inner ethertype is always 0x8100. Also note that
616 * the dot1q and dot1ad naming spaces are independent, so it is legal to
617 * have both "Gig3/0/0.1 dot1q 100" and "Gig3/0/0.2 dot1ad 100". For example:
618 *
619 * <intf-name> <id> dot1ad <outer_id> inner-dot1q <inner_id> [exact-match]
620 * - a subinterface with the name <intf-name>.<id>. The subinterface
621 * is a double dot1ad vlan with outer vlan id <outer_id> and inner vlan
622 * id <inner_id>.
623 *
624 * <intf-name> <id> untagged
625 * - a subinterface with the name <intf-name>.<id>. The subinterface
626 * has no vlan tags. Only one can be specified per interface.
627 *
628 * <intf-name> <id> default
629 * - a subinterface with the name <intf-name>.<id>. This is associated
630 * with a packet that did not match any other configured subinterface
631 * on this interface. Only one can be specified per interface.
632 */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700633
634static clib_error_t *
Dave Barachba868bb2016-08-08 09:51:21 -0400635parse_vlan_sub_interfaces (unformat_input_t * input,
636 vnet_sw_interface_t * template)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700637{
Dave Barachba868bb2016-08-08 09:51:21 -0400638 clib_error_t *error = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700639 u32 inner_vlan, outer_vlan;
640
Dave Barachba868bb2016-08-08 09:51:21 -0400641 if (unformat (input, "any inner-dot1q any"))
642 {
643 template->sub.eth.flags.two_tags = 1;
644 template->sub.eth.flags.outer_vlan_id_any = 1;
645 template->sub.eth.flags.inner_vlan_id_any = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700646 }
Dave Barachba868bb2016-08-08 09:51:21 -0400647 else if (unformat (input, "any"))
648 {
649 template->sub.eth.flags.one_tag = 1;
650 template->sub.eth.flags.outer_vlan_id_any = 1;
651 }
652 else if (unformat (input, "%d inner-dot1q any", &outer_vlan))
653 {
654 template->sub.eth.flags.two_tags = 1;
655 template->sub.eth.flags.inner_vlan_id_any = 1;
656 template->sub.eth.outer_vlan_id = outer_vlan;
657 }
658 else if (unformat (input, "%d inner-dot1q %d", &outer_vlan, &inner_vlan))
659 {
660 template->sub.eth.flags.two_tags = 1;
661 template->sub.eth.outer_vlan_id = outer_vlan;
662 template->sub.eth.inner_vlan_id = inner_vlan;
663 }
664 else if (unformat (input, "%d", &outer_vlan))
665 {
666 template->sub.eth.flags.one_tag = 1;
667 template->sub.eth.outer_vlan_id = outer_vlan;
668 }
669 else
670 {
671 error = clib_error_return (0, "expected dot1q config, got `%U'",
672 format_unformat_error, input);
673 goto done;
674 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700675
Dave Barachba868bb2016-08-08 09:51:21 -0400676 if (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
677 {
678 if (unformat (input, "exact-match"))
679 {
680 template->sub.eth.flags.exact_match = 1;
681 }
682 }
683
684done:
Ed Warnickecb9cada2015-12-08 15:45:58 -0700685 return error;
686}
687
688static clib_error_t *
689create_sub_interfaces (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -0400690 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700691{
Dave Barachba868bb2016-08-08 09:51:21 -0400692 vnet_main_t *vnm = vnet_get_main ();
693 clib_error_t *error = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700694 u32 hw_if_index, sw_if_index;
Dave Barachba868bb2016-08-08 09:51:21 -0400695 vnet_hw_interface_t *hi;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700696 u32 id, id_min, id_max;
697 vnet_sw_interface_t template;
698
699 hw_if_index = ~0;
Dave Barachba868bb2016-08-08 09:51:21 -0400700 if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700701 {
702 error = clib_error_return (0, "unknown interface `%U'",
703 format_unformat_error, input);
704 goto done;
705 }
706
Dave Barachb7b92992018-10-17 10:38:51 -0400707 clib_memset (&template, 0, sizeof (template));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700708 template.sub.eth.raw_flags = 0;
709
Dave Barachba868bb2016-08-08 09:51:21 -0400710 if (unformat (input, "%d default", &id_min))
711 {
712 id_max = id_min;
713 template.sub.eth.flags.default_sub = 1;
714 }
715 else if (unformat (input, "%d untagged", &id_min))
716 {
717 id_max = id_min;
718 template.sub.eth.flags.no_tags = 1;
719 template.sub.eth.flags.exact_match = 1;
720 }
721 else if (unformat (input, "%d dot1q", &id_min))
722 {
723 /* parse dot1q config */
724 id_max = id_min;
725 error = parse_vlan_sub_interfaces (input, &template);
726 if (error)
727 goto done;
728 }
729 else if (unformat (input, "%d dot1ad", &id_min))
730 {
731 /* parse dot1ad config */
732 id_max = id_min;
733 template.sub.eth.flags.dot1ad = 1;
734 error = parse_vlan_sub_interfaces (input, &template);
735 if (error)
736 goto done;
737 }
738 else if (unformat (input, "%d-%d", &id_min, &id_max))
739 {
740 template.sub.eth.flags.one_tag = 1;
Dave Barachba868bb2016-08-08 09:51:21 -0400741 template.sub.eth.flags.exact_match = 1;
742 if (id_min > id_max)
743 goto id_error;
744 }
745 else if (unformat (input, "%d", &id_min))
746 {
747 id_max = id_min;
748 template.sub.eth.flags.one_tag = 1;
749 template.sub.eth.outer_vlan_id = id_min;
750 template.sub.eth.flags.exact_match = 1;
751 }
752 else
753 {
Ed Warnickecb9cada2015-12-08 15:45:58 -0700754 id_error:
755 error = clib_error_return (0, "expected ID or ID MIN-MAX, got `%U'",
756 format_unformat_error, input);
757 goto done;
Dave Barachba868bb2016-08-08 09:51:21 -0400758 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700759
760 hi = vnet_get_hw_interface (vnm, hw_if_index);
John Lobcebbb92016-04-05 15:47:43 -0400761
Dave Barachba868bb2016-08-08 09:51:21 -0400762 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE)
763 {
764 error =
765 clib_error_return (0,
766 "not allowed as %v belong to a BondEthernet interface",
767 hi->name);
768 goto done;
769 }
John Lobcebbb92016-04-05 15:47:43 -0400770
Ed Warnickecb9cada2015-12-08 15:45:58 -0700771 for (id = id_min; id <= id_max; id++)
772 {
Dave Barachba868bb2016-08-08 09:51:21 -0400773 uword *p;
774 vnet_interface_main_t *im = &vnm->interface_main;
775 u64 sup_and_sub_key = ((u64) (hi->sw_if_index) << 32) | (u64) id;
776 u64 *kp;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700777
778 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
779 if (p)
Dave Barachba868bb2016-08-08 09:51:21 -0400780 {
781 if (CLIB_DEBUG > 0)
782 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
783 hi->sw_if_index, id);
784 continue;
785 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700786
Ed Warnickecb9cada2015-12-08 15:45:58 -0700787 template.type = VNET_SW_INTERFACE_TYPE_SUB;
Eyal Baric5b13602016-11-24 19:42:43 +0200788 template.flood_class = VNET_FLOOD_CLASS_NORMAL;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700789 template.sup_sw_if_index = hi->sw_if_index;
790 template.sub.id = id;
Eyal Baria4509cf2016-09-26 09:24:09 +0300791 if (id_min < id_max)
792 template.sub.eth.outer_vlan_id = id;
793
Ed Warnickecb9cada2015-12-08 15:45:58 -0700794 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
Dave Barachba868bb2016-08-08 09:51:21 -0400795 if (error)
796 goto done;
Dave Barach16ad6ae2016-07-28 17:55:30 -0400797
Jon Loeligerb22e1f02019-12-19 09:03:52 -0600798 kp = clib_mem_alloc (sizeof (*kp));
799 *kp = sup_and_sub_key;
800
Ed Warnickecb9cada2015-12-08 15:45:58 -0700801 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
802 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
Dave Barachba868bb2016-08-08 09:51:21 -0400803 vlib_cli_output (vm, "%U\n", format_vnet_sw_if_index_name,
804 vnet_get_main (), sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700805 }
806
Dave Barachba868bb2016-08-08 09:51:21 -0400807done:
Ed Warnickecb9cada2015-12-08 15:45:58 -0700808 return error;
809}
810
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700811/*?
Billy McFalle9bac692017-08-11 14:05:11 -0400812 * This command is used to add VLAN IDs to interfaces, also known as subinterfaces.
813 * The primary input to this command is the '<em>interface</em>' and '<em>subId</em>'
814 * (subinterface Id) parameters. If no additional VLAN ID is provide, the VLAN ID is
815 * assumed to be the '<em>subId</em>'. The VLAN ID and '<em>subId</em>' can be different,
816 * but this is not recommended.
817 *
818 * This command has several variations:
819 * - <b>create sub-interfaces <interface> <subId></b> - Create a subinterface to
820 * process packets with a given 802.1q VLAN ID (same value as the '<em>subId</em>').
821 *
822 * - <b>create sub-interfaces <interface> <subId> default</b> - Adding the
823 * '<em>default</em>' parameter indicates that packets with VLAN IDs that do not
824 * match any other subinterfaces should be sent to this subinterface.
825 *
826 * - <b>create sub-interfaces <interface> <subId> untagged</b> - Adding the
827 * '<em>untagged</em>' parameter indicates that packets no VLAN IDs should be sent
828 * to this subinterface.
829 *
830 * - <b>create sub-interfaces <interface> <subId>-<subId></b> - Create a range of
831 * subinterfaces to handle a range of VLAN IDs.
832 *
833 * - <b>create sub-interfaces <interface> <subId> dot1q|dot1ad <vlanId>|any [exact-match]</b> -
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -0700834 * Use this command to specify the outer VLAN ID, to either be explicit or to make the
Billy McFalle9bac692017-08-11 14:05:11 -0400835 * VLAN ID different from the '<em>subId</em>'.
836 *
837 * - <b>create sub-interfaces <interface> <subId> dot1q|dot1ad <vlanId>|any inner-dot1q
838 * <vlanId>|any [exact-match]</b> - Use this command to specify the outer VLAN ID and
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -0700839 * the inner VLAN ID.
Billy McFalle9bac692017-08-11 14:05:11 -0400840 *
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -0700841 * When '<em>dot1q</em>' or '<em>dot1ad</em>' is explicitly entered, subinterfaces
Billy McFalle9bac692017-08-11 14:05:11 -0400842 * can be configured as either exact-match or non-exact match. Non-exact match is the CLI
843 * default. If '<em>exact-match</em>' is specified, packets must have the same number of
844 * VLAN tags as the configuration. For non-exact-match, packets must at least that number
845 * of tags. L3 (routed) interfaces must be configured as exact-match. L2 interfaces are
846 * typically configured as non-exact-match. If '<em>dot1q</em>' or '<em>dot1ad</em>' is NOT
847 * entered, then the default behavior is exact-match.
848 *
849 * Use the '<em>show interface</em>' command to display all subinterfaces.
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700850 *
851 * @cliexpar
Billy McFalle9bac692017-08-11 14:05:11 -0400852 * @parblock
853 * Example of how to create a VLAN subinterface 11 to process packets on 802.1q VLAN ID 11:
854 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11}
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700855 *
Billy McFalle9bac692017-08-11 14:05:11 -0400856 * The previous example is shorthand and is equivalent to:
857 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11 dot1q 11 exact-match}
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700858 *
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700859 *
Billy McFalle9bac692017-08-11 14:05:11 -0400860 * Example of how to create a subinterface number that is different from the VLAN ID:
861 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11 dot1q 100}
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700862 *
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700863 *
Billy McFalle9bac692017-08-11 14:05:11 -0400864 * Examples of how to create q-in-q and q-in-any subinterfaces:
865 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11 dot1q 100 inner-dot1q 200}
866 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 12 dot1q 100 inner-dot1q any}
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700867 *
Billy McFalle9bac692017-08-11 14:05:11 -0400868 * Examples of how to create dot1ad interfaces:
869 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11 dot1ad 11}
870 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 12 dot1ad 100 inner-dot1q 200}
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700871 *
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700872 *
Billy McFalle9bac692017-08-11 14:05:11 -0400873 * Examples of '<em>exact-match</em>' versus non-exact match. A packet with
874 * outer VLAN 100 and inner VLAN 200 would match this interface, because the default
875 * is non-exact match:
876 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 5 dot1q 100}
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700877 *
Billy McFalle9bac692017-08-11 14:05:11 -0400878 * However, the same packet would NOT match this interface because '<em>exact-match</em>'
879 * is specified and only one VLAN is configured, but packet contains two VLANs:
880 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 5 dot1q 100 exact-match}
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700881 *
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700882 *
Billy McFalle9bac692017-08-11 14:05:11 -0400883 * Example of how to created a subinterface to process untagged packets:
884 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 5 untagged}
885 *
886 * Example of how to created a subinterface to process any packet with a VLAN ID that
887 * does not match any other subinterface:
888 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 7 default}
889 *
890 * When subinterfaces are created, they are in the down state. Example of how to
891 * enable a newly created subinterface:
892 * @cliexcmd{set interface GigabitEthernet2/0/0.7 up}
893 * @endparblock
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700894 ?*/
Ed Warnickecb9cada2015-12-08 15:45:58 -0700895VLIB_CLI_COMMAND (create_sub_interfaces_command, static) = {
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700896 .path = "create sub-interfaces",
Billy McFalle9bac692017-08-11 14:05:11 -0400897 .short_help = "create sub-interfaces <interface> "
898 "{<subId> [default|untagged]} | "
899 "{<subId>-<subId>} | "
900 "{<subId> dot1q|dot1ad <vlanId>|any [inner-dot1q <vlanId>|any] [exact-match]}",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700901 .function = create_sub_interfaces,
902};
903
904static clib_error_t *
905set_state (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -0400906 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700907{
Dave Barachba868bb2016-08-08 09:51:21 -0400908 vnet_main_t *vnm = vnet_get_main ();
909 clib_error_t *error;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700910 u32 sw_if_index, flags;
911
912 sw_if_index = ~0;
Dave Barachba868bb2016-08-08 09:51:21 -0400913 if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700914 {
915 error = clib_error_return (0, "unknown interface `%U'",
916 format_unformat_error, input);
917 goto done;
918 }
919
Dave Barachba868bb2016-08-08 09:51:21 -0400920 if (!unformat (input, "%U", unformat_vnet_sw_interface_flags, &flags))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700921 {
922 error = clib_error_return (0, "unknown flags `%U'",
923 format_unformat_error, input);
924 goto done;
925 }
926
927 error = vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
928 if (error)
929 goto done;
930
Dave Barachba868bb2016-08-08 09:51:21 -0400931done:
Ed Warnickecb9cada2015-12-08 15:45:58 -0700932 return error;
933}
934
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700935/*?
Billy McFalle9bac692017-08-11 14:05:11 -0400936 * This command is used to change the admin state (up/down) of an interface.
937 *
938 * If an interface is down, the optional '<em>punt</em>' flag can also be set.
939 * The '<em>punt</em>' flag implies the interface is disabled for forwarding
940 * but punt all traffic to slow-path. Use the '<em>enable</em>' flag to clear
941 * '<em>punt</em>' flag (interface is still down).
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700942 *
943 * @cliexpar
Nathan Skrzypczak2c77ae42021-09-29 15:36:51 +0200944 * Example of how to configure the admin state of an interface to
945 '<em>up</em>':
Billy McFalle9bac692017-08-11 14:05:11 -0400946 * @cliexcmd{set interface state GigabitEthernet2/0/0 up}
Nathan Skrzypczak2c77ae42021-09-29 15:36:51 +0200947 * Example of how to configure the admin state of an interface to
948 '<em>down</em>':
Billy McFalle9bac692017-08-11 14:05:11 -0400949 * @cliexcmd{set interface state GigabitEthernet2/0/0 down}
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700950 ?*/
Ed Warnickecb9cada2015-12-08 15:45:58 -0700951VLIB_CLI_COMMAND (set_state_command, static) = {
952 .path = "set interface state",
Billy McFalle9bac692017-08-11 14:05:11 -0400953 .short_help = "set interface state <interface> [up|down|punt|enable]",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700954 .function = set_state,
955};
956
957static clib_error_t *
958set_unnumbered (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -0400959 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700960{
Dave Barachba868bb2016-08-08 09:51:21 -0400961 vnet_main_t *vnm = vnet_get_main ();
Neale Ranns2ae2bc52018-03-16 03:22:39 -0700962 u32 unnumbered_sw_if_index = ~0;
963 u32 inherit_from_sw_if_index = ~0;
964 int enable = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700965
Igor Mikhailov (imichail)ab3e42b2016-09-25 15:11:53 -0700966 if (unformat (input, "%U use %U",
967 unformat_vnet_sw_interface, vnm, &unnumbered_sw_if_index,
968 unformat_vnet_sw_interface, vnm, &inherit_from_sw_if_index))
Neale Ranns2ae2bc52018-03-16 03:22:39 -0700969 enable = 1;
Igor Mikhailov (imichail)ab3e42b2016-09-25 15:11:53 -0700970 else if (unformat (input, "del %U",
971 unformat_vnet_sw_interface, vnm,
972 &unnumbered_sw_if_index))
Neale Ranns2ae2bc52018-03-16 03:22:39 -0700973 enable = 0;
Igor Mikhailov (imichail)ab3e42b2016-09-25 15:11:53 -0700974 else
975 return clib_error_return (0, "parse error '%U'",
976 format_unformat_error, input);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700977
Neale Ranns2ae2bc52018-03-16 03:22:39 -0700978 if (~0 == unnumbered_sw_if_index)
979 return clib_error_return (0, "Specify the unnumbered interface");
980 if (enable && ~0 == inherit_from_sw_if_index)
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -0700981 return clib_error_return (0, "When enabling unnumbered specify the"
Neale Ranns2ae2bc52018-03-16 03:22:39 -0700982 " IP enabled interface that it uses");
Neale Ranns898273f2017-03-18 02:57:38 -0700983
Stanislav Zaikin328b5da2021-07-15 16:27:29 +0200984 int rv = vnet_sw_interface_update_unnumbered (
985 unnumbered_sw_if_index, inherit_from_sw_if_index, enable);
986
987 switch (rv)
988 {
989 case 0:
990 break;
991
992 case VNET_API_ERROR_UNEXPECTED_INTF_STATE:
993 return clib_error_return (
994 0,
995 "When enabling unnumbered both interfaces must be in the same tables");
996
997 default:
998 return clib_error_return (
999 0, "vnet_sw_interface_update_unnumbered returned %d", rv);
1000 }
Neale Ranns898273f2017-03-18 02:57:38 -07001001
Neale Ranns2ae2bc52018-03-16 03:22:39 -07001002 return (NULL);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001003}
1004
1005VLIB_CLI_COMMAND (set_unnumbered_command, static) = {
1006 .path = "set interface unnumbered",
Billy McFalle9bac692017-08-11 14:05:11 -04001007 .short_help = "set interface unnumbered [<interface> use <interface> | del <interface>]",
Ed Warnickecb9cada2015-12-08 15:45:58 -07001008 .function = set_unnumbered,
1009};
1010
1011
1012
1013static clib_error_t *
1014set_hw_class (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -04001015 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001016{
Dave Barachba868bb2016-08-08 09:51:21 -04001017 vnet_main_t *vnm = vnet_get_main ();
1018 vnet_interface_main_t *im = &vnm->interface_main;
1019 clib_error_t *error;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001020 u32 hw_if_index, hw_class_index;
1021
1022 hw_if_index = ~0;
Dave Barachba868bb2016-08-08 09:51:21 -04001023 if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
Ed Warnickecb9cada2015-12-08 15:45:58 -07001024 {
1025 error = clib_error_return (0, "unknown hardware interface `%U'",
1026 format_unformat_error, input);
1027 goto done;
1028 }
1029
Dave Barachba868bb2016-08-08 09:51:21 -04001030 if (!unformat_user (input, unformat_hash_string,
1031 im->hw_interface_class_by_name, &hw_class_index))
Ed Warnickecb9cada2015-12-08 15:45:58 -07001032 {
1033 error = clib_error_return (0, "unknown hardware class `%U'",
1034 format_unformat_error, input);
1035 goto done;
1036 }
1037
1038 error = vnet_hw_interface_set_class (vnm, hw_if_index, hw_class_index);
1039 if (error)
1040 goto done;
1041
Dave Barachba868bb2016-08-08 09:51:21 -04001042done:
Ed Warnickecb9cada2015-12-08 15:45:58 -07001043 return error;
1044}
1045
1046VLIB_CLI_COMMAND (set_hw_class_command, static) = {
1047 .path = "set interface hw-class",
1048 .short_help = "Set interface hardware class",
1049 .function = set_hw_class,
1050};
1051
Dave Barachba868bb2016-08-08 09:51:21 -04001052static clib_error_t *
1053vnet_interface_cli_init (vlib_main_t * vm)
1054{
1055 return 0;
1056}
Ed Warnickecb9cada2015-12-08 15:45:58 -07001057
1058VLIB_INIT_FUNCTION (vnet_interface_cli_init);
1059
Dave Barachba868bb2016-08-08 09:51:21 -04001060static clib_error_t *
Ed Warnickecb9cada2015-12-08 15:45:58 -07001061renumber_interface_command_fn (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -04001062 unformat_input_t * input,
1063 vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001064{
1065 u32 hw_if_index;
1066 u32 new_dev_instance;
Dave Barachba868bb2016-08-08 09:51:21 -04001067 vnet_main_t *vnm = vnet_get_main ();
Ed Warnickecb9cada2015-12-08 15:45:58 -07001068 int rv;
1069
Dave Barachba868bb2016-08-08 09:51:21 -04001070 if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
Ed Warnickecb9cada2015-12-08 15:45:58 -07001071 return clib_error_return (0, "unknown hardware interface `%U'",
Dave Barachba868bb2016-08-08 09:51:21 -04001072 format_unformat_error, input);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001073
Dave Barachba868bb2016-08-08 09:51:21 -04001074 if (!unformat (input, "%d", &new_dev_instance))
Ed Warnickecb9cada2015-12-08 15:45:58 -07001075 return clib_error_return (0, "new dev instance missing");
1076
1077 rv = vnet_interface_name_renumber (hw_if_index, new_dev_instance);
1078
1079 switch (rv)
1080 {
1081 case 0:
1082 break;
1083
1084 default:
1085 return clib_error_return (0, "vnet_interface_name_renumber returned %d",
Dave Barachba868bb2016-08-08 09:51:21 -04001086 rv);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001087
1088 }
1089
1090 return 0;
1091}
1092
1093
1094VLIB_CLI_COMMAND (renumber_interface_command, static) = {
1095 .path = "renumber interface",
Billy McFalle9bac692017-08-11 14:05:11 -04001096 .short_help = "renumber interface <interface> <new-dev-instance>",
Ed Warnickecb9cada2015-12-08 15:45:58 -07001097 .function = renumber_interface_command_fn,
1098};
1099
Damjan Marion8358ff92016-04-15 14:26:00 +02001100static clib_error_t *
1101promiscuous_cmd (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -04001102 unformat_input_t * input, vlib_cli_command_t * cmd)
Damjan Marion8358ff92016-04-15 14:26:00 +02001103{
Dave Barachba868bb2016-08-08 09:51:21 -04001104 vnet_main_t *vnm = vnet_get_main ();
Damjan Marion8358ff92016-04-15 14:26:00 +02001105 u32 hw_if_index;
1106 u32 flags = ETHERNET_INTERFACE_FLAG_ACCEPT_ALL;
Dave Barachba868bb2016-08-08 09:51:21 -04001107 ethernet_main_t *em = &ethernet_main;
1108 ethernet_interface_t *eif;
Damjan Marion8358ff92016-04-15 14:26:00 +02001109
1110 if (unformat (input, "on %U",
Dave Barachba868bb2016-08-08 09:51:21 -04001111 unformat_vnet_hw_interface, vnm, &hw_if_index))
Damjan Marion8358ff92016-04-15 14:26:00 +02001112 ;
1113 else if (unformat (input, "off %U",
Dave Barachba868bb2016-08-08 09:51:21 -04001114 unformat_ethernet_interface, vnm, &hw_if_index))
Damjan Marion8358ff92016-04-15 14:26:00 +02001115 flags = 0;
1116 else
1117 return clib_error_return (0, "unknown input `%U'",
Dave Barachba868bb2016-08-08 09:51:21 -04001118 format_unformat_error, input);
Damjan Marion8358ff92016-04-15 14:26:00 +02001119
1120 eif = ethernet_get_interface (em, hw_if_index);
1121 if (!eif)
1122 return clib_error_return (0, "not supported");
1123
1124 ethernet_set_flags (vnm, hw_if_index, flags);
1125 return 0;
1126}
1127
1128VLIB_CLI_COMMAND (set_interface_promiscuous_cmd, static) = {
1129 .path = "set interface promiscuous",
Billy McFalle9bac692017-08-11 14:05:11 -04001130 .short_help = "set interface promiscuous [on|off] <interface>",
Damjan Marion8358ff92016-04-15 14:26:00 +02001131 .function = promiscuous_cmd,
1132};
1133
1134static clib_error_t *
1135mtu_cmd (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd)
1136{
Dave Barachba868bb2016-08-08 09:51:21 -04001137 vnet_main_t *vnm = vnet_get_main ();
Ole Troand7231612018-06-07 10:17:57 +02001138 u32 hw_if_index, sw_if_index, mtu;
Damjan Marionfe7d4a22018-04-13 19:43:39 +02001139 ethernet_main_t *em = &ethernet_main;
Ole Troand7231612018-06-07 10:17:57 +02001140 u32 mtus[VNET_N_MTU] = { 0, 0, 0, 0 };
Damjan Marion81bb6fc2022-01-16 22:47:55 +01001141 clib_error_t *err;
Damjan Marion8358ff92016-04-15 14:26:00 +02001142
Damjan Marionfe7d4a22018-04-13 19:43:39 +02001143 if (unformat (input, "%d %U", &mtu,
1144 unformat_vnet_hw_interface, vnm, &hw_if_index))
Damjan Marion8358ff92016-04-15 14:26:00 +02001145 {
Ole Troand7231612018-06-07 10:17:57 +02001146 /*
1147 * Change physical MTU on interface. Only supported for Ethernet
1148 * interfaces
1149 */
Damjan Marionfe7d4a22018-04-13 19:43:39 +02001150 ethernet_interface_t *eif = ethernet_get_interface (em, hw_if_index);
1151
1152 if (!eif)
1153 return clib_error_return (0, "not supported");
1154
Damjan Marion81bb6fc2022-01-16 22:47:55 +01001155 err = vnet_hw_interface_set_mtu (vnm, hw_if_index, mtu);
1156 if (err)
1157 return err;
Ole Troand7231612018-06-07 10:17:57 +02001158 goto done;
Damjan Marion8358ff92016-04-15 14:26:00 +02001159 }
Ole Troand7231612018-06-07 10:17:57 +02001160 else if (unformat (input, "packet %d %U", &mtu,
1161 unformat_vnet_sw_interface, vnm, &sw_if_index))
1162 /* Set default packet MTU (including L3 header */
1163 mtus[VNET_MTU_L3] = mtu;
1164 else if (unformat (input, "ip4 %d %U", &mtu,
1165 unformat_vnet_sw_interface, vnm, &sw_if_index))
1166 mtus[VNET_MTU_IP4] = mtu;
1167 else if (unformat (input, "ip6 %d %U", &mtu,
1168 unformat_vnet_sw_interface, vnm, &sw_if_index))
1169 mtus[VNET_MTU_IP6] = mtu;
1170 else if (unformat (input, "mpls %d %U", &mtu,
1171 unformat_vnet_sw_interface, vnm, &sw_if_index))
1172 mtus[VNET_MTU_MPLS] = mtu;
Damjan Marion8358ff92016-04-15 14:26:00 +02001173 else
Damjan Marionfe7d4a22018-04-13 19:43:39 +02001174 return clib_error_return (0, "unknown input `%U'",
1175 format_unformat_error, input);
Ole Troand7231612018-06-07 10:17:57 +02001176
1177 vnet_sw_interface_set_protocol_mtu (vnm, sw_if_index, mtus);
1178
1179done:
Damjan Marion8358ff92016-04-15 14:26:00 +02001180 return 0;
1181}
1182
1183VLIB_CLI_COMMAND (set_interface_mtu_cmd, static) = {
1184 .path = "set interface mtu",
Ole Troand7231612018-06-07 10:17:57 +02001185 .short_help = "set interface mtu [packet|ip4|ip6|mpls] <value> <interface>",
Damjan Marion8358ff92016-04-15 14:26:00 +02001186 .function = mtu_cmd,
1187};
1188
Pavel Kotucekc631f2d2016-09-26 10:40:02 +02001189static clib_error_t *
Matthew Smithe0792fd2019-07-12 11:48:24 -05001190show_interface_sec_mac_addr_fn (vlib_main_t * vm, unformat_input_t * input,
1191 vlib_cli_command_t * cmd)
1192{
1193 vnet_main_t *vnm = vnet_get_main ();
1194 vnet_interface_main_t *im = &vnm->interface_main;
1195 ethernet_main_t *em = &ethernet_main;
1196 u32 sw_if_index = ~0;
1197 vnet_sw_interface_t *si, *sorted_sis = 0;
1198
1199 if (unformat (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
1200 {
1201 si = pool_elt_at_index (im->sw_interfaces, sw_if_index);
1202 vec_add1 (sorted_sis, si[0]);
1203 }
1204
1205 /* if an interface name was not passed, get all interfaces */
1206 if (vec_len (sorted_sis) == 0)
1207 {
1208 sorted_sis =
1209 vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
Damjan Marion8bea5892022-04-04 22:40:45 +02001210 vec_set_len (sorted_sis, 0);
Damjan Marionb2c31b62020-12-13 21:47:40 +01001211 pool_foreach (si, im->sw_interfaces)
1212 {
Matthew Smithe0792fd2019-07-12 11:48:24 -05001213 int visible = vnet_swif_is_api_visible (si);
1214 if (visible)
Damjan Marionb2c31b62020-12-13 21:47:40 +01001215 vec_add1 (sorted_sis, si[0]);
1216 }
Matthew Smithe0792fd2019-07-12 11:48:24 -05001217 /* Sort by name. */
1218 vec_sort_with_function (sorted_sis, sw_interface_name_compare);
1219 }
1220
1221 vec_foreach (si, sorted_sis)
1222 {
1223 vnet_sw_interface_t *sup_si;
1224 ethernet_interface_t *ei;
1225
1226 sup_si = vnet_get_sup_sw_interface (vnm, si->sw_if_index);
1227 ei = ethernet_get_interface (em, sup_si->hw_if_index);
1228
1229 vlib_cli_output (vm, "%U (%s):",
1230 format_vnet_sw_if_index_name, vnm, si->sw_if_index,
1231 (si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
1232 "up" : "dn");
1233
1234 if (ei && ei->secondary_addrs)
1235 {
Benoît Ganneb44c77d2020-10-20 16:24:17 +02001236 ethernet_interface_address_t *sec_addr;
Matthew Smithe0792fd2019-07-12 11:48:24 -05001237
1238 vec_foreach (sec_addr, ei->secondary_addrs)
1239 {
Benoît Ganneb44c77d2020-10-20 16:24:17 +02001240 vlib_cli_output (vm, " %U", format_mac_address_t, &sec_addr->mac);
Matthew Smithe0792fd2019-07-12 11:48:24 -05001241 }
1242 }
1243 }
1244
1245 vec_free (sorted_sis);
1246 return 0;
1247}
1248
1249/*?
1250 * This command is used to display interface secondary mac addresses.
1251 *
1252 * @cliexpar
1253 * Example of how to display interface secondary mac addresses:
1254 * @cliexstart{show interface secondary-mac-address}
1255 * @cliexend
1256?*/
Matthew Smithe0792fd2019-07-12 11:48:24 -05001257VLIB_CLI_COMMAND (show_interface_sec_mac_addr, static) = {
1258 .path = "show interface secondary-mac-address",
1259 .short_help = "show interface secondary-mac-address [<interface>]",
1260 .function = show_interface_sec_mac_addr_fn,
1261};
Matthew Smithe0792fd2019-07-12 11:48:24 -05001262
1263static clib_error_t *
1264interface_add_del_mac_address (vlib_main_t * vm, unformat_input_t * input,
1265 vlib_cli_command_t * cmd)
1266{
1267 vnet_main_t *vnm = vnet_get_main ();
1268 vnet_sw_interface_t *si = NULL;
1269 clib_error_t *error = 0;
1270 u32 sw_if_index = ~0;
1271 u8 mac[6] = { 0 };
1272 u8 is_add, is_del;
1273
1274 is_add = is_del = 0;
1275
1276 if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
1277 {
1278 error = clib_error_return (0, "unknown interface `%U'",
1279 format_unformat_error, input);
1280 goto done;
1281 }
1282 if (!unformat_user (input, unformat_ethernet_address, mac))
1283 {
1284 error = clib_error_return (0, "expected mac address `%U'",
1285 format_unformat_error, input);
1286 goto done;
1287 }
1288
1289 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1290 {
1291 if (unformat (input, "add"))
1292 is_add = 1;
1293 else if (unformat (input, "del"))
1294 is_del = 1;
1295 else
1296 break;
1297 }
1298
1299 if (is_add == is_del)
1300 {
1301 error = clib_error_return (0, "must choose one of add or del");
1302 goto done;
1303 }
1304
1305 si = vnet_get_sw_interface (vnm, sw_if_index);
1306 error =
1307 vnet_hw_interface_add_del_mac_address (vnm, si->hw_if_index, mac, is_add);
1308
1309done:
1310 return error;
1311}
1312
1313/*?
1314 * The '<em>set interface secondary-mac-address </em>' command allows adding
1315 * or deleting extra MAC addresses on a given interface without changing the
1316 * default MAC address. This could allow packets sent to these MAC addresses
1317 * to be received without setting the interface to promiscuous mode.
1318 * Not all interfaces support this operation. The ones that do are mostly
1319 * hardware NICs, though virtio does also.
1320 *
1321 * @cliexpar
1322 * @parblock
1323 * Example of how to add a secondary MAC Address on an interface:
1324 * @cliexcmd{set interface secondary-mac-address GigabitEthernet0/8/0 aa:bb:cc:dd:ee:01 add}
1325 * Example of how to delete a secondary MAC address from an interface:
1326 * @cliexcmd{set interface secondary-mac-address GigabitEthernet0/8/0 aa:bb:cc:dd:ee:01 del}
1327 * @endparblock
1328?*/
Matthew Smithe0792fd2019-07-12 11:48:24 -05001329VLIB_CLI_COMMAND (interface_add_del_mac_address_cmd, static) = {
1330 .path = "set interface secondary-mac-address",
1331 .short_help = "set interface secondary-mac-address <interface> <mac-address> [(add|del)]",
1332 .function = interface_add_del_mac_address,
1333};
Matthew Smithe0792fd2019-07-12 11:48:24 -05001334
1335static clib_error_t *
Pavel Kotucekc631f2d2016-09-26 10:40:02 +02001336set_interface_mac_address (vlib_main_t * vm, unformat_input_t * input,
1337 vlib_cli_command_t * cmd)
1338{
1339 vnet_main_t *vnm = vnet_get_main ();
Neale Rannsd867a7c2017-10-04 02:29:07 -07001340 vnet_sw_interface_t *si = NULL;
Pavel Kotucekc631f2d2016-09-26 10:40:02 +02001341 clib_error_t *error = 0;
1342 u32 sw_if_index = ~0;
John Lo62fcc0a2017-10-31 14:31:10 -04001343 u8 mac[6] = { 0 };
Pavel Kotucekc631f2d2016-09-26 10:40:02 +02001344
1345 if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
1346 {
1347 error = clib_error_return (0, "unknown interface `%U'",
1348 format_unformat_error, input);
1349 goto done;
1350 }
John Lo62fcc0a2017-10-31 14:31:10 -04001351 if (!unformat_user (input, unformat_ethernet_address, mac))
Pavel Kotucekc631f2d2016-09-26 10:40:02 +02001352 {
1353 error = clib_error_return (0, "expected mac address `%U'",
1354 format_unformat_error, input);
1355 goto done;
1356 }
Neale Rannsd867a7c2017-10-04 02:29:07 -07001357 si = vnet_get_sw_interface (vnm, sw_if_index);
1358 error = vnet_hw_interface_change_mac_address (vnm, si->hw_if_index, mac);
Pavel Kotucekc631f2d2016-09-26 10:40:02 +02001359done:
1360 return error;
1361}
1362
1363/*?
1364 * The '<em>set interface mac address </em>' command allows to set MAC address of given interface.
1365 * In case of NIC interfaces the one has to support MAC address change. A side effect of MAC address
1366 * change are changes of MAC addresses in FIB tables (ipv4 and ipv6).
1367 *
1368 * @cliexpar
1369 * @parblock
1370 * Example of how to change MAC Address of interface:
1371 * @cliexcmd{set interface mac address GigabitEthernet0/8/0 aa:bb:cc:dd:ee:01}
1372 * @cliexcmd{set interface mac address host-vpp0 aa:bb:cc:dd:ee:02}
1373 * @cliexcmd{set interface mac address tap-0 aa:bb:cc:dd:ee:03}
1374 * @cliexcmd{set interface mac address pg0 aa:bb:cc:dd:ee:04}
1375 * @endparblock
1376?*/
Pavel Kotucekc631f2d2016-09-26 10:40:02 +02001377VLIB_CLI_COMMAND (set_interface_mac_address_cmd, static) = {
1378 .path = "set interface mac address",
Billy McFalle9bac692017-08-11 14:05:11 -04001379 .short_help = "set interface mac address <interface> <mac-address>",
Pavel Kotucekc631f2d2016-09-26 10:40:02 +02001380 .function = set_interface_mac_address,
1381};
Pavel Kotucekc631f2d2016-09-26 10:40:02 +02001382
Dave Barach7be864a2016-11-28 11:41:35 -05001383static clib_error_t *
1384set_tag (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd)
1385{
1386 vnet_main_t *vnm = vnet_get_main ();
1387 u32 sw_if_index = ~0;
1388 u8 *tag = 0;
1389
1390 if (!unformat (input, "%U %s", unformat_vnet_sw_interface,
1391 vnm, &sw_if_index, &tag))
1392 return clib_error_return (0, "unknown input `%U'",
1393 format_unformat_error, input);
1394
1395 vnet_set_sw_interface_tag (vnm, tag, sw_if_index);
1396
1397 return 0;
1398}
1399
Dave Barach7be864a2016-11-28 11:41:35 -05001400VLIB_CLI_COMMAND (set_tag_command, static) = {
1401 .path = "set interface tag",
Billy McFalle9bac692017-08-11 14:05:11 -04001402 .short_help = "set interface tag <interface> <tag>",
Dave Barach7be864a2016-11-28 11:41:35 -05001403 .function = set_tag,
1404};
Dave Barach7be864a2016-11-28 11:41:35 -05001405
1406static clib_error_t *
1407clear_tag (vlib_main_t * vm, unformat_input_t * input,
1408 vlib_cli_command_t * cmd)
1409{
1410 vnet_main_t *vnm = vnet_get_main ();
1411 u32 sw_if_index = ~0;
1412
1413 if (!unformat (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
1414 return clib_error_return (0, "unknown input `%U'",
1415 format_unformat_error, input);
1416
1417 vnet_clear_sw_interface_tag (vnm, sw_if_index);
1418
1419 return 0;
1420}
1421
Dave Barach7be864a2016-11-28 11:41:35 -05001422VLIB_CLI_COMMAND (clear_tag_command, static) = {
1423 .path = "clear interface tag",
Billy McFalle9bac692017-08-11 14:05:11 -04001424 .short_help = "clear interface tag <interface>",
Dave Barach7be864a2016-11-28 11:41:35 -05001425 .function = clear_tag,
1426};
Dave Barach7be864a2016-11-28 11:41:35 -05001427
Damjan Marion44036902017-04-28 12:29:15 +02001428static clib_error_t *
Neale Ranns1855b8e2018-07-11 10:31:26 -07001429set_ip_directed_broadcast (vlib_main_t * vm,
1430 unformat_input_t * input, vlib_cli_command_t * cmd)
1431{
1432 vnet_main_t *vnm = vnet_get_main ();
1433 u32 sw_if_index = ~0;
1434 u8 enable = 0;
1435
1436 if (!unformat (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index));
1437 else if (unformat (input, "enable"))
1438 enable = 1;
1439 else if (unformat (input, "disable"))
1440 enable = 0;
1441 else
1442 return clib_error_return (0, "unknown input: `%U'",
1443 format_unformat_error, input);
1444
1445 if (~0 == sw_if_index)
1446 return clib_error_return (0, "specify an interface: `%U'",
1447 format_unformat_error, input);
1448
1449 vnet_sw_interface_ip_directed_broadcast (vnm, sw_if_index, enable);
1450
1451 return 0;
1452}
1453
1454/*?
1455 * This command is used to enable/disable IP directed broadcast
1456 * If directed broadcast is enabled a packet sent to the interface's
1457 * subnet broadcast address will be sent L2 broadcast on the interface,
1458 * otherwise it is dropped.
1459 ?*/
Neale Ranns1855b8e2018-07-11 10:31:26 -07001460VLIB_CLI_COMMAND (set_ip_directed_broadcast_command, static) = {
1461 .path = "set interface ip directed-broadcast",
1462 .short_help = "set interface enable <interface> <enable|disable>",
1463 .function = set_ip_directed_broadcast,
1464};
Neale Ranns1855b8e2018-07-11 10:31:26 -07001465
Stevenad8015b2017-10-29 22:10:46 -07001466clib_error_t *
1467set_hw_interface_change_rx_mode (vnet_main_t * vnm, u32 hw_if_index,
1468 u8 queue_id_valid, u32 queue_id,
Damjan Marioneabd4242020-10-07 20:59:07 +02001469 vnet_hw_if_rx_mode mode)
Stevenad8015b2017-10-29 22:10:46 -07001470{
1471 clib_error_t *error = 0;
1472 vnet_hw_interface_t *hw;
Damjan Marion94100532020-11-06 23:25:57 +01001473 u32 *queue_indices = 0;
Damjan Marionb8dd9812023-11-03 13:47:05 +00001474 vnet_dev_port_t *port;
1475
1476 port = vnet_dev_get_port_from_hw_if_index (hw_if_index);
1477
1478 if (port)
1479 {
1480 vlib_main_t *vm = vlib_get_main ();
1481 vnet_dev_rv_t rv;
1482
1483 vnet_dev_port_cfg_change_req_t req = {
1484 .type = mode == VNET_HW_IF_RX_MODE_POLLING ?
1485 VNET_DEV_PORT_CFG_RXQ_INTR_MODE_DISABLE :
1486 VNET_DEV_PORT_CFG_RXQ_INTR_MODE_ENABLE,
1487 .queue_id = queue_id_valid ? queue_id : 0,
1488 .all_queues = queue_id_valid ? 0 : 1,
1489 };
1490
1491 if ((rv = vnet_dev_port_cfg_change_req_validate (vm, port, &req)))
1492 return vnet_dev_port_err (
1493 vm, port, rv, "rx queue interupt mode enable/disable not supported");
1494
1495 if ((rv = vnet_dev_process_port_cfg_change_req (vm, port, &req)))
1496 return vnet_dev_port_err (
1497 vm, port, rv,
1498 "device failed to enable/disable queue interrupt mode");
1499 return 0;
1500 }
Stevenad8015b2017-10-29 22:10:46 -07001501
1502 hw = vnet_get_hw_interface (vnm, hw_if_index);
1503
Damjan Marion94100532020-11-06 23:25:57 +01001504 if (queue_id_valid)
1505 {
1506 u32 queue_index;
1507 queue_index =
1508 vnet_hw_if_get_rx_queue_index_by_id (vnm, hw_if_index, queue_id);
1509 if (queue_index == ~0)
1510 return clib_error_return (0, "unknown queue %u on interface %s",
1511 queue_id, hw->name);
1512 vec_add1 (queue_indices, queue_index);
Stevenad8015b2017-10-29 22:10:46 -07001513 }
1514 else
Damjan Marion94100532020-11-06 23:25:57 +01001515 queue_indices = hw->rx_queue_indices;
Stevenad8015b2017-10-29 22:10:46 -07001516
Damjan Marion94100532020-11-06 23:25:57 +01001517 for (int i = 0; i < vec_len (queue_indices); i++)
1518 {
1519 int rv = vnet_hw_if_set_rx_queue_mode (vnm, queue_indices[i], mode);
1520 if (rv)
Wayne Morrison389aae52022-08-05 09:47:24 -04001521 {
1522 error = clib_error_return (
1523 0, "unable to set rx-mode on interface %v queue-id %u.\n",
1524 hw->name, queue_id);
1525 goto done;
1526 }
Damjan Marion94100532020-11-06 23:25:57 +01001527 }
1528
1529done:
1530 if (queue_indices != hw->rx_queue_indices)
1531 vec_free (queue_indices);
1532 vnet_hw_if_update_runtime_data (vnm, hw_if_index);
1533 return error;
Stevenad8015b2017-10-29 22:10:46 -07001534}
1535
Stevene3a395c2017-05-09 16:19:50 -07001536static clib_error_t *
Damjan Marion44036902017-04-28 12:29:15 +02001537set_interface_rx_mode (vlib_main_t * vm, unformat_input_t * input,
1538 vlib_cli_command_t * cmd)
1539{
1540 clib_error_t *error = 0;
1541 unformat_input_t _line_input, *line_input = &_line_input;
1542 vnet_main_t *vnm = vnet_get_main ();
Damjan Marion44036902017-04-28 12:29:15 +02001543 u32 hw_if_index = (u32) ~ 0;
1544 u32 queue_id = (u32) ~ 0;
Damjan Marioneabd4242020-10-07 20:59:07 +02001545 vnet_hw_if_rx_mode mode = VNET_HW_IF_RX_MODE_UNKNOWN;
Stevenad8015b2017-10-29 22:10:46 -07001546 u8 queue_id_valid = 0;
Dave Barach7be864a2016-11-28 11:41:35 -05001547
Damjan Marion44036902017-04-28 12:29:15 +02001548 if (!unformat_user (input, unformat_line_input, line_input))
1549 return 0;
1550
1551 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1552 {
1553 if (unformat
1554 (line_input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
1555 ;
1556 else if (unformat (line_input, "queue %d", &queue_id))
Stevenad8015b2017-10-29 22:10:46 -07001557 queue_id_valid = 1;
Damjan Marion44036902017-04-28 12:29:15 +02001558 else if (unformat (line_input, "polling"))
Damjan Marioneabd4242020-10-07 20:59:07 +02001559 mode = VNET_HW_IF_RX_MODE_POLLING;
Damjan Marion44036902017-04-28 12:29:15 +02001560 else if (unformat (line_input, "interrupt"))
Damjan Marioneabd4242020-10-07 20:59:07 +02001561 mode = VNET_HW_IF_RX_MODE_INTERRUPT;
Damjan Marion44036902017-04-28 12:29:15 +02001562 else if (unformat (line_input, "adaptive"))
Damjan Marioneabd4242020-10-07 20:59:07 +02001563 mode = VNET_HW_IF_RX_MODE_ADAPTIVE;
Damjan Marion44036902017-04-28 12:29:15 +02001564 else
1565 {
1566 error = clib_error_return (0, "parse error: '%U'",
1567 format_unformat_error, line_input);
1568 unformat_free (line_input);
1569 return error;
1570 }
1571 }
1572
1573 unformat_free (line_input);
1574
1575 if (hw_if_index == (u32) ~ 0)
1576 return clib_error_return (0, "please specify valid interface name");
1577
Damjan Marioneabd4242020-10-07 20:59:07 +02001578 if (mode == VNET_HW_IF_RX_MODE_UNKNOWN)
Damjan Marion44036902017-04-28 12:29:15 +02001579 return clib_error_return (0, "please specify valid rx-mode");
1580
Stevenad8015b2017-10-29 22:10:46 -07001581 error = set_hw_interface_change_rx_mode (vnm, hw_if_index, queue_id_valid,
1582 queue_id, mode);
Damjan Marion44036902017-04-28 12:29:15 +02001583
Stevene3a395c2017-05-09 16:19:50 -07001584 return (error);
Damjan Marion44036902017-04-28 12:29:15 +02001585}
1586
1587/*?
Billy McFalle9bac692017-08-11 14:05:11 -04001588 * This command is used to assign the RX packet processing mode (polling,
1589 * interrupt, adaptive) of the a given interface, and optionally a
1590 * given queue. If the '<em>queue</em>' is not provided, the '<em>mode</em>'
1591 * is applied to all queues of the interface. Not all interfaces support
1592 * all modes. To display the current rx-mode use the command
1593 * '<em>show interface rx-placement</em>'.
Damjan Marion44036902017-04-28 12:29:15 +02001594 *
1595 * @cliexpar
Billy McFalle9bac692017-08-11 14:05:11 -04001596 * Example of how to assign rx-mode to all queues on an interface:
1597 * @cliexcmd{set interface rx-mode VirtualEthernet0/0/12 polling}
1598 * Example of how to assign rx-mode to one queue of an interface:
1599 * @cliexcmd{set interface rx-mode VirtualEthernet0/0/12 queue 0 interrupt}
1600 * Example of how to display the rx-mode of all interfaces:
Damjan Marion44036902017-04-28 12:29:15 +02001601 * @cliexstart{show interface rx-placement}
1602 * Thread 1 (vpp_wk_0):
Billy McFalle9bac692017-08-11 14:05:11 -04001603 * node dpdk-input:
1604 * GigabitEthernet7/0/0 queue 0 (polling)
1605 * node vhost-user-input:
1606 * VirtualEthernet0/0/12 queue 0 (interrupt)
1607 * VirtualEthernet0/0/12 queue 2 (polling)
1608 * VirtualEthernet0/0/13 queue 0 (polling)
1609 * VirtualEthernet0/0/13 queue 2 (polling)
Damjan Marion44036902017-04-28 12:29:15 +02001610 * Thread 2 (vpp_wk_1):
Billy McFalle9bac692017-08-11 14:05:11 -04001611 * node dpdk-input:
1612 * GigabitEthernet7/0/1 queue 0 (polling)
1613 * node vhost-user-input:
1614 * VirtualEthernet0/0/12 queue 1 (polling)
1615 * VirtualEthernet0/0/12 queue 3 (polling)
1616 * VirtualEthernet0/0/13 queue 1 (polling)
1617 * VirtualEthernet0/0/13 queue 3 (polling)
Damjan Marion44036902017-04-28 12:29:15 +02001618 * @cliexend
Damjan Marion44036902017-04-28 12:29:15 +02001619?*/
Damjan Marionfe7d4a22018-04-13 19:43:39 +02001620VLIB_CLI_COMMAND (cmd_set_if_rx_mode,static) = {
Damjan Marion44036902017-04-28 12:29:15 +02001621 .path = "set interface rx-mode",
1622 .short_help = "set interface rx-mode <interface> [queue <n>] [polling | interrupt | adaptive]",
1623 .function = set_interface_rx_mode,
1624};
Damjan Marion44036902017-04-28 12:29:15 +02001625
1626static clib_error_t *
1627show_interface_rx_placement_fn (vlib_main_t * vm, unformat_input_t * input,
1628 vlib_cli_command_t * cmd)
1629{
1630 u8 *s = 0;
1631 vnet_main_t *vnm = vnet_get_main ();
Mohammed Hawari9fecbe12020-12-11 19:36:37 +01001632 vnet_hw_if_rx_queue_t **all_queues = 0;
1633 vnet_hw_if_rx_queue_t **qptr;
1634 vnet_hw_if_rx_queue_t *q;
Nathan Skrzypczak455779f2021-02-15 14:48:33 +01001635 pool_foreach (q, vnm->interface_main.hw_if_rx_queues)
Mohammed Hawari9fecbe12020-12-11 19:36:37 +01001636 vec_add1 (all_queues, q);
1637 vec_sort_with_function (all_queues, vnet_hw_if_rxq_cmp_cli_api);
1638 u32 prev_node = ~0;
Damjan Marion44036902017-04-28 12:29:15 +02001639
Mohammed Hawari9fecbe12020-12-11 19:36:37 +01001640 vec_foreach (qptr, all_queues)
1641 {
1642 u32 current_thread = qptr[0]->thread_index;
1643 u32 hw_if_index = qptr[0]->hw_if_index;
1644 vnet_hw_interface_t *hw_if = vnet_get_hw_interface (vnm, hw_if_index);
1645 u32 current_node = hw_if->input_node_index;
1646 if (current_node != prev_node)
1647 s = format (s, " node %U:\n", format_vlib_node_name, vm, current_node);
1648 s = format (s, " %U queue %u (%U)\n", format_vnet_sw_if_index_name,
1649 vnm, hw_if->sw_if_index, qptr[0]->queue_id,
1650 format_vnet_hw_if_rx_mode, qptr[0]->mode);
1651 if (qptr == all_queues + vec_len (all_queues) - 1 ||
1652 current_thread != qptr[1]->thread_index)
1653 {
1654 vlib_cli_output (vm, "Thread %u (%s):\n%v", current_thread,
1655 vlib_worker_threads[current_thread].name, s);
1656 vec_reset_length (s);
1657 }
1658 prev_node = current_node;
1659 }
Damjan Marion44036902017-04-28 12:29:15 +02001660 vec_free (s);
Mohammed Hawari9fecbe12020-12-11 19:36:37 +01001661 vec_free (all_queues);
Damjan Marion44036902017-04-28 12:29:15 +02001662 return 0;
1663}
1664
Billy McFalle9bac692017-08-11 14:05:11 -04001665/*?
1666 * This command is used to display the interface and queue worker
1667 * thread placement.
1668 *
1669 * @cliexpar
1670 * Example of how to display the interface placement:
1671 * @cliexstart{show interface rx-placement}
1672 * Thread 1 (vpp_wk_0):
1673 * node dpdk-input:
1674 * GigabitEthernet7/0/0 queue 0 (polling)
1675 * node vhost-user-input:
1676 * VirtualEthernet0/0/12 queue 0 (polling)
1677 * VirtualEthernet0/0/12 queue 2 (polling)
1678 * VirtualEthernet0/0/13 queue 0 (polling)
1679 * VirtualEthernet0/0/13 queue 2 (polling)
1680 * Thread 2 (vpp_wk_1):
1681 * node dpdk-input:
1682 * GigabitEthernet7/0/1 queue 0 (polling)
1683 * node vhost-user-input:
1684 * VirtualEthernet0/0/12 queue 1 (polling)
1685 * VirtualEthernet0/0/12 queue 3 (polling)
1686 * VirtualEthernet0/0/13 queue 1 (polling)
1687 * VirtualEthernet0/0/13 queue 3 (polling)
1688 * @cliexend
1689?*/
Damjan Marion44036902017-04-28 12:29:15 +02001690VLIB_CLI_COMMAND (show_interface_rx_placement, static) = {
1691 .path = "show interface rx-placement",
1692 .short_help = "show interface rx-placement",
1693 .function = show_interface_rx_placement_fn,
1694};
Mohsin Kazmi54f7c512018-08-23 18:28:11 +02001695clib_error_t *
1696set_hw_interface_rx_placement (u32 hw_if_index, u32 queue_id,
1697 u32 thread_index, u8 is_main)
Damjan Marion44036902017-04-28 12:29:15 +02001698{
Damjan Marion44036902017-04-28 12:29:15 +02001699 vnet_main_t *vnm = vnet_get_main ();
1700 vnet_device_main_t *vdm = &vnet_device_main;
Damjan Marion94100532020-11-06 23:25:57 +01001701 vnet_hw_interface_t *hw;
1702 u32 queue_index;
Damjan Marion44036902017-04-28 12:29:15 +02001703
Mohsin Kazmi54f7c512018-08-23 18:28:11 +02001704 if (is_main)
1705 thread_index = 0;
1706 else
1707 thread_index += vdm->first_worker_thread_index;
Damjan Marion44036902017-04-28 12:29:15 +02001708
1709 if (thread_index > vdm->last_worker_thread_index)
1710 return clib_error_return (0,
1711 "please specify valid worker thread or main");
1712
Damjan Marion94100532020-11-06 23:25:57 +01001713 hw = vnet_get_hw_interface (vnm, hw_if_index);
Damjan Marion44036902017-04-28 12:29:15 +02001714
Damjan Marion94100532020-11-06 23:25:57 +01001715 queue_index =
1716 vnet_hw_if_get_rx_queue_index_by_id (vnm, hw_if_index, queue_id);
1717 if (queue_index == ~0)
1718 return clib_error_return (0, "unknown queue %u on interface %s", queue_id,
1719 hw->name);
1720 vnet_hw_if_set_rx_queue_thread_index (vnm, queue_index, thread_index);
1721 vnet_hw_if_update_runtime_data (vnm, hw_if_index);
1722 return 0;
Mohsin Kazmi54f7c512018-08-23 18:28:11 +02001723}
1724
1725static clib_error_t *
Mohammed Hawari9fecbe12020-12-11 19:36:37 +01001726set_interface_rx_placement (vlib_main_t *vm, unformat_input_t *input,
1727 vlib_cli_command_t *cmd)
Mohsin Kazmi54f7c512018-08-23 18:28:11 +02001728{
1729 clib_error_t *error = 0;
1730 unformat_input_t _line_input, *line_input = &_line_input;
1731 vnet_main_t *vnm = vnet_get_main ();
1732 u32 hw_if_index = (u32) ~ 0;
1733 u32 queue_id = (u32) 0;
1734 u32 thread_index = (u32) ~ 0;
1735 u8 is_main = 0;
1736
1737 if (!unformat_user (input, unformat_line_input, line_input))
1738 return 0;
1739
1740 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1741 {
1742 if (unformat
1743 (line_input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
1744 ;
1745 else if (unformat (line_input, "queue %d", &queue_id))
1746 ;
1747 else if (unformat (line_input, "main", &thread_index))
1748 is_main = 1;
1749 else if (unformat (line_input, "worker %d", &thread_index))
1750 ;
1751 else
1752 {
1753 error = clib_error_return (0, "parse error: '%U'",
1754 format_unformat_error, line_input);
1755 unformat_free (line_input);
1756 return error;
1757 }
1758 }
1759
1760 unformat_free (line_input);
1761
1762 if (hw_if_index == (u32) ~ 0)
1763 return clib_error_return (0, "please specify valid interface name");
1764
1765 error = set_hw_interface_rx_placement (hw_if_index, queue_id, thread_index,
1766 is_main);
1767
1768 return (error);
Damjan Marion44036902017-04-28 12:29:15 +02001769}
1770
1771/*?
1772 * This command is used to assign a given interface, and optionally a
1773 * given queue, to a different thread. If the '<em>queue</em>' is not provided,
Billy McFalle9bac692017-08-11 14:05:11 -04001774 * it defaults to 0. The '<em>worker</em>' parameter is zero based and the index
1775 * in the thread name, for example, 0 in the thread name '<em>vpp_wk_0</em>'.
Damjan Marion44036902017-04-28 12:29:15 +02001776 *
1777 * @cliexpar
1778 * Example of how to display the interface placement:
Billy McFalle9bac692017-08-11 14:05:11 -04001779 * @cliexstart{show interface rx-placement}
Damjan Marion44036902017-04-28 12:29:15 +02001780 * Thread 1 (vpp_wk_0):
Billy McFalle9bac692017-08-11 14:05:11 -04001781 * node dpdk-input:
1782 * GigabitEthernet7/0/0 queue 0 (polling)
1783 * node vhost-user-input:
1784 * VirtualEthernet0/0/12 queue 0 (polling)
1785 * VirtualEthernet0/0/12 queue 2 (polling)
1786 * VirtualEthernet0/0/13 queue 0 (polling)
1787 * VirtualEthernet0/0/13 queue 2 (polling)
Damjan Marion44036902017-04-28 12:29:15 +02001788 * Thread 2 (vpp_wk_1):
Billy McFalle9bac692017-08-11 14:05:11 -04001789 * node dpdk-input:
1790 * GigabitEthernet7/0/1 queue 0 (polling)
1791 * node vhost-user-input:
1792 * VirtualEthernet0/0/12 queue 1 (polling)
1793 * VirtualEthernet0/0/12 queue 3 (polling)
1794 * VirtualEthernet0/0/13 queue 1 (polling)
1795 * VirtualEthernet0/0/13 queue 3 (polling)
Damjan Marion44036902017-04-28 12:29:15 +02001796 * @cliexend
Billy McFalle9bac692017-08-11 14:05:11 -04001797 * Example of how to assign a interface and queue to a worker thread:
1798 * @cliexcmd{set interface rx-placement VirtualEthernet0/0/12 queue 1 worker 0}
1799 * Example of how to display the interface placement:
1800 * @cliexstart{show interface rx-placement}
1801 * Thread 1 (vpp_wk_0):
1802 * node dpdk-input:
1803 * GigabitEthernet7/0/0 queue 0 (polling)
1804 * node vhost-user-input:
1805 * VirtualEthernet0/0/12 queue 0 (polling)
1806 * VirtualEthernet0/0/12 queue 1 (polling)
1807 * VirtualEthernet0/0/12 queue 2 (polling)
1808 * VirtualEthernet0/0/13 queue 0 (polling)
1809 * VirtualEthernet0/0/13 queue 2 (polling)
1810 * Thread 2 (vpp_wk_1):
1811 * node dpdk-input:
1812 * GigabitEthernet7/0/1 queue 0 (polling)
1813 * node vhost-user-input:
1814 * VirtualEthernet0/0/12 queue 3 (polling)
1815 * VirtualEthernet0/0/13 queue 1 (polling)
1816 * VirtualEthernet0/0/13 queue 3 (polling)
1817 * @cliexend
Damjan Marion44036902017-04-28 12:29:15 +02001818?*/
Damjan Marion44036902017-04-28 12:29:15 +02001819VLIB_CLI_COMMAND (cmd_set_if_rx_placement,static) = {
1820 .path = "set interface rx-placement",
Billy McFalle9bac692017-08-11 14:05:11 -04001821 .short_help = "set interface rx-placement <interface> [queue <n>] "
Damjan Marion6f9ac652017-06-15 19:01:31 +02001822 "[worker <n> | main]",
Damjan Marion44036902017-04-28 12:29:15 +02001823 .function = set_interface_rx_placement,
Damjan Marion6f9ac652017-06-15 19:01:31 +02001824 .is_mp_safe = 1,
Damjan Marion44036902017-04-28 12:29:15 +02001825};
Dave Barach5ecd5a52019-02-25 15:27:28 -05001826
Mohsin Kazmi0d05c0d2021-11-09 17:44:10 +00001827int
Mohsin Kazmi005605f2021-05-24 18:33:50 +02001828set_hw_interface_tx_queue (u32 hw_if_index, u32 queue_id, uword *bitmap)
1829{
1830 vnet_main_t *vnm = vnet_get_main ();
Mohsin Kazmi0d05c0d2021-11-09 17:44:10 +00001831 vlib_thread_main_t *vtm = vlib_get_thread_main ();
Mohsin Kazmi005605f2021-05-24 18:33:50 +02001832 vnet_hw_if_tx_queue_t *txq;
1833 u32 queue_index;
1834 u32 thread_index;
1835
Mohsin Kazmi005605f2021-05-24 18:33:50 +02001836 /* highest set bit in bitmap should not exceed last worker thread index */
Steven Luong8e3f1092021-06-17 08:22:50 -07001837 thread_index = clib_bitmap_last_set (bitmap);
Mohsin Kazmi0d05c0d2021-11-09 17:44:10 +00001838 if ((thread_index != ~0) && (thread_index >= vtm->n_vlib_mains))
1839 return VNET_API_ERROR_INVALID_VALUE;
Mohsin Kazmi005605f2021-05-24 18:33:50 +02001840
1841 queue_index =
1842 vnet_hw_if_get_tx_queue_index_by_id (vnm, hw_if_index, queue_id);
1843 if (queue_index == ~0)
Mohsin Kazmi0d05c0d2021-11-09 17:44:10 +00001844 return VNET_API_ERROR_INVALID_QUEUE;
Mohsin Kazmi005605f2021-05-24 18:33:50 +02001845
1846 txq = vnet_hw_if_get_tx_queue (vnm, queue_index);
1847
1848 // free the existing bitmap
1849 if (clib_bitmap_count_set_bits (txq->threads))
1850 {
1851 txq->shared_queue = 0;
1852 clib_bitmap_free (txq->threads);
1853 }
1854
1855 clib_bitmap_foreach (thread_index, bitmap)
1856 vnet_hw_if_tx_queue_assign_thread (vnm, queue_index, thread_index);
1857
1858 vnet_hw_if_update_runtime_data (vnm, hw_if_index);
1859 return 0;
1860}
1861
1862static clib_error_t *
1863set_interface_tx_queue (vlib_main_t *vm, unformat_input_t *input,
1864 vlib_cli_command_t *cmd)
1865{
1866 clib_error_t *error = 0;
1867 unformat_input_t _line_input, *line_input = &_line_input;
1868 vnet_main_t *vnm = vnet_get_main ();
1869 u32 hw_if_index = (u32) ~0;
1870 u32 queue_id = (u32) 0;
1871 uword *bitmap = 0;
Mohsin Kazmi0d05c0d2021-11-09 17:44:10 +00001872 int rv = 0;
Mohsin Kazmi005605f2021-05-24 18:33:50 +02001873
1874 if (!unformat_user (input, unformat_line_input, line_input))
1875 return 0;
1876
1877 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1878 {
1879 if (unformat (line_input, "%U", unformat_vnet_hw_interface, vnm,
1880 &hw_if_index))
1881 ;
1882 else if (unformat (line_input, "queue %d", &queue_id))
1883 ;
1884 else if (unformat (line_input, "threads %U", unformat_bitmap_list,
1885 &bitmap))
1886 ;
1887 else
1888 {
1889 error = clib_error_return (0, "parse error: '%U'",
1890 format_unformat_error, line_input);
1891 unformat_free (line_input);
1892 return error;
1893 }
1894 }
1895
1896 unformat_free (line_input);
1897
1898 if (hw_if_index == (u32) ~0)
1899 {
1900 error = clib_error_return (0, "please specify valid interface name");
1901 goto error;
1902 }
1903
Mohsin Kazmi0d05c0d2021-11-09 17:44:10 +00001904 rv = set_hw_interface_tx_queue (hw_if_index, queue_id, bitmap);
1905
1906 switch (rv)
1907 {
1908 case VNET_API_ERROR_INVALID_VALUE:
1909 error = clib_error_return (
1910 0, "please specify valid thread(s) - last thread index %u",
1911 clib_bitmap_last_set (bitmap));
1912 break;
1913 case VNET_API_ERROR_INVALID_QUEUE:
1914 error = clib_error_return (
1915 0, "unknown queue %u on interface %s", queue_id,
1916 vnet_get_hw_interface (vnet_get_main (), hw_if_index)->name);
1917 break;
1918 default:
1919 break;
1920 }
Mohsin Kazmi005605f2021-05-24 18:33:50 +02001921
1922error:
1923 clib_bitmap_free (bitmap);
1924 return (error);
1925}
1926
1927VLIB_CLI_COMMAND (cmd_set_if_tx_queue, static) = {
1928 .path = "set interface tx-queue",
1929 .short_help = "set interface tx-queue <interface> queue <n> "
Steven Luong8e3f1092021-06-17 08:22:50 -07001930 "[threads <list>]",
Mohsin Kazmi005605f2021-05-24 18:33:50 +02001931 .function = set_interface_tx_queue,
1932 .is_mp_safe = 1,
1933};
1934
1935clib_error_t *
Chenmin Sunc4665092020-07-06 08:20:39 +08001936set_interface_rss_queues (vlib_main_t * vm, u32 hw_if_index,
1937 clib_bitmap_t * bitmap)
1938{
1939 vnet_main_t *vnm = vnet_get_main ();
1940 vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, hw_if_index);
1941
1942 return vnet_hw_interface_set_rss_queues (vnm, hi, bitmap);
1943}
1944
1945static clib_error_t *
1946set_interface_rss_queues_fn (vlib_main_t * vm,
1947 unformat_input_t * input,
1948 vlib_cli_command_t * cmd)
1949{
1950 clib_error_t *error = 0;
1951 unformat_input_t _line_input, *line_input = &_line_input;
1952 vnet_main_t *vnm = vnet_get_main ();
1953 u32 hw_if_index = (u32) ~ 0;
1954 clib_bitmap_t *bitmap = NULL;
1955
1956 if (!unformat_user (input, unformat_line_input, line_input))
1957 return 0;
1958
1959 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1960 {
1961 if (unformat
1962 (line_input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
1963 ;
1964 else
1965 if (unformat (line_input, "list %U", unformat_bitmap_list, &bitmap))
1966 ;
1967 else
1968 {
1969 error = clib_error_return (0, "parse error: '%U'",
1970 format_unformat_error, line_input);
1971 unformat_free (line_input);
1972 goto done;
1973 }
1974 }
1975
1976 unformat_free (line_input);
1977
1978 if (hw_if_index == (u32) ~ 0)
1979 {
1980 error = clib_error_return (0, "please specify valid interface name");
1981 goto done;
1982 }
1983
1984 if (bitmap == NULL)
1985 {
1986 error = clib_error_return (0, "please specify the valid rss queues");
1987 goto done;
1988 }
1989
1990 error = set_interface_rss_queues (vm, hw_if_index, bitmap);
1991
1992done:
1993 if (bitmap)
1994 clib_bitmap_free (bitmap);
1995
1996 return (error);
1997}
1998
1999/*?
2000 * This command is used to set the rss queues of a given interface
2001 * Not all the interfaces support this operation.
2002 * To display the current rss queues, use the command
2003 * '<em>show hardware-interfaces</em>'.
2004 *
2005 * @cliexpar
2006 * Example of how to set the rss queues to 0,2-5,7 of an interface:
2007 * @cliexstart{set interface rss queues VirtualFunctionEthernet18/1/0 list 0,2-5,7}
2008 * @cliexend
2009?*/
Chenmin Sunc4665092020-07-06 08:20:39 +08002010VLIB_CLI_COMMAND (cmd_set_interface_rss_queues,static) = {
2011 .path = "set interface rss queues",
2012 .short_help = "set interface rss queues <interface> <list <queue-list>>",
2013 .function = set_interface_rss_queues_fn,
2014};
Chenmin Sunc4665092020-07-06 08:20:39 +08002015
Dave Barach33909772019-09-23 10:27:27 -04002016static u8 *
2017format_vnet_pcap (u8 * s, va_list * args)
2018{
2019 vnet_pcap_t *pp = va_arg (*args, vnet_pcap_t *);
2020 int type = va_arg (*args, int);
2021 int printed = 0;
2022
2023 if (type == 0)
2024 {
2025 if (pp->pcap_rx_enable)
2026 {
2027 s = format (s, "rx");
2028 printed = 1;
2029 }
2030 if (pp->pcap_tx_enable)
2031 {
2032 if (printed)
2033 s = format (s, " and ");
2034 s = format (s, "tx");
2035 printed = 1;
2036 }
2037 if (pp->pcap_drop_enable)
2038 {
2039 if (printed)
2040 s = format (s, " and ");
2041 s = format (s, "drop");
2042 printed = 1;
2043 }
2044 return s;
2045 }
2046 s = format (s, "unknown type %d!", type);
2047 return s;
2048}
2049
2050
Dave Barachb97641c2019-09-09 16:38:17 -04002051int
2052vnet_pcap_dispatch_trace_configure (vnet_pcap_dispatch_trace_args_t * a)
2053{
2054 vlib_main_t *vm = vlib_get_main ();
Damjan Marion8fb5add2021-03-04 18:41:59 +01002055 vnet_main_t *vnm = vnet_get_main ();
2056 vnet_pcap_t *pp = &vnm->pcap;
Dave Barachb97641c2019-09-09 16:38:17 -04002057 pcap_main_t *pm = &pp->pcap_main;
Dave Barachf5667c32019-09-25 11:27:46 -04002058 vnet_classify_main_t *cm = &vnet_classify_main;
Dave Barachb97641c2019-09-09 16:38:17 -04002059
2060 if (a->status)
2061 {
Dave Barach33909772019-09-23 10:27:27 -04002062 if (pp->pcap_rx_enable || pp->pcap_tx_enable || pp->pcap_drop_enable)
Dave Barachb97641c2019-09-09 16:38:17 -04002063 {
2064 vlib_cli_output
Dave Barach33909772019-09-23 10:27:27 -04002065 (vm, "pcap %U dispatch capture enabled: %d of %d pkts...",
2066 format_vnet_pcap, pp, 0 /* print type */ ,
Dave Barachb97641c2019-09-09 16:38:17 -04002067 pm->n_packets_captured, pm->n_packets_to_capture);
2068 vlib_cli_output (vm, "capture to file %s", pm->file_name);
2069 }
2070 else
Dave Barach33909772019-09-23 10:27:27 -04002071 vlib_cli_output (vm, "pcap dispatch capture disabled");
2072
Dave Barachb97641c2019-09-09 16:38:17 -04002073 return 0;
2074 }
2075
2076 /* Consistency checks */
2077
2078 /* Enable w/ capture already enabled not allowed */
Dave Barach33909772019-09-23 10:27:27 -04002079 if ((pp->pcap_rx_enable + pp->pcap_tx_enable + pp->pcap_drop_enable)
2080 && (a->rx_enable + a->tx_enable + a->drop_enable))
Dave Barachb97641c2019-09-09 16:38:17 -04002081 return VNET_API_ERROR_INVALID_VALUE;
2082
2083 /* Disable capture with capture already disabled, not interesting */
Mohammed Hawari9fecbe12020-12-11 19:36:37 +01002084 if (((pp->pcap_rx_enable + pp->pcap_tx_enable + pp->pcap_drop_enable) ==
2085 0) &&
2086 ((a->rx_enable + a->tx_enable + a->drop_enable == 0)))
Dave Barachb97641c2019-09-09 16:38:17 -04002087 return VNET_API_ERROR_VALUE_EXIST;
2088
2089 /* Change number of packets to capture while capturing */
Dave Barach33909772019-09-23 10:27:27 -04002090 if ((pp->pcap_rx_enable + pp->pcap_tx_enable + pp->pcap_drop_enable)
2091 && (a->rx_enable + a->tx_enable + a->drop_enable)
Dave Barachb97641c2019-09-09 16:38:17 -04002092 && (pm->n_packets_to_capture != a->packets_to_capture))
2093 return VNET_API_ERROR_INVALID_VALUE_2;
2094
Dave Barach33909772019-09-23 10:27:27 -04002095 /* Classify filter specified, but no classify filter configured */
Dave Barachf5667c32019-09-25 11:27:46 -04002096 if ((a->rx_enable + a->tx_enable + a->drop_enable) && a->filter &&
Benoît Ganne5943e362021-02-26 14:46:58 +01002097 (!cm->classify_table_index_by_sw_if_index ||
2098 cm->classify_table_index_by_sw_if_index[0] == ~0))
Dave Barach9137e542019-09-13 17:47:50 -04002099 return VNET_API_ERROR_NO_SUCH_LABEL;
2100
Dave Barach33909772019-09-23 10:27:27 -04002101 if (a->rx_enable + a->tx_enable + a->drop_enable)
Dave Barachb97641c2019-09-09 16:38:17 -04002102 {
Dave Barach586462f2020-08-05 16:12:35 -04002103 void *save_pcap_data;
2104
Dave Barach33909772019-09-23 10:27:27 -04002105 /* Sanity check max bytes per pkt */
2106 if (a->max_bytes_per_pkt < 32 || a->max_bytes_per_pkt > 9000)
2107 return VNET_API_ERROR_INVALID_MEMORY_SIZE;
2108
Dave Barachb97641c2019-09-09 16:38:17 -04002109 /* Clean up from previous run, if any */
Dave Barach586462f2020-08-05 16:12:35 -04002110 vec_reset_length (pm->pcap_data);
2111
2112 /* Throw away the data buffer? */
2113 if (a->free_data)
2114 vec_free (pm->pcap_data);
2115
2116 save_pcap_data = pm->pcap_data;
2117
Dave Barachb97641c2019-09-09 16:38:17 -04002118 memset (pm, 0, sizeof (*pm));
2119
Dave Barach586462f2020-08-05 16:12:35 -04002120 pm->pcap_data = save_pcap_data;
2121
Dave Barach11fb09e2020-08-06 12:10:09 -04002122 vec_validate_aligned (vnet_trace_placeholder, 2048,
2123 CLIB_CACHE_LINE_BYTES);
Dave Barachb97641c2019-09-09 16:38:17 -04002124 if (pm->lock == 0)
2125 clib_spinlock_init (&(pm->lock));
2126
2127 if (a->filename == 0)
Dave Barach33909772019-09-23 10:27:27 -04002128 {
2129 u8 *stem = 0;
2130
2131 if (a->rx_enable)
2132 stem = format (stem, "rx");
2133 if (a->tx_enable)
2134 stem = format (stem, "tx");
2135 if (a->drop_enable)
2136 stem = format (stem, "drop");
Benoît Ganne7d4a9972020-07-17 11:49:56 +02002137 a->filename = format (0, "/tmp/%v.pcap%c", stem, 0);
Dave Barach33909772019-09-23 10:27:27 -04002138 vec_free (stem);
2139 }
Dave Barachb97641c2019-09-09 16:38:17 -04002140
2141 pm->file_name = (char *) a->filename;
2142 pm->n_packets_captured = 0;
2143 pm->packet_type = PCAP_PACKET_TYPE_ethernet;
Dave Barach586462f2020-08-05 16:12:35 -04002144 /* Preallocate the data vector? */
2145 if (a->preallocate_data)
2146 {
2147 vec_validate
2148 (pm->pcap_data, a->packets_to_capture
2149 * ((sizeof (pcap_packet_header_t) + a->max_bytes_per_pkt)));
2150 vec_reset_length (pm->pcap_data);
2151 }
Dave Barachb97641c2019-09-09 16:38:17 -04002152 pm->n_packets_to_capture = a->packets_to_capture;
2153 pp->pcap_sw_if_index = a->sw_if_index;
Dave Barach9137e542019-09-13 17:47:50 -04002154 if (a->filter)
Jon Loeliger5c1e48c2020-10-15 14:41:36 -04002155 pp->filter_classify_table_index =
2156 cm->classify_table_index_by_sw_if_index[0];
Dave Barach9137e542019-09-13 17:47:50 -04002157 else
2158 pp->filter_classify_table_index = ~0;
Benoît Ganne5cfe4522021-03-03 17:37:25 +01002159 pp->pcap_error_index = a->drop_err;
Dave Barach33909772019-09-23 10:27:27 -04002160 pp->pcap_rx_enable = a->rx_enable;
2161 pp->pcap_tx_enable = a->tx_enable;
2162 pp->pcap_drop_enable = a->drop_enable;
2163 pp->max_bytes_per_pkt = a->max_bytes_per_pkt;
Dave Barachb97641c2019-09-09 16:38:17 -04002164 }
2165 else
2166 {
Dave Barach33909772019-09-23 10:27:27 -04002167 pp->pcap_rx_enable = 0;
2168 pp->pcap_tx_enable = 0;
2169 pp->pcap_drop_enable = 0;
Dave Barachf5667c32019-09-25 11:27:46 -04002170 pp->filter_classify_table_index = ~0;
Benoît Ganne5cfe4522021-03-03 17:37:25 +01002171 pp->pcap_error_index = ~0;
Dave Barachb97641c2019-09-09 16:38:17 -04002172 if (pm->n_packets_captured)
2173 {
2174 clib_error_t *error;
2175 pm->n_packets_to_capture = pm->n_packets_captured;
2176 vlib_cli_output (vm, "Write %d packets to %s, and stop capture...",
2177 pm->n_packets_captured, pm->file_name);
2178 error = pcap_write (pm);
Andrew Yourtchenko4da15062019-09-11 14:14:43 +00002179 if (pm->flags & PCAP_MAIN_INIT_DONE)
Dave Barachb97641c2019-09-09 16:38:17 -04002180 pcap_close (pm);
2181 /* Report I/O errors... */
2182 if (error)
2183 {
2184 clib_error_report (error);
2185 return VNET_API_ERROR_SYSCALL_ERROR_1;
2186 }
Dave Barach586462f2020-08-05 16:12:35 -04002187 vec_free (pm->file_name);
2188 if (a->free_data)
2189 vec_free (pm->pcap_data);
Dave Barachb97641c2019-09-09 16:38:17 -04002190 return 0;
2191 }
2192 else
2193 return VNET_API_ERROR_NO_SUCH_ENTRY;
2194 }
2195
2196 return 0;
2197}
2198
2199static clib_error_t *
Dave Barach33909772019-09-23 10:27:27 -04002200pcap_trace_command_fn (vlib_main_t * vm,
2201 unformat_input_t * input, vlib_cli_command_t * cmd)
Dave Barach5ecd5a52019-02-25 15:27:28 -05002202{
Dave Barach5ecd5a52019-02-25 15:27:28 -05002203 unformat_input_t _line_input, *line_input = &_line_input;
Dave Barachb97641c2019-09-09 16:38:17 -04002204 vnet_pcap_dispatch_trace_args_t _a, *a = &_a;
Dave Barach5ecd5a52019-02-25 15:27:28 -05002205 vnet_main_t *vnm = vnet_get_main ();
Dave Barachb97641c2019-09-09 16:38:17 -04002206 u8 *filename = 0;
2207 u32 max = 1000;
Dave Barach33909772019-09-23 10:27:27 -04002208 u32 max_bytes_per_pkt = 512;
Dave Barachb97641c2019-09-09 16:38:17 -04002209 int rv;
Dave Barach33909772019-09-23 10:27:27 -04002210 int rx_enable = 0;
2211 int tx_enable = 0;
Dave Barach586462f2020-08-05 16:12:35 -04002212 int preallocate_data = 0;
Dave Barach33909772019-09-23 10:27:27 -04002213 int drop_enable = 0;
Dave Barachb97641c2019-09-09 16:38:17 -04002214 int status = 0;
Dave Barach9137e542019-09-13 17:47:50 -04002215 int filter = 0;
Dave Barach586462f2020-08-05 16:12:35 -04002216 int free_data = 0;
Dave Barach4330c462020-06-10 17:07:32 -04002217 u32 sw_if_index = 0; /* default: any interface */
Benoît Ganne5cfe4522021-03-03 17:37:25 +01002218 vlib_error_t drop_err = ~0; /* default: any error */
Dave Barach5ecd5a52019-02-25 15:27:28 -05002219
2220 /* Get a line of input. */
2221 if (!unformat_user (input, unformat_line_input, line_input))
2222 return 0;
2223
2224 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2225 {
Dave Barach33909772019-09-23 10:27:27 -04002226 if (unformat (line_input, "rx"))
2227 rx_enable = 1;
2228 else if (unformat (line_input, "tx"))
2229 tx_enable = 1;
2230 else if (unformat (line_input, "drop"))
2231 drop_enable = 1;
2232 else if (unformat (line_input, "off"))
2233 rx_enable = tx_enable = drop_enable = 0;
2234 else if (unformat (line_input, "max-bytes-per-pkt %u",
2235 &max_bytes_per_pkt))
Dave Barachb97641c2019-09-09 16:38:17 -04002236 ;
2237 else if (unformat (line_input, "max %d", &max))
2238 ;
2239 else if (unformat (line_input, "packets-to-capture %d", &max))
2240 ;
2241 else if (unformat (line_input, "file %U", unformat_vlib_tmpfile,
2242 &filename))
2243 ;
2244 else if (unformat (line_input, "status %=", &status, 1))
2245 ;
2246 else if (unformat (line_input, "intfc %U",
2247 unformat_vnet_sw_interface, vnm, &sw_if_index))
2248 ;
Dave Barach586462f2020-08-05 16:12:35 -04002249 else if (unformat (line_input, "interface %U",
2250 unformat_vnet_sw_interface, vnm, &sw_if_index))
2251 ;
Benoît Ganne5cfe4522021-03-03 17:37:25 +01002252 else if (unformat (line_input, "error %U", unformat_vlib_error, vm,
2253 &drop_err))
2254 ;
Dave Barach586462f2020-08-05 16:12:35 -04002255 else if (unformat (line_input, "preallocate-data %=",
2256 &preallocate_data, 1))
2257 ;
2258 else if (unformat (line_input, "free-data %=", &free_data, 1))
2259 ;
2260 else if (unformat (line_input, "intfc any")
2261 || unformat (line_input, "interface any"))
Dave Barachb97641c2019-09-09 16:38:17 -04002262 sw_if_index = 0;
Dave Barach9137e542019-09-13 17:47:50 -04002263 else if (unformat (line_input, "filter"))
2264 filter = 1;
Dave Barach5ecd5a52019-02-25 15:27:28 -05002265 else
2266 {
Dave Barachb97641c2019-09-09 16:38:17 -04002267 return clib_error_return (0, "unknown input `%U'",
2268 format_unformat_error, line_input);
Dave Barach5ecd5a52019-02-25 15:27:28 -05002269 }
2270 }
Dave Barachb97641c2019-09-09 16:38:17 -04002271
Dave Barach5ecd5a52019-02-25 15:27:28 -05002272 unformat_free (line_input);
2273
Dave Barachb97641c2019-09-09 16:38:17 -04002274 /* no need for memset (a, 0, sizeof (*a)), set all fields here. */
2275 a->filename = filename;
Dave Barach33909772019-09-23 10:27:27 -04002276 a->rx_enable = rx_enable;
2277 a->tx_enable = tx_enable;
Dave Barach586462f2020-08-05 16:12:35 -04002278 a->preallocate_data = preallocate_data;
2279 a->free_data = free_data;
Dave Barach33909772019-09-23 10:27:27 -04002280 a->drop_enable = drop_enable;
Dave Barachb97641c2019-09-09 16:38:17 -04002281 a->status = status;
2282 a->packets_to_capture = max;
Dave Barachb97641c2019-09-09 16:38:17 -04002283 a->sw_if_index = sw_if_index;
Dave Barach9137e542019-09-13 17:47:50 -04002284 a->filter = filter;
Dave Barach33909772019-09-23 10:27:27 -04002285 a->max_bytes_per_pkt = max_bytes_per_pkt;
Benoît Ganne5cfe4522021-03-03 17:37:25 +01002286 a->drop_err = drop_err;
Dave Barach5ecd5a52019-02-25 15:27:28 -05002287
Dave Barachb97641c2019-09-09 16:38:17 -04002288 rv = vnet_pcap_dispatch_trace_configure (a);
2289
2290 switch (rv)
Dave Barach5ecd5a52019-02-25 15:27:28 -05002291 {
Dave Barachb97641c2019-09-09 16:38:17 -04002292 case 0:
2293 break;
Dave Barach5ecd5a52019-02-25 15:27:28 -05002294
Dave Barachb97641c2019-09-09 16:38:17 -04002295 case VNET_API_ERROR_INVALID_VALUE:
2296 return clib_error_return (0, "dispatch trace already enabled...");
Dave Barach5ecd5a52019-02-25 15:27:28 -05002297
Dave Barachb97641c2019-09-09 16:38:17 -04002298 case VNET_API_ERROR_VALUE_EXIST:
2299 return clib_error_return (0, "dispatch trace already disabled...");
Dave Barach5ecd5a52019-02-25 15:27:28 -05002300
Dave Barachb97641c2019-09-09 16:38:17 -04002301 case VNET_API_ERROR_INVALID_VALUE_2:
2302 return clib_error_return
2303 (0, "can't change number of records to capture while tracing...");
2304
2305 case VNET_API_ERROR_SYSCALL_ERROR_1:
2306 return clib_error_return (0, "I/O writing trace capture...");
2307
2308 case VNET_API_ERROR_NO_SUCH_ENTRY:
2309 return clib_error_return (0, "No packets captured...");
2310
Dave Barach33909772019-09-23 10:27:27 -04002311 case VNET_API_ERROR_INVALID_MEMORY_SIZE:
2312 return clib_error_return (0,
2313 "Max bytes per pkt must be > 32, < 9000...");
2314
Dave Barach9137e542019-09-13 17:47:50 -04002315 case VNET_API_ERROR_NO_SUCH_LABEL:
2316 return clib_error_return
2317 (0, "No classify filter configured, see 'classify filter...'");
2318
Dave Barachb97641c2019-09-09 16:38:17 -04002319 default:
2320 vlib_cli_output (vm, "WARNING: trace configure returned %d", rv);
2321 break;
Dave Barach5ecd5a52019-02-25 15:27:28 -05002322 }
Dave Barachb97641c2019-09-09 16:38:17 -04002323 return 0;
Dave Barach5ecd5a52019-02-25 15:27:28 -05002324}
2325
Dave Barach5ecd5a52019-02-25 15:27:28 -05002326/*?
2327 * This command is used to start or stop a packet capture, or show
Dave Barach33909772019-09-23 10:27:27 -04002328 * the status of packet capture.
Dave Barach5ecd5a52019-02-25 15:27:28 -05002329 *
2330 * This command has the following optional parameters:
2331 *
Dave Barach33909772019-09-23 10:27:27 -04002332 *
2333 * - <b>rx</b> - Capture received packets
2334 *
2335 * - <b>tx</b> - Capture transmitted packets
2336 *
2337 * - <b>drop</b> - Capture dropped packets
2338 *
2339 * - <b>off</b> - Stop capturing packets, write results to the specified file
Dave Barach5ecd5a52019-02-25 15:27:28 -05002340 *
2341 * - <b>max <nn></b> - Depth of local buffer. Once '<em>nn</em>' number
2342 * of packets have been received, buffer is flushed to file. Once another
2343 * '<em>nn</em>' number of packets have been received, buffer is flushed
2344 * to file, overwriting previous write. If not entered, value defaults
2345 * to 100. Can only be updated if packet capture is off.
2346 *
Dave Barach33909772019-09-23 10:27:27 -04002347 * - <b>max-bytes-per-pkt <nnnn></b> - Maximum number of bytes to capture
2348 * for each packet. Must be >= 32, <= 9000.
2349 *
Dave Barach586462f2020-08-05 16:12:35 -04002350 * - <b>preallocate-data</b> - Preallocate the data buffer, to avoid
2351 * vector expansion delays during pcap capture
2352 *
2353 * - <b>free-data</b> - Free the data buffer. Ordinarily it's a feature
2354 * to retain the data buffer so this option is seldom used.
2355 *
Dave Barach33909772019-09-23 10:27:27 -04002356 * - <b>intfc <interface-name>|any</b> - Used to specify a given interface,
Dave Barach5ecd5a52019-02-25 15:27:28 -05002357 * or use '<em>any</em>' to run packet capture on all interfaces.
2358 * '<em>any</em>' is the default if not provided. Settings from a previous
2359 * packet capture are preserved, so '<em>any</em>' can be used to reset
2360 * the interface setting.
2361 *
Nobuhiro MIKId346f392023-02-28 18:30:09 +09002362 * - <b>filter</b> - Use the pcap trace rx / tx / drop filter, which
Dave Barachf5667c32019-09-25 11:27:46 -04002363 * must be configured. Use <b>classify filter pcap...</b> to configure the
2364 * filter. The filter will only be executed if the per-interface or
2365 * any-interface tests fail.
2366 *
Benoît Ganne5cfe4522021-03-03 17:37:25 +01002367 * - <b>error <node>.<error></b> - filter packets based on a specific error.
Maxime Peimddc16cf2023-01-13 08:04:55 +00002368 * For example: error {ip4-udp-lookup}.{no_listener}
Benoît Ganne5cfe4522021-03-03 17:37:25 +01002369 *
Dave Barach5ecd5a52019-02-25 15:27:28 -05002370 * - <b>file <name></b> - Used to specify the output filename. The file will
2371 * be placed in the '<em>/tmp</em>' directory, so only the filename is
2372 * supported. Directory should not be entered. If file already exists, file
Dave Barach33909772019-09-23 10:27:27 -04002373 * will be overwritten. If no filename is provided, the file will be
2374 * named "/tmp/rx.pcap", "/tmp/tx.pcap", "/tmp/rxandtx.pcap", etc.
2375 * Can only be updated if packet capture is off.
Dave Barach5ecd5a52019-02-25 15:27:28 -05002376 *
2377 * - <b>status</b> - Displays the current status and configured attributes
2378 * associated with a packet capture. If packet capture is in progress,
2379 * '<em>status</em>' also will return the number of packets currently in
2380 * the local buffer. All additional attributes entered on command line
2381 * with '<em>status</em>' will be ignored and not applied.
2382 *
2383 * @cliexpar
2384 * Example of how to display the status of a tx packet capture when off:
Dave Barach33909772019-09-23 10:27:27 -04002385 * @cliexstart{pcap trace status}
Dave Barach5ecd5a52019-02-25 15:27:28 -05002386 * max is 100, for any interface to file /tmp/vpe.pcap
2387 * pcap tx capture is off...
2388 * @cliexend
2389 * Example of how to start a tx packet capture:
Benoît Ganne5cfe4522021-03-03 17:37:25 +01002390 * @cliexstart{pcap trace tx max 35 intfc GigabitEthernet0/8/0 file
Nathan Skrzypczak2c77ae42021-09-29 15:36:51 +02002391 * vppTest.pcap}
Dave Barach5ecd5a52019-02-25 15:27:28 -05002392 * @cliexend
2393 * Example of how to display the status of a tx packet capture in progress:
Dave Barach33909772019-09-23 10:27:27 -04002394 * @cliexstart{pcap trace status}
Dave Barach5ecd5a52019-02-25 15:27:28 -05002395 * max is 35, for interface GigabitEthernet0/8/0 to file /tmp/vppTest.pcap
2396 * pcap tx capture is on: 20 of 35 pkts...
2397 * @cliexend
2398 * Example of how to stop a tx packet capture:
Dave Barach33909772019-09-23 10:27:27 -04002399 * @cliexstart{pcap trace off}
Dave Barach5ecd5a52019-02-25 15:27:28 -05002400 * captured 21 pkts...
2401 * saved to /tmp/vppTest.pcap...
2402 * @cliexend
2403?*/
Dave Barach5ecd5a52019-02-25 15:27:28 -05002404
2405VLIB_CLI_COMMAND (pcap_tx_trace_command, static) = {
Dave Barach33909772019-09-23 10:27:27 -04002406 .path = "pcap trace",
Dave Barach5ecd5a52019-02-25 15:27:28 -05002407 .short_help =
Dave Barach586462f2020-08-05 16:12:35 -04002408 "pcap trace [rx] [tx] [drop] [off] [max <nn>] [intfc <interface>|any]\n"
2409 " [file <name>] [status] [max-bytes-per-pkt <nnnn>][filter]\n"
2410 " [preallocate-data][free-data]",
Dave Barach33909772019-09-23 10:27:27 -04002411 .function = pcap_trace_command_fn,
Dave Barach5ecd5a52019-02-25 15:27:28 -05002412};
Dave Barach5ecd5a52019-02-25 15:27:28 -05002413
Steven Luongf49734d2021-07-26 13:38:05 -07002414static clib_error_t *
Maxime Peim3f407552023-07-03 17:45:51 +02002415set_pcap_filter_function (vlib_main_t *vm, unformat_input_t *input,
2416 vlib_cli_command_t *cmd)
2417{
2418 vnet_pcap_t *pp = &vnet_get_main ()->pcap;
2419 unformat_input_t _line_input, *line_input = &_line_input;
2420 vlib_is_packet_traced_fn_t *res = 0;
2421 clib_error_t *error = 0;
2422
2423 if (!unformat_user (input, unformat_line_input, line_input))
2424 return 0;
2425
2426 while (unformat_check_input (line_input) != (uword) UNFORMAT_END_OF_INPUT)
2427 {
2428 if (unformat (line_input, "%U", unformat_vlib_trace_filter_function,
2429 &res))
2430 ;
2431 else
2432 {
2433 error = clib_error_create (
2434 "expected valid trace filter function, got `%U'",
2435 format_unformat_error, line_input);
2436 goto done;
2437 }
2438 }
2439 pp->current_filter_function = res;
2440
2441done:
2442 unformat_free (line_input);
2443
2444 return error;
2445}
2446
2447VLIB_CLI_COMMAND (set_pcap_filter_function_cli, static) = {
2448 .path = "set pcap filter function",
2449 .short_help = "set pcap filter function <func_name>",
2450 .function = set_pcap_filter_function,
2451};
2452
2453static clib_error_t *
2454show_pcap_filter_function (vlib_main_t *vm, unformat_input_t *input,
2455 vlib_cli_command_t *cmd)
2456{
2457 vnet_pcap_t *pp = &vnet_get_main ()->pcap;
2458 vlib_trace_filter_main_t *tfm = &vlib_trace_filter_main;
2459 vlib_is_packet_traced_fn_t *current_trace_filter_fn =
2460 pp->current_filter_function;
2461 vlib_trace_filter_function_registration_t *reg =
2462 tfm->trace_filter_registration;
2463
2464 while (reg)
2465 {
2466 vlib_cli_output (vm, "%sname:%s description: %s priority: %u",
2467 reg->function == current_trace_filter_fn ? "(*) " : "",
2468 reg->name, reg->description, reg->priority);
2469 reg = reg->next;
2470 }
2471 return 0;
2472}
2473
2474VLIB_CLI_COMMAND (show_pcap_filter_function_cli, static) = {
2475 .path = "show pcap filter function",
2476 .short_help = "show pcap filter function",
2477 .function = show_pcap_filter_function,
2478};
2479
2480static clib_error_t *
Steven Luongf49734d2021-07-26 13:38:05 -07002481set_interface_name (vlib_main_t *vm, unformat_input_t *input,
2482 vlib_cli_command_t *cmd)
2483{
2484 clib_error_t *error = 0;
2485 unformat_input_t _line_input, *line_input = &_line_input;
2486 vnet_main_t *vnm = vnet_get_main ();
2487 u32 hw_if_index = ~0;
2488 char *name = 0;
2489
2490 if (!unformat_user (input, unformat_line_input, line_input))
2491 return 0;
2492
2493 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2494 {
2495 if (unformat (line_input, "%U %s", unformat_vnet_hw_interface, vnm,
2496 &hw_if_index, &name))
2497 ;
2498 else
2499 {
2500 error = clib_error_return (0, "parse error: '%U'",
2501 format_unformat_error, line_input);
2502 unformat_free (line_input);
2503 vec_free (name);
2504 return error;
2505 }
2506 }
2507
2508 unformat_free (line_input);
2509
2510 if (hw_if_index == (u32) ~0 || name == 0)
2511 {
2512 vec_free (name);
2513 error = clib_error_return (0, "please specify valid interface name");
2514 return error;
2515 }
2516
2517 error = vnet_rename_interface (vnm, hw_if_index, name);
2518 vec_free (name);
2519
2520 return (error);
2521}
2522
2523VLIB_CLI_COMMAND (cmd_set_if_name, static) = {
2524 .path = "set interface name",
2525 .short_help = "set interface name <interface-name> <new-interface-name>",
2526 .function = set_interface_name,
2527 .is_mp_safe = 1,
2528};
Mohsin Kazmi0d05c0d2021-11-09 17:44:10 +00002529
2530static clib_error_t *
2531set_interface_tx_hash_cmd (vlib_main_t *vm, unformat_input_t *input,
2532 vlib_cli_command_t *cmd)
2533{
2534 clib_error_t *error = 0;
2535 unformat_input_t _line_input, *line_input = &_line_input;
2536 vnet_main_t *vnm = vnet_get_main ();
2537 vnet_hw_interface_t *hi;
2538 u8 *hash_name = 0;
2539 u32 hw_if_index = (u32) ~0;
2540 vnet_hash_fn_t hf;
2541 vnet_hash_fn_type_t ftype;
2542
2543 if (!unformat_user (input, unformat_line_input, line_input))
2544 return 0;
2545
2546 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2547 {
2548 if (unformat (line_input, "%U", unformat_vnet_hw_interface, vnm,
2549 &hw_if_index))
2550 ;
2551 else if (unformat (line_input, "hash-name %s", &hash_name))
2552 ;
2553 else
2554 {
2555 error = clib_error_return (0, "parse error: '%U'",
2556 format_unformat_error, line_input);
2557 unformat_free (line_input);
2558 return error;
2559 }
2560 }
2561
2562 unformat_free (line_input);
2563
2564 if (hw_if_index == (u32) ~0)
2565 {
2566 error = clib_error_return (0, "please specify valid interface name");
2567 goto error;
2568 }
2569
Dave Barach9e0f9e22022-01-18 08:52:47 -05002570 if (hash_name == 0)
2571 {
2572 error = clib_error_return (0, "hash-name is required");
2573 goto error;
2574 }
2575
Mohsin Kazmi0d05c0d2021-11-09 17:44:10 +00002576 hi = vnet_get_hw_interface (vnm, hw_if_index);
2577 ftype =
2578 vnet_get_hw_interface_class (vnm, hi->hw_class_index)->tx_hash_fn_type;
2579 hf = vnet_hash_function_from_name ((const char *) hash_name, ftype);
2580
2581 if (!hf)
2582 {
2583 error = clib_error_return (0, "please specify valid hash name");
2584 goto error;
2585 }
2586
2587 hi->hf = hf;
2588error:
2589 vec_free (hash_name);
2590 return (error);
2591}
2592
2593VLIB_CLI_COMMAND (cmd_set_if_tx_hash, static) = {
2594 .path = "set interface tx-hash",
2595 .short_help = "set interface tx-hash <interface> hash-name <hash-name>",
2596 .function = set_interface_tx_hash_cmd,
2597};
2598
2599static clib_error_t *
2600show_tx_hash (vlib_main_t *vm, unformat_input_t *input,
2601 vlib_cli_command_t *cmd)
2602{
2603 clib_error_t *error = 0;
2604 unformat_input_t _line_input, *line_input = &_line_input;
2605 vnet_main_t *vnm = vnet_get_main ();
2606 vnet_hw_interface_t *hi;
2607 vnet_hash_function_registration_t *hash;
2608 u32 hw_if_index = (u32) ~0;
2609 vnet_hash_fn_type_t ftype;
2610
2611 if (!unformat_user (input, unformat_line_input, line_input))
2612 return 0;
2613
2614 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2615 {
2616 if (unformat (line_input, "%U", unformat_vnet_hw_interface, vnm,
2617 &hw_if_index))
2618 ;
2619 else
2620 {
2621 error = clib_error_return (0, "parse error: '%U'",
2622 format_unformat_error, line_input);
2623 unformat_free (line_input);
2624 goto error;
2625 }
2626 }
2627
2628 unformat_free (line_input);
2629
2630 if (hw_if_index == (u32) ~0)
2631 {
2632 error = clib_error_return (0, "please specify valid interface name");
2633 goto error;
2634 }
2635
2636 hi = vnet_get_hw_interface (vnm, hw_if_index);
2637 ftype =
2638 vnet_get_hw_interface_class (vnm, hi->hw_class_index)->tx_hash_fn_type;
2639
2640 if (hi->hf)
2641 {
2642 hash = vnet_hash_function_from_func (hi->hf, ftype);
2643 if (hash)
2644 vlib_cli_output (vm, "%U", format_vnet_hash, hash);
2645 else
2646 vlib_cli_output (vm, "no matching hash function found");
2647 }
2648 else
2649 vlib_cli_output (vm, "no hashing function set");
2650
2651error:
2652 return (error);
2653}
2654
2655VLIB_CLI_COMMAND (cmd_show_tx_hash, static) = {
2656 .path = "show interface tx-hash",
2657 .short_help = "show interface tx-hash [interface]",
2658 .function = show_tx_hash,
2659};
2660
Dave Barachba868bb2016-08-08 09:51:21 -04002661/*
2662 * fd.io coding-style-patch-verification: ON
2663 *
2664 * Local Variables:
2665 * eval: (c-set-style "gnu")
2666 * End:
2667 */