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