blob: 059f668d664bd18589fd879d43e8c07f297d66c2 [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 Ranns4d5b9172018-10-24 02:57:49 -070030#include <vnet/ip/ip_types_api.h>
31#include <vnet/ethernet/ethernet_types_api.h>
Matus Fabianf468e232016-12-02 06:00:53 -080032
33#include <vnet/vnet_msg_enum.h>
34
35#define vl_typedefs /* define message structures */
36#include <vnet/vnet_all_api_h.h>
37#undef vl_typedefs
38
39#define vl_endianfun /* define message structures */
40#include <vnet/vnet_all_api_h.h>
41#undef vl_endianfun
42
Ole Troan01384fe2017-05-12 11:55:35 +020043#define vl_api_bridge_domain_details_t_endian vl_noop_handler
44#define vl_api_bridge_domain_details_t_print vl_noop_handler
45
Matus Fabianf468e232016-12-02 06:00:53 -080046/* instantiate all the print functions we know about */
47#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
48#define vl_printfun
49#include <vnet/vnet_all_api_h.h>
50#undef vl_printfun
51
52#include <vlibapi/api_helper_macros.h>
53
Pavel Kotucek0f971d82017-01-03 10:48:54 +010054#define foreach_vpe_api_msg \
55_(L2_XCONNECT_DUMP, l2_xconnect_dump) \
56_(L2_FIB_CLEAR_TABLE, l2_fib_clear_table) \
57_(L2_FIB_TABLE_DUMP, l2_fib_table_dump) \
Eyal Bari7537e712017-04-27 14:07:55 +030058_(L2FIB_FLUSH_ALL, l2fib_flush_all) \
Eyal Barif24991c2017-04-05 05:33:21 +030059_(L2FIB_FLUSH_INT, l2fib_flush_int) \
60_(L2FIB_FLUSH_BD, l2fib_flush_bd) \
Pavel Kotucek0f971d82017-01-03 10:48:54 +010061_(L2FIB_ADD_DEL, l2fib_add_del) \
John Lo8d00fff2017-08-03 00:35:36 -040062_(WANT_L2_MACS_EVENTS, want_l2_macs_events) \
Pavel Kotucek0f971d82017-01-03 10:48:54 +010063_(L2_FLAGS, l2_flags) \
Neale Rannsb8d44812017-11-10 06:53:54 -080064_(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect) \
65_(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge) \
66_(L2_PATCH_ADD_DEL, l2_patch_add_del) \
67_(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter) \
68_(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del) \
John Loe26c81f2019-01-07 15:16:33 -050069_(BD_IP_MAC_FLUSH, bd_ip_mac_flush) \
Mohsin Kazmi5d82d2f2018-08-13 19:17:54 +020070_(BD_IP_MAC_DUMP, bd_ip_mac_dump) \
Neale Rannsb8d44812017-11-10 06:53:54 -080071_(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del) \
72_(BRIDGE_DOMAIN_DUMP, bridge_domain_dump) \
73_(BRIDGE_FLAGS, bridge_flags) \
Pavel Kotucekadec5872017-01-25 08:50:53 +010074_(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite) \
Neale Rannsb8d44812017-11-10 06:53:54 -080075_(L2_INTERFACE_PBB_TAG_REWRITE, l2_interface_pbb_tag_rewrite) \
76_(BRIDGE_DOMAIN_SET_MAC_AGE, bridge_domain_set_mac_age) \
77_(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath)
Matus Fabianf468e232016-12-02 06:00:53 -080078
79static void
Florin Coras6c4dae22018-01-09 06:39:23 -080080send_l2_xconnect_details (vl_api_registration_t * reg, u32 context,
Matus Fabianf468e232016-12-02 06:00:53 -080081 u32 rx_sw_if_index, u32 tx_sw_if_index)
82{
83 vl_api_l2_xconnect_details_t *mp;
84
85 mp = vl_msg_api_alloc (sizeof (*mp));
Dave Barachb7b92992018-10-17 10:38:51 -040086 clib_memset (mp, 0, sizeof (*mp));
Matus Fabianf468e232016-12-02 06:00:53 -080087 mp->_vl_msg_id = ntohs (VL_API_L2_XCONNECT_DETAILS);
88 mp->context = context;
89 mp->rx_sw_if_index = htonl (rx_sw_if_index);
90 mp->tx_sw_if_index = htonl (tx_sw_if_index);
91
Florin Coras6c4dae22018-01-09 06:39:23 -080092 vl_api_send_msg (reg, (u8 *) mp);
Matus Fabianf468e232016-12-02 06:00:53 -080093}
94
95static void
96vl_api_l2_xconnect_dump_t_handler (vl_api_l2_xconnect_dump_t * mp)
97{
Florin Coras6c4dae22018-01-09 06:39:23 -080098 vl_api_registration_t *reg;
Matus Fabianf468e232016-12-02 06:00:53 -080099 vnet_main_t *vnm = vnet_get_main ();
100 vnet_interface_main_t *im = &vnm->interface_main;
101 l2input_main_t *l2im = &l2input_main;
102 vnet_sw_interface_t *swif;
103 l2_input_config_t *config;
104
Florin Coras6c4dae22018-01-09 06:39:23 -0800105 reg = vl_api_client_index_to_registration (mp->client_index);
106 if (!reg)
Matus Fabianf468e232016-12-02 06:00:53 -0800107 return;
108
109 /* *INDENT-OFF* */
110 pool_foreach (swif, im->sw_interfaces,
111 ({
112 config = vec_elt_at_index (l2im->configs, swif->sw_if_index);
113 if (config->xconnect)
Florin Coras6c4dae22018-01-09 06:39:23 -0800114 send_l2_xconnect_details (reg, mp->context, swif->sw_if_index,
Matus Fabianf468e232016-12-02 06:00:53 -0800115 config->output_sw_if_index);
116 }));
117 /* *INDENT-ON* */
118}
119
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100120static void
121vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t * mp)
122{
123 int rv = 0;
124 vl_api_l2_fib_clear_table_reply_t *rmp;
125
Eyal Bari7537e712017-04-27 14:07:55 +0300126 /* Clear all MACs including static MACs */
127 l2fib_clear_table ();
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100128
129 REPLY_MACRO (VL_API_L2_FIB_CLEAR_TABLE_REPLY);
130}
131
132static void
133send_l2fib_table_entry (vpe_api_main_t * am,
Florin Coras6c4dae22018-01-09 06:39:23 -0800134 vl_api_registration_t * reg,
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100135 l2fib_entry_key_t * l2fe_key,
136 l2fib_entry_result_t * l2fe_res, u32 context)
137{
Ole Troan01384fe2017-05-12 11:55:35 +0200138 vl_api_l2_fib_table_details_t *mp;
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100139
140 mp = vl_msg_api_alloc (sizeof (*mp));
Dave Barachb7b92992018-10-17 10:38:51 -0400141 clib_memset (mp, 0, sizeof (*mp));
Ole Troan01384fe2017-05-12 11:55:35 +0200142 mp->_vl_msg_id = ntohs (VL_API_L2_FIB_TABLE_DETAILS);
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100143
144 mp->bd_id =
145 ntohl (l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
146
Mohsin Kazmi57938f62017-10-27 21:28:07 +0200147 clib_memcpy (mp->mac, l2fe_key->fields.mac, 6);
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100148 mp->sw_if_index = ntohl (l2fe_res->fields.sw_if_index);
Neale Ranns7341b6d2018-09-19 04:07:02 -0700149 mp->static_mac = (l2fib_entry_result_is_set_STATIC (l2fe_res) ? 1 : 0);
150 mp->filter_mac = (l2fib_entry_result_is_set_FILTER (l2fe_res) ? 1 : 0);
151 mp->bvi_mac = (l2fib_entry_result_is_set_BVI (l2fe_res) ? 1 : 0);
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100152 mp->context = context;
153
Florin Coras6c4dae22018-01-09 06:39:23 -0800154 vl_api_send_msg (reg, (u8 *) mp);
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100155}
156
157static void
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100158vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t * mp)
159{
160 vpe_api_main_t *am = &vpe_api_main;
161 bd_main_t *bdm = &bd_main;
162 l2fib_entry_key_t *l2fe_key = NULL;
163 l2fib_entry_result_t *l2fe_res = NULL;
164 u32 ni, bd_id = ntohl (mp->bd_id);
165 u32 bd_index;
Florin Coras6c4dae22018-01-09 06:39:23 -0800166 vl_api_registration_t *reg;
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100167 uword *p;
168
Florin Coras6c4dae22018-01-09 06:39:23 -0800169 reg = vl_api_client_index_to_registration (mp->client_index);
170 if (!reg)
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100171 return;
172
173 /* see l2fib_table_dump: ~0 means "any" */
174 if (bd_id == ~0)
175 bd_index = ~0;
176 else
177 {
178 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
179 if (p == 0)
180 return;
181
182 bd_index = p[0];
183 }
184
185 l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
186
187 vec_foreach_index (ni, l2fe_key)
188 {
Florin Coras6c4dae22018-01-09 06:39:23 -0800189 send_l2fib_table_entry (am, reg, vec_elt_at_index (l2fe_key, ni),
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100190 vec_elt_at_index (l2fe_res, ni), mp->context);
191 }
192 vec_free (l2fe_key);
193 vec_free (l2fe_res);
194}
195
196static void
197vl_api_l2fib_add_del_t_handler (vl_api_l2fib_add_del_t * mp)
198{
199 bd_main_t *bdm = &bd_main;
200 l2input_main_t *l2im = &l2input_main;
201 vl_api_l2fib_add_del_reply_t *rmp;
202 int rv = 0;
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100203 u32 bd_id = ntohl (mp->bd_id);
Eyal Bari31a71ab2017-06-25 14:42:33 +0300204 uword *p = hash_get (bdm->bd_index_by_bd_id, bd_id);
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100205
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100206 if (!p)
207 {
208 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
209 goto bad_sw_if_index;
210 }
Eyal Bari31a71ab2017-06-25 14:42:33 +0300211 u32 bd_index = p[0];
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100212
Mohsin Kazmi57938f62017-10-27 21:28:07 +0200213 u8 mac[6];
214
215 clib_memcpy (mac, mp->mac, 6);
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100216 if (mp->is_add)
217 {
Eyal Bari31a71ab2017-06-25 14:42:33 +0300218 if (mp->filter_mac)
219 l2fib_add_filter_entry (mac, bd_index);
220 else
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100221 {
Neale Rannsb54d0812018-09-06 06:22:56 -0700222 l2fib_entry_result_flags_t flags = L2FIB_ENTRY_RESULT_FLAG_NONE;
Eyal Bari31a71ab2017-06-25 14:42:33 +0300223 u32 sw_if_index = ntohl (mp->sw_if_index);
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100224 VALIDATE_SW_IF_INDEX (mp);
225 if (vec_len (l2im->configs) <= sw_if_index)
226 {
227 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
228 goto bad_sw_if_index;
229 }
230 else
231 {
232 l2_input_config_t *config;
233 config = vec_elt_at_index (l2im->configs, sw_if_index);
234 if (config->bridge == 0)
235 {
236 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
237 goto bad_sw_if_index;
238 }
239 }
Neale Rannsb54d0812018-09-06 06:22:56 -0700240 if (mp->static_mac)
241 flags |= L2FIB_ENTRY_RESULT_FLAG_STATIC;
242 if (mp->bvi_mac)
243 flags |= L2FIB_ENTRY_RESULT_FLAG_BVI;
244 l2fib_add_entry (mac, bd_index, sw_if_index, flags);
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100245 }
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100246 }
247 else
248 {
John Lo7dbd7262018-05-31 10:25:18 -0400249 u32 sw_if_index = ntohl (mp->sw_if_index);
250 if (l2fib_del_entry (mac, bd_index, sw_if_index))
251 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100252 }
253
254 BAD_SW_IF_INDEX_LABEL;
255
256 REPLY_MACRO (VL_API_L2FIB_ADD_DEL_REPLY);
257}
258
259static void
John Lo8d00fff2017-08-03 00:35:36 -0400260vl_api_want_l2_macs_events_t_handler (vl_api_want_l2_macs_events_t * mp)
261{
262 int rv = 0;
263 vl_api_want_l2_macs_events_reply_t *rmp;
264 l2learn_main_t *lm = &l2learn_main;
265 l2fib_main_t *fm = &l2fib_main;
266 u32 pid = ntohl (mp->pid);
267 u32 learn_limit = ntohl (mp->learn_limit);
268
269 if (mp->enable_disable)
270 {
271 if (lm->client_pid == 0)
272 {
273 lm->client_pid = pid;
274 lm->client_index = mp->client_index;
275
276 if (mp->max_macs_in_event)
277 fm->max_macs_in_event = mp->max_macs_in_event * 10;
278 else
279 fm->max_macs_in_event = L2FIB_EVENT_MAX_MACS_DEFAULT;
280
281 if (mp->scan_delay)
282 fm->event_scan_delay = (f64) (mp->scan_delay) * 10e-3;
283 else
284 fm->event_scan_delay = L2FIB_EVENT_SCAN_DELAY_DEFAULT;
285
286 /* change learn limit and flush all learned MACs */
287 if (learn_limit && (learn_limit < L2LEARN_DEFAULT_LIMIT))
288 lm->global_learn_limit = learn_limit;
289 else
290 lm->global_learn_limit = L2FIB_EVENT_LEARN_LIMIT_DEFAULT;
291
292 l2fib_flush_all_mac (vlib_get_main ());
293 }
294 else if (lm->client_pid != pid)
295 {
296 rv = VNET_API_ERROR_L2_MACS_EVENT_CLINET_PRESENT;
297 goto exit;
298 }
299 }
300 else if (lm->client_pid)
301 {
302 lm->client_pid = 0;
303 lm->client_index = 0;
John Lodbfa5742017-09-02 08:27:36 -0400304 if (learn_limit && (learn_limit < L2LEARN_DEFAULT_LIMIT))
John Loe531f4c2017-08-22 09:16:50 -0400305 lm->global_learn_limit = learn_limit;
306 else
307 lm->global_learn_limit = L2LEARN_DEFAULT_LIMIT;
John Lo8d00fff2017-08-03 00:35:36 -0400308 }
309
310exit:
311 REPLY_MACRO (VL_API_WANT_L2_MACS_EVENTS_REPLY);
312}
313
314static void
Eyal Barif24991c2017-04-05 05:33:21 +0300315vl_api_l2fib_flush_int_t_handler (vl_api_l2fib_flush_int_t * mp)
316{
317 int rv = 0;
318 vlib_main_t *vm = vlib_get_main ();
319 vl_api_l2fib_flush_int_reply_t *rmp;
320
321 VALIDATE_SW_IF_INDEX (mp);
322
323 u32 sw_if_index = ntohl (mp->sw_if_index);
324 l2fib_flush_int_mac (vm, sw_if_index);
325
326 BAD_SW_IF_INDEX_LABEL;
327 REPLY_MACRO (VL_API_L2FIB_FLUSH_INT_REPLY);
328}
329
330static void
Eyal Bari7537e712017-04-27 14:07:55 +0300331vl_api_l2fib_flush_all_t_handler (vl_api_l2fib_flush_all_t * mp)
332{
333 int rv = 0;
334 vl_api_l2fib_flush_all_reply_t *rmp;
335
336 l2fib_flush_all_mac (vlib_get_main ());
337 REPLY_MACRO (VL_API_L2FIB_FLUSH_ALL_REPLY);
338}
339
340static void
Eyal Barif24991c2017-04-05 05:33:21 +0300341vl_api_l2fib_flush_bd_t_handler (vl_api_l2fib_flush_bd_t * mp)
342{
343 int rv = 0;
344 vlib_main_t *vm = vlib_get_main ();
345 bd_main_t *bdm = &bd_main;
346 vl_api_l2fib_flush_bd_reply_t *rmp;
347
348 u32 bd_id = ntohl (mp->bd_id);
349 uword *p = hash_get (bdm->bd_index_by_bd_id, bd_id);
350 if (p == 0)
351 {
352 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
353 goto out;
354 }
355 l2fib_flush_bd_mac (vm, *p);
356out:
357 REPLY_MACRO (VL_API_L2FIB_FLUSH_BD_REPLY);
358}
359
360static void
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100361vl_api_l2_flags_t_handler (vl_api_l2_flags_t * mp)
362{
363 vl_api_l2_flags_reply_t *rmp;
364 int rv = 0;
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100365 u32 rbm = 0;
366
367 VALIDATE_SW_IF_INDEX (mp);
368
Eyal Barifead6702017-04-04 04:46:32 +0300369 u32 sw_if_index = ntohl (mp->sw_if_index);
John Lo8d00fff2017-08-03 00:35:36 -0400370 u32 flags = ntohl (mp->feature_bitmap);
371 u32 bitmap = 0;
372
373 if (flags & L2_LEARN)
374 bitmap |= L2INPUT_FEAT_LEARN;
375
376 if (flags & L2_FWD)
377 bitmap |= L2INPUT_FEAT_FWD;
378
379 if (flags & L2_FLOOD)
380 bitmap |= L2INPUT_FEAT_FLOOD;
381
382 if (flags & L2_UU_FLOOD)
383 bitmap |= L2INPUT_FEAT_UU_FLOOD;
384
385 if (flags & L2_ARP_TERM)
386 bitmap |= L2INPUT_FEAT_ARP_TERM;
387
388 rbm = l2input_intf_bitmap_enable (sw_if_index, bitmap, mp->is_set);
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100389
390 BAD_SW_IF_INDEX_LABEL;
391
392 /* *INDENT-OFF* */
393 REPLY_MACRO2(VL_API_L2_FLAGS_REPLY,
394 ({
395 rmp->resulting_feature_bitmap = ntohl(rbm);
396 }));
397 /* *INDENT-ON* */
398}
399
400static void
Eyal Barifead6702017-04-04 04:46:32 +0300401vl_api_bridge_domain_set_mac_age_t_handler (vl_api_bridge_domain_set_mac_age_t
402 * mp)
403{
404 vlib_main_t *vm = vlib_get_main ();
405 bd_main_t *bdm = &bd_main;
406 vl_api_bridge_domain_set_mac_age_reply_t *rmp;
407 int rv = 0;
408 u32 bd_id = ntohl (mp->bd_id);
Jon Loeliger1c7d4852017-05-02 11:06:23 -0500409 uword *p;
410
411 if (bd_id == 0)
412 {
413 rv = VNET_API_ERROR_BD_NOT_MODIFIABLE;
414 goto out;
415 }
416
417 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
Eyal Barifead6702017-04-04 04:46:32 +0300418 if (p == 0)
419 {
420 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
421 goto out;
422 }
423 bd_set_mac_age (vm, *p, mp->mac_age);
424out:
425 REPLY_MACRO (VL_API_BRIDGE_DOMAIN_SET_MAC_AGE_REPLY);
426}
427
428static void
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100429vl_api_bridge_domain_add_del_t_handler (vl_api_bridge_domain_add_del_t * mp)
430{
Eyal Barib1352ed2017-04-07 23:14:17 +0300431 l2_bridge_domain_add_del_args_t a = {
432 .is_add = mp->is_add,
433 .flood = mp->flood,
434 .uu_flood = mp->uu_flood,
435 .forward = mp->forward,
436 .learn = mp->learn,
437 .arp_term = mp->arp_term,
438 .mac_age = mp->mac_age,
439 .bd_id = ntohl (mp->bd_id),
Jerome Tollet48304142017-09-05 12:13:22 +0100440 .bd_tag = mp->bd_tag
Eyal Barib1352ed2017-04-07 23:14:17 +0300441 };
442
443 int rv = bd_add_del (&a);
444
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100445 vl_api_bridge_domain_add_del_reply_t *rmp;
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100446 REPLY_MACRO (VL_API_BRIDGE_DOMAIN_ADD_DEL_REPLY);
447}
448
449static void
Ole Troan01384fe2017-05-12 11:55:35 +0200450send_bridge_domain_details (l2input_main_t * l2im,
Florin Coras6c4dae22018-01-09 06:39:23 -0800451 vl_api_registration_t * reg,
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100452 l2_bridge_domain_t * bd_config,
453 u32 n_sw_ifs, u32 context)
454{
455 vl_api_bridge_domain_details_t *mp;
Ole Troan01384fe2017-05-12 11:55:35 +0200456 l2_flood_member_t *m;
457 vl_api_bridge_domain_sw_if_t *sw_ifs;
458 l2_input_config_t *input_cfg;
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100459
Ole Troan01384fe2017-05-12 11:55:35 +0200460 mp = vl_msg_api_alloc (sizeof (*mp) +
461 (n_sw_ifs * sizeof (vl_api_bridge_domain_sw_if_t)));
Dave Barachb7b92992018-10-17 10:38:51 -0400462 clib_memset (mp, 0, sizeof (*mp));
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100463 mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_DETAILS);
464 mp->bd_id = ntohl (bd_config->bd_id);
465 mp->flood = bd_feature_flood (bd_config);
466 mp->uu_flood = bd_feature_uu_flood (bd_config);
467 mp->forward = bd_feature_forward (bd_config);
468 mp->learn = bd_feature_learn (bd_config);
469 mp->arp_term = bd_feature_arp_term (bd_config);
470 mp->bvi_sw_if_index = ntohl (bd_config->bvi_sw_if_index);
Neale Rannsb4743802018-09-05 09:13:57 -0700471 mp->uu_fwd_sw_if_index = ntohl (bd_config->uu_fwd_sw_if_index);
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100472 mp->mac_age = bd_config->mac_age;
Jerome Tollet48304142017-09-05 12:13:22 +0100473 if (bd_config->bd_tag)
474 {
475 strncpy ((char *) mp->bd_tag, (char *) bd_config->bd_tag,
476 ARRAY_LEN (mp->bd_tag) - 1);
477 mp->bd_tag[ARRAY_LEN (mp->bd_tag) - 1] = 0;
478 }
479
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100480 mp->context = context;
481
Ole Troan01384fe2017-05-12 11:55:35 +0200482 sw_ifs = (vl_api_bridge_domain_sw_if_t *) mp->sw_if_details;
483 vec_foreach (m, bd_config->members)
484 {
485 sw_ifs->sw_if_index = ntohl (m->sw_if_index);
486 input_cfg = vec_elt_at_index (l2im->configs, m->sw_if_index);
487 sw_ifs->shg = input_cfg->shg;
488 sw_ifs++;
489 mp->n_sw_ifs++;
490 }
491 mp->n_sw_ifs = htonl (mp->n_sw_ifs);
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100492
Florin Coras6c4dae22018-01-09 06:39:23 -0800493 vl_api_send_msg (reg, (u8 *) mp);
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100494}
495
496static void
497vl_api_bridge_domain_dump_t_handler (vl_api_bridge_domain_dump_t * mp)
498{
499 bd_main_t *bdm = &bd_main;
500 l2input_main_t *l2im = &l2input_main;
Florin Coras6c4dae22018-01-09 06:39:23 -0800501 vl_api_registration_t *reg;
502 u32 bd_id, bd_index, end;
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100503
Florin Coras6c4dae22018-01-09 06:39:23 -0800504 reg = vl_api_client_index_to_registration (mp->client_index);
505 if (!reg)
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100506 return;
507
Florin Coras6c4dae22018-01-09 06:39:23 -0800508 bd_id = ntohl (mp->bd_id);
Jon Loeliger1c7d4852017-05-02 11:06:23 -0500509 if (bd_id == 0)
510 return;
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100511
Eyal Bari259fca72017-05-14 10:38:39 +0300512 if (bd_id == ~0)
513 bd_index = 0, end = vec_len (l2im->bd_configs);
514 else
515 {
516 bd_index = bd_find_index (bdm, bd_id);
517 if (bd_index == ~0)
518 return;
519
520 end = bd_index + 1;
521 }
Jon Loeliger1c7d4852017-05-02 11:06:23 -0500522
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100523 for (; bd_index < end; bd_index++)
524 {
Eyal Bari259fca72017-05-14 10:38:39 +0300525 l2_bridge_domain_t *bd_config =
526 l2input_bd_config_from_index (l2im, bd_index);
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100527 /* skip dummy bd_id 0 */
528 if (bd_config && (bd_config->bd_id > 0))
Florin Coras6c4dae22018-01-09 06:39:23 -0800529 send_bridge_domain_details (l2im, reg, bd_config,
Ole Troan01384fe2017-05-12 11:55:35 +0200530 vec_len (bd_config->members),
531 mp->context);
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100532 }
533}
534
Neale Rannsb4743802018-09-05 09:13:57 -0700535static bd_flags_t
536bd_flags_decode (vl_api_bd_flags_t v)
537{
538 bd_flags_t f = L2_NONE;
539
540 v = ntohl (v);
541
542 if (v & BRIDGE_API_FLAG_LEARN)
543 f |= L2_LEARN;
544 if (v & BRIDGE_API_FLAG_FWD)
545 f |= L2_FWD;
546 if (v & BRIDGE_API_FLAG_FLOOD)
547 f |= L2_FLOOD;
548 if (v & BRIDGE_API_FLAG_UU_FLOOD)
549 f |= L2_UU_FLOOD;
550 if (v & BRIDGE_API_FLAG_ARP_TERM)
551 f |= L2_ARP_TERM;
552
553 return (f);
554}
555
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100556static void
557vl_api_bridge_flags_t_handler (vl_api_bridge_flags_t * mp)
558{
559 vlib_main_t *vm = vlib_get_main ();
560 bd_main_t *bdm = &bd_main;
561 vl_api_bridge_flags_reply_t *rmp;
Dave Barach98d6b612019-01-03 09:30:00 -0500562 u32 bitmap = 0;
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100563 int rv = 0;
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100564
Neale Rannsb4743802018-09-05 09:13:57 -0700565 bd_flags_t flags = bd_flags_decode (mp->flags);
Eyal Bari259fca72017-05-14 10:38:39 +0300566 u32 bd_id = ntohl (mp->bd_id);
Jon Loeliger1c7d4852017-05-02 11:06:23 -0500567 if (bd_id == 0)
568 {
569 rv = VNET_API_ERROR_BD_NOT_MODIFIABLE;
570 goto out;
571 }
572
Eyal Bari259fca72017-05-14 10:38:39 +0300573 u32 bd_index = bd_find_index (bdm, bd_id);
574 if (bd_index == ~0)
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100575 {
576 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
577 goto out;
578 }
579
Dave Barach98d6b612019-01-03 09:30:00 -0500580 bitmap = bd_set_flags (vm, bd_index, flags, mp->is_set);
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100581
582out:
583 /* *INDENT-OFF* */
584 REPLY_MACRO2(VL_API_BRIDGE_FLAGS_REPLY,
585 ({
John Lo8d00fff2017-08-03 00:35:36 -0400586 rmp->resulting_feature_bitmap = ntohl(bitmap);
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100587 }));
588 /* *INDENT-ON* */
589}
Matus Fabianf468e232016-12-02 06:00:53 -0800590
Pavel Kotucekadec5872017-01-25 08:50:53 +0100591static void
592 vl_api_l2_interface_vlan_tag_rewrite_t_handler
593 (vl_api_l2_interface_vlan_tag_rewrite_t * mp)
594{
595 int rv = 0;
596 vl_api_l2_interface_vlan_tag_rewrite_reply_t *rmp;
597 vnet_main_t *vnm = vnet_get_main ();
598 vlib_main_t *vm = vlib_get_main ();
599 u32 vtr_op;
600
601 VALIDATE_SW_IF_INDEX (mp);
602
603 vtr_op = ntohl (mp->vtr_op);
604
605 /* The L2 code is unsuspicious */
606 switch (vtr_op)
607 {
608 case L2_VTR_DISABLED:
609 case L2_VTR_PUSH_1:
610 case L2_VTR_PUSH_2:
611 case L2_VTR_POP_1:
612 case L2_VTR_POP_2:
613 case L2_VTR_TRANSLATE_1_1:
614 case L2_VTR_TRANSLATE_1_2:
615 case L2_VTR_TRANSLATE_2_1:
616 case L2_VTR_TRANSLATE_2_2:
617 break;
618
619 default:
620 rv = VNET_API_ERROR_INVALID_VALUE;
621 goto bad_sw_if_index;
622 }
623
624 rv = l2vtr_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op,
625 ntohl (mp->push_dot1q), ntohl (mp->tag1),
626 ntohl (mp->tag2));
627
628 BAD_SW_IF_INDEX_LABEL;
629
630 REPLY_MACRO (VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
631}
632
633static void
634 vl_api_l2_interface_pbb_tag_rewrite_t_handler
635 (vl_api_l2_interface_pbb_tag_rewrite_t * mp)
636{
637 vl_api_l2_interface_pbb_tag_rewrite_reply_t *rmp;
638 vnet_main_t *vnm = vnet_get_main ();
639 vlib_main_t *vm = vlib_get_main ();
640 u32 vtr_op;
641 int rv = 0;
642
643 VALIDATE_SW_IF_INDEX (mp);
644
645 vtr_op = ntohl (mp->vtr_op);
646
647 switch (vtr_op)
648 {
649 case L2_VTR_DISABLED:
650 case L2_VTR_PUSH_2:
651 case L2_VTR_POP_2:
652 case L2_VTR_TRANSLATE_2_1:
653 break;
654
655 default:
656 rv = VNET_API_ERROR_INVALID_VALUE;
657 goto bad_sw_if_index;
658 }
659
660 rv = l2pbb_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op,
661 mp->b_dmac, mp->b_smac, ntohs (mp->b_vlanid),
662 ntohl (mp->i_sid), ntohs (mp->outer_tag));
663
664 BAD_SW_IF_INDEX_LABEL;
665
666 REPLY_MACRO (VL_API_L2_INTERFACE_PBB_TAG_REWRITE_REPLY);
667}
668
Neale Rannsb8d44812017-11-10 06:53:54 -0800669static void
670 vl_api_sw_interface_set_l2_xconnect_t_handler
671 (vl_api_sw_interface_set_l2_xconnect_t * mp)
672{
673 vl_api_sw_interface_set_l2_xconnect_reply_t *rmp;
674 int rv = 0;
675 u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
676 u32 tx_sw_if_index = ntohl (mp->tx_sw_if_index);
677 vlib_main_t *vm = vlib_get_main ();
678 vnet_main_t *vnm = vnet_get_main ();
679
680 VALIDATE_RX_SW_IF_INDEX (mp);
681
682 if (mp->enable)
683 {
684 VALIDATE_TX_SW_IF_INDEX (mp);
685 rv = set_int_l2_mode (vm, vnm, MODE_L2_XC,
Neale Rannsb4743802018-09-05 09:13:57 -0700686 rx_sw_if_index, 0,
687 L2_BD_PORT_TYPE_NORMAL, 0, tx_sw_if_index);
Neale Rannsb8d44812017-11-10 06:53:54 -0800688 }
689 else
690 {
Neale Rannsb4743802018-09-05 09:13:57 -0700691 rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0,
692 L2_BD_PORT_TYPE_NORMAL, 0, 0);
Neale Rannsb8d44812017-11-10 06:53:54 -0800693 }
694
Alexander Chernavine178b272018-09-24 05:42:01 -0400695 switch (rv)
696 {
697 case MODE_ERROR_ETH:
698 rv = VNET_API_ERROR_NON_ETHERNET;
699 break;
700 case MODE_ERROR_BVI_DEF:
701 rv = VNET_API_ERROR_BD_ALREADY_HAS_BVI;
702 break;
703 }
704
Neale Rannsb8d44812017-11-10 06:53:54 -0800705 BAD_RX_SW_IF_INDEX_LABEL;
706 BAD_TX_SW_IF_INDEX_LABEL;
707
708 REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY);
709}
710
Neale Rannsb4743802018-09-05 09:13:57 -0700711static int
712l2_bd_port_type_decode (vl_api_l2_port_type_t v, l2_bd_port_type_t * l)
713{
714 v = clib_net_to_host_u32 (v);
715
716 switch (v)
717 {
718 case L2_API_PORT_TYPE_NORMAL:
719 *l = L2_BD_PORT_TYPE_NORMAL;
720 return 0;
721 case L2_API_PORT_TYPE_BVI:
722 *l = L2_BD_PORT_TYPE_BVI;
723 return 0;
724 case L2_API_PORT_TYPE_UU_FWD:
725 *l = L2_BD_PORT_TYPE_UU_FWD;
726 return 0;
727 }
728
729 return (VNET_API_ERROR_INVALID_VALUE);
730}
731
Neale Rannsb8d44812017-11-10 06:53:54 -0800732static void
733 vl_api_sw_interface_set_l2_bridge_t_handler
734 (vl_api_sw_interface_set_l2_bridge_t * mp)
735{
736 bd_main_t *bdm = &bd_main;
737 vl_api_sw_interface_set_l2_bridge_reply_t *rmp;
738 int rv = 0;
739 vlib_main_t *vm = vlib_get_main ();
740 vnet_main_t *vnm = vnet_get_main ();
Neale Rannsb4743802018-09-05 09:13:57 -0700741 l2_bd_port_type_t pt;
Neale Rannsb8d44812017-11-10 06:53:54 -0800742
743 VALIDATE_RX_SW_IF_INDEX (mp);
744 u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
Neale Rannsb4743802018-09-05 09:13:57 -0700745 rv = l2_bd_port_type_decode (mp->port_type, &pt);
Neale Rannsb8d44812017-11-10 06:53:54 -0800746
Neale Rannsb4743802018-09-05 09:13:57 -0700747 if (0 != rv)
748 goto out;
Neale Rannsb8d44812017-11-10 06:53:54 -0800749 if (mp->enable)
750 {
751 VALIDATE_BD_ID (mp);
752 u32 bd_id = ntohl (mp->bd_id);
753 u32 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
Neale Rannsb4743802018-09-05 09:13:57 -0700754
Neale Rannsb8d44812017-11-10 06:53:54 -0800755 rv = set_int_l2_mode (vm, vnm, MODE_L2_BRIDGE,
Neale Rannsb4743802018-09-05 09:13:57 -0700756 rx_sw_if_index, bd_index, pt, mp->shg, 0);
Neale Rannsb8d44812017-11-10 06:53:54 -0800757 }
758 else
759 {
Neale Rannsb4743802018-09-05 09:13:57 -0700760 rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, pt, 0, 0);
Neale Rannsb8d44812017-11-10 06:53:54 -0800761 }
762
Alexander Chernavine178b272018-09-24 05:42:01 -0400763 switch (rv)
764 {
765 case MODE_ERROR_ETH:
766 rv = VNET_API_ERROR_NON_ETHERNET;
767 break;
768 case MODE_ERROR_BVI_DEF:
769 rv = VNET_API_ERROR_BD_ALREADY_HAS_BVI;
770 break;
771 }
772
Neale Rannsb8d44812017-11-10 06:53:54 -0800773 BAD_RX_SW_IF_INDEX_LABEL;
774 BAD_BD_ID_LABEL;
Neale Rannsb4743802018-09-05 09:13:57 -0700775out:
Neale Rannsb8d44812017-11-10 06:53:54 -0800776 REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY);
777}
778
779static void
Mohsin Kazmi5d82d2f2018-08-13 19:17:54 +0200780send_bd_ip_mac_entry (vpe_api_main_t * am,
781 vl_api_registration_t * reg,
782 u32 bd_id, u8 is_ipv6,
783 u8 * ip_address, u8 * mac_address, u32 context)
784{
785 vl_api_bd_ip_mac_details_t *mp;
786
787 mp = vl_msg_api_alloc (sizeof (*mp));
Dave Barachb7b92992018-10-17 10:38:51 -0400788 clib_memset (mp, 0, sizeof (*mp));
Mohsin Kazmi5d82d2f2018-08-13 19:17:54 +0200789 mp->_vl_msg_id = ntohs (VL_API_BD_IP_MAC_DETAILS);
790
791 mp->bd_id = ntohl (bd_id);
792
793 clib_memcpy (mp->mac_address, mac_address, 6);
794 mp->is_ipv6 = is_ipv6;
795 clib_memcpy (mp->ip_address, ip_address, (is_ipv6) ? 16 : 4);
796 mp->context = context;
797
798 vl_api_send_msg (reg, (u8 *) mp);
799}
800
801static void
802vl_api_bd_ip_mac_dump_t_handler (vl_api_bd_ip_mac_dump_t * mp)
803{
804 vpe_api_main_t *am = &vpe_api_main;
805 bd_main_t *bdm = &bd_main;
806 l2_bridge_domain_t *bd_config;
807 u32 bd_id = ntohl (mp->bd_id);
Mohsin Kazmib24dfec2018-08-23 12:24:19 +0200808 u32 bd_index, start, end;
Mohsin Kazmi5d82d2f2018-08-13 19:17:54 +0200809 vl_api_registration_t *reg;
810 uword *p;
811
812 reg = vl_api_client_index_to_registration (mp->client_index);
813 if (!reg)
814 return;
815
Mohsin Kazmi5d82d2f2018-08-13 19:17:54 +0200816 /* see bd_id: ~0 means "any" */
817 if (bd_id == ~0)
Mohsin Kazmib24dfec2018-08-23 12:24:19 +0200818 {
819 start = 1;
820 end = vec_len (l2input_main.bd_configs);
821 }
Mohsin Kazmi5d82d2f2018-08-13 19:17:54 +0200822 else
823 {
824 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
825 if (p == 0)
826 return;
827
828 bd_index = p[0];
829 vec_validate (l2input_main.bd_configs, bd_index);
830 start = bd_index;
831 end = start + 1;
832 }
833
834 for (bd_index = start; bd_index < end; bd_index++)
835 {
836 bd_config = vec_elt_at_index (l2input_main.bd_configs, bd_index);
837 if (bd_is_valid (bd_config))
838 {
839 ip4_address_t ip4_addr;
840 ip6_address_t *ip6_addr;
841 u64 mac_addr;
842 bd_id = bd_config->bd_id;
843
844 /* *INDENT-OFF* */
845 hash_foreach (ip4_addr.as_u32, mac_addr, bd_config->mac_by_ip4,
846 ({
847 send_bd_ip_mac_entry (am, reg, bd_id, 0, (u8 *) &(ip4_addr.as_u8), (u8 *) &mac_addr, mp->context);
848 }));
849
850 hash_foreach_mem (ip6_addr, mac_addr, bd_config->mac_by_ip6,
851 ({
852 send_bd_ip_mac_entry (am, reg, bd_id, 1, (u8 *) &(ip6_addr->as_u8), (u8 *) &mac_addr, mp->context);
853 }));
854 /* *INDENT-ON* */
855 }
856 }
857}
858
859static void
Neale Rannsb8d44812017-11-10 06:53:54 -0800860vl_api_bd_ip_mac_add_del_t_handler (vl_api_bd_ip_mac_add_del_t * mp)
861{
Neale Ranns4d5b9172018-10-24 02:57:49 -0700862 ip46_address_t ip_addr = ip46_address_initializer;
Neale Rannsb8d44812017-11-10 06:53:54 -0800863 vl_api_bd_ip_mac_add_del_reply_t *rmp;
Neale Ranns4d5b9172018-10-24 02:57:49 -0700864 bd_main_t *bdm = &bd_main;
865 u32 bd_index, bd_id;
866 mac_address_t mac;
867 ip46_type_t type;
Neale Rannsb8d44812017-11-10 06:53:54 -0800868 int rv = 0;
Neale Rannsb8d44812017-11-10 06:53:54 -0800869 uword *p;
870
Neale Ranns4d5b9172018-10-24 02:57:49 -0700871 bd_id = ntohl (mp->bd_id);
872
Neale Rannsb8d44812017-11-10 06:53:54 -0800873 if (bd_id == 0)
874 {
875 rv = VNET_API_ERROR_BD_NOT_MODIFIABLE;
876 goto out;
877 }
878
879 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
880 if (p == 0)
881 {
882 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
883 goto out;
884 }
Neale Rannsb8d44812017-11-10 06:53:54 -0800885 bd_index = p[0];
Neale Ranns4d5b9172018-10-24 02:57:49 -0700886
887 type = ip_address_decode (&mp->ip, &ip_addr);
Ole Troan8006c6a2018-12-17 12:02:26 +0100888 mac_address_decode (mp->mac, &mac);
Neale Ranns4d5b9172018-10-24 02:57:49 -0700889
890 if (bd_add_del_ip_mac (bd_index, type, &ip_addr, &mac, mp->is_add))
Neale Rannsb8d44812017-11-10 06:53:54 -0800891 rv = VNET_API_ERROR_UNSPECIFIED;
892
893out:
894 REPLY_MACRO (VL_API_BD_IP_MAC_ADD_DEL_REPLY);
895}
896
John Loe26c81f2019-01-07 15:16:33 -0500897static void
898vl_api_bd_ip_mac_flush_t_handler (vl_api_bd_ip_mac_flush_t * mp)
899{
900 vl_api_bd_ip_mac_flush_reply_t *rmp;
901 bd_main_t *bdm = &bd_main;
902 u32 bd_index, bd_id;
903 int rv = 0;
904 uword *p;
905
906 bd_id = ntohl (mp->bd_id);
907
908 if (bd_id == 0)
909 {
910 rv = VNET_API_ERROR_BD_NOT_MODIFIABLE;
911 goto out;
912 }
913
914 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
915 if (p == 0)
916 {
917 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
918 goto out;
919 }
920 bd_index = p[0];
921
922 bd_flush_ip_mac (bd_index);
923
924out:
925 REPLY_MACRO (VL_API_BD_IP_MAC_FLUSH_REPLY);
926}
927
Neale Rannsb8d44812017-11-10 06:53:54 -0800928extern void l2_efp_filter_configure (vnet_main_t * vnet_main,
Neale Ranns6b9b41c2018-07-23 05:47:09 -0400929 u32 sw_if_index, u8 enable);
Neale Rannsb8d44812017-11-10 06:53:54 -0800930
931static void
932vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *
933 mp)
934{
935 int rv;
936 vl_api_l2_interface_efp_filter_reply_t *rmp;
937 vnet_main_t *vnm = vnet_get_main ();
938
Neale Ranns6b9b41c2018-07-23 05:47:09 -0400939 VALIDATE_SW_IF_INDEX (mp);
940
Neale Rannsb8d44812017-11-10 06:53:54 -0800941 // enable/disable the feature
Neale Ranns6b9b41c2018-07-23 05:47:09 -0400942 l2_efp_filter_configure (vnm, ntohl (mp->sw_if_index), mp->enable_disable);
Neale Rannsb8d44812017-11-10 06:53:54 -0800943 rv = vnm->api_errno;
944
Neale Ranns6b9b41c2018-07-23 05:47:09 -0400945 BAD_SW_IF_INDEX_LABEL;
Neale Rannsb8d44812017-11-10 06:53:54 -0800946 REPLY_MACRO (VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
947}
948
949static void
950vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t * mp)
951{
952 extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
953 int is_add);
954 vl_api_l2_patch_add_del_reply_t *rmp;
955 int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
956 int is_add);
957 int rv = 0;
958
959 VALIDATE_RX_SW_IF_INDEX (mp);
960 VALIDATE_TX_SW_IF_INDEX (mp);
961
962 rv = vnet_l2_patch_add_del (ntohl (mp->rx_sw_if_index),
963 ntohl (mp->tx_sw_if_index),
964 (int) (mp->is_add != 0));
965
966 BAD_RX_SW_IF_INDEX_LABEL;
967 BAD_TX_SW_IF_INDEX_LABEL;
968
969 REPLY_MACRO (VL_API_L2_PATCH_ADD_DEL_REPLY);
970}
971
972static void
973vl_api_sw_interface_set_vpath_t_handler (vl_api_sw_interface_set_vpath_t * mp)
974{
975 vl_api_sw_interface_set_vpath_reply_t *rmp;
976 int rv = 0;
977 u32 sw_if_index = ntohl (mp->sw_if_index);
978
979 VALIDATE_SW_IF_INDEX (mp);
980
981 l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_VPATH, mp->enable);
982 vnet_feature_enable_disable ("ip4-unicast", "vpath-input-ip4",
983 sw_if_index, mp->enable, 0, 0);
984 vnet_feature_enable_disable ("ip4-multicast", "vpath-input-ip4",
985 sw_if_index, mp->enable, 0, 0);
986 vnet_feature_enable_disable ("ip6-unicast", "vpath-input-ip6",
987 sw_if_index, mp->enable, 0, 0);
988 vnet_feature_enable_disable ("ip6-multicast", "vpath-input-ip6",
989 sw_if_index, mp->enable, 0, 0);
990
991 BAD_SW_IF_INDEX_LABEL;
992
993 REPLY_MACRO (VL_API_SW_INTERFACE_SET_VPATH_REPLY);
994}
995
Matus Fabianf468e232016-12-02 06:00:53 -0800996/*
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100997 * l2_api_hookup
Matus Fabianf468e232016-12-02 06:00:53 -0800998 * Add vpe's API message handlers to the table.
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -0700999 * vlib has already mapped shared memory and
Matus Fabianf468e232016-12-02 06:00:53 -08001000 * added the client registration handlers.
1001 * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
1002 */
1003#define vl_msg_name_crc_list
1004#include <vnet/vnet_all_api_h.h>
1005#undef vl_msg_name_crc_list
1006
1007static void
1008setup_message_id_table (api_main_t * am)
1009{
1010#define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
1011 foreach_vl_msg_name_crc_l2;
1012#undef _
1013}
1014
1015static clib_error_t *
1016l2_api_hookup (vlib_main_t * vm)
1017{
1018 api_main_t *am = &api_main;
1019
1020#define _(N,n) \
1021 vl_msg_api_set_handlers(VL_API_##N, #n, \
1022 vl_api_##n##_t_handler, \
1023 vl_noop_handler, \
1024 vl_api_##n##_t_endian, \
1025 vl_api_##n##_t_print, \
1026 sizeof(vl_api_##n##_t), 1);
1027 foreach_vpe_api_msg;
1028#undef _
1029
1030 /*
1031 * Set up the (msg_name, crc, message-id) table
1032 */
1033 setup_message_id_table (am);
1034
1035 return 0;
1036}
1037
1038VLIB_API_INIT_FUNCTION (l2_api_hookup);
1039
1040/*
1041 * fd.io coding-style-patch-verification: ON
1042 *
1043 * Local Variables:
1044 * eval: (c-set-style "gnu")
1045 * End:
1046 */