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>
35 #include <vlibapi/api.h>
36 #include <vlibmemory/api.h>
38 /* define message IDs */
39 #include <gbp/gbp_msg_enum.h>
41 #define vl_typedefs /* define message structures */
42 #include <gbp/gbp_all_api_h.h>
45 #define vl_endianfun /* define message structures */
46 #include <gbp/gbp_all_api_h.h>
49 /* instantiate all the print functions we know about */
50 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
52 #include <gbp/gbp_all_api_h.h>
55 /* Get the API version number */
56 #define vl_api_version(n,v) static u32 api_version=(v);
57 #include <gbp/gbp_all_api_h.h>
60 #include <vlibapi/api_helper_macros.h>
62 #define foreach_gbp_api_msg \
63 _(GBP_ENDPOINT_ADD, gbp_endpoint_add) \
64 _(GBP_ENDPOINT_DEL, gbp_endpoint_del) \
65 _(GBP_ENDPOINT_DUMP, gbp_endpoint_dump) \
66 _(GBP_SUBNET_ADD_DEL, gbp_subnet_add_del) \
67 _(GBP_SUBNET_DUMP, gbp_subnet_dump) \
68 _(GBP_ENDPOINT_GROUP_ADD, gbp_endpoint_group_add) \
69 _(GBP_ENDPOINT_GROUP_DEL, gbp_endpoint_group_del) \
70 _(GBP_ENDPOINT_GROUP_DUMP, gbp_endpoint_group_dump) \
71 _(GBP_BRIDGE_DOMAIN_ADD, gbp_bridge_domain_add) \
72 _(GBP_BRIDGE_DOMAIN_DEL, gbp_bridge_domain_del) \
73 _(GBP_BRIDGE_DOMAIN_DUMP, gbp_bridge_domain_dump) \
74 _(GBP_ROUTE_DOMAIN_ADD, gbp_route_domain_add) \
75 _(GBP_ROUTE_DOMAIN_DEL, gbp_route_domain_del) \
76 _(GBP_ROUTE_DOMAIN_DUMP, gbp_route_domain_dump) \
77 _(GBP_RECIRC_ADD_DEL, gbp_recirc_add_del) \
78 _(GBP_RECIRC_DUMP, gbp_recirc_dump) \
79 _(GBP_EXT_ITF_ADD_DEL, gbp_ext_itf_add_del) \
80 _(GBP_EXT_ITF_DUMP, gbp_ext_itf_dump) \
81 _(GBP_CONTRACT_ADD_DEL, gbp_contract_add_del) \
82 _(GBP_CONTRACT_DUMP, gbp_contract_dump) \
83 _(GBP_VXLAN_TUNNEL_ADD, gbp_vxlan_tunnel_add) \
84 _(GBP_VXLAN_TUNNEL_DEL, gbp_vxlan_tunnel_del) \
85 _(GBP_VXLAN_TUNNEL_DUMP, gbp_vxlan_tunnel_dump)
89 static u16 msg_id_base;
91 #define GBP_MSG_BASE msg_id_base
93 static gbp_endpoint_flags_t
94 gbp_endpoint_flags_decode (vl_api_gbp_endpoint_flags_t v)
96 gbp_endpoint_flags_t f = GBP_ENDPOINT_FLAG_NONE;
100 if (v & GBP_API_ENDPOINT_FLAG_BOUNCE)
101 f |= GBP_ENDPOINT_FLAG_BOUNCE;
102 if (v & GBP_API_ENDPOINT_FLAG_REMOTE)
103 f |= GBP_ENDPOINT_FLAG_REMOTE;
104 if (v & GBP_API_ENDPOINT_FLAG_LEARNT)
105 f |= GBP_ENDPOINT_FLAG_LEARNT;
106 if (v & GBP_API_ENDPOINT_FLAG_EXTERNAL)
107 f |= GBP_ENDPOINT_FLAG_EXTERNAL;
112 static vl_api_gbp_endpoint_flags_t
113 gbp_endpoint_flags_encode (gbp_endpoint_flags_t f)
115 vl_api_gbp_endpoint_flags_t v = 0;
118 if (f & GBP_ENDPOINT_FLAG_BOUNCE)
119 v |= GBP_API_ENDPOINT_FLAG_BOUNCE;
120 if (f & GBP_ENDPOINT_FLAG_REMOTE)
121 v |= GBP_API_ENDPOINT_FLAG_REMOTE;
122 if (f & GBP_ENDPOINT_FLAG_LEARNT)
123 v |= GBP_API_ENDPOINT_FLAG_LEARNT;
124 if (f & GBP_ENDPOINT_FLAG_EXTERNAL)
125 v |= GBP_API_ENDPOINT_FLAG_EXTERNAL;
133 vl_api_gbp_endpoint_add_t_handler (vl_api_gbp_endpoint_add_t * mp)
135 vl_api_gbp_endpoint_add_reply_t *rmp;
136 gbp_endpoint_flags_t gef;
137 u32 sw_if_index, handle;
142 VALIDATE_SW_IF_INDEX (&(mp->endpoint));
144 gef = gbp_endpoint_flags_decode (mp->endpoint.flags), ips = NULL;
145 sw_if_index = ntohl (mp->endpoint.sw_if_index);
147 if (mp->endpoint.n_ips)
149 vec_validate (ips, mp->endpoint.n_ips - 1);
151 vec_foreach_index (ii, ips)
153 ip_address_decode (&mp->endpoint.ips[ii], &ips[ii]);
156 mac_address_decode (mp->endpoint.mac, &mac);
158 if (GBP_ENDPOINT_FLAG_REMOTE & gef)
160 ip46_address_t tun_src, tun_dst;
162 ip_address_decode (&mp->endpoint.tun.src, &tun_src);
163 ip_address_decode (&mp->endpoint.tun.dst, &tun_dst);
165 rv = gbp_endpoint_update_and_lock (GBP_ENDPOINT_SRC_CP,
166 sw_if_index, ips, &mac,
167 INDEX_INVALID, INDEX_INVALID,
168 ntohs (mp->endpoint.sclass),
169 gef, &tun_src, &tun_dst, &handle);
173 rv = gbp_endpoint_update_and_lock (GBP_ENDPOINT_SRC_CP,
174 sw_if_index, ips, &mac,
175 INDEX_INVALID, INDEX_INVALID,
176 ntohs (mp->endpoint.sclass),
177 gef, NULL, NULL, &handle);
180 BAD_SW_IF_INDEX_LABEL;
183 REPLY_MACRO2 (VL_API_GBP_ENDPOINT_ADD_REPLY + GBP_MSG_BASE,
185 rmp->handle = htonl (handle);
191 vl_api_gbp_endpoint_del_t_handler (vl_api_gbp_endpoint_del_t * mp)
193 vl_api_gbp_endpoint_del_reply_t *rmp;
196 gbp_endpoint_unlock (GBP_ENDPOINT_SRC_CP, ntohl (mp->handle));
198 REPLY_MACRO (VL_API_GBP_ENDPOINT_DEL_REPLY + GBP_MSG_BASE);
201 typedef struct gbp_walk_ctx_t_
203 vl_api_registration_t *reg;
208 gbp_endpoint_send_details (index_t gei, void *args)
210 vl_api_gbp_endpoint_details_t *mp;
211 gbp_endpoint_loc_t *gel;
212 gbp_endpoint_fwd_t *gef;
218 ge = gbp_endpoint_get (gei);
220 n_ips = vec_len (ge->ge_key.gek_ips);
221 mp = vl_msg_api_alloc (sizeof (*mp) + (sizeof (*mp->endpoint.ips) * n_ips));
225 clib_memset (mp, 0, sizeof (*mp));
226 mp->_vl_msg_id = ntohs (VL_API_GBP_ENDPOINT_DETAILS + GBP_MSG_BASE);
227 mp->context = ctx->context;
229 gel = &ge->ge_locs[0];
232 if (gbp_endpoint_is_remote (ge))
234 mp->endpoint.sw_if_index = ntohl (gel->tun.gel_parent_sw_if_index);
235 ip_address_encode (&gel->tun.gel_src, IP46_TYPE_ANY,
236 &mp->endpoint.tun.src);
237 ip_address_encode (&gel->tun.gel_dst, IP46_TYPE_ANY,
238 &mp->endpoint.tun.dst);
242 mp->endpoint.sw_if_index = ntohl (gef->gef_itf);
244 mp->endpoint.sclass = ntohs (ge->ge_fwd.gef_sclass);
245 mp->endpoint.n_ips = n_ips;
246 mp->endpoint.flags = gbp_endpoint_flags_encode (gef->gef_flags);
247 mp->handle = htonl (gei);
248 mp->age = vlib_time_now (vlib_get_main ()) - ge->ge_last_time;
249 mac_address_encode (&ge->ge_key.gek_mac, mp->endpoint.mac);
251 vec_foreach_index (ii, ge->ge_key.gek_ips)
253 ip_address_encode (&ge->ge_key.gek_ips[ii].fp_addr,
254 IP46_TYPE_ANY, &mp->endpoint.ips[ii]);
257 vl_api_send_msg (ctx->reg, (u8 *) mp);
259 return (WALK_CONTINUE);
263 vl_api_gbp_endpoint_dump_t_handler (vl_api_gbp_endpoint_dump_t * mp)
265 vl_api_registration_t *reg;
267 reg = vl_api_client_index_to_registration (mp->client_index);
271 gbp_walk_ctx_t ctx = {
273 .context = mp->context,
276 gbp_endpoint_walk (gbp_endpoint_send_details, &ctx);
280 gbp_retention_decode (const vl_api_gbp_endpoint_retention_t * in,
281 gbp_endpoint_retention_t * out)
283 out->remote_ep_timeout = ntohl (in->remote_ep_timeout);
287 vl_api_gbp_endpoint_group_add_t_handler
288 (vl_api_gbp_endpoint_group_add_t * mp)
290 vl_api_gbp_endpoint_group_add_reply_t *rmp;
291 gbp_endpoint_retention_t retention;
294 gbp_retention_decode (&mp->epg.retention, &retention);
296 rv = gbp_endpoint_group_add_and_lock (ntohl (mp->epg.vnid),
297 ntohs (mp->epg.sclass),
298 ntohl (mp->epg.bd_id),
299 ntohl (mp->epg.rd_id),
300 ntohl (mp->epg.uplink_sw_if_index),
303 REPLY_MACRO (VL_API_GBP_ENDPOINT_GROUP_ADD_REPLY + GBP_MSG_BASE);
307 vl_api_gbp_endpoint_group_del_t_handler
308 (vl_api_gbp_endpoint_group_del_t * mp)
310 vl_api_gbp_endpoint_group_del_reply_t *rmp;
313 rv = gbp_endpoint_group_delete (ntohs (mp->sclass));
315 REPLY_MACRO (VL_API_GBP_ENDPOINT_GROUP_DEL_REPLY + GBP_MSG_BASE);
318 static gbp_bridge_domain_flags_t
319 gbp_bridge_domain_flags_from_api (vl_api_gbp_bridge_domain_flags_t a)
321 gbp_bridge_domain_flags_t g;
323 g = GBP_BD_FLAG_NONE;
324 a = clib_net_to_host_u32 (a);
326 if (a & GBP_BD_API_FLAG_DO_NOT_LEARN)
327 g |= GBP_BD_FLAG_DO_NOT_LEARN;
328 if (a & GBP_BD_API_FLAG_UU_FWD_DROP)
329 g |= GBP_BD_FLAG_UU_FWD_DROP;
330 if (a & GBP_BD_API_FLAG_MCAST_DROP)
331 g |= GBP_BD_FLAG_MCAST_DROP;
332 if (a & GBP_BD_API_FLAG_UCAST_ARP)
333 g |= GBP_BD_FLAG_UCAST_ARP;
339 vl_api_gbp_bridge_domain_add_t_handler (vl_api_gbp_bridge_domain_add_t * mp)
341 vl_api_gbp_bridge_domain_add_reply_t *rmp;
344 rv = gbp_bridge_domain_add_and_lock (ntohl (mp->bd.bd_id),
345 ntohl (mp->bd.rd_id),
346 gbp_bridge_domain_flags_from_api
348 ntohl (mp->bd.bvi_sw_if_index),
349 ntohl (mp->bd.uu_fwd_sw_if_index),
350 ntohl (mp->bd.bm_flood_sw_if_index));
352 REPLY_MACRO (VL_API_GBP_BRIDGE_DOMAIN_ADD_REPLY + GBP_MSG_BASE);
356 vl_api_gbp_bridge_domain_del_t_handler (vl_api_gbp_bridge_domain_del_t * mp)
358 vl_api_gbp_bridge_domain_del_reply_t *rmp;
361 rv = gbp_bridge_domain_delete (ntohl (mp->bd_id));
363 REPLY_MACRO (VL_API_GBP_BRIDGE_DOMAIN_DEL_REPLY + GBP_MSG_BASE);
367 vl_api_gbp_route_domain_add_t_handler (vl_api_gbp_route_domain_add_t * mp)
369 vl_api_gbp_route_domain_add_reply_t *rmp;
372 rv = gbp_route_domain_add_and_lock (ntohl (mp->rd.rd_id),
373 ntohs (mp->rd.scope),
374 ntohl (mp->rd.ip4_table_id),
375 ntohl (mp->rd.ip6_table_id),
376 ntohl (mp->rd.ip4_uu_sw_if_index),
377 ntohl (mp->rd.ip6_uu_sw_if_index));
379 REPLY_MACRO (VL_API_GBP_ROUTE_DOMAIN_ADD_REPLY + GBP_MSG_BASE);
383 vl_api_gbp_route_domain_del_t_handler (vl_api_gbp_route_domain_del_t * mp)
385 vl_api_gbp_route_domain_del_reply_t *rmp;
388 rv = gbp_route_domain_delete (ntohl (mp->rd_id));
390 REPLY_MACRO (VL_API_GBP_ROUTE_DOMAIN_DEL_REPLY + GBP_MSG_BASE);
394 gub_subnet_type_from_api (vl_api_gbp_subnet_type_t a, gbp_subnet_type_t * t)
396 a = clib_net_to_host_u32 (a);
400 case GBP_API_SUBNET_TRANSPORT:
401 *t = GBP_SUBNET_TRANSPORT;
403 case GBP_API_SUBNET_L3_OUT:
404 *t = GBP_SUBNET_L3_OUT;
406 case GBP_API_SUBNET_ANON_L3_OUT:
407 *t = GBP_SUBNET_ANON_L3_OUT;
409 case GBP_API_SUBNET_STITCHED_INTERNAL:
410 *t = GBP_SUBNET_STITCHED_INTERNAL;
412 case GBP_API_SUBNET_STITCHED_EXTERNAL:
413 *t = GBP_SUBNET_STITCHED_EXTERNAL;
421 vl_api_gbp_subnet_add_del_t_handler (vl_api_gbp_subnet_add_del_t * mp)
423 vl_api_gbp_subnet_add_del_reply_t *rmp;
424 gbp_subnet_type_t type;
428 ip_prefix_decode (&mp->subnet.prefix, &pfx);
430 rv = gub_subnet_type_from_api (mp->subnet.type, &type);
436 rv = gbp_subnet_add (ntohl (mp->subnet.rd_id),
438 ntohl (mp->subnet.sw_if_index),
439 ntohs (mp->subnet.sclass));
441 rv = gbp_subnet_del (ntohl (mp->subnet.rd_id), &pfx);
444 REPLY_MACRO (VL_API_GBP_SUBNET_ADD_DEL_REPLY + GBP_MSG_BASE);
447 static vl_api_gbp_subnet_type_t
448 gub_subnet_type_to_api (gbp_subnet_type_t t)
450 vl_api_gbp_subnet_type_t a = 0;
454 case GBP_SUBNET_TRANSPORT:
455 a = GBP_API_SUBNET_TRANSPORT;
457 case GBP_SUBNET_STITCHED_INTERNAL:
458 a = GBP_API_SUBNET_STITCHED_INTERNAL;
460 case GBP_SUBNET_STITCHED_EXTERNAL:
461 a = GBP_API_SUBNET_STITCHED_EXTERNAL;
463 case GBP_SUBNET_L3_OUT:
464 a = GBP_API_SUBNET_L3_OUT;
466 case GBP_SUBNET_ANON_L3_OUT:
467 a = GBP_API_SUBNET_ANON_L3_OUT;
471 a = clib_host_to_net_u32 (a);
477 gbp_subnet_send_details (u32 rd_id,
478 const fib_prefix_t * pfx,
479 gbp_subnet_type_t type,
480 u32 sw_if_index, sclass_t sclass, void *args)
482 vl_api_gbp_subnet_details_t *mp;
486 mp = vl_msg_api_alloc (sizeof (*mp));
490 clib_memset (mp, 0, sizeof (*mp));
491 mp->_vl_msg_id = ntohs (VL_API_GBP_SUBNET_DETAILS + GBP_MSG_BASE);
492 mp->context = ctx->context;
494 mp->subnet.type = gub_subnet_type_to_api (type);
495 mp->subnet.sw_if_index = ntohl (sw_if_index);
496 mp->subnet.sclass = ntohs (sclass);
497 mp->subnet.rd_id = ntohl (rd_id);
498 ip_prefix_encode (pfx, &mp->subnet.prefix);
500 vl_api_send_msg (ctx->reg, (u8 *) mp);
502 return (WALK_CONTINUE);
506 vl_api_gbp_subnet_dump_t_handler (vl_api_gbp_subnet_dump_t * mp)
508 vl_api_registration_t *reg;
510 reg = vl_api_client_index_to_registration (mp->client_index);
514 gbp_walk_ctx_t ctx = {
516 .context = mp->context,
519 gbp_subnet_walk (gbp_subnet_send_details, &ctx);
523 gbp_endpoint_group_send_details (gbp_endpoint_group_t * gg, void *args)
525 vl_api_gbp_endpoint_group_details_t *mp;
529 mp = vl_msg_api_alloc (sizeof (*mp));
533 clib_memset (mp, 0, sizeof (*mp));
534 mp->_vl_msg_id = ntohs (VL_API_GBP_ENDPOINT_GROUP_DETAILS + GBP_MSG_BASE);
535 mp->context = ctx->context;
537 mp->epg.uplink_sw_if_index = ntohl (gg->gg_uplink_sw_if_index);
538 mp->epg.vnid = ntohl (gg->gg_vnid);
539 mp->epg.sclass = ntohs (gg->gg_sclass);
540 mp->epg.bd_id = ntohl (gbp_endpoint_group_get_bd_id (gg));
541 mp->epg.rd_id = ntohl (gbp_route_domain_get_rd_id (gg->gg_rd));
543 vl_api_send_msg (ctx->reg, (u8 *) mp);
549 vl_api_gbp_endpoint_group_dump_t_handler (vl_api_gbp_endpoint_group_dump_t *
552 vl_api_registration_t *reg;
554 reg = vl_api_client_index_to_registration (mp->client_index);
558 gbp_walk_ctx_t ctx = {
560 .context = mp->context,
563 gbp_endpoint_group_walk (gbp_endpoint_group_send_details, &ctx);
567 gbp_bridge_domain_send_details (gbp_bridge_domain_t * gb, void *args)
569 vl_api_gbp_bridge_domain_details_t *mp;
570 gbp_route_domain_t *gr;
574 mp = vl_msg_api_alloc (sizeof (*mp));
578 memset (mp, 0, sizeof (*mp));
579 mp->_vl_msg_id = ntohs (VL_API_GBP_BRIDGE_DOMAIN_DETAILS + GBP_MSG_BASE);
580 mp->context = ctx->context;
582 gr = gbp_route_domain_get (gb->gb_rdi);
584 mp->bd.bd_id = ntohl (gb->gb_bd_id);
585 mp->bd.rd_id = ntohl (gr->grd_id);
586 mp->bd.bvi_sw_if_index = ntohl (gb->gb_bvi_sw_if_index);
587 mp->bd.uu_fwd_sw_if_index = ntohl (gb->gb_uu_fwd_sw_if_index);
588 mp->bd.bm_flood_sw_if_index = ntohl (gb->gb_bm_flood_sw_if_index);
590 vl_api_send_msg (ctx->reg, (u8 *) mp);
596 vl_api_gbp_bridge_domain_dump_t_handler (vl_api_gbp_bridge_domain_dump_t * mp)
598 vl_api_registration_t *reg;
600 reg = vl_api_client_index_to_registration (mp->client_index);
604 gbp_walk_ctx_t ctx = {
606 .context = mp->context,
609 gbp_bridge_domain_walk (gbp_bridge_domain_send_details, &ctx);
613 gbp_route_domain_send_details (gbp_route_domain_t * grd, void *args)
615 vl_api_gbp_route_domain_details_t *mp;
619 mp = vl_msg_api_alloc (sizeof (*mp));
623 memset (mp, 0, sizeof (*mp));
624 mp->_vl_msg_id = ntohs (VL_API_GBP_ROUTE_DOMAIN_DETAILS + GBP_MSG_BASE);
625 mp->context = ctx->context;
627 mp->rd.rd_id = ntohl (grd->grd_id);
628 mp->rd.ip4_uu_sw_if_index =
629 ntohl (grd->grd_uu_sw_if_index[FIB_PROTOCOL_IP4]);
630 mp->rd.ip6_uu_sw_if_index =
631 ntohl (grd->grd_uu_sw_if_index[FIB_PROTOCOL_IP6]);
633 vl_api_send_msg (ctx->reg, (u8 *) mp);
639 vl_api_gbp_route_domain_dump_t_handler (vl_api_gbp_route_domain_dump_t * mp)
641 vl_api_registration_t *reg;
643 reg = vl_api_client_index_to_registration (mp->client_index);
647 gbp_walk_ctx_t ctx = {
649 .context = mp->context,
652 gbp_route_domain_walk (gbp_route_domain_send_details, &ctx);
656 vl_api_gbp_recirc_add_del_t_handler (vl_api_gbp_recirc_add_del_t * mp)
658 vl_api_gbp_recirc_add_del_reply_t *rmp;
662 sw_if_index = ntohl (mp->recirc.sw_if_index);
663 if (!vnet_sw_if_index_is_api_valid (sw_if_index))
664 goto bad_sw_if_index;
667 rv = gbp_recirc_add (sw_if_index,
668 ntohs (mp->recirc.sclass), mp->recirc.is_ext);
670 rv = gbp_recirc_delete (sw_if_index);
672 BAD_SW_IF_INDEX_LABEL;
674 REPLY_MACRO (VL_API_GBP_RECIRC_ADD_DEL_REPLY + GBP_MSG_BASE);
678 gbp_recirc_send_details (gbp_recirc_t * gr, void *args)
680 vl_api_gbp_recirc_details_t *mp;
684 mp = vl_msg_api_alloc (sizeof (*mp));
688 clib_memset (mp, 0, sizeof (*mp));
689 mp->_vl_msg_id = ntohs (VL_API_GBP_RECIRC_DETAILS + GBP_MSG_BASE);
690 mp->context = ctx->context;
692 mp->recirc.sclass = ntohs (gr->gr_sclass);
693 mp->recirc.sw_if_index = ntohl (gr->gr_sw_if_index);
694 mp->recirc.is_ext = gr->gr_is_ext;
696 vl_api_send_msg (ctx->reg, (u8 *) mp);
698 return (WALK_CONTINUE);
702 vl_api_gbp_recirc_dump_t_handler (vl_api_gbp_recirc_dump_t * mp)
704 vl_api_registration_t *reg;
706 reg = vl_api_client_index_to_registration (mp->client_index);
710 gbp_walk_ctx_t ctx = {
712 .context = mp->context,
715 gbp_recirc_walk (gbp_recirc_send_details, &ctx);
719 vl_api_gbp_ext_itf_add_del_t_handler (vl_api_gbp_ext_itf_add_del_t * mp)
721 vl_api_gbp_ext_itf_add_del_reply_t *rmp;
722 u32 sw_if_index = ~0;
723 vl_api_gbp_ext_itf_t *ext_itf;
726 ext_itf = &mp->ext_itf;
728 sw_if_index = ntohl (ext_itf->sw_if_index);
730 if (!vnet_sw_if_index_is_api_valid (sw_if_index))
731 goto bad_sw_if_index;
734 rv = gbp_ext_itf_add (sw_if_index,
735 ntohl (ext_itf->bd_id), ntohl (ext_itf->rd_id),
736 ntohl (ext_itf->flags));
738 rv = gbp_ext_itf_delete (sw_if_index);
740 BAD_SW_IF_INDEX_LABEL;
742 REPLY_MACRO (VL_API_GBP_EXT_ITF_ADD_DEL_REPLY + GBP_MSG_BASE);
746 gbp_ext_itf_send_details (gbp_ext_itf_t * gx, void *args)
748 vl_api_gbp_ext_itf_details_t *mp;
752 mp = vl_msg_api_alloc (sizeof (*mp));
756 clib_memset (mp, 0, sizeof (*mp));
757 mp->_vl_msg_id = ntohs (VL_API_GBP_EXT_ITF_DETAILS + GBP_MSG_BASE);
758 mp->context = ctx->context;
760 mp->ext_itf.flags = ntohl (gx->gx_flags);
761 mp->ext_itf.bd_id = ntohl (gbp_bridge_domain_get_bd_id (gx->gx_bd));
762 mp->ext_itf.rd_id = ntohl (gbp_route_domain_get_rd_id (gx->gx_rd));
763 mp->ext_itf.sw_if_index = ntohl (gx->gx_itf);
765 vl_api_send_msg (ctx->reg, (u8 *) mp);
767 return (WALK_CONTINUE);
771 vl_api_gbp_ext_itf_dump_t_handler (vl_api_gbp_ext_itf_dump_t * mp)
773 vl_api_registration_t *reg;
775 reg = vl_api_client_index_to_registration (mp->client_index);
779 gbp_walk_ctx_t ctx = {
781 .context = mp->context,
784 gbp_ext_itf_walk (gbp_ext_itf_send_details, &ctx);
788 gbp_contract_rule_action_deocde (vl_api_gbp_rule_action_t in,
789 gbp_rule_action_t * out)
791 in = clib_net_to_host_u32 (in);
795 case GBP_API_RULE_PERMIT:
796 *out = GBP_RULE_PERMIT;
798 case GBP_API_RULE_DENY:
799 *out = GBP_RULE_DENY;
801 case GBP_API_RULE_REDIRECT:
802 *out = GBP_RULE_REDIRECT;
810 gbp_hash_mode_decode (vl_api_gbp_hash_mode_t in, gbp_hash_mode_t * out)
812 in = clib_net_to_host_u32 (in);
816 case GBP_API_HASH_MODE_SRC_IP:
817 *out = GBP_HASH_MODE_SRC_IP;
819 case GBP_API_HASH_MODE_DST_IP:
820 *out = GBP_HASH_MODE_DST_IP;
822 case GBP_API_HASH_MODE_SYMMETRIC:
823 *out = GBP_HASH_MODE_SYMMETRIC;
831 gbp_next_hop_decode (const vl_api_gbp_next_hop_t * in, index_t * gnhi)
837 gbd = gbp_bridge_domain_find_and_lock (ntohl (in->bd_id));
839 if (INDEX_INVALID == gbd)
840 return (VNET_API_ERROR_BD_NOT_MODIFIABLE);
842 grd = gbp_route_domain_find_and_lock (ntohl (in->rd_id));
844 if (INDEX_INVALID == grd)
845 return (VNET_API_ERROR_NO_SUCH_FIB);
847 ip_address_decode (&in->ip, &ip);
848 mac_address_decode (in->mac, &mac);
850 *gnhi = gbp_next_hop_alloc (&ip, grd, &mac, gbd);
856 gbp_next_hop_set_decode (const vl_api_gbp_next_hop_set_t * in,
857 gbp_hash_mode_t * hash_mode, index_t ** out)
860 index_t *gnhis = NULL;
864 rv = gbp_hash_mode_decode (in->hash_mode, hash_mode);
869 vec_validate (gnhis, in->n_nhs - 1);
871 for (ii = 0; ii < in->n_nhs; ii++)
873 rv = gbp_next_hop_decode (&in->nhs[ii], &gnhis[ii]);
887 gbp_contract_rule_decode (const vl_api_gbp_rule_t * in, index_t * gui)
889 gbp_hash_mode_t hash_mode;
890 gbp_rule_action_t action;
894 rv = gbp_contract_rule_action_deocde (in->action, &action);
899 if (GBP_RULE_REDIRECT == action)
901 rv = gbp_next_hop_set_decode (&in->nh_set, &hash_mode, &nhs);
908 hash_mode = GBP_HASH_MODE_SRC_IP;
911 *gui = gbp_rule_alloc (action, hash_mode, nhs);
917 gbp_contract_rules_decode (u8 n_rules,
918 const vl_api_gbp_rule_t * rules, index_t ** out)
920 index_t *guis = NULL;
930 vec_validate (guis, n_rules - 1);
932 for (ii = 0; ii < n_rules; ii++)
934 rv = gbp_contract_rule_decode (&rules[ii], &guis[ii]);
948 vl_api_gbp_contract_add_del_t_handler (vl_api_gbp_contract_add_del_t * mp)
950 vl_api_gbp_contract_add_del_reply_t *rmp;
951 u16 *allowed_ethertypes;
952 u32 stats_index = ~0;
959 rv = gbp_contract_rules_decode (mp->contract.n_rules,
960 mp->contract.rules, &rules);
964 allowed_ethertypes = NULL;
967 * allowed ether types
969 n_et = mp->contract.n_ether_types;
970 vec_validate (allowed_ethertypes, n_et - 1);
972 for (ii = 0; ii < n_et; ii++)
974 /* leave the ether types in network order */
975 allowed_ethertypes[ii] = mp->contract.allowed_ethertypes[ii];
978 rv = gbp_contract_update (ntohs (mp->contract.scope),
979 ntohs (mp->contract.sclass),
980 ntohs (mp->contract.dclass),
981 ntohl (mp->contract.acl_index),
982 rules, allowed_ethertypes, &stats_index);
985 rv = gbp_contract_delete (ntohs (mp->contract.scope),
986 ntohs (mp->contract.sclass),
987 ntohs (mp->contract.dclass));
991 REPLY_MACRO2 (VL_API_GBP_CONTRACT_ADD_DEL_REPLY + GBP_MSG_BASE,
993 rmp->stats_index = htonl (stats_index);
999 gbp_contract_send_details (gbp_contract_t * gbpc, void *args)
1001 vl_api_gbp_contract_details_t *mp;
1002 gbp_walk_ctx_t *ctx;
1005 mp = vl_msg_api_alloc (sizeof (*mp));
1009 clib_memset (mp, 0, sizeof (*mp));
1010 mp->_vl_msg_id = ntohs (VL_API_GBP_CONTRACT_DETAILS + GBP_MSG_BASE);
1011 mp->context = ctx->context;
1013 mp->contract.sclass = ntohs (gbpc->gc_key.gck_src);
1014 mp->contract.dclass = ntohs (gbpc->gc_key.gck_dst);
1015 mp->contract.acl_index = ntohl (gbpc->gc_acl_index);
1016 mp->contract.scope = ntohs (gbpc->gc_key.gck_scope);
1018 vl_api_send_msg (ctx->reg, (u8 *) mp);
1024 vl_api_gbp_contract_dump_t_handler (vl_api_gbp_contract_dump_t * mp)
1026 vl_api_registration_t *reg;
1028 reg = vl_api_client_index_to_registration (mp->client_index);
1032 gbp_walk_ctx_t ctx = {
1034 .context = mp->context,
1037 gbp_contract_walk (gbp_contract_send_details, &ctx);
1041 gbp_vxlan_tunnel_mode_2_layer (vl_api_gbp_vxlan_tunnel_mode_t mode,
1042 gbp_vxlan_tunnel_layer_t * l)
1044 mode = clib_net_to_host_u32 (mode);
1048 case GBP_VXLAN_TUNNEL_MODE_L2:
1049 *l = GBP_VXLAN_TUN_L2;
1051 case GBP_VXLAN_TUNNEL_MODE_L3:
1052 *l = GBP_VXLAN_TUN_L3;
1059 vl_api_gbp_vxlan_tunnel_add_t_handler (vl_api_gbp_vxlan_tunnel_add_t * mp)
1061 vl_api_gbp_vxlan_tunnel_add_reply_t *rmp;
1062 gbp_vxlan_tunnel_layer_t layer;
1067 ip4_address_decode (mp->tunnel.src, &src);
1068 rv = gbp_vxlan_tunnel_mode_2_layer (mp->tunnel.mode, &layer);
1073 rv = gbp_vxlan_tunnel_add (ntohl (mp->tunnel.vni),
1075 ntohl (mp->tunnel.bd_rd_id), &src, &sw_if_index);
1079 REPLY_MACRO2 (VL_API_GBP_VXLAN_TUNNEL_ADD_REPLY + GBP_MSG_BASE,
1081 rmp->sw_if_index = htonl (sw_if_index);
1087 vl_api_gbp_vxlan_tunnel_del_t_handler (vl_api_gbp_vxlan_tunnel_add_t * mp)
1089 vl_api_gbp_vxlan_tunnel_del_reply_t *rmp;
1092 rv = gbp_vxlan_tunnel_del (ntohl (mp->tunnel.vni));
1094 REPLY_MACRO (VL_API_GBP_VXLAN_TUNNEL_DEL_REPLY + GBP_MSG_BASE);
1097 static vl_api_gbp_vxlan_tunnel_mode_t
1098 gbp_vxlan_tunnel_layer_2_mode (gbp_vxlan_tunnel_layer_t layer)
1100 vl_api_gbp_vxlan_tunnel_mode_t mode = GBP_VXLAN_TUNNEL_MODE_L2;
1104 case GBP_VXLAN_TUN_L2:
1105 mode = GBP_VXLAN_TUNNEL_MODE_L2;
1107 case GBP_VXLAN_TUN_L3:
1108 mode = GBP_VXLAN_TUNNEL_MODE_L3;
1111 mode = clib_host_to_net_u32 (mode);
1117 gbp_vxlan_tunnel_send_details (gbp_vxlan_tunnel_t * gt, void *args)
1119 vl_api_gbp_vxlan_tunnel_details_t *mp;
1120 gbp_walk_ctx_t *ctx;
1123 mp = vl_msg_api_alloc (sizeof (*mp));
1127 memset (mp, 0, sizeof (*mp));
1128 mp->_vl_msg_id = htons (VL_API_GBP_VXLAN_TUNNEL_DETAILS + GBP_MSG_BASE);
1129 mp->context = ctx->context;
1131 mp->tunnel.vni = htonl (gt->gt_vni);
1132 mp->tunnel.mode = gbp_vxlan_tunnel_layer_2_mode (gt->gt_layer);
1133 mp->tunnel.bd_rd_id = htonl (gt->gt_bd_rd_id);
1135 vl_api_send_msg (ctx->reg, (u8 *) mp);
1141 vl_api_gbp_vxlan_tunnel_dump_t_handler (vl_api_gbp_vxlan_tunnel_dump_t * mp)
1143 vl_api_registration_t *reg;
1145 reg = vl_api_client_index_to_registration (mp->client_index);
1149 gbp_walk_ctx_t ctx = {
1151 .context = mp->context,
1154 gbp_vxlan_walk (gbp_vxlan_tunnel_send_details, &ctx);
1159 * Add vpe's API message handlers to the table.
1160 * vlib has already mapped shared memory and
1161 * added the client registration handlers.
1162 * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
1164 #define vl_msg_name_crc_list
1165 #include <gbp/gbp_all_api_h.h>
1166 #undef vl_msg_name_crc_list
1169 setup_message_id_table (api_main_t * am)
1171 #define _(id,n,crc) \
1172 vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + GBP_MSG_BASE);
1173 foreach_vl_msg_name_crc_gbp;
1178 gbp_api_hookup (vlib_main_t * vm)
1181 vl_msg_api_set_handlers(VL_API_##N + GBP_MSG_BASE, \
1183 vl_api_##n##_t_handler, \
1185 vl_api_##n##_t_endian, \
1186 vl_api_##n##_t_print, \
1187 sizeof(vl_api_##n##_t), 1);
1188 foreach_gbp_api_msg;
1192 static clib_error_t *
1193 gbp_init (vlib_main_t * vm)
1195 api_main_t *am = &api_main;
1196 gbp_main_t *gbpm = &gbp_main;
1197 u8 *name = format (0, "gbp_%08x%c", api_version, 0);
1199 gbpm->gbp_acl_user_id = ~0;
1201 /* Ask for a correctly-sized block of API message decode slots */
1202 msg_id_base = vl_msg_api_get_msg_ids ((char *) name,
1203 VL_MSG_FIRST_AVAILABLE);
1204 gbp_api_hookup (vm);
1206 /* Add our API messages to the global name_crc hash table */
1207 setup_message_id_table (am);
1213 VLIB_API_INIT_FUNCTION (gbp_init);
1216 VLIB_PLUGIN_REGISTER () = {
1217 .version = VPP_BUILD_VER,
1218 .description = "Group Based Policy (GBP)",
1224 * fd.io coding-style-patch-verification: ON
1227 * eval: (c-set-style "gnu")