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 | * ethernet_interface.c: ethernet interfaces |
| 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 | |
| 40 | #include <vnet/vnet.h> |
| 41 | #include <vnet/ip/ip.h> |
| 42 | #include <vnet/pg/pg.h> |
| 43 | #include <vnet/ethernet/ethernet.h> |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 44 | //#include <vnet/ethernet/arp.h> |
John Lo | 405e41b | 2016-04-23 15:14:12 -0400 | [diff] [blame] | 45 | #include <vnet/l2/l2_input.h> |
Neale Ranns | 3b81a1e | 2018-09-06 09:50:26 -0700 | [diff] [blame] | 46 | #include <vnet/l2/l2_bd.h> |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 47 | #include <vnet/adj/adj.h> |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 48 | #include <vnet/adj/adj_mcast.h> |
| 49 | #include <vnet/ip-neighbor/ip_neighbor.h> |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 50 | |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 51 | /** |
| 52 | * @file |
| 53 | * @brief Loopback Interfaces. |
| 54 | * |
| 55 | * This file contains code to manage loopback interfaces. |
| 56 | */ |
| 57 | |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 58 | static const u8 * |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 59 | ethernet_ip4_mcast_dst_addr (void) |
| 60 | { |
| 61 | const static u8 ethernet_mcast_dst_mac[] = { |
| 62 | 0x1, 0x0, 0x5e, 0x0, 0x0, 0x0, |
| 63 | }; |
| 64 | |
| 65 | return (ethernet_mcast_dst_mac); |
| 66 | } |
| 67 | |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 68 | static const u8 * |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 69 | ethernet_ip6_mcast_dst_addr (void) |
| 70 | { |
| 71 | const static u8 ethernet_mcast_dst_mac[] = { |
| 72 | 0x33, 0x33, 0x00, 0x0, 0x0, 0x0, |
| 73 | }; |
| 74 | |
| 75 | return (ethernet_mcast_dst_mac); |
| 76 | } |
| 77 | |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 78 | /** |
| 79 | * @brief build a rewrite string to use for sending packets of type 'link_type' |
| 80 | * to 'dst_address' |
| 81 | */ |
| 82 | u8 * |
| 83 | ethernet_build_rewrite (vnet_main_t * vnm, |
| 84 | u32 sw_if_index, |
| 85 | vnet_link_t link_type, const void *dst_address) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 86 | { |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 87 | vnet_sw_interface_t *sub_sw = vnet_get_sw_interface (vnm, sw_if_index); |
| 88 | vnet_sw_interface_t *sup_sw = vnet_get_sup_sw_interface (vnm, sw_if_index); |
| 89 | vnet_hw_interface_t *hw = vnet_get_sup_hw_interface (vnm, sw_if_index); |
| 90 | ethernet_main_t *em = ðernet_main; |
| 91 | ethernet_interface_t *ei; |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 92 | ethernet_header_t *h; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 93 | ethernet_type_t type; |
| 94 | uword n_bytes = sizeof (h[0]); |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 95 | u8 *rewrite = NULL; |
Pavel Kotucek | 15ac81c | 2017-06-20 14:00:26 +0200 | [diff] [blame] | 96 | u8 is_p2p = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 97 | |
Neale Ranns | 17ff3c1 | 2018-07-04 10:24:24 -0700 | [diff] [blame] | 98 | if ((sub_sw->type == VNET_SW_INTERFACE_TYPE_P2P) || |
| 99 | (sub_sw->type == VNET_SW_INTERFACE_TYPE_PIPE)) |
Pavel Kotucek | 15ac81c | 2017-06-20 14:00:26 +0200 | [diff] [blame] | 100 | is_p2p = 1; |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 101 | if (sub_sw != sup_sw) |
| 102 | { |
| 103 | if (sub_sw->sub.eth.flags.one_tag) |
| 104 | { |
| 105 | n_bytes += sizeof (ethernet_vlan_header_t); |
| 106 | } |
| 107 | else if (sub_sw->sub.eth.flags.two_tags) |
| 108 | { |
| 109 | n_bytes += 2 * (sizeof (ethernet_vlan_header_t)); |
| 110 | } |
Pavel Kotucek | 15ac81c | 2017-06-20 14:00:26 +0200 | [diff] [blame] | 111 | else if (PREDICT_FALSE (is_p2p)) |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 112 | { |
Pavel Kotucek | 15ac81c | 2017-06-20 14:00:26 +0200 | [diff] [blame] | 113 | n_bytes = sizeof (ethernet_header_t); |
| 114 | } |
| 115 | if (PREDICT_FALSE (!is_p2p)) |
| 116 | { |
| 117 | // Check for encaps that are not supported for L3 interfaces |
| 118 | if (!(sub_sw->sub.eth.flags.exact_match) || |
| 119 | (sub_sw->sub.eth.flags.default_sub) || |
| 120 | (sub_sw->sub.eth.flags.outer_vlan_id_any) || |
| 121 | (sub_sw->sub.eth.flags.inner_vlan_id_any)) |
| 122 | { |
| 123 | return 0; |
| 124 | } |
| 125 | } |
| 126 | else |
| 127 | { |
| 128 | n_bytes = sizeof (ethernet_header_t); |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 129 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 130 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 131 | |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 132 | switch (link_type) |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 133 | { |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 134 | #define _(a,b) case VNET_LINK_##a: type = ETHERNET_TYPE_##b; break |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 135 | _(IP4, IP4); |
| 136 | _(IP6, IP6); |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 137 | _(MPLS, MPLS); |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 138 | _(ARP, ARP); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 139 | #undef _ |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 140 | default: |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 141 | return NULL; |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 142 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 143 | |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 144 | vec_validate (rewrite, n_bytes - 1); |
| 145 | h = (ethernet_header_t *) rewrite; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 146 | ei = pool_elt_at_index (em->interfaces, hw->hw_instance); |
Benoît Ganne | b44c77d | 2020-10-20 16:24:17 +0200 | [diff] [blame] | 147 | clib_memcpy (h->src_address, &ei->address, sizeof (h->src_address)); |
Pavel Kotucek | 15ac81c | 2017-06-20 14:00:26 +0200 | [diff] [blame] | 148 | if (is_p2p) |
| 149 | { |
| 150 | clib_memcpy (h->dst_address, sub_sw->p2p.client_mac, |
| 151 | sizeof (h->dst_address)); |
| 152 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 153 | else |
Pavel Kotucek | 15ac81c | 2017-06-20 14:00:26 +0200 | [diff] [blame] | 154 | { |
| 155 | if (dst_address) |
| 156 | clib_memcpy (h->dst_address, dst_address, sizeof (h->dst_address)); |
| 157 | else |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 158 | clib_memset (h->dst_address, ~0, sizeof (h->dst_address)); /* broadcast */ |
Pavel Kotucek | 15ac81c | 2017-06-20 14:00:26 +0200 | [diff] [blame] | 159 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 160 | |
Pavel Kotucek | 15ac81c | 2017-06-20 14:00:26 +0200 | [diff] [blame] | 161 | if (PREDICT_FALSE (!is_p2p) && sub_sw->sub.eth.flags.one_tag) |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 162 | { |
| 163 | ethernet_vlan_header_t *outer = (void *) (h + 1); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 164 | |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 165 | h->type = sub_sw->sub.eth.flags.dot1ad ? |
| 166 | clib_host_to_net_u16 (ETHERNET_TYPE_DOT1AD) : |
| 167 | clib_host_to_net_u16 (ETHERNET_TYPE_VLAN); |
| 168 | outer->priority_cfi_and_id = |
| 169 | clib_host_to_net_u16 (sub_sw->sub.eth.outer_vlan_id); |
| 170 | outer->type = clib_host_to_net_u16 (type); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 171 | |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 172 | } |
Pavel Kotucek | 15ac81c | 2017-06-20 14:00:26 +0200 | [diff] [blame] | 173 | else if (PREDICT_FALSE (!is_p2p) && sub_sw->sub.eth.flags.two_tags) |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 174 | { |
| 175 | ethernet_vlan_header_t *outer = (void *) (h + 1); |
| 176 | ethernet_vlan_header_t *inner = (void *) (outer + 1); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 177 | |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 178 | h->type = sub_sw->sub.eth.flags.dot1ad ? |
| 179 | clib_host_to_net_u16 (ETHERNET_TYPE_DOT1AD) : |
| 180 | clib_host_to_net_u16 (ETHERNET_TYPE_VLAN); |
| 181 | outer->priority_cfi_and_id = |
| 182 | clib_host_to_net_u16 (sub_sw->sub.eth.outer_vlan_id); |
| 183 | outer->type = clib_host_to_net_u16 (ETHERNET_TYPE_VLAN); |
| 184 | inner->priority_cfi_and_id = |
| 185 | clib_host_to_net_u16 (sub_sw->sub.eth.inner_vlan_id); |
| 186 | inner->type = clib_host_to_net_u16 (type); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 187 | |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 188 | } |
| 189 | else |
| 190 | { |
| 191 | h->type = clib_host_to_net_u16 (type); |
| 192 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 193 | |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 194 | return (rewrite); |
| 195 | } |
| 196 | |
| 197 | void |
| 198 | ethernet_update_adjacency (vnet_main_t * vnm, u32 sw_if_index, u32 ai) |
| 199 | { |
Pavel Kotucek | 15ac81c | 2017-06-20 14:00:26 +0200 | [diff] [blame] | 200 | vnet_sw_interface_t *si = vnet_get_sw_interface (vnm, sw_if_index); |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 201 | |
Neale Ranns | 17ff3c1 | 2018-07-04 10:24:24 -0700 | [diff] [blame] | 202 | if ((si->type == VNET_SW_INTERFACE_TYPE_P2P) || |
| 203 | (si->type == VNET_SW_INTERFACE_TYPE_PIPE)) |
Pavel Kotucek | 15ac81c | 2017-06-20 14:00:26 +0200 | [diff] [blame] | 204 | { |
| 205 | default_update_adjacency (vnm, sw_if_index, ai); |
| 206 | } |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 207 | else |
| 208 | { |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 209 | ip_adjacency_t *adj; |
| 210 | |
| 211 | adj = adj_get (ai); |
| 212 | |
| 213 | switch (adj->lookup_next_index) |
| 214 | { |
| 215 | case IP_LOOKUP_NEXT_GLEAN: |
| 216 | adj_glean_update_rewrite (ai); |
| 217 | break; |
| 218 | case IP_LOOKUP_NEXT_ARP: |
Neale Ranns | ea8adf7 | 2021-08-13 08:10:59 +0000 | [diff] [blame] | 219 | case IP_LOOKUP_NEXT_REWRITE: |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 220 | ip_neighbor_update (vnm, ai); |
| 221 | break; |
| 222 | case IP_LOOKUP_NEXT_BCAST: |
| 223 | adj_nbr_update_rewrite (ai, |
| 224 | ADJ_NBR_REWRITE_FLAG_COMPLETE, |
| 225 | ethernet_build_rewrite |
| 226 | (vnm, |
| 227 | adj->rewrite_header.sw_if_index, |
| 228 | adj->ia_link, |
| 229 | VNET_REWRITE_FOR_SW_INTERFACE_ADDRESS_BROADCAST)); |
| 230 | break; |
| 231 | case IP_LOOKUP_NEXT_MCAST: |
| 232 | { |
| 233 | /* |
| 234 | * Construct a partial rewrite from the known ethernet mcast dest MAC |
| 235 | */ |
| 236 | u8 *rewrite; |
| 237 | u8 offset; |
| 238 | |
| 239 | rewrite = ethernet_build_rewrite |
| 240 | (vnm, |
| 241 | sw_if_index, |
| 242 | adj->ia_link, |
| 243 | (adj->ia_nh_proto == FIB_PROTOCOL_IP6 ? |
| 244 | ethernet_ip6_mcast_dst_addr () : |
| 245 | ethernet_ip4_mcast_dst_addr ())); |
| 246 | |
| 247 | /* |
| 248 | * Complete the remaining fields of the adj's rewrite to direct the |
| 249 | * complete of the rewrite at switch time by copying in the IP |
| 250 | * dst address's bytes. |
| 251 | * Ofset is 2 bytes into the destintation address. |
| 252 | */ |
| 253 | offset = vec_len (rewrite) - 2; |
| 254 | adj_mcast_update_rewrite (ai, rewrite, offset); |
| 255 | |
| 256 | break; |
| 257 | } |
| 258 | case IP_LOOKUP_NEXT_DROP: |
| 259 | case IP_LOOKUP_NEXT_PUNT: |
| 260 | case IP_LOOKUP_NEXT_LOCAL: |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 261 | case IP_LOOKUP_NEXT_MCAST_MIDCHAIN: |
| 262 | case IP_LOOKUP_NEXT_MIDCHAIN: |
| 263 | case IP_LOOKUP_NEXT_ICMP_ERROR: |
| 264 | case IP_LOOKUP_N_NEXT: |
| 265 | ASSERT (0); |
| 266 | break; |
| 267 | } |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 268 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 269 | } |
| 270 | |
Benoît Ganne | b44c77d | 2020-10-20 16:24:17 +0200 | [diff] [blame] | 271 | static void |
| 272 | ethernet_interface_address_copy (ethernet_interface_address_t * dst, |
| 273 | const u8 * mac) |
| 274 | { |
| 275 | clib_memcpy (&dst->mac, (u8 *) mac, sizeof (dst->mac)); |
| 276 | /* |
| 277 | * ethernet dataplane loads mac as u64, makes sure the last 2 bytes are 0 |
| 278 | * for comparison purpose |
| 279 | */ |
| 280 | dst->zero = 0; |
| 281 | } |
| 282 | |
| 283 | static void |
| 284 | ethernet_set_mac (vnet_hw_interface_t * hi, ethernet_interface_t * ei, |
| 285 | const u8 * mac_address) |
| 286 | { |
| 287 | vec_validate (hi->hw_address, sizeof (mac_address_t) - 1); |
| 288 | clib_memcpy (hi->hw_address, mac_address, sizeof (mac_address_t)); |
| 289 | ethernet_interface_address_copy (&ei->address, mac_address); |
| 290 | } |
| 291 | |
Neale Ranns | 3be6b28 | 2016-12-20 14:24:01 +0000 | [diff] [blame] | 292 | static clib_error_t * |
Neale Ranns | 3b81a1e | 2018-09-06 09:50:26 -0700 | [diff] [blame] | 293 | ethernet_mac_change (vnet_hw_interface_t * hi, |
| 294 | const u8 * old_address, const u8 * mac_address) |
Neale Ranns | 3be6b28 | 2016-12-20 14:24:01 +0000 | [diff] [blame] | 295 | { |
| 296 | ethernet_interface_t *ei; |
| 297 | ethernet_main_t *em; |
| 298 | |
| 299 | em = ðernet_main; |
| 300 | ei = pool_elt_at_index (em->interfaces, hi->hw_instance); |
| 301 | |
Benoît Ganne | b44c77d | 2020-10-20 16:24:17 +0200 | [diff] [blame] | 302 | ethernet_set_mac (hi, ei, mac_address); |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 303 | |
| 304 | { |
| 305 | ethernet_address_change_ctx_t *cb; |
| 306 | vec_foreach (cb, em->address_change_callbacks) |
| 307 | cb->function (em, hi->sw_if_index, cb->function_opaque); |
| 308 | } |
Neale Ranns | 3be6b28 | 2016-12-20 14:24:01 +0000 | [diff] [blame] | 309 | |
| 310 | return (NULL); |
| 311 | } |
| 312 | |
Damjan Marion | 88a9c0e | 2022-01-06 21:14:08 +0100 | [diff] [blame] | 313 | static clib_error_t * |
Damjan Marion | 1cd0e5d | 2022-01-17 14:49:17 +0100 | [diff] [blame^] | 314 | ethernet_set_max_frame_size (vnet_main_t *vnm, vnet_hw_interface_t *hi, |
| 315 | u32 frame_size) |
Damjan Marion | 88a9c0e | 2022-01-06 21:14:08 +0100 | [diff] [blame] | 316 | { |
| 317 | ethernet_interface_t *ei = |
| 318 | pool_elt_at_index (ethernet_main.interfaces, hi->hw_instance); |
| 319 | |
Damjan Marion | 1cd0e5d | 2022-01-17 14:49:17 +0100 | [diff] [blame^] | 320 | if (ei->cb.set_max_frame_size) |
| 321 | return ei->cb.set_max_frame_size (vnm, hi, frame_size); |
Damjan Marion | 88a9c0e | 2022-01-06 21:14:08 +0100 | [diff] [blame] | 322 | |
Damjan Marion | 1cd0e5d | 2022-01-17 14:49:17 +0100 | [diff] [blame^] | 323 | return vnet_error ( |
| 324 | VNET_ERR_UNSUPPORTED, |
| 325 | "underlying driver doesn't support changing Max Frame Size"); |
Damjan Marion | 88a9c0e | 2022-01-06 21:14:08 +0100 | [diff] [blame] | 326 | } |
| 327 | |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 328 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 329 | VNET_HW_INTERFACE_CLASS (ethernet_hw_interface_class) = { |
| 330 | .name = "Ethernet", |
Mohsin Kazmi | 0d05c0d | 2021-11-09 17:44:10 +0000 | [diff] [blame] | 331 | .tx_hash_fn_type = VNET_HASH_FN_TYPE_ETHERNET, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 332 | .format_address = format_ethernet_address, |
| 333 | .format_header = format_ethernet_header_with_length, |
| 334 | .unformat_hw_address = unformat_ethernet_address, |
| 335 | .unformat_header = unformat_ethernet_header, |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 336 | .build_rewrite = ethernet_build_rewrite, |
| 337 | .update_adjacency = ethernet_update_adjacency, |
Neale Ranns | 3be6b28 | 2016-12-20 14:24:01 +0000 | [diff] [blame] | 338 | .mac_addr_change_function = ethernet_mac_change, |
Damjan Marion | 1cd0e5d | 2022-01-17 14:49:17 +0100 | [diff] [blame^] | 339 | .set_max_frame_size = ethernet_set_max_frame_size, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 340 | }; |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 341 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 342 | |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 343 | uword |
| 344 | unformat_ethernet_interface (unformat_input_t * input, va_list * args) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 345 | { |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 346 | vnet_main_t *vnm = va_arg (*args, vnet_main_t *); |
| 347 | u32 *result = va_arg (*args, u32 *); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 348 | u32 hw_if_index; |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 349 | ethernet_main_t *em = ðernet_main; |
| 350 | ethernet_interface_t *eif; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 351 | |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 352 | if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 353 | return 0; |
| 354 | |
| 355 | eif = ethernet_get_interface (em, hw_if_index); |
| 356 | if (eif) |
| 357 | { |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 358 | *result = hw_if_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 359 | return 1; |
| 360 | } |
| 361 | return 0; |
| 362 | } |
| 363 | |
Damjan Marion | 5c954c4 | 2022-01-06 20:36:14 +0100 | [diff] [blame] | 364 | u32 |
| 365 | vnet_eth_register_interface (vnet_main_t *vnm, |
| 366 | vnet_eth_interface_registration_t *r) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 367 | { |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 368 | ethernet_main_t *em = ðernet_main; |
| 369 | ethernet_interface_t *ei; |
| 370 | vnet_hw_interface_t *hi; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 371 | u32 hw_if_index; |
| 372 | |
| 373 | pool_get (em->interfaces, ei); |
Damjan Marion | 5c954c4 | 2022-01-06 20:36:14 +0100 | [diff] [blame] | 374 | clib_memcpy (&ei->cb, &r->cb, sizeof (vnet_eth_if_callbacks_t)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 375 | |
Damjan Marion | 5c954c4 | 2022-01-06 20:36:14 +0100 | [diff] [blame] | 376 | hw_if_index = vnet_register_interface ( |
| 377 | vnm, r->dev_class_index, r->dev_instance, |
| 378 | ethernet_hw_interface_class.index, ei - em->interfaces); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 379 | |
| 380 | hi = vnet_get_hw_interface (vnm, hw_if_index); |
| 381 | |
| 382 | ethernet_setup_node (vnm->vlib_main, hi->output_node_index); |
| 383 | |
Damjan Marion | 1cd0e5d | 2022-01-17 14:49:17 +0100 | [diff] [blame^] | 384 | hi->min_frame_size = ETHERNET_MIN_PACKET_BYTES; |
| 385 | hi->frame_overhead = |
| 386 | r->frame_overhead ? |
| 387 | r->max_frame_size : |
| 388 | sizeof (ethernet_header_t) + 2 * sizeof (ethernet_vlan_header_t); |
| 389 | hi->max_frame_size = r->max_frame_size ? |
| 390 | r->max_frame_size : |
| 391 | ethernet_main.default_mtu + hi->frame_overhead; |
| 392 | ; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 393 | |
Dave Barach | 5fa4525 | 2020-02-26 10:27:08 -0500 | [diff] [blame] | 394 | /* Default ethernet MTU, 9000 unless set by ethernet_config see below */ |
| 395 | vnet_sw_interface_set_mtu (vnm, hi->sw_if_index, em->default_mtu); |
Damjan Marion | fe7d4a2 | 2018-04-13 19:43:39 +0200 | [diff] [blame] | 396 | |
Damjan Marion | 5c954c4 | 2022-01-06 20:36:14 +0100 | [diff] [blame] | 397 | ethernet_set_mac (hi, ei, r->address); |
| 398 | return hw_if_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 399 | } |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 400 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 401 | void |
| 402 | ethernet_delete_interface (vnet_main_t * vnm, u32 hw_if_index) |
| 403 | { |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 404 | ethernet_main_t *em = ðernet_main; |
| 405 | ethernet_interface_t *ei; |
| 406 | vnet_hw_interface_t *hi; |
| 407 | main_intf_t *main_intf; |
| 408 | vlan_table_t *vlan_table; |
| 409 | u32 idx; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 410 | |
| 411 | hi = vnet_get_hw_interface (vnm, hw_if_index); |
| 412 | ei = pool_elt_at_index (em->interfaces, hi->hw_instance); |
| 413 | |
| 414 | /* Delete vlan mapping table for dot1q and dot1ad. */ |
| 415 | main_intf = vec_elt_at_index (em->main_intfs, hi->hw_if_index); |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 416 | if (main_intf->dot1q_vlans) |
| 417 | { |
| 418 | vlan_table = vec_elt_at_index (em->vlan_pool, main_intf->dot1q_vlans); |
| 419 | for (idx = 0; idx < ETHERNET_N_VLAN; idx++) |
| 420 | { |
| 421 | if (vlan_table->vlans[idx].qinqs) |
| 422 | { |
| 423 | pool_put_index (em->qinq_pool, vlan_table->vlans[idx].qinqs); |
John Lo | d63abff | 2018-10-04 16:22:21 -0400 | [diff] [blame] | 424 | vlan_table->vlans[idx].qinqs = 0; |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 425 | } |
| 426 | } |
| 427 | pool_put_index (em->vlan_pool, main_intf->dot1q_vlans); |
Steve Shin | 8a3e575 | 2018-02-20 11:38:34 -0800 | [diff] [blame] | 428 | main_intf->dot1q_vlans = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 429 | } |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 430 | if (main_intf->dot1ad_vlans) |
| 431 | { |
| 432 | vlan_table = vec_elt_at_index (em->vlan_pool, main_intf->dot1ad_vlans); |
| 433 | for (idx = 0; idx < ETHERNET_N_VLAN; idx++) |
| 434 | { |
| 435 | if (vlan_table->vlans[idx].qinqs) |
| 436 | { |
| 437 | pool_put_index (em->qinq_pool, vlan_table->vlans[idx].qinqs); |
John Lo | d63abff | 2018-10-04 16:22:21 -0400 | [diff] [blame] | 438 | vlan_table->vlans[idx].qinqs = 0; |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 439 | } |
| 440 | } |
| 441 | pool_put_index (em->vlan_pool, main_intf->dot1ad_vlans); |
Steve Shin | 8a3e575 | 2018-02-20 11:38:34 -0800 | [diff] [blame] | 442 | main_intf->dot1ad_vlans = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 443 | } |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 444 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 445 | vnet_delete_hw_interface (vnm, hw_if_index); |
| 446 | pool_put (em->interfaces, ei); |
| 447 | } |
| 448 | |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 449 | u32 |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 450 | ethernet_set_flags (vnet_main_t * vnm, u32 hw_if_index, u32 flags) |
| 451 | { |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 452 | ethernet_main_t *em = ðernet_main; |
| 453 | vnet_hw_interface_t *hi; |
| 454 | ethernet_interface_t *ei; |
John Lo | 4a302ee | 2020-05-12 22:34:39 -0400 | [diff] [blame] | 455 | u32 opn_flags = flags & ETHERNET_INTERFACE_FLAGS_SET_OPN_MASK; |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 456 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 457 | hi = vnet_get_hw_interface (vnm, hw_if_index); |
| 458 | |
| 459 | ASSERT (hi->hw_class_index == ethernet_hw_interface_class.index); |
| 460 | |
| 461 | ei = pool_elt_at_index (em->interfaces, hi->hw_instance); |
John Lo | 4a302ee | 2020-05-12 22:34:39 -0400 | [diff] [blame] | 462 | |
| 463 | /* preserve status bits and update last set operation bits */ |
| 464 | ei->flags = (ei->flags & ETHERNET_INTERFACE_FLAGS_STATUS_MASK) | opn_flags; |
| 465 | |
Damjan Marion | 5c954c4 | 2022-01-06 20:36:14 +0100 | [diff] [blame] | 466 | if (ei->cb.flag_change) |
John Lo | 4a302ee | 2020-05-12 22:34:39 -0400 | [diff] [blame] | 467 | { |
| 468 | switch (opn_flags) |
| 469 | { |
| 470 | case ETHERNET_INTERFACE_FLAG_DEFAULT_L3: |
Damjan Marion | d4f88cc | 2022-01-05 01:52:38 +0100 | [diff] [blame] | 471 | if (hi->caps & VNET_HW_IF_CAP_MAC_FILTER) |
John Lo | 4a302ee | 2020-05-12 22:34:39 -0400 | [diff] [blame] | 472 | { |
Damjan Marion | 5c954c4 | 2022-01-06 20:36:14 +0100 | [diff] [blame] | 473 | if (ei->cb.flag_change (vnm, hi, opn_flags) != ~0) |
John Lo | 4a302ee | 2020-05-12 22:34:39 -0400 | [diff] [blame] | 474 | { |
| 475 | ei->flags |= ETHERNET_INTERFACE_FLAG_STATUS_L3; |
| 476 | return 0; |
| 477 | } |
| 478 | ei->flags &= ~ETHERNET_INTERFACE_FLAG_STATUS_L3; |
| 479 | return ~0; |
| 480 | } |
| 481 | /* fall through */ |
| 482 | case ETHERNET_INTERFACE_FLAG_ACCEPT_ALL: |
| 483 | ei->flags &= ~ETHERNET_INTERFACE_FLAG_STATUS_L3; |
Damjan Marion | 5c954c4 | 2022-01-06 20:36:14 +0100 | [diff] [blame] | 484 | return ei->cb.flag_change (vnm, hi, opn_flags); |
John Lo | 4a302ee | 2020-05-12 22:34:39 -0400 | [diff] [blame] | 485 | default: |
| 486 | return ~0; |
| 487 | } |
| 488 | } |
| 489 | return ~0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 490 | } |
| 491 | |
Dave Barach | 635ec3b | 2018-07-13 20:12:45 -0400 | [diff] [blame] | 492 | /** |
| 493 | * Echo packets back to ethernet/l2-input. |
Dave Barach | 635ec3b | 2018-07-13 20:12:45 -0400 | [diff] [blame] | 494 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 495 | static uword |
| 496 | simulated_ethernet_interface_tx (vlib_main_t * vm, |
Dave Barach | 635ec3b | 2018-07-13 20:12:45 -0400 | [diff] [blame] | 497 | vlib_node_runtime_t * |
| 498 | node, vlib_frame_t * frame) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 499 | { |
Dave Barach | 78451a6 | 2018-07-21 09:25:00 -0400 | [diff] [blame] | 500 | u32 n_left_from, *from; |
| 501 | u32 next_index = 0; |
| 502 | u32 n_bytes; |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 503 | u32 thread_index = vm->thread_index; |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 504 | vnet_main_t *vnm = vnet_get_main (); |
| 505 | vnet_interface_main_t *im = &vnm->interface_main; |
Dave Barach | 635ec3b | 2018-07-13 20:12:45 -0400 | [diff] [blame] | 506 | l2_input_config_t *config; |
Dave Barach | 78451a6 | 2018-07-21 09:25:00 -0400 | [diff] [blame] | 507 | vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b; |
| 508 | u16 nexts[VLIB_FRAME_SIZE], *next; |
| 509 | u32 new_rx_sw_if_index = ~0; |
| 510 | u32 new_tx_sw_if_index = ~0; |
John Lo | 405e41b | 2016-04-23 15:14:12 -0400 | [diff] [blame] | 511 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 512 | n_left_from = frame->n_vectors; |
Damjan Marion | a3d5986 | 2018-11-10 10:23:00 +0100 | [diff] [blame] | 513 | from = vlib_frame_vector_args (frame); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 514 | |
Dave Barach | 78451a6 | 2018-07-21 09:25:00 -0400 | [diff] [blame] | 515 | vlib_get_buffers (vm, from, bufs, n_left_from); |
| 516 | b = bufs; |
| 517 | next = nexts; |
Dave Barach | 635ec3b | 2018-07-13 20:12:45 -0400 | [diff] [blame] | 518 | |
Dave Barach | 78451a6 | 2018-07-21 09:25:00 -0400 | [diff] [blame] | 519 | /* Ordinarily, this is the only config lookup. */ |
| 520 | config = l2input_intf_config (vnet_buffer (b[0])->sw_if_index[VLIB_TX]); |
Neale Ranns | 47a3d99 | 2020-09-29 15:38:51 +0000 | [diff] [blame] | 521 | next_index = (l2_input_is_bridge (config) ? |
| 522 | VNET_SIMULATED_ETHERNET_TX_NEXT_L2_INPUT : |
| 523 | VNET_SIMULATED_ETHERNET_TX_NEXT_ETHERNET_INPUT); |
| 524 | new_tx_sw_if_index = l2_input_is_bvi (config) ? L2INPUT_BVI : ~0; |
Dave Barach | 78451a6 | 2018-07-21 09:25:00 -0400 | [diff] [blame] | 525 | new_rx_sw_if_index = vnet_buffer (b[0])->sw_if_index[VLIB_TX]; |
Dave Barach | 635ec3b | 2018-07-13 20:12:45 -0400 | [diff] [blame] | 526 | |
Dave Barach | 78451a6 | 2018-07-21 09:25:00 -0400 | [diff] [blame] | 527 | while (n_left_from >= 4) |
| 528 | { |
| 529 | u32 sw_if_index0, sw_if_index1, sw_if_index2, sw_if_index3; |
| 530 | u32 not_all_match_config; |
Dave Barach | 635ec3b | 2018-07-13 20:12:45 -0400 | [diff] [blame] | 531 | |
Dave Barach | 78451a6 | 2018-07-21 09:25:00 -0400 | [diff] [blame] | 532 | /* Prefetch next iteration. */ |
| 533 | if (PREDICT_TRUE (n_left_from >= 8)) |
| 534 | { |
| 535 | vlib_prefetch_buffer_header (b[4], STORE); |
| 536 | vlib_prefetch_buffer_header (b[5], STORE); |
| 537 | vlib_prefetch_buffer_header (b[6], STORE); |
| 538 | vlib_prefetch_buffer_header (b[7], STORE); |
| 539 | } |
Dave Barach | 635ec3b | 2018-07-13 20:12:45 -0400 | [diff] [blame] | 540 | |
Dave Barach | 78451a6 | 2018-07-21 09:25:00 -0400 | [diff] [blame] | 541 | /* Make sure all pkts were transmitted on the same (loop) intfc */ |
| 542 | sw_if_index0 = vnet_buffer (b[0])->sw_if_index[VLIB_TX]; |
| 543 | sw_if_index1 = vnet_buffer (b[1])->sw_if_index[VLIB_TX]; |
| 544 | sw_if_index2 = vnet_buffer (b[2])->sw_if_index[VLIB_TX]; |
| 545 | sw_if_index3 = vnet_buffer (b[3])->sw_if_index[VLIB_TX]; |
Dave Barach | 635ec3b | 2018-07-13 20:12:45 -0400 | [diff] [blame] | 546 | |
Dave Barach | 78451a6 | 2018-07-21 09:25:00 -0400 | [diff] [blame] | 547 | not_all_match_config = (sw_if_index0 ^ sw_if_index1) |
| 548 | ^ (sw_if_index2 ^ sw_if_index3); |
| 549 | not_all_match_config += sw_if_index0 ^ new_rx_sw_if_index; |
| 550 | |
| 551 | /* Speed path / expected case: all pkts on the same intfc */ |
| 552 | if (PREDICT_TRUE (not_all_match_config == 0)) |
| 553 | { |
| 554 | next[0] = next_index; |
| 555 | next[1] = next_index; |
| 556 | next[2] = next_index; |
| 557 | next[3] = next_index; |
| 558 | vnet_buffer (b[0])->sw_if_index[VLIB_RX] = new_rx_sw_if_index; |
| 559 | vnet_buffer (b[1])->sw_if_index[VLIB_RX] = new_rx_sw_if_index; |
| 560 | vnet_buffer (b[2])->sw_if_index[VLIB_RX] = new_rx_sw_if_index; |
| 561 | vnet_buffer (b[3])->sw_if_index[VLIB_RX] = new_rx_sw_if_index; |
| 562 | vnet_buffer (b[0])->sw_if_index[VLIB_TX] = new_tx_sw_if_index; |
| 563 | vnet_buffer (b[1])->sw_if_index[VLIB_TX] = new_tx_sw_if_index; |
| 564 | vnet_buffer (b[2])->sw_if_index[VLIB_TX] = new_tx_sw_if_index; |
| 565 | vnet_buffer (b[3])->sw_if_index[VLIB_TX] = new_tx_sw_if_index; |
| 566 | n_bytes = vlib_buffer_length_in_chain (vm, b[0]); |
| 567 | n_bytes += vlib_buffer_length_in_chain (vm, b[1]); |
| 568 | n_bytes += vlib_buffer_length_in_chain (vm, b[2]); |
| 569 | n_bytes += vlib_buffer_length_in_chain (vm, b[3]); |
| 570 | |
| 571 | if (next_index == VNET_SIMULATED_ETHERNET_TX_NEXT_L2_INPUT) |
| 572 | { |
| 573 | vnet_update_l2_len (b[0]); |
| 574 | vnet_update_l2_len (b[1]); |
| 575 | vnet_update_l2_len (b[2]); |
| 576 | vnet_update_l2_len (b[3]); |
| 577 | } |
| 578 | |
| 579 | /* increment TX interface stat */ |
| 580 | vlib_increment_combined_counter (im->combined_sw_if_counters + |
| 581 | VNET_INTERFACE_COUNTER_TX, |
| 582 | thread_index, new_rx_sw_if_index, |
| 583 | 4 /* pkts */ , n_bytes); |
| 584 | b += 4; |
| 585 | next += 4; |
| 586 | n_left_from -= 4; |
| 587 | continue; |
| 588 | } |
| 589 | |
| 590 | /* |
| 591 | * Slow path: we know that at least one of the pkts |
| 592 | * was transmitted on a different sw_if_index, so |
| 593 | * check each sw_if_index against the cached data and proceed |
| 594 | * accordingly. |
| 595 | * |
| 596 | * This shouldn't happen, but code can (and does) bypass the |
| 597 | * per-interface output node, so deal with it. |
| 598 | */ |
| 599 | if (PREDICT_FALSE (vnet_buffer (b[0])->sw_if_index[VLIB_TX] |
| 600 | != new_rx_sw_if_index)) |
| 601 | { |
| 602 | config = l2input_intf_config |
| 603 | (vnet_buffer (b[0])->sw_if_index[VLIB_TX]); |
Neale Ranns | 47a3d99 | 2020-09-29 15:38:51 +0000 | [diff] [blame] | 604 | next_index = (l2_input_is_bridge (config) ? |
| 605 | VNET_SIMULATED_ETHERNET_TX_NEXT_L2_INPUT : |
| 606 | VNET_SIMULATED_ETHERNET_TX_NEXT_ETHERNET_INPUT); |
| 607 | new_tx_sw_if_index = l2_input_is_bvi (config) ? L2INPUT_BVI : ~0; |
Dave Barach | 78451a6 | 2018-07-21 09:25:00 -0400 | [diff] [blame] | 608 | new_rx_sw_if_index = vnet_buffer (b[0])->sw_if_index[VLIB_TX]; |
| 609 | } |
| 610 | next[0] = next_index; |
| 611 | vnet_buffer (b[0])->sw_if_index[VLIB_RX] = new_rx_sw_if_index; |
| 612 | vnet_buffer (b[0])->sw_if_index[VLIB_TX] = new_tx_sw_if_index; |
| 613 | n_bytes = vlib_buffer_length_in_chain (vm, b[0]); |
| 614 | if (next_index == VNET_SIMULATED_ETHERNET_TX_NEXT_L2_INPUT) |
| 615 | vnet_update_l2_len (b[0]); |
| 616 | |
| 617 | vlib_increment_combined_counter (im->combined_sw_if_counters + |
| 618 | VNET_INTERFACE_COUNTER_TX, |
| 619 | thread_index, new_rx_sw_if_index, |
| 620 | 1 /* pkts */ , n_bytes); |
| 621 | |
| 622 | if (PREDICT_FALSE (vnet_buffer (b[1])->sw_if_index[VLIB_TX] |
| 623 | != new_rx_sw_if_index)) |
| 624 | { |
| 625 | config = l2input_intf_config |
| 626 | (vnet_buffer (b[1])->sw_if_index[VLIB_TX]); |
Neale Ranns | 47a3d99 | 2020-09-29 15:38:51 +0000 | [diff] [blame] | 627 | next_index = (l2_input_is_bridge (config) ? |
| 628 | VNET_SIMULATED_ETHERNET_TX_NEXT_L2_INPUT : |
| 629 | VNET_SIMULATED_ETHERNET_TX_NEXT_ETHERNET_INPUT); |
Dave Barach | 78451a6 | 2018-07-21 09:25:00 -0400 | [diff] [blame] | 630 | new_rx_sw_if_index = vnet_buffer (b[1])->sw_if_index[VLIB_TX]; |
Neale Ranns | 47a3d99 | 2020-09-29 15:38:51 +0000 | [diff] [blame] | 631 | new_tx_sw_if_index = l2_input_is_bvi (config) ? L2INPUT_BVI : ~0; |
Dave Barach | 78451a6 | 2018-07-21 09:25:00 -0400 | [diff] [blame] | 632 | } |
| 633 | next[1] = next_index; |
| 634 | vnet_buffer (b[1])->sw_if_index[VLIB_RX] = new_rx_sw_if_index; |
| 635 | vnet_buffer (b[1])->sw_if_index[VLIB_TX] = new_tx_sw_if_index; |
| 636 | n_bytes = vlib_buffer_length_in_chain (vm, b[1]); |
| 637 | if (next_index == VNET_SIMULATED_ETHERNET_TX_NEXT_L2_INPUT) |
| 638 | vnet_update_l2_len (b[1]); |
| 639 | |
| 640 | vlib_increment_combined_counter (im->combined_sw_if_counters + |
| 641 | VNET_INTERFACE_COUNTER_TX, |
| 642 | thread_index, new_rx_sw_if_index, |
| 643 | 1 /* pkts */ , n_bytes); |
| 644 | |
| 645 | if (PREDICT_FALSE (vnet_buffer (b[2])->sw_if_index[VLIB_TX] |
| 646 | != new_rx_sw_if_index)) |
| 647 | { |
| 648 | config = l2input_intf_config |
| 649 | (vnet_buffer (b[2])->sw_if_index[VLIB_TX]); |
Neale Ranns | 47a3d99 | 2020-09-29 15:38:51 +0000 | [diff] [blame] | 650 | next_index = (l2_input_is_bridge (config) ? |
| 651 | VNET_SIMULATED_ETHERNET_TX_NEXT_L2_INPUT : |
| 652 | VNET_SIMULATED_ETHERNET_TX_NEXT_ETHERNET_INPUT); |
Dave Barach | 78451a6 | 2018-07-21 09:25:00 -0400 | [diff] [blame] | 653 | new_rx_sw_if_index = vnet_buffer (b[2])->sw_if_index[VLIB_TX]; |
Neale Ranns | 47a3d99 | 2020-09-29 15:38:51 +0000 | [diff] [blame] | 654 | new_tx_sw_if_index = l2_input_is_bvi (config) ? L2INPUT_BVI : ~0; |
Dave Barach | 78451a6 | 2018-07-21 09:25:00 -0400 | [diff] [blame] | 655 | } |
| 656 | next[2] = next_index; |
| 657 | vnet_buffer (b[2])->sw_if_index[VLIB_RX] = new_rx_sw_if_index; |
| 658 | vnet_buffer (b[2])->sw_if_index[VLIB_TX] = new_tx_sw_if_index; |
| 659 | n_bytes = vlib_buffer_length_in_chain (vm, b[2]); |
| 660 | if (next_index == VNET_SIMULATED_ETHERNET_TX_NEXT_L2_INPUT) |
| 661 | vnet_update_l2_len (b[2]); |
| 662 | |
| 663 | vlib_increment_combined_counter (im->combined_sw_if_counters + |
| 664 | VNET_INTERFACE_COUNTER_TX, |
| 665 | thread_index, new_rx_sw_if_index, |
| 666 | 1 /* pkts */ , n_bytes); |
| 667 | |
| 668 | if (PREDICT_FALSE (vnet_buffer (b[3])->sw_if_index[VLIB_TX] |
| 669 | != new_rx_sw_if_index)) |
| 670 | { |
| 671 | config = l2input_intf_config |
| 672 | (vnet_buffer (b[3])->sw_if_index[VLIB_TX]); |
Neale Ranns | 47a3d99 | 2020-09-29 15:38:51 +0000 | [diff] [blame] | 673 | next_index = (l2_input_is_bridge (config) ? |
| 674 | VNET_SIMULATED_ETHERNET_TX_NEXT_L2_INPUT : |
| 675 | VNET_SIMULATED_ETHERNET_TX_NEXT_ETHERNET_INPUT); |
Dave Barach | 78451a6 | 2018-07-21 09:25:00 -0400 | [diff] [blame] | 676 | new_rx_sw_if_index = vnet_buffer (b[3])->sw_if_index[VLIB_TX]; |
Neale Ranns | 47a3d99 | 2020-09-29 15:38:51 +0000 | [diff] [blame] | 677 | new_tx_sw_if_index = l2_input_is_bvi (config) ? L2INPUT_BVI : ~0; |
Dave Barach | 78451a6 | 2018-07-21 09:25:00 -0400 | [diff] [blame] | 678 | } |
| 679 | next[3] = next_index; |
| 680 | vnet_buffer (b[3])->sw_if_index[VLIB_RX] = new_rx_sw_if_index; |
| 681 | vnet_buffer (b[3])->sw_if_index[VLIB_TX] = new_tx_sw_if_index; |
| 682 | n_bytes = vlib_buffer_length_in_chain (vm, b[3]); |
| 683 | if (next_index == VNET_SIMULATED_ETHERNET_TX_NEXT_L2_INPUT) |
| 684 | vnet_update_l2_len (b[3]); |
| 685 | |
| 686 | vlib_increment_combined_counter (im->combined_sw_if_counters + |
| 687 | VNET_INTERFACE_COUNTER_TX, |
| 688 | thread_index, new_rx_sw_if_index, |
| 689 | 1 /* pkts */ , n_bytes); |
| 690 | b += 4; |
| 691 | next += 4; |
| 692 | n_left_from -= 4; |
| 693 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 694 | while (n_left_from > 0) |
| 695 | { |
Dave Barach | 78451a6 | 2018-07-21 09:25:00 -0400 | [diff] [blame] | 696 | if (PREDICT_FALSE (vnet_buffer (b[0])->sw_if_index[VLIB_TX] |
| 697 | != new_rx_sw_if_index)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 698 | { |
Dave Barach | 78451a6 | 2018-07-21 09:25:00 -0400 | [diff] [blame] | 699 | config = l2input_intf_config |
| 700 | (vnet_buffer (b[0])->sw_if_index[VLIB_TX]); |
Neale Ranns | 47a3d99 | 2020-09-29 15:38:51 +0000 | [diff] [blame] | 701 | next_index = (l2_input_is_bridge (config) ? |
| 702 | VNET_SIMULATED_ETHERNET_TX_NEXT_L2_INPUT : |
| 703 | VNET_SIMULATED_ETHERNET_TX_NEXT_ETHERNET_INPUT); |
| 704 | new_tx_sw_if_index = l2_input_is_bvi (config) ? L2INPUT_BVI : ~0; |
Dave Barach | 78451a6 | 2018-07-21 09:25:00 -0400 | [diff] [blame] | 705 | new_rx_sw_if_index = vnet_buffer (b[0])->sw_if_index[VLIB_TX]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 706 | } |
Dave Barach | 78451a6 | 2018-07-21 09:25:00 -0400 | [diff] [blame] | 707 | next[0] = next_index; |
| 708 | vnet_buffer (b[0])->sw_if_index[VLIB_RX] = new_rx_sw_if_index; |
| 709 | vnet_buffer (b[0])->sw_if_index[VLIB_TX] = new_tx_sw_if_index; |
| 710 | n_bytes = vlib_buffer_length_in_chain (vm, b[0]); |
| 711 | if (next_index == VNET_SIMULATED_ETHERNET_TX_NEXT_L2_INPUT) |
| 712 | vnet_update_l2_len (b[0]); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 713 | |
Dave Barach | 78451a6 | 2018-07-21 09:25:00 -0400 | [diff] [blame] | 714 | vlib_increment_combined_counter (im->combined_sw_if_counters + |
| 715 | VNET_INTERFACE_COUNTER_TX, |
| 716 | thread_index, new_rx_sw_if_index, |
| 717 | 1 /* pkts */ , n_bytes); |
| 718 | b += 1; |
| 719 | next += 1; |
| 720 | n_left_from -= 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 721 | } |
| 722 | |
Dave Barach | 78451a6 | 2018-07-21 09:25:00 -0400 | [diff] [blame] | 723 | vlib_buffer_enqueue_to_next (vm, node, from, nexts, frame->n_vectors); |
Dave Barach | 635ec3b | 2018-07-13 20:12:45 -0400 | [diff] [blame] | 724 | |
| 725 | return frame->n_vectors; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 726 | } |
| 727 | |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 728 | static u8 * |
| 729 | format_simulated_ethernet_name (u8 * s, va_list * args) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 730 | { |
| 731 | u32 dev_instance = va_arg (*args, u32); |
| 732 | return format (s, "loop%d", dev_instance); |
| 733 | } |
| 734 | |
Pierre Pfister | f00f91a | 2016-03-09 18:22:32 +0000 | [diff] [blame] | 735 | static clib_error_t * |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 736 | simulated_ethernet_admin_up_down (vnet_main_t * vnm, u32 hw_if_index, |
| 737 | u32 flags) |
Pierre Pfister | f00f91a | 2016-03-09 18:22:32 +0000 | [diff] [blame] | 738 | { |
| 739 | u32 hw_flags = (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 740 | VNET_HW_INTERFACE_FLAG_LINK_UP : 0; |
Pierre Pfister | f00f91a | 2016-03-09 18:22:32 +0000 | [diff] [blame] | 741 | vnet_hw_interface_set_flags (vnm, hw_if_index, hw_flags); |
| 742 | return 0; |
| 743 | } |
| 744 | |
Neale Ranns | 3b81a1e | 2018-09-06 09:50:26 -0700 | [diff] [blame] | 745 | static clib_error_t * |
| 746 | simulated_ethernet_mac_change (vnet_hw_interface_t * hi, |
| 747 | const u8 * old_address, const u8 * mac_address) |
| 748 | { |
| 749 | l2input_interface_mac_change (hi->sw_if_index, old_address, mac_address); |
| 750 | |
| 751 | return (NULL); |
| 752 | } |
| 753 | |
| 754 | |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 755 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 756 | VNET_DEVICE_CLASS (ethernet_simulated_device_class) = { |
| 757 | .name = "Loopback", |
| 758 | .format_device_name = format_simulated_ethernet_name, |
| 759 | .tx_function = simulated_ethernet_interface_tx, |
Pierre Pfister | f00f91a | 2016-03-09 18:22:32 +0000 | [diff] [blame] | 760 | .admin_up_down_function = simulated_ethernet_admin_up_down, |
Neale Ranns | 3b81a1e | 2018-09-06 09:50:26 -0700 | [diff] [blame] | 761 | .mac_addr_change_function = simulated_ethernet_mac_change, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 762 | }; |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 763 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 764 | |
Jon Loeliger | c83c3b7 | 2017-02-23 13:57:35 -0600 | [diff] [blame] | 765 | /* |
| 766 | * Maintain a bitmap of allocated loopback instance numbers. |
| 767 | */ |
| 768 | #define LOOPBACK_MAX_INSTANCE (16 * 1024) |
| 769 | |
| 770 | static u32 |
| 771 | loopback_instance_alloc (u8 is_specified, u32 want) |
| 772 | { |
| 773 | ethernet_main_t *em = ðernet_main; |
| 774 | |
| 775 | /* |
| 776 | * Check for dynamically allocaetd instance number. |
| 777 | */ |
| 778 | if (!is_specified) |
| 779 | { |
| 780 | u32 bit; |
| 781 | |
| 782 | bit = clib_bitmap_first_clear (em->bm_loopback_instances); |
| 783 | if (bit >= LOOPBACK_MAX_INSTANCE) |
| 784 | { |
| 785 | return ~0; |
| 786 | } |
| 787 | em->bm_loopback_instances = clib_bitmap_set (em->bm_loopback_instances, |
| 788 | bit, 1); |
| 789 | return bit; |
| 790 | } |
| 791 | |
| 792 | /* |
| 793 | * In range? |
| 794 | */ |
| 795 | if (want >= LOOPBACK_MAX_INSTANCE) |
| 796 | { |
| 797 | return ~0; |
| 798 | } |
| 799 | |
| 800 | /* |
| 801 | * Already in use? |
| 802 | */ |
| 803 | if (clib_bitmap_get (em->bm_loopback_instances, want)) |
| 804 | { |
| 805 | return ~0; |
| 806 | } |
| 807 | |
| 808 | /* |
| 809 | * Grant allocation request. |
| 810 | */ |
| 811 | em->bm_loopback_instances = clib_bitmap_set (em->bm_loopback_instances, |
| 812 | want, 1); |
| 813 | |
| 814 | return want; |
| 815 | } |
| 816 | |
| 817 | static int |
| 818 | loopback_instance_free (u32 instance) |
| 819 | { |
| 820 | ethernet_main_t *em = ðernet_main; |
| 821 | |
| 822 | if (instance >= LOOPBACK_MAX_INSTANCE) |
| 823 | { |
| 824 | return -1; |
| 825 | } |
| 826 | |
| 827 | if (clib_bitmap_get (em->bm_loopback_instances, instance) == 0) |
| 828 | { |
| 829 | return -1; |
| 830 | } |
| 831 | |
| 832 | em->bm_loopback_instances = clib_bitmap_set (em->bm_loopback_instances, |
| 833 | instance, 0); |
| 834 | return 0; |
| 835 | } |
| 836 | |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 837 | int |
Jon Loeliger | c83c3b7 | 2017-02-23 13:57:35 -0600 | [diff] [blame] | 838 | vnet_create_loopback_interface (u32 * sw_if_indexp, u8 * mac_address, |
| 839 | u8 is_specified, u32 user_instance) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 840 | { |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 841 | vnet_main_t *vnm = vnet_get_main (); |
| 842 | vlib_main_t *vm = vlib_get_main (); |
Jon Loeliger | c83c3b7 | 2017-02-23 13:57:35 -0600 | [diff] [blame] | 843 | u32 instance; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 844 | u8 address[6]; |
| 845 | u32 hw_if_index; |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 846 | vnet_hw_interface_t *hw_if; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 847 | u32 slot; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 848 | |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 849 | ASSERT (sw_if_indexp); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 850 | |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 851 | *sw_if_indexp = (u32) ~ 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 852 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 853 | clib_memset (address, 0, sizeof (address)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 854 | |
| 855 | /* |
Jon Loeliger | c83c3b7 | 2017-02-23 13:57:35 -0600 | [diff] [blame] | 856 | * Allocate a loopback instance. Either select on dynamically |
| 857 | * or try to use the desired user_instance number. |
| 858 | */ |
| 859 | instance = loopback_instance_alloc (is_specified, user_instance); |
| 860 | if (instance == ~0) |
| 861 | { |
| 862 | return VNET_API_ERROR_INVALID_REGISTRATION; |
| 863 | } |
| 864 | |
| 865 | /* |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 866 | * Default MAC address (dead:0000:0000 + instance) is allocated |
| 867 | * if zero mac_address is configured. Otherwise, user-configurable MAC |
| 868 | * address is programmed on the loopback interface. |
| 869 | */ |
| 870 | if (memcmp (address, mac_address, sizeof (address))) |
Damjan Marion | f1213b8 | 2016-03-13 02:22:06 +0100 | [diff] [blame] | 871 | clib_memcpy (address, mac_address, sizeof (address)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 872 | else |
| 873 | { |
| 874 | address[0] = 0xde; |
| 875 | address[1] = 0xad; |
| 876 | address[5] = instance; |
| 877 | } |
| 878 | |
Damjan Marion | 5c954c4 | 2022-01-06 20:36:14 +0100 | [diff] [blame] | 879 | vnet_eth_interface_registration_t eir = {}; |
| 880 | eir.dev_class_index = ethernet_simulated_device_class.index; |
| 881 | eir.dev_instance = instance; |
| 882 | eir.address = address; |
| 883 | hw_if_index = vnet_eth_register_interface (vnm, &eir); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 884 | hw_if = vnet_get_hw_interface (vnm, hw_if_index); |
| 885 | slot = vlib_node_add_named_next_with_slot |
| 886 | (vm, hw_if->tx_node_index, |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 887 | "ethernet-input", VNET_SIMULATED_ETHERNET_TX_NEXT_ETHERNET_INPUT); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 888 | ASSERT (slot == VNET_SIMULATED_ETHERNET_TX_NEXT_ETHERNET_INPUT); |
| 889 | |
Dave Barach | 635ec3b | 2018-07-13 20:12:45 -0400 | [diff] [blame] | 890 | slot = vlib_node_add_named_next_with_slot |
| 891 | (vm, hw_if->tx_node_index, |
| 892 | "l2-input", VNET_SIMULATED_ETHERNET_TX_NEXT_L2_INPUT); |
| 893 | ASSERT (slot == VNET_SIMULATED_ETHERNET_TX_NEXT_L2_INPUT); |
| 894 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 895 | { |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 896 | vnet_sw_interface_t *si = vnet_get_hw_sw_interface (vnm, hw_if_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 897 | *sw_if_indexp = si->sw_if_index; |
Neale Ranns | 87dad11 | 2018-04-09 01:53:01 -0700 | [diff] [blame] | 898 | |
| 899 | /* By default don't flood to loopbacks, as packets just keep |
| 900 | * coming back ... If this loopback becomes a BVI, we'll change it */ |
| 901 | si->flood_class = VNET_FLOOD_CLASS_NO_FLOOD; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 902 | } |
| 903 | |
| 904 | return 0; |
| 905 | } |
| 906 | |
| 907 | static clib_error_t * |
| 908 | create_simulated_ethernet_interfaces (vlib_main_t * vm, |
| 909 | unformat_input_t * input, |
| 910 | vlib_cli_command_t * cmd) |
| 911 | { |
| 912 | int rv; |
| 913 | u32 sw_if_index; |
| 914 | u8 mac_address[6]; |
Jon Loeliger | c83c3b7 | 2017-02-23 13:57:35 -0600 | [diff] [blame] | 915 | u8 is_specified = 0; |
| 916 | u32 user_instance = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 917 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 918 | clib_memset (mac_address, 0, sizeof (mac_address)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 919 | |
| 920 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 921 | { |
| 922 | if (unformat (input, "mac %U", unformat_ethernet_address, mac_address)) |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 923 | ; |
Jon Loeliger | c83c3b7 | 2017-02-23 13:57:35 -0600 | [diff] [blame] | 924 | if (unformat (input, "instance %d", &user_instance)) |
| 925 | is_specified = 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 926 | else |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 927 | break; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 928 | } |
| 929 | |
Jon Loeliger | c83c3b7 | 2017-02-23 13:57:35 -0600 | [diff] [blame] | 930 | rv = vnet_create_loopback_interface (&sw_if_index, mac_address, |
| 931 | is_specified, user_instance); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 932 | |
| 933 | if (rv) |
| 934 | return clib_error_return (0, "vnet_create_loopback_interface failed"); |
| 935 | |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 936 | vlib_cli_output (vm, "%U\n", format_vnet_sw_if_index_name, vnet_get_main (), |
| 937 | sw_if_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 938 | return 0; |
| 939 | } |
| 940 | |
Billy McFall | 2d085d9 | 2016-09-13 21:47:55 -0400 | [diff] [blame] | 941 | /*? |
| 942 | * Create a loopback interface. Optionally, a MAC Address can be |
| 943 | * provided. If not provided, de:ad:00:00:00:<loopId> will be used. |
| 944 | * |
| 945 | * @cliexpar |
| 946 | * The following two command syntaxes are equivalent: |
Jon Loeliger | c83c3b7 | 2017-02-23 13:57:35 -0600 | [diff] [blame] | 947 | * @cliexcmd{loopback create-interface [mac <mac-addr>] [instance <instance>]} |
| 948 | * @cliexcmd{create loopback interface [mac <mac-addr>] [instance <instance>]} |
Billy McFall | 2d085d9 | 2016-09-13 21:47:55 -0400 | [diff] [blame] | 949 | * Example of how to create a loopback interface: |
| 950 | * @cliexcmd{loopback create-interface} |
| 951 | ?*/ |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 952 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 953 | VLIB_CLI_COMMAND (create_simulated_ethernet_interface_command, static) = { |
| 954 | .path = "loopback create-interface", |
Jon Loeliger | c83c3b7 | 2017-02-23 13:57:35 -0600 | [diff] [blame] | 955 | .short_help = "loopback create-interface [mac <mac-addr>] [instance <instance>]", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 956 | .function = create_simulated_ethernet_interfaces, |
| 957 | }; |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 958 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 959 | |
Billy McFall | 2d085d9 | 2016-09-13 21:47:55 -0400 | [diff] [blame] | 960 | /*? |
| 961 | * Create a loopback interface. Optionally, a MAC Address can be |
| 962 | * provided. If not provided, de:ad:00:00:00:<loopId> will be used. |
| 963 | * |
| 964 | * @cliexpar |
| 965 | * The following two command syntaxes are equivalent: |
Jon Loeliger | c83c3b7 | 2017-02-23 13:57:35 -0600 | [diff] [blame] | 966 | * @cliexcmd{loopback create-interface [mac <mac-addr>] [instance <instance>]} |
| 967 | * @cliexcmd{create loopback interface [mac <mac-addr>] [instance <instance>]} |
Billy McFall | 2d085d9 | 2016-09-13 21:47:55 -0400 | [diff] [blame] | 968 | * Example of how to create a loopback interface: |
| 969 | * @cliexcmd{create loopback interface} |
| 970 | ?*/ |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 971 | /* *INDENT-OFF* */ |
Alpesh Patel | 370a24e | 2016-04-08 07:27:37 -0700 | [diff] [blame] | 972 | VLIB_CLI_COMMAND (create_loopback_interface_command, static) = { |
| 973 | .path = "create loopback interface", |
Jon Loeliger | c83c3b7 | 2017-02-23 13:57:35 -0600 | [diff] [blame] | 974 | .short_help = "create loopback interface [mac <mac-addr>] [instance <instance>]", |
Alpesh Patel | 370a24e | 2016-04-08 07:27:37 -0700 | [diff] [blame] | 975 | .function = create_simulated_ethernet_interfaces, |
| 976 | }; |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 977 | /* *INDENT-ON* */ |
Alpesh Patel | 370a24e | 2016-04-08 07:27:37 -0700 | [diff] [blame] | 978 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 979 | ethernet_interface_t * |
| 980 | ethernet_get_interface (ethernet_main_t * em, u32 hw_if_index) |
| 981 | { |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 982 | vnet_hw_interface_t *i = |
| 983 | vnet_get_hw_interface (vnet_get_main (), hw_if_index); |
| 984 | return (i->hw_class_index == |
| 985 | ethernet_hw_interface_class. |
| 986 | index ? pool_elt_at_index (em->interfaces, i->hw_instance) : 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 987 | } |
| 988 | |
Matthew G Smith | d459bf3 | 2019-09-04 15:01:04 -0500 | [diff] [blame] | 989 | mac_address_t * |
| 990 | ethernet_interface_add_del_address (ethernet_main_t * em, |
| 991 | u32 hw_if_index, const u8 * address, |
| 992 | u8 is_add) |
| 993 | { |
| 994 | ethernet_interface_t *ei = ethernet_get_interface (em, hw_if_index); |
Benoît Ganne | b44c77d | 2020-10-20 16:24:17 +0200 | [diff] [blame] | 995 | ethernet_interface_address_t *if_addr = 0; |
| 996 | int found = 0; |
Matthew G Smith | d459bf3 | 2019-09-04 15:01:04 -0500 | [diff] [blame] | 997 | |
| 998 | /* return if there is not an ethernet interface for this hw interface */ |
| 999 | if (!ei) |
| 1000 | return 0; |
| 1001 | |
| 1002 | /* determine whether the address is configured on the interface */ |
| 1003 | vec_foreach (if_addr, ei->secondary_addrs) |
| 1004 | { |
Benoît Ganne | b44c77d | 2020-10-20 16:24:17 +0200 | [diff] [blame] | 1005 | if (ethernet_mac_address_equal (if_addr->mac.bytes, address)) |
| 1006 | { |
| 1007 | found = 1; |
| 1008 | break; |
| 1009 | } |
Matthew G Smith | d459bf3 | 2019-09-04 15:01:04 -0500 | [diff] [blame] | 1010 | } |
| 1011 | |
Benoît Ganne | b44c77d | 2020-10-20 16:24:17 +0200 | [diff] [blame] | 1012 | if (is_add) |
Matthew G Smith | d459bf3 | 2019-09-04 15:01:04 -0500 | [diff] [blame] | 1013 | { |
Benoît Ganne | b44c77d | 2020-10-20 16:24:17 +0200 | [diff] [blame] | 1014 | if (!found) |
Matthew G Smith | d459bf3 | 2019-09-04 15:01:04 -0500 | [diff] [blame] | 1015 | { |
Benoît Ganne | b44c77d | 2020-10-20 16:24:17 +0200 | [diff] [blame] | 1016 | /* address not found yet: add it */ |
Matthew G Smith | d459bf3 | 2019-09-04 15:01:04 -0500 | [diff] [blame] | 1017 | vec_add2 (ei->secondary_addrs, if_addr, 1); |
Benoît Ganne | b44c77d | 2020-10-20 16:24:17 +0200 | [diff] [blame] | 1018 | ethernet_interface_address_copy (if_addr, address); |
Matthew G Smith | d459bf3 | 2019-09-04 15:01:04 -0500 | [diff] [blame] | 1019 | } |
Benoît Ganne | b44c77d | 2020-10-20 16:24:17 +0200 | [diff] [blame] | 1020 | return &if_addr->mac; |
Matthew G Smith | d459bf3 | 2019-09-04 15:01:04 -0500 | [diff] [blame] | 1021 | } |
| 1022 | |
Benoît Ganne | b44c77d | 2020-10-20 16:24:17 +0200 | [diff] [blame] | 1023 | /* delete case */ |
| 1024 | if (found) |
| 1025 | vec_delete (ei->secondary_addrs, 1, if_addr - ei->secondary_addrs); |
| 1026 | |
| 1027 | return 0; |
Matthew G Smith | d459bf3 | 2019-09-04 15:01:04 -0500 | [diff] [blame] | 1028 | } |
| 1029 | |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 1030 | int |
| 1031 | vnet_delete_loopback_interface (u32 sw_if_index) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1032 | { |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 1033 | vnet_main_t *vnm = vnet_get_main (); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1034 | |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 1035 | if (pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1036 | return VNET_API_ERROR_INVALID_SW_IF_INDEX; |
| 1037 | |
Eyal Bari | b52c034 | 2018-07-16 19:18:56 +0300 | [diff] [blame] | 1038 | vnet_hw_interface_t *hw = vnet_get_sup_hw_interface (vnm, sw_if_index); |
| 1039 | if (hw == 0 || hw->dev_class_index != ethernet_simulated_device_class.index) |
| 1040 | return VNET_API_ERROR_INVALID_SW_IF_INDEX; |
Jon Loeliger | c83c3b7 | 2017-02-23 13:57:35 -0600 | [diff] [blame] | 1041 | |
Eyal Bari | b52c034 | 2018-07-16 19:18:56 +0300 | [diff] [blame] | 1042 | if (loopback_instance_free (hw->dev_instance) < 0) |
| 1043 | return VNET_API_ERROR_INVALID_SW_IF_INDEX; |
Jon Loeliger | c83c3b7 | 2017-02-23 13:57:35 -0600 | [diff] [blame] | 1044 | |
Eyal Bari | b52c034 | 2018-07-16 19:18:56 +0300 | [diff] [blame] | 1045 | ethernet_delete_interface (vnm, hw->hw_if_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1046 | |
| 1047 | return 0; |
| 1048 | } |
| 1049 | |
Pavel Kotucek | d85590a | 2016-08-26 13:35:40 +0200 | [diff] [blame] | 1050 | int |
Neale Ranns | 669f4e3 | 2019-10-28 07:56:15 -0700 | [diff] [blame] | 1051 | vnet_create_sub_interface (u32 sw_if_index, u32 id, |
| 1052 | u32 flags, u16 inner_vlan_id, u16 outer_vlan_id, |
| 1053 | u32 * sub_sw_if_index) |
| 1054 | { |
| 1055 | vnet_main_t *vnm = vnet_get_main (); |
| 1056 | vnet_interface_main_t *im = &vnm->interface_main; |
| 1057 | vnet_hw_interface_t *hi; |
| 1058 | u64 sup_and_sub_key = ((u64) (sw_if_index) << 32) | (u64) id; |
| 1059 | vnet_sw_interface_t template; |
| 1060 | uword *p; |
| 1061 | u64 *kp; |
| 1062 | |
| 1063 | hi = vnet_get_sup_hw_interface (vnm, sw_if_index); |
| 1064 | |
| 1065 | p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key); |
| 1066 | if (p) |
| 1067 | { |
| 1068 | return (VNET_API_ERROR_VLAN_ALREADY_EXISTS); |
| 1069 | } |
| 1070 | |
| 1071 | clib_memset (&template, 0, sizeof (template)); |
| 1072 | template.type = VNET_SW_INTERFACE_TYPE_SUB; |
| 1073 | template.flood_class = VNET_FLOOD_CLASS_NORMAL; |
| 1074 | template.sup_sw_if_index = sw_if_index; |
| 1075 | template.sub.id = id; |
| 1076 | template.sub.eth.raw_flags = flags; |
| 1077 | template.sub.eth.outer_vlan_id = outer_vlan_id; |
| 1078 | template.sub.eth.inner_vlan_id = inner_vlan_id; |
| 1079 | |
| 1080 | if (vnet_create_sw_interface (vnm, &template, sub_sw_if_index)) |
| 1081 | return (VNET_API_ERROR_UNSPECIFIED); |
| 1082 | |
| 1083 | kp = clib_mem_alloc (sizeof (*kp)); |
| 1084 | *kp = sup_and_sub_key; |
| 1085 | |
| 1086 | hash_set (hi->sub_interface_sw_if_index_by_id, id, *sub_sw_if_index); |
| 1087 | hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, *sub_sw_if_index); |
| 1088 | |
| 1089 | return (0); |
| 1090 | } |
| 1091 | |
| 1092 | int |
Pavel Kotucek | d85590a | 2016-08-26 13:35:40 +0200 | [diff] [blame] | 1093 | vnet_delete_sub_interface (u32 sw_if_index) |
| 1094 | { |
| 1095 | vnet_main_t *vnm = vnet_get_main (); |
Steve Shin | a36f08c | 2018-03-07 13:29:29 -0800 | [diff] [blame] | 1096 | vnet_sw_interface_t *si; |
Pavel Kotucek | d85590a | 2016-08-26 13:35:40 +0200 | [diff] [blame] | 1097 | int rv = 0; |
| 1098 | |
| 1099 | if (pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index)) |
| 1100 | return VNET_API_ERROR_INVALID_SW_IF_INDEX; |
| 1101 | |
Steve Shin | a36f08c | 2018-03-07 13:29:29 -0800 | [diff] [blame] | 1102 | si = vnet_get_sw_interface (vnm, sw_if_index); |
Pavel Kotucek | 15ac81c | 2017-06-20 14:00:26 +0200 | [diff] [blame] | 1103 | if (si->type == VNET_SW_INTERFACE_TYPE_SUB || |
Neale Ranns | 17ff3c1 | 2018-07-04 10:24:24 -0700 | [diff] [blame] | 1104 | si->type == VNET_SW_INTERFACE_TYPE_PIPE || |
Pavel Kotucek | 15ac81c | 2017-06-20 14:00:26 +0200 | [diff] [blame] | 1105 | si->type == VNET_SW_INTERFACE_TYPE_P2P) |
Pavel Kotucek | d85590a | 2016-08-26 13:35:40 +0200 | [diff] [blame] | 1106 | { |
John Lo | 5957a14 | 2018-01-18 12:44:50 -0500 | [diff] [blame] | 1107 | vnet_interface_main_t *im = &vnm->interface_main; |
| 1108 | vnet_hw_interface_t *hi = vnet_get_sup_hw_interface (vnm, sw_if_index); |
Pavel Kotucek | d85590a | 2016-08-26 13:35:40 +0200 | [diff] [blame] | 1109 | u64 sup_and_sub_key = |
| 1110 | ((u64) (si->sup_sw_if_index) << 32) | (u64) si->sub.id; |
John Lo | 5957a14 | 2018-01-18 12:44:50 -0500 | [diff] [blame] | 1111 | hash_unset_mem_free (&im->sw_if_index_by_sup_and_sub, &sup_and_sub_key); |
| 1112 | hash_unset (hi->sub_interface_sw_if_index_by_id, si->sub.id); |
Pavel Kotucek | d85590a | 2016-08-26 13:35:40 +0200 | [diff] [blame] | 1113 | vnet_delete_sw_interface (vnm, sw_if_index); |
| 1114 | } |
| 1115 | else |
John Lo | 5957a14 | 2018-01-18 12:44:50 -0500 | [diff] [blame] | 1116 | rv = VNET_API_ERROR_INVALID_SUB_SW_IF_INDEX; |
| 1117 | |
Pavel Kotucek | d85590a | 2016-08-26 13:35:40 +0200 | [diff] [blame] | 1118 | return rv; |
| 1119 | } |
| 1120 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1121 | static clib_error_t * |
| 1122 | delete_simulated_ethernet_interfaces (vlib_main_t * vm, |
| 1123 | unformat_input_t * input, |
| 1124 | vlib_cli_command_t * cmd) |
| 1125 | { |
| 1126 | int rv; |
| 1127 | u32 sw_if_index = ~0; |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 1128 | vnet_main_t *vnm = vnet_get_main (); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1129 | |
| 1130 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 1131 | { |
| 1132 | if (unformat (input, "intfc %U", |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 1133 | unformat_vnet_sw_interface, vnm, &sw_if_index)) |
| 1134 | ; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1135 | else |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 1136 | break; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1137 | } |
| 1138 | |
| 1139 | if (sw_if_index == ~0) |
| 1140 | return clib_error_return (0, "interface not specified"); |
| 1141 | |
| 1142 | rv = vnet_delete_loopback_interface (sw_if_index); |
| 1143 | |
| 1144 | if (rv) |
| 1145 | return clib_error_return (0, "vnet_delete_loopback_interface failed"); |
| 1146 | |
| 1147 | return 0; |
| 1148 | } |
| 1149 | |
Pavel Kotucek | d85590a | 2016-08-26 13:35:40 +0200 | [diff] [blame] | 1150 | static clib_error_t * |
| 1151 | delete_sub_interface (vlib_main_t * vm, |
| 1152 | unformat_input_t * input, vlib_cli_command_t * cmd) |
| 1153 | { |
| 1154 | int rv = 0; |
| 1155 | u32 sw_if_index = ~0; |
| 1156 | vnet_main_t *vnm = vnet_get_main (); |
| 1157 | |
| 1158 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 1159 | { |
| 1160 | if (unformat |
| 1161 | (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index)) |
| 1162 | ; |
| 1163 | else |
| 1164 | break; |
| 1165 | } |
| 1166 | if (sw_if_index == ~0) |
| 1167 | return clib_error_return (0, "interface doesn't exist"); |
| 1168 | |
| 1169 | if (pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index)) |
| 1170 | rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; |
| 1171 | else |
| 1172 | rv = vnet_delete_sub_interface (sw_if_index); |
| 1173 | if (rv) |
| 1174 | return clib_error_return (0, "delete_subinterface_interface failed"); |
| 1175 | return 0; |
| 1176 | } |
| 1177 | |
Billy McFall | 2d085d9 | 2016-09-13 21:47:55 -0400 | [diff] [blame] | 1178 | /*? |
| 1179 | * Delete a loopback interface. |
| 1180 | * |
| 1181 | * @cliexpar |
| 1182 | * The following two command syntaxes are equivalent: |
| 1183 | * @cliexcmd{loopback delete-interface intfc <interface>} |
| 1184 | * @cliexcmd{delete loopback interface intfc <interface>} |
| 1185 | * Example of how to delete a loopback interface: |
| 1186 | * @cliexcmd{loopback delete-interface intfc loop0} |
| 1187 | ?*/ |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 1188 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1189 | VLIB_CLI_COMMAND (delete_simulated_ethernet_interface_command, static) = { |
| 1190 | .path = "loopback delete-interface", |
Billy McFall | 2d085d9 | 2016-09-13 21:47:55 -0400 | [diff] [blame] | 1191 | .short_help = "loopback delete-interface intfc <interface>", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1192 | .function = delete_simulated_ethernet_interfaces, |
| 1193 | }; |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 1194 | /* *INDENT-ON* */ |
Alpesh S. Patel | 633951c | 2016-04-12 09:58:56 -0700 | [diff] [blame] | 1195 | |
Billy McFall | 2d085d9 | 2016-09-13 21:47:55 -0400 | [diff] [blame] | 1196 | /*? |
| 1197 | * Delete a loopback interface. |
| 1198 | * |
| 1199 | * @cliexpar |
| 1200 | * The following two command syntaxes are equivalent: |
| 1201 | * @cliexcmd{loopback delete-interface intfc <interface>} |
| 1202 | * @cliexcmd{delete loopback interface intfc <interface>} |
| 1203 | * Example of how to delete a loopback interface: |
| 1204 | * @cliexcmd{delete loopback interface intfc loop0} |
| 1205 | ?*/ |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 1206 | /* *INDENT-OFF* */ |
Alpesh S. Patel | 633951c | 2016-04-12 09:58:56 -0700 | [diff] [blame] | 1207 | VLIB_CLI_COMMAND (delete_loopback_interface_command, static) = { |
| 1208 | .path = "delete loopback interface", |
| 1209 | .short_help = "delete loopback interface intfc <interface>", |
| 1210 | .function = delete_simulated_ethernet_interfaces, |
| 1211 | }; |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 1212 | /* *INDENT-ON* */ |
| 1213 | |
Billy McFall | 2d085d9 | 2016-09-13 21:47:55 -0400 | [diff] [blame] | 1214 | /*? |
| 1215 | * Delete a sub-interface. |
| 1216 | * |
| 1217 | * @cliexpar |
| 1218 | * Example of how to delete a sub-interface: |
| 1219 | * @cliexcmd{delete sub-interface GigabitEthernet0/8/0.200} |
| 1220 | ?*/ |
Pavel Kotucek | d85590a | 2016-08-26 13:35:40 +0200 | [diff] [blame] | 1221 | /* *INDENT-OFF* */ |
| 1222 | VLIB_CLI_COMMAND (delete_sub_interface_command, static) = { |
| 1223 | .path = "delete sub-interface", |
| 1224 | .short_help = "delete sub-interface <interface>", |
| 1225 | .function = delete_sub_interface, |
| 1226 | }; |
| 1227 | /* *INDENT-ON* */ |
| 1228 | |
Paul Vinciguerra | 491741a | 2020-03-02 16:10:54 -0500 | [diff] [blame] | 1229 | /* ethernet { ... } configuration. */ |
| 1230 | /*? |
| 1231 | * |
| 1232 | * @cfgcmd{default-mtu <n>} |
| 1233 | * Specify the default mtu in the range of 64-9000. The default is 9000 bytes. |
| 1234 | * |
| 1235 | */ |
Dave Barach | 5fa4525 | 2020-02-26 10:27:08 -0500 | [diff] [blame] | 1236 | static clib_error_t * |
| 1237 | ethernet_config (vlib_main_t * vm, unformat_input_t * input) |
| 1238 | { |
| 1239 | ethernet_main_t *em = ðernet_main; |
| 1240 | |
| 1241 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 1242 | { |
| 1243 | if (unformat (input, "default-mtu %u", &em->default_mtu)) |
| 1244 | { |
| 1245 | if (em->default_mtu < 64 || em->default_mtu > 9000) |
| 1246 | return clib_error_return (0, "default MTU must be >=64, <=9000"); |
| 1247 | } |
| 1248 | else |
| 1249 | { |
| 1250 | return clib_error_return (0, "unknown input '%U'", |
| 1251 | format_unformat_error, input); |
| 1252 | } |
| 1253 | } |
| 1254 | return 0; |
| 1255 | } |
| 1256 | |
| 1257 | VLIB_CONFIG_FUNCTION (ethernet_config, "ethernet"); |
| 1258 | |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 1259 | /* |
| 1260 | * fd.io coding-style-patch-verification: ON |
| 1261 | * |
| 1262 | * Local Variables: |
| 1263 | * eval: (c-set-style "gnu") |
| 1264 | * End: |
| 1265 | */ |