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.api_enum.h>
41 #include <gbp/gbp.api_types.h>
42 #include <vnet/format_fns.h>
43 #include <vlibapi/api_helper_macros.h>
44 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
45 #include "gbp_api_print.h"
49 static u16 msg_id_base;
51 #define GBP_MSG_BASE msg_id_base
53 static gbp_endpoint_flags_t
54 gbp_endpoint_flags_decode (vl_api_gbp_endpoint_flags_t v)
56 gbp_endpoint_flags_t f = GBP_ENDPOINT_FLAG_NONE;
60 if (v & GBP_API_ENDPOINT_FLAG_BOUNCE)
61 f |= GBP_ENDPOINT_FLAG_BOUNCE;
62 if (v & GBP_API_ENDPOINT_FLAG_REMOTE)
63 f |= GBP_ENDPOINT_FLAG_REMOTE;
64 if (v & GBP_API_ENDPOINT_FLAG_LEARNT)
65 f |= GBP_ENDPOINT_FLAG_LEARNT;
66 if (v & GBP_API_ENDPOINT_FLAG_EXTERNAL)
67 f |= GBP_ENDPOINT_FLAG_EXTERNAL;
72 static vl_api_gbp_endpoint_flags_t
73 gbp_endpoint_flags_encode (gbp_endpoint_flags_t f)
75 vl_api_gbp_endpoint_flags_t v = 0;
78 if (f & GBP_ENDPOINT_FLAG_BOUNCE)
79 v |= GBP_API_ENDPOINT_FLAG_BOUNCE;
80 if (f & GBP_ENDPOINT_FLAG_REMOTE)
81 v |= GBP_API_ENDPOINT_FLAG_REMOTE;
82 if (f & GBP_ENDPOINT_FLAG_LEARNT)
83 v |= GBP_API_ENDPOINT_FLAG_LEARNT;
84 if (f & GBP_ENDPOINT_FLAG_EXTERNAL)
85 v |= GBP_API_ENDPOINT_FLAG_EXTERNAL;
93 vl_api_gbp_endpoint_add_t_handler (vl_api_gbp_endpoint_add_t * mp)
95 vl_api_gbp_endpoint_add_reply_t *rmp;
96 gbp_endpoint_flags_t gef;
97 u32 sw_if_index, handle;
102 VALIDATE_SW_IF_INDEX (&(mp->endpoint));
104 gef = gbp_endpoint_flags_decode (mp->endpoint.flags), ips = NULL;
105 sw_if_index = ntohl (mp->endpoint.sw_if_index);
107 if (mp->endpoint.n_ips)
109 vec_validate (ips, mp->endpoint.n_ips - 1);
111 vec_foreach_index (ii, ips)
113 ip_address_decode (&mp->endpoint.ips[ii], &ips[ii]);
116 mac_address_decode (mp->endpoint.mac, &mac);
118 if (GBP_ENDPOINT_FLAG_REMOTE & gef)
120 ip46_address_t tun_src, tun_dst;
122 ip_address_decode (&mp->endpoint.tun.src, &tun_src);
123 ip_address_decode (&mp->endpoint.tun.dst, &tun_dst);
125 rv = gbp_endpoint_update_and_lock (GBP_ENDPOINT_SRC_CP,
126 sw_if_index, ips, &mac,
127 INDEX_INVALID, INDEX_INVALID,
128 ntohs (mp->endpoint.sclass),
129 gef, &tun_src, &tun_dst, &handle);
133 rv = gbp_endpoint_update_and_lock (GBP_ENDPOINT_SRC_CP,
134 sw_if_index, ips, &mac,
135 INDEX_INVALID, INDEX_INVALID,
136 ntohs (mp->endpoint.sclass),
137 gef, NULL, NULL, &handle);
140 BAD_SW_IF_INDEX_LABEL;
143 REPLY_MACRO2 (VL_API_GBP_ENDPOINT_ADD_REPLY + GBP_MSG_BASE,
145 rmp->handle = htonl (handle);
151 vl_api_gbp_endpoint_del_t_handler (vl_api_gbp_endpoint_del_t * mp)
153 vl_api_gbp_endpoint_del_reply_t *rmp;
156 gbp_endpoint_unlock (GBP_ENDPOINT_SRC_CP, ntohl (mp->handle));
158 REPLY_MACRO (VL_API_GBP_ENDPOINT_DEL_REPLY + GBP_MSG_BASE);
161 typedef struct gbp_walk_ctx_t_
163 vl_api_registration_t *reg;
168 gbp_endpoint_send_details (index_t gei, void *args)
170 vl_api_gbp_endpoint_details_t *mp;
171 gbp_endpoint_loc_t *gel;
172 gbp_endpoint_fwd_t *gef;
178 ge = gbp_endpoint_get (gei);
180 n_ips = vec_len (ge->ge_key.gek_ips);
181 mp = vl_msg_api_alloc (sizeof (*mp) + (sizeof (*mp->endpoint.ips) * n_ips));
185 clib_memset (mp, 0, sizeof (*mp));
186 mp->_vl_msg_id = ntohs (VL_API_GBP_ENDPOINT_DETAILS + GBP_MSG_BASE);
187 mp->context = ctx->context;
189 gel = &ge->ge_locs[0];
192 if (gbp_endpoint_is_remote (ge))
194 mp->endpoint.sw_if_index = ntohl (gel->tun.gel_parent_sw_if_index);
195 ip_address_encode (&gel->tun.gel_src, IP46_TYPE_ANY,
196 &mp->endpoint.tun.src);
197 ip_address_encode (&gel->tun.gel_dst, IP46_TYPE_ANY,
198 &mp->endpoint.tun.dst);
202 mp->endpoint.sw_if_index =
203 ntohl (gbp_itf_get_sw_if_index (gef->gef_itf));
205 mp->endpoint.sclass = ntohs (ge->ge_fwd.gef_sclass);
206 mp->endpoint.n_ips = n_ips;
207 mp->endpoint.flags = gbp_endpoint_flags_encode (gef->gef_flags);
208 mp->handle = htonl (gei);
210 clib_host_to_net_f64 (vlib_time_now (vlib_get_main ()) -
212 mac_address_encode (&ge->ge_key.gek_mac, mp->endpoint.mac);
214 vec_foreach_index (ii, ge->ge_key.gek_ips)
216 ip_address_encode (&ge->ge_key.gek_ips[ii].fp_addr,
217 IP46_TYPE_ANY, &mp->endpoint.ips[ii]);
220 vl_api_send_msg (ctx->reg, (u8 *) mp);
222 return (WALK_CONTINUE);
226 vl_api_gbp_endpoint_dump_t_handler (vl_api_gbp_endpoint_dump_t * mp)
228 vl_api_registration_t *reg;
230 reg = vl_api_client_index_to_registration (mp->client_index);
234 gbp_walk_ctx_t ctx = {
236 .context = mp->context,
239 gbp_endpoint_walk (gbp_endpoint_send_details, &ctx);
243 gbp_retention_decode (const vl_api_gbp_endpoint_retention_t * in,
244 gbp_endpoint_retention_t * out)
246 out->remote_ep_timeout = ntohl (in->remote_ep_timeout);
250 vl_api_gbp_endpoint_group_add_t_handler
251 (vl_api_gbp_endpoint_group_add_t * mp)
253 vl_api_gbp_endpoint_group_add_reply_t *rmp;
254 gbp_endpoint_retention_t retention;
257 gbp_retention_decode (&mp->epg.retention, &retention);
259 rv = gbp_endpoint_group_add_and_lock (ntohl (mp->epg.vnid),
260 ntohs (mp->epg.sclass),
261 ntohl (mp->epg.bd_id),
262 ntohl (mp->epg.rd_id),
263 ntohl (mp->epg.uplink_sw_if_index),
266 REPLY_MACRO (VL_API_GBP_ENDPOINT_GROUP_ADD_REPLY + GBP_MSG_BASE);
270 vl_api_gbp_endpoint_group_del_t_handler
271 (vl_api_gbp_endpoint_group_del_t * mp)
273 vl_api_gbp_endpoint_group_del_reply_t *rmp;
276 rv = gbp_endpoint_group_delete (ntohs (mp->sclass));
278 REPLY_MACRO (VL_API_GBP_ENDPOINT_GROUP_DEL_REPLY + GBP_MSG_BASE);
281 static gbp_bridge_domain_flags_t
282 gbp_bridge_domain_flags_from_api (vl_api_gbp_bridge_domain_flags_t a)
284 gbp_bridge_domain_flags_t g;
286 g = GBP_BD_FLAG_NONE;
287 a = clib_net_to_host_u32 (a);
289 if (a & GBP_BD_API_FLAG_DO_NOT_LEARN)
290 g |= GBP_BD_FLAG_DO_NOT_LEARN;
291 if (a & GBP_BD_API_FLAG_UU_FWD_DROP)
292 g |= GBP_BD_FLAG_UU_FWD_DROP;
293 if (a & GBP_BD_API_FLAG_MCAST_DROP)
294 g |= GBP_BD_FLAG_MCAST_DROP;
295 if (a & GBP_BD_API_FLAG_UCAST_ARP)
296 g |= GBP_BD_FLAG_UCAST_ARP;
302 vl_api_gbp_bridge_domain_add_t_handler (vl_api_gbp_bridge_domain_add_t * mp)
304 vl_api_gbp_bridge_domain_add_reply_t *rmp;
307 rv = gbp_bridge_domain_add_and_lock (ntohl (mp->bd.bd_id),
308 ntohl (mp->bd.rd_id),
309 gbp_bridge_domain_flags_from_api
311 ntohl (mp->bd.bvi_sw_if_index),
312 ntohl (mp->bd.uu_fwd_sw_if_index),
313 ntohl (mp->bd.bm_flood_sw_if_index));
315 REPLY_MACRO (VL_API_GBP_BRIDGE_DOMAIN_ADD_REPLY + GBP_MSG_BASE);
319 vl_api_gbp_bridge_domain_del_t_handler (vl_api_gbp_bridge_domain_del_t * mp)
321 vl_api_gbp_bridge_domain_del_reply_t *rmp;
324 rv = gbp_bridge_domain_delete (ntohl (mp->bd_id));
326 REPLY_MACRO (VL_API_GBP_BRIDGE_DOMAIN_DEL_REPLY + GBP_MSG_BASE);
330 vl_api_gbp_route_domain_add_t_handler (vl_api_gbp_route_domain_add_t * mp)
332 vl_api_gbp_route_domain_add_reply_t *rmp;
335 rv = gbp_route_domain_add_and_lock (ntohl (mp->rd.rd_id),
336 ntohs (mp->rd.scope),
337 ntohl (mp->rd.ip4_table_id),
338 ntohl (mp->rd.ip6_table_id),
339 ntohl (mp->rd.ip4_uu_sw_if_index),
340 ntohl (mp->rd.ip6_uu_sw_if_index));
342 REPLY_MACRO (VL_API_GBP_ROUTE_DOMAIN_ADD_REPLY + GBP_MSG_BASE);
346 vl_api_gbp_route_domain_del_t_handler (vl_api_gbp_route_domain_del_t * mp)
348 vl_api_gbp_route_domain_del_reply_t *rmp;
351 rv = gbp_route_domain_delete (ntohl (mp->rd_id));
353 REPLY_MACRO (VL_API_GBP_ROUTE_DOMAIN_DEL_REPLY + GBP_MSG_BASE);
357 gub_subnet_type_from_api (vl_api_gbp_subnet_type_t a, gbp_subnet_type_t * t)
359 a = clib_net_to_host_u32 (a);
363 case GBP_API_SUBNET_TRANSPORT:
364 *t = GBP_SUBNET_TRANSPORT;
366 case GBP_API_SUBNET_L3_OUT:
367 *t = GBP_SUBNET_L3_OUT;
369 case GBP_API_SUBNET_ANON_L3_OUT:
370 *t = GBP_SUBNET_ANON_L3_OUT;
372 case GBP_API_SUBNET_STITCHED_INTERNAL:
373 *t = GBP_SUBNET_STITCHED_INTERNAL;
375 case GBP_API_SUBNET_STITCHED_EXTERNAL:
376 *t = GBP_SUBNET_STITCHED_EXTERNAL;
384 vl_api_gbp_subnet_add_del_t_handler (vl_api_gbp_subnet_add_del_t * mp)
386 vl_api_gbp_subnet_add_del_reply_t *rmp;
387 gbp_subnet_type_t type;
391 ip_prefix_decode (&mp->subnet.prefix, &pfx);
393 rv = gub_subnet_type_from_api (mp->subnet.type, &type);
399 rv = gbp_subnet_add (ntohl (mp->subnet.rd_id),
401 ntohl (mp->subnet.sw_if_index),
402 ntohs (mp->subnet.sclass));
404 rv = gbp_subnet_del (ntohl (mp->subnet.rd_id), &pfx);
407 REPLY_MACRO (VL_API_GBP_SUBNET_ADD_DEL_REPLY + GBP_MSG_BASE);
410 static vl_api_gbp_subnet_type_t
411 gub_subnet_type_to_api (gbp_subnet_type_t t)
413 vl_api_gbp_subnet_type_t a = 0;
417 case GBP_SUBNET_TRANSPORT:
418 a = GBP_API_SUBNET_TRANSPORT;
420 case GBP_SUBNET_STITCHED_INTERNAL:
421 a = GBP_API_SUBNET_STITCHED_INTERNAL;
423 case GBP_SUBNET_STITCHED_EXTERNAL:
424 a = GBP_API_SUBNET_STITCHED_EXTERNAL;
426 case GBP_SUBNET_L3_OUT:
427 a = GBP_API_SUBNET_L3_OUT;
429 case GBP_SUBNET_ANON_L3_OUT:
430 a = GBP_API_SUBNET_ANON_L3_OUT;
434 a = clib_host_to_net_u32 (a);
440 gbp_subnet_send_details (u32 rd_id,
441 const fib_prefix_t * pfx,
442 gbp_subnet_type_t type,
443 u32 sw_if_index, sclass_t sclass, void *args)
445 vl_api_gbp_subnet_details_t *mp;
449 mp = vl_msg_api_alloc (sizeof (*mp));
453 clib_memset (mp, 0, sizeof (*mp));
454 mp->_vl_msg_id = ntohs (VL_API_GBP_SUBNET_DETAILS + GBP_MSG_BASE);
455 mp->context = ctx->context;
457 mp->subnet.type = gub_subnet_type_to_api (type);
458 mp->subnet.sw_if_index = ntohl (sw_if_index);
459 mp->subnet.sclass = ntohs (sclass);
460 mp->subnet.rd_id = ntohl (rd_id);
461 ip_prefix_encode (pfx, &mp->subnet.prefix);
463 vl_api_send_msg (ctx->reg, (u8 *) mp);
465 return (WALK_CONTINUE);
469 vl_api_gbp_subnet_dump_t_handler (vl_api_gbp_subnet_dump_t * mp)
471 vl_api_registration_t *reg;
473 reg = vl_api_client_index_to_registration (mp->client_index);
477 gbp_walk_ctx_t ctx = {
479 .context = mp->context,
482 gbp_subnet_walk (gbp_subnet_send_details, &ctx);
486 gbp_endpoint_group_send_details (gbp_endpoint_group_t * gg, void *args)
488 vl_api_gbp_endpoint_group_details_t *mp;
492 mp = vl_msg_api_alloc (sizeof (*mp));
496 clib_memset (mp, 0, sizeof (*mp));
497 mp->_vl_msg_id = ntohs (VL_API_GBP_ENDPOINT_GROUP_DETAILS + GBP_MSG_BASE);
498 mp->context = ctx->context;
500 mp->epg.uplink_sw_if_index = ntohl (gg->gg_uplink_sw_if_index);
501 mp->epg.vnid = ntohl (gg->gg_vnid);
502 mp->epg.sclass = ntohs (gg->gg_sclass);
503 mp->epg.bd_id = ntohl (gbp_endpoint_group_get_bd_id (gg));
504 mp->epg.rd_id = ntohl (gbp_route_domain_get_rd_id (gg->gg_rd));
506 vl_api_send_msg (ctx->reg, (u8 *) mp);
512 vl_api_gbp_endpoint_group_dump_t_handler (vl_api_gbp_endpoint_group_dump_t *
515 vl_api_registration_t *reg;
517 reg = vl_api_client_index_to_registration (mp->client_index);
521 gbp_walk_ctx_t ctx = {
523 .context = mp->context,
526 gbp_endpoint_group_walk (gbp_endpoint_group_send_details, &ctx);
530 gbp_bridge_domain_send_details (gbp_bridge_domain_t * gb, void *args)
532 vl_api_gbp_bridge_domain_details_t *mp;
533 gbp_route_domain_t *gr;
537 mp = vl_msg_api_alloc (sizeof (*mp));
541 memset (mp, 0, sizeof (*mp));
542 mp->_vl_msg_id = ntohs (VL_API_GBP_BRIDGE_DOMAIN_DETAILS + GBP_MSG_BASE);
543 mp->context = ctx->context;
545 gr = gbp_route_domain_get (gb->gb_rdi);
547 mp->bd.bd_id = ntohl (gb->gb_bd_id);
548 mp->bd.rd_id = ntohl (gr->grd_id);
549 mp->bd.bvi_sw_if_index = ntohl (gb->gb_bvi_sw_if_index);
550 mp->bd.uu_fwd_sw_if_index = ntohl (gb->gb_uu_fwd_sw_if_index);
551 mp->bd.bm_flood_sw_if_index =
552 ntohl (gbp_itf_get_sw_if_index (gb->gb_bm_flood_itf));
554 vl_api_send_msg (ctx->reg, (u8 *) mp);
560 vl_api_gbp_bridge_domain_dump_t_handler (vl_api_gbp_bridge_domain_dump_t * mp)
562 vl_api_registration_t *reg;
564 reg = vl_api_client_index_to_registration (mp->client_index);
568 gbp_walk_ctx_t ctx = {
570 .context = mp->context,
573 gbp_bridge_domain_walk (gbp_bridge_domain_send_details, &ctx);
577 gbp_route_domain_send_details (gbp_route_domain_t * grd, void *args)
579 vl_api_gbp_route_domain_details_t *mp;
583 mp = vl_msg_api_alloc (sizeof (*mp));
587 memset (mp, 0, sizeof (*mp));
588 mp->_vl_msg_id = ntohs (VL_API_GBP_ROUTE_DOMAIN_DETAILS + GBP_MSG_BASE);
589 mp->context = ctx->context;
591 mp->rd.rd_id = ntohl (grd->grd_id);
592 mp->rd.ip4_uu_sw_if_index =
593 ntohl (grd->grd_uu_sw_if_index[FIB_PROTOCOL_IP4]);
594 mp->rd.ip6_uu_sw_if_index =
595 ntohl (grd->grd_uu_sw_if_index[FIB_PROTOCOL_IP6]);
597 vl_api_send_msg (ctx->reg, (u8 *) mp);
603 vl_api_gbp_route_domain_dump_t_handler (vl_api_gbp_route_domain_dump_t * mp)
605 vl_api_registration_t *reg;
607 reg = vl_api_client_index_to_registration (mp->client_index);
611 gbp_walk_ctx_t ctx = {
613 .context = mp->context,
616 gbp_route_domain_walk (gbp_route_domain_send_details, &ctx);
620 vl_api_gbp_recirc_add_del_t_handler (vl_api_gbp_recirc_add_del_t * mp)
622 vl_api_gbp_recirc_add_del_reply_t *rmp;
626 sw_if_index = ntohl (mp->recirc.sw_if_index);
627 if (!vnet_sw_if_index_is_api_valid (sw_if_index))
628 goto bad_sw_if_index;
631 rv = gbp_recirc_add (sw_if_index,
632 ntohs (mp->recirc.sclass), mp->recirc.is_ext);
634 rv = gbp_recirc_delete (sw_if_index);
636 BAD_SW_IF_INDEX_LABEL;
638 REPLY_MACRO (VL_API_GBP_RECIRC_ADD_DEL_REPLY + GBP_MSG_BASE);
642 gbp_recirc_send_details (gbp_recirc_t * gr, void *args)
644 vl_api_gbp_recirc_details_t *mp;
648 mp = vl_msg_api_alloc (sizeof (*mp));
652 clib_memset (mp, 0, sizeof (*mp));
653 mp->_vl_msg_id = ntohs (VL_API_GBP_RECIRC_DETAILS + GBP_MSG_BASE);
654 mp->context = ctx->context;
656 mp->recirc.sclass = ntohs (gr->gr_sclass);
657 mp->recirc.sw_if_index = ntohl (gr->gr_sw_if_index);
658 mp->recirc.is_ext = gr->gr_is_ext;
660 vl_api_send_msg (ctx->reg, (u8 *) mp);
662 return (WALK_CONTINUE);
666 vl_api_gbp_recirc_dump_t_handler (vl_api_gbp_recirc_dump_t * mp)
668 vl_api_registration_t *reg;
670 reg = vl_api_client_index_to_registration (mp->client_index);
674 gbp_walk_ctx_t ctx = {
676 .context = mp->context,
679 gbp_recirc_walk (gbp_recirc_send_details, &ctx);
683 vl_api_gbp_ext_itf_add_del_t_handler (vl_api_gbp_ext_itf_add_del_t * mp)
685 vl_api_gbp_ext_itf_add_del_reply_t *rmp;
686 u32 sw_if_index = ~0;
687 vl_api_gbp_ext_itf_t *ext_itf;
690 ext_itf = &mp->ext_itf;
692 sw_if_index = ntohl (ext_itf->sw_if_index);
694 if (!vnet_sw_if_index_is_api_valid (sw_if_index))
695 goto bad_sw_if_index;
698 rv = gbp_ext_itf_add (sw_if_index,
699 ntohl (ext_itf->bd_id), ntohl (ext_itf->rd_id),
700 ntohl (ext_itf->flags));
702 rv = gbp_ext_itf_delete (sw_if_index);
704 BAD_SW_IF_INDEX_LABEL;
706 REPLY_MACRO (VL_API_GBP_EXT_ITF_ADD_DEL_REPLY + GBP_MSG_BASE);
710 gbp_ext_itf_send_details (gbp_ext_itf_t * gx, void *args)
712 vl_api_gbp_ext_itf_details_t *mp;
716 mp = vl_msg_api_alloc (sizeof (*mp));
720 clib_memset (mp, 0, sizeof (*mp));
721 mp->_vl_msg_id = ntohs (VL_API_GBP_EXT_ITF_DETAILS + GBP_MSG_BASE);
722 mp->context = ctx->context;
724 mp->ext_itf.flags = ntohl (gx->gx_flags);
725 mp->ext_itf.bd_id = ntohl (gbp_bridge_domain_get_bd_id (gx->gx_bd));
726 mp->ext_itf.rd_id = ntohl (gbp_route_domain_get_rd_id (gx->gx_rd));
727 mp->ext_itf.sw_if_index = ntohl (gbp_itf_get_sw_if_index (gx->gx_itf));
729 vl_api_send_msg (ctx->reg, (u8 *) mp);
731 return (WALK_CONTINUE);
735 vl_api_gbp_ext_itf_dump_t_handler (vl_api_gbp_ext_itf_dump_t * mp)
737 vl_api_registration_t *reg;
739 reg = vl_api_client_index_to_registration (mp->client_index);
743 gbp_walk_ctx_t ctx = {
745 .context = mp->context,
748 gbp_ext_itf_walk (gbp_ext_itf_send_details, &ctx);
752 gbp_contract_rule_action_deocde (vl_api_gbp_rule_action_t in,
753 gbp_rule_action_t * out)
755 in = clib_net_to_host_u32 (in);
759 case GBP_API_RULE_PERMIT:
760 *out = GBP_RULE_PERMIT;
762 case GBP_API_RULE_DENY:
763 *out = GBP_RULE_DENY;
765 case GBP_API_RULE_REDIRECT:
766 *out = GBP_RULE_REDIRECT;
774 gbp_hash_mode_decode (vl_api_gbp_hash_mode_t in, gbp_hash_mode_t * out)
776 in = clib_net_to_host_u32 (in);
780 case GBP_API_HASH_MODE_SRC_IP:
781 *out = GBP_HASH_MODE_SRC_IP;
783 case GBP_API_HASH_MODE_DST_IP:
784 *out = GBP_HASH_MODE_DST_IP;
786 case GBP_API_HASH_MODE_SYMMETRIC:
787 *out = GBP_HASH_MODE_SYMMETRIC;
795 gbp_next_hop_decode (const vl_api_gbp_next_hop_t * in, index_t * gnhi)
801 gbd = gbp_bridge_domain_find_and_lock (ntohl (in->bd_id));
803 if (INDEX_INVALID == gbd)
804 return (VNET_API_ERROR_BD_NOT_MODIFIABLE);
806 grd = gbp_route_domain_find_and_lock (ntohl (in->rd_id));
808 if (INDEX_INVALID == grd)
809 return (VNET_API_ERROR_NO_SUCH_FIB);
811 ip_address_decode (&in->ip, &ip);
812 mac_address_decode (in->mac, &mac);
814 *gnhi = gbp_next_hop_alloc (&ip, grd, &mac, gbd);
820 gbp_next_hop_set_decode (const vl_api_gbp_next_hop_set_t * in,
821 gbp_hash_mode_t * hash_mode, index_t ** out)
824 index_t *gnhis = NULL;
828 rv = gbp_hash_mode_decode (in->hash_mode, hash_mode);
833 vec_validate (gnhis, in->n_nhs - 1);
835 for (ii = 0; ii < in->n_nhs; ii++)
837 rv = gbp_next_hop_decode (&in->nhs[ii], &gnhis[ii]);
851 gbp_contract_rule_decode (const vl_api_gbp_rule_t * in, index_t * gui)
853 gbp_hash_mode_t hash_mode;
854 gbp_rule_action_t action;
858 rv = gbp_contract_rule_action_deocde (in->action, &action);
863 if (GBP_RULE_REDIRECT == action)
865 rv = gbp_next_hop_set_decode (&in->nh_set, &hash_mode, &nhs);
872 hash_mode = GBP_HASH_MODE_SRC_IP;
875 *gui = gbp_rule_alloc (action, hash_mode, nhs);
881 gbp_contract_rules_decode (u8 n_rules,
882 const vl_api_gbp_rule_t * rules, index_t ** out)
884 index_t *guis = NULL;
894 vec_validate (guis, n_rules - 1);
896 for (ii = 0; ii < n_rules; ii++)
898 rv = gbp_contract_rule_decode (&rules[ii], &guis[ii]);
903 vec_foreach (gui, guis) gbp_rule_free (*gui);
914 vl_api_gbp_contract_add_del_t_handler (vl_api_gbp_contract_add_del_t * mp)
916 vl_api_gbp_contract_add_del_reply_t *rmp;
917 u16 *allowed_ethertypes;
918 u32 stats_index = ~0;
925 rv = gbp_contract_rules_decode (mp->contract.n_rules,
926 mp->contract.rules, &rules);
930 allowed_ethertypes = NULL;
933 * allowed ether types
935 n_et = mp->contract.n_ether_types;
936 vec_validate (allowed_ethertypes, n_et - 1);
938 for (ii = 0; ii < n_et; ii++)
940 /* leave the ether types in network order */
941 allowed_ethertypes[ii] = mp->contract.allowed_ethertypes[ii];
944 rv = gbp_contract_update (ntohs (mp->contract.scope),
945 ntohs (mp->contract.sclass),
946 ntohs (mp->contract.dclass),
947 ntohl (mp->contract.acl_index),
948 rules, allowed_ethertypes, &stats_index);
951 rv = gbp_contract_delete (ntohs (mp->contract.scope),
952 ntohs (mp->contract.sclass),
953 ntohs (mp->contract.dclass));
957 REPLY_MACRO2 (VL_API_GBP_CONTRACT_ADD_DEL_REPLY + GBP_MSG_BASE,
959 rmp->stats_index = htonl (stats_index);
965 gbp_contract_send_details (gbp_contract_t * gbpc, void *args)
967 vl_api_gbp_contract_details_t *mp;
971 mp = vl_msg_api_alloc (sizeof (*mp));
975 clib_memset (mp, 0, sizeof (*mp));
976 mp->_vl_msg_id = ntohs (VL_API_GBP_CONTRACT_DETAILS + GBP_MSG_BASE);
977 mp->context = ctx->context;
979 mp->contract.sclass = ntohs (gbpc->gc_key.gck_src);
980 mp->contract.dclass = ntohs (gbpc->gc_key.gck_dst);
981 mp->contract.acl_index = ntohl (gbpc->gc_acl_index);
982 mp->contract.scope = ntohs (gbpc->gc_key.gck_scope);
984 vl_api_send_msg (ctx->reg, (u8 *) mp);
990 vl_api_gbp_contract_dump_t_handler (vl_api_gbp_contract_dump_t * mp)
992 vl_api_registration_t *reg;
994 reg = vl_api_client_index_to_registration (mp->client_index);
998 gbp_walk_ctx_t ctx = {
1000 .context = mp->context,
1003 gbp_contract_walk (gbp_contract_send_details, &ctx);
1007 gbp_vxlan_tunnel_mode_2_layer (vl_api_gbp_vxlan_tunnel_mode_t mode,
1008 gbp_vxlan_tunnel_layer_t * l)
1010 mode = clib_net_to_host_u32 (mode);
1014 case GBP_VXLAN_TUNNEL_MODE_L2:
1015 *l = GBP_VXLAN_TUN_L2;
1017 case GBP_VXLAN_TUNNEL_MODE_L3:
1018 *l = GBP_VXLAN_TUN_L3;
1025 vl_api_gbp_vxlan_tunnel_add_t_handler (vl_api_gbp_vxlan_tunnel_add_t * mp)
1027 vl_api_gbp_vxlan_tunnel_add_reply_t *rmp;
1028 gbp_vxlan_tunnel_layer_t layer;
1033 ip4_address_decode (mp->tunnel.src, &src);
1034 rv = gbp_vxlan_tunnel_mode_2_layer (mp->tunnel.mode, &layer);
1039 rv = gbp_vxlan_tunnel_add (ntohl (mp->tunnel.vni),
1041 ntohl (mp->tunnel.bd_rd_id), &src, &sw_if_index);
1045 REPLY_MACRO2 (VL_API_GBP_VXLAN_TUNNEL_ADD_REPLY + GBP_MSG_BASE,
1047 rmp->sw_if_index = htonl (sw_if_index);
1053 vl_api_gbp_vxlan_tunnel_del_t_handler (vl_api_gbp_vxlan_tunnel_add_t * mp)
1055 vl_api_gbp_vxlan_tunnel_del_reply_t *rmp;
1058 rv = gbp_vxlan_tunnel_del (ntohl (mp->tunnel.vni));
1060 REPLY_MACRO (VL_API_GBP_VXLAN_TUNNEL_DEL_REPLY + GBP_MSG_BASE);
1063 static vl_api_gbp_vxlan_tunnel_mode_t
1064 gbp_vxlan_tunnel_layer_2_mode (gbp_vxlan_tunnel_layer_t layer)
1066 vl_api_gbp_vxlan_tunnel_mode_t mode = GBP_VXLAN_TUNNEL_MODE_L2;
1070 case GBP_VXLAN_TUN_L2:
1071 mode = GBP_VXLAN_TUNNEL_MODE_L2;
1073 case GBP_VXLAN_TUN_L3:
1074 mode = GBP_VXLAN_TUNNEL_MODE_L3;
1077 mode = clib_host_to_net_u32 (mode);
1083 gbp_vxlan_tunnel_send_details (gbp_vxlan_tunnel_t * gt, void *args)
1085 vl_api_gbp_vxlan_tunnel_details_t *mp;
1086 gbp_walk_ctx_t *ctx;
1089 mp = vl_msg_api_alloc (sizeof (*mp));
1093 memset (mp, 0, sizeof (*mp));
1094 mp->_vl_msg_id = htons (VL_API_GBP_VXLAN_TUNNEL_DETAILS + GBP_MSG_BASE);
1095 mp->context = ctx->context;
1097 mp->tunnel.vni = htonl (gt->gt_vni);
1098 mp->tunnel.mode = gbp_vxlan_tunnel_layer_2_mode (gt->gt_layer);
1099 mp->tunnel.bd_rd_id = htonl (gt->gt_bd_rd_id);
1101 vl_api_send_msg (ctx->reg, (u8 *) mp);
1107 vl_api_gbp_vxlan_tunnel_dump_t_handler (vl_api_gbp_vxlan_tunnel_dump_t * mp)
1109 vl_api_registration_t *reg;
1111 reg = vl_api_client_index_to_registration (mp->client_index);
1115 gbp_walk_ctx_t ctx = {
1117 .context = mp->context,
1120 gbp_vxlan_walk (gbp_vxlan_tunnel_send_details, &ctx);
1123 #include <gbp/gbp.api.c>
1124 static clib_error_t *
1125 gbp_init (vlib_main_t * vm)
1127 gbp_main_t *gbpm = &gbp_main;
1129 gbpm->gbp_acl_user_id = ~0;
1131 /* Ask for a correctly-sized block of API message decode slots */
1132 msg_id_base = setup_message_id_table ();
1137 VLIB_API_INIT_FUNCTION (gbp_init);
1140 VLIB_PLUGIN_REGISTER () = {
1141 .version = VPP_BUILD_VER,
1142 .description = "Group Based Policy (GBP)",
1148 * fd.io coding-style-patch-verification: ON
1151 * eval: (c-set-style "gnu")