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