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 |
| 42 | * Interface CLI. |
| 43 | */ |
| 44 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 45 | #include <vnet/vnet.h> |
| 46 | #include <vnet/ip/ip.h> |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 47 | #include <vppinfra/bitmap.h> |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 48 | #include <vnet/fib/ip4_fib.h> |
| 49 | #include <vnet/fib/ip6_fib.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 50 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 51 | static int |
| 52 | compare_interface_names (void *a1, void *a2) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 53 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 54 | u32 *hi1 = a1; |
| 55 | u32 *hi2 = a2; |
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 | return vnet_hw_interface_compare (vnet_get_main (), *hi1, *hi2); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | static clib_error_t * |
| 61 | show_or_clear_hw_interfaces (vlib_main_t * vm, |
| 62 | unformat_input_t * input, |
| 63 | vlib_cli_command_t * cmd) |
| 64 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 65 | clib_error_t *error = 0; |
| 66 | vnet_main_t *vnm = vnet_get_main (); |
| 67 | vnet_interface_main_t *im = &vnm->interface_main; |
| 68 | vnet_hw_interface_t *hi; |
| 69 | u32 hw_if_index, *hw_if_indices = 0; |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 70 | int i, verbose = -1, is_show, show_bond = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 71 | |
| 72 | is_show = strstr (cmd->path, "show") != 0; |
| 73 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 74 | { |
| 75 | /* See if user wants to show a specific interface. */ |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 76 | if (unformat |
| 77 | (input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index)) |
| 78 | vec_add1 (hw_if_indices, hw_if_index); |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 79 | |
Sean Hope | 679ea79 | 2016-02-22 15:12:01 -0500 | [diff] [blame] | 80 | /* See if user wants to show an interface with a specific hw_if_index. */ |
| 81 | else if (unformat (input, "%u", &hw_if_index)) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 82 | vec_add1 (hw_if_indices, hw_if_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 83 | |
| 84 | else if (unformat (input, "verbose")) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 85 | verbose = 1; /* this is also the default */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 86 | |
| 87 | else if (unformat (input, "detail")) |
| 88 | verbose = 2; |
| 89 | |
| 90 | else if (unformat (input, "brief")) |
| 91 | verbose = 0; |
| 92 | |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 93 | else if (unformat (input, "bond")) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 94 | { |
| 95 | show_bond = 1; |
| 96 | if (verbose < 0) |
| 97 | verbose = 0; /* default to brief for link bonding */ |
| 98 | } |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 99 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 100 | else |
| 101 | { |
| 102 | error = clib_error_return (0, "unknown input `%U'", |
| 103 | format_unformat_error, input); |
| 104 | goto done; |
| 105 | } |
| 106 | } |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 107 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 108 | /* Gather interfaces. */ |
| 109 | if (vec_len (hw_if_indices) == 0) |
| 110 | pool_foreach (hi, im->hw_interfaces, |
| 111 | vec_add1 (hw_if_indices, hi - im->hw_interfaces)); |
| 112 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 113 | if (verbose < 0) |
| 114 | verbose = 1; /* default to verbose (except bond) */ |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 115 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 116 | if (is_show) |
| 117 | { |
| 118 | /* Sort by name. */ |
| 119 | vec_sort_with_function (hw_if_indices, compare_interface_names); |
| 120 | |
| 121 | vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm, 0, verbose); |
| 122 | for (i = 0; i < vec_len (hw_if_indices); i++) |
| 123 | { |
| 124 | hi = vnet_get_hw_interface (vnm, hw_if_indices[i]); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 125 | if (show_bond == 0) /* show all interfaces */ |
| 126 | vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm, |
| 127 | hi, verbose); |
| 128 | else if ((hi->bond_info) && |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 129 | (hi->bond_info != VNET_HW_INTERFACE_BOND_INFO_SLAVE)) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 130 | { /* show only bonded interface and all its slave interfaces */ |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 131 | int hw_idx; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 132 | vnet_hw_interface_t *shi; |
| 133 | vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm, |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 134 | hi, verbose); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 135 | |
| 136 | /* *INDENT-OFF* */ |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 137 | clib_bitmap_foreach (hw_idx, hi->bond_info, |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 138 | ({ |
| 139 | shi = vnet_get_hw_interface(vnm, hw_idx); |
| 140 | vlib_cli_output (vm, "%U\n", |
| 141 | format_vnet_hw_interface, vnm, shi, verbose); |
| 142 | })); |
| 143 | /* *INDENT-ON* */ |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 144 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 145 | } |
| 146 | } |
| 147 | else |
| 148 | { |
| 149 | for (i = 0; i < vec_len (hw_if_indices); i++) |
| 150 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 151 | vnet_device_class_t *dc; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 152 | |
| 153 | hi = vnet_get_hw_interface (vnm, hw_if_indices[i]); |
| 154 | dc = vec_elt_at_index (im->device_classes, hi->dev_class_index); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 155 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 156 | if (dc->clear_counters) |
| 157 | dc->clear_counters (hi->dev_instance); |
| 158 | } |
| 159 | } |
| 160 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 161 | done: |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 162 | vec_free (hw_if_indices); |
| 163 | return error; |
| 164 | } |
| 165 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 166 | /* *INDENT-OFF* */ |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 167 | /*? |
| 168 | * Displays various information about the state of the current terminal |
| 169 | * session. |
| 170 | * |
| 171 | * @cliexpar |
| 172 | * @cliexstart{show hardware} |
| 173 | * Name Link Hardware |
| 174 | * GigabitEthernet2/0/0 up GigabitEthernet2/0/0 |
| 175 | * Ethernet address 00:50:56:b7:7c:83 |
| 176 | * Intel 82545em_copper |
| 177 | * link up, media 1000T full-duplex, master, |
| 178 | * 0 unprocessed, 384 total buffers on rx queue 0 ring |
| 179 | * 237 buffers in driver rx cache |
| 180 | * rx total packets 1816 |
| 181 | * rx total bytes 181084 |
| 182 | * rx good packets 1816 |
| 183 | * rx good bytes 181084 |
| 184 | * rx 65 127 byte packets 1586 |
| 185 | * rx 256 511 byte packets 230 |
| 186 | * tx total packets 346 |
| 187 | * tx total bytes 90224 |
| 188 | * tx good packets 346 |
| 189 | * tx good bytes 88840 |
| 190 | * tx 64 byte packets 1 |
| 191 | * tx 65 127 byte packets 115 |
| 192 | * tx 256 511 byte packets 230 |
| 193 | * @cliexend |
| 194 | ?*/ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 195 | VLIB_CLI_COMMAND (show_hw_interfaces_command, static) = { |
| 196 | .path = "show hardware-interfaces", |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 197 | .short_help = "show hardware-interfaces [brief|verbose|detail] [bond] [<if-name1> <if-name2> ...]", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 198 | .function = show_or_clear_hw_interfaces, |
| 199 | }; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 200 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 201 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 202 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 203 | VLIB_CLI_COMMAND (clear_hw_interface_counters_command, static) = { |
| 204 | .path = "clear hardware-interfaces", |
| 205 | .short_help = "Clear hardware interfaces statistics", |
| 206 | .function = show_or_clear_hw_interfaces, |
| 207 | }; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 208 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 209 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 210 | static int |
| 211 | sw_interface_name_compare (void *a1, void *a2) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 212 | { |
| 213 | vnet_sw_interface_t *si1 = a1; |
| 214 | vnet_sw_interface_t *si2 = a2; |
| 215 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 216 | return vnet_sw_interface_compare (vnet_get_main (), |
| 217 | si1->sw_if_index, si2->sw_if_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | static clib_error_t * |
| 221 | show_sw_interfaces (vlib_main_t * vm, |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 222 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 223 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 224 | clib_error_t *error = 0; |
| 225 | vnet_main_t *vnm = vnet_get_main (); |
| 226 | vnet_interface_main_t *im = &vnm->interface_main; |
| 227 | vnet_sw_interface_t *si, *sorted_sis = 0; |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 228 | u32 sw_if_index = ~(u32) 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 229 | u8 show_addresses = 0; |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 230 | u8 show_features = 0; |
Dave Barach | 7be864a | 2016-11-28 11:41:35 -0500 | [diff] [blame] | 231 | u8 show_tag = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 232 | |
| 233 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 234 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 235 | /* See if user wants to show specific interface */ |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 236 | if (unformat |
| 237 | (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 238 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 239 | si = pool_elt_at_index (im->sw_interfaces, sw_if_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 240 | vec_add1 (sorted_sis, si[0]); |
| 241 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 242 | else if (unformat (input, "address") || unformat (input, "addr")) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 243 | show_addresses = 1; |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 244 | else if (unformat (input, "features") || unformat (input, "feat")) |
| 245 | show_features = 1; |
Dave Barach | 7be864a | 2016-11-28 11:41:35 -0500 | [diff] [blame] | 246 | else if (unformat (input, "tag")) |
| 247 | show_tag = 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 248 | else |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 249 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 250 | error = clib_error_return (0, "unknown input `%U'", |
| 251 | format_unformat_error, input); |
| 252 | goto done; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 253 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 254 | } |
| 255 | |
Dave Barach | 7be864a | 2016-11-28 11:41:35 -0500 | [diff] [blame] | 256 | if (show_features || show_tag) |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 257 | { |
| 258 | if (sw_if_index == ~(u32) 0) |
| 259 | return clib_error_return (0, "Interface not specified..."); |
Dave Barach | 7be864a | 2016-11-28 11:41:35 -0500 | [diff] [blame] | 260 | } |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 261 | |
Dave Barach | 7be864a | 2016-11-28 11:41:35 -0500 | [diff] [blame] | 262 | if (show_features) |
| 263 | { |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 264 | vnet_interface_features_show (vm, sw_if_index); |
| 265 | return 0; |
| 266 | } |
Dave Barach | 7be864a | 2016-11-28 11:41:35 -0500 | [diff] [blame] | 267 | if (show_tag) |
| 268 | { |
| 269 | u8 *tag; |
| 270 | tag = vnet_get_sw_interface_tag (vnm, sw_if_index); |
| 271 | vlib_cli_output (vm, "%U: %s", |
| 272 | format_vnet_sw_if_index_name, vnm, sw_if_index, |
| 273 | tag ? (char *) tag : "(none)"); |
| 274 | return 0; |
| 275 | } |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 276 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 277 | if (!show_addresses) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 278 | vlib_cli_output (vm, "%U\n", format_vnet_sw_interface, vnm, 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 279 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 280 | if (vec_len (sorted_sis) == 0) /* Get all interfaces */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 281 | { |
| 282 | /* Gather interfaces. */ |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 283 | sorted_sis = |
| 284 | vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 285 | _vec_len (sorted_sis) = 0; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 286 | pool_foreach (si, im->sw_interfaces, ( |
| 287 | { |
Eyal Bari | 3212c57 | 2017-03-06 11:47:50 +0200 | [diff] [blame] | 288 | if (vnet_swif_is_api_visible |
| 289 | (si)) vec_add1 (sorted_sis, |
| 290 | si[0]);} |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 291 | )); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 292 | |
| 293 | /* Sort by name. */ |
| 294 | vec_sort_with_function (sorted_sis, sw_interface_name_compare); |
| 295 | } |
| 296 | |
| 297 | if (show_addresses) |
| 298 | { |
| 299 | vec_foreach (si, sorted_sis) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 300 | { |
| 301 | l2input_main_t *l2m = &l2input_main; |
| 302 | ip4_main_t *im4 = &ip4_main; |
| 303 | ip6_main_t *im6 = &ip6_main; |
| 304 | ip_lookup_main_t *lm4 = &im4->lookup_main; |
| 305 | ip_lookup_main_t *lm6 = &im6->lookup_main; |
| 306 | ip_interface_address_t *ia = 0; |
| 307 | ip4_address_t *r4; |
| 308 | ip6_address_t *r6; |
| 309 | u32 fib_index4 = 0, fib_index6 = 0; |
| 310 | ip4_fib_t *fib4; |
| 311 | ip6_fib_t *fib6; |
| 312 | l2_input_config_t *config; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 313 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 314 | if (vec_len (im4->fib_index_by_sw_if_index) > si->sw_if_index) |
| 315 | fib_index4 = vec_elt (im4->fib_index_by_sw_if_index, |
| 316 | si->sw_if_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 317 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 318 | if (vec_len (im6->fib_index_by_sw_if_index) > si->sw_if_index) |
| 319 | fib_index6 = vec_elt (im6->fib_index_by_sw_if_index, |
| 320 | si->sw_if_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 321 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 322 | fib4 = ip4_fib_get (fib_index4); |
| 323 | fib6 = ip6_fib_get (fib_index6); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 324 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 325 | if (si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED) |
| 326 | vlib_cli_output |
| 327 | (vm, "%U (%s): \n unnumbered, use %U", |
| 328 | format_vnet_sw_if_index_name, |
| 329 | vnm, si->sw_if_index, |
| 330 | (si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? "up" : "dn", |
| 331 | format_vnet_sw_if_index_name, vnm, si->unnumbered_sw_if_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 332 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 333 | else |
| 334 | { |
| 335 | vlib_cli_output (vm, "%U (%s):", |
| 336 | format_vnet_sw_if_index_name, |
| 337 | vnm, si->sw_if_index, |
| 338 | (si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) |
| 339 | ? "up" : "dn"); |
| 340 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 341 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 342 | /* Display any L2 addressing info */ |
| 343 | vec_validate (l2m->configs, si->sw_if_index); |
| 344 | config = vec_elt_at_index (l2m->configs, si->sw_if_index); |
| 345 | if (config->bridge) |
| 346 | { |
| 347 | u32 bd_id = l2input_main.bd_configs[config->bd_index].bd_id; |
| 348 | vlib_cli_output (vm, " l2 bridge bd_id %d%s%d", bd_id, |
| 349 | config->bvi ? " bvi shg " : " shg ", |
| 350 | config->shg); |
| 351 | } |
| 352 | else if (config->xconnect) |
| 353 | { |
| 354 | vlib_cli_output (vm, " l2 xconnect %U", |
| 355 | format_vnet_sw_if_index_name, |
| 356 | vnm, config->output_sw_if_index); |
| 357 | } |
| 358 | |
| 359 | /* Display any IP4 addressing info */ |
| 360 | /* *INDENT-OFF* */ |
| 361 | foreach_ip_interface_address (lm4, ia, si->sw_if_index, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 362 | 1 /* honor unnumbered */, |
| 363 | ({ |
| 364 | r4 = ip_interface_address_get_address (lm4, ia); |
| 365 | if (fib4->table_id) |
| 366 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 367 | vlib_cli_output (vm, " %U/%d table %d", |
| 368 | format_ip4_address, r4, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 369 | ia->address_length, |
| 370 | fib4->table_id); |
| 371 | } |
| 372 | else |
| 373 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 374 | vlib_cli_output (vm, " %U/%d", |
| 375 | format_ip4_address, r4, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 376 | ia->address_length); |
| 377 | } |
| 378 | })); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 379 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 380 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 381 | /* Display any IP6 addressing info */ |
| 382 | /* *INDENT-OFF* */ |
| 383 | foreach_ip_interface_address (lm6, ia, si->sw_if_index, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 384 | 1 /* honor unnumbered */, |
| 385 | ({ |
| 386 | r6 = ip_interface_address_get_address (lm6, ia); |
| 387 | if (fib6->table_id) |
| 388 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 389 | vlib_cli_output (vm, " %U/%d table %d", |
| 390 | format_ip6_address, r6, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 391 | ia->address_length, |
| 392 | fib6->table_id); |
| 393 | } |
| 394 | else |
| 395 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 396 | vlib_cli_output (vm, " %U/%d", |
| 397 | format_ip6_address, r6, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 398 | ia->address_length); |
| 399 | } |
| 400 | })); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 401 | /* *INDENT-ON* */ |
| 402 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 403 | } |
| 404 | else |
| 405 | { |
| 406 | vec_foreach (si, sorted_sis) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 407 | { |
| 408 | vlib_cli_output (vm, "%U\n", format_vnet_sw_interface, vnm, si); |
| 409 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 410 | } |
| 411 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 412 | done: |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 413 | vec_free (sorted_sis); |
| 414 | return error; |
| 415 | } |
| 416 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 417 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 418 | VLIB_CLI_COMMAND (show_sw_interfaces_command, static) = { |
| 419 | .path = "show interfaces", |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 420 | .short_help = "show interfaces [address|addr|features|feat] [<if-name1> <if-name2> ...]", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 421 | .function = show_sw_interfaces, |
| 422 | }; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 423 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 424 | |
| 425 | /* Root of all interface commands. */ |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 426 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 427 | VLIB_CLI_COMMAND (vnet_cli_interface_command, static) = { |
| 428 | .path = "interface", |
| 429 | .short_help = "Interface commands", |
| 430 | }; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 431 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 432 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 433 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 434 | VLIB_CLI_COMMAND (vnet_cli_set_interface_command, static) = { |
| 435 | .path = "set interface", |
| 436 | .short_help = "Interface commands", |
| 437 | }; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 438 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 439 | |
| 440 | static clib_error_t * |
| 441 | clear_interface_counters (vlib_main_t * vm, |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 442 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 443 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 444 | vnet_main_t *vnm = vnet_get_main (); |
| 445 | vnet_interface_main_t *im = &vnm->interface_main; |
| 446 | vlib_simple_counter_main_t *sm; |
| 447 | vlib_combined_counter_main_t *cm; |
| 448 | static vnet_main_t **my_vnet_mains; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 449 | int i, j, n_counters; |
| 450 | |
| 451 | vec_reset_length (my_vnet_mains); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 452 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 453 | for (i = 0; i < vec_len (vnet_mains); i++) |
| 454 | { |
| 455 | if (vnet_mains[i]) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 456 | vec_add1 (my_vnet_mains, vnet_mains[i]); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | if (vec_len (vnet_mains) == 0) |
| 460 | vec_add1 (my_vnet_mains, vnm); |
| 461 | |
| 462 | n_counters = vec_len (im->combined_sw_if_counters); |
| 463 | |
| 464 | for (j = 0; j < n_counters; j++) |
| 465 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 466 | for (i = 0; i < vec_len (my_vnet_mains); i++) |
| 467 | { |
| 468 | im = &my_vnet_mains[i]->interface_main; |
| 469 | cm = im->combined_sw_if_counters + j; |
| 470 | vlib_clear_combined_counters (cm); |
| 471 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | n_counters = vec_len (im->sw_if_counters); |
| 475 | |
| 476 | for (j = 0; j < n_counters; j++) |
| 477 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 478 | for (i = 0; i < vec_len (my_vnet_mains); i++) |
| 479 | { |
| 480 | im = &my_vnet_mains[i]->interface_main; |
| 481 | sm = im->sw_if_counters + j; |
| 482 | vlib_clear_simple_counters (sm); |
| 483 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | return 0; |
| 487 | } |
| 488 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 489 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 490 | VLIB_CLI_COMMAND (clear_interface_counters_command, static) = { |
| 491 | .path = "clear interfaces", |
| 492 | .short_help = "Clear interfaces statistics", |
| 493 | .function = clear_interface_counters, |
| 494 | }; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 495 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 496 | |
Chris Luke | 16bcf7d | 2016-09-01 14:31:46 -0400 | [diff] [blame] | 497 | /** |
| 498 | * Parse subinterface names. |
| 499 | * |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 500 | * The following subinterface syntax is supported. The first two are for |
| 501 | * backwards compatability: |
| 502 | * |
| 503 | * <intf-name> <id> |
| 504 | * - a subinterface with the name <intf-name>.<id>. The subinterface |
| 505 | * is a single dot1q vlan with vlan id <id> and exact-match semantics. |
| 506 | * |
| 507 | * <intf-name> <min_id>-<max_id> |
| 508 | * - a set of the above subinterfaces, repeating for each id |
| 509 | * in the range <min_id> to <max_id> |
| 510 | * |
| 511 | * In the following, exact-match semantics (i.e. the number of vlan tags on the |
| 512 | * packet must match the number of tags in the configuration) are used only if |
| 513 | * the keyword exact-match is present. Non-exact match is the default. |
| 514 | * |
| 515 | * <intf-name> <id> dot1q <outer_id> [exact-match] |
| 516 | * - a subinterface with the name <intf-name>.<id>. The subinterface |
| 517 | * is a single dot1q vlan with vlan id <outer_id>. |
| 518 | * |
| 519 | * <intf-name> <id> dot1q any [exact-match] |
| 520 | * - a subinterface with the name <intf-name>.<id>. The subinterface |
| 521 | * is a single dot1q vlan with any vlan id. |
| 522 | * |
| 523 | * <intf-name> <id> dot1q <outer_id> inner-dot1q <inner_id> [exact-match] |
| 524 | * - a subinterface with the name <intf-name>.<id>. The subinterface |
| 525 | * is a double dot1q vlan with outer vlan id <outer_id> and inner vlan id |
| 526 | * <inner_id>. |
| 527 | * |
| 528 | * <intf-name> <id> dot1q <outer_id> inner-dot1q any [exact-match] |
| 529 | * - a subinterface with the name <intf-name>.<id>. The subinterface |
| 530 | * is a double dot1q vlan with outer vlan id <id> and any inner vlan id. |
| 531 | * |
| 532 | * <intf-name> <id> dot1q any inner-dot1q any [exact-match] |
| 533 | * |
| 534 | * - a subinterface with the name <intf-name>.<id>. The subinterface |
| 535 | * is a double dot1q vlan with any outer vlan id and any inner vlan id. |
| 536 | * |
| 537 | * For each of the above CLI, there is a duplicate that uses the keyword |
| 538 | * "dot1ad" in place of the first "dot1q". These interfaces use ethertype |
| 539 | * 0x88ad in place of 0x8100 for the outer ethertype. Note that for double- |
| 540 | * tagged packets the inner ethertype is always 0x8100. Also note that |
| 541 | * the dot1q and dot1ad naming spaces are independent, so it is legal to |
| 542 | * have both "Gig3/0/0.1 dot1q 100" and "Gig3/0/0.2 dot1ad 100". For example: |
| 543 | * |
| 544 | * <intf-name> <id> dot1ad <outer_id> inner-dot1q <inner_id> [exact-match] |
| 545 | * - a subinterface with the name <intf-name>.<id>. The subinterface |
| 546 | * is a double dot1ad vlan with outer vlan id <outer_id> and inner vlan |
| 547 | * id <inner_id>. |
| 548 | * |
| 549 | * <intf-name> <id> untagged |
| 550 | * - a subinterface with the name <intf-name>.<id>. The subinterface |
| 551 | * has no vlan tags. Only one can be specified per interface. |
| 552 | * |
| 553 | * <intf-name> <id> default |
| 554 | * - a subinterface with the name <intf-name>.<id>. This is associated |
| 555 | * with a packet that did not match any other configured subinterface |
| 556 | * on this interface. Only one can be specified per interface. |
| 557 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 558 | |
| 559 | static clib_error_t * |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 560 | parse_vlan_sub_interfaces (unformat_input_t * input, |
| 561 | vnet_sw_interface_t * template) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 562 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 563 | clib_error_t *error = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 564 | u32 inner_vlan, outer_vlan; |
| 565 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 566 | if (unformat (input, "any inner-dot1q any")) |
| 567 | { |
| 568 | template->sub.eth.flags.two_tags = 1; |
| 569 | template->sub.eth.flags.outer_vlan_id_any = 1; |
| 570 | template->sub.eth.flags.inner_vlan_id_any = 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 571 | } |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 572 | else if (unformat (input, "any")) |
| 573 | { |
| 574 | template->sub.eth.flags.one_tag = 1; |
| 575 | template->sub.eth.flags.outer_vlan_id_any = 1; |
| 576 | } |
| 577 | else if (unformat (input, "%d inner-dot1q any", &outer_vlan)) |
| 578 | { |
| 579 | template->sub.eth.flags.two_tags = 1; |
| 580 | template->sub.eth.flags.inner_vlan_id_any = 1; |
| 581 | template->sub.eth.outer_vlan_id = outer_vlan; |
| 582 | } |
| 583 | else if (unformat (input, "%d inner-dot1q %d", &outer_vlan, &inner_vlan)) |
| 584 | { |
| 585 | template->sub.eth.flags.two_tags = 1; |
| 586 | template->sub.eth.outer_vlan_id = outer_vlan; |
| 587 | template->sub.eth.inner_vlan_id = inner_vlan; |
| 588 | } |
| 589 | else if (unformat (input, "%d", &outer_vlan)) |
| 590 | { |
| 591 | template->sub.eth.flags.one_tag = 1; |
| 592 | template->sub.eth.outer_vlan_id = outer_vlan; |
| 593 | } |
| 594 | else |
| 595 | { |
| 596 | error = clib_error_return (0, "expected dot1q config, got `%U'", |
| 597 | format_unformat_error, input); |
| 598 | goto done; |
| 599 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 600 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 601 | if (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 602 | { |
| 603 | if (unformat (input, "exact-match")) |
| 604 | { |
| 605 | template->sub.eth.flags.exact_match = 1; |
| 606 | } |
| 607 | } |
| 608 | |
| 609 | done: |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 610 | return error; |
| 611 | } |
| 612 | |
| 613 | static clib_error_t * |
| 614 | create_sub_interfaces (vlib_main_t * vm, |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 615 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 616 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 617 | vnet_main_t *vnm = vnet_get_main (); |
| 618 | clib_error_t *error = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 619 | u32 hw_if_index, sw_if_index; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 620 | vnet_hw_interface_t *hi; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 621 | u32 id, id_min, id_max; |
| 622 | vnet_sw_interface_t template; |
| 623 | |
| 624 | hw_if_index = ~0; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 625 | if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 626 | { |
| 627 | error = clib_error_return (0, "unknown interface `%U'", |
| 628 | format_unformat_error, input); |
| 629 | goto done; |
| 630 | } |
| 631 | |
| 632 | memset (&template, 0, sizeof (template)); |
| 633 | template.sub.eth.raw_flags = 0; |
| 634 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 635 | if (unformat (input, "%d default", &id_min)) |
| 636 | { |
| 637 | id_max = id_min; |
| 638 | template.sub.eth.flags.default_sub = 1; |
| 639 | } |
| 640 | else if (unformat (input, "%d untagged", &id_min)) |
| 641 | { |
| 642 | id_max = id_min; |
| 643 | template.sub.eth.flags.no_tags = 1; |
| 644 | template.sub.eth.flags.exact_match = 1; |
| 645 | } |
| 646 | else if (unformat (input, "%d dot1q", &id_min)) |
| 647 | { |
| 648 | /* parse dot1q config */ |
| 649 | id_max = id_min; |
| 650 | error = parse_vlan_sub_interfaces (input, &template); |
| 651 | if (error) |
| 652 | goto done; |
| 653 | } |
| 654 | else if (unformat (input, "%d dot1ad", &id_min)) |
| 655 | { |
| 656 | /* parse dot1ad config */ |
| 657 | id_max = id_min; |
| 658 | template.sub.eth.flags.dot1ad = 1; |
| 659 | error = parse_vlan_sub_interfaces (input, &template); |
| 660 | if (error) |
| 661 | goto done; |
| 662 | } |
| 663 | else if (unformat (input, "%d-%d", &id_min, &id_max)) |
| 664 | { |
| 665 | template.sub.eth.flags.one_tag = 1; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 666 | template.sub.eth.flags.exact_match = 1; |
| 667 | if (id_min > id_max) |
| 668 | goto id_error; |
| 669 | } |
| 670 | else if (unformat (input, "%d", &id_min)) |
| 671 | { |
| 672 | id_max = id_min; |
| 673 | template.sub.eth.flags.one_tag = 1; |
| 674 | template.sub.eth.outer_vlan_id = id_min; |
| 675 | template.sub.eth.flags.exact_match = 1; |
| 676 | } |
| 677 | else |
| 678 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 679 | id_error: |
| 680 | error = clib_error_return (0, "expected ID or ID MIN-MAX, got `%U'", |
| 681 | format_unformat_error, input); |
| 682 | goto done; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 683 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 684 | |
| 685 | hi = vnet_get_hw_interface (vnm, hw_if_index); |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 686 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 687 | if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE) |
| 688 | { |
| 689 | error = |
| 690 | clib_error_return (0, |
| 691 | "not allowed as %v belong to a BondEthernet interface", |
| 692 | hi->name); |
| 693 | goto done; |
| 694 | } |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 695 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 696 | for (id = id_min; id <= id_max; id++) |
| 697 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 698 | uword *p; |
| 699 | vnet_interface_main_t *im = &vnm->interface_main; |
| 700 | u64 sup_and_sub_key = ((u64) (hi->sw_if_index) << 32) | (u64) id; |
| 701 | u64 *kp; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 702 | |
| 703 | p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key); |
| 704 | if (p) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 705 | { |
| 706 | if (CLIB_DEBUG > 0) |
| 707 | clib_warning ("sup sw_if_index %d, sub id %d already exists\n", |
| 708 | hi->sw_if_index, id); |
| 709 | continue; |
| 710 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 711 | |
| 712 | kp = clib_mem_alloc (sizeof (*kp)); |
| 713 | *kp = sup_and_sub_key; |
| 714 | |
| 715 | template.type = VNET_SW_INTERFACE_TYPE_SUB; |
Eyal Bari | c5b1360 | 2016-11-24 19:42:43 +0200 | [diff] [blame] | 716 | template.flood_class = VNET_FLOOD_CLASS_NORMAL; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 717 | template.sup_sw_if_index = hi->sw_if_index; |
| 718 | template.sub.id = id; |
Eyal Bari | a4509cf | 2016-09-26 09:24:09 +0300 | [diff] [blame] | 719 | if (id_min < id_max) |
| 720 | template.sub.eth.outer_vlan_id = id; |
| 721 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 722 | error = vnet_create_sw_interface (vnm, &template, &sw_if_index); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 723 | if (error) |
| 724 | goto done; |
Dave Barach | 16ad6ae | 2016-07-28 17:55:30 -0400 | [diff] [blame] | 725 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 726 | hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index); |
| 727 | 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] | 728 | vlib_cli_output (vm, "%U\n", format_vnet_sw_if_index_name, |
| 729 | vnet_get_main (), sw_if_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 730 | } |
| 731 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 732 | done: |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 733 | return error; |
| 734 | } |
| 735 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 736 | /* *INDENT-OFF* */ |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 737 | /*? |
| 738 | * Create vlan subinterfaces |
| 739 | * |
| 740 | * @cliexpar |
| 741 | * @cliexstart{create sub-interfaces} |
| 742 | * |
| 743 | * To create a vlan subinterface 11 to process packets on 802.1q VLAN id 11, use: |
| 744 | * |
| 745 | * vpp# create sub GigabitEthernet2/0/0 11 |
| 746 | * |
| 747 | * This shorthand is equivalent to: |
| 748 | * vpp# create sub GigabitEthernet2/0/0 11 dot1q 11 exact-match |
| 749 | * |
| 750 | * You can specify a subinterface number that is different from the vlan id: |
| 751 | * vpp# create sub GigabitEthernet2/0/0 11 dot1q 100 |
| 752 | * |
| 753 | * You can create qinq and q-in-any interfaces: |
| 754 | * vpp# create sub GigabitEthernet2/0/0 11 dot1q 100 inner-dot1q 200 |
| 755 | * vpp# create sub GigabitEthernet2/0/0 12 dot1q 100 inner-dot1q any |
| 756 | * |
| 757 | * You can also create dot1ad interfaces: |
| 758 | * vpp# create sub GigabitEthernet2/0/0 11 dot1ad 11 |
| 759 | * vpp# create sub GigabitEthernet2/0/0 12 dot1q 100 inner-dot1q 200 |
| 760 | * |
| 761 | * Subinterfaces can be configured as either exact-match or non-exact match. |
| 762 | * Non-exact match is the CLI default. If exact-match is specified, |
| 763 | * packets must have the same number of vlan tags as the configuration. |
| 764 | * For non-exact-match, packets must at least that number of tags. |
| 765 | * L3 (routed) interfaces must be configured as exact-match. |
| 766 | * L2 interfaces are typically configured as non-exact-match. |
| 767 | * |
| 768 | * For example, a packet with outer vlan 100 and inner 200 would match this interface: |
| 769 | * vpp# create sub GigabitEthernet2/0/0 5 dot1q 100 |
| 770 | * |
| 771 | * but would not match this interface: |
| 772 | * vpp# create sub GigabitEthernet2/0/0 5 dot1q 100 exact-match |
| 773 | * |
| 774 | * There are two special subinterfaces that can be configured. Subinterface untagged has no vlan tags: |
| 775 | * vpp# create sub GigabitEthernet2/0/0 5 untagged |
| 776 | * |
| 777 | * The subinterface default matches any packet that does not match any other subinterface: |
| 778 | * vpp# create sub GigabitEthernet2/0/0 7 default |
| 779 | * @cliexend |
| 780 | ?*/ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 781 | VLIB_CLI_COMMAND (create_sub_interfaces_command, static) = { |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 782 | .path = "create sub-interfaces", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 783 | .short_help = "create sub-interfaces <nn>[-<nn>] [dot1q|dot1ad|default|untagged]", |
| 784 | .function = create_sub_interfaces, |
| 785 | }; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 786 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 787 | |
| 788 | static clib_error_t * |
| 789 | set_state (vlib_main_t * vm, |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 790 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 791 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 792 | vnet_main_t *vnm = vnet_get_main (); |
| 793 | clib_error_t *error; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 794 | u32 sw_if_index, flags; |
| 795 | |
| 796 | sw_if_index = ~0; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 797 | if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 798 | { |
| 799 | error = clib_error_return (0, "unknown interface `%U'", |
| 800 | format_unformat_error, input); |
| 801 | goto done; |
| 802 | } |
| 803 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 804 | if (!unformat (input, "%U", unformat_vnet_sw_interface_flags, &flags)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 805 | { |
| 806 | error = clib_error_return (0, "unknown flags `%U'", |
| 807 | format_unformat_error, input); |
| 808 | goto done; |
| 809 | } |
| 810 | |
| 811 | error = vnet_sw_interface_set_flags (vnm, sw_if_index, flags); |
| 812 | if (error) |
| 813 | goto done; |
| 814 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 815 | done: |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 816 | return error; |
| 817 | } |
| 818 | |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 819 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 820 | /* *INDENT-OFF* */ |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 821 | /*? |
| 822 | * Interface admin up/down |
| 823 | * |
| 824 | * @cliexpar |
| 825 | * @cliexstart{set interface state} |
| 826 | * vpp# set interface state GigabitEthernet2/0/0 up |
| 827 | * vpp# set interface state GigabitEthernet2/0/0 down |
| 828 | * @cliexend |
| 829 | ?*/ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 830 | VLIB_CLI_COMMAND (set_state_command, static) = { |
| 831 | .path = "set interface state", |
| 832 | .short_help = "Set interface state", |
| 833 | .function = set_state, |
| 834 | }; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 835 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 836 | |
| 837 | static clib_error_t * |
| 838 | set_unnumbered (vlib_main_t * vm, |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 839 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 840 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 841 | vnet_main_t *vnm = vnet_get_main (); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 842 | u32 unnumbered_sw_if_index; |
| 843 | u32 inherit_from_sw_if_index; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 844 | vnet_sw_interface_t *si; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 845 | int is_set = 0; |
| 846 | int is_del = 0; |
| 847 | |
Igor Mikhailov (imichail) | ab3e42b | 2016-09-25 15:11:53 -0700 | [diff] [blame] | 848 | if (unformat (input, "%U use %U", |
| 849 | unformat_vnet_sw_interface, vnm, &unnumbered_sw_if_index, |
| 850 | unformat_vnet_sw_interface, vnm, &inherit_from_sw_if_index)) |
| 851 | is_set = 1; |
| 852 | else if (unformat (input, "del %U", |
| 853 | unformat_vnet_sw_interface, vnm, |
| 854 | &unnumbered_sw_if_index)) |
| 855 | is_del = 1; |
| 856 | else |
| 857 | return clib_error_return (0, "parse error '%U'", |
| 858 | format_unformat_error, input); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 859 | |
| 860 | si = vnet_get_sw_interface (vnm, unnumbered_sw_if_index); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 861 | if (is_del) |
| 862 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 863 | si->flags &= ~(VNET_SW_INTERFACE_FLAG_UNNUMBERED); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 864 | si->unnumbered_sw_if_index = (u32) ~ 0; |
Igor Mikhailov (imichail) | 15977ef | 2016-10-04 20:09:41 -0700 | [diff] [blame] | 865 | ip4_sw_interface_enable_disable (unnumbered_sw_if_index, 0); |
| 866 | ip6_sw_interface_enable_disable (unnumbered_sw_if_index, 0); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 867 | } |
Igor Mikhailov (imichail) | ab3e42b | 2016-09-25 15:11:53 -0700 | [diff] [blame] | 868 | else if (is_set) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 869 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 870 | si->flags |= VNET_SW_INTERFACE_FLAG_UNNUMBERED; |
| 871 | si->unnumbered_sw_if_index = inherit_from_sw_if_index; |
Igor Mikhailov (imichail) | 15977ef | 2016-10-04 20:09:41 -0700 | [diff] [blame] | 872 | ip4_sw_interface_enable_disable (unnumbered_sw_if_index, 1); |
| 873 | ip6_sw_interface_enable_disable (unnumbered_sw_if_index, 1); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 874 | } |
| 875 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 876 | return 0; |
| 877 | } |
| 878 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 879 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 880 | VLIB_CLI_COMMAND (set_unnumbered_command, static) = { |
| 881 | .path = "set interface unnumbered", |
Igor Mikhailov (imichail) | ab3e42b | 2016-09-25 15:11:53 -0700 | [diff] [blame] | 882 | .short_help = "set interface unnumbered [<intfc> use <intfc> | del <intfc>]", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 883 | .function = set_unnumbered, |
| 884 | }; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 885 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 886 | |
| 887 | |
| 888 | |
| 889 | static clib_error_t * |
| 890 | set_hw_class (vlib_main_t * vm, |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 891 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 892 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 893 | vnet_main_t *vnm = vnet_get_main (); |
| 894 | vnet_interface_main_t *im = &vnm->interface_main; |
| 895 | clib_error_t *error; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 896 | u32 hw_if_index, hw_class_index; |
| 897 | |
| 898 | hw_if_index = ~0; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 899 | if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 900 | { |
| 901 | error = clib_error_return (0, "unknown hardware interface `%U'", |
| 902 | format_unformat_error, input); |
| 903 | goto done; |
| 904 | } |
| 905 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 906 | if (!unformat_user (input, unformat_hash_string, |
| 907 | im->hw_interface_class_by_name, &hw_class_index)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 908 | { |
| 909 | error = clib_error_return (0, "unknown hardware class `%U'", |
| 910 | format_unformat_error, input); |
| 911 | goto done; |
| 912 | } |
| 913 | |
| 914 | error = vnet_hw_interface_set_class (vnm, hw_if_index, hw_class_index); |
| 915 | if (error) |
| 916 | goto done; |
| 917 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 918 | done: |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 919 | return error; |
| 920 | } |
| 921 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 922 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 923 | VLIB_CLI_COMMAND (set_hw_class_command, static) = { |
| 924 | .path = "set interface hw-class", |
| 925 | .short_help = "Set interface hardware class", |
| 926 | .function = set_hw_class, |
| 927 | }; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 928 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 929 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 930 | static clib_error_t * |
| 931 | vnet_interface_cli_init (vlib_main_t * vm) |
| 932 | { |
| 933 | return 0; |
| 934 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 935 | |
| 936 | VLIB_INIT_FUNCTION (vnet_interface_cli_init); |
| 937 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 938 | static clib_error_t * |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 939 | renumber_interface_command_fn (vlib_main_t * vm, |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 940 | unformat_input_t * input, |
| 941 | vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 942 | { |
| 943 | u32 hw_if_index; |
| 944 | u32 new_dev_instance; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 945 | vnet_main_t *vnm = vnet_get_main (); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 946 | int rv; |
| 947 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 948 | if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 949 | return clib_error_return (0, "unknown hardware interface `%U'", |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 950 | format_unformat_error, input); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 951 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 952 | if (!unformat (input, "%d", &new_dev_instance)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 953 | return clib_error_return (0, "new dev instance missing"); |
| 954 | |
| 955 | rv = vnet_interface_name_renumber (hw_if_index, new_dev_instance); |
| 956 | |
| 957 | switch (rv) |
| 958 | { |
| 959 | case 0: |
| 960 | break; |
| 961 | |
| 962 | default: |
| 963 | return clib_error_return (0, "vnet_interface_name_renumber returned %d", |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 964 | rv); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 965 | |
| 966 | } |
| 967 | |
| 968 | return 0; |
| 969 | } |
| 970 | |
| 971 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 972 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 973 | VLIB_CLI_COMMAND (renumber_interface_command, static) = { |
| 974 | .path = "renumber interface", |
| 975 | .short_help = "renumber interface <if-name> <new-dev-instance>", |
| 976 | .function = renumber_interface_command_fn, |
| 977 | }; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 978 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 979 | |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 980 | static clib_error_t * |
| 981 | promiscuous_cmd (vlib_main_t * vm, |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 982 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 983 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 984 | vnet_main_t *vnm = vnet_get_main (); |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 985 | u32 hw_if_index; |
| 986 | u32 flags = ETHERNET_INTERFACE_FLAG_ACCEPT_ALL; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 987 | ethernet_main_t *em = ðernet_main; |
| 988 | ethernet_interface_t *eif; |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 989 | |
| 990 | if (unformat (input, "on %U", |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 991 | unformat_vnet_hw_interface, vnm, &hw_if_index)) |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 992 | ; |
| 993 | else if (unformat (input, "off %U", |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 994 | unformat_ethernet_interface, vnm, &hw_if_index)) |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 995 | flags = 0; |
| 996 | else |
| 997 | return clib_error_return (0, "unknown input `%U'", |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 998 | format_unformat_error, input); |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 999 | |
| 1000 | eif = ethernet_get_interface (em, hw_if_index); |
| 1001 | if (!eif) |
| 1002 | return clib_error_return (0, "not supported"); |
| 1003 | |
| 1004 | ethernet_set_flags (vnm, hw_if_index, flags); |
| 1005 | return 0; |
| 1006 | } |
| 1007 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1008 | /* *INDENT-OFF* */ |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1009 | VLIB_CLI_COMMAND (set_interface_promiscuous_cmd, static) = { |
| 1010 | .path = "set interface promiscuous", |
| 1011 | .short_help = "set interface promiscuous [on | off] <intfc>", |
| 1012 | .function = promiscuous_cmd, |
| 1013 | }; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1014 | /* *INDENT-ON* */ |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1015 | |
| 1016 | static clib_error_t * |
| 1017 | mtu_cmd (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) |
| 1018 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1019 | vnet_main_t *vnm = vnet_get_main (); |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1020 | u32 hw_if_index, mtu; |
| 1021 | u32 flags = ETHERNET_INTERFACE_FLAG_MTU; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1022 | ethernet_main_t *em = ðernet_main; |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1023 | |
| 1024 | if (unformat (input, "%d %U", &mtu, |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1025 | unformat_vnet_hw_interface, vnm, &hw_if_index)) |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1026 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1027 | vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, hw_if_index); |
| 1028 | ethernet_interface_t *eif = ethernet_get_interface (em, hw_if_index); |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1029 | |
| 1030 | if (!eif) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1031 | return clib_error_return (0, "not supported"); |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1032 | |
Mohsin Kazmi | f2ba9aa | 2016-04-24 18:53:42 +0200 | [diff] [blame] | 1033 | if (mtu < hi->min_supported_packet_bytes) |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1034 | return clib_error_return (0, "Invalid mtu (%d): " |
| 1035 | "must be >= min pkt bytes (%d)", mtu, |
Mohsin Kazmi | f2ba9aa | 2016-04-24 18:53:42 +0200 | [diff] [blame] | 1036 | hi->min_supported_packet_bytes); |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1037 | |
Mohsin Kazmi | f2ba9aa | 2016-04-24 18:53:42 +0200 | [diff] [blame] | 1038 | if (mtu > hi->max_supported_packet_bytes) |
| 1039 | return clib_error_return (0, "Invalid mtu (%d): must be <= (%d)", mtu, |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1040 | hi->max_supported_packet_bytes); |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1041 | |
| 1042 | if (hi->max_packet_bytes != mtu) |
| 1043 | { |
| 1044 | hi->max_packet_bytes = mtu; |
| 1045 | ethernet_set_flags (vnm, hw_if_index, flags); |
| 1046 | } |
| 1047 | } |
| 1048 | else |
| 1049 | return clib_error_return (0, "unknown input `%U'", |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1050 | format_unformat_error, input); |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1051 | return 0; |
| 1052 | } |
| 1053 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1054 | /* *INDENT-OFF* */ |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1055 | VLIB_CLI_COMMAND (set_interface_mtu_cmd, static) = { |
| 1056 | .path = "set interface mtu", |
Mohsin Kazmi | f2ba9aa | 2016-04-24 18:53:42 +0200 | [diff] [blame] | 1057 | .short_help = "set interface mtu <value> <intfc>", |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1058 | .function = mtu_cmd, |
| 1059 | }; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1060 | /* *INDENT-ON* */ |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1061 | |
Pavel Kotucek | c631f2d | 2016-09-26 10:40:02 +0200 | [diff] [blame] | 1062 | static clib_error_t * |
| 1063 | set_interface_mac_address (vlib_main_t * vm, unformat_input_t * input, |
| 1064 | vlib_cli_command_t * cmd) |
| 1065 | { |
| 1066 | vnet_main_t *vnm = vnet_get_main (); |
| 1067 | clib_error_t *error = 0; |
| 1068 | u32 sw_if_index = ~0; |
| 1069 | u64 mac = 0; |
| 1070 | |
| 1071 | if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index)) |
| 1072 | { |
| 1073 | error = clib_error_return (0, "unknown interface `%U'", |
| 1074 | format_unformat_error, input); |
| 1075 | goto done; |
| 1076 | } |
| 1077 | if (!unformat_user (input, unformat_ethernet_address, &mac)) |
| 1078 | { |
| 1079 | error = clib_error_return (0, "expected mac address `%U'", |
| 1080 | format_unformat_error, input); |
| 1081 | goto done; |
| 1082 | } |
| 1083 | error = vnet_hw_interface_change_mac_address (vnm, sw_if_index, mac); |
| 1084 | done: |
| 1085 | return error; |
| 1086 | } |
| 1087 | |
| 1088 | /*? |
| 1089 | * The '<em>set interface mac address </em>' command allows to set MAC address of given interface. |
| 1090 | * In case of NIC interfaces the one has to support MAC address change. A side effect of MAC address |
| 1091 | * change are changes of MAC addresses in FIB tables (ipv4 and ipv6). |
| 1092 | * |
| 1093 | * @cliexpar |
| 1094 | * @parblock |
| 1095 | * Example of how to change MAC Address of interface: |
| 1096 | * @cliexcmd{set interface mac address GigabitEthernet0/8/0 aa:bb:cc:dd:ee:01} |
| 1097 | * @cliexcmd{set interface mac address host-vpp0 aa:bb:cc:dd:ee:02} |
| 1098 | * @cliexcmd{set interface mac address tap-0 aa:bb:cc:dd:ee:03} |
| 1099 | * @cliexcmd{set interface mac address pg0 aa:bb:cc:dd:ee:04} |
| 1100 | * @endparblock |
| 1101 | ?*/ |
| 1102 | /* *INDENT-OFF* */ |
| 1103 | VLIB_CLI_COMMAND (set_interface_mac_address_cmd, static) = { |
| 1104 | .path = "set interface mac address", |
| 1105 | .short_help = "set interface mac address <intfc> <mac-address>", |
| 1106 | .function = set_interface_mac_address, |
| 1107 | }; |
| 1108 | /* *INDENT-ON* */ |
| 1109 | |
Dave Barach | 7be864a | 2016-11-28 11:41:35 -0500 | [diff] [blame] | 1110 | static clib_error_t * |
| 1111 | set_tag (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) |
| 1112 | { |
| 1113 | vnet_main_t *vnm = vnet_get_main (); |
| 1114 | u32 sw_if_index = ~0; |
| 1115 | u8 *tag = 0; |
| 1116 | |
| 1117 | if (!unformat (input, "%U %s", unformat_vnet_sw_interface, |
| 1118 | vnm, &sw_if_index, &tag)) |
| 1119 | return clib_error_return (0, "unknown input `%U'", |
| 1120 | format_unformat_error, input); |
| 1121 | |
| 1122 | vnet_set_sw_interface_tag (vnm, tag, sw_if_index); |
| 1123 | |
| 1124 | return 0; |
| 1125 | } |
| 1126 | |
| 1127 | /* *INDENT-OFF* */ |
| 1128 | VLIB_CLI_COMMAND (set_tag_command, static) = { |
| 1129 | .path = "set interface tag", |
| 1130 | .short_help = "set interface tag <intfc> <tag>", |
| 1131 | .function = set_tag, |
| 1132 | }; |
| 1133 | /* *INDENT-ON* */ |
| 1134 | |
| 1135 | static clib_error_t * |
| 1136 | clear_tag (vlib_main_t * vm, unformat_input_t * input, |
| 1137 | vlib_cli_command_t * cmd) |
| 1138 | { |
| 1139 | vnet_main_t *vnm = vnet_get_main (); |
| 1140 | u32 sw_if_index = ~0; |
| 1141 | |
| 1142 | if (!unformat (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index)) |
| 1143 | return clib_error_return (0, "unknown input `%U'", |
| 1144 | format_unformat_error, input); |
| 1145 | |
| 1146 | vnet_clear_sw_interface_tag (vnm, sw_if_index); |
| 1147 | |
| 1148 | return 0; |
| 1149 | } |
| 1150 | |
| 1151 | /* *INDENT-OFF* */ |
| 1152 | VLIB_CLI_COMMAND (clear_tag_command, static) = { |
| 1153 | .path = "clear interface tag", |
| 1154 | .short_help = "clear interface tag <intfc>", |
| 1155 | .function = clear_tag, |
| 1156 | }; |
| 1157 | /* *INDENT-ON* */ |
| 1158 | |
| 1159 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1160 | /* |
| 1161 | * fd.io coding-style-patch-verification: ON |
| 1162 | * |
| 1163 | * Local Variables: |
| 1164 | * eval: (c-set-style "gnu") |
| 1165 | * End: |
| 1166 | */ |