2 *------------------------------------------------------------------
3 * Copyright (c) 2018 Cisco and/or its affiliates.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *------------------------------------------------------------------
18 #include <vnet/vnet.h>
19 #include <vnet/plugin/plugin.h>
21 #include <vnet/interface.h>
22 #include <vnet/api_errno.h>
23 #include <vnet/ip/ip_types_api.h>
24 #include <vnet/ethernet/ethernet_types_api.h>
25 #include <vpp/app/version.h>
28 #include <gbp/gbp_learn.h>
29 #include <gbp/gbp_itf.h>
30 #include <gbp/gbp_vxlan.h>
31 #include <gbp/gbp_bridge_domain.h>
32 #include <gbp/gbp_route_domain.h>
33 #include <gbp/gbp_ext_itf.h>
34 #include <gbp/gbp_contract.h>
36 #include <vlibapi/api.h>
37 #include <vlibmemory/api.h>
39 /* define message IDs */
40 #include <gbp/gbp_msg_enum.h>
42 #define vl_typedefs /* define message structures */
43 #include <gbp/gbp_all_api_h.h>
46 #define vl_endianfun /* define message structures */
47 #include <gbp/gbp_all_api_h.h>
50 /* instantiate all the print functions we know about */
51 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
53 #include <gbp/gbp_all_api_h.h>
56 /* Get the API version number */
57 #define vl_api_version(n,v) static u32 api_version=(v);
58 #include <gbp/gbp_all_api_h.h>
61 #include <vlibapi/api_helper_macros.h>
63 #define foreach_gbp_api_msg \
64 _(GBP_ENDPOINT_ADD, gbp_endpoint_add) \
65 _(GBP_ENDPOINT_DEL, gbp_endpoint_del) \
66 _(GBP_ENDPOINT_DUMP, gbp_endpoint_dump) \
67 _(GBP_SUBNET_ADD_DEL, gbp_subnet_add_del) \
68 _(GBP_SUBNET_DUMP, gbp_subnet_dump) \
69 _(GBP_ENDPOINT_GROUP_ADD, gbp_endpoint_group_add) \
70 _(GBP_ENDPOINT_GROUP_DEL, gbp_endpoint_group_del) \
71 _(GBP_ENDPOINT_GROUP_DUMP, gbp_endpoint_group_dump) \
72 _(GBP_BRIDGE_DOMAIN_ADD, gbp_bridge_domain_add) \
73 _(GBP_BRIDGE_DOMAIN_DEL, gbp_bridge_domain_del) \
74 _(GBP_BRIDGE_DOMAIN_DUMP, gbp_bridge_domain_dump) \
75 _(GBP_ROUTE_DOMAIN_ADD, gbp_route_domain_add) \
76 _(GBP_ROUTE_DOMAIN_DEL, gbp_route_domain_del) \
77 _(GBP_ROUTE_DOMAIN_DUMP, gbp_route_domain_dump) \
78 _(GBP_RECIRC_ADD_DEL, gbp_recirc_add_del) \
79 _(GBP_RECIRC_DUMP, gbp_recirc_dump) \
80 _(GBP_EXT_ITF_ADD_DEL, gbp_ext_itf_add_del) \
81 _(GBP_EXT_ITF_DUMP, gbp_ext_itf_dump) \
82 _(GBP_CONTRACT_ADD_DEL, gbp_contract_add_del) \
83 _(GBP_CONTRACT_DUMP, gbp_contract_dump) \
84 _(GBP_VXLAN_TUNNEL_ADD, gbp_vxlan_tunnel_add) \
85 _(GBP_VXLAN_TUNNEL_DEL, gbp_vxlan_tunnel_del) \
86 _(GBP_VXLAN_TUNNEL_DUMP, gbp_vxlan_tunnel_dump)
90 static u16 msg_id_base;
92 #define GBP_MSG_BASE msg_id_base
94 static gbp_endpoint_flags_t
95 gbp_endpoint_flags_decode (vl_api_gbp_endpoint_flags_t v)
97 gbp_endpoint_flags_t f = GBP_ENDPOINT_FLAG_NONE;
101 if (v & GBP_API_ENDPOINT_FLAG_BOUNCE)
102 f |= GBP_ENDPOINT_FLAG_BOUNCE;
103 if (v & GBP_API_ENDPOINT_FLAG_REMOTE)
104 f |= GBP_ENDPOINT_FLAG_REMOTE;
105 if (v & GBP_API_ENDPOINT_FLAG_LEARNT)
106 f |= GBP_ENDPOINT_FLAG_LEARNT;
107 if (v & GBP_API_ENDPOINT_FLAG_EXTERNAL)
108 f |= GBP_ENDPOINT_FLAG_EXTERNAL;
113 static vl_api_gbp_endpoint_flags_t
114 gbp_endpoint_flags_encode (gbp_endpoint_flags_t f)
116 vl_api_gbp_endpoint_flags_t v = 0;
119 if (f & GBP_ENDPOINT_FLAG_BOUNCE)
120 v |= GBP_API_ENDPOINT_FLAG_BOUNCE;
121 if (f & GBP_ENDPOINT_FLAG_REMOTE)
122 v |= GBP_API_ENDPOINT_FLAG_REMOTE;
123 if (f & GBP_ENDPOINT_FLAG_LEARNT)
124 v |= GBP_API_ENDPOINT_FLAG_LEARNT;
125 if (f & GBP_ENDPOINT_FLAG_EXTERNAL)
126 v |= GBP_API_ENDPOINT_FLAG_EXTERNAL;
134 vl_api_gbp_endpoint_add_t_handler (vl_api_gbp_endpoint_add_t * mp)
136 vl_api_gbp_endpoint_add_reply_t *rmp;
137 gbp_endpoint_flags_t gef;
138 u32 sw_if_index, handle;
143 VALIDATE_SW_IF_INDEX (&(mp->endpoint));
145 gef = gbp_endpoint_flags_decode (mp->endpoint.flags), ips = NULL;
146 sw_if_index = ntohl (mp->endpoint.sw_if_index);
148 if (mp->endpoint.n_ips)
150 vec_validate (ips, mp->endpoint.n_ips - 1);
152 vec_foreach_index (ii, ips)
154 ip_address_decode (&mp->endpoint.ips[ii], &ips[ii]);
157 mac_address_decode (mp->endpoint.mac, &mac);
159 if (GBP_ENDPOINT_FLAG_REMOTE & gef)
161 ip46_address_t tun_src, tun_dst;
163 ip_address_decode (&mp->endpoint.tun.src, &tun_src);
164 ip_address_decode (&mp->endpoint.tun.dst, &tun_dst);
166 rv = gbp_endpoint_update_and_lock (GBP_ENDPOINT_SRC_CP,
167 sw_if_index, ips, &mac,
168 INDEX_INVALID, INDEX_INVALID,
169 ntohs (mp->endpoint.sclass),
170 gef, &tun_src, &tun_dst, &handle);
174 rv = gbp_endpoint_update_and_lock (GBP_ENDPOINT_SRC_CP,
175 sw_if_index, ips, &mac,
176 INDEX_INVALID, INDEX_INVALID,
177 ntohs (mp->endpoint.sclass),
178 gef, NULL, NULL, &handle);
181 BAD_SW_IF_INDEX_LABEL;
184 REPLY_MACRO2 (VL_API_GBP_ENDPOINT_ADD_REPLY + GBP_MSG_BASE,
186 rmp->handle = htonl (handle);
192 vl_api_gbp_endpoint_del_t_handler (vl_api_gbp_endpoint_del_t * mp)
194 vl_api_gbp_endpoint_del_reply_t *rmp;
197 gbp_endpoint_unlock (GBP_ENDPOINT_SRC_CP, ntohl (mp->handle));
199 REPLY_MACRO (VL_API_GBP_ENDPOINT_DEL_REPLY + GBP_MSG_BASE);
202 typedef struct gbp_walk_ctx_t_
204 vl_api_registration_t *reg;
209 gbp_endpoint_send_details (index_t gei, void *args)
211 vl_api_gbp_endpoint_details_t *mp;
212 gbp_endpoint_loc_t *gel;
213 gbp_endpoint_fwd_t *gef;
219 ge = gbp_endpoint_get (gei);
221 n_ips = vec_len (ge->ge_key.gek_ips);
222 mp = vl_msg_api_alloc (sizeof (*mp) + (sizeof (*mp->endpoint.ips) * n_ips));
226 clib_memset (mp, 0, sizeof (*mp));
227 mp->_vl_msg_id = ntohs (VL_API_GBP_ENDPOINT_DETAILS + GBP_MSG_BASE);
228 mp->context = ctx->context;
230 gel = &ge->ge_locs[0];
233 if (gbp_endpoint_is_remote (ge))
235 mp->endpoint.sw_if_index = ntohl (gel->tun.gel_parent_sw_if_index);
236 ip_address_encode (&gel->tun.gel_src, IP46_TYPE_ANY,
237 &mp->endpoint.tun.src);
238 ip_address_encode (&gel->tun.gel_dst, IP46_TYPE_ANY,
239 &mp->endpoint.tun.dst);
243 mp->endpoint.sw_if_index = ntohl (gef->gef_itf);
245 mp->endpoint.sclass = ntohs (ge->ge_fwd.gef_sclass);
246 mp->endpoint.n_ips = n_ips;
247 mp->endpoint.flags = gbp_endpoint_flags_encode (gef->gef_flags);
248 mp->handle = htonl (gei);
249 mp->age = vlib_time_now (vlib_get_main ()) - ge->ge_last_time;
250 mac_address_encode (&ge->ge_key.gek_mac, mp->endpoint.mac);
252 vec_foreach_index (ii, ge->ge_key.gek_ips)
254 ip_address_encode (&ge->ge_key.gek_ips[ii].fp_addr,
255 IP46_TYPE_ANY, &mp->endpoint.ips[ii]);
258 vl_api_send_msg (ctx->reg, (u8 *) mp);
260 return (WALK_CONTINUE);
264 vl_api_gbp_endpoint_dump_t_handler (vl_api_gbp_endpoint_dump_t * mp)
266 vl_api_registration_t *reg;
268 reg = vl_api_client_index_to_registration (mp->client_index);
272 gbp_walk_ctx_t ctx = {
274 .context = mp->context,
277 gbp_endpoint_walk (gbp_endpoint_send_details, &ctx);
281 gbp_retention_decode (const vl_api_gbp_endpoint_retention_t * in,
282 gbp_endpoint_retention_t * out)
284 out->remote_ep_timeout = ntohl (in->remote_ep_timeout);
288 vl_api_gbp_endpoint_group_add_t_handler
289 (vl_api_gbp_endpoint_group_add_t * mp)
291 vl_api_gbp_endpoint_group_add_reply_t *rmp;
292 gbp_endpoint_retention_t retention;
295 gbp_retention_decode (&mp->epg.retention, &retention);
297 rv = gbp_endpoint_group_add_and_lock (ntohl (mp->epg.vnid),
298 ntohs (mp->epg.sclass),
299 ntohl (mp->epg.bd_id),
300 ntohl (mp->epg.rd_id),
301 ntohl (mp->epg.uplink_sw_if_index),
304 REPLY_MACRO (VL_API_GBP_ENDPOINT_GROUP_ADD_REPLY + GBP_MSG_BASE);
308 vl_api_gbp_endpoint_group_del_t_handler
309 (vl_api_gbp_endpoint_group_del_t * mp)
311 vl_api_gbp_endpoint_group_del_reply_t *rmp;
314 rv = gbp_endpoint_group_delete (ntohs (mp->sclass));
316 REPLY_MACRO (VL_API_GBP_ENDPOINT_GROUP_DEL_REPLY + GBP_MSG_BASE);
319 static gbp_bridge_domain_flags_t
320 gbp_bridge_domain_flags_from_api (vl_api_gbp_bridge_domain_flags_t a)
322 gbp_bridge_domain_flags_t g;
324 g = GBP_BD_FLAG_NONE;
325 a = clib_net_to_host_u32 (a);
327 if (a & GBP_BD_API_FLAG_DO_NOT_LEARN)
328 g |= GBP_BD_FLAG_DO_NOT_LEARN;
329 if (a & GBP_BD_API_FLAG_UU_FWD_DROP)
330 g |= GBP_BD_FLAG_UU_FWD_DROP;
331 if (a & GBP_BD_API_FLAG_MCAST_DROP)
332 g |= GBP_BD_FLAG_MCAST_DROP;
333 if (a & GBP_BD_API_FLAG_UCAST_ARP)
334 g |= GBP_BD_FLAG_UCAST_ARP;
340 vl_api_gbp_bridge_domain_add_t_handler (vl_api_gbp_bridge_domain_add_t * mp)
342 vl_api_gbp_bridge_domain_add_reply_t *rmp;
345 rv = gbp_bridge_domain_add_and_lock (ntohl (mp->bd.bd_id),
346 ntohl (mp->bd.rd_id),
347 gbp_bridge_domain_flags_from_api
349 ntohl (mp->bd.bvi_sw_if_index),
350 ntohl (mp->bd.uu_fwd_sw_if_index),
351 ntohl (mp->bd.bm_flood_sw_if_index));
353 REPLY_MACRO (VL_API_GBP_BRIDGE_DOMAIN_ADD_REPLY + GBP_MSG_BASE);
357 vl_api_gbp_bridge_domain_del_t_handler (vl_api_gbp_bridge_domain_del_t * mp)
359 vl_api_gbp_bridge_domain_del_reply_t *rmp;
362 rv = gbp_bridge_domain_delete (ntohl (mp->bd_id));
364 REPLY_MACRO (VL_API_GBP_BRIDGE_DOMAIN_DEL_REPLY + GBP_MSG_BASE);
368 vl_api_gbp_route_domain_add_t_handler (vl_api_gbp_route_domain_add_t * mp)
370 vl_api_gbp_route_domain_add_reply_t *rmp;
373 rv = gbp_route_domain_add_and_lock (ntohl (mp->rd.rd_id),
374 ntohs (mp->rd.scope),
375 ntohl (mp->rd.ip4_table_id),
376 ntohl (mp->rd.ip6_table_id),
377 ntohl (mp->rd.ip4_uu_sw_if_index),
378 ntohl (mp->rd.ip6_uu_sw_if_index));
380 REPLY_MACRO (VL_API_GBP_ROUTE_DOMAIN_ADD_REPLY + GBP_MSG_BASE);
384 vl_api_gbp_route_domain_del_t_handler (vl_api_gbp_route_domain_del_t * mp)
386 vl_api_gbp_route_domain_del_reply_t *rmp;
389 rv = gbp_route_domain_delete (ntohl (mp->rd_id));
391 REPLY_MACRO (VL_API_GBP_ROUTE_DOMAIN_DEL_REPLY + GBP_MSG_BASE);
395 gub_subnet_type_from_api (vl_api_gbp_subnet_type_t a, gbp_subnet_type_t * t)
397 a = clib_net_to_host_u32 (a);
401 case GBP_API_SUBNET_TRANSPORT:
402 *t = GBP_SUBNET_TRANSPORT;
404 case GBP_API_SUBNET_L3_OUT:
405 *t = GBP_SUBNET_L3_OUT;
407 case GBP_API_SUBNET_ANON_L3_OUT:
408 *t = GBP_SUBNET_ANON_L3_OUT;
410 case GBP_API_SUBNET_STITCHED_INTERNAL:
411 *t = GBP_SUBNET_STITCHED_INTERNAL;
413 case GBP_API_SUBNET_STITCHED_EXTERNAL:
414 *t = GBP_SUBNET_STITCHED_EXTERNAL;
422 vl_api_gbp_subnet_add_del_t_handler (vl_api_gbp_subnet_add_del_t * mp)
424 vl_api_gbp_subnet_add_del_reply_t *rmp;
425 gbp_subnet_type_t type;
429 ip_prefix_decode (&mp->subnet.prefix, &pfx);
431 rv = gub_subnet_type_from_api (mp->subnet.type, &type);
437 rv = gbp_subnet_add (ntohl (mp->subnet.rd_id),
439 ntohl (mp->subnet.sw_if_index),
440 ntohs (mp->subnet.sclass));
442 rv = gbp_subnet_del (ntohl (mp->subnet.rd_id), &pfx);
445 REPLY_MACRO (VL_API_GBP_SUBNET_ADD_DEL_REPLY + GBP_MSG_BASE);
448 static vl_api_gbp_subnet_type_t
449 gub_subnet_type_to_api (gbp_subnet_type_t t)
451 vl_api_gbp_subnet_type_t a = 0;
455 case GBP_SUBNET_TRANSPORT:
456 a = GBP_API_SUBNET_TRANSPORT;
458 case GBP_SUBNET_STITCHED_INTERNAL:
459 a = GBP_API_SUBNET_STITCHED_INTERNAL;
461 case GBP_SUBNET_STITCHED_EXTERNAL:
462 a = GBP_API_SUBNET_STITCHED_EXTERNAL;
464 case GBP_SUBNET_L3_OUT:
465 a = GBP_API_SUBNET_L3_OUT;
467 case GBP_SUBNET_ANON_L3_OUT:
468 a = GBP_API_SUBNET_ANON_L3_OUT;
472 a = clib_host_to_net_u32 (a);
478 gbp_subnet_send_details (u32 rd_id,
479 const fib_prefix_t * pfx,
480 gbp_subnet_type_t type,
481 u32 sw_if_index, sclass_t sclass, void *args)
483 vl_api_gbp_subnet_details_t *mp;
487 mp = vl_msg_api_alloc (sizeof (*mp));
491 clib_memset (mp, 0, sizeof (*mp));
492 mp->_vl_msg_id = ntohs (VL_API_GBP_SUBNET_DETAILS + GBP_MSG_BASE);
493 mp->context = ctx->context;
495 mp->subnet.type = gub_subnet_type_to_api (type);
496 mp->subnet.sw_if_index = ntohl (sw_if_index);
497 mp->subnet.sclass = ntohs (sclass);
498 mp->subnet.rd_id = ntohl (rd_id);
499 ip_prefix_encode (pfx, &mp->subnet.prefix);
501 vl_api_send_msg (ctx->reg, (u8 *) mp);
503 return (WALK_CONTINUE);
507 vl_api_gbp_subnet_dump_t_handler (vl_api_gbp_subnet_dump_t * mp)
509 vl_api_registration_t *reg;
511 reg = vl_api_client_index_to_registration (mp->client_index);
515 gbp_walk_ctx_t ctx = {
517 .context = mp->context,
520 gbp_subnet_walk (gbp_subnet_send_details, &ctx);
524 gbp_endpoint_group_send_details (gbp_endpoint_group_t * gg, void *args)
526 vl_api_gbp_endpoint_group_details_t *mp;
530 mp = vl_msg_api_alloc (sizeof (*mp));
534 clib_memset (mp, 0, sizeof (*mp));
535 mp->_vl_msg_id = ntohs (VL_API_GBP_ENDPOINT_GROUP_DETAILS + GBP_MSG_BASE);
536 mp->context = ctx->context;
538 mp->epg.uplink_sw_if_index = ntohl (gg->gg_uplink_sw_if_index);
539 mp->epg.vnid = ntohl (gg->gg_vnid);
540 mp->epg.sclass = ntohs (gg->gg_sclass);
541 mp->epg.bd_id = ntohl (gbp_endpoint_group_get_bd_id (gg));
542 mp->epg.rd_id = ntohl (gbp_route_domain_get_rd_id (gg->gg_rd));
544 vl_api_send_msg (ctx->reg, (u8 *) mp);
550 vl_api_gbp_endpoint_group_dump_t_handler (vl_api_gbp_endpoint_group_dump_t *
553 vl_api_registration_t *reg;
555 reg = vl_api_client_index_to_registration (mp->client_index);
559 gbp_walk_ctx_t ctx = {
561 .context = mp->context,
564 gbp_endpoint_group_walk (gbp_endpoint_group_send_details, &ctx);
568 gbp_bridge_domain_send_details (gbp_bridge_domain_t * gb, void *args)
570 vl_api_gbp_bridge_domain_details_t *mp;
571 gbp_route_domain_t *gr;
575 mp = vl_msg_api_alloc (sizeof (*mp));
579 memset (mp, 0, sizeof (*mp));
580 mp->_vl_msg_id = ntohs (VL_API_GBP_BRIDGE_DOMAIN_DETAILS + GBP_MSG_BASE);
581 mp->context = ctx->context;
583 gr = gbp_route_domain_get (gb->gb_rdi);
585 mp->bd.bd_id = ntohl (gb->gb_bd_id);
586 mp->bd.rd_id = ntohl (gr->grd_id);
587 mp->bd.bvi_sw_if_index = ntohl (gb->gb_bvi_sw_if_index);
588 mp->bd.uu_fwd_sw_if_index = ntohl (gb->gb_uu_fwd_sw_if_index);
589 mp->bd.bm_flood_sw_if_index = ntohl (gb->gb_bm_flood_sw_if_index);
591 vl_api_send_msg (ctx->reg, (u8 *) mp);
597 vl_api_gbp_bridge_domain_dump_t_handler (vl_api_gbp_bridge_domain_dump_t * mp)
599 vl_api_registration_t *reg;
601 reg = vl_api_client_index_to_registration (mp->client_index);
605 gbp_walk_ctx_t ctx = {
607 .context = mp->context,
610 gbp_bridge_domain_walk (gbp_bridge_domain_send_details, &ctx);
614 gbp_route_domain_send_details (gbp_route_domain_t * grd, void *args)
616 vl_api_gbp_route_domain_details_t *mp;
620 mp = vl_msg_api_alloc (sizeof (*mp));
624 memset (mp, 0, sizeof (*mp));
625 mp->_vl_msg_id = ntohs (VL_API_GBP_ROUTE_DOMAIN_DETAILS + GBP_MSG_BASE);
626 mp->context = ctx->context;
628 mp->rd.rd_id = ntohl (grd->grd_id);
629 mp->rd.ip4_uu_sw_if_index =
630 ntohl (grd->grd_uu_sw_if_index[FIB_PROTOCOL_IP4]);
631 mp->rd.ip6_uu_sw_if_index =
632 ntohl (grd->grd_uu_sw_if_index[FIB_PROTOCOL_IP6]);
634 vl_api_send_msg (ctx->reg, (u8 *) mp);
640 vl_api_gbp_route_domain_dump_t_handler (vl_api_gbp_route_domain_dump_t * mp)
642 vl_api_registration_t *reg;
644 reg = vl_api_client_index_to_registration (mp->client_index);
648 gbp_walk_ctx_t ctx = {
650 .context = mp->context,
653 gbp_route_domain_walk (gbp_route_domain_send_details, &ctx);
657 vl_api_gbp_recirc_add_del_t_handler (vl_api_gbp_recirc_add_del_t * mp)
659 vl_api_gbp_recirc_add_del_reply_t *rmp;
663 sw_if_index = ntohl (mp->recirc.sw_if_index);
664 if (!vnet_sw_if_index_is_api_valid (sw_if_index))
665 goto bad_sw_if_index;
668 rv = gbp_recirc_add (sw_if_index,
669 ntohs (mp->recirc.sclass), mp->recirc.is_ext);
671 rv = gbp_recirc_delete (sw_if_index);
673 BAD_SW_IF_INDEX_LABEL;
675 REPLY_MACRO (VL_API_GBP_RECIRC_ADD_DEL_REPLY + GBP_MSG_BASE);
679 gbp_recirc_send_details (gbp_recirc_t * gr, void *args)
681 vl_api_gbp_recirc_details_t *mp;
685 mp = vl_msg_api_alloc (sizeof (*mp));
689 clib_memset (mp, 0, sizeof (*mp));
690 mp->_vl_msg_id = ntohs (VL_API_GBP_RECIRC_DETAILS + GBP_MSG_BASE);
691 mp->context = ctx->context;
693 mp->recirc.sclass = ntohs (gr->gr_sclass);
694 mp->recirc.sw_if_index = ntohl (gr->gr_sw_if_index);
695 mp->recirc.is_ext = gr->gr_is_ext;
697 vl_api_send_msg (ctx->reg, (u8 *) mp);
699 return (WALK_CONTINUE);
703 vl_api_gbp_recirc_dump_t_handler (vl_api_gbp_recirc_dump_t * mp)
705 vl_api_registration_t *reg;
707 reg = vl_api_client_index_to_registration (mp->client_index);
711 gbp_walk_ctx_t ctx = {
713 .context = mp->context,
716 gbp_recirc_walk (gbp_recirc_send_details, &ctx);
720 vl_api_gbp_ext_itf_add_del_t_handler (vl_api_gbp_ext_itf_add_del_t * mp)
722 vl_api_gbp_ext_itf_add_del_reply_t *rmp;
723 u32 sw_if_index = ~0;
724 vl_api_gbp_ext_itf_t *ext_itf;
727 ext_itf = &mp->ext_itf;
729 sw_if_index = ntohl (ext_itf->sw_if_index);
731 if (!vnet_sw_if_index_is_api_valid (sw_if_index))
732 goto bad_sw_if_index;
735 rv = gbp_ext_itf_add (sw_if_index,
736 ntohl (ext_itf->bd_id), ntohl (ext_itf->rd_id),
737 ntohl (ext_itf->flags));
739 rv = gbp_ext_itf_delete (sw_if_index);
741 BAD_SW_IF_INDEX_LABEL;
743 REPLY_MACRO (VL_API_GBP_EXT_ITF_ADD_DEL_REPLY + GBP_MSG_BASE);
747 gbp_ext_itf_send_details (gbp_ext_itf_t * gx, void *args)
749 vl_api_gbp_ext_itf_details_t *mp;
753 mp = vl_msg_api_alloc (sizeof (*mp));
757 clib_memset (mp, 0, sizeof (*mp));
758 mp->_vl_msg_id = ntohs (VL_API_GBP_EXT_ITF_DETAILS + GBP_MSG_BASE);
759 mp->context = ctx->context;
761 mp->ext_itf.flags = ntohl (gx->gx_flags);
762 mp->ext_itf.bd_id = ntohl (gbp_bridge_domain_get_bd_id (gx->gx_bd));
763 mp->ext_itf.rd_id = ntohl (gbp_route_domain_get_rd_id (gx->gx_rd));
764 mp->ext_itf.sw_if_index = ntohl (gx->gx_itf);
766 vl_api_send_msg (ctx->reg, (u8 *) mp);
768 return (WALK_CONTINUE);
772 vl_api_gbp_ext_itf_dump_t_handler (vl_api_gbp_ext_itf_dump_t * mp)
774 vl_api_registration_t *reg;
776 reg = vl_api_client_index_to_registration (mp->client_index);
780 gbp_walk_ctx_t ctx = {
782 .context = mp->context,
785 gbp_ext_itf_walk (gbp_ext_itf_send_details, &ctx);
789 gbp_contract_rule_action_deocde (vl_api_gbp_rule_action_t in,
790 gbp_rule_action_t * out)
792 in = clib_net_to_host_u32 (in);
796 case GBP_API_RULE_PERMIT:
797 *out = GBP_RULE_PERMIT;
799 case GBP_API_RULE_DENY:
800 *out = GBP_RULE_DENY;
802 case GBP_API_RULE_REDIRECT:
803 *out = GBP_RULE_REDIRECT;
811 gbp_hash_mode_decode (vl_api_gbp_hash_mode_t in, gbp_hash_mode_t * out)
813 in = clib_net_to_host_u32 (in);
817 case GBP_API_HASH_MODE_SRC_IP:
818 *out = GBP_HASH_MODE_SRC_IP;
820 case GBP_API_HASH_MODE_DST_IP:
821 *out = GBP_HASH_MODE_DST_IP;
823 case GBP_API_HASH_MODE_SYMMETRIC:
824 *out = GBP_HASH_MODE_SYMMETRIC;
832 gbp_next_hop_decode (const vl_api_gbp_next_hop_t * in, index_t * gnhi)
838 gbd = gbp_bridge_domain_find_and_lock (ntohl (in->bd_id));
840 if (INDEX_INVALID == gbd)
841 return (VNET_API_ERROR_BD_NOT_MODIFIABLE);
843 grd = gbp_route_domain_find_and_lock (ntohl (in->rd_id));
845 if (INDEX_INVALID == grd)
846 return (VNET_API_ERROR_NO_SUCH_FIB);
848 ip_address_decode (&in->ip, &ip);
849 mac_address_decode (in->mac, &mac);
851 *gnhi = gbp_next_hop_alloc (&ip, grd, &mac, gbd);
857 gbp_next_hop_set_decode (const vl_api_gbp_next_hop_set_t * in,
858 gbp_hash_mode_t * hash_mode, index_t ** out)
861 index_t *gnhis = NULL;
865 rv = gbp_hash_mode_decode (in->hash_mode, hash_mode);
870 vec_validate (gnhis, in->n_nhs - 1);
872 for (ii = 0; ii < in->n_nhs; ii++)
874 rv = gbp_next_hop_decode (&in->nhs[ii], &gnhis[ii]);
888 gbp_contract_rule_decode (const vl_api_gbp_rule_t * in, index_t * gui)
890 gbp_hash_mode_t hash_mode;
891 gbp_rule_action_t action;
895 rv = gbp_contract_rule_action_deocde (in->action, &action);
900 if (GBP_RULE_REDIRECT == action)
902 rv = gbp_next_hop_set_decode (&in->nh_set, &hash_mode, &nhs);
909 hash_mode = GBP_HASH_MODE_SRC_IP;
912 *gui = gbp_rule_alloc (action, hash_mode, nhs);
918 gbp_contract_rules_decode (u8 n_rules,
919 const vl_api_gbp_rule_t * rules, index_t ** out)
921 index_t *guis = NULL;
931 vec_validate (guis, n_rules - 1);
933 for (ii = 0; ii < n_rules; ii++)
935 rv = gbp_contract_rule_decode (&rules[ii], &guis[ii]);
949 vl_api_gbp_contract_add_del_t_handler (vl_api_gbp_contract_add_del_t * mp)
951 vl_api_gbp_contract_add_del_reply_t *rmp;
952 u16 *allowed_ethertypes;
953 u32 stats_index = ~0;
960 rv = gbp_contract_rules_decode (mp->contract.n_rules,
961 mp->contract.rules, &rules);
965 allowed_ethertypes = NULL;
968 * allowed ether types
970 n_et = mp->contract.n_ether_types;
971 vec_validate (allowed_ethertypes, n_et - 1);
973 for (ii = 0; ii < n_et; ii++)
975 /* leave the ether types in network order */
976 allowed_ethertypes[ii] = mp->contract.allowed_ethertypes[ii];
979 rv = gbp_contract_update (ntohs (mp->contract.scope),
980 ntohs (mp->contract.sclass),
981 ntohs (mp->contract.dclass),
982 ntohl (mp->contract.acl_index),
983 rules, allowed_ethertypes, &stats_index);
986 rv = gbp_contract_delete (ntohs (mp->contract.scope),
987 ntohs (mp->contract.sclass),
988 ntohs (mp->contract.dclass));
992 REPLY_MACRO2 (VL_API_GBP_CONTRACT_ADD_DEL_REPLY + GBP_MSG_BASE,
994 rmp->stats_index = htonl (stats_index);
1000 gbp_contract_send_details (gbp_contract_t * gbpc, void *args)
1002 vl_api_gbp_contract_details_t *mp;
1003 gbp_walk_ctx_t *ctx;
1006 mp = vl_msg_api_alloc (sizeof (*mp));
1010 clib_memset (mp, 0, sizeof (*mp));
1011 mp->_vl_msg_id = ntohs (VL_API_GBP_CONTRACT_DETAILS + GBP_MSG_BASE);
1012 mp->context = ctx->context;
1014 mp->contract.sclass = ntohs (gbpc->gc_key.gck_src);
1015 mp->contract.dclass = ntohs (gbpc->gc_key.gck_dst);
1016 mp->contract.acl_index = ntohl (gbpc->gc_acl_index);
1017 mp->contract.scope = ntohs (gbpc->gc_key.gck_scope);
1019 vl_api_send_msg (ctx->reg, (u8 *) mp);
1025 vl_api_gbp_contract_dump_t_handler (vl_api_gbp_contract_dump_t * mp)
1027 vl_api_registration_t *reg;
1029 reg = vl_api_client_index_to_registration (mp->client_index);
1033 gbp_walk_ctx_t ctx = {
1035 .context = mp->context,
1038 gbp_contract_walk (gbp_contract_send_details, &ctx);
1042 gbp_vxlan_tunnel_mode_2_layer (vl_api_gbp_vxlan_tunnel_mode_t mode,
1043 gbp_vxlan_tunnel_layer_t * l)
1045 mode = clib_net_to_host_u32 (mode);
1049 case GBP_VXLAN_TUNNEL_MODE_L2:
1050 *l = GBP_VXLAN_TUN_L2;
1052 case GBP_VXLAN_TUNNEL_MODE_L3:
1053 *l = GBP_VXLAN_TUN_L3;
1060 vl_api_gbp_vxlan_tunnel_add_t_handler (vl_api_gbp_vxlan_tunnel_add_t * mp)
1062 vl_api_gbp_vxlan_tunnel_add_reply_t *rmp;
1063 gbp_vxlan_tunnel_layer_t layer;
1068 ip4_address_decode (mp->tunnel.src, &src);
1069 rv = gbp_vxlan_tunnel_mode_2_layer (mp->tunnel.mode, &layer);
1074 rv = gbp_vxlan_tunnel_add (ntohl (mp->tunnel.vni),
1076 ntohl (mp->tunnel.bd_rd_id), &src, &sw_if_index);
1080 REPLY_MACRO2 (VL_API_GBP_VXLAN_TUNNEL_ADD_REPLY + GBP_MSG_BASE,
1082 rmp->sw_if_index = htonl (sw_if_index);
1088 vl_api_gbp_vxlan_tunnel_del_t_handler (vl_api_gbp_vxlan_tunnel_add_t * mp)
1090 vl_api_gbp_vxlan_tunnel_del_reply_t *rmp;
1093 rv = gbp_vxlan_tunnel_del (ntohl (mp->tunnel.vni));
1095 REPLY_MACRO (VL_API_GBP_VXLAN_TUNNEL_DEL_REPLY + GBP_MSG_BASE);
1098 static vl_api_gbp_vxlan_tunnel_mode_t
1099 gbp_vxlan_tunnel_layer_2_mode (gbp_vxlan_tunnel_layer_t layer)
1101 vl_api_gbp_vxlan_tunnel_mode_t mode = GBP_VXLAN_TUNNEL_MODE_L2;
1105 case GBP_VXLAN_TUN_L2:
1106 mode = GBP_VXLAN_TUNNEL_MODE_L2;
1108 case GBP_VXLAN_TUN_L3:
1109 mode = GBP_VXLAN_TUNNEL_MODE_L3;
1112 mode = clib_host_to_net_u32 (mode);
1118 gbp_vxlan_tunnel_send_details (gbp_vxlan_tunnel_t * gt, void *args)
1120 vl_api_gbp_vxlan_tunnel_details_t *mp;
1121 gbp_walk_ctx_t *ctx;
1124 mp = vl_msg_api_alloc (sizeof (*mp));
1128 memset (mp, 0, sizeof (*mp));
1129 mp->_vl_msg_id = htons (VL_API_GBP_VXLAN_TUNNEL_DETAILS + GBP_MSG_BASE);
1130 mp->context = ctx->context;
1132 mp->tunnel.vni = htonl (gt->gt_vni);
1133 mp->tunnel.mode = gbp_vxlan_tunnel_layer_2_mode (gt->gt_layer);
1134 mp->tunnel.bd_rd_id = htonl (gt->gt_bd_rd_id);
1136 vl_api_send_msg (ctx->reg, (u8 *) mp);
1142 vl_api_gbp_vxlan_tunnel_dump_t_handler (vl_api_gbp_vxlan_tunnel_dump_t * mp)
1144 vl_api_registration_t *reg;
1146 reg = vl_api_client_index_to_registration (mp->client_index);
1150 gbp_walk_ctx_t ctx = {
1152 .context = mp->context,
1155 gbp_vxlan_walk (gbp_vxlan_tunnel_send_details, &ctx);
1160 * Add vpe's API message handlers to the table.
1161 * vlib has already mapped shared memory and
1162 * added the client registration handlers.
1163 * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
1165 #define vl_msg_name_crc_list
1166 #include <gbp/gbp_all_api_h.h>
1167 #undef vl_msg_name_crc_list
1170 setup_message_id_table (api_main_t * am)
1172 #define _(id,n,crc) \
1173 vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + GBP_MSG_BASE);
1174 foreach_vl_msg_name_crc_gbp;
1179 gbp_api_hookup (vlib_main_t * vm)
1182 vl_msg_api_set_handlers(VL_API_##N + GBP_MSG_BASE, \
1184 vl_api_##n##_t_handler, \
1186 vl_api_##n##_t_endian, \
1187 vl_api_##n##_t_print, \
1188 sizeof(vl_api_##n##_t), 1);
1189 foreach_gbp_api_msg;
1193 static clib_error_t *
1194 gbp_init (vlib_main_t * vm)
1196 api_main_t *am = &api_main;
1197 gbp_main_t *gbpm = &gbp_main;
1198 u8 *name = format (0, "gbp_%08x%c", api_version, 0);
1200 gbpm->gbp_acl_user_id = ~0;
1202 /* Ask for a correctly-sized block of API message decode slots */
1203 msg_id_base = vl_msg_api_get_msg_ids ((char *) name,
1204 VL_MSG_FIRST_AVAILABLE);
1205 gbp_api_hookup (vm);
1207 /* Add our API messages to the global name_crc hash table */
1208 setup_message_id_table (am);
1214 VLIB_API_INIT_FUNCTION (gbp_init);
1217 VLIB_PLUGIN_REGISTER () = {
1218 .version = VPP_BUILD_VER,
1219 .description = "Group Based Policy (GBP)",
1225 * fd.io coding-style-patch-verification: ON
1228 * eval: (c-set-style "gnu")