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