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