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