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