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_ENDPOINT_LEARN_SET_INACTIVE_THRESHOLD, gbp_endpoint_learn_set_inactive_threshold) \
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.epg_id),
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.epg_id),
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);
203 vl_api_gbp_endpoint_learn_set_inactive_threshold_t_handler
204 (vl_api_gbp_endpoint_learn_set_inactive_threshold_t * mp)
206 vl_api_gbp_endpoint_learn_set_inactive_threshold_reply_t *rmp;
209 gbp_learn_set_inactive_threshold (ntohl (mp->threshold));
211 REPLY_MACRO (VL_API_GBP_ENDPOINT_LEARN_SET_INACTIVE_THRESHOLD_REPLY +
215 typedef struct gbp_walk_ctx_t_
217 vl_api_registration_t *reg;
222 gbp_endpoint_send_details (index_t gei, void *args)
224 vl_api_gbp_endpoint_details_t *mp;
225 gbp_endpoint_loc_t *gel;
226 gbp_endpoint_fwd_t *gef;
232 ge = gbp_endpoint_get (gei);
234 n_ips = vec_len (ge->ge_key.gek_ips);
235 mp = vl_msg_api_alloc (sizeof (*mp) + (sizeof (*mp->endpoint.ips) * n_ips));
239 clib_memset (mp, 0, sizeof (*mp));
240 mp->_vl_msg_id = ntohs (VL_API_GBP_ENDPOINT_DETAILS + GBP_MSG_BASE);
241 mp->context = ctx->context;
243 gel = &ge->ge_locs[0];
246 if (gbp_endpoint_is_remote (ge))
248 mp->endpoint.sw_if_index = ntohl (gel->tun.gel_parent_sw_if_index);
249 ip_address_encode (&gel->tun.gel_src, IP46_TYPE_ANY,
250 &mp->endpoint.tun.src);
251 ip_address_encode (&gel->tun.gel_dst, IP46_TYPE_ANY,
252 &mp->endpoint.tun.dst);
256 mp->endpoint.sw_if_index = ntohl (gef->gef_itf);
258 mp->endpoint.epg_id = ntohs (ge->ge_fwd.gef_epg_id);
259 mp->endpoint.n_ips = n_ips;
260 mp->endpoint.flags = gbp_endpoint_flags_encode (gef->gef_flags);
261 mp->handle = htonl (gei);
262 mp->age = vlib_time_now (vlib_get_main ()) - ge->ge_last_time;
263 mac_address_encode (&ge->ge_key.gek_mac, mp->endpoint.mac);
265 vec_foreach_index (ii, ge->ge_key.gek_ips)
267 ip_address_encode (&ge->ge_key.gek_ips[ii].fp_addr,
268 IP46_TYPE_ANY, &mp->endpoint.ips[ii]);
271 vl_api_send_msg (ctx->reg, (u8 *) mp);
273 return (WALK_CONTINUE);
277 vl_api_gbp_endpoint_dump_t_handler (vl_api_gbp_endpoint_dump_t * mp)
279 vl_api_registration_t *reg;
281 reg = vl_api_client_index_to_registration (mp->client_index);
285 gbp_walk_ctx_t ctx = {
287 .context = mp->context,
290 gbp_endpoint_walk (gbp_endpoint_send_details, &ctx);
294 vl_api_gbp_endpoint_group_add_t_handler
295 (vl_api_gbp_endpoint_group_add_t * mp)
297 vl_api_gbp_endpoint_group_add_reply_t *rmp;
300 rv = gbp_endpoint_group_add_and_lock (ntohs (mp->epg.epg_id),
301 ntohl (mp->epg.bd_id),
302 ntohl (mp->epg.rd_id),
303 ntohl (mp->epg.uplink_sw_if_index));
305 REPLY_MACRO (VL_API_GBP_ENDPOINT_GROUP_ADD_REPLY + GBP_MSG_BASE);
309 vl_api_gbp_endpoint_group_del_t_handler
310 (vl_api_gbp_endpoint_group_del_t * mp)
312 vl_api_gbp_endpoint_group_del_reply_t *rmp;
315 rv = gbp_endpoint_group_delete (ntohs (mp->epg_id));
317 REPLY_MACRO (VL_API_GBP_ENDPOINT_GROUP_DEL_REPLY + GBP_MSG_BASE);
320 static gbp_bridge_domain_flags_t
321 gbp_bridge_domain_flags_from_api (vl_api_gbp_bridge_domain_flags_t a)
323 gbp_bridge_domain_flags_t g;
325 g = GBP_BD_FLAG_NONE;
326 a = clib_net_to_host_u32 (a);
328 if (a & GBP_BD_API_FLAG_DO_NOT_LEARN)
329 g |= GBP_BD_FLAG_DO_NOT_LEARN;
335 vl_api_gbp_bridge_domain_add_t_handler (vl_api_gbp_bridge_domain_add_t * mp)
337 vl_api_gbp_bridge_domain_add_reply_t *rmp;
340 rv = gbp_bridge_domain_add_and_lock (ntohl (mp->bd.bd_id),
341 gbp_bridge_domain_flags_from_api
343 ntohl (mp->bd.bvi_sw_if_index),
344 ntohl (mp->bd.uu_fwd_sw_if_index));
346 REPLY_MACRO (VL_API_GBP_BRIDGE_DOMAIN_ADD_REPLY + GBP_MSG_BASE);
350 vl_api_gbp_bridge_domain_del_t_handler (vl_api_gbp_bridge_domain_del_t * mp)
352 vl_api_gbp_bridge_domain_del_reply_t *rmp;
355 rv = gbp_bridge_domain_delete (ntohl (mp->bd_id));
357 REPLY_MACRO (VL_API_GBP_BRIDGE_DOMAIN_DEL_REPLY + GBP_MSG_BASE);
361 vl_api_gbp_route_domain_add_t_handler (vl_api_gbp_route_domain_add_t * mp)
363 vl_api_gbp_route_domain_add_reply_t *rmp;
366 rv = gbp_route_domain_add_and_lock (ntohl (mp->rd.rd_id),
367 ntohl (mp->rd.ip4_table_id),
368 ntohl (mp->rd.ip6_table_id),
369 ntohl (mp->rd.ip4_uu_sw_if_index),
370 ntohl (mp->rd.ip6_uu_sw_if_index));
372 REPLY_MACRO (VL_API_GBP_ROUTE_DOMAIN_ADD_REPLY + GBP_MSG_BASE);
376 vl_api_gbp_route_domain_del_t_handler (vl_api_gbp_route_domain_del_t * mp)
378 vl_api_gbp_route_domain_del_reply_t *rmp;
381 rv = gbp_route_domain_delete (ntohl (mp->rd_id));
383 REPLY_MACRO (VL_API_GBP_ROUTE_DOMAIN_DEL_REPLY + GBP_MSG_BASE);
387 gub_subnet_type_from_api (vl_api_gbp_subnet_type_t a, gbp_subnet_type_t * t)
389 a = clib_net_to_host_u32 (a);
393 case GBP_API_SUBNET_TRANSPORT:
394 *t = GBP_SUBNET_TRANSPORT;
396 case GBP_API_SUBNET_L3_OUT:
397 *t = GBP_SUBNET_L3_OUT;
399 case GBP_API_SUBNET_STITCHED_INTERNAL:
400 *t = GBP_SUBNET_STITCHED_INTERNAL;
402 case GBP_API_SUBNET_STITCHED_EXTERNAL:
403 *t = GBP_SUBNET_STITCHED_EXTERNAL;
411 vl_api_gbp_subnet_add_del_t_handler (vl_api_gbp_subnet_add_del_t * mp)
413 vl_api_gbp_subnet_add_del_reply_t *rmp;
414 gbp_subnet_type_t type;
418 ip_prefix_decode (&mp->subnet.prefix, &pfx);
420 rv = gub_subnet_type_from_api (mp->subnet.type, &type);
426 rv = gbp_subnet_add (ntohl (mp->subnet.rd_id),
428 ntohl (mp->subnet.sw_if_index),
429 ntohs (mp->subnet.epg_id));
431 rv = gbp_subnet_del (ntohl (mp->subnet.rd_id), &pfx);
434 REPLY_MACRO (VL_API_GBP_SUBNET_ADD_DEL_REPLY + GBP_MSG_BASE);
437 static vl_api_gbp_subnet_type_t
438 gub_subnet_type_to_api (gbp_subnet_type_t t)
440 vl_api_gbp_subnet_type_t a = 0;
444 case GBP_SUBNET_TRANSPORT:
445 a = GBP_API_SUBNET_TRANSPORT;
447 case GBP_SUBNET_STITCHED_INTERNAL:
448 a = GBP_API_SUBNET_STITCHED_INTERNAL;
450 case GBP_SUBNET_STITCHED_EXTERNAL:
451 a = GBP_API_SUBNET_STITCHED_EXTERNAL;
453 case GBP_SUBNET_L3_OUT:
454 a = GBP_API_SUBNET_L3_OUT;
458 a = clib_host_to_net_u32 (a);
464 gbp_subnet_send_details (u32 rd_id,
465 const fib_prefix_t * pfx,
466 gbp_subnet_type_t type,
467 u32 sw_if_index, epg_id_t epg, void *args)
469 vl_api_gbp_subnet_details_t *mp;
473 mp = vl_msg_api_alloc (sizeof (*mp));
477 clib_memset (mp, 0, sizeof (*mp));
478 mp->_vl_msg_id = ntohs (VL_API_GBP_SUBNET_DETAILS + GBP_MSG_BASE);
479 mp->context = ctx->context;
481 mp->subnet.type = gub_subnet_type_to_api (type);
482 mp->subnet.sw_if_index = ntohl (sw_if_index);
483 mp->subnet.epg_id = ntohs (epg);
484 mp->subnet.rd_id = ntohl (rd_id);
485 ip_prefix_encode (pfx, &mp->subnet.prefix);
487 vl_api_send_msg (ctx->reg, (u8 *) mp);
489 return (WALK_CONTINUE);
493 vl_api_gbp_subnet_dump_t_handler (vl_api_gbp_subnet_dump_t * mp)
495 vl_api_registration_t *reg;
497 reg = vl_api_client_index_to_registration (mp->client_index);
501 gbp_walk_ctx_t ctx = {
503 .context = mp->context,
506 gbp_subnet_walk (gbp_subnet_send_details, &ctx);
510 gbp_endpoint_group_send_details (gbp_endpoint_group_t * gg, void *args)
512 vl_api_gbp_endpoint_group_details_t *mp;
516 mp = vl_msg_api_alloc (sizeof (*mp));
520 clib_memset (mp, 0, sizeof (*mp));
521 mp->_vl_msg_id = ntohs (VL_API_GBP_ENDPOINT_GROUP_DETAILS + GBP_MSG_BASE);
522 mp->context = ctx->context;
524 mp->epg.uplink_sw_if_index = ntohl (gg->gg_uplink_sw_if_index);
525 mp->epg.epg_id = ntohs (gg->gg_id);
526 mp->epg.bd_id = ntohl (gbp_endpoint_group_get_bd_id (gg));
527 mp->epg.rd_id = ntohl (gbp_route_domain_get_rd_id (gg->gg_rd));
529 vl_api_send_msg (ctx->reg, (u8 *) mp);
535 vl_api_gbp_endpoint_group_dump_t_handler (vl_api_gbp_endpoint_group_dump_t *
538 vl_api_registration_t *reg;
540 reg = vl_api_client_index_to_registration (mp->client_index);
544 gbp_walk_ctx_t ctx = {
546 .context = mp->context,
549 gbp_endpoint_group_walk (gbp_endpoint_group_send_details, &ctx);
553 gbp_bridge_domain_send_details (gbp_bridge_domain_t * gb, void *args)
555 vl_api_gbp_bridge_domain_details_t *mp;
559 mp = vl_msg_api_alloc (sizeof (*mp));
563 memset (mp, 0, sizeof (*mp));
564 mp->_vl_msg_id = ntohs (VL_API_GBP_BRIDGE_DOMAIN_DETAILS + GBP_MSG_BASE);
565 mp->context = ctx->context;
567 mp->bd.bd_id = ntohl (gb->gb_bd_id);
568 mp->bd.bvi_sw_if_index = ntohl (gb->gb_bvi_sw_if_index);
569 mp->bd.uu_fwd_sw_if_index = ntohl (gb->gb_uu_fwd_sw_if_index);
571 vl_api_send_msg (ctx->reg, (u8 *) mp);
577 vl_api_gbp_bridge_domain_dump_t_handler (vl_api_gbp_bridge_domain_dump_t * mp)
579 vl_api_registration_t *reg;
581 reg = vl_api_client_index_to_registration (mp->client_index);
585 gbp_walk_ctx_t ctx = {
587 .context = mp->context,
590 gbp_bridge_domain_walk (gbp_bridge_domain_send_details, &ctx);
594 gbp_route_domain_send_details (gbp_route_domain_t * grd, void *args)
596 vl_api_gbp_route_domain_details_t *mp;
600 mp = vl_msg_api_alloc (sizeof (*mp));
604 memset (mp, 0, sizeof (*mp));
605 mp->_vl_msg_id = ntohs (VL_API_GBP_ROUTE_DOMAIN_DETAILS + GBP_MSG_BASE);
606 mp->context = ctx->context;
608 mp->rd.rd_id = ntohl (grd->grd_id);
609 mp->rd.ip4_uu_sw_if_index =
610 ntohl (grd->grd_uu_sw_if_index[FIB_PROTOCOL_IP4]);
611 mp->rd.ip6_uu_sw_if_index =
612 ntohl (grd->grd_uu_sw_if_index[FIB_PROTOCOL_IP6]);
614 vl_api_send_msg (ctx->reg, (u8 *) mp);
620 vl_api_gbp_route_domain_dump_t_handler (vl_api_gbp_route_domain_dump_t * mp)
622 vl_api_registration_t *reg;
624 reg = vl_api_client_index_to_registration (mp->client_index);
628 gbp_walk_ctx_t ctx = {
630 .context = mp->context,
633 gbp_route_domain_walk (gbp_route_domain_send_details, &ctx);
637 vl_api_gbp_recirc_add_del_t_handler (vl_api_gbp_recirc_add_del_t * mp)
639 vl_api_gbp_recirc_add_del_reply_t *rmp;
643 sw_if_index = ntohl (mp->recirc.sw_if_index);
644 if (!vnet_sw_if_index_is_api_valid (sw_if_index))
645 goto bad_sw_if_index;
648 rv = gbp_recirc_add (sw_if_index,
649 ntohs (mp->recirc.epg_id), mp->recirc.is_ext);
651 rv = gbp_recirc_delete (sw_if_index);
653 BAD_SW_IF_INDEX_LABEL;
655 REPLY_MACRO (VL_API_GBP_RECIRC_ADD_DEL_REPLY + GBP_MSG_BASE);
659 gbp_recirc_send_details (gbp_recirc_t * gr, void *args)
661 vl_api_gbp_recirc_details_t *mp;
665 mp = vl_msg_api_alloc (sizeof (*mp));
669 clib_memset (mp, 0, sizeof (*mp));
670 mp->_vl_msg_id = ntohs (VL_API_GBP_RECIRC_DETAILS + GBP_MSG_BASE);
671 mp->context = ctx->context;
673 mp->recirc.epg_id = ntohs (gr->gr_epg);
674 mp->recirc.sw_if_index = ntohl (gr->gr_sw_if_index);
675 mp->recirc.is_ext = gr->gr_is_ext;
677 vl_api_send_msg (ctx->reg, (u8 *) mp);
679 return (WALK_CONTINUE);
683 vl_api_gbp_recirc_dump_t_handler (vl_api_gbp_recirc_dump_t * mp)
685 vl_api_registration_t *reg;
687 reg = vl_api_client_index_to_registration (mp->client_index);
691 gbp_walk_ctx_t ctx = {
693 .context = mp->context,
696 gbp_recirc_walk (gbp_recirc_send_details, &ctx);
700 vl_api_gbp_ext_itf_add_del_t_handler (vl_api_gbp_ext_itf_add_del_t * mp)
702 vl_api_gbp_ext_itf_add_del_reply_t *rmp;
703 u32 sw_if_index = ~0;
704 vl_api_gbp_ext_itf_t *ext_itf;
707 ext_itf = &mp->ext_itf;
709 sw_if_index = ntohl (ext_itf->sw_if_index);
711 if (!vnet_sw_if_index_is_api_valid (sw_if_index))
712 goto bad_sw_if_index;
715 rv = gbp_ext_itf_add (sw_if_index,
716 ntohl (ext_itf->bd_id), ntohl (ext_itf->rd_id));
718 rv = gbp_ext_itf_delete (sw_if_index);
720 BAD_SW_IF_INDEX_LABEL;
722 REPLY_MACRO (VL_API_GBP_EXT_ITF_ADD_DEL_REPLY + GBP_MSG_BASE);
726 gbp_ext_itf_send_details (gbp_ext_itf_t * gx, void *args)
728 vl_api_gbp_ext_itf_details_t *mp;
732 mp = vl_msg_api_alloc (sizeof (*mp));
736 clib_memset (mp, 0, sizeof (*mp));
737 mp->_vl_msg_id = ntohs (VL_API_GBP_EXT_ITF_DETAILS + GBP_MSG_BASE);
738 mp->context = ctx->context;
740 mp->ext_itf.bd_id = ntohl (gbp_bridge_domain_get_bd_id (gx->gx_bd));
741 mp->ext_itf.rd_id = ntohl (gbp_route_domain_get_rd_id (gx->gx_rd));
742 mp->ext_itf.sw_if_index = ntohl (gx->gx_itf);
744 vl_api_send_msg (ctx->reg, (u8 *) mp);
746 return (WALK_CONTINUE);
750 vl_api_gbp_ext_itf_dump_t_handler (vl_api_gbp_ext_itf_dump_t * mp)
752 vl_api_registration_t *reg;
754 reg = vl_api_client_index_to_registration (mp->client_index);
758 gbp_walk_ctx_t ctx = {
760 .context = mp->context,
763 gbp_ext_itf_walk (gbp_ext_itf_send_details, &ctx);
767 gbp_contract_rule_action_deocde (vl_api_gbp_rule_action_t in,
768 gbp_rule_action_t * out)
770 in = clib_net_to_host_u32 (in);
774 case GBP_API_RULE_PERMIT:
775 *out = GBP_RULE_PERMIT;
777 case GBP_API_RULE_DENY:
778 *out = GBP_RULE_DENY;
780 case GBP_API_RULE_REDIRECT:
781 *out = GBP_RULE_REDIRECT;
789 gbp_hash_mode_decode (vl_api_gbp_hash_mode_t in, gbp_hash_mode_t * out)
791 in = clib_net_to_host_u32 (in);
795 case GBP_API_HASH_MODE_SRC_IP:
796 *out = GBP_HASH_MODE_SRC_IP;
798 case GBP_API_HASH_MODE_DST_IP:
799 *out = GBP_HASH_MODE_DST_IP;
801 case GBP_API_HASH_MODE_SYMMETRIC:
802 *out = GBP_HASH_MODE_SYMMETRIC;
810 gbp_next_hop_decode (const vl_api_gbp_next_hop_t * in, index_t * gnhi)
816 gbd = gbp_bridge_domain_find_and_lock (ntohl (in->bd_id));
818 if (INDEX_INVALID == gbd)
819 return (VNET_API_ERROR_BD_NOT_MODIFIABLE);
821 grd = gbp_route_domain_find_and_lock (ntohl (in->rd_id));
823 if (INDEX_INVALID == grd)
824 return (VNET_API_ERROR_NO_SUCH_FIB);
826 ip_address_decode (&in->ip, &ip);
827 mac_address_decode (in->mac, &mac);
829 *gnhi = gbp_next_hop_alloc (&ip, grd, &mac, gbd);
835 gbp_next_hop_set_decode (const vl_api_gbp_next_hop_set_t * in,
836 gbp_hash_mode_t * hash_mode, index_t ** out)
839 index_t *gnhis = NULL;
843 rv = gbp_hash_mode_decode (in->hash_mode, hash_mode);
848 vec_validate (gnhis, in->n_nhs - 1);
850 for (ii = 0; ii < in->n_nhs; ii++)
852 rv = gbp_next_hop_decode (&in->nhs[ii], &gnhis[ii]);
866 gbp_contract_rule_decode (const vl_api_gbp_rule_t * in, index_t * gui)
868 gbp_hash_mode_t hash_mode;
869 gbp_rule_action_t action;
873 rv = gbp_contract_rule_action_deocde (in->action, &action);
878 if (GBP_RULE_REDIRECT == action)
880 rv = gbp_next_hop_set_decode (&in->nh_set, &hash_mode, &nhs);
887 hash_mode = GBP_HASH_MODE_SRC_IP;
890 *gui = gbp_rule_alloc (action, hash_mode, nhs);
896 gbp_contract_rules_decode (u8 n_rules,
897 const vl_api_gbp_rule_t * rules, index_t ** out)
899 index_t *guis = NULL;
909 vec_validate (guis, n_rules - 1);
911 for (ii = 0; ii < n_rules; ii++)
913 rv = gbp_contract_rule_decode (&rules[ii], &guis[ii]);
927 vl_api_gbp_contract_add_del_t_handler (vl_api_gbp_contract_add_del_t * mp)
929 vl_api_gbp_contract_add_del_reply_t *rmp;
930 u16 *allowed_ethertypes;
938 rv = gbp_contract_rules_decode (mp->contract.n_rules,
939 mp->contract.rules, &rules);
943 allowed_ethertypes = NULL;
946 * move past the variable legnth array of rules to get to the
947 * allowed ether types
949 data = (((u8 *) & mp->contract.n_ether_types) +
950 (sizeof (mp->contract.rules[0]) * mp->contract.n_rules));
952 et = (u16 *) (++data);
953 vec_validate (allowed_ethertypes, n_et - 1);
955 for (ii = 0; ii < n_et; ii++)
957 /* leave the ether types in network order */
958 allowed_ethertypes[ii] = et[ii];
961 rv = gbp_contract_update (ntohs (mp->contract.src_epg),
962 ntohs (mp->contract.dst_epg),
963 ntohl (mp->contract.acl_index),
964 rules, allowed_ethertypes);
967 rv = gbp_contract_delete (ntohs (mp->contract.src_epg),
968 ntohs (mp->contract.dst_epg));
971 REPLY_MACRO (VL_API_GBP_CONTRACT_ADD_DEL_REPLY + GBP_MSG_BASE);
975 gbp_contract_send_details (gbp_contract_t * gbpc, void *args)
977 vl_api_gbp_contract_details_t *mp;
981 mp = vl_msg_api_alloc (sizeof (*mp));
985 clib_memset (mp, 0, sizeof (*mp));
986 mp->_vl_msg_id = ntohs (VL_API_GBP_CONTRACT_DETAILS + GBP_MSG_BASE);
987 mp->context = ctx->context;
989 mp->contract.src_epg = ntohs (gbpc->gc_key.gck_src);
990 mp->contract.dst_epg = ntohs (gbpc->gc_key.gck_dst);
991 // mp->contract.acl_index = ntohl (gbpc->gc_value.gc_acl_index);
993 vl_api_send_msg (ctx->reg, (u8 *) mp);
999 vl_api_gbp_contract_dump_t_handler (vl_api_gbp_contract_dump_t * mp)
1001 vl_api_registration_t *reg;
1003 reg = vl_api_client_index_to_registration (mp->client_index);
1007 gbp_walk_ctx_t ctx = {
1009 .context = mp->context,
1012 gbp_contract_walk (gbp_contract_send_details, &ctx);
1016 gbp_vxlan_tunnel_mode_2_layer (vl_api_gbp_vxlan_tunnel_mode_t mode,
1017 gbp_vxlan_tunnel_layer_t * l)
1019 mode = clib_net_to_host_u32 (mode);
1023 case GBP_VXLAN_TUNNEL_MODE_L2:
1024 *l = GBP_VXLAN_TUN_L2;
1026 case GBP_VXLAN_TUNNEL_MODE_L3:
1027 *l = GBP_VXLAN_TUN_L3;
1034 vl_api_gbp_vxlan_tunnel_add_t_handler (vl_api_gbp_vxlan_tunnel_add_t * mp)
1036 vl_api_gbp_vxlan_tunnel_add_reply_t *rmp;
1037 gbp_vxlan_tunnel_layer_t layer;
1041 rv = gbp_vxlan_tunnel_mode_2_layer (mp->tunnel.mode, &layer);
1046 rv = gbp_vxlan_tunnel_add (ntohl (mp->tunnel.vni),
1048 ntohl (mp->tunnel.bd_rd_id), &sw_if_index);
1052 REPLY_MACRO2 (VL_API_GBP_VXLAN_TUNNEL_ADD_REPLY + GBP_MSG_BASE,
1054 rmp->sw_if_index = htonl (sw_if_index);
1060 vl_api_gbp_vxlan_tunnel_del_t_handler (vl_api_gbp_vxlan_tunnel_add_t * mp)
1062 vl_api_gbp_vxlan_tunnel_del_reply_t *rmp;
1065 rv = gbp_vxlan_tunnel_del (ntohl (mp->tunnel.vni));
1067 REPLY_MACRO (VL_API_GBP_VXLAN_TUNNEL_DEL_REPLY + GBP_MSG_BASE);
1070 static vl_api_gbp_vxlan_tunnel_mode_t
1071 gbp_vxlan_tunnel_layer_2_mode (gbp_vxlan_tunnel_layer_t layer)
1073 vl_api_gbp_vxlan_tunnel_mode_t mode = GBP_VXLAN_TUNNEL_MODE_L2;
1077 case GBP_VXLAN_TUN_L2:
1078 mode = GBP_VXLAN_TUNNEL_MODE_L2;
1080 case GBP_VXLAN_TUN_L3:
1081 mode = GBP_VXLAN_TUNNEL_MODE_L3;
1084 mode = clib_host_to_net_u32 (mode);
1090 gbp_vxlan_tunnel_send_details (gbp_vxlan_tunnel_t * gt, void *args)
1092 vl_api_gbp_vxlan_tunnel_details_t *mp;
1093 gbp_walk_ctx_t *ctx;
1096 mp = vl_msg_api_alloc (sizeof (*mp));
1100 memset (mp, 0, sizeof (*mp));
1101 mp->_vl_msg_id = htons (VL_API_GBP_VXLAN_TUNNEL_DETAILS + GBP_MSG_BASE);
1102 mp->context = ctx->context;
1104 mp->tunnel.vni = htonl (gt->gt_vni);
1105 mp->tunnel.mode = gbp_vxlan_tunnel_layer_2_mode (gt->gt_layer);
1106 mp->tunnel.bd_rd_id = htonl (gt->gt_bd_rd_id);
1108 vl_api_send_msg (ctx->reg, (u8 *) mp);
1114 vl_api_gbp_vxlan_tunnel_dump_t_handler (vl_api_gbp_vxlan_tunnel_dump_t * mp)
1116 vl_api_registration_t *reg;
1118 reg = vl_api_client_index_to_registration (mp->client_index);
1122 gbp_walk_ctx_t ctx = {
1124 .context = mp->context,
1127 gbp_vxlan_walk (gbp_vxlan_tunnel_send_details, &ctx);
1132 * Add vpe's API message handlers to the table.
1133 * vlib has already mapped shared memory and
1134 * added the client registration handlers.
1135 * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
1137 #define vl_msg_name_crc_list
1138 #include <gbp/gbp_all_api_h.h>
1139 #undef vl_msg_name_crc_list
1142 setup_message_id_table (api_main_t * am)
1144 #define _(id,n,crc) \
1145 vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + GBP_MSG_BASE);
1146 foreach_vl_msg_name_crc_gbp;
1151 gbp_api_hookup (vlib_main_t * vm)
1154 vl_msg_api_set_handlers(VL_API_##N + GBP_MSG_BASE, \
1156 vl_api_##n##_t_handler, \
1158 vl_api_##n##_t_endian, \
1159 vl_api_##n##_t_print, \
1160 sizeof(vl_api_##n##_t), 1);
1161 foreach_gbp_api_msg;
1165 static clib_error_t *
1166 gbp_init (vlib_main_t * vm)
1168 api_main_t *am = &api_main;
1169 gbp_main_t *gbpm = &gbp_main;
1170 u8 *name = format (0, "gbp_%08x%c", api_version, 0);
1172 gbpm->gbp_acl_user_id = ~0;
1174 /* Ask for a correctly-sized block of API message decode slots */
1175 msg_id_base = vl_msg_api_get_msg_ids ((char *) name,
1176 VL_MSG_FIRST_AVAILABLE);
1177 gbp_api_hookup (vm);
1179 /* Add our API messages to the global name_crc hash table */
1180 setup_message_id_table (am);
1186 VLIB_API_INIT_FUNCTION (gbp_init);
1189 VLIB_PLUGIN_REGISTER () = {
1190 .version = VPP_BUILD_VER,
1191 .description = "Group Based Policy",
1197 * fd.io coding-style-patch-verification: ON
1200 * eval: (c-set-style "gnu")