blob: f72b4930049f3ab4e419c37bcf99b06dde88d481 [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
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 Rannscbe25aa2019-09-30 10:53:31 +000044//#include <vnet/ethernet/arp.h>
John Lo405e41b2016-04-23 15:14:12 -040045#include <vnet/l2/l2_input.h>
Neale Ranns3b81a1e2018-09-06 09:50:26 -070046#include <vnet/l2/l2_bd.h>
Neale Rannsb80c5362016-10-08 13:03:40 +010047#include <vnet/adj/adj.h>
Neale Rannscbe25aa2019-09-30 10:53:31 +000048#include <vnet/adj/adj_mcast.h>
49#include <vnet/ip-neighbor/ip_neighbor.h>
Neale Ranns0bfe5d82016-08-25 15:29:12 +010050
Neale Ranns5e575b12016-10-03 09:40:25 +010051/**
52 * @file
53 * @brief Loopback Interfaces.
54 *
55 * This file contains code to manage loopback interfaces.
56 */
57
Neale Rannscbe25aa2019-09-30 10:53:31 +000058static const u8 *
Neale Ranns32e1c012016-11-22 17:07:28 +000059ethernet_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 Rannscbe25aa2019-09-30 10:53:31 +000068static const u8 *
Neale Ranns32e1c012016-11-22 17:07:28 +000069ethernet_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 Rannsb80c5362016-10-08 13:03:40 +010078/**
79 * @brief build a rewrite string to use for sending packets of type 'link_type'
80 * to 'dst_address'
81 */
82u8 *
83ethernet_build_rewrite (vnet_main_t * vnm,
84 u32 sw_if_index,
85 vnet_link_t link_type, const void *dst_address)
Ed Warnickecb9cada2015-12-08 15:45:58 -070086{
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -070087 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 = &ethernet_main;
91 ethernet_interface_t *ei;
Neale Rannsb80c5362016-10-08 13:03:40 +010092 ethernet_header_t *h;
Ed Warnickecb9cada2015-12-08 15:45:58 -070093 ethernet_type_t type;
94 uword n_bytes = sizeof (h[0]);
Neale Rannsb80c5362016-10-08 13:03:40 +010095 u8 *rewrite = NULL;
Pavel Kotucek15ac81c2017-06-20 14:00:26 +020096 u8 is_p2p = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070097
Neale Ranns17ff3c12018-07-04 10:24:24 -070098 if ((sub_sw->type == VNET_SW_INTERFACE_TYPE_P2P) ||
99 (sub_sw->type == VNET_SW_INTERFACE_TYPE_PIPE))
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200100 is_p2p = 1;
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -0700101 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 Kotucek15ac81c2017-06-20 14:00:26 +0200111 else if (PREDICT_FALSE (is_p2p))
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -0700112 {
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200113 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)e70dcc82016-08-15 18:33:19 -0700129 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700130 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700131
Neale Rannsb80c5362016-10-08 13:03:40 +0100132 switch (link_type)
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -0700133 {
Neale Rannsb80c5362016-10-08 13:03:40 +0100134#define _(a,b) case VNET_LINK_##a: type = ETHERNET_TYPE_##b; break
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -0700135 _(IP4, IP4);
136 _(IP6, IP6);
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800137 _(MPLS, MPLS);
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -0700138 _(ARP, ARP);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700139#undef _
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -0700140 default:
Neale Rannsb80c5362016-10-08 13:03:40 +0100141 return NULL;
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -0700142 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700143
Neale Rannsb80c5362016-10-08 13:03:40 +0100144 vec_validate (rewrite, n_bytes - 1);
145 h = (ethernet_header_t *) rewrite;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700146 ei = pool_elt_at_index (em->interfaces, hw->hw_instance);
Benoît Ganneb44c77d2020-10-20 16:24:17 +0200147 clib_memcpy (h->src_address, &ei->address, sizeof (h->src_address));
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200148 if (is_p2p)
149 {
150 clib_memcpy (h->dst_address, sub_sw->p2p.client_mac,
151 sizeof (h->dst_address));
152 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700153 else
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200154 {
155 if (dst_address)
156 clib_memcpy (h->dst_address, dst_address, sizeof (h->dst_address));
157 else
Dave Barachb7b92992018-10-17 10:38:51 -0400158 clib_memset (h->dst_address, ~0, sizeof (h->dst_address)); /* broadcast */
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200159 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700160
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200161 if (PREDICT_FALSE (!is_p2p) && sub_sw->sub.eth.flags.one_tag)
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -0700162 {
163 ethernet_vlan_header_t *outer = (void *) (h + 1);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700164
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -0700165 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 Warnickecb9cada2015-12-08 15:45:58 -0700171
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -0700172 }
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200173 else if (PREDICT_FALSE (!is_p2p) && sub_sw->sub.eth.flags.two_tags)
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -0700174 {
175 ethernet_vlan_header_t *outer = (void *) (h + 1);
176 ethernet_vlan_header_t *inner = (void *) (outer + 1);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700177
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -0700178 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 Warnickecb9cada2015-12-08 15:45:58 -0700187
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -0700188 }
189 else
190 {
191 h->type = clib_host_to_net_u16 (type);
192 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700193
Neale Rannsb80c5362016-10-08 13:03:40 +0100194 return (rewrite);
195}
196
197void
198ethernet_update_adjacency (vnet_main_t * vnm, u32 sw_if_index, u32 ai)
199{
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200200 vnet_sw_interface_t *si = vnet_get_sw_interface (vnm, sw_if_index);
Neale Rannscbe25aa2019-09-30 10:53:31 +0000201
Neale Ranns17ff3c12018-07-04 10:24:24 -0700202 if ((si->type == VNET_SW_INTERFACE_TYPE_P2P) ||
203 (si->type == VNET_SW_INTERFACE_TYPE_PIPE))
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200204 {
205 default_update_adjacency (vnm, sw_if_index, ai);
206 }
Neale Rannsb80c5362016-10-08 13:03:40 +0100207 else
208 {
Neale Rannscbe25aa2019-09-30 10:53:31 +0000209 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:
219 ip_neighbor_update (vnm, ai);
220 break;
221 case IP_LOOKUP_NEXT_BCAST:
222 adj_nbr_update_rewrite (ai,
223 ADJ_NBR_REWRITE_FLAG_COMPLETE,
224 ethernet_build_rewrite
225 (vnm,
226 adj->rewrite_header.sw_if_index,
227 adj->ia_link,
228 VNET_REWRITE_FOR_SW_INTERFACE_ADDRESS_BROADCAST));
229 break;
230 case IP_LOOKUP_NEXT_MCAST:
231 {
232 /*
233 * Construct a partial rewrite from the known ethernet mcast dest MAC
234 */
235 u8 *rewrite;
236 u8 offset;
237
238 rewrite = ethernet_build_rewrite
239 (vnm,
240 sw_if_index,
241 adj->ia_link,
242 (adj->ia_nh_proto == FIB_PROTOCOL_IP6 ?
243 ethernet_ip6_mcast_dst_addr () :
244 ethernet_ip4_mcast_dst_addr ()));
245
246 /*
247 * Complete the remaining fields of the adj's rewrite to direct the
248 * complete of the rewrite at switch time by copying in the IP
249 * dst address's bytes.
250 * Ofset is 2 bytes into the destintation address.
251 */
252 offset = vec_len (rewrite) - 2;
253 adj_mcast_update_rewrite (ai, rewrite, offset);
254
255 break;
256 }
257 case IP_LOOKUP_NEXT_DROP:
258 case IP_LOOKUP_NEXT_PUNT:
259 case IP_LOOKUP_NEXT_LOCAL:
260 case IP_LOOKUP_NEXT_REWRITE:
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 Rannsb80c5362016-10-08 13:03:40 +0100268 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700269}
270
Benoît Ganneb44c77d2020-10-20 16:24:17 +0200271static void
272ethernet_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
283static void
284ethernet_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 Ranns3be6b282016-12-20 14:24:01 +0000292static clib_error_t *
Neale Ranns3b81a1e2018-09-06 09:50:26 -0700293ethernet_mac_change (vnet_hw_interface_t * hi,
294 const u8 * old_address, const u8 * mac_address)
Neale Ranns3be6b282016-12-20 14:24:01 +0000295{
296 ethernet_interface_t *ei;
297 ethernet_main_t *em;
298
299 em = &ethernet_main;
300 ei = pool_elt_at_index (em->interfaces, hi->hw_instance);
301
Benoît Ganneb44c77d2020-10-20 16:24:17 +0200302 ethernet_set_mac (hi, ei, mac_address);
Neale Rannscbe25aa2019-09-30 10:53:31 +0000303
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 Ranns3be6b282016-12-20 14:24:01 +0000309
310 return (NULL);
311}
312
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -0700313/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700314VNET_HW_INTERFACE_CLASS (ethernet_hw_interface_class) = {
315 .name = "Ethernet",
316 .format_address = format_ethernet_address,
317 .format_header = format_ethernet_header_with_length,
318 .unformat_hw_address = unformat_ethernet_address,
319 .unformat_header = unformat_ethernet_header,
Neale Rannsb80c5362016-10-08 13:03:40 +0100320 .build_rewrite = ethernet_build_rewrite,
321 .update_adjacency = ethernet_update_adjacency,
Neale Ranns3be6b282016-12-20 14:24:01 +0000322 .mac_addr_change_function = ethernet_mac_change,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700323};
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -0700324/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700325
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -0700326uword
327unformat_ethernet_interface (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700328{
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -0700329 vnet_main_t *vnm = va_arg (*args, vnet_main_t *);
330 u32 *result = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700331 u32 hw_if_index;
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -0700332 ethernet_main_t *em = &ethernet_main;
333 ethernet_interface_t *eif;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700334
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -0700335 if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700336 return 0;
337
338 eif = ethernet_get_interface (em, hw_if_index);
339 if (eif)
340 {
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -0700341 *result = hw_if_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700342 return 1;
343 }
344 return 0;
345}
346
347clib_error_t *
348ethernet_register_interface (vnet_main_t * vnm,
349 u32 dev_class_index,
350 u32 dev_instance,
Neale Ranns192b13f2019-03-15 02:16:20 -0700351 const u8 * address,
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -0700352 u32 * hw_if_index_return,
353 ethernet_flag_change_function_t flag_change)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700354{
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -0700355 ethernet_main_t *em = &ethernet_main;
356 ethernet_interface_t *ei;
357 vnet_hw_interface_t *hi;
358 clib_error_t *error = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700359 u32 hw_if_index;
360
361 pool_get (em->interfaces, ei);
362 ei->flag_change = flag_change;
363
364 hw_if_index = vnet_register_interface
365 (vnm,
366 dev_class_index, dev_instance,
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -0700367 ethernet_hw_interface_class.index, ei - em->interfaces);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700368 *hw_if_index_return = hw_if_index;
369
370 hi = vnet_get_hw_interface (vnm, hw_if_index);
371
372 ethernet_setup_node (vnm->vlib_main, hi->output_node_index);
373
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -0700374 hi->min_packet_bytes = hi->min_supported_packet_bytes =
375 ETHERNET_MIN_PACKET_BYTES;
376 hi->max_packet_bytes = hi->max_supported_packet_bytes =
377 ETHERNET_MAX_PACKET_BYTES;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700378
Dave Barach5fa45252020-02-26 10:27:08 -0500379 /* Default ethernet MTU, 9000 unless set by ethernet_config see below */
380 vnet_sw_interface_set_mtu (vnm, hi->sw_if_index, em->default_mtu);
Damjan Marionfe7d4a22018-04-13 19:43:39 +0200381
Benoît Ganneb44c77d2020-10-20 16:24:17 +0200382 ethernet_set_mac (hi, ei, address);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700383
384 if (error)
385 {
386 pool_put (em->interfaces, ei);
387 return error;
388 }
389 return error;
390}
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -0700391
Ed Warnickecb9cada2015-12-08 15:45:58 -0700392void
393ethernet_delete_interface (vnet_main_t * vnm, u32 hw_if_index)
394{
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -0700395 ethernet_main_t *em = &ethernet_main;
396 ethernet_interface_t *ei;
397 vnet_hw_interface_t *hi;
398 main_intf_t *main_intf;
399 vlan_table_t *vlan_table;
400 u32 idx;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700401
402 hi = vnet_get_hw_interface (vnm, hw_if_index);
403 ei = pool_elt_at_index (em->interfaces, hi->hw_instance);
404
405 /* Delete vlan mapping table for dot1q and dot1ad. */
406 main_intf = vec_elt_at_index (em->main_intfs, hi->hw_if_index);
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -0700407 if (main_intf->dot1q_vlans)
408 {
409 vlan_table = vec_elt_at_index (em->vlan_pool, main_intf->dot1q_vlans);
410 for (idx = 0; idx < ETHERNET_N_VLAN; idx++)
411 {
412 if (vlan_table->vlans[idx].qinqs)
413 {
414 pool_put_index (em->qinq_pool, vlan_table->vlans[idx].qinqs);
John Lod63abff2018-10-04 16:22:21 -0400415 vlan_table->vlans[idx].qinqs = 0;
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -0700416 }
417 }
418 pool_put_index (em->vlan_pool, main_intf->dot1q_vlans);
Steve Shin8a3e5752018-02-20 11:38:34 -0800419 main_intf->dot1q_vlans = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700420 }
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -0700421 if (main_intf->dot1ad_vlans)
422 {
423 vlan_table = vec_elt_at_index (em->vlan_pool, main_intf->dot1ad_vlans);
424 for (idx = 0; idx < ETHERNET_N_VLAN; idx++)
425 {
426 if (vlan_table->vlans[idx].qinqs)
427 {
428 pool_put_index (em->qinq_pool, vlan_table->vlans[idx].qinqs);
John Lod63abff2018-10-04 16:22:21 -0400429 vlan_table->vlans[idx].qinqs = 0;
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -0700430 }
431 }
432 pool_put_index (em->vlan_pool, main_intf->dot1ad_vlans);
Steve Shin8a3e5752018-02-20 11:38:34 -0800433 main_intf->dot1ad_vlans = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700434 }
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -0700435
Ed Warnickecb9cada2015-12-08 15:45:58 -0700436 vnet_delete_hw_interface (vnm, hw_if_index);
437 pool_put (em->interfaces, ei);
438}
439
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -0700440u32
Ed Warnickecb9cada2015-12-08 15:45:58 -0700441ethernet_set_flags (vnet_main_t * vnm, u32 hw_if_index, u32 flags)
442{
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -0700443 ethernet_main_t *em = &ethernet_main;
444 vnet_hw_interface_t *hi;
445 ethernet_interface_t *ei;
John Lo4a302ee2020-05-12 22:34:39 -0400446 u32 opn_flags = flags & ETHERNET_INTERFACE_FLAGS_SET_OPN_MASK;
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -0700447
Ed Warnickecb9cada2015-12-08 15:45:58 -0700448 hi = vnet_get_hw_interface (vnm, hw_if_index);
449
450 ASSERT (hi->hw_class_index == ethernet_hw_interface_class.index);
451
452 ei = pool_elt_at_index (em->interfaces, hi->hw_instance);
John Lo4a302ee2020-05-12 22:34:39 -0400453
454 /* preserve status bits and update last set operation bits */
455 ei->flags = (ei->flags & ETHERNET_INTERFACE_FLAGS_STATUS_MASK) | opn_flags;
456
Ed Warnickecb9cada2015-12-08 15:45:58 -0700457 if (ei->flag_change)
John Lo4a302ee2020-05-12 22:34:39 -0400458 {
459 switch (opn_flags)
460 {
461 case ETHERNET_INTERFACE_FLAG_DEFAULT_L3:
Mohsin Kazmi5b3f5232021-02-10 12:03:53 +0100462 if (hi->caps & VNET_HW_INTERFACE_CAP_SUPPORTS_MAC_FILTER)
John Lo4a302ee2020-05-12 22:34:39 -0400463 {
464 if (ei->flag_change (vnm, hi, opn_flags) != ~0)
465 {
466 ei->flags |= ETHERNET_INTERFACE_FLAG_STATUS_L3;
467 return 0;
468 }
469 ei->flags &= ~ETHERNET_INTERFACE_FLAG_STATUS_L3;
470 return ~0;
471 }
472 /* fall through */
473 case ETHERNET_INTERFACE_FLAG_ACCEPT_ALL:
474 ei->flags &= ~ETHERNET_INTERFACE_FLAG_STATUS_L3;
475 /* fall through */
476 case ETHERNET_INTERFACE_FLAG_MTU:
477 return ei->flag_change (vnm, hi, opn_flags);
478 default:
479 return ~0;
480 }
481 }
482 return ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700483}
484
Dave Barach635ec3b2018-07-13 20:12:45 -0400485/**
486 * Echo packets back to ethernet/l2-input.
Dave Barach635ec3b2018-07-13 20:12:45 -0400487 */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700488static uword
489simulated_ethernet_interface_tx (vlib_main_t * vm,
Dave Barach635ec3b2018-07-13 20:12:45 -0400490 vlib_node_runtime_t *
491 node, vlib_frame_t * frame)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700492{
Dave Barach78451a62018-07-21 09:25:00 -0400493 u32 n_left_from, *from;
494 u32 next_index = 0;
495 u32 n_bytes;
Damjan Marion586afd72017-04-05 19:18:20 +0200496 u32 thread_index = vm->thread_index;
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -0700497 vnet_main_t *vnm = vnet_get_main ();
498 vnet_interface_main_t *im = &vnm->interface_main;
Dave Barach635ec3b2018-07-13 20:12:45 -0400499 l2_input_config_t *config;
Dave Barach78451a62018-07-21 09:25:00 -0400500 vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b;
501 u16 nexts[VLIB_FRAME_SIZE], *next;
502 u32 new_rx_sw_if_index = ~0;
503 u32 new_tx_sw_if_index = ~0;
John Lo405e41b2016-04-23 15:14:12 -0400504
Ed Warnickecb9cada2015-12-08 15:45:58 -0700505 n_left_from = frame->n_vectors;
Damjan Mariona3d59862018-11-10 10:23:00 +0100506 from = vlib_frame_vector_args (frame);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700507
Dave Barach78451a62018-07-21 09:25:00 -0400508 vlib_get_buffers (vm, from, bufs, n_left_from);
509 b = bufs;
510 next = nexts;
Dave Barach635ec3b2018-07-13 20:12:45 -0400511
Dave Barach78451a62018-07-21 09:25:00 -0400512 /* Ordinarily, this is the only config lookup. */
513 config = l2input_intf_config (vnet_buffer (b[0])->sw_if_index[VLIB_TX]);
Neale Ranns47a3d992020-09-29 15:38:51 +0000514 next_index = (l2_input_is_bridge (config) ?
515 VNET_SIMULATED_ETHERNET_TX_NEXT_L2_INPUT :
516 VNET_SIMULATED_ETHERNET_TX_NEXT_ETHERNET_INPUT);
517 new_tx_sw_if_index = l2_input_is_bvi (config) ? L2INPUT_BVI : ~0;
Dave Barach78451a62018-07-21 09:25:00 -0400518 new_rx_sw_if_index = vnet_buffer (b[0])->sw_if_index[VLIB_TX];
Dave Barach635ec3b2018-07-13 20:12:45 -0400519
Dave Barach78451a62018-07-21 09:25:00 -0400520 while (n_left_from >= 4)
521 {
522 u32 sw_if_index0, sw_if_index1, sw_if_index2, sw_if_index3;
523 u32 not_all_match_config;
Dave Barach635ec3b2018-07-13 20:12:45 -0400524
Dave Barach78451a62018-07-21 09:25:00 -0400525 /* Prefetch next iteration. */
526 if (PREDICT_TRUE (n_left_from >= 8))
527 {
528 vlib_prefetch_buffer_header (b[4], STORE);
529 vlib_prefetch_buffer_header (b[5], STORE);
530 vlib_prefetch_buffer_header (b[6], STORE);
531 vlib_prefetch_buffer_header (b[7], STORE);
532 }
Dave Barach635ec3b2018-07-13 20:12:45 -0400533
Dave Barach78451a62018-07-21 09:25:00 -0400534 /* Make sure all pkts were transmitted on the same (loop) intfc */
535 sw_if_index0 = vnet_buffer (b[0])->sw_if_index[VLIB_TX];
536 sw_if_index1 = vnet_buffer (b[1])->sw_if_index[VLIB_TX];
537 sw_if_index2 = vnet_buffer (b[2])->sw_if_index[VLIB_TX];
538 sw_if_index3 = vnet_buffer (b[3])->sw_if_index[VLIB_TX];
Dave Barach635ec3b2018-07-13 20:12:45 -0400539
Dave Barach78451a62018-07-21 09:25:00 -0400540 not_all_match_config = (sw_if_index0 ^ sw_if_index1)
541 ^ (sw_if_index2 ^ sw_if_index3);
542 not_all_match_config += sw_if_index0 ^ new_rx_sw_if_index;
543
544 /* Speed path / expected case: all pkts on the same intfc */
545 if (PREDICT_TRUE (not_all_match_config == 0))
546 {
547 next[0] = next_index;
548 next[1] = next_index;
549 next[2] = next_index;
550 next[3] = next_index;
551 vnet_buffer (b[0])->sw_if_index[VLIB_RX] = new_rx_sw_if_index;
552 vnet_buffer (b[1])->sw_if_index[VLIB_RX] = new_rx_sw_if_index;
553 vnet_buffer (b[2])->sw_if_index[VLIB_RX] = new_rx_sw_if_index;
554 vnet_buffer (b[3])->sw_if_index[VLIB_RX] = new_rx_sw_if_index;
555 vnet_buffer (b[0])->sw_if_index[VLIB_TX] = new_tx_sw_if_index;
556 vnet_buffer (b[1])->sw_if_index[VLIB_TX] = new_tx_sw_if_index;
557 vnet_buffer (b[2])->sw_if_index[VLIB_TX] = new_tx_sw_if_index;
558 vnet_buffer (b[3])->sw_if_index[VLIB_TX] = new_tx_sw_if_index;
559 n_bytes = vlib_buffer_length_in_chain (vm, b[0]);
560 n_bytes += vlib_buffer_length_in_chain (vm, b[1]);
561 n_bytes += vlib_buffer_length_in_chain (vm, b[2]);
562 n_bytes += vlib_buffer_length_in_chain (vm, b[3]);
563
564 if (next_index == VNET_SIMULATED_ETHERNET_TX_NEXT_L2_INPUT)
565 {
566 vnet_update_l2_len (b[0]);
567 vnet_update_l2_len (b[1]);
568 vnet_update_l2_len (b[2]);
569 vnet_update_l2_len (b[3]);
570 }
571
572 /* increment TX interface stat */
573 vlib_increment_combined_counter (im->combined_sw_if_counters +
574 VNET_INTERFACE_COUNTER_TX,
575 thread_index, new_rx_sw_if_index,
576 4 /* pkts */ , n_bytes);
577 b += 4;
578 next += 4;
579 n_left_from -= 4;
580 continue;
581 }
582
583 /*
584 * Slow path: we know that at least one of the pkts
585 * was transmitted on a different sw_if_index, so
586 * check each sw_if_index against the cached data and proceed
587 * accordingly.
588 *
589 * This shouldn't happen, but code can (and does) bypass the
590 * per-interface output node, so deal with it.
591 */
592 if (PREDICT_FALSE (vnet_buffer (b[0])->sw_if_index[VLIB_TX]
593 != new_rx_sw_if_index))
594 {
595 config = l2input_intf_config
596 (vnet_buffer (b[0])->sw_if_index[VLIB_TX]);
Neale Ranns47a3d992020-09-29 15:38:51 +0000597 next_index = (l2_input_is_bridge (config) ?
598 VNET_SIMULATED_ETHERNET_TX_NEXT_L2_INPUT :
599 VNET_SIMULATED_ETHERNET_TX_NEXT_ETHERNET_INPUT);
600 new_tx_sw_if_index = l2_input_is_bvi (config) ? L2INPUT_BVI : ~0;
Dave Barach78451a62018-07-21 09:25:00 -0400601 new_rx_sw_if_index = vnet_buffer (b[0])->sw_if_index[VLIB_TX];
602 }
603 next[0] = next_index;
604 vnet_buffer (b[0])->sw_if_index[VLIB_RX] = new_rx_sw_if_index;
605 vnet_buffer (b[0])->sw_if_index[VLIB_TX] = new_tx_sw_if_index;
606 n_bytes = vlib_buffer_length_in_chain (vm, b[0]);
607 if (next_index == VNET_SIMULATED_ETHERNET_TX_NEXT_L2_INPUT)
608 vnet_update_l2_len (b[0]);
609
610 vlib_increment_combined_counter (im->combined_sw_if_counters +
611 VNET_INTERFACE_COUNTER_TX,
612 thread_index, new_rx_sw_if_index,
613 1 /* pkts */ , n_bytes);
614
615 if (PREDICT_FALSE (vnet_buffer (b[1])->sw_if_index[VLIB_TX]
616 != new_rx_sw_if_index))
617 {
618 config = l2input_intf_config
619 (vnet_buffer (b[1])->sw_if_index[VLIB_TX]);
Neale Ranns47a3d992020-09-29 15:38:51 +0000620 next_index = (l2_input_is_bridge (config) ?
621 VNET_SIMULATED_ETHERNET_TX_NEXT_L2_INPUT :
622 VNET_SIMULATED_ETHERNET_TX_NEXT_ETHERNET_INPUT);
Dave Barach78451a62018-07-21 09:25:00 -0400623 new_rx_sw_if_index = vnet_buffer (b[1])->sw_if_index[VLIB_TX];
Neale Ranns47a3d992020-09-29 15:38:51 +0000624 new_tx_sw_if_index = l2_input_is_bvi (config) ? L2INPUT_BVI : ~0;
Dave Barach78451a62018-07-21 09:25:00 -0400625 }
626 next[1] = next_index;
627 vnet_buffer (b[1])->sw_if_index[VLIB_RX] = new_rx_sw_if_index;
628 vnet_buffer (b[1])->sw_if_index[VLIB_TX] = new_tx_sw_if_index;
629 n_bytes = vlib_buffer_length_in_chain (vm, b[1]);
630 if (next_index == VNET_SIMULATED_ETHERNET_TX_NEXT_L2_INPUT)
631 vnet_update_l2_len (b[1]);
632
633 vlib_increment_combined_counter (im->combined_sw_if_counters +
634 VNET_INTERFACE_COUNTER_TX,
635 thread_index, new_rx_sw_if_index,
636 1 /* pkts */ , n_bytes);
637
638 if (PREDICT_FALSE (vnet_buffer (b[2])->sw_if_index[VLIB_TX]
639 != new_rx_sw_if_index))
640 {
641 config = l2input_intf_config
642 (vnet_buffer (b[2])->sw_if_index[VLIB_TX]);
Neale Ranns47a3d992020-09-29 15:38:51 +0000643 next_index = (l2_input_is_bridge (config) ?
644 VNET_SIMULATED_ETHERNET_TX_NEXT_L2_INPUT :
645 VNET_SIMULATED_ETHERNET_TX_NEXT_ETHERNET_INPUT);
Dave Barach78451a62018-07-21 09:25:00 -0400646 new_rx_sw_if_index = vnet_buffer (b[2])->sw_if_index[VLIB_TX];
Neale Ranns47a3d992020-09-29 15:38:51 +0000647 new_tx_sw_if_index = l2_input_is_bvi (config) ? L2INPUT_BVI : ~0;
Dave Barach78451a62018-07-21 09:25:00 -0400648 }
649 next[2] = next_index;
650 vnet_buffer (b[2])->sw_if_index[VLIB_RX] = new_rx_sw_if_index;
651 vnet_buffer (b[2])->sw_if_index[VLIB_TX] = new_tx_sw_if_index;
652 n_bytes = vlib_buffer_length_in_chain (vm, b[2]);
653 if (next_index == VNET_SIMULATED_ETHERNET_TX_NEXT_L2_INPUT)
654 vnet_update_l2_len (b[2]);
655
656 vlib_increment_combined_counter (im->combined_sw_if_counters +
657 VNET_INTERFACE_COUNTER_TX,
658 thread_index, new_rx_sw_if_index,
659 1 /* pkts */ , n_bytes);
660
661 if (PREDICT_FALSE (vnet_buffer (b[3])->sw_if_index[VLIB_TX]
662 != new_rx_sw_if_index))
663 {
664 config = l2input_intf_config
665 (vnet_buffer (b[3])->sw_if_index[VLIB_TX]);
Neale Ranns47a3d992020-09-29 15:38:51 +0000666 next_index = (l2_input_is_bridge (config) ?
667 VNET_SIMULATED_ETHERNET_TX_NEXT_L2_INPUT :
668 VNET_SIMULATED_ETHERNET_TX_NEXT_ETHERNET_INPUT);
Dave Barach78451a62018-07-21 09:25:00 -0400669 new_rx_sw_if_index = vnet_buffer (b[3])->sw_if_index[VLIB_TX];
Neale Ranns47a3d992020-09-29 15:38:51 +0000670 new_tx_sw_if_index = l2_input_is_bvi (config) ? L2INPUT_BVI : ~0;
Dave Barach78451a62018-07-21 09:25:00 -0400671 }
672 next[3] = next_index;
673 vnet_buffer (b[3])->sw_if_index[VLIB_RX] = new_rx_sw_if_index;
674 vnet_buffer (b[3])->sw_if_index[VLIB_TX] = new_tx_sw_if_index;
675 n_bytes = vlib_buffer_length_in_chain (vm, b[3]);
676 if (next_index == VNET_SIMULATED_ETHERNET_TX_NEXT_L2_INPUT)
677 vnet_update_l2_len (b[3]);
678
679 vlib_increment_combined_counter (im->combined_sw_if_counters +
680 VNET_INTERFACE_COUNTER_TX,
681 thread_index, new_rx_sw_if_index,
682 1 /* pkts */ , n_bytes);
683 b += 4;
684 next += 4;
685 n_left_from -= 4;
686 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700687 while (n_left_from > 0)
688 {
Dave Barach78451a62018-07-21 09:25:00 -0400689 if (PREDICT_FALSE (vnet_buffer (b[0])->sw_if_index[VLIB_TX]
690 != new_rx_sw_if_index))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700691 {
Dave Barach78451a62018-07-21 09:25:00 -0400692 config = l2input_intf_config
693 (vnet_buffer (b[0])->sw_if_index[VLIB_TX]);
Neale Ranns47a3d992020-09-29 15:38:51 +0000694 next_index = (l2_input_is_bridge (config) ?
695 VNET_SIMULATED_ETHERNET_TX_NEXT_L2_INPUT :
696 VNET_SIMULATED_ETHERNET_TX_NEXT_ETHERNET_INPUT);
697 new_tx_sw_if_index = l2_input_is_bvi (config) ? L2INPUT_BVI : ~0;
Dave Barach78451a62018-07-21 09:25:00 -0400698 new_rx_sw_if_index = vnet_buffer (b[0])->sw_if_index[VLIB_TX];
Ed Warnickecb9cada2015-12-08 15:45:58 -0700699 }
Dave Barach78451a62018-07-21 09:25:00 -0400700 next[0] = next_index;
701 vnet_buffer (b[0])->sw_if_index[VLIB_RX] = new_rx_sw_if_index;
702 vnet_buffer (b[0])->sw_if_index[VLIB_TX] = new_tx_sw_if_index;
703 n_bytes = vlib_buffer_length_in_chain (vm, b[0]);
704 if (next_index == VNET_SIMULATED_ETHERNET_TX_NEXT_L2_INPUT)
705 vnet_update_l2_len (b[0]);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700706
Dave Barach78451a62018-07-21 09:25:00 -0400707 vlib_increment_combined_counter (im->combined_sw_if_counters +
708 VNET_INTERFACE_COUNTER_TX,
709 thread_index, new_rx_sw_if_index,
710 1 /* pkts */ , n_bytes);
711 b += 1;
712 next += 1;
713 n_left_from -= 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700714 }
715
Dave Barach78451a62018-07-21 09:25:00 -0400716 vlib_buffer_enqueue_to_next (vm, node, from, nexts, frame->n_vectors);
Dave Barach635ec3b2018-07-13 20:12:45 -0400717
718 return frame->n_vectors;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700719}
720
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -0700721static u8 *
722format_simulated_ethernet_name (u8 * s, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700723{
724 u32 dev_instance = va_arg (*args, u32);
725 return format (s, "loop%d", dev_instance);
726}
727
Pierre Pfisterf00f91a2016-03-09 18:22:32 +0000728static clib_error_t *
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -0700729simulated_ethernet_admin_up_down (vnet_main_t * vnm, u32 hw_if_index,
730 u32 flags)
Pierre Pfisterf00f91a2016-03-09 18:22:32 +0000731{
732 u32 hw_flags = (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -0700733 VNET_HW_INTERFACE_FLAG_LINK_UP : 0;
Pierre Pfisterf00f91a2016-03-09 18:22:32 +0000734 vnet_hw_interface_set_flags (vnm, hw_if_index, hw_flags);
735 return 0;
736}
737
Neale Ranns3b81a1e2018-09-06 09:50:26 -0700738static clib_error_t *
739simulated_ethernet_mac_change (vnet_hw_interface_t * hi,
740 const u8 * old_address, const u8 * mac_address)
741{
742 l2input_interface_mac_change (hi->sw_if_index, old_address, mac_address);
743
744 return (NULL);
745}
746
747
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -0700748/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700749VNET_DEVICE_CLASS (ethernet_simulated_device_class) = {
750 .name = "Loopback",
751 .format_device_name = format_simulated_ethernet_name,
752 .tx_function = simulated_ethernet_interface_tx,
Pierre Pfisterf00f91a2016-03-09 18:22:32 +0000753 .admin_up_down_function = simulated_ethernet_admin_up_down,
Neale Ranns3b81a1e2018-09-06 09:50:26 -0700754 .mac_addr_change_function = simulated_ethernet_mac_change,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700755};
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -0700756/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700757
Jon Loeligerc83c3b72017-02-23 13:57:35 -0600758/*
759 * Maintain a bitmap of allocated loopback instance numbers.
760 */
761#define LOOPBACK_MAX_INSTANCE (16 * 1024)
762
763static u32
764loopback_instance_alloc (u8 is_specified, u32 want)
765{
766 ethernet_main_t *em = &ethernet_main;
767
768 /*
769 * Check for dynamically allocaetd instance number.
770 */
771 if (!is_specified)
772 {
773 u32 bit;
774
775 bit = clib_bitmap_first_clear (em->bm_loopback_instances);
776 if (bit >= LOOPBACK_MAX_INSTANCE)
777 {
778 return ~0;
779 }
780 em->bm_loopback_instances = clib_bitmap_set (em->bm_loopback_instances,
781 bit, 1);
782 return bit;
783 }
784
785 /*
786 * In range?
787 */
788 if (want >= LOOPBACK_MAX_INSTANCE)
789 {
790 return ~0;
791 }
792
793 /*
794 * Already in use?
795 */
796 if (clib_bitmap_get (em->bm_loopback_instances, want))
797 {
798 return ~0;
799 }
800
801 /*
802 * Grant allocation request.
803 */
804 em->bm_loopback_instances = clib_bitmap_set (em->bm_loopback_instances,
805 want, 1);
806
807 return want;
808}
809
810static int
811loopback_instance_free (u32 instance)
812{
813 ethernet_main_t *em = &ethernet_main;
814
815 if (instance >= LOOPBACK_MAX_INSTANCE)
816 {
817 return -1;
818 }
819
820 if (clib_bitmap_get (em->bm_loopback_instances, instance) == 0)
821 {
822 return -1;
823 }
824
825 em->bm_loopback_instances = clib_bitmap_set (em->bm_loopback_instances,
826 instance, 0);
827 return 0;
828}
829
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -0700830int
Jon Loeligerc83c3b72017-02-23 13:57:35 -0600831vnet_create_loopback_interface (u32 * sw_if_indexp, u8 * mac_address,
832 u8 is_specified, u32 user_instance)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700833{
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -0700834 vnet_main_t *vnm = vnet_get_main ();
835 vlib_main_t *vm = vlib_get_main ();
836 clib_error_t *error;
Jon Loeligerc83c3b72017-02-23 13:57:35 -0600837 u32 instance;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700838 u8 address[6];
839 u32 hw_if_index;
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -0700840 vnet_hw_interface_t *hw_if;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700841 u32 slot;
842 int rv = 0;
843
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -0700844 ASSERT (sw_if_indexp);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700845
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -0700846 *sw_if_indexp = (u32) ~ 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700847
Dave Barachb7b92992018-10-17 10:38:51 -0400848 clib_memset (address, 0, sizeof (address));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700849
850 /*
Jon Loeligerc83c3b72017-02-23 13:57:35 -0600851 * Allocate a loopback instance. Either select on dynamically
852 * or try to use the desired user_instance number.
853 */
854 instance = loopback_instance_alloc (is_specified, user_instance);
855 if (instance == ~0)
856 {
857 return VNET_API_ERROR_INVALID_REGISTRATION;
858 }
859
860 /*
Ed Warnickecb9cada2015-12-08 15:45:58 -0700861 * Default MAC address (dead:0000:0000 + instance) is allocated
862 * if zero mac_address is configured. Otherwise, user-configurable MAC
863 * address is programmed on the loopback interface.
864 */
865 if (memcmp (address, mac_address, sizeof (address)))
Damjan Marionf1213b82016-03-13 02:22:06 +0100866 clib_memcpy (address, mac_address, sizeof (address));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700867 else
868 {
869 address[0] = 0xde;
870 address[1] = 0xad;
871 address[5] = instance;
872 }
873
874 error = ethernet_register_interface
875 (vnm,
Jon Loeligerc83c3b72017-02-23 13:57:35 -0600876 ethernet_simulated_device_class.index, instance, address, &hw_if_index,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700877 /* flag change */ 0);
878
879 if (error)
880 {
881 rv = VNET_API_ERROR_INVALID_REGISTRATION;
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -0700882 clib_error_report (error);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700883 return rv;
884 }
885
886 hw_if = vnet_get_hw_interface (vnm, hw_if_index);
887 slot = vlib_node_add_named_next_with_slot
888 (vm, hw_if->tx_node_index,
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -0700889 "ethernet-input", VNET_SIMULATED_ETHERNET_TX_NEXT_ETHERNET_INPUT);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700890 ASSERT (slot == VNET_SIMULATED_ETHERNET_TX_NEXT_ETHERNET_INPUT);
891
Dave Barach635ec3b2018-07-13 20:12:45 -0400892 slot = vlib_node_add_named_next_with_slot
893 (vm, hw_if->tx_node_index,
894 "l2-input", VNET_SIMULATED_ETHERNET_TX_NEXT_L2_INPUT);
895 ASSERT (slot == VNET_SIMULATED_ETHERNET_TX_NEXT_L2_INPUT);
896
Ed Warnickecb9cada2015-12-08 15:45:58 -0700897 {
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -0700898 vnet_sw_interface_t *si = vnet_get_hw_sw_interface (vnm, hw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700899 *sw_if_indexp = si->sw_if_index;
Neale Ranns87dad112018-04-09 01:53:01 -0700900
901 /* By default don't flood to loopbacks, as packets just keep
902 * coming back ... If this loopback becomes a BVI, we'll change it */
903 si->flood_class = VNET_FLOOD_CLASS_NO_FLOOD;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700904 }
905
906 return 0;
907}
908
909static clib_error_t *
910create_simulated_ethernet_interfaces (vlib_main_t * vm,
911 unformat_input_t * input,
912 vlib_cli_command_t * cmd)
913{
914 int rv;
915 u32 sw_if_index;
916 u8 mac_address[6];
Jon Loeligerc83c3b72017-02-23 13:57:35 -0600917 u8 is_specified = 0;
918 u32 user_instance = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700919
Dave Barachb7b92992018-10-17 10:38:51 -0400920 clib_memset (mac_address, 0, sizeof (mac_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700921
922 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
923 {
924 if (unformat (input, "mac %U", unformat_ethernet_address, mac_address))
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -0700925 ;
Jon Loeligerc83c3b72017-02-23 13:57:35 -0600926 if (unformat (input, "instance %d", &user_instance))
927 is_specified = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700928 else
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -0700929 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700930 }
931
Jon Loeligerc83c3b72017-02-23 13:57:35 -0600932 rv = vnet_create_loopback_interface (&sw_if_index, mac_address,
933 is_specified, user_instance);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700934
935 if (rv)
936 return clib_error_return (0, "vnet_create_loopback_interface failed");
937
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -0700938 vlib_cli_output (vm, "%U\n", format_vnet_sw_if_index_name, vnet_get_main (),
939 sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700940 return 0;
941}
942
Billy McFall2d085d92016-09-13 21:47:55 -0400943/*?
944 * Create a loopback interface. Optionally, a MAC Address can be
945 * provided. If not provided, de:ad:00:00:00:<loopId> will be used.
946 *
947 * @cliexpar
948 * The following two command syntaxes are equivalent:
Jon Loeligerc83c3b72017-02-23 13:57:35 -0600949 * @cliexcmd{loopback create-interface [mac <mac-addr>] [instance <instance>]}
950 * @cliexcmd{create loopback interface [mac <mac-addr>] [instance <instance>]}
Billy McFall2d085d92016-09-13 21:47:55 -0400951 * Example of how to create a loopback interface:
952 * @cliexcmd{loopback create-interface}
953?*/
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -0700954/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700955VLIB_CLI_COMMAND (create_simulated_ethernet_interface_command, static) = {
956 .path = "loopback create-interface",
Jon Loeligerc83c3b72017-02-23 13:57:35 -0600957 .short_help = "loopback create-interface [mac <mac-addr>] [instance <instance>]",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700958 .function = create_simulated_ethernet_interfaces,
959};
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -0700960/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700961
Billy McFall2d085d92016-09-13 21:47:55 -0400962/*?
963 * Create a loopback interface. Optionally, a MAC Address can be
964 * provided. If not provided, de:ad:00:00:00:<loopId> will be used.
965 *
966 * @cliexpar
967 * The following two command syntaxes are equivalent:
Jon Loeligerc83c3b72017-02-23 13:57:35 -0600968 * @cliexcmd{loopback create-interface [mac <mac-addr>] [instance <instance>]}
969 * @cliexcmd{create loopback interface [mac <mac-addr>] [instance <instance>]}
Billy McFall2d085d92016-09-13 21:47:55 -0400970 * Example of how to create a loopback interface:
971 * @cliexcmd{create loopback interface}
972?*/
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -0700973/* *INDENT-OFF* */
Alpesh Patel370a24e2016-04-08 07:27:37 -0700974VLIB_CLI_COMMAND (create_loopback_interface_command, static) = {
975 .path = "create loopback interface",
Jon Loeligerc83c3b72017-02-23 13:57:35 -0600976 .short_help = "create loopback interface [mac <mac-addr>] [instance <instance>]",
Alpesh Patel370a24e2016-04-08 07:27:37 -0700977 .function = create_simulated_ethernet_interfaces,
978};
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -0700979/* *INDENT-ON* */
Alpesh Patel370a24e2016-04-08 07:27:37 -0700980
Ed Warnickecb9cada2015-12-08 15:45:58 -0700981ethernet_interface_t *
982ethernet_get_interface (ethernet_main_t * em, u32 hw_if_index)
983{
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -0700984 vnet_hw_interface_t *i =
985 vnet_get_hw_interface (vnet_get_main (), hw_if_index);
986 return (i->hw_class_index ==
987 ethernet_hw_interface_class.
988 index ? pool_elt_at_index (em->interfaces, i->hw_instance) : 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700989}
990
Matthew G Smithd459bf32019-09-04 15:01:04 -0500991mac_address_t *
992ethernet_interface_add_del_address (ethernet_main_t * em,
993 u32 hw_if_index, const u8 * address,
994 u8 is_add)
995{
996 ethernet_interface_t *ei = ethernet_get_interface (em, hw_if_index);
Benoît Ganneb44c77d2020-10-20 16:24:17 +0200997 ethernet_interface_address_t *if_addr = 0;
998 int found = 0;
Matthew G Smithd459bf32019-09-04 15:01:04 -0500999
1000 /* return if there is not an ethernet interface for this hw interface */
1001 if (!ei)
1002 return 0;
1003
1004 /* determine whether the address is configured on the interface */
1005 vec_foreach (if_addr, ei->secondary_addrs)
1006 {
Benoît Ganneb44c77d2020-10-20 16:24:17 +02001007 if (ethernet_mac_address_equal (if_addr->mac.bytes, address))
1008 {
1009 found = 1;
1010 break;
1011 }
Matthew G Smithd459bf32019-09-04 15:01:04 -05001012 }
1013
Benoît Ganneb44c77d2020-10-20 16:24:17 +02001014 if (is_add)
Matthew G Smithd459bf32019-09-04 15:01:04 -05001015 {
Benoît Ganneb44c77d2020-10-20 16:24:17 +02001016 if (!found)
Matthew G Smithd459bf32019-09-04 15:01:04 -05001017 {
Benoît Ganneb44c77d2020-10-20 16:24:17 +02001018 /* address not found yet: add it */
Matthew G Smithd459bf32019-09-04 15:01:04 -05001019 vec_add2 (ei->secondary_addrs, if_addr, 1);
Benoît Ganneb44c77d2020-10-20 16:24:17 +02001020 ethernet_interface_address_copy (if_addr, address);
Matthew G Smithd459bf32019-09-04 15:01:04 -05001021 }
Benoît Ganneb44c77d2020-10-20 16:24:17 +02001022 return &if_addr->mac;
Matthew G Smithd459bf32019-09-04 15:01:04 -05001023 }
1024
Benoît Ganneb44c77d2020-10-20 16:24:17 +02001025 /* delete case */
1026 if (found)
1027 vec_delete (ei->secondary_addrs, 1, if_addr - ei->secondary_addrs);
1028
1029 return 0;
Matthew G Smithd459bf32019-09-04 15:01:04 -05001030}
1031
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -07001032int
1033vnet_delete_loopback_interface (u32 sw_if_index)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001034{
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -07001035 vnet_main_t *vnm = vnet_get_main ();
Ed Warnickecb9cada2015-12-08 15:45:58 -07001036
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -07001037 if (pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index))
Ed Warnickecb9cada2015-12-08 15:45:58 -07001038 return VNET_API_ERROR_INVALID_SW_IF_INDEX;
1039
Eyal Barib52c0342018-07-16 19:18:56 +03001040 vnet_hw_interface_t *hw = vnet_get_sup_hw_interface (vnm, sw_if_index);
1041 if (hw == 0 || hw->dev_class_index != ethernet_simulated_device_class.index)
1042 return VNET_API_ERROR_INVALID_SW_IF_INDEX;
Jon Loeligerc83c3b72017-02-23 13:57:35 -06001043
Eyal Barib52c0342018-07-16 19:18:56 +03001044 if (loopback_instance_free (hw->dev_instance) < 0)
1045 return VNET_API_ERROR_INVALID_SW_IF_INDEX;
Jon Loeligerc83c3b72017-02-23 13:57:35 -06001046
Eyal Barib52c0342018-07-16 19:18:56 +03001047 ethernet_delete_interface (vnm, hw->hw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001048
1049 return 0;
1050}
1051
Pavel Kotucekd85590a2016-08-26 13:35:40 +02001052int
Neale Ranns669f4e32019-10-28 07:56:15 -07001053vnet_create_sub_interface (u32 sw_if_index, u32 id,
1054 u32 flags, u16 inner_vlan_id, u16 outer_vlan_id,
1055 u32 * sub_sw_if_index)
1056{
1057 vnet_main_t *vnm = vnet_get_main ();
1058 vnet_interface_main_t *im = &vnm->interface_main;
1059 vnet_hw_interface_t *hi;
1060 u64 sup_and_sub_key = ((u64) (sw_if_index) << 32) | (u64) id;
1061 vnet_sw_interface_t template;
1062 uword *p;
1063 u64 *kp;
1064
1065 hi = vnet_get_sup_hw_interface (vnm, sw_if_index);
1066
1067 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1068 if (p)
1069 {
1070 return (VNET_API_ERROR_VLAN_ALREADY_EXISTS);
1071 }
1072
1073 clib_memset (&template, 0, sizeof (template));
1074 template.type = VNET_SW_INTERFACE_TYPE_SUB;
1075 template.flood_class = VNET_FLOOD_CLASS_NORMAL;
1076 template.sup_sw_if_index = sw_if_index;
1077 template.sub.id = id;
1078 template.sub.eth.raw_flags = flags;
1079 template.sub.eth.outer_vlan_id = outer_vlan_id;
1080 template.sub.eth.inner_vlan_id = inner_vlan_id;
1081
1082 if (vnet_create_sw_interface (vnm, &template, sub_sw_if_index))
1083 return (VNET_API_ERROR_UNSPECIFIED);
1084
1085 kp = clib_mem_alloc (sizeof (*kp));
1086 *kp = sup_and_sub_key;
1087
1088 hash_set (hi->sub_interface_sw_if_index_by_id, id, *sub_sw_if_index);
1089 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, *sub_sw_if_index);
1090
1091 return (0);
1092}
1093
1094int
Pavel Kotucekd85590a2016-08-26 13:35:40 +02001095vnet_delete_sub_interface (u32 sw_if_index)
1096{
1097 vnet_main_t *vnm = vnet_get_main ();
Steve Shina36f08c2018-03-07 13:29:29 -08001098 vnet_sw_interface_t *si;
Pavel Kotucekd85590a2016-08-26 13:35:40 +02001099 int rv = 0;
1100
1101 if (pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index))
1102 return VNET_API_ERROR_INVALID_SW_IF_INDEX;
1103
Steve Shina36f08c2018-03-07 13:29:29 -08001104 si = vnet_get_sw_interface (vnm, sw_if_index);
Pavel Kotucek15ac81c2017-06-20 14:00:26 +02001105 if (si->type == VNET_SW_INTERFACE_TYPE_SUB ||
Neale Ranns17ff3c12018-07-04 10:24:24 -07001106 si->type == VNET_SW_INTERFACE_TYPE_PIPE ||
Pavel Kotucek15ac81c2017-06-20 14:00:26 +02001107 si->type == VNET_SW_INTERFACE_TYPE_P2P)
Pavel Kotucekd85590a2016-08-26 13:35:40 +02001108 {
John Lo5957a142018-01-18 12:44:50 -05001109 vnet_interface_main_t *im = &vnm->interface_main;
1110 vnet_hw_interface_t *hi = vnet_get_sup_hw_interface (vnm, sw_if_index);
Pavel Kotucekd85590a2016-08-26 13:35:40 +02001111 u64 sup_and_sub_key =
1112 ((u64) (si->sup_sw_if_index) << 32) | (u64) si->sub.id;
John Lo5957a142018-01-18 12:44:50 -05001113 hash_unset_mem_free (&im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
1114 hash_unset (hi->sub_interface_sw_if_index_by_id, si->sub.id);
Pavel Kotucekd85590a2016-08-26 13:35:40 +02001115 vnet_delete_sw_interface (vnm, sw_if_index);
1116 }
1117 else
John Lo5957a142018-01-18 12:44:50 -05001118 rv = VNET_API_ERROR_INVALID_SUB_SW_IF_INDEX;
1119
Pavel Kotucekd85590a2016-08-26 13:35:40 +02001120 return rv;
1121}
1122
Ed Warnickecb9cada2015-12-08 15:45:58 -07001123static clib_error_t *
1124delete_simulated_ethernet_interfaces (vlib_main_t * vm,
1125 unformat_input_t * input,
1126 vlib_cli_command_t * cmd)
1127{
1128 int rv;
1129 u32 sw_if_index = ~0;
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -07001130 vnet_main_t *vnm = vnet_get_main ();
Ed Warnickecb9cada2015-12-08 15:45:58 -07001131
1132 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1133 {
1134 if (unformat (input, "intfc %U",
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -07001135 unformat_vnet_sw_interface, vnm, &sw_if_index))
1136 ;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001137 else
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -07001138 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001139 }
1140
1141 if (sw_if_index == ~0)
1142 return clib_error_return (0, "interface not specified");
1143
1144 rv = vnet_delete_loopback_interface (sw_if_index);
1145
1146 if (rv)
1147 return clib_error_return (0, "vnet_delete_loopback_interface failed");
1148
1149 return 0;
1150}
1151
Pavel Kotucekd85590a2016-08-26 13:35:40 +02001152static clib_error_t *
1153delete_sub_interface (vlib_main_t * vm,
1154 unformat_input_t * input, vlib_cli_command_t * cmd)
1155{
1156 int rv = 0;
1157 u32 sw_if_index = ~0;
1158 vnet_main_t *vnm = vnet_get_main ();
1159
1160 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1161 {
1162 if (unformat
1163 (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
1164 ;
1165 else
1166 break;
1167 }
1168 if (sw_if_index == ~0)
1169 return clib_error_return (0, "interface doesn't exist");
1170
1171 if (pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index))
1172 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1173 else
1174 rv = vnet_delete_sub_interface (sw_if_index);
1175 if (rv)
1176 return clib_error_return (0, "delete_subinterface_interface failed");
1177 return 0;
1178}
1179
Billy McFall2d085d92016-09-13 21:47:55 -04001180/*?
1181 * Delete a loopback interface.
1182 *
1183 * @cliexpar
1184 * The following two command syntaxes are equivalent:
1185 * @cliexcmd{loopback delete-interface intfc <interface>}
1186 * @cliexcmd{delete loopback interface intfc <interface>}
1187 * Example of how to delete a loopback interface:
1188 * @cliexcmd{loopback delete-interface intfc loop0}
1189?*/
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -07001190/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001191VLIB_CLI_COMMAND (delete_simulated_ethernet_interface_command, static) = {
1192 .path = "loopback delete-interface",
Billy McFall2d085d92016-09-13 21:47:55 -04001193 .short_help = "loopback delete-interface intfc <interface>",
Ed Warnickecb9cada2015-12-08 15:45:58 -07001194 .function = delete_simulated_ethernet_interfaces,
1195};
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -07001196/* *INDENT-ON* */
Alpesh S. Patel633951c2016-04-12 09:58:56 -07001197
Billy McFall2d085d92016-09-13 21:47:55 -04001198/*?
1199 * Delete a loopback interface.
1200 *
1201 * @cliexpar
1202 * The following two command syntaxes are equivalent:
1203 * @cliexcmd{loopback delete-interface intfc <interface>}
1204 * @cliexcmd{delete loopback interface intfc <interface>}
1205 * Example of how to delete a loopback interface:
1206 * @cliexcmd{delete loopback interface intfc loop0}
1207?*/
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -07001208/* *INDENT-OFF* */
Alpesh S. Patel633951c2016-04-12 09:58:56 -07001209VLIB_CLI_COMMAND (delete_loopback_interface_command, static) = {
1210 .path = "delete loopback interface",
1211 .short_help = "delete loopback interface intfc <interface>",
1212 .function = delete_simulated_ethernet_interfaces,
1213};
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -07001214/* *INDENT-ON* */
1215
Billy McFall2d085d92016-09-13 21:47:55 -04001216/*?
1217 * Delete a sub-interface.
1218 *
1219 * @cliexpar
1220 * Example of how to delete a sub-interface:
1221 * @cliexcmd{delete sub-interface GigabitEthernet0/8/0.200}
1222?*/
Pavel Kotucekd85590a2016-08-26 13:35:40 +02001223/* *INDENT-OFF* */
1224VLIB_CLI_COMMAND (delete_sub_interface_command, static) = {
1225 .path = "delete sub-interface",
1226 .short_help = "delete sub-interface <interface>",
1227 .function = delete_sub_interface,
1228};
1229/* *INDENT-ON* */
1230
Paul Vinciguerra491741a2020-03-02 16:10:54 -05001231/* ethernet { ... } configuration. */
1232/*?
1233 *
1234 * @cfgcmd{default-mtu &lt;n&gt;}
1235 * Specify the default mtu in the range of 64-9000. The default is 9000 bytes.
1236 *
1237 */
Dave Barach5fa45252020-02-26 10:27:08 -05001238static clib_error_t *
1239ethernet_config (vlib_main_t * vm, unformat_input_t * input)
1240{
1241 ethernet_main_t *em = &ethernet_main;
1242
1243 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1244 {
1245 if (unformat (input, "default-mtu %u", &em->default_mtu))
1246 {
1247 if (em->default_mtu < 64 || em->default_mtu > 9000)
1248 return clib_error_return (0, "default MTU must be >=64, <=9000");
1249 }
1250 else
1251 {
1252 return clib_error_return (0, "unknown input '%U'",
1253 format_unformat_error, input);
1254 }
1255 }
1256 return 0;
1257}
1258
1259VLIB_CONFIG_FUNCTION (ethernet_config, "ethernet");
1260
Keith Burns (alagalah)e70dcc82016-08-15 18:33:19 -07001261/*
1262 * fd.io coding-style-patch-verification: ON
1263 *
1264 * Local Variables:
1265 * eval: (c-set-style "gnu")
1266 * End:
1267 */