Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015 Cisco and/or its affiliates. |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at: |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
| 15 | /* |
| 16 | * interface_cli.c: interface CLI |
| 17 | * |
| 18 | * Copyright (c) 2008 Eliot Dresselhaus |
| 19 | * |
| 20 | * Permission is hereby granted, free of charge, to any person obtaining |
| 21 | * a copy of this software and associated documentation files (the |
| 22 | * "Software"), to deal in the Software without restriction, including |
| 23 | * without limitation the rights to use, copy, modify, merge, publish, |
| 24 | * distribute, sublicense, and/or sell copies of the Software, and to |
| 25 | * permit persons to whom the Software is furnished to do so, subject to |
| 26 | * the following conditions: |
| 27 | * |
| 28 | * The above copyright notice and this permission notice shall be |
| 29 | * included in all copies or substantial portions of the Software. |
| 30 | * |
| 31 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 32 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 33 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 34 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
| 35 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
| 36 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
| 37 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 38 | */ |
Chris Luke | 16bcf7d | 2016-09-01 14:31:46 -0400 | [diff] [blame] | 39 | /** |
| 40 | * @file |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 41 | * @brief Interface CLI. |
| 42 | * |
| 43 | * Source code for several CLI interface commands. |
| 44 | * |
Chris Luke | 16bcf7d | 2016-09-01 14:31:46 -0400 | [diff] [blame] | 45 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 46 | #include <vnet/vnet.h> |
| 47 | #include <vnet/ip/ip.h> |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 48 | #include <vppinfra/bitmap.h> |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 49 | #include <vnet/fib/ip4_fib.h> |
| 50 | #include <vnet/fib/ip6_fib.h> |
Eyal Bari | 942402b | 2017-07-26 11:57:04 +0300 | [diff] [blame] | 51 | #include <vnet/l2/l2_output.h> |
| 52 | #include <vnet/l2/l2_input.h> |
Neale Ranns | ba4a5bf | 2020-01-09 06:43:14 +0000 | [diff] [blame] | 53 | #include <vnet/classify/vnet_classify.h> |
Damjan Marion | 9410053 | 2020-11-06 23:25:57 +0100 | [diff] [blame] | 54 | #include <vnet/interface/rx_queue_funcs.h> |
Mohsin Kazmi | 005605f | 2021-05-24 18:33:50 +0200 | [diff] [blame] | 55 | #include <vnet/interface/tx_queue_funcs.h> |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 56 | static int |
| 57 | compare_interface_names (void *a1, void *a2) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 58 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 59 | u32 *hi1 = a1; |
| 60 | u32 *hi2 = a2; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 61 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 62 | return vnet_hw_interface_compare (vnet_get_main (), *hi1, *hi2); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | static clib_error_t * |
| 66 | show_or_clear_hw_interfaces (vlib_main_t * vm, |
| 67 | unformat_input_t * input, |
Benoît Ganne | 17814d7 | 2020-07-24 09:57:11 +0200 | [diff] [blame] | 68 | vlib_cli_command_t * cmd, int is_show) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 69 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 70 | clib_error_t *error = 0; |
| 71 | vnet_main_t *vnm = vnet_get_main (); |
| 72 | vnet_interface_main_t *im = &vnm->interface_main; |
| 73 | vnet_hw_interface_t *hi; |
| 74 | u32 hw_if_index, *hw_if_indices = 0; |
Benoît Ganne | 17814d7 | 2020-07-24 09:57:11 +0200 | [diff] [blame] | 75 | int i, verbose = -1, show_bond = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 76 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 77 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 78 | { |
| 79 | /* See if user wants to show a specific interface. */ |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 80 | if (unformat |
| 81 | (input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index)) |
| 82 | vec_add1 (hw_if_indices, hw_if_index); |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 83 | |
Sean Hope | 679ea79 | 2016-02-22 15:12:01 -0500 | [diff] [blame] | 84 | /* See if user wants to show an interface with a specific hw_if_index. */ |
| 85 | else if (unformat (input, "%u", &hw_if_index)) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 86 | vec_add1 (hw_if_indices, hw_if_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 87 | |
| 88 | else if (unformat (input, "verbose")) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 89 | verbose = 1; /* this is also the default */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 90 | |
| 91 | else if (unformat (input, "detail")) |
| 92 | verbose = 2; |
| 93 | |
| 94 | else if (unformat (input, "brief")) |
| 95 | verbose = 0; |
| 96 | |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 97 | else if (unformat (input, "bond")) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 98 | { |
| 99 | show_bond = 1; |
| 100 | if (verbose < 0) |
| 101 | verbose = 0; /* default to brief for link bonding */ |
| 102 | } |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 103 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 104 | else |
| 105 | { |
| 106 | error = clib_error_return (0, "unknown input `%U'", |
| 107 | format_unformat_error, input); |
| 108 | goto done; |
| 109 | } |
| 110 | } |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 111 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 112 | /* Gather interfaces. */ |
| 113 | if (vec_len (hw_if_indices) == 0) |
Damjan Marion | b2c31b6 | 2020-12-13 21:47:40 +0100 | [diff] [blame] | 114 | pool_foreach (hi, im->hw_interfaces) |
| 115 | vec_add1 (hw_if_indices, hi - im->hw_interfaces); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 116 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 117 | if (verbose < 0) |
| 118 | verbose = 1; /* default to verbose (except bond) */ |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 119 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 120 | if (is_show) |
| 121 | { |
| 122 | /* Sort by name. */ |
| 123 | vec_sort_with_function (hw_if_indices, compare_interface_names); |
| 124 | |
| 125 | vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm, 0, verbose); |
| 126 | for (i = 0; i < vec_len (hw_if_indices); i++) |
| 127 | { |
| 128 | hi = vnet_get_hw_interface (vnm, hw_if_indices[i]); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 129 | if (show_bond == 0) /* show all interfaces */ |
| 130 | vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm, |
| 131 | hi, verbose); |
| 132 | else if ((hi->bond_info) && |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 133 | (hi->bond_info != VNET_HW_INTERFACE_BOND_INFO_SLAVE)) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 134 | { /* show only bonded interface and all its slave interfaces */ |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 135 | int hw_idx; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 136 | vnet_hw_interface_t *shi; |
| 137 | vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm, |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 138 | hi, verbose); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 139 | |
| 140 | /* *INDENT-OFF* */ |
Damjan Marion | f0ca1e8 | 2020-12-13 23:26:56 +0100 | [diff] [blame] | 141 | clib_bitmap_foreach (hw_idx, hi->bond_info) |
| 142 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 143 | shi = vnet_get_hw_interface(vnm, hw_idx); |
| 144 | vlib_cli_output (vm, "%U\n", |
| 145 | format_vnet_hw_interface, vnm, shi, verbose); |
Damjan Marion | f0ca1e8 | 2020-12-13 23:26:56 +0100 | [diff] [blame] | 146 | } |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 147 | /* *INDENT-ON* */ |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 148 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 149 | } |
| 150 | } |
| 151 | else |
| 152 | { |
| 153 | for (i = 0; i < vec_len (hw_if_indices); i++) |
| 154 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 155 | vnet_device_class_t *dc; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 156 | |
| 157 | hi = vnet_get_hw_interface (vnm, hw_if_indices[i]); |
| 158 | dc = vec_elt_at_index (im->device_classes, hi->dev_class_index); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 159 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 160 | if (dc->clear_counters) |
| 161 | dc->clear_counters (hi->dev_instance); |
| 162 | } |
| 163 | } |
| 164 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 165 | done: |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 166 | vec_free (hw_if_indices); |
| 167 | return error; |
| 168 | } |
| 169 | |
Benoît Ganne | 17814d7 | 2020-07-24 09:57:11 +0200 | [diff] [blame] | 170 | static clib_error_t * |
| 171 | show_hw_interfaces (vlib_main_t * vm, |
| 172 | unformat_input_t * input, vlib_cli_command_t * cmd) |
| 173 | { |
| 174 | return show_or_clear_hw_interfaces (vm, input, cmd, 1 /* is_show */ ); |
| 175 | } |
| 176 | |
| 177 | static clib_error_t * |
| 178 | clear_hw_interfaces (vlib_main_t * vm, |
| 179 | unformat_input_t * input, vlib_cli_command_t * cmd) |
| 180 | { |
| 181 | return show_or_clear_hw_interfaces (vm, input, cmd, 0 /* is_show */ ); |
| 182 | } |
| 183 | |
| 184 | |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 185 | /*? |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 186 | * Display more detailed information about all or a list of given interfaces. |
| 187 | * The verboseness of the output can be controlled by the following optional |
| 188 | * parameters: |
| 189 | * - brief: Only show name, index and state (default for bonded interfaces). |
| 190 | * - verbose: Also display additional attributes (default for all other interfaces). |
| 191 | * - detail: Also display all remaining attributes and extended statistics. |
| 192 | * |
| 193 | * To limit the output of the command to bonded interfaces and their slave |
| 194 | * interfaces, use the '<em>bond</em>' optional parameter. |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 195 | * |
| 196 | * @cliexpar |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 197 | * Example of how to display default data for all interfaces: |
| 198 | * @cliexstart{show hardware-interfaces} |
| 199 | * Name Idx Link Hardware |
| 200 | * GigabitEthernet7/0/0 1 up GigabitEthernet7/0/0 |
| 201 | * Ethernet address ec:f4:bb:c0:bc:fc |
| 202 | * Intel e1000 |
| 203 | * carrier up full duplex speed 1000 mtu 9216 |
| 204 | * rx queues 1, rx desc 1024, tx queues 3, tx desc 1024 |
| 205 | * cpu socket 0 |
| 206 | * GigabitEthernet7/0/1 2 up GigabitEthernet7/0/1 |
| 207 | * Ethernet address ec:f4:bb:c0:bc:fd |
| 208 | * Intel e1000 |
| 209 | * carrier up full duplex speed 1000 mtu 9216 |
| 210 | * rx queues 1, rx desc 1024, tx queues 3, tx desc 1024 |
| 211 | * cpu socket 0 |
| 212 | * VirtualEthernet0/0/0 3 up VirtualEthernet0/0/0 |
| 213 | * Ethernet address 02:fe:a5:a9:8b:8e |
| 214 | * VirtualEthernet0/0/1 4 up VirtualEthernet0/0/1 |
| 215 | * Ethernet address 02:fe:c0:4e:3b:b0 |
| 216 | * VirtualEthernet0/0/2 5 up VirtualEthernet0/0/2 |
| 217 | * Ethernet address 02:fe:1f:73:92:81 |
| 218 | * VirtualEthernet0/0/3 6 up VirtualEthernet0/0/3 |
| 219 | * Ethernet address 02:fe:f2:25:c4:68 |
| 220 | * local0 0 down local0 |
| 221 | * local |
| 222 | * @cliexend |
| 223 | * Example of how to display '<em>verbose</em>' data for an interface by name and |
| 224 | * software index (where 2 is the software index): |
| 225 | * @cliexstart{show hardware-interfaces GigabitEthernet7/0/0 2 verbose} |
| 226 | * Name Idx Link Hardware |
| 227 | * GigabitEthernet7/0/0 1 up GigabitEthernet7/0/0 |
| 228 | * Ethernet address ec:f4:bb:c0:bc:fc |
| 229 | * Intel e1000 |
| 230 | * carrier up full duplex speed 1000 mtu 9216 |
| 231 | * rx queues 1, rx desc 1024, tx queues 3, tx desc 1024 |
| 232 | * cpu socket 0 |
| 233 | * GigabitEthernet7/0/1 2 down GigabitEthernet7/0/1 |
| 234 | * Ethernet address ec:f4:bb:c0:bc:fd |
| 235 | * Intel e1000 |
| 236 | * carrier up full duplex speed 1000 mtu 9216 |
| 237 | * rx queues 1, rx desc 1024, tx queues 3, tx desc 1024 |
| 238 | * cpu socket 0 |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 239 | * @cliexend |
| 240 | ?*/ |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 241 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 242 | VLIB_CLI_COMMAND (show_hw_interfaces_command, static) = { |
| 243 | .path = "show hardware-interfaces", |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 244 | .short_help = "show hardware-interfaces [brief|verbose|detail] [bond] " |
| 245 | "[<interface> [<interface> [..]]] [<sw_idx> [<sw_idx> [..]]]", |
Benoît Ganne | 17814d7 | 2020-07-24 09:57:11 +0200 | [diff] [blame] | 246 | .function = show_hw_interfaces, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 247 | }; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 248 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 249 | |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 250 | |
| 251 | /*? |
| 252 | * Clear the extended statistics for all or a list of given interfaces |
| 253 | * (statistics associated with the '<em>show hardware-interfaces</em>' command). |
| 254 | * |
| 255 | * @cliexpar |
| 256 | * Example of how to clear the extended statistics for all interfaces: |
| 257 | * @cliexcmd{clear hardware-interfaces} |
| 258 | * Example of how to clear the extended statistics for an interface by |
| 259 | * name and software index (where 2 is the software index): |
| 260 | * @cliexcmd{clear hardware-interfaces GigabitEthernet7/0/0 2} |
| 261 | ?*/ |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 262 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 263 | VLIB_CLI_COMMAND (clear_hw_interface_counters_command, static) = { |
| 264 | .path = "clear hardware-interfaces", |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 265 | .short_help = "clear hardware-interfaces " |
| 266 | "[<interface> [<interface> [..]]] [<sw_idx> [<sw_idx> [..]]]", |
Benoît Ganne | 17814d7 | 2020-07-24 09:57:11 +0200 | [diff] [blame] | 267 | .function = clear_hw_interfaces, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 268 | }; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 269 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 270 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 271 | static int |
| 272 | sw_interface_name_compare (void *a1, void *a2) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 273 | { |
| 274 | vnet_sw_interface_t *si1 = a1; |
| 275 | vnet_sw_interface_t *si2 = a2; |
| 276 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 277 | return vnet_sw_interface_compare (vnet_get_main (), |
| 278 | si1->sw_if_index, si2->sw_if_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | static clib_error_t * |
| 282 | show_sw_interfaces (vlib_main_t * vm, |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 283 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 284 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 285 | clib_error_t *error = 0; |
| 286 | vnet_main_t *vnm = vnet_get_main (); |
Dave Barach | 525c9d0 | 2018-05-26 10:48:55 -0400 | [diff] [blame] | 287 | unformat_input_t _linput, *linput = &_linput; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 288 | vnet_interface_main_t *im = &vnm->interface_main; |
| 289 | vnet_sw_interface_t *si, *sorted_sis = 0; |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 290 | u32 sw_if_index = ~(u32) 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 291 | u8 show_addresses = 0; |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 292 | u8 show_features = 0; |
Dave Barach | 7be864a | 2016-11-28 11:41:35 -0500 | [diff] [blame] | 293 | u8 show_tag = 0; |
Jon Loeliger | 9485d99 | 2019-11-08 15:05:23 -0600 | [diff] [blame] | 294 | u8 show_vtr = 0; |
Dave Barach | 525c9d0 | 2018-05-26 10:48:55 -0400 | [diff] [blame] | 295 | int verbose = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 296 | |
Dave Barach | 525c9d0 | 2018-05-26 10:48:55 -0400 | [diff] [blame] | 297 | /* |
| 298 | * Get a line of input. Won't work if the user typed |
| 299 | * "show interface" and nothing more. |
| 300 | */ |
| 301 | if (unformat_user (input, unformat_line_input, linput)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 302 | { |
Dave Barach | 525c9d0 | 2018-05-26 10:48:55 -0400 | [diff] [blame] | 303 | while (unformat_check_input (linput) != UNFORMAT_END_OF_INPUT) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 304 | { |
Dave Barach | 525c9d0 | 2018-05-26 10:48:55 -0400 | [diff] [blame] | 305 | /* See if user wants to show specific interface */ |
| 306 | if (unformat |
| 307 | (linput, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index)) |
| 308 | { |
| 309 | si = pool_elt_at_index (im->sw_interfaces, sw_if_index); |
| 310 | vec_add1 (sorted_sis, si[0]); |
| 311 | } |
| 312 | else if (unformat (linput, "address") || unformat (linput, "addr")) |
| 313 | show_addresses = 1; |
| 314 | else if (unformat (linput, "features") || unformat (linput, "feat")) |
| 315 | show_features = 1; |
| 316 | else if (unformat (linput, "tag")) |
| 317 | show_tag = 1; |
Jon Loeliger | 9485d99 | 2019-11-08 15:05:23 -0600 | [diff] [blame] | 318 | else if (unformat (linput, "vtr")) |
| 319 | show_vtr = 1; |
Dave Barach | 525c9d0 | 2018-05-26 10:48:55 -0400 | [diff] [blame] | 320 | else if (unformat (linput, "verbose")) |
| 321 | verbose = 1; |
Neale Ranns | e619ada | 2021-09-22 10:49:43 +0000 | [diff] [blame] | 322 | else if (unformat (linput, "%d", &sw_if_index)) |
| 323 | { |
| 324 | if (!pool_is_free_index (im->sw_interfaces, sw_if_index)) |
| 325 | { |
| 326 | si = pool_elt_at_index (im->sw_interfaces, sw_if_index); |
| 327 | vec_add1 (sorted_sis, si[0]); |
| 328 | } |
| 329 | else |
| 330 | { |
| 331 | vec_free (sorted_sis); |
| 332 | error = clib_error_return (0, "unknown interface index `%d'", |
| 333 | sw_if_index); |
| 334 | goto done; |
| 335 | } |
| 336 | } |
Dave Barach | 525c9d0 | 2018-05-26 10:48:55 -0400 | [diff] [blame] | 337 | else |
| 338 | { |
Dave Barach | 8fdde3c | 2019-05-17 10:46:40 -0400 | [diff] [blame] | 339 | vec_free (sorted_sis); |
Dave Barach | 525c9d0 | 2018-05-26 10:48:55 -0400 | [diff] [blame] | 340 | error = clib_error_return (0, "unknown input `%U'", |
| 341 | format_unformat_error, linput); |
| 342 | goto done; |
| 343 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 344 | } |
Dave Barach | 525c9d0 | 2018-05-26 10:48:55 -0400 | [diff] [blame] | 345 | unformat_free (linput); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 346 | } |
Jon Loeliger | 9485d99 | 2019-11-08 15:05:23 -0600 | [diff] [blame] | 347 | if (show_features || show_tag || show_vtr) |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 348 | { |
| 349 | if (sw_if_index == ~(u32) 0) |
Dave Barach | 8fdde3c | 2019-05-17 10:46:40 -0400 | [diff] [blame] | 350 | { |
| 351 | vec_free (sorted_sis); |
| 352 | return clib_error_return (0, "Interface not specified..."); |
| 353 | } |
Dave Barach | 7be864a | 2016-11-28 11:41:35 -0500 | [diff] [blame] | 354 | } |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 355 | |
Dave Barach | 7be864a | 2016-11-28 11:41:35 -0500 | [diff] [blame] | 356 | if (show_features) |
| 357 | { |
Dave Barach | 525c9d0 | 2018-05-26 10:48:55 -0400 | [diff] [blame] | 358 | vnet_interface_features_show (vm, sw_if_index, verbose); |
Neale Ranns | 47a3d99 | 2020-09-29 15:38:51 +0000 | [diff] [blame] | 359 | vlib_cli_output (vm, "%U", format_l2_input_features, sw_if_index, 1); |
Eyal Bari | 942402b | 2017-07-26 11:57:04 +0300 | [diff] [blame] | 360 | |
| 361 | l2_output_config_t *l2_output = l2output_intf_config (sw_if_index); |
| 362 | vlib_cli_output (vm, "\nl2-output:"); |
| 363 | if (l2_output->out_vtr_flag) |
| 364 | vlib_cli_output (vm, "%10s (%s)", "VTR", "--internal--"); |
| 365 | vlib_cli_output (vm, "%U", format_l2_output_features, |
Neale Ranns | 5d9df1d | 2018-11-09 08:19:27 -0800 | [diff] [blame] | 366 | l2_output->feature_bitmap, 1); |
Dave Barach | 8fdde3c | 2019-05-17 10:46:40 -0400 | [diff] [blame] | 367 | vec_free (sorted_sis); |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 368 | return 0; |
| 369 | } |
Dave Barach | 7be864a | 2016-11-28 11:41:35 -0500 | [diff] [blame] | 370 | if (show_tag) |
| 371 | { |
| 372 | u8 *tag; |
| 373 | tag = vnet_get_sw_interface_tag (vnm, sw_if_index); |
| 374 | vlib_cli_output (vm, "%U: %s", |
| 375 | format_vnet_sw_if_index_name, vnm, sw_if_index, |
| 376 | tag ? (char *) tag : "(none)"); |
Dave Barach | 8fdde3c | 2019-05-17 10:46:40 -0400 | [diff] [blame] | 377 | vec_free (sorted_sis); |
Dave Barach | 7be864a | 2016-11-28 11:41:35 -0500 | [diff] [blame] | 378 | return 0; |
| 379 | } |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 380 | |
Jon Loeliger | 9485d99 | 2019-11-08 15:05:23 -0600 | [diff] [blame] | 381 | /* |
| 382 | * Show vlan tag rewrite data for one interface. |
| 383 | */ |
| 384 | if (show_vtr) |
| 385 | { |
| 386 | u32 vtr_op = L2_VTR_DISABLED; |
| 387 | u32 push_dot1q = 0, tag1 = 0, tag2 = 0; |
| 388 | |
| 389 | if (l2vtr_get (vm, vnm, sw_if_index, |
| 390 | &vtr_op, &push_dot1q, &tag1, &tag2) != 0) |
| 391 | { |
| 392 | vlib_cli_output (vm, "%U: Problem getting vlan tag-rewrite data", |
| 393 | format_vnet_sw_if_index_name, vnm, sw_if_index); |
| 394 | return 0; |
| 395 | } |
| 396 | vlib_cli_output (vm, "%U: VTR %0U", |
| 397 | format_vnet_sw_if_index_name, vnm, sw_if_index, |
| 398 | format_vtr, vtr_op, push_dot1q, tag1, tag2); |
| 399 | return 0; |
| 400 | } |
| 401 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 402 | if (!show_addresses) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 403 | vlib_cli_output (vm, "%U\n", format_vnet_sw_interface, vnm, 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 404 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 405 | if (vec_len (sorted_sis) == 0) /* Get all interfaces */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 406 | { |
| 407 | /* Gather interfaces. */ |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 408 | sorted_sis = |
| 409 | vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 410 | _vec_len (sorted_sis) = 0; |
Dave Barach | 525c9d0 | 2018-05-26 10:48:55 -0400 | [diff] [blame] | 411 | /* *INDENT-OFF* */ |
Damjan Marion | b2c31b6 | 2020-12-13 21:47:40 +0100 | [diff] [blame] | 412 | pool_foreach (si, im->sw_interfaces) |
| 413 | { |
Dave Barach | 525c9d0 | 2018-05-26 10:48:55 -0400 | [diff] [blame] | 414 | int visible = vnet_swif_is_api_visible (si); |
| 415 | if (visible) |
Damjan Marion | b2c31b6 | 2020-12-13 21:47:40 +0100 | [diff] [blame] | 416 | vec_add1 (sorted_sis, si[0]); |
| 417 | } |
Ole Troan | d723161 | 2018-06-07 10:17:57 +0200 | [diff] [blame] | 418 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 419 | /* Sort by name. */ |
| 420 | vec_sort_with_function (sorted_sis, sw_interface_name_compare); |
| 421 | } |
| 422 | |
| 423 | if (show_addresses) |
| 424 | { |
| 425 | vec_foreach (si, sorted_sis) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 426 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 427 | ip4_main_t *im4 = &ip4_main; |
| 428 | ip6_main_t *im6 = &ip6_main; |
| 429 | ip_lookup_main_t *lm4 = &im4->lookup_main; |
| 430 | ip_lookup_main_t *lm6 = &im6->lookup_main; |
| 431 | ip_interface_address_t *ia = 0; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 432 | u32 fib_index4 = 0, fib_index6 = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 433 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 434 | if (vec_len (im4->fib_index_by_sw_if_index) > si->sw_if_index) |
| 435 | fib_index4 = vec_elt (im4->fib_index_by_sw_if_index, |
| 436 | si->sw_if_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 437 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 438 | if (vec_len (im6->fib_index_by_sw_if_index) > si->sw_if_index) |
| 439 | fib_index6 = vec_elt (im6->fib_index_by_sw_if_index, |
| 440 | si->sw_if_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 441 | |
John Lo | 4478d8e | 2018-01-12 17:15:25 -0500 | [diff] [blame] | 442 | ip4_fib_t *fib4 = ip4_fib_get (fib_index4); |
| 443 | ip6_fib_t *fib6 = ip6_fib_get (fib_index6); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 444 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 445 | if (si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED) |
| 446 | vlib_cli_output |
| 447 | (vm, "%U (%s): \n unnumbered, use %U", |
John Lo | 4478d8e | 2018-01-12 17:15:25 -0500 | [diff] [blame] | 448 | format_vnet_sw_if_index_name, vnm, si->sw_if_index, |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 449 | (si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? "up" : "dn", |
| 450 | format_vnet_sw_if_index_name, vnm, si->unnumbered_sw_if_index); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 451 | else |
John Lo | 4478d8e | 2018-01-12 17:15:25 -0500 | [diff] [blame] | 452 | vlib_cli_output |
| 453 | (vm, "%U (%s):", |
| 454 | format_vnet_sw_if_index_name, vnm, si->sw_if_index, |
| 455 | (si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? "up" : "dn"); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 456 | |
Eyal Bari | 942402b | 2017-07-26 11:57:04 +0300 | [diff] [blame] | 457 | /* Display any L2 info */ |
Neale Ranns | 47a3d99 | 2020-09-29 15:38:51 +0000 | [diff] [blame] | 458 | vlib_cli_output (vm, "%U", format_l2_input, si->sw_if_index); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 459 | |
John Lo | 4478d8e | 2018-01-12 17:15:25 -0500 | [diff] [blame] | 460 | /* *INDENT-OFF* */ |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 461 | /* Display any IP4 addressing info */ |
John Lo | 4478d8e | 2018-01-12 17:15:25 -0500 | [diff] [blame] | 462 | foreach_ip_interface_address (lm4, ia, si->sw_if_index, |
| 463 | 1 /* honor unnumbered */, |
| 464 | ({ |
| 465 | ip4_address_t *r4 = ip_interface_address_get_address (lm4, ia); |
Neale Ranns | d695333 | 2021-08-10 07:39:18 +0000 | [diff] [blame] | 466 | if (fib4->hash.table_id) |
| 467 | vlib_cli_output ( |
| 468 | vm, " L3 %U/%d ip4 table-id %d fib-idx %d", format_ip4_address, |
| 469 | r4, ia->address_length, fib4->hash.table_id, |
| 470 | ip4_fib_index_from_table_id (fib4->hash.table_id)); |
John Lo | 4478d8e | 2018-01-12 17:15:25 -0500 | [diff] [blame] | 471 | else |
| 472 | vlib_cli_output (vm, " L3 %U/%d", |
| 473 | format_ip4_address, r4, ia->address_length); |
| 474 | })); |
| 475 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 476 | |
John Lo | 4478d8e | 2018-01-12 17:15:25 -0500 | [diff] [blame] | 477 | /* *INDENT-OFF* */ |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 478 | /* Display any IP6 addressing info */ |
John Lo | 4478d8e | 2018-01-12 17:15:25 -0500 | [diff] [blame] | 479 | foreach_ip_interface_address (lm6, ia, si->sw_if_index, |
| 480 | 1 /* honor unnumbered */, |
| 481 | ({ |
| 482 | ip6_address_t *r6 = ip_interface_address_get_address (lm6, ia); |
| 483 | if (fib6->table_id) |
| 484 | vlib_cli_output (vm, " L3 %U/%d ip6 table-id %d fib-idx %d", |
| 485 | format_ip6_address, r6, ia->address_length, |
| 486 | fib6->table_id, |
| 487 | ip6_fib_index_from_table_id (fib6->table_id)); |
| 488 | else |
| 489 | vlib_cli_output (vm, " L3 %U/%d", |
| 490 | format_ip6_address, r6, ia->address_length); |
| 491 | })); |
| 492 | /* *INDENT-ON* */ |
Ole Troan | d723161 | 2018-06-07 10:17:57 +0200 | [diff] [blame] | 493 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 494 | } |
Ole Troan | d723161 | 2018-06-07 10:17:57 +0200 | [diff] [blame] | 495 | 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 Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 502 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 503 | done: |
Ole Troan | d723161 | 2018-06-07 10:17:57 +0200 | [diff] [blame] | 504 | vec_free (sorted_sis); |
| 505 | return error; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 506 | } |
| 507 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 508 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 509 | VLIB_CLI_COMMAND (show_sw_interfaces_command, static) = { |
Dave Barach | 13ad1f0 | 2017-03-26 19:36:18 -0400 | [diff] [blame] | 510 | .path = "show interface", |
Jon Loeliger | 9485d99 | 2019-11-08 15:05:23 -0600 | [diff] [blame] | 511 | .short_help = "show interface [address|addr|features|feat|vtr] [<interface> [<interface> [..]]] [verbose]", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 512 | .function = show_sw_interfaces, |
Steven Luong | c5fa2b8 | 2019-04-25 11:19:49 -0700 | [diff] [blame] | 513 | .is_mp_safe = 1, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 514 | }; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 515 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 516 | |
| 517 | /* Root of all interface commands. */ |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 518 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 519 | VLIB_CLI_COMMAND (vnet_cli_interface_command, static) = { |
| 520 | .path = "interface", |
| 521 | .short_help = "Interface commands", |
| 522 | }; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 523 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 524 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 525 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 526 | VLIB_CLI_COMMAND (vnet_cli_set_interface_command, static) = { |
| 527 | .path = "set interface", |
| 528 | .short_help = "Interface commands", |
| 529 | }; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 530 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 531 | |
| 532 | static clib_error_t * |
| 533 | clear_interface_counters (vlib_main_t * vm, |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 534 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 535 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 536 | vnet_main_t *vnm = vnet_get_main (); |
| 537 | vnet_interface_main_t *im = &vnm->interface_main; |
| 538 | vlib_simple_counter_main_t *sm; |
| 539 | vlib_combined_counter_main_t *cm; |
Dave Barach | 8fdde3c | 2019-05-17 10:46:40 -0400 | [diff] [blame] | 540 | int j, n_counters; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 541 | |
| 542 | n_counters = vec_len (im->combined_sw_if_counters); |
| 543 | |
| 544 | for (j = 0; j < n_counters; j++) |
| 545 | { |
Dave Barach | 8fdde3c | 2019-05-17 10:46:40 -0400 | [diff] [blame] | 546 | im = &vnm->interface_main; |
| 547 | cm = im->combined_sw_if_counters + j; |
| 548 | vlib_clear_combined_counters (cm); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | n_counters = vec_len (im->sw_if_counters); |
| 552 | |
| 553 | for (j = 0; j < n_counters; j++) |
| 554 | { |
Dave Barach | 8fdde3c | 2019-05-17 10:46:40 -0400 | [diff] [blame] | 555 | im = &vnm->interface_main; |
| 556 | sm = im->sw_if_counters + j; |
| 557 | vlib_clear_simple_counters (sm); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 558 | } |
| 559 | |
| 560 | return 0; |
| 561 | } |
| 562 | |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 563 | /*? |
| 564 | * Clear the statistics for all interfaces (statistics associated with the |
| 565 | * '<em>show interface</em>' command). |
| 566 | * |
| 567 | * @cliexpar |
| 568 | * Example of how to clear the statistics for all interfaces: |
| 569 | * @cliexcmd{clear interfaces} |
| 570 | ?*/ |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 571 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 572 | VLIB_CLI_COMMAND (clear_interface_counters_command, static) = { |
| 573 | .path = "clear interfaces", |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 574 | .short_help = "clear interfaces", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 575 | .function = clear_interface_counters, |
| 576 | }; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 577 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 578 | |
Chris Luke | 16bcf7d | 2016-09-01 14:31:46 -0400 | [diff] [blame] | 579 | /** |
| 580 | * Parse subinterface names. |
| 581 | * |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 582 | * The following subinterface syntax is supported. The first two are for |
| 583 | * backwards compatability: |
| 584 | * |
| 585 | * <intf-name> <id> |
| 586 | * - a subinterface with the name <intf-name>.<id>. The subinterface |
| 587 | * is a single dot1q vlan with vlan id <id> and exact-match semantics. |
| 588 | * |
| 589 | * <intf-name> <min_id>-<max_id> |
| 590 | * - a set of the above subinterfaces, repeating for each id |
| 591 | * in the range <min_id> to <max_id> |
| 592 | * |
| 593 | * In the following, exact-match semantics (i.e. the number of vlan tags on the |
| 594 | * packet must match the number of tags in the configuration) are used only if |
| 595 | * the keyword exact-match is present. Non-exact match is the default. |
| 596 | * |
| 597 | * <intf-name> <id> dot1q <outer_id> [exact-match] |
| 598 | * - a subinterface with the name <intf-name>.<id>. The subinterface |
| 599 | * is a single dot1q vlan with vlan id <outer_id>. |
| 600 | * |
| 601 | * <intf-name> <id> dot1q any [exact-match] |
| 602 | * - a subinterface with the name <intf-name>.<id>. The subinterface |
| 603 | * is a single dot1q vlan with any vlan id. |
| 604 | * |
| 605 | * <intf-name> <id> dot1q <outer_id> inner-dot1q <inner_id> [exact-match] |
| 606 | * - a subinterface with the name <intf-name>.<id>. The subinterface |
| 607 | * is a double dot1q vlan with outer vlan id <outer_id> and inner vlan id |
| 608 | * <inner_id>. |
| 609 | * |
| 610 | * <intf-name> <id> dot1q <outer_id> inner-dot1q any [exact-match] |
| 611 | * - a subinterface with the name <intf-name>.<id>. The subinterface |
| 612 | * is a double dot1q vlan with outer vlan id <id> and any inner vlan id. |
| 613 | * |
| 614 | * <intf-name> <id> dot1q any inner-dot1q any [exact-match] |
| 615 | * |
| 616 | * - a subinterface with the name <intf-name>.<id>. The subinterface |
| 617 | * is a double dot1q vlan with any outer vlan id and any inner vlan id. |
| 618 | * |
| 619 | * For each of the above CLI, there is a duplicate that uses the keyword |
| 620 | * "dot1ad" in place of the first "dot1q". These interfaces use ethertype |
| 621 | * 0x88ad in place of 0x8100 for the outer ethertype. Note that for double- |
| 622 | * tagged packets the inner ethertype is always 0x8100. Also note that |
| 623 | * the dot1q and dot1ad naming spaces are independent, so it is legal to |
| 624 | * have both "Gig3/0/0.1 dot1q 100" and "Gig3/0/0.2 dot1ad 100". For example: |
| 625 | * |
| 626 | * <intf-name> <id> dot1ad <outer_id> inner-dot1q <inner_id> [exact-match] |
| 627 | * - a subinterface with the name <intf-name>.<id>. The subinterface |
| 628 | * is a double dot1ad vlan with outer vlan id <outer_id> and inner vlan |
| 629 | * id <inner_id>. |
| 630 | * |
| 631 | * <intf-name> <id> untagged |
| 632 | * - a subinterface with the name <intf-name>.<id>. The subinterface |
| 633 | * has no vlan tags. Only one can be specified per interface. |
| 634 | * |
| 635 | * <intf-name> <id> default |
| 636 | * - a subinterface with the name <intf-name>.<id>. This is associated |
| 637 | * with a packet that did not match any other configured subinterface |
| 638 | * on this interface. Only one can be specified per interface. |
| 639 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 640 | |
| 641 | static clib_error_t * |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 642 | parse_vlan_sub_interfaces (unformat_input_t * input, |
| 643 | vnet_sw_interface_t * template) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 644 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 645 | clib_error_t *error = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 646 | u32 inner_vlan, outer_vlan; |
| 647 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 648 | if (unformat (input, "any inner-dot1q any")) |
| 649 | { |
| 650 | template->sub.eth.flags.two_tags = 1; |
| 651 | template->sub.eth.flags.outer_vlan_id_any = 1; |
| 652 | template->sub.eth.flags.inner_vlan_id_any = 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 653 | } |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 654 | else if (unformat (input, "any")) |
| 655 | { |
| 656 | template->sub.eth.flags.one_tag = 1; |
| 657 | template->sub.eth.flags.outer_vlan_id_any = 1; |
| 658 | } |
| 659 | else if (unformat (input, "%d inner-dot1q any", &outer_vlan)) |
| 660 | { |
| 661 | template->sub.eth.flags.two_tags = 1; |
| 662 | template->sub.eth.flags.inner_vlan_id_any = 1; |
| 663 | template->sub.eth.outer_vlan_id = outer_vlan; |
| 664 | } |
| 665 | else if (unformat (input, "%d inner-dot1q %d", &outer_vlan, &inner_vlan)) |
| 666 | { |
| 667 | template->sub.eth.flags.two_tags = 1; |
| 668 | template->sub.eth.outer_vlan_id = outer_vlan; |
| 669 | template->sub.eth.inner_vlan_id = inner_vlan; |
| 670 | } |
| 671 | else if (unformat (input, "%d", &outer_vlan)) |
| 672 | { |
| 673 | template->sub.eth.flags.one_tag = 1; |
| 674 | template->sub.eth.outer_vlan_id = outer_vlan; |
| 675 | } |
| 676 | else |
| 677 | { |
| 678 | error = clib_error_return (0, "expected dot1q config, got `%U'", |
| 679 | format_unformat_error, input); |
| 680 | goto done; |
| 681 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 682 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 683 | if (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 684 | { |
| 685 | if (unformat (input, "exact-match")) |
| 686 | { |
| 687 | template->sub.eth.flags.exact_match = 1; |
| 688 | } |
| 689 | } |
| 690 | |
| 691 | done: |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 692 | return error; |
| 693 | } |
| 694 | |
| 695 | static clib_error_t * |
| 696 | create_sub_interfaces (vlib_main_t * vm, |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 697 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 698 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 699 | vnet_main_t *vnm = vnet_get_main (); |
| 700 | clib_error_t *error = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 701 | u32 hw_if_index, sw_if_index; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 702 | vnet_hw_interface_t *hi; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 703 | u32 id, id_min, id_max; |
| 704 | vnet_sw_interface_t template; |
| 705 | |
| 706 | hw_if_index = ~0; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 707 | if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 708 | { |
| 709 | error = clib_error_return (0, "unknown interface `%U'", |
| 710 | format_unformat_error, input); |
| 711 | goto done; |
| 712 | } |
| 713 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 714 | clib_memset (&template, 0, sizeof (template)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 715 | template.sub.eth.raw_flags = 0; |
| 716 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 717 | if (unformat (input, "%d default", &id_min)) |
| 718 | { |
| 719 | id_max = id_min; |
| 720 | template.sub.eth.flags.default_sub = 1; |
| 721 | } |
| 722 | else if (unformat (input, "%d untagged", &id_min)) |
| 723 | { |
| 724 | id_max = id_min; |
| 725 | template.sub.eth.flags.no_tags = 1; |
| 726 | template.sub.eth.flags.exact_match = 1; |
| 727 | } |
| 728 | else if (unformat (input, "%d dot1q", &id_min)) |
| 729 | { |
| 730 | /* parse dot1q config */ |
| 731 | id_max = id_min; |
| 732 | error = parse_vlan_sub_interfaces (input, &template); |
| 733 | if (error) |
| 734 | goto done; |
| 735 | } |
| 736 | else if (unformat (input, "%d dot1ad", &id_min)) |
| 737 | { |
| 738 | /* parse dot1ad config */ |
| 739 | id_max = id_min; |
| 740 | template.sub.eth.flags.dot1ad = 1; |
| 741 | error = parse_vlan_sub_interfaces (input, &template); |
| 742 | if (error) |
| 743 | goto done; |
| 744 | } |
| 745 | else if (unformat (input, "%d-%d", &id_min, &id_max)) |
| 746 | { |
| 747 | template.sub.eth.flags.one_tag = 1; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 748 | template.sub.eth.flags.exact_match = 1; |
| 749 | if (id_min > id_max) |
| 750 | goto id_error; |
| 751 | } |
| 752 | else if (unformat (input, "%d", &id_min)) |
| 753 | { |
| 754 | id_max = id_min; |
| 755 | template.sub.eth.flags.one_tag = 1; |
| 756 | template.sub.eth.outer_vlan_id = id_min; |
| 757 | template.sub.eth.flags.exact_match = 1; |
| 758 | } |
| 759 | else |
| 760 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 761 | id_error: |
| 762 | error = clib_error_return (0, "expected ID or ID MIN-MAX, got `%U'", |
| 763 | format_unformat_error, input); |
| 764 | goto done; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 765 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 766 | |
| 767 | hi = vnet_get_hw_interface (vnm, hw_if_index); |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 768 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 769 | if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE) |
| 770 | { |
| 771 | error = |
| 772 | clib_error_return (0, |
| 773 | "not allowed as %v belong to a BondEthernet interface", |
| 774 | hi->name); |
| 775 | goto done; |
| 776 | } |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 777 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 778 | for (id = id_min; id <= id_max; id++) |
| 779 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 780 | uword *p; |
| 781 | vnet_interface_main_t *im = &vnm->interface_main; |
| 782 | u64 sup_and_sub_key = ((u64) (hi->sw_if_index) << 32) | (u64) id; |
| 783 | u64 *kp; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 784 | |
| 785 | p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key); |
| 786 | if (p) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 787 | { |
| 788 | if (CLIB_DEBUG > 0) |
| 789 | clib_warning ("sup sw_if_index %d, sub id %d already exists\n", |
| 790 | hi->sw_if_index, id); |
| 791 | continue; |
| 792 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 793 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 794 | template.type = VNET_SW_INTERFACE_TYPE_SUB; |
Eyal Bari | c5b1360 | 2016-11-24 19:42:43 +0200 | [diff] [blame] | 795 | template.flood_class = VNET_FLOOD_CLASS_NORMAL; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 796 | template.sup_sw_if_index = hi->sw_if_index; |
| 797 | template.sub.id = id; |
Eyal Bari | a4509cf | 2016-09-26 09:24:09 +0300 | [diff] [blame] | 798 | if (id_min < id_max) |
| 799 | template.sub.eth.outer_vlan_id = id; |
| 800 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 801 | error = vnet_create_sw_interface (vnm, &template, &sw_if_index); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 802 | if (error) |
| 803 | goto done; |
Dave Barach | 16ad6ae | 2016-07-28 17:55:30 -0400 | [diff] [blame] | 804 | |
Jon Loeliger | b22e1f0 | 2019-12-19 09:03:52 -0600 | [diff] [blame] | 805 | kp = clib_mem_alloc (sizeof (*kp)); |
| 806 | *kp = sup_and_sub_key; |
| 807 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 808 | hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index); |
| 809 | hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 810 | vlib_cli_output (vm, "%U\n", format_vnet_sw_if_index_name, |
| 811 | vnet_get_main (), sw_if_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 812 | } |
| 813 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 814 | done: |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 815 | return error; |
| 816 | } |
| 817 | |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 818 | /*? |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 819 | * This command is used to add VLAN IDs to interfaces, also known as subinterfaces. |
| 820 | * The primary input to this command is the '<em>interface</em>' and '<em>subId</em>' |
| 821 | * (subinterface Id) parameters. If no additional VLAN ID is provide, the VLAN ID is |
| 822 | * assumed to be the '<em>subId</em>'. The VLAN ID and '<em>subId</em>' can be different, |
| 823 | * but this is not recommended. |
| 824 | * |
| 825 | * This command has several variations: |
| 826 | * - <b>create sub-interfaces <interface> <subId></b> - Create a subinterface to |
| 827 | * process packets with a given 802.1q VLAN ID (same value as the '<em>subId</em>'). |
| 828 | * |
| 829 | * - <b>create sub-interfaces <interface> <subId> default</b> - Adding the |
| 830 | * '<em>default</em>' parameter indicates that packets with VLAN IDs that do not |
| 831 | * match any other subinterfaces should be sent to this subinterface. |
| 832 | * |
| 833 | * - <b>create sub-interfaces <interface> <subId> untagged</b> - Adding the |
| 834 | * '<em>untagged</em>' parameter indicates that packets no VLAN IDs should be sent |
| 835 | * to this subinterface. |
| 836 | * |
| 837 | * - <b>create sub-interfaces <interface> <subId>-<subId></b> - Create a range of |
| 838 | * subinterfaces to handle a range of VLAN IDs. |
| 839 | * |
| 840 | * - <b>create sub-interfaces <interface> <subId> dot1q|dot1ad <vlanId>|any [exact-match]</b> - |
Paul Vinciguerra | bdc0e6b | 2018-09-22 05:32:50 -0700 | [diff] [blame] | 841 | * Use this command to specify the outer VLAN ID, to either be explicit or to make the |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 842 | * VLAN ID different from the '<em>subId</em>'. |
| 843 | * |
| 844 | * - <b>create sub-interfaces <interface> <subId> dot1q|dot1ad <vlanId>|any inner-dot1q |
| 845 | * <vlanId>|any [exact-match]</b> - Use this command to specify the outer VLAN ID and |
Paul Vinciguerra | bdc0e6b | 2018-09-22 05:32:50 -0700 | [diff] [blame] | 846 | * the inner VLAN ID. |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 847 | * |
Paul Vinciguerra | bdc0e6b | 2018-09-22 05:32:50 -0700 | [diff] [blame] | 848 | * When '<em>dot1q</em>' or '<em>dot1ad</em>' is explicitly entered, subinterfaces |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 849 | * can be configured as either exact-match or non-exact match. Non-exact match is the CLI |
| 850 | * default. If '<em>exact-match</em>' is specified, packets must have the same number of |
| 851 | * VLAN tags as the configuration. For non-exact-match, packets must at least that number |
| 852 | * of tags. L3 (routed) interfaces must be configured as exact-match. L2 interfaces are |
| 853 | * typically configured as non-exact-match. If '<em>dot1q</em>' or '<em>dot1ad</em>' is NOT |
| 854 | * entered, then the default behavior is exact-match. |
| 855 | * |
| 856 | * Use the '<em>show interface</em>' command to display all subinterfaces. |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 857 | * |
| 858 | * @cliexpar |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 859 | * @parblock |
| 860 | * Example of how to create a VLAN subinterface 11 to process packets on 802.1q VLAN ID 11: |
| 861 | * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11} |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 862 | * |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 863 | * The previous example is shorthand and is equivalent to: |
| 864 | * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11 dot1q 11 exact-match} |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 865 | * |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 866 | * |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 867 | * Example of how to create a subinterface number that is different from the VLAN ID: |
| 868 | * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11 dot1q 100} |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 869 | * |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 870 | * |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 871 | * Examples of how to create q-in-q and q-in-any subinterfaces: |
| 872 | * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11 dot1q 100 inner-dot1q 200} |
| 873 | * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 12 dot1q 100 inner-dot1q any} |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 874 | * |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 875 | * Examples of how to create dot1ad interfaces: |
| 876 | * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11 dot1ad 11} |
| 877 | * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 12 dot1ad 100 inner-dot1q 200} |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 878 | * |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 879 | * |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 880 | * Examples of '<em>exact-match</em>' versus non-exact match. A packet with |
| 881 | * outer VLAN 100 and inner VLAN 200 would match this interface, because the default |
| 882 | * is non-exact match: |
| 883 | * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 5 dot1q 100} |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 884 | * |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 885 | * However, the same packet would NOT match this interface because '<em>exact-match</em>' |
| 886 | * is specified and only one VLAN is configured, but packet contains two VLANs: |
| 887 | * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 5 dot1q 100 exact-match} |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 888 | * |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 889 | * |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 890 | * Example of how to created a subinterface to process untagged packets: |
| 891 | * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 5 untagged} |
| 892 | * |
| 893 | * Example of how to created a subinterface to process any packet with a VLAN ID that |
| 894 | * does not match any other subinterface: |
| 895 | * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 7 default} |
| 896 | * |
| 897 | * When subinterfaces are created, they are in the down state. Example of how to |
| 898 | * enable a newly created subinterface: |
| 899 | * @cliexcmd{set interface GigabitEthernet2/0/0.7 up} |
| 900 | * @endparblock |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 901 | ?*/ |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 902 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 903 | VLIB_CLI_COMMAND (create_sub_interfaces_command, static) = { |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 904 | .path = "create sub-interfaces", |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 905 | .short_help = "create sub-interfaces <interface> " |
| 906 | "{<subId> [default|untagged]} | " |
| 907 | "{<subId>-<subId>} | " |
| 908 | "{<subId> dot1q|dot1ad <vlanId>|any [inner-dot1q <vlanId>|any] [exact-match]}", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 909 | .function = create_sub_interfaces, |
| 910 | }; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 911 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 912 | |
| 913 | static clib_error_t * |
| 914 | set_state (vlib_main_t * vm, |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 915 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 916 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 917 | vnet_main_t *vnm = vnet_get_main (); |
| 918 | clib_error_t *error; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 919 | u32 sw_if_index, flags; |
| 920 | |
| 921 | sw_if_index = ~0; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 922 | if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 923 | { |
| 924 | error = clib_error_return (0, "unknown interface `%U'", |
| 925 | format_unformat_error, input); |
| 926 | goto done; |
| 927 | } |
| 928 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 929 | if (!unformat (input, "%U", unformat_vnet_sw_interface_flags, &flags)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 930 | { |
| 931 | error = clib_error_return (0, "unknown flags `%U'", |
| 932 | format_unformat_error, input); |
| 933 | goto done; |
| 934 | } |
| 935 | |
| 936 | error = vnet_sw_interface_set_flags (vnm, sw_if_index, flags); |
| 937 | if (error) |
| 938 | goto done; |
| 939 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 940 | done: |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 941 | return error; |
| 942 | } |
| 943 | |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 944 | /*? |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 945 | * This command is used to change the admin state (up/down) of an interface. |
| 946 | * |
| 947 | * If an interface is down, the optional '<em>punt</em>' flag can also be set. |
| 948 | * The '<em>punt</em>' flag implies the interface is disabled for forwarding |
| 949 | * but punt all traffic to slow-path. Use the '<em>enable</em>' flag to clear |
| 950 | * '<em>punt</em>' flag (interface is still down). |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 951 | * |
| 952 | * @cliexpar |
Nathan Skrzypczak | 2c77ae4 | 2021-09-29 15:36:51 +0200 | [diff] [blame] | 953 | * Example of how to configure the admin state of an interface to |
| 954 | '<em>up</em>': |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 955 | * @cliexcmd{set interface state GigabitEthernet2/0/0 up} |
Nathan Skrzypczak | 2c77ae4 | 2021-09-29 15:36:51 +0200 | [diff] [blame] | 956 | * Example of how to configure the admin state of an interface to |
| 957 | '<em>down</em>': |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 958 | * @cliexcmd{set interface state GigabitEthernet2/0/0 down} |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 959 | ?*/ |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 960 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 961 | VLIB_CLI_COMMAND (set_state_command, static) = { |
| 962 | .path = "set interface state", |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 963 | .short_help = "set interface state <interface> [up|down|punt|enable]", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 964 | .function = set_state, |
| 965 | }; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 966 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 967 | |
| 968 | static clib_error_t * |
| 969 | set_unnumbered (vlib_main_t * vm, |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 970 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 971 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 972 | vnet_main_t *vnm = vnet_get_main (); |
Neale Ranns | 2ae2bc5 | 2018-03-16 03:22:39 -0700 | [diff] [blame] | 973 | u32 unnumbered_sw_if_index = ~0; |
| 974 | u32 inherit_from_sw_if_index = ~0; |
| 975 | int enable = 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 976 | |
Igor Mikhailov (imichail) | ab3e42b | 2016-09-25 15:11:53 -0700 | [diff] [blame] | 977 | if (unformat (input, "%U use %U", |
| 978 | unformat_vnet_sw_interface, vnm, &unnumbered_sw_if_index, |
| 979 | unformat_vnet_sw_interface, vnm, &inherit_from_sw_if_index)) |
Neale Ranns | 2ae2bc5 | 2018-03-16 03:22:39 -0700 | [diff] [blame] | 980 | enable = 1; |
Igor Mikhailov (imichail) | ab3e42b | 2016-09-25 15:11:53 -0700 | [diff] [blame] | 981 | else if (unformat (input, "del %U", |
| 982 | unformat_vnet_sw_interface, vnm, |
| 983 | &unnumbered_sw_if_index)) |
Neale Ranns | 2ae2bc5 | 2018-03-16 03:22:39 -0700 | [diff] [blame] | 984 | enable = 0; |
Igor Mikhailov (imichail) | ab3e42b | 2016-09-25 15:11:53 -0700 | [diff] [blame] | 985 | else |
| 986 | return clib_error_return (0, "parse error '%U'", |
| 987 | format_unformat_error, input); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 988 | |
Neale Ranns | 2ae2bc5 | 2018-03-16 03:22:39 -0700 | [diff] [blame] | 989 | if (~0 == unnumbered_sw_if_index) |
| 990 | return clib_error_return (0, "Specify the unnumbered interface"); |
| 991 | if (enable && ~0 == inherit_from_sw_if_index) |
Paul Vinciguerra | bdc0e6b | 2018-09-22 05:32:50 -0700 | [diff] [blame] | 992 | return clib_error_return (0, "When enabling unnumbered specify the" |
Neale Ranns | 2ae2bc5 | 2018-03-16 03:22:39 -0700 | [diff] [blame] | 993 | " IP enabled interface that it uses"); |
Neale Ranns | 898273f | 2017-03-18 02:57:38 -0700 | [diff] [blame] | 994 | |
Stanislav Zaikin | 328b5da | 2021-07-15 16:27:29 +0200 | [diff] [blame] | 995 | int rv = vnet_sw_interface_update_unnumbered ( |
| 996 | unnumbered_sw_if_index, inherit_from_sw_if_index, enable); |
| 997 | |
| 998 | switch (rv) |
| 999 | { |
| 1000 | case 0: |
| 1001 | break; |
| 1002 | |
| 1003 | case VNET_API_ERROR_UNEXPECTED_INTF_STATE: |
| 1004 | return clib_error_return ( |
| 1005 | 0, |
| 1006 | "When enabling unnumbered both interfaces must be in the same tables"); |
| 1007 | |
| 1008 | default: |
| 1009 | return clib_error_return ( |
| 1010 | 0, "vnet_sw_interface_update_unnumbered returned %d", rv); |
| 1011 | } |
Neale Ranns | 898273f | 2017-03-18 02:57:38 -0700 | [diff] [blame] | 1012 | |
Neale Ranns | 2ae2bc5 | 2018-03-16 03:22:39 -0700 | [diff] [blame] | 1013 | return (NULL); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1014 | } |
| 1015 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1016 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1017 | VLIB_CLI_COMMAND (set_unnumbered_command, static) = { |
| 1018 | .path = "set interface unnumbered", |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 1019 | .short_help = "set interface unnumbered [<interface> use <interface> | del <interface>]", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1020 | .function = set_unnumbered, |
| 1021 | }; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1022 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1023 | |
| 1024 | |
| 1025 | |
| 1026 | static clib_error_t * |
| 1027 | set_hw_class (vlib_main_t * vm, |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1028 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1029 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1030 | vnet_main_t *vnm = vnet_get_main (); |
| 1031 | vnet_interface_main_t *im = &vnm->interface_main; |
| 1032 | clib_error_t *error; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1033 | u32 hw_if_index, hw_class_index; |
| 1034 | |
| 1035 | hw_if_index = ~0; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1036 | if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1037 | { |
| 1038 | error = clib_error_return (0, "unknown hardware interface `%U'", |
| 1039 | format_unformat_error, input); |
| 1040 | goto done; |
| 1041 | } |
| 1042 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1043 | if (!unformat_user (input, unformat_hash_string, |
| 1044 | im->hw_interface_class_by_name, &hw_class_index)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1045 | { |
| 1046 | error = clib_error_return (0, "unknown hardware class `%U'", |
| 1047 | format_unformat_error, input); |
| 1048 | goto done; |
| 1049 | } |
| 1050 | |
| 1051 | error = vnet_hw_interface_set_class (vnm, hw_if_index, hw_class_index); |
| 1052 | if (error) |
| 1053 | goto done; |
| 1054 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1055 | done: |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1056 | return error; |
| 1057 | } |
| 1058 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1059 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1060 | VLIB_CLI_COMMAND (set_hw_class_command, static) = { |
| 1061 | .path = "set interface hw-class", |
| 1062 | .short_help = "Set interface hardware class", |
| 1063 | .function = set_hw_class, |
| 1064 | }; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1065 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1066 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1067 | static clib_error_t * |
| 1068 | vnet_interface_cli_init (vlib_main_t * vm) |
| 1069 | { |
| 1070 | return 0; |
| 1071 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1072 | |
| 1073 | VLIB_INIT_FUNCTION (vnet_interface_cli_init); |
| 1074 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1075 | static clib_error_t * |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1076 | renumber_interface_command_fn (vlib_main_t * vm, |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1077 | unformat_input_t * input, |
| 1078 | vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1079 | { |
| 1080 | u32 hw_if_index; |
| 1081 | u32 new_dev_instance; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1082 | vnet_main_t *vnm = vnet_get_main (); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1083 | int rv; |
| 1084 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1085 | if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1086 | return clib_error_return (0, "unknown hardware interface `%U'", |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1087 | format_unformat_error, input); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1088 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1089 | if (!unformat (input, "%d", &new_dev_instance)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1090 | return clib_error_return (0, "new dev instance missing"); |
| 1091 | |
| 1092 | rv = vnet_interface_name_renumber (hw_if_index, new_dev_instance); |
| 1093 | |
| 1094 | switch (rv) |
| 1095 | { |
| 1096 | case 0: |
| 1097 | break; |
| 1098 | |
| 1099 | default: |
| 1100 | return clib_error_return (0, "vnet_interface_name_renumber returned %d", |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1101 | rv); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1102 | |
| 1103 | } |
| 1104 | |
| 1105 | return 0; |
| 1106 | } |
| 1107 | |
| 1108 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1109 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1110 | VLIB_CLI_COMMAND (renumber_interface_command, static) = { |
| 1111 | .path = "renumber interface", |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 1112 | .short_help = "renumber interface <interface> <new-dev-instance>", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1113 | .function = renumber_interface_command_fn, |
| 1114 | }; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1115 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1116 | |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1117 | static clib_error_t * |
| 1118 | promiscuous_cmd (vlib_main_t * vm, |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1119 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1120 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1121 | vnet_main_t *vnm = vnet_get_main (); |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1122 | u32 hw_if_index; |
| 1123 | u32 flags = ETHERNET_INTERFACE_FLAG_ACCEPT_ALL; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1124 | ethernet_main_t *em = ðernet_main; |
| 1125 | ethernet_interface_t *eif; |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1126 | |
| 1127 | if (unformat (input, "on %U", |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1128 | unformat_vnet_hw_interface, vnm, &hw_if_index)) |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1129 | ; |
| 1130 | else if (unformat (input, "off %U", |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1131 | unformat_ethernet_interface, vnm, &hw_if_index)) |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1132 | flags = 0; |
| 1133 | else |
| 1134 | return clib_error_return (0, "unknown input `%U'", |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1135 | format_unformat_error, input); |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1136 | |
| 1137 | eif = ethernet_get_interface (em, hw_if_index); |
| 1138 | if (!eif) |
| 1139 | return clib_error_return (0, "not supported"); |
| 1140 | |
| 1141 | ethernet_set_flags (vnm, hw_if_index, flags); |
| 1142 | return 0; |
| 1143 | } |
| 1144 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1145 | /* *INDENT-OFF* */ |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1146 | VLIB_CLI_COMMAND (set_interface_promiscuous_cmd, static) = { |
| 1147 | .path = "set interface promiscuous", |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 1148 | .short_help = "set interface promiscuous [on|off] <interface>", |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1149 | .function = promiscuous_cmd, |
| 1150 | }; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1151 | /* *INDENT-ON* */ |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1152 | |
| 1153 | static clib_error_t * |
| 1154 | mtu_cmd (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) |
| 1155 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1156 | vnet_main_t *vnm = vnet_get_main (); |
Ole Troan | d723161 | 2018-06-07 10:17:57 +0200 | [diff] [blame] | 1157 | u32 hw_if_index, sw_if_index, mtu; |
Damjan Marion | fe7d4a2 | 2018-04-13 19:43:39 +0200 | [diff] [blame] | 1158 | ethernet_main_t *em = ðernet_main; |
Ole Troan | d723161 | 2018-06-07 10:17:57 +0200 | [diff] [blame] | 1159 | u32 mtus[VNET_N_MTU] = { 0, 0, 0, 0 }; |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1160 | |
Damjan Marion | fe7d4a2 | 2018-04-13 19:43:39 +0200 | [diff] [blame] | 1161 | if (unformat (input, "%d %U", &mtu, |
| 1162 | unformat_vnet_hw_interface, vnm, &hw_if_index)) |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1163 | { |
Ole Troan | d723161 | 2018-06-07 10:17:57 +0200 | [diff] [blame] | 1164 | /* |
| 1165 | * Change physical MTU on interface. Only supported for Ethernet |
| 1166 | * interfaces |
| 1167 | */ |
Damjan Marion | fe7d4a2 | 2018-04-13 19:43:39 +0200 | [diff] [blame] | 1168 | vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, hw_if_index); |
| 1169 | ethernet_interface_t *eif = ethernet_get_interface (em, hw_if_index); |
| 1170 | |
| 1171 | if (!eif) |
| 1172 | return clib_error_return (0, "not supported"); |
| 1173 | |
| 1174 | if (mtu < hi->min_supported_packet_bytes) |
| 1175 | return clib_error_return (0, "Invalid mtu (%d): " |
| 1176 | "must be >= min pkt bytes (%d)", mtu, |
| 1177 | hi->min_supported_packet_bytes); |
| 1178 | |
| 1179 | if (mtu > hi->max_supported_packet_bytes) |
| 1180 | return clib_error_return (0, "Invalid mtu (%d): must be <= (%d)", mtu, |
| 1181 | hi->max_supported_packet_bytes); |
| 1182 | |
| 1183 | vnet_hw_interface_set_mtu (vnm, hw_if_index, mtu); |
Ole Troan | d723161 | 2018-06-07 10:17:57 +0200 | [diff] [blame] | 1184 | goto done; |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1185 | } |
Ole Troan | d723161 | 2018-06-07 10:17:57 +0200 | [diff] [blame] | 1186 | else if (unformat (input, "packet %d %U", &mtu, |
| 1187 | unformat_vnet_sw_interface, vnm, &sw_if_index)) |
| 1188 | /* Set default packet MTU (including L3 header */ |
| 1189 | mtus[VNET_MTU_L3] = mtu; |
| 1190 | else if (unformat (input, "ip4 %d %U", &mtu, |
| 1191 | unformat_vnet_sw_interface, vnm, &sw_if_index)) |
| 1192 | mtus[VNET_MTU_IP4] = mtu; |
| 1193 | else if (unformat (input, "ip6 %d %U", &mtu, |
| 1194 | unformat_vnet_sw_interface, vnm, &sw_if_index)) |
| 1195 | mtus[VNET_MTU_IP6] = mtu; |
| 1196 | else if (unformat (input, "mpls %d %U", &mtu, |
| 1197 | unformat_vnet_sw_interface, vnm, &sw_if_index)) |
| 1198 | mtus[VNET_MTU_MPLS] = mtu; |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1199 | else |
Damjan Marion | fe7d4a2 | 2018-04-13 19:43:39 +0200 | [diff] [blame] | 1200 | return clib_error_return (0, "unknown input `%U'", |
| 1201 | format_unformat_error, input); |
Ole Troan | d723161 | 2018-06-07 10:17:57 +0200 | [diff] [blame] | 1202 | |
| 1203 | vnet_sw_interface_set_protocol_mtu (vnm, sw_if_index, mtus); |
| 1204 | |
| 1205 | done: |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1206 | return 0; |
| 1207 | } |
| 1208 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1209 | /* *INDENT-OFF* */ |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1210 | VLIB_CLI_COMMAND (set_interface_mtu_cmd, static) = { |
| 1211 | .path = "set interface mtu", |
Ole Troan | d723161 | 2018-06-07 10:17:57 +0200 | [diff] [blame] | 1212 | .short_help = "set interface mtu [packet|ip4|ip6|mpls] <value> <interface>", |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1213 | .function = mtu_cmd, |
| 1214 | }; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1215 | /* *INDENT-ON* */ |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1216 | |
Pavel Kotucek | c631f2d | 2016-09-26 10:40:02 +0200 | [diff] [blame] | 1217 | static clib_error_t * |
Matthew Smith | e0792fd | 2019-07-12 11:48:24 -0500 | [diff] [blame] | 1218 | show_interface_sec_mac_addr_fn (vlib_main_t * vm, unformat_input_t * input, |
| 1219 | vlib_cli_command_t * cmd) |
| 1220 | { |
| 1221 | vnet_main_t *vnm = vnet_get_main (); |
| 1222 | vnet_interface_main_t *im = &vnm->interface_main; |
| 1223 | ethernet_main_t *em = ðernet_main; |
| 1224 | u32 sw_if_index = ~0; |
| 1225 | vnet_sw_interface_t *si, *sorted_sis = 0; |
| 1226 | |
| 1227 | if (unformat (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index)) |
| 1228 | { |
| 1229 | si = pool_elt_at_index (im->sw_interfaces, sw_if_index); |
| 1230 | vec_add1 (sorted_sis, si[0]); |
| 1231 | } |
| 1232 | |
| 1233 | /* if an interface name was not passed, get all interfaces */ |
| 1234 | if (vec_len (sorted_sis) == 0) |
| 1235 | { |
| 1236 | sorted_sis = |
| 1237 | vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces)); |
| 1238 | _vec_len (sorted_sis) = 0; |
| 1239 | /* *INDENT-OFF* */ |
Damjan Marion | b2c31b6 | 2020-12-13 21:47:40 +0100 | [diff] [blame] | 1240 | pool_foreach (si, im->sw_interfaces) |
| 1241 | { |
Matthew Smith | e0792fd | 2019-07-12 11:48:24 -0500 | [diff] [blame] | 1242 | int visible = vnet_swif_is_api_visible (si); |
| 1243 | if (visible) |
Damjan Marion | b2c31b6 | 2020-12-13 21:47:40 +0100 | [diff] [blame] | 1244 | vec_add1 (sorted_sis, si[0]); |
| 1245 | } |
Matthew Smith | e0792fd | 2019-07-12 11:48:24 -0500 | [diff] [blame] | 1246 | /* *INDENT-ON* */ |
| 1247 | /* Sort by name. */ |
| 1248 | vec_sort_with_function (sorted_sis, sw_interface_name_compare); |
| 1249 | } |
| 1250 | |
| 1251 | vec_foreach (si, sorted_sis) |
| 1252 | { |
| 1253 | vnet_sw_interface_t *sup_si; |
| 1254 | ethernet_interface_t *ei; |
| 1255 | |
| 1256 | sup_si = vnet_get_sup_sw_interface (vnm, si->sw_if_index); |
| 1257 | ei = ethernet_get_interface (em, sup_si->hw_if_index); |
| 1258 | |
| 1259 | vlib_cli_output (vm, "%U (%s):", |
| 1260 | format_vnet_sw_if_index_name, vnm, si->sw_if_index, |
| 1261 | (si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? |
| 1262 | "up" : "dn"); |
| 1263 | |
| 1264 | if (ei && ei->secondary_addrs) |
| 1265 | { |
Benoît Ganne | b44c77d | 2020-10-20 16:24:17 +0200 | [diff] [blame] | 1266 | ethernet_interface_address_t *sec_addr; |
Matthew Smith | e0792fd | 2019-07-12 11:48:24 -0500 | [diff] [blame] | 1267 | |
| 1268 | vec_foreach (sec_addr, ei->secondary_addrs) |
| 1269 | { |
Benoît Ganne | b44c77d | 2020-10-20 16:24:17 +0200 | [diff] [blame] | 1270 | vlib_cli_output (vm, " %U", format_mac_address_t, &sec_addr->mac); |
Matthew Smith | e0792fd | 2019-07-12 11:48:24 -0500 | [diff] [blame] | 1271 | } |
| 1272 | } |
| 1273 | } |
| 1274 | |
| 1275 | vec_free (sorted_sis); |
| 1276 | return 0; |
| 1277 | } |
| 1278 | |
| 1279 | /*? |
| 1280 | * This command is used to display interface secondary mac addresses. |
| 1281 | * |
| 1282 | * @cliexpar |
| 1283 | * Example of how to display interface secondary mac addresses: |
| 1284 | * @cliexstart{show interface secondary-mac-address} |
| 1285 | * @cliexend |
| 1286 | ?*/ |
| 1287 | /* *INDENT-OFF* */ |
| 1288 | VLIB_CLI_COMMAND (show_interface_sec_mac_addr, static) = { |
| 1289 | .path = "show interface secondary-mac-address", |
| 1290 | .short_help = "show interface secondary-mac-address [<interface>]", |
| 1291 | .function = show_interface_sec_mac_addr_fn, |
| 1292 | }; |
| 1293 | /* *INDENT-ON* */ |
| 1294 | |
| 1295 | static clib_error_t * |
| 1296 | interface_add_del_mac_address (vlib_main_t * vm, unformat_input_t * input, |
| 1297 | vlib_cli_command_t * cmd) |
| 1298 | { |
| 1299 | vnet_main_t *vnm = vnet_get_main (); |
| 1300 | vnet_sw_interface_t *si = NULL; |
| 1301 | clib_error_t *error = 0; |
| 1302 | u32 sw_if_index = ~0; |
| 1303 | u8 mac[6] = { 0 }; |
| 1304 | u8 is_add, is_del; |
| 1305 | |
| 1306 | is_add = is_del = 0; |
| 1307 | |
| 1308 | if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index)) |
| 1309 | { |
| 1310 | error = clib_error_return (0, "unknown interface `%U'", |
| 1311 | format_unformat_error, input); |
| 1312 | goto done; |
| 1313 | } |
| 1314 | if (!unformat_user (input, unformat_ethernet_address, mac)) |
| 1315 | { |
| 1316 | error = clib_error_return (0, "expected mac address `%U'", |
| 1317 | format_unformat_error, input); |
| 1318 | goto done; |
| 1319 | } |
| 1320 | |
| 1321 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 1322 | { |
| 1323 | if (unformat (input, "add")) |
| 1324 | is_add = 1; |
| 1325 | else if (unformat (input, "del")) |
| 1326 | is_del = 1; |
| 1327 | else |
| 1328 | break; |
| 1329 | } |
| 1330 | |
| 1331 | if (is_add == is_del) |
| 1332 | { |
| 1333 | error = clib_error_return (0, "must choose one of add or del"); |
| 1334 | goto done; |
| 1335 | } |
| 1336 | |
| 1337 | si = vnet_get_sw_interface (vnm, sw_if_index); |
| 1338 | error = |
| 1339 | vnet_hw_interface_add_del_mac_address (vnm, si->hw_if_index, mac, is_add); |
| 1340 | |
| 1341 | done: |
| 1342 | return error; |
| 1343 | } |
| 1344 | |
| 1345 | /*? |
| 1346 | * The '<em>set interface secondary-mac-address </em>' command allows adding |
| 1347 | * or deleting extra MAC addresses on a given interface without changing the |
| 1348 | * default MAC address. This could allow packets sent to these MAC addresses |
| 1349 | * to be received without setting the interface to promiscuous mode. |
| 1350 | * Not all interfaces support this operation. The ones that do are mostly |
| 1351 | * hardware NICs, though virtio does also. |
| 1352 | * |
| 1353 | * @cliexpar |
| 1354 | * @parblock |
| 1355 | * Example of how to add a secondary MAC Address on an interface: |
| 1356 | * @cliexcmd{set interface secondary-mac-address GigabitEthernet0/8/0 aa:bb:cc:dd:ee:01 add} |
| 1357 | * Example of how to delete a secondary MAC address from an interface: |
| 1358 | * @cliexcmd{set interface secondary-mac-address GigabitEthernet0/8/0 aa:bb:cc:dd:ee:01 del} |
| 1359 | * @endparblock |
| 1360 | ?*/ |
| 1361 | /* *INDENT-OFF* */ |
| 1362 | VLIB_CLI_COMMAND (interface_add_del_mac_address_cmd, static) = { |
| 1363 | .path = "set interface secondary-mac-address", |
| 1364 | .short_help = "set interface secondary-mac-address <interface> <mac-address> [(add|del)]", |
| 1365 | .function = interface_add_del_mac_address, |
| 1366 | }; |
| 1367 | /* *INDENT-ON* */ |
| 1368 | |
| 1369 | static clib_error_t * |
Pavel Kotucek | c631f2d | 2016-09-26 10:40:02 +0200 | [diff] [blame] | 1370 | set_interface_mac_address (vlib_main_t * vm, unformat_input_t * input, |
| 1371 | vlib_cli_command_t * cmd) |
| 1372 | { |
| 1373 | vnet_main_t *vnm = vnet_get_main (); |
Neale Ranns | d867a7c | 2017-10-04 02:29:07 -0700 | [diff] [blame] | 1374 | vnet_sw_interface_t *si = NULL; |
Pavel Kotucek | c631f2d | 2016-09-26 10:40:02 +0200 | [diff] [blame] | 1375 | clib_error_t *error = 0; |
| 1376 | u32 sw_if_index = ~0; |
John Lo | 62fcc0a | 2017-10-31 14:31:10 -0400 | [diff] [blame] | 1377 | u8 mac[6] = { 0 }; |
Pavel Kotucek | c631f2d | 2016-09-26 10:40:02 +0200 | [diff] [blame] | 1378 | |
| 1379 | if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index)) |
| 1380 | { |
| 1381 | error = clib_error_return (0, "unknown interface `%U'", |
| 1382 | format_unformat_error, input); |
| 1383 | goto done; |
| 1384 | } |
John Lo | 62fcc0a | 2017-10-31 14:31:10 -0400 | [diff] [blame] | 1385 | if (!unformat_user (input, unformat_ethernet_address, mac)) |
Pavel Kotucek | c631f2d | 2016-09-26 10:40:02 +0200 | [diff] [blame] | 1386 | { |
| 1387 | error = clib_error_return (0, "expected mac address `%U'", |
| 1388 | format_unformat_error, input); |
| 1389 | goto done; |
| 1390 | } |
Neale Ranns | d867a7c | 2017-10-04 02:29:07 -0700 | [diff] [blame] | 1391 | si = vnet_get_sw_interface (vnm, sw_if_index); |
| 1392 | error = vnet_hw_interface_change_mac_address (vnm, si->hw_if_index, mac); |
Pavel Kotucek | c631f2d | 2016-09-26 10:40:02 +0200 | [diff] [blame] | 1393 | done: |
| 1394 | return error; |
| 1395 | } |
| 1396 | |
| 1397 | /*? |
| 1398 | * The '<em>set interface mac address </em>' command allows to set MAC address of given interface. |
| 1399 | * In case of NIC interfaces the one has to support MAC address change. A side effect of MAC address |
| 1400 | * change are changes of MAC addresses in FIB tables (ipv4 and ipv6). |
| 1401 | * |
| 1402 | * @cliexpar |
| 1403 | * @parblock |
| 1404 | * Example of how to change MAC Address of interface: |
| 1405 | * @cliexcmd{set interface mac address GigabitEthernet0/8/0 aa:bb:cc:dd:ee:01} |
| 1406 | * @cliexcmd{set interface mac address host-vpp0 aa:bb:cc:dd:ee:02} |
| 1407 | * @cliexcmd{set interface mac address tap-0 aa:bb:cc:dd:ee:03} |
| 1408 | * @cliexcmd{set interface mac address pg0 aa:bb:cc:dd:ee:04} |
| 1409 | * @endparblock |
| 1410 | ?*/ |
| 1411 | /* *INDENT-OFF* */ |
| 1412 | VLIB_CLI_COMMAND (set_interface_mac_address_cmd, static) = { |
| 1413 | .path = "set interface mac address", |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 1414 | .short_help = "set interface mac address <interface> <mac-address>", |
Pavel Kotucek | c631f2d | 2016-09-26 10:40:02 +0200 | [diff] [blame] | 1415 | .function = set_interface_mac_address, |
| 1416 | }; |
| 1417 | /* *INDENT-ON* */ |
| 1418 | |
Dave Barach | 7be864a | 2016-11-28 11:41:35 -0500 | [diff] [blame] | 1419 | static clib_error_t * |
| 1420 | set_tag (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) |
| 1421 | { |
| 1422 | vnet_main_t *vnm = vnet_get_main (); |
| 1423 | u32 sw_if_index = ~0; |
| 1424 | u8 *tag = 0; |
| 1425 | |
| 1426 | if (!unformat (input, "%U %s", unformat_vnet_sw_interface, |
| 1427 | vnm, &sw_if_index, &tag)) |
| 1428 | return clib_error_return (0, "unknown input `%U'", |
| 1429 | format_unformat_error, input); |
| 1430 | |
| 1431 | vnet_set_sw_interface_tag (vnm, tag, sw_if_index); |
| 1432 | |
| 1433 | return 0; |
| 1434 | } |
| 1435 | |
| 1436 | /* *INDENT-OFF* */ |
| 1437 | VLIB_CLI_COMMAND (set_tag_command, static) = { |
| 1438 | .path = "set interface tag", |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 1439 | .short_help = "set interface tag <interface> <tag>", |
Dave Barach | 7be864a | 2016-11-28 11:41:35 -0500 | [diff] [blame] | 1440 | .function = set_tag, |
| 1441 | }; |
| 1442 | /* *INDENT-ON* */ |
| 1443 | |
| 1444 | static clib_error_t * |
| 1445 | clear_tag (vlib_main_t * vm, unformat_input_t * input, |
| 1446 | vlib_cli_command_t * cmd) |
| 1447 | { |
| 1448 | vnet_main_t *vnm = vnet_get_main (); |
| 1449 | u32 sw_if_index = ~0; |
| 1450 | |
| 1451 | if (!unformat (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index)) |
| 1452 | return clib_error_return (0, "unknown input `%U'", |
| 1453 | format_unformat_error, input); |
| 1454 | |
| 1455 | vnet_clear_sw_interface_tag (vnm, sw_if_index); |
| 1456 | |
| 1457 | return 0; |
| 1458 | } |
| 1459 | |
| 1460 | /* *INDENT-OFF* */ |
| 1461 | VLIB_CLI_COMMAND (clear_tag_command, static) = { |
| 1462 | .path = "clear interface tag", |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 1463 | .short_help = "clear interface tag <interface>", |
Dave Barach | 7be864a | 2016-11-28 11:41:35 -0500 | [diff] [blame] | 1464 | .function = clear_tag, |
| 1465 | }; |
| 1466 | /* *INDENT-ON* */ |
| 1467 | |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1468 | static clib_error_t * |
Neale Ranns | 1855b8e | 2018-07-11 10:31:26 -0700 | [diff] [blame] | 1469 | set_ip_directed_broadcast (vlib_main_t * vm, |
| 1470 | unformat_input_t * input, vlib_cli_command_t * cmd) |
| 1471 | { |
| 1472 | vnet_main_t *vnm = vnet_get_main (); |
| 1473 | u32 sw_if_index = ~0; |
| 1474 | u8 enable = 0; |
| 1475 | |
| 1476 | if (!unformat (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index)); |
| 1477 | else if (unformat (input, "enable")) |
| 1478 | enable = 1; |
| 1479 | else if (unformat (input, "disable")) |
| 1480 | enable = 0; |
| 1481 | else |
| 1482 | return clib_error_return (0, "unknown input: `%U'", |
| 1483 | format_unformat_error, input); |
| 1484 | |
| 1485 | if (~0 == sw_if_index) |
| 1486 | return clib_error_return (0, "specify an interface: `%U'", |
| 1487 | format_unformat_error, input); |
| 1488 | |
| 1489 | vnet_sw_interface_ip_directed_broadcast (vnm, sw_if_index, enable); |
| 1490 | |
| 1491 | return 0; |
| 1492 | } |
| 1493 | |
| 1494 | /*? |
| 1495 | * This command is used to enable/disable IP directed broadcast |
| 1496 | * If directed broadcast is enabled a packet sent to the interface's |
| 1497 | * subnet broadcast address will be sent L2 broadcast on the interface, |
| 1498 | * otherwise it is dropped. |
| 1499 | ?*/ |
| 1500 | /* *INDENT-OFF* */ |
| 1501 | VLIB_CLI_COMMAND (set_ip_directed_broadcast_command, static) = { |
| 1502 | .path = "set interface ip directed-broadcast", |
| 1503 | .short_help = "set interface enable <interface> <enable|disable>", |
| 1504 | .function = set_ip_directed_broadcast, |
| 1505 | }; |
| 1506 | /* *INDENT-ON* */ |
| 1507 | |
Steven | ad8015b | 2017-10-29 22:10:46 -0700 | [diff] [blame] | 1508 | clib_error_t * |
| 1509 | set_hw_interface_change_rx_mode (vnet_main_t * vnm, u32 hw_if_index, |
| 1510 | u8 queue_id_valid, u32 queue_id, |
Damjan Marion | eabd424 | 2020-10-07 20:59:07 +0200 | [diff] [blame] | 1511 | vnet_hw_if_rx_mode mode) |
Steven | ad8015b | 2017-10-29 22:10:46 -0700 | [diff] [blame] | 1512 | { |
| 1513 | clib_error_t *error = 0; |
| 1514 | vnet_hw_interface_t *hw; |
Damjan Marion | 9410053 | 2020-11-06 23:25:57 +0100 | [diff] [blame] | 1515 | u32 *queue_indices = 0; |
Steven | ad8015b | 2017-10-29 22:10:46 -0700 | [diff] [blame] | 1516 | |
| 1517 | hw = vnet_get_hw_interface (vnm, hw_if_index); |
| 1518 | |
Damjan Marion | 9410053 | 2020-11-06 23:25:57 +0100 | [diff] [blame] | 1519 | if (queue_id_valid) |
| 1520 | { |
| 1521 | u32 queue_index; |
| 1522 | queue_index = |
| 1523 | vnet_hw_if_get_rx_queue_index_by_id (vnm, hw_if_index, queue_id); |
| 1524 | if (queue_index == ~0) |
| 1525 | return clib_error_return (0, "unknown queue %u on interface %s", |
| 1526 | queue_id, hw->name); |
| 1527 | vec_add1 (queue_indices, queue_index); |
Steven | ad8015b | 2017-10-29 22:10:46 -0700 | [diff] [blame] | 1528 | } |
| 1529 | else |
Damjan Marion | 9410053 | 2020-11-06 23:25:57 +0100 | [diff] [blame] | 1530 | queue_indices = hw->rx_queue_indices; |
Steven | ad8015b | 2017-10-29 22:10:46 -0700 | [diff] [blame] | 1531 | |
Damjan Marion | 9410053 | 2020-11-06 23:25:57 +0100 | [diff] [blame] | 1532 | for (int i = 0; i < vec_len (queue_indices); i++) |
| 1533 | { |
| 1534 | int rv = vnet_hw_if_set_rx_queue_mode (vnm, queue_indices[i], mode); |
| 1535 | if (rv) |
| 1536 | goto done; |
| 1537 | } |
| 1538 | |
| 1539 | done: |
| 1540 | if (queue_indices != hw->rx_queue_indices) |
| 1541 | vec_free (queue_indices); |
| 1542 | vnet_hw_if_update_runtime_data (vnm, hw_if_index); |
| 1543 | return error; |
Steven | ad8015b | 2017-10-29 22:10:46 -0700 | [diff] [blame] | 1544 | } |
| 1545 | |
Steven | e3a395c | 2017-05-09 16:19:50 -0700 | [diff] [blame] | 1546 | static clib_error_t * |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1547 | set_interface_rx_mode (vlib_main_t * vm, unformat_input_t * input, |
| 1548 | vlib_cli_command_t * cmd) |
| 1549 | { |
| 1550 | clib_error_t *error = 0; |
| 1551 | unformat_input_t _line_input, *line_input = &_line_input; |
| 1552 | vnet_main_t *vnm = vnet_get_main (); |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1553 | u32 hw_if_index = (u32) ~ 0; |
| 1554 | u32 queue_id = (u32) ~ 0; |
Damjan Marion | eabd424 | 2020-10-07 20:59:07 +0200 | [diff] [blame] | 1555 | vnet_hw_if_rx_mode mode = VNET_HW_IF_RX_MODE_UNKNOWN; |
Steven | ad8015b | 2017-10-29 22:10:46 -0700 | [diff] [blame] | 1556 | u8 queue_id_valid = 0; |
Dave Barach | 7be864a | 2016-11-28 11:41:35 -0500 | [diff] [blame] | 1557 | |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1558 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 1559 | return 0; |
| 1560 | |
| 1561 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 1562 | { |
| 1563 | if (unformat |
| 1564 | (line_input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index)) |
| 1565 | ; |
| 1566 | else if (unformat (line_input, "queue %d", &queue_id)) |
Steven | ad8015b | 2017-10-29 22:10:46 -0700 | [diff] [blame] | 1567 | queue_id_valid = 1; |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1568 | else if (unformat (line_input, "polling")) |
Damjan Marion | eabd424 | 2020-10-07 20:59:07 +0200 | [diff] [blame] | 1569 | mode = VNET_HW_IF_RX_MODE_POLLING; |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1570 | else if (unformat (line_input, "interrupt")) |
Damjan Marion | eabd424 | 2020-10-07 20:59:07 +0200 | [diff] [blame] | 1571 | mode = VNET_HW_IF_RX_MODE_INTERRUPT; |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1572 | else if (unformat (line_input, "adaptive")) |
Damjan Marion | eabd424 | 2020-10-07 20:59:07 +0200 | [diff] [blame] | 1573 | mode = VNET_HW_IF_RX_MODE_ADAPTIVE; |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1574 | else |
| 1575 | { |
| 1576 | error = clib_error_return (0, "parse error: '%U'", |
| 1577 | format_unformat_error, line_input); |
| 1578 | unformat_free (line_input); |
| 1579 | return error; |
| 1580 | } |
| 1581 | } |
| 1582 | |
| 1583 | unformat_free (line_input); |
| 1584 | |
| 1585 | if (hw_if_index == (u32) ~ 0) |
| 1586 | return clib_error_return (0, "please specify valid interface name"); |
| 1587 | |
Damjan Marion | eabd424 | 2020-10-07 20:59:07 +0200 | [diff] [blame] | 1588 | if (mode == VNET_HW_IF_RX_MODE_UNKNOWN) |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1589 | return clib_error_return (0, "please specify valid rx-mode"); |
| 1590 | |
Steven | ad8015b | 2017-10-29 22:10:46 -0700 | [diff] [blame] | 1591 | error = set_hw_interface_change_rx_mode (vnm, hw_if_index, queue_id_valid, |
| 1592 | queue_id, mode); |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1593 | |
Steven | e3a395c | 2017-05-09 16:19:50 -0700 | [diff] [blame] | 1594 | return (error); |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1595 | } |
| 1596 | |
| 1597 | /*? |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 1598 | * This command is used to assign the RX packet processing mode (polling, |
| 1599 | * interrupt, adaptive) of the a given interface, and optionally a |
| 1600 | * given queue. If the '<em>queue</em>' is not provided, the '<em>mode</em>' |
| 1601 | * is applied to all queues of the interface. Not all interfaces support |
| 1602 | * all modes. To display the current rx-mode use the command |
| 1603 | * '<em>show interface rx-placement</em>'. |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1604 | * |
| 1605 | * @cliexpar |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 1606 | * Example of how to assign rx-mode to all queues on an interface: |
| 1607 | * @cliexcmd{set interface rx-mode VirtualEthernet0/0/12 polling} |
| 1608 | * Example of how to assign rx-mode to one queue of an interface: |
| 1609 | * @cliexcmd{set interface rx-mode VirtualEthernet0/0/12 queue 0 interrupt} |
| 1610 | * Example of how to display the rx-mode of all interfaces: |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1611 | * @cliexstart{show interface rx-placement} |
| 1612 | * Thread 1 (vpp_wk_0): |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 1613 | * node dpdk-input: |
| 1614 | * GigabitEthernet7/0/0 queue 0 (polling) |
| 1615 | * node vhost-user-input: |
| 1616 | * VirtualEthernet0/0/12 queue 0 (interrupt) |
| 1617 | * VirtualEthernet0/0/12 queue 2 (polling) |
| 1618 | * VirtualEthernet0/0/13 queue 0 (polling) |
| 1619 | * VirtualEthernet0/0/13 queue 2 (polling) |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1620 | * Thread 2 (vpp_wk_1): |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 1621 | * node dpdk-input: |
| 1622 | * GigabitEthernet7/0/1 queue 0 (polling) |
| 1623 | * node vhost-user-input: |
| 1624 | * VirtualEthernet0/0/12 queue 1 (polling) |
| 1625 | * VirtualEthernet0/0/12 queue 3 (polling) |
| 1626 | * VirtualEthernet0/0/13 queue 1 (polling) |
| 1627 | * VirtualEthernet0/0/13 queue 3 (polling) |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1628 | * @cliexend |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1629 | ?*/ |
| 1630 | /* *INDENT-OFF* */ |
Damjan Marion | fe7d4a2 | 2018-04-13 19:43:39 +0200 | [diff] [blame] | 1631 | VLIB_CLI_COMMAND (cmd_set_if_rx_mode,static) = { |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1632 | .path = "set interface rx-mode", |
| 1633 | .short_help = "set interface rx-mode <interface> [queue <n>] [polling | interrupt | adaptive]", |
| 1634 | .function = set_interface_rx_mode, |
| 1635 | }; |
| 1636 | /* *INDENT-ON* */ |
| 1637 | |
| 1638 | static clib_error_t * |
| 1639 | show_interface_rx_placement_fn (vlib_main_t * vm, unformat_input_t * input, |
| 1640 | vlib_cli_command_t * cmd) |
| 1641 | { |
| 1642 | u8 *s = 0; |
| 1643 | vnet_main_t *vnm = vnet_get_main (); |
Mohammed Hawari | 9fecbe1 | 2020-12-11 19:36:37 +0100 | [diff] [blame] | 1644 | vnet_hw_if_rx_queue_t **all_queues = 0; |
| 1645 | vnet_hw_if_rx_queue_t **qptr; |
| 1646 | vnet_hw_if_rx_queue_t *q; |
Nathan Skrzypczak | 455779f | 2021-02-15 14:48:33 +0100 | [diff] [blame] | 1647 | pool_foreach (q, vnm->interface_main.hw_if_rx_queues) |
Mohammed Hawari | 9fecbe1 | 2020-12-11 19:36:37 +0100 | [diff] [blame] | 1648 | vec_add1 (all_queues, q); |
| 1649 | vec_sort_with_function (all_queues, vnet_hw_if_rxq_cmp_cli_api); |
| 1650 | u32 prev_node = ~0; |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1651 | |
Mohammed Hawari | 9fecbe1 | 2020-12-11 19:36:37 +0100 | [diff] [blame] | 1652 | vec_foreach (qptr, all_queues) |
| 1653 | { |
| 1654 | u32 current_thread = qptr[0]->thread_index; |
| 1655 | u32 hw_if_index = qptr[0]->hw_if_index; |
| 1656 | vnet_hw_interface_t *hw_if = vnet_get_hw_interface (vnm, hw_if_index); |
| 1657 | u32 current_node = hw_if->input_node_index; |
| 1658 | if (current_node != prev_node) |
| 1659 | s = format (s, " node %U:\n", format_vlib_node_name, vm, current_node); |
| 1660 | s = format (s, " %U queue %u (%U)\n", format_vnet_sw_if_index_name, |
| 1661 | vnm, hw_if->sw_if_index, qptr[0]->queue_id, |
| 1662 | format_vnet_hw_if_rx_mode, qptr[0]->mode); |
| 1663 | if (qptr == all_queues + vec_len (all_queues) - 1 || |
| 1664 | current_thread != qptr[1]->thread_index) |
| 1665 | { |
| 1666 | vlib_cli_output (vm, "Thread %u (%s):\n%v", current_thread, |
| 1667 | vlib_worker_threads[current_thread].name, s); |
| 1668 | vec_reset_length (s); |
| 1669 | } |
| 1670 | prev_node = current_node; |
| 1671 | } |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1672 | vec_free (s); |
Mohammed Hawari | 9fecbe1 | 2020-12-11 19:36:37 +0100 | [diff] [blame] | 1673 | vec_free (all_queues); |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1674 | return 0; |
| 1675 | } |
| 1676 | |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 1677 | /*? |
| 1678 | * This command is used to display the interface and queue worker |
| 1679 | * thread placement. |
| 1680 | * |
| 1681 | * @cliexpar |
| 1682 | * Example of how to display the interface placement: |
| 1683 | * @cliexstart{show interface rx-placement} |
| 1684 | * Thread 1 (vpp_wk_0): |
| 1685 | * node dpdk-input: |
| 1686 | * GigabitEthernet7/0/0 queue 0 (polling) |
| 1687 | * node vhost-user-input: |
| 1688 | * VirtualEthernet0/0/12 queue 0 (polling) |
| 1689 | * VirtualEthernet0/0/12 queue 2 (polling) |
| 1690 | * VirtualEthernet0/0/13 queue 0 (polling) |
| 1691 | * VirtualEthernet0/0/13 queue 2 (polling) |
| 1692 | * Thread 2 (vpp_wk_1): |
| 1693 | * node dpdk-input: |
| 1694 | * GigabitEthernet7/0/1 queue 0 (polling) |
| 1695 | * node vhost-user-input: |
| 1696 | * VirtualEthernet0/0/12 queue 1 (polling) |
| 1697 | * VirtualEthernet0/0/12 queue 3 (polling) |
| 1698 | * VirtualEthernet0/0/13 queue 1 (polling) |
| 1699 | * VirtualEthernet0/0/13 queue 3 (polling) |
| 1700 | * @cliexend |
| 1701 | ?*/ |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1702 | /* *INDENT-OFF* */ |
| 1703 | VLIB_CLI_COMMAND (show_interface_rx_placement, static) = { |
| 1704 | .path = "show interface rx-placement", |
| 1705 | .short_help = "show interface rx-placement", |
| 1706 | .function = show_interface_rx_placement_fn, |
| 1707 | }; |
| 1708 | /* *INDENT-ON* */ |
Mohsin Kazmi | 54f7c51 | 2018-08-23 18:28:11 +0200 | [diff] [blame] | 1709 | clib_error_t * |
| 1710 | set_hw_interface_rx_placement (u32 hw_if_index, u32 queue_id, |
| 1711 | u32 thread_index, u8 is_main) |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1712 | { |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1713 | vnet_main_t *vnm = vnet_get_main (); |
| 1714 | vnet_device_main_t *vdm = &vnet_device_main; |
Damjan Marion | 9410053 | 2020-11-06 23:25:57 +0100 | [diff] [blame] | 1715 | vnet_hw_interface_t *hw; |
| 1716 | u32 queue_index; |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1717 | |
Mohsin Kazmi | 54f7c51 | 2018-08-23 18:28:11 +0200 | [diff] [blame] | 1718 | if (is_main) |
| 1719 | thread_index = 0; |
| 1720 | else |
| 1721 | thread_index += vdm->first_worker_thread_index; |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1722 | |
| 1723 | if (thread_index > vdm->last_worker_thread_index) |
| 1724 | return clib_error_return (0, |
| 1725 | "please specify valid worker thread or main"); |
| 1726 | |
Damjan Marion | 9410053 | 2020-11-06 23:25:57 +0100 | [diff] [blame] | 1727 | hw = vnet_get_hw_interface (vnm, hw_if_index); |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1728 | |
Damjan Marion | 9410053 | 2020-11-06 23:25:57 +0100 | [diff] [blame] | 1729 | queue_index = |
| 1730 | vnet_hw_if_get_rx_queue_index_by_id (vnm, hw_if_index, queue_id); |
| 1731 | if (queue_index == ~0) |
| 1732 | return clib_error_return (0, "unknown queue %u on interface %s", queue_id, |
| 1733 | hw->name); |
| 1734 | vnet_hw_if_set_rx_queue_thread_index (vnm, queue_index, thread_index); |
| 1735 | vnet_hw_if_update_runtime_data (vnm, hw_if_index); |
| 1736 | return 0; |
Mohsin Kazmi | 54f7c51 | 2018-08-23 18:28:11 +0200 | [diff] [blame] | 1737 | } |
| 1738 | |
| 1739 | static clib_error_t * |
Mohammed Hawari | 9fecbe1 | 2020-12-11 19:36:37 +0100 | [diff] [blame] | 1740 | set_interface_rx_placement (vlib_main_t *vm, unformat_input_t *input, |
| 1741 | vlib_cli_command_t *cmd) |
Mohsin Kazmi | 54f7c51 | 2018-08-23 18:28:11 +0200 | [diff] [blame] | 1742 | { |
| 1743 | clib_error_t *error = 0; |
| 1744 | unformat_input_t _line_input, *line_input = &_line_input; |
| 1745 | vnet_main_t *vnm = vnet_get_main (); |
| 1746 | u32 hw_if_index = (u32) ~ 0; |
| 1747 | u32 queue_id = (u32) 0; |
| 1748 | u32 thread_index = (u32) ~ 0; |
| 1749 | u8 is_main = 0; |
| 1750 | |
| 1751 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 1752 | return 0; |
| 1753 | |
| 1754 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 1755 | { |
| 1756 | if (unformat |
| 1757 | (line_input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index)) |
| 1758 | ; |
| 1759 | else if (unformat (line_input, "queue %d", &queue_id)) |
| 1760 | ; |
| 1761 | else if (unformat (line_input, "main", &thread_index)) |
| 1762 | is_main = 1; |
| 1763 | else if (unformat (line_input, "worker %d", &thread_index)) |
| 1764 | ; |
| 1765 | else |
| 1766 | { |
| 1767 | error = clib_error_return (0, "parse error: '%U'", |
| 1768 | format_unformat_error, line_input); |
| 1769 | unformat_free (line_input); |
| 1770 | return error; |
| 1771 | } |
| 1772 | } |
| 1773 | |
| 1774 | unformat_free (line_input); |
| 1775 | |
| 1776 | if (hw_if_index == (u32) ~ 0) |
| 1777 | return clib_error_return (0, "please specify valid interface name"); |
| 1778 | |
| 1779 | error = set_hw_interface_rx_placement (hw_if_index, queue_id, thread_index, |
| 1780 | is_main); |
| 1781 | |
| 1782 | return (error); |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1783 | } |
| 1784 | |
| 1785 | /*? |
| 1786 | * This command is used to assign a given interface, and optionally a |
| 1787 | * given queue, to a different thread. If the '<em>queue</em>' is not provided, |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 1788 | * it defaults to 0. The '<em>worker</em>' parameter is zero based and the index |
| 1789 | * in the thread name, for example, 0 in the thread name '<em>vpp_wk_0</em>'. |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1790 | * |
| 1791 | * @cliexpar |
| 1792 | * Example of how to display the interface placement: |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 1793 | * @cliexstart{show interface rx-placement} |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1794 | * Thread 1 (vpp_wk_0): |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 1795 | * node dpdk-input: |
| 1796 | * GigabitEthernet7/0/0 queue 0 (polling) |
| 1797 | * node vhost-user-input: |
| 1798 | * VirtualEthernet0/0/12 queue 0 (polling) |
| 1799 | * VirtualEthernet0/0/12 queue 2 (polling) |
| 1800 | * VirtualEthernet0/0/13 queue 0 (polling) |
| 1801 | * VirtualEthernet0/0/13 queue 2 (polling) |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1802 | * Thread 2 (vpp_wk_1): |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 1803 | * node dpdk-input: |
| 1804 | * GigabitEthernet7/0/1 queue 0 (polling) |
| 1805 | * node vhost-user-input: |
| 1806 | * VirtualEthernet0/0/12 queue 1 (polling) |
| 1807 | * VirtualEthernet0/0/12 queue 3 (polling) |
| 1808 | * VirtualEthernet0/0/13 queue 1 (polling) |
| 1809 | * VirtualEthernet0/0/13 queue 3 (polling) |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1810 | * @cliexend |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 1811 | * Example of how to assign a interface and queue to a worker thread: |
| 1812 | * @cliexcmd{set interface rx-placement VirtualEthernet0/0/12 queue 1 worker 0} |
| 1813 | * Example of how to display the interface placement: |
| 1814 | * @cliexstart{show interface rx-placement} |
| 1815 | * Thread 1 (vpp_wk_0): |
| 1816 | * node dpdk-input: |
| 1817 | * GigabitEthernet7/0/0 queue 0 (polling) |
| 1818 | * node vhost-user-input: |
| 1819 | * VirtualEthernet0/0/12 queue 0 (polling) |
| 1820 | * VirtualEthernet0/0/12 queue 1 (polling) |
| 1821 | * VirtualEthernet0/0/12 queue 2 (polling) |
| 1822 | * VirtualEthernet0/0/13 queue 0 (polling) |
| 1823 | * VirtualEthernet0/0/13 queue 2 (polling) |
| 1824 | * Thread 2 (vpp_wk_1): |
| 1825 | * node dpdk-input: |
| 1826 | * GigabitEthernet7/0/1 queue 0 (polling) |
| 1827 | * node vhost-user-input: |
| 1828 | * VirtualEthernet0/0/12 queue 3 (polling) |
| 1829 | * VirtualEthernet0/0/13 queue 1 (polling) |
| 1830 | * VirtualEthernet0/0/13 queue 3 (polling) |
| 1831 | * @cliexend |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1832 | ?*/ |
| 1833 | /* *INDENT-OFF* */ |
| 1834 | VLIB_CLI_COMMAND (cmd_set_if_rx_placement,static) = { |
| 1835 | .path = "set interface rx-placement", |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 1836 | .short_help = "set interface rx-placement <interface> [queue <n>] " |
Damjan Marion | 6f9ac65 | 2017-06-15 19:01:31 +0200 | [diff] [blame] | 1837 | "[worker <n> | main]", |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1838 | .function = set_interface_rx_placement, |
Damjan Marion | 6f9ac65 | 2017-06-15 19:01:31 +0200 | [diff] [blame] | 1839 | .is_mp_safe = 1, |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1840 | }; |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1841 | /* *INDENT-ON* */ |
Dave Barach | 5ecd5a5 | 2019-02-25 15:27:28 -0500 | [diff] [blame] | 1842 | |
Chenmin Sun | c466509 | 2020-07-06 08:20:39 +0800 | [diff] [blame] | 1843 | clib_error_t * |
Mohsin Kazmi | 005605f | 2021-05-24 18:33:50 +0200 | [diff] [blame] | 1844 | set_hw_interface_tx_queue (u32 hw_if_index, u32 queue_id, uword *bitmap) |
| 1845 | { |
| 1846 | vnet_main_t *vnm = vnet_get_main (); |
| 1847 | vnet_device_main_t *vdm = &vnet_device_main; |
| 1848 | vnet_hw_interface_t *hw; |
| 1849 | vnet_hw_if_tx_queue_t *txq; |
| 1850 | u32 queue_index; |
| 1851 | u32 thread_index; |
| 1852 | |
| 1853 | hw = vnet_get_hw_interface (vnm, hw_if_index); |
| 1854 | |
| 1855 | /* highest set bit in bitmap should not exceed last worker thread index */ |
Steven Luong | 8e3f109 | 2021-06-17 08:22:50 -0700 | [diff] [blame] | 1856 | thread_index = clib_bitmap_last_set (bitmap); |
| 1857 | if ((thread_index != ~0) && (thread_index > vdm->last_worker_thread_index)) |
Mohsin Kazmi | 005605f | 2021-05-24 18:33:50 +0200 | [diff] [blame] | 1858 | return clib_error_return (0, "please specify valid thread(s)"); |
| 1859 | |
| 1860 | queue_index = |
| 1861 | vnet_hw_if_get_tx_queue_index_by_id (vnm, hw_if_index, queue_id); |
| 1862 | if (queue_index == ~0) |
| 1863 | return clib_error_return (0, "unknown queue %u on interface %s", queue_id, |
| 1864 | hw->name); |
| 1865 | |
| 1866 | txq = vnet_hw_if_get_tx_queue (vnm, queue_index); |
| 1867 | |
| 1868 | // free the existing bitmap |
| 1869 | if (clib_bitmap_count_set_bits (txq->threads)) |
| 1870 | { |
| 1871 | txq->shared_queue = 0; |
| 1872 | clib_bitmap_free (txq->threads); |
| 1873 | } |
| 1874 | |
| 1875 | clib_bitmap_foreach (thread_index, bitmap) |
| 1876 | vnet_hw_if_tx_queue_assign_thread (vnm, queue_index, thread_index); |
| 1877 | |
| 1878 | vnet_hw_if_update_runtime_data (vnm, hw_if_index); |
| 1879 | return 0; |
| 1880 | } |
| 1881 | |
| 1882 | static clib_error_t * |
| 1883 | set_interface_tx_queue (vlib_main_t *vm, unformat_input_t *input, |
| 1884 | vlib_cli_command_t *cmd) |
| 1885 | { |
| 1886 | clib_error_t *error = 0; |
| 1887 | unformat_input_t _line_input, *line_input = &_line_input; |
| 1888 | vnet_main_t *vnm = vnet_get_main (); |
| 1889 | u32 hw_if_index = (u32) ~0; |
| 1890 | u32 queue_id = (u32) 0; |
| 1891 | uword *bitmap = 0; |
| 1892 | |
| 1893 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 1894 | return 0; |
| 1895 | |
| 1896 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 1897 | { |
| 1898 | if (unformat (line_input, "%U", unformat_vnet_hw_interface, vnm, |
| 1899 | &hw_if_index)) |
| 1900 | ; |
| 1901 | else if (unformat (line_input, "queue %d", &queue_id)) |
| 1902 | ; |
| 1903 | else if (unformat (line_input, "threads %U", unformat_bitmap_list, |
| 1904 | &bitmap)) |
| 1905 | ; |
| 1906 | else |
| 1907 | { |
| 1908 | error = clib_error_return (0, "parse error: '%U'", |
| 1909 | format_unformat_error, line_input); |
| 1910 | unformat_free (line_input); |
| 1911 | return error; |
| 1912 | } |
| 1913 | } |
| 1914 | |
| 1915 | unformat_free (line_input); |
| 1916 | |
| 1917 | if (hw_if_index == (u32) ~0) |
| 1918 | { |
| 1919 | error = clib_error_return (0, "please specify valid interface name"); |
| 1920 | goto error; |
| 1921 | } |
| 1922 | |
| 1923 | error = set_hw_interface_tx_queue (hw_if_index, queue_id, bitmap); |
| 1924 | |
| 1925 | error: |
| 1926 | clib_bitmap_free (bitmap); |
| 1927 | return (error); |
| 1928 | } |
| 1929 | |
| 1930 | VLIB_CLI_COMMAND (cmd_set_if_tx_queue, static) = { |
| 1931 | .path = "set interface tx-queue", |
| 1932 | .short_help = "set interface tx-queue <interface> queue <n> " |
Steven Luong | 8e3f109 | 2021-06-17 08:22:50 -0700 | [diff] [blame] | 1933 | "[threads <list>]", |
Mohsin Kazmi | 005605f | 2021-05-24 18:33:50 +0200 | [diff] [blame] | 1934 | .function = set_interface_tx_queue, |
| 1935 | .is_mp_safe = 1, |
| 1936 | }; |
| 1937 | |
| 1938 | clib_error_t * |
Chenmin Sun | c466509 | 2020-07-06 08:20:39 +0800 | [diff] [blame] | 1939 | set_interface_rss_queues (vlib_main_t * vm, u32 hw_if_index, |
| 1940 | clib_bitmap_t * bitmap) |
| 1941 | { |
| 1942 | vnet_main_t *vnm = vnet_get_main (); |
| 1943 | vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, hw_if_index); |
| 1944 | |
| 1945 | return vnet_hw_interface_set_rss_queues (vnm, hi, bitmap); |
| 1946 | } |
| 1947 | |
| 1948 | static clib_error_t * |
| 1949 | set_interface_rss_queues_fn (vlib_main_t * vm, |
| 1950 | unformat_input_t * input, |
| 1951 | vlib_cli_command_t * cmd) |
| 1952 | { |
| 1953 | clib_error_t *error = 0; |
| 1954 | unformat_input_t _line_input, *line_input = &_line_input; |
| 1955 | vnet_main_t *vnm = vnet_get_main (); |
| 1956 | u32 hw_if_index = (u32) ~ 0; |
| 1957 | clib_bitmap_t *bitmap = NULL; |
| 1958 | |
| 1959 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 1960 | return 0; |
| 1961 | |
| 1962 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 1963 | { |
| 1964 | if (unformat |
| 1965 | (line_input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index)) |
| 1966 | ; |
| 1967 | else |
| 1968 | if (unformat (line_input, "list %U", unformat_bitmap_list, &bitmap)) |
| 1969 | ; |
| 1970 | else |
| 1971 | { |
| 1972 | error = clib_error_return (0, "parse error: '%U'", |
| 1973 | format_unformat_error, line_input); |
| 1974 | unformat_free (line_input); |
| 1975 | goto done; |
| 1976 | } |
| 1977 | } |
| 1978 | |
| 1979 | unformat_free (line_input); |
| 1980 | |
| 1981 | if (hw_if_index == (u32) ~ 0) |
| 1982 | { |
| 1983 | error = clib_error_return (0, "please specify valid interface name"); |
| 1984 | goto done; |
| 1985 | } |
| 1986 | |
| 1987 | if (bitmap == NULL) |
| 1988 | { |
| 1989 | error = clib_error_return (0, "please specify the valid rss queues"); |
| 1990 | goto done; |
| 1991 | } |
| 1992 | |
| 1993 | error = set_interface_rss_queues (vm, hw_if_index, bitmap); |
| 1994 | |
| 1995 | done: |
| 1996 | if (bitmap) |
| 1997 | clib_bitmap_free (bitmap); |
| 1998 | |
| 1999 | return (error); |
| 2000 | } |
| 2001 | |
| 2002 | /*? |
| 2003 | * This command is used to set the rss queues of a given interface |
| 2004 | * Not all the interfaces support this operation. |
| 2005 | * To display the current rss queues, use the command |
| 2006 | * '<em>show hardware-interfaces</em>'. |
| 2007 | * |
| 2008 | * @cliexpar |
| 2009 | * Example of how to set the rss queues to 0,2-5,7 of an interface: |
| 2010 | * @cliexstart{set interface rss queues VirtualFunctionEthernet18/1/0 list 0,2-5,7} |
| 2011 | * @cliexend |
| 2012 | ?*/ |
| 2013 | /* *INDENT-OFF* */ |
| 2014 | VLIB_CLI_COMMAND (cmd_set_interface_rss_queues,static) = { |
| 2015 | .path = "set interface rss queues", |
| 2016 | .short_help = "set interface rss queues <interface> <list <queue-list>>", |
| 2017 | .function = set_interface_rss_queues_fn, |
| 2018 | }; |
| 2019 | /* *INDENT-ON* */ |
| 2020 | |
Dave Barach | 3390977 | 2019-09-23 10:27:27 -0400 | [diff] [blame] | 2021 | static u8 * |
| 2022 | format_vnet_pcap (u8 * s, va_list * args) |
| 2023 | { |
| 2024 | vnet_pcap_t *pp = va_arg (*args, vnet_pcap_t *); |
| 2025 | int type = va_arg (*args, int); |
| 2026 | int printed = 0; |
| 2027 | |
| 2028 | if (type == 0) |
| 2029 | { |
| 2030 | if (pp->pcap_rx_enable) |
| 2031 | { |
| 2032 | s = format (s, "rx"); |
| 2033 | printed = 1; |
| 2034 | } |
| 2035 | if (pp->pcap_tx_enable) |
| 2036 | { |
| 2037 | if (printed) |
| 2038 | s = format (s, " and "); |
| 2039 | s = format (s, "tx"); |
| 2040 | printed = 1; |
| 2041 | } |
| 2042 | if (pp->pcap_drop_enable) |
| 2043 | { |
| 2044 | if (printed) |
| 2045 | s = format (s, " and "); |
| 2046 | s = format (s, "drop"); |
| 2047 | printed = 1; |
| 2048 | } |
| 2049 | return s; |
| 2050 | } |
| 2051 | s = format (s, "unknown type %d!", type); |
| 2052 | return s; |
| 2053 | } |
| 2054 | |
| 2055 | |
Dave Barach | b97641c | 2019-09-09 16:38:17 -0400 | [diff] [blame] | 2056 | int |
| 2057 | vnet_pcap_dispatch_trace_configure (vnet_pcap_dispatch_trace_args_t * a) |
| 2058 | { |
| 2059 | vlib_main_t *vm = vlib_get_main (); |
Damjan Marion | 8fb5add | 2021-03-04 18:41:59 +0100 | [diff] [blame] | 2060 | vnet_main_t *vnm = vnet_get_main (); |
| 2061 | vnet_pcap_t *pp = &vnm->pcap; |
Dave Barach | b97641c | 2019-09-09 16:38:17 -0400 | [diff] [blame] | 2062 | pcap_main_t *pm = &pp->pcap_main; |
Dave Barach | f5667c3 | 2019-09-25 11:27:46 -0400 | [diff] [blame] | 2063 | vnet_classify_main_t *cm = &vnet_classify_main; |
Dave Barach | b97641c | 2019-09-09 16:38:17 -0400 | [diff] [blame] | 2064 | |
| 2065 | if (a->status) |
| 2066 | { |
Dave Barach | 3390977 | 2019-09-23 10:27:27 -0400 | [diff] [blame] | 2067 | if (pp->pcap_rx_enable || pp->pcap_tx_enable || pp->pcap_drop_enable) |
Dave Barach | b97641c | 2019-09-09 16:38:17 -0400 | [diff] [blame] | 2068 | { |
| 2069 | vlib_cli_output |
Dave Barach | 3390977 | 2019-09-23 10:27:27 -0400 | [diff] [blame] | 2070 | (vm, "pcap %U dispatch capture enabled: %d of %d pkts...", |
| 2071 | format_vnet_pcap, pp, 0 /* print type */ , |
Dave Barach | b97641c | 2019-09-09 16:38:17 -0400 | [diff] [blame] | 2072 | pm->n_packets_captured, pm->n_packets_to_capture); |
| 2073 | vlib_cli_output (vm, "capture to file %s", pm->file_name); |
| 2074 | } |
| 2075 | else |
Dave Barach | 3390977 | 2019-09-23 10:27:27 -0400 | [diff] [blame] | 2076 | vlib_cli_output (vm, "pcap dispatch capture disabled"); |
| 2077 | |
Dave Barach | b97641c | 2019-09-09 16:38:17 -0400 | [diff] [blame] | 2078 | return 0; |
| 2079 | } |
| 2080 | |
| 2081 | /* Consistency checks */ |
| 2082 | |
| 2083 | /* Enable w/ capture already enabled not allowed */ |
Dave Barach | 3390977 | 2019-09-23 10:27:27 -0400 | [diff] [blame] | 2084 | if ((pp->pcap_rx_enable + pp->pcap_tx_enable + pp->pcap_drop_enable) |
| 2085 | && (a->rx_enable + a->tx_enable + a->drop_enable)) |
Dave Barach | b97641c | 2019-09-09 16:38:17 -0400 | [diff] [blame] | 2086 | return VNET_API_ERROR_INVALID_VALUE; |
| 2087 | |
| 2088 | /* Disable capture with capture already disabled, not interesting */ |
Mohammed Hawari | 9fecbe1 | 2020-12-11 19:36:37 +0100 | [diff] [blame] | 2089 | if (((pp->pcap_rx_enable + pp->pcap_tx_enable + pp->pcap_drop_enable) == |
| 2090 | 0) && |
| 2091 | ((a->rx_enable + a->tx_enable + a->drop_enable == 0))) |
Dave Barach | b97641c | 2019-09-09 16:38:17 -0400 | [diff] [blame] | 2092 | return VNET_API_ERROR_VALUE_EXIST; |
| 2093 | |
| 2094 | /* Change number of packets to capture while capturing */ |
Dave Barach | 3390977 | 2019-09-23 10:27:27 -0400 | [diff] [blame] | 2095 | if ((pp->pcap_rx_enable + pp->pcap_tx_enable + pp->pcap_drop_enable) |
| 2096 | && (a->rx_enable + a->tx_enable + a->drop_enable) |
Dave Barach | b97641c | 2019-09-09 16:38:17 -0400 | [diff] [blame] | 2097 | && (pm->n_packets_to_capture != a->packets_to_capture)) |
| 2098 | return VNET_API_ERROR_INVALID_VALUE_2; |
| 2099 | |
Dave Barach | 3390977 | 2019-09-23 10:27:27 -0400 | [diff] [blame] | 2100 | /* Classify filter specified, but no classify filter configured */ |
Dave Barach | f5667c3 | 2019-09-25 11:27:46 -0400 | [diff] [blame] | 2101 | if ((a->rx_enable + a->tx_enable + a->drop_enable) && a->filter && |
Benoît Ganne | 5943e36 | 2021-02-26 14:46:58 +0100 | [diff] [blame] | 2102 | (!cm->classify_table_index_by_sw_if_index || |
| 2103 | cm->classify_table_index_by_sw_if_index[0] == ~0)) |
Dave Barach | 9137e54 | 2019-09-13 17:47:50 -0400 | [diff] [blame] | 2104 | return VNET_API_ERROR_NO_SUCH_LABEL; |
| 2105 | |
Dave Barach | 3390977 | 2019-09-23 10:27:27 -0400 | [diff] [blame] | 2106 | if (a->rx_enable + a->tx_enable + a->drop_enable) |
Dave Barach | b97641c | 2019-09-09 16:38:17 -0400 | [diff] [blame] | 2107 | { |
Dave Barach | 586462f | 2020-08-05 16:12:35 -0400 | [diff] [blame] | 2108 | void *save_pcap_data; |
| 2109 | |
Dave Barach | 3390977 | 2019-09-23 10:27:27 -0400 | [diff] [blame] | 2110 | /* Sanity check max bytes per pkt */ |
| 2111 | if (a->max_bytes_per_pkt < 32 || a->max_bytes_per_pkt > 9000) |
| 2112 | return VNET_API_ERROR_INVALID_MEMORY_SIZE; |
| 2113 | |
Dave Barach | b97641c | 2019-09-09 16:38:17 -0400 | [diff] [blame] | 2114 | /* Clean up from previous run, if any */ |
Dave Barach | 586462f | 2020-08-05 16:12:35 -0400 | [diff] [blame] | 2115 | vec_reset_length (pm->pcap_data); |
| 2116 | |
| 2117 | /* Throw away the data buffer? */ |
| 2118 | if (a->free_data) |
| 2119 | vec_free (pm->pcap_data); |
| 2120 | |
| 2121 | save_pcap_data = pm->pcap_data; |
| 2122 | |
Dave Barach | b97641c | 2019-09-09 16:38:17 -0400 | [diff] [blame] | 2123 | memset (pm, 0, sizeof (*pm)); |
| 2124 | |
Dave Barach | 586462f | 2020-08-05 16:12:35 -0400 | [diff] [blame] | 2125 | pm->pcap_data = save_pcap_data; |
| 2126 | |
Dave Barach | 11fb09e | 2020-08-06 12:10:09 -0400 | [diff] [blame] | 2127 | vec_validate_aligned (vnet_trace_placeholder, 2048, |
| 2128 | CLIB_CACHE_LINE_BYTES); |
Dave Barach | b97641c | 2019-09-09 16:38:17 -0400 | [diff] [blame] | 2129 | if (pm->lock == 0) |
| 2130 | clib_spinlock_init (&(pm->lock)); |
| 2131 | |
| 2132 | if (a->filename == 0) |
Dave Barach | 3390977 | 2019-09-23 10:27:27 -0400 | [diff] [blame] | 2133 | { |
| 2134 | u8 *stem = 0; |
| 2135 | |
| 2136 | if (a->rx_enable) |
| 2137 | stem = format (stem, "rx"); |
| 2138 | if (a->tx_enable) |
| 2139 | stem = format (stem, "tx"); |
| 2140 | if (a->drop_enable) |
| 2141 | stem = format (stem, "drop"); |
Benoît Ganne | 7d4a997 | 2020-07-17 11:49:56 +0200 | [diff] [blame] | 2142 | a->filename = format (0, "/tmp/%v.pcap%c", stem, 0); |
Dave Barach | 3390977 | 2019-09-23 10:27:27 -0400 | [diff] [blame] | 2143 | vec_free (stem); |
| 2144 | } |
Dave Barach | b97641c | 2019-09-09 16:38:17 -0400 | [diff] [blame] | 2145 | |
| 2146 | pm->file_name = (char *) a->filename; |
| 2147 | pm->n_packets_captured = 0; |
| 2148 | pm->packet_type = PCAP_PACKET_TYPE_ethernet; |
Dave Barach | 586462f | 2020-08-05 16:12:35 -0400 | [diff] [blame] | 2149 | /* Preallocate the data vector? */ |
| 2150 | if (a->preallocate_data) |
| 2151 | { |
| 2152 | vec_validate |
| 2153 | (pm->pcap_data, a->packets_to_capture |
| 2154 | * ((sizeof (pcap_packet_header_t) + a->max_bytes_per_pkt))); |
| 2155 | vec_reset_length (pm->pcap_data); |
| 2156 | } |
Dave Barach | b97641c | 2019-09-09 16:38:17 -0400 | [diff] [blame] | 2157 | pm->n_packets_to_capture = a->packets_to_capture; |
| 2158 | pp->pcap_sw_if_index = a->sw_if_index; |
Dave Barach | 9137e54 | 2019-09-13 17:47:50 -0400 | [diff] [blame] | 2159 | if (a->filter) |
Jon Loeliger | 5c1e48c | 2020-10-15 14:41:36 -0400 | [diff] [blame] | 2160 | pp->filter_classify_table_index = |
| 2161 | cm->classify_table_index_by_sw_if_index[0]; |
Dave Barach | 9137e54 | 2019-09-13 17:47:50 -0400 | [diff] [blame] | 2162 | else |
| 2163 | pp->filter_classify_table_index = ~0; |
Benoît Ganne | 5cfe452 | 2021-03-03 17:37:25 +0100 | [diff] [blame] | 2164 | pp->pcap_error_index = a->drop_err; |
Dave Barach | 3390977 | 2019-09-23 10:27:27 -0400 | [diff] [blame] | 2165 | pp->pcap_rx_enable = a->rx_enable; |
| 2166 | pp->pcap_tx_enable = a->tx_enable; |
| 2167 | pp->pcap_drop_enable = a->drop_enable; |
| 2168 | pp->max_bytes_per_pkt = a->max_bytes_per_pkt; |
Dave Barach | b97641c | 2019-09-09 16:38:17 -0400 | [diff] [blame] | 2169 | } |
| 2170 | else |
| 2171 | { |
Dave Barach | 3390977 | 2019-09-23 10:27:27 -0400 | [diff] [blame] | 2172 | pp->pcap_rx_enable = 0; |
| 2173 | pp->pcap_tx_enable = 0; |
| 2174 | pp->pcap_drop_enable = 0; |
Dave Barach | f5667c3 | 2019-09-25 11:27:46 -0400 | [diff] [blame] | 2175 | pp->filter_classify_table_index = ~0; |
Benoît Ganne | 5cfe452 | 2021-03-03 17:37:25 +0100 | [diff] [blame] | 2176 | pp->pcap_error_index = ~0; |
Dave Barach | b97641c | 2019-09-09 16:38:17 -0400 | [diff] [blame] | 2177 | if (pm->n_packets_captured) |
| 2178 | { |
| 2179 | clib_error_t *error; |
| 2180 | pm->n_packets_to_capture = pm->n_packets_captured; |
| 2181 | vlib_cli_output (vm, "Write %d packets to %s, and stop capture...", |
| 2182 | pm->n_packets_captured, pm->file_name); |
| 2183 | error = pcap_write (pm); |
Andrew Yourtchenko | 4da1506 | 2019-09-11 14:14:43 +0000 | [diff] [blame] | 2184 | if (pm->flags & PCAP_MAIN_INIT_DONE) |
Dave Barach | b97641c | 2019-09-09 16:38:17 -0400 | [diff] [blame] | 2185 | pcap_close (pm); |
| 2186 | /* Report I/O errors... */ |
| 2187 | if (error) |
| 2188 | { |
| 2189 | clib_error_report (error); |
| 2190 | return VNET_API_ERROR_SYSCALL_ERROR_1; |
| 2191 | } |
Dave Barach | 586462f | 2020-08-05 16:12:35 -0400 | [diff] [blame] | 2192 | vec_free (pm->file_name); |
| 2193 | if (a->free_data) |
| 2194 | vec_free (pm->pcap_data); |
Dave Barach | b97641c | 2019-09-09 16:38:17 -0400 | [diff] [blame] | 2195 | return 0; |
| 2196 | } |
| 2197 | else |
| 2198 | return VNET_API_ERROR_NO_SUCH_ENTRY; |
| 2199 | } |
| 2200 | |
| 2201 | return 0; |
| 2202 | } |
| 2203 | |
| 2204 | static clib_error_t * |
Dave Barach | 3390977 | 2019-09-23 10:27:27 -0400 | [diff] [blame] | 2205 | pcap_trace_command_fn (vlib_main_t * vm, |
| 2206 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Dave Barach | 5ecd5a5 | 2019-02-25 15:27:28 -0500 | [diff] [blame] | 2207 | { |
Dave Barach | 5ecd5a5 | 2019-02-25 15:27:28 -0500 | [diff] [blame] | 2208 | unformat_input_t _line_input, *line_input = &_line_input; |
Dave Barach | b97641c | 2019-09-09 16:38:17 -0400 | [diff] [blame] | 2209 | vnet_pcap_dispatch_trace_args_t _a, *a = &_a; |
Dave Barach | 5ecd5a5 | 2019-02-25 15:27:28 -0500 | [diff] [blame] | 2210 | vnet_main_t *vnm = vnet_get_main (); |
Dave Barach | b97641c | 2019-09-09 16:38:17 -0400 | [diff] [blame] | 2211 | u8 *filename = 0; |
| 2212 | u32 max = 1000; |
Dave Barach | 3390977 | 2019-09-23 10:27:27 -0400 | [diff] [blame] | 2213 | u32 max_bytes_per_pkt = 512; |
Dave Barach | b97641c | 2019-09-09 16:38:17 -0400 | [diff] [blame] | 2214 | int rv; |
Dave Barach | 3390977 | 2019-09-23 10:27:27 -0400 | [diff] [blame] | 2215 | int rx_enable = 0; |
| 2216 | int tx_enable = 0; |
Dave Barach | 586462f | 2020-08-05 16:12:35 -0400 | [diff] [blame] | 2217 | int preallocate_data = 0; |
Dave Barach | 3390977 | 2019-09-23 10:27:27 -0400 | [diff] [blame] | 2218 | int drop_enable = 0; |
Dave Barach | b97641c | 2019-09-09 16:38:17 -0400 | [diff] [blame] | 2219 | int status = 0; |
Dave Barach | 9137e54 | 2019-09-13 17:47:50 -0400 | [diff] [blame] | 2220 | int filter = 0; |
Dave Barach | 586462f | 2020-08-05 16:12:35 -0400 | [diff] [blame] | 2221 | int free_data = 0; |
Dave Barach | 4330c46 | 2020-06-10 17:07:32 -0400 | [diff] [blame] | 2222 | u32 sw_if_index = 0; /* default: any interface */ |
Benoît Ganne | 5cfe452 | 2021-03-03 17:37:25 +0100 | [diff] [blame] | 2223 | vlib_error_t drop_err = ~0; /* default: any error */ |
Dave Barach | 5ecd5a5 | 2019-02-25 15:27:28 -0500 | [diff] [blame] | 2224 | |
| 2225 | /* Get a line of input. */ |
| 2226 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 2227 | return 0; |
| 2228 | |
| 2229 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 2230 | { |
Dave Barach | 3390977 | 2019-09-23 10:27:27 -0400 | [diff] [blame] | 2231 | if (unformat (line_input, "rx")) |
| 2232 | rx_enable = 1; |
| 2233 | else if (unformat (line_input, "tx")) |
| 2234 | tx_enable = 1; |
| 2235 | else if (unformat (line_input, "drop")) |
| 2236 | drop_enable = 1; |
| 2237 | else if (unformat (line_input, "off")) |
| 2238 | rx_enable = tx_enable = drop_enable = 0; |
| 2239 | else if (unformat (line_input, "max-bytes-per-pkt %u", |
| 2240 | &max_bytes_per_pkt)) |
Dave Barach | b97641c | 2019-09-09 16:38:17 -0400 | [diff] [blame] | 2241 | ; |
| 2242 | else if (unformat (line_input, "max %d", &max)) |
| 2243 | ; |
| 2244 | else if (unformat (line_input, "packets-to-capture %d", &max)) |
| 2245 | ; |
| 2246 | else if (unformat (line_input, "file %U", unformat_vlib_tmpfile, |
| 2247 | &filename)) |
| 2248 | ; |
| 2249 | else if (unformat (line_input, "status %=", &status, 1)) |
| 2250 | ; |
| 2251 | else if (unformat (line_input, "intfc %U", |
| 2252 | unformat_vnet_sw_interface, vnm, &sw_if_index)) |
| 2253 | ; |
Dave Barach | 586462f | 2020-08-05 16:12:35 -0400 | [diff] [blame] | 2254 | else if (unformat (line_input, "interface %U", |
| 2255 | unformat_vnet_sw_interface, vnm, &sw_if_index)) |
| 2256 | ; |
Benoît Ganne | 5cfe452 | 2021-03-03 17:37:25 +0100 | [diff] [blame] | 2257 | else if (unformat (line_input, "error %U", unformat_vlib_error, vm, |
| 2258 | &drop_err)) |
| 2259 | ; |
Dave Barach | 586462f | 2020-08-05 16:12:35 -0400 | [diff] [blame] | 2260 | else if (unformat (line_input, "preallocate-data %=", |
| 2261 | &preallocate_data, 1)) |
| 2262 | ; |
| 2263 | else if (unformat (line_input, "free-data %=", &free_data, 1)) |
| 2264 | ; |
| 2265 | else if (unformat (line_input, "intfc any") |
| 2266 | || unformat (line_input, "interface any")) |
Dave Barach | b97641c | 2019-09-09 16:38:17 -0400 | [diff] [blame] | 2267 | sw_if_index = 0; |
Dave Barach | 9137e54 | 2019-09-13 17:47:50 -0400 | [diff] [blame] | 2268 | else if (unformat (line_input, "filter")) |
| 2269 | filter = 1; |
Dave Barach | 5ecd5a5 | 2019-02-25 15:27:28 -0500 | [diff] [blame] | 2270 | else |
| 2271 | { |
Dave Barach | b97641c | 2019-09-09 16:38:17 -0400 | [diff] [blame] | 2272 | return clib_error_return (0, "unknown input `%U'", |
| 2273 | format_unformat_error, line_input); |
Dave Barach | 5ecd5a5 | 2019-02-25 15:27:28 -0500 | [diff] [blame] | 2274 | } |
| 2275 | } |
Dave Barach | b97641c | 2019-09-09 16:38:17 -0400 | [diff] [blame] | 2276 | |
Dave Barach | 5ecd5a5 | 2019-02-25 15:27:28 -0500 | [diff] [blame] | 2277 | unformat_free (line_input); |
| 2278 | |
Dave Barach | b97641c | 2019-09-09 16:38:17 -0400 | [diff] [blame] | 2279 | /* no need for memset (a, 0, sizeof (*a)), set all fields here. */ |
| 2280 | a->filename = filename; |
Dave Barach | 3390977 | 2019-09-23 10:27:27 -0400 | [diff] [blame] | 2281 | a->rx_enable = rx_enable; |
| 2282 | a->tx_enable = tx_enable; |
Dave Barach | 586462f | 2020-08-05 16:12:35 -0400 | [diff] [blame] | 2283 | a->preallocate_data = preallocate_data; |
| 2284 | a->free_data = free_data; |
Dave Barach | 3390977 | 2019-09-23 10:27:27 -0400 | [diff] [blame] | 2285 | a->drop_enable = drop_enable; |
Dave Barach | b97641c | 2019-09-09 16:38:17 -0400 | [diff] [blame] | 2286 | a->status = status; |
| 2287 | a->packets_to_capture = max; |
Dave Barach | b97641c | 2019-09-09 16:38:17 -0400 | [diff] [blame] | 2288 | a->sw_if_index = sw_if_index; |
Dave Barach | 9137e54 | 2019-09-13 17:47:50 -0400 | [diff] [blame] | 2289 | a->filter = filter; |
Dave Barach | 3390977 | 2019-09-23 10:27:27 -0400 | [diff] [blame] | 2290 | a->max_bytes_per_pkt = max_bytes_per_pkt; |
Benoît Ganne | 5cfe452 | 2021-03-03 17:37:25 +0100 | [diff] [blame] | 2291 | a->drop_err = drop_err; |
Dave Barach | 5ecd5a5 | 2019-02-25 15:27:28 -0500 | [diff] [blame] | 2292 | |
Dave Barach | b97641c | 2019-09-09 16:38:17 -0400 | [diff] [blame] | 2293 | rv = vnet_pcap_dispatch_trace_configure (a); |
| 2294 | |
| 2295 | switch (rv) |
Dave Barach | 5ecd5a5 | 2019-02-25 15:27:28 -0500 | [diff] [blame] | 2296 | { |
Dave Barach | b97641c | 2019-09-09 16:38:17 -0400 | [diff] [blame] | 2297 | case 0: |
| 2298 | break; |
Dave Barach | 5ecd5a5 | 2019-02-25 15:27:28 -0500 | [diff] [blame] | 2299 | |
Dave Barach | b97641c | 2019-09-09 16:38:17 -0400 | [diff] [blame] | 2300 | case VNET_API_ERROR_INVALID_VALUE: |
| 2301 | return clib_error_return (0, "dispatch trace already enabled..."); |
Dave Barach | 5ecd5a5 | 2019-02-25 15:27:28 -0500 | [diff] [blame] | 2302 | |
Dave Barach | b97641c | 2019-09-09 16:38:17 -0400 | [diff] [blame] | 2303 | case VNET_API_ERROR_VALUE_EXIST: |
| 2304 | return clib_error_return (0, "dispatch trace already disabled..."); |
Dave Barach | 5ecd5a5 | 2019-02-25 15:27:28 -0500 | [diff] [blame] | 2305 | |
Dave Barach | b97641c | 2019-09-09 16:38:17 -0400 | [diff] [blame] | 2306 | case VNET_API_ERROR_INVALID_VALUE_2: |
| 2307 | return clib_error_return |
| 2308 | (0, "can't change number of records to capture while tracing..."); |
| 2309 | |
| 2310 | case VNET_API_ERROR_SYSCALL_ERROR_1: |
| 2311 | return clib_error_return (0, "I/O writing trace capture..."); |
| 2312 | |
| 2313 | case VNET_API_ERROR_NO_SUCH_ENTRY: |
| 2314 | return clib_error_return (0, "No packets captured..."); |
| 2315 | |
Dave Barach | 3390977 | 2019-09-23 10:27:27 -0400 | [diff] [blame] | 2316 | case VNET_API_ERROR_INVALID_MEMORY_SIZE: |
| 2317 | return clib_error_return (0, |
| 2318 | "Max bytes per pkt must be > 32, < 9000..."); |
| 2319 | |
Dave Barach | 9137e54 | 2019-09-13 17:47:50 -0400 | [diff] [blame] | 2320 | case VNET_API_ERROR_NO_SUCH_LABEL: |
| 2321 | return clib_error_return |
| 2322 | (0, "No classify filter configured, see 'classify filter...'"); |
| 2323 | |
Dave Barach | b97641c | 2019-09-09 16:38:17 -0400 | [diff] [blame] | 2324 | default: |
| 2325 | vlib_cli_output (vm, "WARNING: trace configure returned %d", rv); |
| 2326 | break; |
Dave Barach | 5ecd5a5 | 2019-02-25 15:27:28 -0500 | [diff] [blame] | 2327 | } |
Dave Barach | b97641c | 2019-09-09 16:38:17 -0400 | [diff] [blame] | 2328 | return 0; |
Dave Barach | 5ecd5a5 | 2019-02-25 15:27:28 -0500 | [diff] [blame] | 2329 | } |
| 2330 | |
Dave Barach | 5ecd5a5 | 2019-02-25 15:27:28 -0500 | [diff] [blame] | 2331 | /*? |
| 2332 | * This command is used to start or stop a packet capture, or show |
Dave Barach | 3390977 | 2019-09-23 10:27:27 -0400 | [diff] [blame] | 2333 | * the status of packet capture. |
Dave Barach | 5ecd5a5 | 2019-02-25 15:27:28 -0500 | [diff] [blame] | 2334 | * |
| 2335 | * This command has the following optional parameters: |
| 2336 | * |
Dave Barach | 3390977 | 2019-09-23 10:27:27 -0400 | [diff] [blame] | 2337 | * |
| 2338 | * - <b>rx</b> - Capture received packets |
| 2339 | * |
| 2340 | * - <b>tx</b> - Capture transmitted packets |
| 2341 | * |
| 2342 | * - <b>drop</b> - Capture dropped packets |
| 2343 | * |
| 2344 | * - <b>off</b> - Stop capturing packets, write results to the specified file |
Dave Barach | 5ecd5a5 | 2019-02-25 15:27:28 -0500 | [diff] [blame] | 2345 | * |
| 2346 | * - <b>max <nn></b> - Depth of local buffer. Once '<em>nn</em>' number |
| 2347 | * of packets have been received, buffer is flushed to file. Once another |
| 2348 | * '<em>nn</em>' number of packets have been received, buffer is flushed |
| 2349 | * to file, overwriting previous write. If not entered, value defaults |
| 2350 | * to 100. Can only be updated if packet capture is off. |
| 2351 | * |
Dave Barach | 3390977 | 2019-09-23 10:27:27 -0400 | [diff] [blame] | 2352 | * - <b>max-bytes-per-pkt <nnnn></b> - Maximum number of bytes to capture |
| 2353 | * for each packet. Must be >= 32, <= 9000. |
| 2354 | * |
Dave Barach | 586462f | 2020-08-05 16:12:35 -0400 | [diff] [blame] | 2355 | * - <b>preallocate-data</b> - Preallocate the data buffer, to avoid |
| 2356 | * vector expansion delays during pcap capture |
| 2357 | * |
| 2358 | * - <b>free-data</b> - Free the data buffer. Ordinarily it's a feature |
| 2359 | * to retain the data buffer so this option is seldom used. |
| 2360 | * |
Dave Barach | 3390977 | 2019-09-23 10:27:27 -0400 | [diff] [blame] | 2361 | * - <b>intfc <interface-name>|any</b> - Used to specify a given interface, |
Dave Barach | 5ecd5a5 | 2019-02-25 15:27:28 -0500 | [diff] [blame] | 2362 | * or use '<em>any</em>' to run packet capture on all interfaces. |
| 2363 | * '<em>any</em>' is the default if not provided. Settings from a previous |
| 2364 | * packet capture are preserved, so '<em>any</em>' can be used to reset |
| 2365 | * the interface setting. |
| 2366 | * |
Dave Barach | f5667c3 | 2019-09-25 11:27:46 -0400 | [diff] [blame] | 2367 | * - <b>filter</b> - Use the pcap rx / tx / drop trace filter, which |
| 2368 | * must be configured. Use <b>classify filter pcap...</b> to configure the |
| 2369 | * filter. The filter will only be executed if the per-interface or |
| 2370 | * any-interface tests fail. |
| 2371 | * |
Benoît Ganne | 5cfe452 | 2021-03-03 17:37:25 +0100 | [diff] [blame] | 2372 | * - <b>error <node>.<error></b> - filter packets based on a specific error. |
| 2373 | * For example: error {ip4-udp-lookup}.{No listener for dst port} |
| 2374 | * |
Dave Barach | 5ecd5a5 | 2019-02-25 15:27:28 -0500 | [diff] [blame] | 2375 | * - <b>file <name></b> - Used to specify the output filename. The file will |
| 2376 | * be placed in the '<em>/tmp</em>' directory, so only the filename is |
| 2377 | * supported. Directory should not be entered. If file already exists, file |
Dave Barach | 3390977 | 2019-09-23 10:27:27 -0400 | [diff] [blame] | 2378 | * will be overwritten. If no filename is provided, the file will be |
| 2379 | * named "/tmp/rx.pcap", "/tmp/tx.pcap", "/tmp/rxandtx.pcap", etc. |
| 2380 | * Can only be updated if packet capture is off. |
Dave Barach | 5ecd5a5 | 2019-02-25 15:27:28 -0500 | [diff] [blame] | 2381 | * |
| 2382 | * - <b>status</b> - Displays the current status and configured attributes |
| 2383 | * associated with a packet capture. If packet capture is in progress, |
| 2384 | * '<em>status</em>' also will return the number of packets currently in |
| 2385 | * the local buffer. All additional attributes entered on command line |
| 2386 | * with '<em>status</em>' will be ignored and not applied. |
| 2387 | * |
| 2388 | * @cliexpar |
| 2389 | * Example of how to display the status of a tx packet capture when off: |
Dave Barach | 3390977 | 2019-09-23 10:27:27 -0400 | [diff] [blame] | 2390 | * @cliexstart{pcap trace status} |
Dave Barach | 5ecd5a5 | 2019-02-25 15:27:28 -0500 | [diff] [blame] | 2391 | * max is 100, for any interface to file /tmp/vpe.pcap |
| 2392 | * pcap tx capture is off... |
| 2393 | * @cliexend |
| 2394 | * Example of how to start a tx packet capture: |
Benoît Ganne | 5cfe452 | 2021-03-03 17:37:25 +0100 | [diff] [blame] | 2395 | * @cliexstart{pcap trace tx max 35 intfc GigabitEthernet0/8/0 file |
Nathan Skrzypczak | 2c77ae4 | 2021-09-29 15:36:51 +0200 | [diff] [blame] | 2396 | * vppTest.pcap} |
Dave Barach | 5ecd5a5 | 2019-02-25 15:27:28 -0500 | [diff] [blame] | 2397 | * @cliexend |
| 2398 | * Example of how to display the status of a tx packet capture in progress: |
Dave Barach | 3390977 | 2019-09-23 10:27:27 -0400 | [diff] [blame] | 2399 | * @cliexstart{pcap trace status} |
Dave Barach | 5ecd5a5 | 2019-02-25 15:27:28 -0500 | [diff] [blame] | 2400 | * max is 35, for interface GigabitEthernet0/8/0 to file /tmp/vppTest.pcap |
| 2401 | * pcap tx capture is on: 20 of 35 pkts... |
| 2402 | * @cliexend |
| 2403 | * Example of how to stop a tx packet capture: |
Dave Barach | 3390977 | 2019-09-23 10:27:27 -0400 | [diff] [blame] | 2404 | * @cliexstart{pcap trace off} |
Dave Barach | 5ecd5a5 | 2019-02-25 15:27:28 -0500 | [diff] [blame] | 2405 | * captured 21 pkts... |
| 2406 | * saved to /tmp/vppTest.pcap... |
| 2407 | * @cliexend |
| 2408 | ?*/ |
| 2409 | /* *INDENT-OFF* */ |
| 2410 | |
| 2411 | VLIB_CLI_COMMAND (pcap_tx_trace_command, static) = { |
Dave Barach | 3390977 | 2019-09-23 10:27:27 -0400 | [diff] [blame] | 2412 | .path = "pcap trace", |
Dave Barach | 5ecd5a5 | 2019-02-25 15:27:28 -0500 | [diff] [blame] | 2413 | .short_help = |
Dave Barach | 586462f | 2020-08-05 16:12:35 -0400 | [diff] [blame] | 2414 | "pcap trace [rx] [tx] [drop] [off] [max <nn>] [intfc <interface>|any]\n" |
| 2415 | " [file <name>] [status] [max-bytes-per-pkt <nnnn>][filter]\n" |
| 2416 | " [preallocate-data][free-data]", |
Dave Barach | 3390977 | 2019-09-23 10:27:27 -0400 | [diff] [blame] | 2417 | .function = pcap_trace_command_fn, |
Dave Barach | 5ecd5a5 | 2019-02-25 15:27:28 -0500 | [diff] [blame] | 2418 | }; |
| 2419 | /* *INDENT-ON* */ |
| 2420 | |
Steven Luong | f49734d | 2021-07-26 13:38:05 -0700 | [diff] [blame] | 2421 | static clib_error_t * |
| 2422 | set_interface_name (vlib_main_t *vm, unformat_input_t *input, |
| 2423 | vlib_cli_command_t *cmd) |
| 2424 | { |
| 2425 | clib_error_t *error = 0; |
| 2426 | unformat_input_t _line_input, *line_input = &_line_input; |
| 2427 | vnet_main_t *vnm = vnet_get_main (); |
| 2428 | u32 hw_if_index = ~0; |
| 2429 | char *name = 0; |
| 2430 | |
| 2431 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 2432 | return 0; |
| 2433 | |
| 2434 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 2435 | { |
| 2436 | if (unformat (line_input, "%U %s", unformat_vnet_hw_interface, vnm, |
| 2437 | &hw_if_index, &name)) |
| 2438 | ; |
| 2439 | else |
| 2440 | { |
| 2441 | error = clib_error_return (0, "parse error: '%U'", |
| 2442 | format_unformat_error, line_input); |
| 2443 | unformat_free (line_input); |
| 2444 | vec_free (name); |
| 2445 | return error; |
| 2446 | } |
| 2447 | } |
| 2448 | |
| 2449 | unformat_free (line_input); |
| 2450 | |
| 2451 | if (hw_if_index == (u32) ~0 || name == 0) |
| 2452 | { |
| 2453 | vec_free (name); |
| 2454 | error = clib_error_return (0, "please specify valid interface name"); |
| 2455 | return error; |
| 2456 | } |
| 2457 | |
| 2458 | error = vnet_rename_interface (vnm, hw_if_index, name); |
| 2459 | vec_free (name); |
| 2460 | |
| 2461 | return (error); |
| 2462 | } |
| 2463 | |
| 2464 | VLIB_CLI_COMMAND (cmd_set_if_name, static) = { |
| 2465 | .path = "set interface name", |
| 2466 | .short_help = "set interface name <interface-name> <new-interface-name>", |
| 2467 | .function = set_interface_name, |
| 2468 | .is_mp_safe = 1, |
| 2469 | }; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 2470 | /* |
| 2471 | * fd.io coding-style-patch-verification: ON |
| 2472 | * |
| 2473 | * Local Variables: |
| 2474 | * eval: (c-set-style "gnu") |
| 2475 | * End: |
| 2476 | */ |