blob: f60cd41bb39ad97afb1f13a12c88792d3c8279b5 [file] [log] [blame]
Matus Fabianf468e232016-12-02 06:00:53 -08001/*
2 *------------------------------------------------------------------
3 * l2_api.c - layer 2 forwarding api
4 *
5 * Copyright (c) 2016 Cisco and/or its affiliates.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at:
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *------------------------------------------------------------------
18 */
19
20#include <vnet/vnet.h>
21#include <vlibmemory/api.h>
22
23#include <vnet/interface.h>
24#include <vnet/api_errno.h>
25#include <vnet/l2/l2_input.h>
Pavel Kotucek0f971d82017-01-03 10:48:54 +010026#include <vnet/l2/l2_fib.h>
Pavel Kotucekadec5872017-01-25 08:50:53 +010027#include <vnet/l2/l2_vtr.h>
John Lo8d00fff2017-08-03 00:35:36 -040028#include <vnet/l2/l2_learn.h>
Neale Rannsb4743802018-09-05 09:13:57 -070029#include <vnet/l2/l2_bd.h>
Neale Ranns192b13f2019-03-15 02:16:20 -070030#include <vnet/l2/l2_bvi.h>
Neale Ranns4d5b9172018-10-24 02:57:49 -070031#include <vnet/ip/ip_types_api.h>
32#include <vnet/ethernet/ethernet_types_api.h>
Matus Fabianf468e232016-12-02 06:00:53 -080033
34#include <vnet/vnet_msg_enum.h>
35
36#define vl_typedefs /* define message structures */
37#include <vnet/vnet_all_api_h.h>
38#undef vl_typedefs
39
40#define vl_endianfun /* define message structures */
41#include <vnet/vnet_all_api_h.h>
42#undef vl_endianfun
43
Ole Troan01384fe2017-05-12 11:55:35 +020044#define vl_api_bridge_domain_details_t_endian vl_noop_handler
45#define vl_api_bridge_domain_details_t_print vl_noop_handler
46
Matus Fabianf468e232016-12-02 06:00:53 -080047/* instantiate all the print functions we know about */
48#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
49#define vl_printfun
50#include <vnet/vnet_all_api_h.h>
51#undef vl_printfun
52
53#include <vlibapi/api_helper_macros.h>
54
Pavel Kotucek0f971d82017-01-03 10:48:54 +010055#define foreach_vpe_api_msg \
56_(L2_XCONNECT_DUMP, l2_xconnect_dump) \
57_(L2_FIB_CLEAR_TABLE, l2_fib_clear_table) \
58_(L2_FIB_TABLE_DUMP, l2_fib_table_dump) \
Eyal Bari7537e712017-04-27 14:07:55 +030059_(L2FIB_FLUSH_ALL, l2fib_flush_all) \
Eyal Barif24991c2017-04-05 05:33:21 +030060_(L2FIB_FLUSH_INT, l2fib_flush_int) \
61_(L2FIB_FLUSH_BD, l2fib_flush_bd) \
Pavel Kotucek0f971d82017-01-03 10:48:54 +010062_(L2FIB_ADD_DEL, l2fib_add_del) \
John Lo8d00fff2017-08-03 00:35:36 -040063_(WANT_L2_MACS_EVENTS, want_l2_macs_events) \
Pavel Kotucek0f971d82017-01-03 10:48:54 +010064_(L2_FLAGS, l2_flags) \
Neale Rannsb8d44812017-11-10 06:53:54 -080065_(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect) \
66_(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge) \
67_(L2_PATCH_ADD_DEL, l2_patch_add_del) \
68_(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter) \
69_(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del) \
John Loe26c81f2019-01-07 15:16:33 -050070_(BD_IP_MAC_FLUSH, bd_ip_mac_flush) \
Mohsin Kazmi5d82d2f2018-08-13 19:17:54 +020071_(BD_IP_MAC_DUMP, bd_ip_mac_dump) \
Neale Rannsb8d44812017-11-10 06:53:54 -080072_(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del) \
73_(BRIDGE_DOMAIN_DUMP, bridge_domain_dump) \
74_(BRIDGE_FLAGS, bridge_flags) \
Pavel Kotucekadec5872017-01-25 08:50:53 +010075_(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite) \
Neale Rannsb8d44812017-11-10 06:53:54 -080076_(L2_INTERFACE_PBB_TAG_REWRITE, l2_interface_pbb_tag_rewrite) \
77_(BRIDGE_DOMAIN_SET_MAC_AGE, bridge_domain_set_mac_age) \
Neale Ranns192b13f2019-03-15 02:16:20 -070078_(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath) \
79_(BVI_CREATE, bvi_create) \
80_(BVI_DELETE, bvi_delete)
Matus Fabianf468e232016-12-02 06:00:53 -080081
82static void
Florin Coras6c4dae22018-01-09 06:39:23 -080083send_l2_xconnect_details (vl_api_registration_t * reg, u32 context,
Matus Fabianf468e232016-12-02 06:00:53 -080084 u32 rx_sw_if_index, u32 tx_sw_if_index)
85{
86 vl_api_l2_xconnect_details_t *mp;
87
88 mp = vl_msg_api_alloc (sizeof (*mp));
Dave Barachb7b92992018-10-17 10:38:51 -040089 clib_memset (mp, 0, sizeof (*mp));
Matus Fabianf468e232016-12-02 06:00:53 -080090 mp->_vl_msg_id = ntohs (VL_API_L2_XCONNECT_DETAILS);
91 mp->context = context;
92 mp->rx_sw_if_index = htonl (rx_sw_if_index);
93 mp->tx_sw_if_index = htonl (tx_sw_if_index);
94
Florin Coras6c4dae22018-01-09 06:39:23 -080095 vl_api_send_msg (reg, (u8 *) mp);
Matus Fabianf468e232016-12-02 06:00:53 -080096}
97
98static void
99vl_api_l2_xconnect_dump_t_handler (vl_api_l2_xconnect_dump_t * mp)
100{
Florin Coras6c4dae22018-01-09 06:39:23 -0800101 vl_api_registration_t *reg;
Matus Fabianf468e232016-12-02 06:00:53 -0800102 vnet_main_t *vnm = vnet_get_main ();
103 vnet_interface_main_t *im = &vnm->interface_main;
104 l2input_main_t *l2im = &l2input_main;
105 vnet_sw_interface_t *swif;
106 l2_input_config_t *config;
107
Florin Coras6c4dae22018-01-09 06:39:23 -0800108 reg = vl_api_client_index_to_registration (mp->client_index);
109 if (!reg)
Matus Fabianf468e232016-12-02 06:00:53 -0800110 return;
111
112 /* *INDENT-OFF* */
113 pool_foreach (swif, im->sw_interfaces,
114 ({
115 config = vec_elt_at_index (l2im->configs, swif->sw_if_index);
116 if (config->xconnect)
Florin Coras6c4dae22018-01-09 06:39:23 -0800117 send_l2_xconnect_details (reg, mp->context, swif->sw_if_index,
Matus Fabianf468e232016-12-02 06:00:53 -0800118 config->output_sw_if_index);
119 }));
120 /* *INDENT-ON* */
121}
122
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100123static void
124vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t * mp)
125{
126 int rv = 0;
127 vl_api_l2_fib_clear_table_reply_t *rmp;
128
Eyal Bari7537e712017-04-27 14:07:55 +0300129 /* Clear all MACs including static MACs */
130 l2fib_clear_table ();
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100131
132 REPLY_MACRO (VL_API_L2_FIB_CLEAR_TABLE_REPLY);
133}
134
135static void
136send_l2fib_table_entry (vpe_api_main_t * am,
Florin Coras6c4dae22018-01-09 06:39:23 -0800137 vl_api_registration_t * reg,
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100138 l2fib_entry_key_t * l2fe_key,
139 l2fib_entry_result_t * l2fe_res, u32 context)
140{
Ole Troan01384fe2017-05-12 11:55:35 +0200141 vl_api_l2_fib_table_details_t *mp;
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100142
143 mp = vl_msg_api_alloc (sizeof (*mp));
Dave Barachb7b92992018-10-17 10:38:51 -0400144 clib_memset (mp, 0, sizeof (*mp));
Ole Troan01384fe2017-05-12 11:55:35 +0200145 mp->_vl_msg_id = ntohs (VL_API_L2_FIB_TABLE_DETAILS);
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100146
147 mp->bd_id =
148 ntohl (l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
149
Mohsin Kazmi57938f62017-10-27 21:28:07 +0200150 clib_memcpy (mp->mac, l2fe_key->fields.mac, 6);
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100151 mp->sw_if_index = ntohl (l2fe_res->fields.sw_if_index);
Neale Ranns7341b6d2018-09-19 04:07:02 -0700152 mp->static_mac = (l2fib_entry_result_is_set_STATIC (l2fe_res) ? 1 : 0);
153 mp->filter_mac = (l2fib_entry_result_is_set_FILTER (l2fe_res) ? 1 : 0);
154 mp->bvi_mac = (l2fib_entry_result_is_set_BVI (l2fe_res) ? 1 : 0);
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100155 mp->context = context;
156
Florin Coras6c4dae22018-01-09 06:39:23 -0800157 vl_api_send_msg (reg, (u8 *) mp);
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100158}
159
160static void
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100161vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t * mp)
162{
163 vpe_api_main_t *am = &vpe_api_main;
164 bd_main_t *bdm = &bd_main;
165 l2fib_entry_key_t *l2fe_key = NULL;
166 l2fib_entry_result_t *l2fe_res = NULL;
167 u32 ni, bd_id = ntohl (mp->bd_id);
168 u32 bd_index;
Florin Coras6c4dae22018-01-09 06:39:23 -0800169 vl_api_registration_t *reg;
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100170 uword *p;
171
Florin Coras6c4dae22018-01-09 06:39:23 -0800172 reg = vl_api_client_index_to_registration (mp->client_index);
173 if (!reg)
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100174 return;
175
176 /* see l2fib_table_dump: ~0 means "any" */
177 if (bd_id == ~0)
178 bd_index = ~0;
179 else
180 {
181 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
182 if (p == 0)
183 return;
184
185 bd_index = p[0];
186 }
187
188 l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
189
190 vec_foreach_index (ni, l2fe_key)
191 {
Florin Coras6c4dae22018-01-09 06:39:23 -0800192 send_l2fib_table_entry (am, reg, vec_elt_at_index (l2fe_key, ni),
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100193 vec_elt_at_index (l2fe_res, ni), mp->context);
194 }
195 vec_free (l2fe_key);
196 vec_free (l2fe_res);
197}
198
199static void
200vl_api_l2fib_add_del_t_handler (vl_api_l2fib_add_del_t * mp)
201{
202 bd_main_t *bdm = &bd_main;
203 l2input_main_t *l2im = &l2input_main;
204 vl_api_l2fib_add_del_reply_t *rmp;
205 int rv = 0;
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100206 u32 bd_id = ntohl (mp->bd_id);
Eyal Bari31a71ab2017-06-25 14:42:33 +0300207 uword *p = hash_get (bdm->bd_index_by_bd_id, bd_id);
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100208
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100209 if (!p)
210 {
211 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
212 goto bad_sw_if_index;
213 }
Eyal Bari31a71ab2017-06-25 14:42:33 +0300214 u32 bd_index = p[0];
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100215
Mohsin Kazmi57938f62017-10-27 21:28:07 +0200216 u8 mac[6];
217
218 clib_memcpy (mac, mp->mac, 6);
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100219 if (mp->is_add)
220 {
Eyal Bari31a71ab2017-06-25 14:42:33 +0300221 if (mp->filter_mac)
222 l2fib_add_filter_entry (mac, bd_index);
223 else
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100224 {
Neale Rannsb54d0812018-09-06 06:22:56 -0700225 l2fib_entry_result_flags_t flags = L2FIB_ENTRY_RESULT_FLAG_NONE;
Eyal Bari31a71ab2017-06-25 14:42:33 +0300226 u32 sw_if_index = ntohl (mp->sw_if_index);
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100227 VALIDATE_SW_IF_INDEX (mp);
228 if (vec_len (l2im->configs) <= sw_if_index)
229 {
230 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
231 goto bad_sw_if_index;
232 }
233 else
234 {
235 l2_input_config_t *config;
236 config = vec_elt_at_index (l2im->configs, sw_if_index);
237 if (config->bridge == 0)
238 {
239 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
240 goto bad_sw_if_index;
241 }
242 }
Neale Rannsb54d0812018-09-06 06:22:56 -0700243 if (mp->static_mac)
244 flags |= L2FIB_ENTRY_RESULT_FLAG_STATIC;
245 if (mp->bvi_mac)
246 flags |= L2FIB_ENTRY_RESULT_FLAG_BVI;
247 l2fib_add_entry (mac, bd_index, sw_if_index, flags);
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100248 }
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100249 }
250 else
251 {
John Lo7dbd7262018-05-31 10:25:18 -0400252 u32 sw_if_index = ntohl (mp->sw_if_index);
253 if (l2fib_del_entry (mac, bd_index, sw_if_index))
254 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100255 }
256
257 BAD_SW_IF_INDEX_LABEL;
258
259 REPLY_MACRO (VL_API_L2FIB_ADD_DEL_REPLY);
260}
261
262static void
John Lo8d00fff2017-08-03 00:35:36 -0400263vl_api_want_l2_macs_events_t_handler (vl_api_want_l2_macs_events_t * mp)
264{
265 int rv = 0;
266 vl_api_want_l2_macs_events_reply_t *rmp;
267 l2learn_main_t *lm = &l2learn_main;
268 l2fib_main_t *fm = &l2fib_main;
269 u32 pid = ntohl (mp->pid);
270 u32 learn_limit = ntohl (mp->learn_limit);
271
272 if (mp->enable_disable)
273 {
274 if (lm->client_pid == 0)
275 {
276 lm->client_pid = pid;
277 lm->client_index = mp->client_index;
278
279 if (mp->max_macs_in_event)
280 fm->max_macs_in_event = mp->max_macs_in_event * 10;
281 else
282 fm->max_macs_in_event = L2FIB_EVENT_MAX_MACS_DEFAULT;
283
284 if (mp->scan_delay)
285 fm->event_scan_delay = (f64) (mp->scan_delay) * 10e-3;
286 else
287 fm->event_scan_delay = L2FIB_EVENT_SCAN_DELAY_DEFAULT;
288
289 /* change learn limit and flush all learned MACs */
290 if (learn_limit && (learn_limit < L2LEARN_DEFAULT_LIMIT))
291 lm->global_learn_limit = learn_limit;
292 else
293 lm->global_learn_limit = L2FIB_EVENT_LEARN_LIMIT_DEFAULT;
294
295 l2fib_flush_all_mac (vlib_get_main ());
296 }
297 else if (lm->client_pid != pid)
298 {
299 rv = VNET_API_ERROR_L2_MACS_EVENT_CLINET_PRESENT;
300 goto exit;
301 }
302 }
303 else if (lm->client_pid)
304 {
305 lm->client_pid = 0;
306 lm->client_index = 0;
John Lodbfa5742017-09-02 08:27:36 -0400307 if (learn_limit && (learn_limit < L2LEARN_DEFAULT_LIMIT))
John Loe531f4c2017-08-22 09:16:50 -0400308 lm->global_learn_limit = learn_limit;
309 else
310 lm->global_learn_limit = L2LEARN_DEFAULT_LIMIT;
John Lo8d00fff2017-08-03 00:35:36 -0400311 }
312
313exit:
314 REPLY_MACRO (VL_API_WANT_L2_MACS_EVENTS_REPLY);
315}
316
317static void
Eyal Barif24991c2017-04-05 05:33:21 +0300318vl_api_l2fib_flush_int_t_handler (vl_api_l2fib_flush_int_t * mp)
319{
320 int rv = 0;
321 vlib_main_t *vm = vlib_get_main ();
322 vl_api_l2fib_flush_int_reply_t *rmp;
323
324 VALIDATE_SW_IF_INDEX (mp);
325
326 u32 sw_if_index = ntohl (mp->sw_if_index);
327 l2fib_flush_int_mac (vm, sw_if_index);
328
329 BAD_SW_IF_INDEX_LABEL;
330 REPLY_MACRO (VL_API_L2FIB_FLUSH_INT_REPLY);
331}
332
333static void
Eyal Bari7537e712017-04-27 14:07:55 +0300334vl_api_l2fib_flush_all_t_handler (vl_api_l2fib_flush_all_t * mp)
335{
336 int rv = 0;
337 vl_api_l2fib_flush_all_reply_t *rmp;
338
339 l2fib_flush_all_mac (vlib_get_main ());
340 REPLY_MACRO (VL_API_L2FIB_FLUSH_ALL_REPLY);
341}
342
343static void
Eyal Barif24991c2017-04-05 05:33:21 +0300344vl_api_l2fib_flush_bd_t_handler (vl_api_l2fib_flush_bd_t * mp)
345{
346 int rv = 0;
347 vlib_main_t *vm = vlib_get_main ();
348 bd_main_t *bdm = &bd_main;
349 vl_api_l2fib_flush_bd_reply_t *rmp;
350
351 u32 bd_id = ntohl (mp->bd_id);
352 uword *p = hash_get (bdm->bd_index_by_bd_id, bd_id);
353 if (p == 0)
354 {
355 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
356 goto out;
357 }
358 l2fib_flush_bd_mac (vm, *p);
359out:
360 REPLY_MACRO (VL_API_L2FIB_FLUSH_BD_REPLY);
361}
362
363static void
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100364vl_api_l2_flags_t_handler (vl_api_l2_flags_t * mp)
365{
366 vl_api_l2_flags_reply_t *rmp;
367 int rv = 0;
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100368 u32 rbm = 0;
369
370 VALIDATE_SW_IF_INDEX (mp);
371
Eyal Barifead6702017-04-04 04:46:32 +0300372 u32 sw_if_index = ntohl (mp->sw_if_index);
John Lo8d00fff2017-08-03 00:35:36 -0400373 u32 flags = ntohl (mp->feature_bitmap);
374 u32 bitmap = 0;
375
376 if (flags & L2_LEARN)
377 bitmap |= L2INPUT_FEAT_LEARN;
378
379 if (flags & L2_FWD)
380 bitmap |= L2INPUT_FEAT_FWD;
381
382 if (flags & L2_FLOOD)
383 bitmap |= L2INPUT_FEAT_FLOOD;
384
385 if (flags & L2_UU_FLOOD)
386 bitmap |= L2INPUT_FEAT_UU_FLOOD;
387
388 if (flags & L2_ARP_TERM)
389 bitmap |= L2INPUT_FEAT_ARP_TERM;
390
391 rbm = l2input_intf_bitmap_enable (sw_if_index, bitmap, mp->is_set);
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100392
393 BAD_SW_IF_INDEX_LABEL;
394
395 /* *INDENT-OFF* */
396 REPLY_MACRO2(VL_API_L2_FLAGS_REPLY,
397 ({
398 rmp->resulting_feature_bitmap = ntohl(rbm);
399 }));
400 /* *INDENT-ON* */
401}
402
403static void
Eyal Barifead6702017-04-04 04:46:32 +0300404vl_api_bridge_domain_set_mac_age_t_handler (vl_api_bridge_domain_set_mac_age_t
405 * mp)
406{
407 vlib_main_t *vm = vlib_get_main ();
408 bd_main_t *bdm = &bd_main;
409 vl_api_bridge_domain_set_mac_age_reply_t *rmp;
410 int rv = 0;
411 u32 bd_id = ntohl (mp->bd_id);
Jon Loeliger1c7d4852017-05-02 11:06:23 -0500412 uword *p;
413
414 if (bd_id == 0)
415 {
416 rv = VNET_API_ERROR_BD_NOT_MODIFIABLE;
417 goto out;
418 }
419
420 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
Eyal Barifead6702017-04-04 04:46:32 +0300421 if (p == 0)
422 {
423 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
424 goto out;
425 }
426 bd_set_mac_age (vm, *p, mp->mac_age);
427out:
428 REPLY_MACRO (VL_API_BRIDGE_DOMAIN_SET_MAC_AGE_REPLY);
429}
430
431static void
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100432vl_api_bridge_domain_add_del_t_handler (vl_api_bridge_domain_add_del_t * mp)
433{
Eyal Barib1352ed2017-04-07 23:14:17 +0300434 l2_bridge_domain_add_del_args_t a = {
435 .is_add = mp->is_add,
436 .flood = mp->flood,
437 .uu_flood = mp->uu_flood,
438 .forward = mp->forward,
439 .learn = mp->learn,
440 .arp_term = mp->arp_term,
441 .mac_age = mp->mac_age,
442 .bd_id = ntohl (mp->bd_id),
Jerome Tollet48304142017-09-05 12:13:22 +0100443 .bd_tag = mp->bd_tag
Eyal Barib1352ed2017-04-07 23:14:17 +0300444 };
445
446 int rv = bd_add_del (&a);
447
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100448 vl_api_bridge_domain_add_del_reply_t *rmp;
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100449 REPLY_MACRO (VL_API_BRIDGE_DOMAIN_ADD_DEL_REPLY);
450}
451
452static void
Ole Troan01384fe2017-05-12 11:55:35 +0200453send_bridge_domain_details (l2input_main_t * l2im,
Florin Coras6c4dae22018-01-09 06:39:23 -0800454 vl_api_registration_t * reg,
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100455 l2_bridge_domain_t * bd_config,
456 u32 n_sw_ifs, u32 context)
457{
458 vl_api_bridge_domain_details_t *mp;
Ole Troan01384fe2017-05-12 11:55:35 +0200459 l2_flood_member_t *m;
460 vl_api_bridge_domain_sw_if_t *sw_ifs;
461 l2_input_config_t *input_cfg;
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100462
Ole Troan01384fe2017-05-12 11:55:35 +0200463 mp = vl_msg_api_alloc (sizeof (*mp) +
464 (n_sw_ifs * sizeof (vl_api_bridge_domain_sw_if_t)));
Dave Barachb7b92992018-10-17 10:38:51 -0400465 clib_memset (mp, 0, sizeof (*mp));
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100466 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_DETAILS);
467 mp->bd_id = ntohl (bd_config->bd_id);
468 mp->flood = bd_feature_flood (bd_config);
469 mp->uu_flood = bd_feature_uu_flood (bd_config);
470 mp->forward = bd_feature_forward (bd_config);
471 mp->learn = bd_feature_learn (bd_config);
472 mp->arp_term = bd_feature_arp_term (bd_config);
473 mp->bvi_sw_if_index = ntohl (bd_config->bvi_sw_if_index);
Neale Rannsb4743802018-09-05 09:13:57 -0700474 mp->uu_fwd_sw_if_index = ntohl (bd_config->uu_fwd_sw_if_index);
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100475 mp->mac_age = bd_config->mac_age;
Jerome Tollet48304142017-09-05 12:13:22 +0100476 if (bd_config->bd_tag)
477 {
478 strncpy ((char *) mp->bd_tag, (char *) bd_config->bd_tag,
479 ARRAY_LEN (mp->bd_tag) - 1);
480 mp->bd_tag[ARRAY_LEN (mp->bd_tag) - 1] = 0;
481 }
482
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100483 mp->context = context;
484
Ole Troan01384fe2017-05-12 11:55:35 +0200485 sw_ifs = (vl_api_bridge_domain_sw_if_t *) mp->sw_if_details;
486 vec_foreach (m, bd_config->members)
487 {
488 sw_ifs->sw_if_index = ntohl (m->sw_if_index);
489 input_cfg = vec_elt_at_index (l2im->configs, m->sw_if_index);
490 sw_ifs->shg = input_cfg->shg;
491 sw_ifs++;
492 mp->n_sw_ifs++;
493 }
494 mp->n_sw_ifs = htonl (mp->n_sw_ifs);
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100495
Florin Coras6c4dae22018-01-09 06:39:23 -0800496 vl_api_send_msg (reg, (u8 *) mp);
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100497}
498
499static void
500vl_api_bridge_domain_dump_t_handler (vl_api_bridge_domain_dump_t * mp)
501{
502 bd_main_t *bdm = &bd_main;
503 l2input_main_t *l2im = &l2input_main;
Florin Coras6c4dae22018-01-09 06:39:23 -0800504 vl_api_registration_t *reg;
505 u32 bd_id, bd_index, end;
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100506
Florin Coras6c4dae22018-01-09 06:39:23 -0800507 reg = vl_api_client_index_to_registration (mp->client_index);
508 if (!reg)
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100509 return;
510
Florin Coras6c4dae22018-01-09 06:39:23 -0800511 bd_id = ntohl (mp->bd_id);
Jon Loeliger1c7d4852017-05-02 11:06:23 -0500512 if (bd_id == 0)
513 return;
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100514
Eyal Bari259fca72017-05-14 10:38:39 +0300515 if (bd_id == ~0)
516 bd_index = 0, end = vec_len (l2im->bd_configs);
517 else
518 {
519 bd_index = bd_find_index (bdm, bd_id);
520 if (bd_index == ~0)
521 return;
522
523 end = bd_index + 1;
524 }
Jon Loeliger1c7d4852017-05-02 11:06:23 -0500525
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100526 for (; bd_index < end; bd_index++)
527 {
Eyal Bari259fca72017-05-14 10:38:39 +0300528 l2_bridge_domain_t *bd_config =
529 l2input_bd_config_from_index (l2im, bd_index);
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100530 /* skip dummy bd_id 0 */
531 if (bd_config && (bd_config->bd_id > 0))
Florin Coras6c4dae22018-01-09 06:39:23 -0800532 send_bridge_domain_details (l2im, reg, bd_config,
Ole Troan01384fe2017-05-12 11:55:35 +0200533 vec_len (bd_config->members),
534 mp->context);
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100535 }
536}
537
Neale Rannsb4743802018-09-05 09:13:57 -0700538static bd_flags_t
539bd_flags_decode (vl_api_bd_flags_t v)
540{
541 bd_flags_t f = L2_NONE;
542
543 v = ntohl (v);
544
545 if (v & BRIDGE_API_FLAG_LEARN)
546 f |= L2_LEARN;
547 if (v & BRIDGE_API_FLAG_FWD)
548 f |= L2_FWD;
549 if (v & BRIDGE_API_FLAG_FLOOD)
550 f |= L2_FLOOD;
551 if (v & BRIDGE_API_FLAG_UU_FLOOD)
552 f |= L2_UU_FLOOD;
553 if (v & BRIDGE_API_FLAG_ARP_TERM)
554 f |= L2_ARP_TERM;
555
556 return (f);
557}
558
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100559static void
560vl_api_bridge_flags_t_handler (vl_api_bridge_flags_t * mp)
561{
562 vlib_main_t *vm = vlib_get_main ();
563 bd_main_t *bdm = &bd_main;
564 vl_api_bridge_flags_reply_t *rmp;
Dave Barach98d6b612019-01-03 09:30:00 -0500565 u32 bitmap = 0;
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100566 int rv = 0;
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100567
Neale Rannsb4743802018-09-05 09:13:57 -0700568 bd_flags_t flags = bd_flags_decode (mp->flags);
Eyal Bari259fca72017-05-14 10:38:39 +0300569 u32 bd_id = ntohl (mp->bd_id);
Jon Loeliger1c7d4852017-05-02 11:06:23 -0500570 if (bd_id == 0)
571 {
572 rv = VNET_API_ERROR_BD_NOT_MODIFIABLE;
573 goto out;
574 }
575
Eyal Bari259fca72017-05-14 10:38:39 +0300576 u32 bd_index = bd_find_index (bdm, bd_id);
577 if (bd_index == ~0)
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100578 {
579 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
580 goto out;
581 }
582
Dave Barach98d6b612019-01-03 09:30:00 -0500583 bitmap = bd_set_flags (vm, bd_index, flags, mp->is_set);
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100584
585out:
586 /* *INDENT-OFF* */
587 REPLY_MACRO2(VL_API_BRIDGE_FLAGS_REPLY,
588 ({
John Lo8d00fff2017-08-03 00:35:36 -0400589 rmp->resulting_feature_bitmap = ntohl(bitmap);
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100590 }));
591 /* *INDENT-ON* */
592}
Matus Fabianf468e232016-12-02 06:00:53 -0800593
Pavel Kotucekadec5872017-01-25 08:50:53 +0100594static void
595 vl_api_l2_interface_vlan_tag_rewrite_t_handler
596 (vl_api_l2_interface_vlan_tag_rewrite_t * mp)
597{
598 int rv = 0;
599 vl_api_l2_interface_vlan_tag_rewrite_reply_t *rmp;
600 vnet_main_t *vnm = vnet_get_main ();
601 vlib_main_t *vm = vlib_get_main ();
602 u32 vtr_op;
603
604 VALIDATE_SW_IF_INDEX (mp);
605
606 vtr_op = ntohl (mp->vtr_op);
607
608 /* The L2 code is unsuspicious */
609 switch (vtr_op)
610 {
611 case L2_VTR_DISABLED:
612 case L2_VTR_PUSH_1:
613 case L2_VTR_PUSH_2:
614 case L2_VTR_POP_1:
615 case L2_VTR_POP_2:
616 case L2_VTR_TRANSLATE_1_1:
617 case L2_VTR_TRANSLATE_1_2:
618 case L2_VTR_TRANSLATE_2_1:
619 case L2_VTR_TRANSLATE_2_2:
620 break;
621
622 default:
623 rv = VNET_API_ERROR_INVALID_VALUE;
624 goto bad_sw_if_index;
625 }
626
627 rv = l2vtr_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op,
628 ntohl (mp->push_dot1q), ntohl (mp->tag1),
629 ntohl (mp->tag2));
630
631 BAD_SW_IF_INDEX_LABEL;
632
633 REPLY_MACRO (VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
634}
635
636static void
637 vl_api_l2_interface_pbb_tag_rewrite_t_handler
638 (vl_api_l2_interface_pbb_tag_rewrite_t * mp)
639{
640 vl_api_l2_interface_pbb_tag_rewrite_reply_t *rmp;
641 vnet_main_t *vnm = vnet_get_main ();
642 vlib_main_t *vm = vlib_get_main ();
643 u32 vtr_op;
644 int rv = 0;
645
646 VALIDATE_SW_IF_INDEX (mp);
647
648 vtr_op = ntohl (mp->vtr_op);
649
650 switch (vtr_op)
651 {
652 case L2_VTR_DISABLED:
653 case L2_VTR_PUSH_2:
654 case L2_VTR_POP_2:
655 case L2_VTR_TRANSLATE_2_1:
656 break;
657
658 default:
659 rv = VNET_API_ERROR_INVALID_VALUE;
660 goto bad_sw_if_index;
661 }
662
663 rv = l2pbb_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op,
664 mp->b_dmac, mp->b_smac, ntohs (mp->b_vlanid),
665 ntohl (mp->i_sid), ntohs (mp->outer_tag));
666
667 BAD_SW_IF_INDEX_LABEL;
668
669 REPLY_MACRO (VL_API_L2_INTERFACE_PBB_TAG_REWRITE_REPLY);
670}
671
Neale Rannsb8d44812017-11-10 06:53:54 -0800672static void
673 vl_api_sw_interface_set_l2_xconnect_t_handler
674 (vl_api_sw_interface_set_l2_xconnect_t * mp)
675{
676 vl_api_sw_interface_set_l2_xconnect_reply_t *rmp;
677 int rv = 0;
678 u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
679 u32 tx_sw_if_index = ntohl (mp->tx_sw_if_index);
680 vlib_main_t *vm = vlib_get_main ();
681 vnet_main_t *vnm = vnet_get_main ();
682
683 VALIDATE_RX_SW_IF_INDEX (mp);
684
685 if (mp->enable)
686 {
687 VALIDATE_TX_SW_IF_INDEX (mp);
688 rv = set_int_l2_mode (vm, vnm, MODE_L2_XC,
Neale Rannsb4743802018-09-05 09:13:57 -0700689 rx_sw_if_index, 0,
690 L2_BD_PORT_TYPE_NORMAL, 0, tx_sw_if_index);
Neale Rannsb8d44812017-11-10 06:53:54 -0800691 }
692 else
693 {
Neale Rannsb4743802018-09-05 09:13:57 -0700694 rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0,
695 L2_BD_PORT_TYPE_NORMAL, 0, 0);
Neale Rannsb8d44812017-11-10 06:53:54 -0800696 }
697
Alexander Chernavine178b272018-09-24 05:42:01 -0400698 switch (rv)
699 {
700 case MODE_ERROR_ETH:
701 rv = VNET_API_ERROR_NON_ETHERNET;
702 break;
703 case MODE_ERROR_BVI_DEF:
704 rv = VNET_API_ERROR_BD_ALREADY_HAS_BVI;
705 break;
706 }
707
Neale Rannsb8d44812017-11-10 06:53:54 -0800708 BAD_RX_SW_IF_INDEX_LABEL;
709 BAD_TX_SW_IF_INDEX_LABEL;
710
711 REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY);
712}
713
Neale Rannsb4743802018-09-05 09:13:57 -0700714static int
715l2_bd_port_type_decode (vl_api_l2_port_type_t v, l2_bd_port_type_t * l)
716{
717 v = clib_net_to_host_u32 (v);
718
719 switch (v)
720 {
721 case L2_API_PORT_TYPE_NORMAL:
722 *l = L2_BD_PORT_TYPE_NORMAL;
723 return 0;
724 case L2_API_PORT_TYPE_BVI:
725 *l = L2_BD_PORT_TYPE_BVI;
726 return 0;
727 case L2_API_PORT_TYPE_UU_FWD:
728 *l = L2_BD_PORT_TYPE_UU_FWD;
729 return 0;
730 }
731
732 return (VNET_API_ERROR_INVALID_VALUE);
733}
734
Neale Rannsb8d44812017-11-10 06:53:54 -0800735static void
736 vl_api_sw_interface_set_l2_bridge_t_handler
737 (vl_api_sw_interface_set_l2_bridge_t * mp)
738{
739 bd_main_t *bdm = &bd_main;
740 vl_api_sw_interface_set_l2_bridge_reply_t *rmp;
741 int rv = 0;
742 vlib_main_t *vm = vlib_get_main ();
743 vnet_main_t *vnm = vnet_get_main ();
Neale Rannsb4743802018-09-05 09:13:57 -0700744 l2_bd_port_type_t pt;
Neale Rannsb8d44812017-11-10 06:53:54 -0800745
746 VALIDATE_RX_SW_IF_INDEX (mp);
747 u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
Neale Rannsb4743802018-09-05 09:13:57 -0700748 rv = l2_bd_port_type_decode (mp->port_type, &pt);
Neale Rannsb8d44812017-11-10 06:53:54 -0800749
Neale Rannsb4743802018-09-05 09:13:57 -0700750 if (0 != rv)
751 goto out;
Neale Rannsb8d44812017-11-10 06:53:54 -0800752 if (mp->enable)
753 {
754 VALIDATE_BD_ID (mp);
755 u32 bd_id = ntohl (mp->bd_id);
756 u32 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
Neale Rannsb4743802018-09-05 09:13:57 -0700757
Neale Rannsb8d44812017-11-10 06:53:54 -0800758 rv = set_int_l2_mode (vm, vnm, MODE_L2_BRIDGE,
Neale Rannsb4743802018-09-05 09:13:57 -0700759 rx_sw_if_index, bd_index, pt, mp->shg, 0);
Neale Rannsb8d44812017-11-10 06:53:54 -0800760 }
761 else
762 {
Neale Rannsb4743802018-09-05 09:13:57 -0700763 rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, pt, 0, 0);
Neale Rannsb8d44812017-11-10 06:53:54 -0800764 }
765
Alexander Chernavine178b272018-09-24 05:42:01 -0400766 switch (rv)
767 {
768 case MODE_ERROR_ETH:
769 rv = VNET_API_ERROR_NON_ETHERNET;
770 break;
771 case MODE_ERROR_BVI_DEF:
772 rv = VNET_API_ERROR_BD_ALREADY_HAS_BVI;
773 break;
774 }
775
Neale Rannsb8d44812017-11-10 06:53:54 -0800776 BAD_RX_SW_IF_INDEX_LABEL;
777 BAD_BD_ID_LABEL;
Neale Rannsb4743802018-09-05 09:13:57 -0700778out:
Neale Rannsb8d44812017-11-10 06:53:54 -0800779 REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY);
780}
781
782static void
Mohsin Kazmi5d82d2f2018-08-13 19:17:54 +0200783send_bd_ip_mac_entry (vpe_api_main_t * am,
784 vl_api_registration_t * reg,
785 u32 bd_id, u8 is_ipv6,
786 u8 * ip_address, u8 * mac_address, u32 context)
787{
788 vl_api_bd_ip_mac_details_t *mp;
789
790 mp = vl_msg_api_alloc (sizeof (*mp));
Dave Barachb7b92992018-10-17 10:38:51 -0400791 clib_memset (mp, 0, sizeof (*mp));
Mohsin Kazmi5d82d2f2018-08-13 19:17:54 +0200792 mp->_vl_msg_id = ntohs (VL_API_BD_IP_MAC_DETAILS);
793
794 mp->bd_id = ntohl (bd_id);
795
796 clib_memcpy (mp->mac_address, mac_address, 6);
797 mp->is_ipv6 = is_ipv6;
798 clib_memcpy (mp->ip_address, ip_address, (is_ipv6) ? 16 : 4);
799 mp->context = context;
800
801 vl_api_send_msg (reg, (u8 *) mp);
802}
803
804static void
805vl_api_bd_ip_mac_dump_t_handler (vl_api_bd_ip_mac_dump_t * mp)
806{
807 vpe_api_main_t *am = &vpe_api_main;
808 bd_main_t *bdm = &bd_main;
809 l2_bridge_domain_t *bd_config;
810 u32 bd_id = ntohl (mp->bd_id);
Mohsin Kazmib24dfec2018-08-23 12:24:19 +0200811 u32 bd_index, start, end;
Mohsin Kazmi5d82d2f2018-08-13 19:17:54 +0200812 vl_api_registration_t *reg;
813 uword *p;
814
815 reg = vl_api_client_index_to_registration (mp->client_index);
816 if (!reg)
817 return;
818
Mohsin Kazmi5d82d2f2018-08-13 19:17:54 +0200819 /* see bd_id: ~0 means "any" */
820 if (bd_id == ~0)
Mohsin Kazmib24dfec2018-08-23 12:24:19 +0200821 {
822 start = 1;
823 end = vec_len (l2input_main.bd_configs);
824 }
Mohsin Kazmi5d82d2f2018-08-13 19:17:54 +0200825 else
826 {
827 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
828 if (p == 0)
829 return;
830
831 bd_index = p[0];
832 vec_validate (l2input_main.bd_configs, bd_index);
833 start = bd_index;
834 end = start + 1;
835 }
836
837 for (bd_index = start; bd_index < end; bd_index++)
838 {
839 bd_config = vec_elt_at_index (l2input_main.bd_configs, bd_index);
840 if (bd_is_valid (bd_config))
841 {
842 ip4_address_t ip4_addr;
843 ip6_address_t *ip6_addr;
844 u64 mac_addr;
845 bd_id = bd_config->bd_id;
846
847 /* *INDENT-OFF* */
848 hash_foreach (ip4_addr.as_u32, mac_addr, bd_config->mac_by_ip4,
849 ({
850 send_bd_ip_mac_entry (am, reg, bd_id, 0, (u8 *) &(ip4_addr.as_u8), (u8 *) &mac_addr, mp->context);
851 }));
852
853 hash_foreach_mem (ip6_addr, mac_addr, bd_config->mac_by_ip6,
854 ({
855 send_bd_ip_mac_entry (am, reg, bd_id, 1, (u8 *) &(ip6_addr->as_u8), (u8 *) &mac_addr, mp->context);
856 }));
857 /* *INDENT-ON* */
858 }
859 }
860}
861
862static void
Neale Rannsb8d44812017-11-10 06:53:54 -0800863vl_api_bd_ip_mac_add_del_t_handler (vl_api_bd_ip_mac_add_del_t * mp)
864{
Neale Ranns4d5b9172018-10-24 02:57:49 -0700865 ip46_address_t ip_addr = ip46_address_initializer;
Neale Rannsb8d44812017-11-10 06:53:54 -0800866 vl_api_bd_ip_mac_add_del_reply_t *rmp;
Neale Ranns4d5b9172018-10-24 02:57:49 -0700867 bd_main_t *bdm = &bd_main;
868 u32 bd_index, bd_id;
869 mac_address_t mac;
870 ip46_type_t type;
Neale Rannsb8d44812017-11-10 06:53:54 -0800871 int rv = 0;
Neale Rannsb8d44812017-11-10 06:53:54 -0800872 uword *p;
873
Neale Ranns4d5b9172018-10-24 02:57:49 -0700874 bd_id = ntohl (mp->bd_id);
875
Neale Rannsb8d44812017-11-10 06:53:54 -0800876 if (bd_id == 0)
877 {
878 rv = VNET_API_ERROR_BD_NOT_MODIFIABLE;
879 goto out;
880 }
881
882 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
883 if (p == 0)
884 {
885 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
886 goto out;
887 }
Neale Rannsb8d44812017-11-10 06:53:54 -0800888 bd_index = p[0];
Neale Ranns4d5b9172018-10-24 02:57:49 -0700889
890 type = ip_address_decode (&mp->ip, &ip_addr);
Ole Troan8006c6a2018-12-17 12:02:26 +0100891 mac_address_decode (mp->mac, &mac);
Neale Ranns4d5b9172018-10-24 02:57:49 -0700892
893 if (bd_add_del_ip_mac (bd_index, type, &ip_addr, &mac, mp->is_add))
Neale Rannsb8d44812017-11-10 06:53:54 -0800894 rv = VNET_API_ERROR_UNSPECIFIED;
895
896out:
897 REPLY_MACRO (VL_API_BD_IP_MAC_ADD_DEL_REPLY);
898}
899
John Loe26c81f2019-01-07 15:16:33 -0500900static void
901vl_api_bd_ip_mac_flush_t_handler (vl_api_bd_ip_mac_flush_t * mp)
902{
903 vl_api_bd_ip_mac_flush_reply_t *rmp;
904 bd_main_t *bdm = &bd_main;
905 u32 bd_index, bd_id;
906 int rv = 0;
907 uword *p;
908
909 bd_id = ntohl (mp->bd_id);
910
911 if (bd_id == 0)
912 {
913 rv = VNET_API_ERROR_BD_NOT_MODIFIABLE;
914 goto out;
915 }
916
917 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
918 if (p == 0)
919 {
920 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
921 goto out;
922 }
923 bd_index = p[0];
924
925 bd_flush_ip_mac (bd_index);
926
927out:
928 REPLY_MACRO (VL_API_BD_IP_MAC_FLUSH_REPLY);
929}
930
Neale Rannsb8d44812017-11-10 06:53:54 -0800931extern void l2_efp_filter_configure (vnet_main_t * vnet_main,
Neale Ranns6b9b41c2018-07-23 05:47:09 -0400932 u32 sw_if_index, u8 enable);
Neale Rannsb8d44812017-11-10 06:53:54 -0800933
934static void
935vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *
936 mp)
937{
938 int rv;
939 vl_api_l2_interface_efp_filter_reply_t *rmp;
940 vnet_main_t *vnm = vnet_get_main ();
941
Neale Ranns6b9b41c2018-07-23 05:47:09 -0400942 VALIDATE_SW_IF_INDEX (mp);
943
Neale Rannsb8d44812017-11-10 06:53:54 -0800944 // enable/disable the feature
Neale Ranns6b9b41c2018-07-23 05:47:09 -0400945 l2_efp_filter_configure (vnm, ntohl (mp->sw_if_index), mp->enable_disable);
Neale Rannsb8d44812017-11-10 06:53:54 -0800946 rv = vnm->api_errno;
947
Neale Ranns6b9b41c2018-07-23 05:47:09 -0400948 BAD_SW_IF_INDEX_LABEL;
Neale Rannsb8d44812017-11-10 06:53:54 -0800949 REPLY_MACRO (VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
950}
951
952static void
953vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t * mp)
954{
955 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
956 int is_add);
957 vl_api_l2_patch_add_del_reply_t *rmp;
958 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
959 int is_add);
960 int rv = 0;
961
962 VALIDATE_RX_SW_IF_INDEX (mp);
963 VALIDATE_TX_SW_IF_INDEX (mp);
964
965 rv = vnet_l2_patch_add_del (ntohl (mp->rx_sw_if_index),
966 ntohl (mp->tx_sw_if_index),
967 (int) (mp->is_add != 0));
968
969 BAD_RX_SW_IF_INDEX_LABEL;
970 BAD_TX_SW_IF_INDEX_LABEL;
971
972 REPLY_MACRO (VL_API_L2_PATCH_ADD_DEL_REPLY);
973}
974
975static void
976vl_api_sw_interface_set_vpath_t_handler (vl_api_sw_interface_set_vpath_t * mp)
977{
978 vl_api_sw_interface_set_vpath_reply_t *rmp;
979 int rv = 0;
980 u32 sw_if_index = ntohl (mp->sw_if_index);
981
982 VALIDATE_SW_IF_INDEX (mp);
983
984 l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_VPATH, mp->enable);
985 vnet_feature_enable_disable ("ip4-unicast", "vpath-input-ip4",
986 sw_if_index, mp->enable, 0, 0);
987 vnet_feature_enable_disable ("ip4-multicast", "vpath-input-ip4",
988 sw_if_index, mp->enable, 0, 0);
989 vnet_feature_enable_disable ("ip6-unicast", "vpath-input-ip6",
990 sw_if_index, mp->enable, 0, 0);
991 vnet_feature_enable_disable ("ip6-multicast", "vpath-input-ip6",
992 sw_if_index, mp->enable, 0, 0);
993
994 BAD_SW_IF_INDEX_LABEL;
995
996 REPLY_MACRO (VL_API_SW_INTERFACE_SET_VPATH_REPLY);
997}
998
Neale Ranns192b13f2019-03-15 02:16:20 -0700999static void
1000vl_api_bvi_create_t_handler (vl_api_bvi_create_t * mp)
1001{
1002 vl_api_bvi_create_reply_t *rmp;
1003 mac_address_t mac;
1004 u32 sw_if_index;
1005 int rv;
1006
1007 mac_address_decode (mp->mac, &mac);
1008
1009 rv = l2_bvi_create (ntohl (mp->user_instance), &mac, &sw_if_index);
1010
1011 /* *INDENT-OFF* */
1012 REPLY_MACRO2(VL_API_BVI_CREATE_REPLY,
1013 ({
1014 rmp->sw_if_index = ntohl (sw_if_index);
1015 }));
1016 /* *INDENT-ON* */
1017}
1018
1019static void
1020vl_api_bvi_delete_t_handler (vl_api_bvi_delete_t * mp)
1021{
1022 vl_api_bvi_delete_reply_t *rmp;
1023 int rv;
1024
1025 rv = l2_bvi_delete (ntohl (mp->sw_if_index));
1026
1027 REPLY_MACRO (VL_API_BVI_DELETE_REPLY);
1028}
1029
Matus Fabianf468e232016-12-02 06:00:53 -08001030/*
Pavel Kotucek0f971d82017-01-03 10:48:54 +01001031 * l2_api_hookup
Matus Fabianf468e232016-12-02 06:00:53 -08001032 * Add vpe's API message handlers to the table.
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -07001033 * vlib has already mapped shared memory and
Matus Fabianf468e232016-12-02 06:00:53 -08001034 * added the client registration handlers.
1035 * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
1036 */
1037#define vl_msg_name_crc_list
1038#include <vnet/vnet_all_api_h.h>
1039#undef vl_msg_name_crc_list
1040
1041static void
1042setup_message_id_table (api_main_t * am)
1043{
1044#define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
1045 foreach_vl_msg_name_crc_l2;
1046#undef _
1047}
1048
1049static clib_error_t *
1050l2_api_hookup (vlib_main_t * vm)
1051{
1052 api_main_t *am = &api_main;
1053
1054#define _(N,n) \
1055 vl_msg_api_set_handlers(VL_API_##N, #n, \
1056 vl_api_##n##_t_handler, \
1057 vl_noop_handler, \
1058 vl_api_##n##_t_endian, \
1059 vl_api_##n##_t_print, \
1060 sizeof(vl_api_##n##_t), 1);
1061 foreach_vpe_api_msg;
1062#undef _
1063
1064 /*
1065 * Set up the (msg_name, crc, message-id) table
1066 */
1067 setup_message_id_table (am);
1068
1069 return 0;
1070}
1071
1072VLIB_API_INIT_FUNCTION (l2_api_hookup);
1073
1074/*
1075 * fd.io coding-style-patch-verification: ON
1076 *
1077 * Local Variables:
1078 * eval: (c-set-style "gnu")
1079 * End:
1080 */