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