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 handle = INDEX_INVALID;
104 VALIDATE_SW_IF_INDEX (&(mp->endpoint));
106 gef = gbp_endpoint_flags_decode (mp->endpoint.flags), ips = NULL;
107 sw_if_index = ntohl (mp->endpoint.sw_if_index);
109 if (mp->endpoint.n_ips)
111 vec_validate (ips, mp->endpoint.n_ips - 1);
113 vec_foreach_index (ii, ips)
115 ip_address_decode (&mp->endpoint.ips[ii], &ips[ii]);
118 mac_address_decode (mp->endpoint.mac, &mac);
120 if (GBP_ENDPOINT_FLAG_REMOTE & gef)
122 ip46_address_t tun_src, tun_dst;
124 ip_address_decode (&mp->endpoint.tun.src, &tun_src);
125 ip_address_decode (&mp->endpoint.tun.dst, &tun_dst);
127 rv = gbp_endpoint_update_and_lock (GBP_ENDPOINT_SRC_CP,
128 sw_if_index, ips, &mac,
129 INDEX_INVALID, INDEX_INVALID,
130 ntohs (mp->endpoint.sclass),
131 gef, &tun_src, &tun_dst, &handle);
135 rv = gbp_endpoint_update_and_lock (GBP_ENDPOINT_SRC_CP,
136 sw_if_index, ips, &mac,
137 INDEX_INVALID, INDEX_INVALID,
138 ntohs (mp->endpoint.sclass),
139 gef, NULL, NULL, &handle);
142 BAD_SW_IF_INDEX_LABEL;
145 REPLY_MACRO2 (VL_API_GBP_ENDPOINT_ADD_REPLY + GBP_MSG_BASE,
147 rmp->handle = htonl (handle);
153 vl_api_gbp_endpoint_del_t_handler (vl_api_gbp_endpoint_del_t * mp)
155 vl_api_gbp_endpoint_del_reply_t *rmp;
158 gbp_endpoint_unlock (GBP_ENDPOINT_SRC_CP, ntohl (mp->handle));
160 REPLY_MACRO (VL_API_GBP_ENDPOINT_DEL_REPLY + GBP_MSG_BASE);
163 typedef struct gbp_walk_ctx_t_
165 vl_api_registration_t *reg;
170 gbp_endpoint_send_details (index_t gei, void *args)
172 vl_api_gbp_endpoint_details_t *mp;
173 gbp_endpoint_loc_t *gel;
174 gbp_endpoint_fwd_t *gef;
180 ge = gbp_endpoint_get (gei);
182 n_ips = vec_len (ge->ge_key.gek_ips);
183 mp = vl_msg_api_alloc (sizeof (*mp) + (sizeof (*mp->endpoint.ips) * n_ips));
187 clib_memset (mp, 0, sizeof (*mp));
188 mp->_vl_msg_id = ntohs (VL_API_GBP_ENDPOINT_DETAILS + GBP_MSG_BASE);
189 mp->context = ctx->context;
191 gel = &ge->ge_locs[0];
194 if (gbp_endpoint_is_remote (ge))
196 mp->endpoint.sw_if_index = ntohl (gel->tun.gel_parent_sw_if_index);
197 ip_address_encode (&gel->tun.gel_src, IP46_TYPE_ANY,
198 &mp->endpoint.tun.src);
199 ip_address_encode (&gel->tun.gel_dst, IP46_TYPE_ANY,
200 &mp->endpoint.tun.dst);
204 mp->endpoint.sw_if_index =
205 ntohl (gbp_itf_get_sw_if_index (gef->gef_itf));
207 mp->endpoint.sclass = ntohs (ge->ge_fwd.gef_sclass);
208 mp->endpoint.n_ips = n_ips;
209 mp->endpoint.flags = gbp_endpoint_flags_encode (gef->gef_flags);
210 mp->handle = htonl (gei);
212 clib_host_to_net_f64 (vlib_time_now (vlib_get_main ()) -
214 mac_address_encode (&ge->ge_key.gek_mac, mp->endpoint.mac);
216 vec_foreach_index (ii, ge->ge_key.gek_ips)
218 ip_address_encode (&ge->ge_key.gek_ips[ii].fp_addr,
219 IP46_TYPE_ANY, &mp->endpoint.ips[ii]);
222 vl_api_send_msg (ctx->reg, (u8 *) mp);
224 return (WALK_CONTINUE);
228 vl_api_gbp_endpoint_dump_t_handler (vl_api_gbp_endpoint_dump_t * mp)
230 vl_api_registration_t *reg;
232 reg = vl_api_client_index_to_registration (mp->client_index);
236 gbp_walk_ctx_t ctx = {
238 .context = mp->context,
241 gbp_endpoint_walk (gbp_endpoint_send_details, &ctx);
245 gbp_retention_decode (const vl_api_gbp_endpoint_retention_t * in,
246 gbp_endpoint_retention_t * out)
248 out->remote_ep_timeout = ntohl (in->remote_ep_timeout);
252 vl_api_gbp_endpoint_group_add_t_handler
253 (vl_api_gbp_endpoint_group_add_t * mp)
255 vl_api_gbp_endpoint_group_add_reply_t *rmp;
256 gbp_endpoint_retention_t retention;
259 gbp_retention_decode (&mp->epg.retention, &retention);
261 rv = gbp_endpoint_group_add_and_lock (ntohl (mp->epg.vnid),
262 ntohs (mp->epg.sclass),
263 ntohl (mp->epg.bd_id),
264 ntohl (mp->epg.rd_id),
265 ntohl (mp->epg.uplink_sw_if_index),
268 REPLY_MACRO (VL_API_GBP_ENDPOINT_GROUP_ADD_REPLY + GBP_MSG_BASE);
272 vl_api_gbp_endpoint_group_del_t_handler
273 (vl_api_gbp_endpoint_group_del_t * mp)
275 vl_api_gbp_endpoint_group_del_reply_t *rmp;
278 rv = gbp_endpoint_group_delete (ntohs (mp->sclass));
280 REPLY_MACRO (VL_API_GBP_ENDPOINT_GROUP_DEL_REPLY + GBP_MSG_BASE);
283 static gbp_bridge_domain_flags_t
284 gbp_bridge_domain_flags_from_api (vl_api_gbp_bridge_domain_flags_t a)
286 gbp_bridge_domain_flags_t g;
288 g = GBP_BD_FLAG_NONE;
289 a = clib_net_to_host_u32 (a);
291 if (a & GBP_BD_API_FLAG_DO_NOT_LEARN)
292 g |= GBP_BD_FLAG_DO_NOT_LEARN;
293 if (a & GBP_BD_API_FLAG_UU_FWD_DROP)
294 g |= GBP_BD_FLAG_UU_FWD_DROP;
295 if (a & GBP_BD_API_FLAG_MCAST_DROP)
296 g |= GBP_BD_FLAG_MCAST_DROP;
297 if (a & GBP_BD_API_FLAG_UCAST_ARP)
298 g |= GBP_BD_FLAG_UCAST_ARP;
304 vl_api_gbp_bridge_domain_add_t_handler (vl_api_gbp_bridge_domain_add_t * mp)
306 vl_api_gbp_bridge_domain_add_reply_t *rmp;
309 rv = gbp_bridge_domain_add_and_lock (ntohl (mp->bd.bd_id),
310 ntohl (mp->bd.rd_id),
311 gbp_bridge_domain_flags_from_api
313 ntohl (mp->bd.bvi_sw_if_index),
314 ntohl (mp->bd.uu_fwd_sw_if_index),
315 ntohl (mp->bd.bm_flood_sw_if_index));
317 REPLY_MACRO (VL_API_GBP_BRIDGE_DOMAIN_ADD_REPLY + GBP_MSG_BASE);
321 vl_api_gbp_bridge_domain_del_t_handler (vl_api_gbp_bridge_domain_del_t * mp)
323 vl_api_gbp_bridge_domain_del_reply_t *rmp;
326 rv = gbp_bridge_domain_delete (ntohl (mp->bd_id));
328 REPLY_MACRO (VL_API_GBP_BRIDGE_DOMAIN_DEL_REPLY + GBP_MSG_BASE);
332 vl_api_gbp_route_domain_add_t_handler (vl_api_gbp_route_domain_add_t * mp)
334 vl_api_gbp_route_domain_add_reply_t *rmp;
337 rv = gbp_route_domain_add_and_lock (ntohl (mp->rd.rd_id),
338 ntohs (mp->rd.scope),
339 ntohl (mp->rd.ip4_table_id),
340 ntohl (mp->rd.ip6_table_id),
341 ntohl (mp->rd.ip4_uu_sw_if_index),
342 ntohl (mp->rd.ip6_uu_sw_if_index));
344 REPLY_MACRO (VL_API_GBP_ROUTE_DOMAIN_ADD_REPLY + GBP_MSG_BASE);
348 vl_api_gbp_route_domain_del_t_handler (vl_api_gbp_route_domain_del_t * mp)
350 vl_api_gbp_route_domain_del_reply_t *rmp;
353 rv = gbp_route_domain_delete (ntohl (mp->rd_id));
355 REPLY_MACRO (VL_API_GBP_ROUTE_DOMAIN_DEL_REPLY + GBP_MSG_BASE);
359 gub_subnet_type_from_api (vl_api_gbp_subnet_type_t a, gbp_subnet_type_t * t)
361 a = clib_net_to_host_u32 (a);
365 case GBP_API_SUBNET_TRANSPORT:
366 *t = GBP_SUBNET_TRANSPORT;
368 case GBP_API_SUBNET_L3_OUT:
369 *t = GBP_SUBNET_L3_OUT;
371 case GBP_API_SUBNET_ANON_L3_OUT:
372 *t = GBP_SUBNET_ANON_L3_OUT;
374 case GBP_API_SUBNET_STITCHED_INTERNAL:
375 *t = GBP_SUBNET_STITCHED_INTERNAL;
377 case GBP_API_SUBNET_STITCHED_EXTERNAL:
378 *t = GBP_SUBNET_STITCHED_EXTERNAL;
386 vl_api_gbp_subnet_add_del_t_handler (vl_api_gbp_subnet_add_del_t * mp)
388 vl_api_gbp_subnet_add_del_reply_t *rmp;
389 gbp_subnet_type_t type;
393 ip_prefix_decode (&mp->subnet.prefix, &pfx);
395 rv = gub_subnet_type_from_api (mp->subnet.type, &type);
401 rv = gbp_subnet_add (ntohl (mp->subnet.rd_id),
403 ntohl (mp->subnet.sw_if_index),
404 ntohs (mp->subnet.sclass));
406 rv = gbp_subnet_del (ntohl (mp->subnet.rd_id), &pfx);
409 REPLY_MACRO (VL_API_GBP_SUBNET_ADD_DEL_REPLY + GBP_MSG_BASE);
412 static vl_api_gbp_subnet_type_t
413 gub_subnet_type_to_api (gbp_subnet_type_t t)
415 vl_api_gbp_subnet_type_t a = 0;
419 case GBP_SUBNET_TRANSPORT:
420 a = GBP_API_SUBNET_TRANSPORT;
422 case GBP_SUBNET_STITCHED_INTERNAL:
423 a = GBP_API_SUBNET_STITCHED_INTERNAL;
425 case GBP_SUBNET_STITCHED_EXTERNAL:
426 a = GBP_API_SUBNET_STITCHED_EXTERNAL;
428 case GBP_SUBNET_L3_OUT:
429 a = GBP_API_SUBNET_L3_OUT;
431 case GBP_SUBNET_ANON_L3_OUT:
432 a = GBP_API_SUBNET_ANON_L3_OUT;
436 a = clib_host_to_net_u32 (a);
442 gbp_subnet_send_details (u32 rd_id,
443 const fib_prefix_t * pfx,
444 gbp_subnet_type_t type,
445 u32 sw_if_index, sclass_t sclass, void *args)
447 vl_api_gbp_subnet_details_t *mp;
451 mp = vl_msg_api_alloc (sizeof (*mp));
455 clib_memset (mp, 0, sizeof (*mp));
456 mp->_vl_msg_id = ntohs (VL_API_GBP_SUBNET_DETAILS + GBP_MSG_BASE);
457 mp->context = ctx->context;
459 mp->subnet.type = gub_subnet_type_to_api (type);
460 mp->subnet.sw_if_index = ntohl (sw_if_index);
461 mp->subnet.sclass = ntohs (sclass);
462 mp->subnet.rd_id = ntohl (rd_id);
463 ip_prefix_encode (pfx, &mp->subnet.prefix);
465 vl_api_send_msg (ctx->reg, (u8 *) mp);
467 return (WALK_CONTINUE);
471 vl_api_gbp_subnet_dump_t_handler (vl_api_gbp_subnet_dump_t * mp)
473 vl_api_registration_t *reg;
475 reg = vl_api_client_index_to_registration (mp->client_index);
479 gbp_walk_ctx_t ctx = {
481 .context = mp->context,
484 gbp_subnet_walk (gbp_subnet_send_details, &ctx);
488 gbp_endpoint_group_send_details (gbp_endpoint_group_t * gg, void *args)
490 vl_api_gbp_endpoint_group_details_t *mp;
494 mp = vl_msg_api_alloc (sizeof (*mp));
498 clib_memset (mp, 0, sizeof (*mp));
499 mp->_vl_msg_id = ntohs (VL_API_GBP_ENDPOINT_GROUP_DETAILS + GBP_MSG_BASE);
500 mp->context = ctx->context;
502 mp->epg.uplink_sw_if_index = ntohl (gg->gg_uplink_sw_if_index);
503 mp->epg.vnid = ntohl (gg->gg_vnid);
504 mp->epg.sclass = ntohs (gg->gg_sclass);
505 mp->epg.bd_id = ntohl (gbp_endpoint_group_get_bd_id (gg));
506 mp->epg.rd_id = ntohl (gbp_route_domain_get_rd_id (gg->gg_rd));
508 vl_api_send_msg (ctx->reg, (u8 *) mp);
514 vl_api_gbp_endpoint_group_dump_t_handler (vl_api_gbp_endpoint_group_dump_t *
517 vl_api_registration_t *reg;
519 reg = vl_api_client_index_to_registration (mp->client_index);
523 gbp_walk_ctx_t ctx = {
525 .context = mp->context,
528 gbp_endpoint_group_walk (gbp_endpoint_group_send_details, &ctx);
532 gbp_bridge_domain_send_details (gbp_bridge_domain_t * gb, void *args)
534 vl_api_gbp_bridge_domain_details_t *mp;
535 gbp_route_domain_t *gr;
539 mp = vl_msg_api_alloc (sizeof (*mp));
543 memset (mp, 0, sizeof (*mp));
544 mp->_vl_msg_id = ntohs (VL_API_GBP_BRIDGE_DOMAIN_DETAILS + GBP_MSG_BASE);
545 mp->context = ctx->context;
547 gr = gbp_route_domain_get (gb->gb_rdi);
549 mp->bd.bd_id = ntohl (gb->gb_bd_id);
550 mp->bd.rd_id = ntohl (gr->grd_id);
551 mp->bd.bvi_sw_if_index = ntohl (gb->gb_bvi_sw_if_index);
552 mp->bd.uu_fwd_sw_if_index = ntohl (gb->gb_uu_fwd_sw_if_index);
553 mp->bd.bm_flood_sw_if_index =
554 ntohl (gbp_itf_get_sw_if_index (gb->gb_bm_flood_itf));
556 vl_api_send_msg (ctx->reg, (u8 *) mp);
562 vl_api_gbp_bridge_domain_dump_t_handler (vl_api_gbp_bridge_domain_dump_t * mp)
564 vl_api_registration_t *reg;
566 reg = vl_api_client_index_to_registration (mp->client_index);
570 gbp_walk_ctx_t ctx = {
572 .context = mp->context,
575 gbp_bridge_domain_walk (gbp_bridge_domain_send_details, &ctx);
579 gbp_route_domain_send_details (gbp_route_domain_t * grd, void *args)
581 vl_api_gbp_route_domain_details_t *mp;
585 mp = vl_msg_api_alloc (sizeof (*mp));
589 memset (mp, 0, sizeof (*mp));
590 mp->_vl_msg_id = ntohs (VL_API_GBP_ROUTE_DOMAIN_DETAILS + GBP_MSG_BASE);
591 mp->context = ctx->context;
593 mp->rd.rd_id = ntohl (grd->grd_id);
594 mp->rd.ip4_uu_sw_if_index =
595 ntohl (grd->grd_uu_sw_if_index[FIB_PROTOCOL_IP4]);
596 mp->rd.ip6_uu_sw_if_index =
597 ntohl (grd->grd_uu_sw_if_index[FIB_PROTOCOL_IP6]);
599 vl_api_send_msg (ctx->reg, (u8 *) mp);
605 vl_api_gbp_route_domain_dump_t_handler (vl_api_gbp_route_domain_dump_t * mp)
607 vl_api_registration_t *reg;
609 reg = vl_api_client_index_to_registration (mp->client_index);
613 gbp_walk_ctx_t ctx = {
615 .context = mp->context,
618 gbp_route_domain_walk (gbp_route_domain_send_details, &ctx);
622 vl_api_gbp_recirc_add_del_t_handler (vl_api_gbp_recirc_add_del_t * mp)
624 vl_api_gbp_recirc_add_del_reply_t *rmp;
628 sw_if_index = ntohl (mp->recirc.sw_if_index);
629 if (!vnet_sw_if_index_is_api_valid (sw_if_index))
630 goto bad_sw_if_index;
633 rv = gbp_recirc_add (sw_if_index,
634 ntohs (mp->recirc.sclass), mp->recirc.is_ext);
636 rv = gbp_recirc_delete (sw_if_index);
638 BAD_SW_IF_INDEX_LABEL;
640 REPLY_MACRO (VL_API_GBP_RECIRC_ADD_DEL_REPLY + GBP_MSG_BASE);
644 gbp_recirc_send_details (gbp_recirc_t * gr, void *args)
646 vl_api_gbp_recirc_details_t *mp;
650 mp = vl_msg_api_alloc (sizeof (*mp));
654 clib_memset (mp, 0, sizeof (*mp));
655 mp->_vl_msg_id = ntohs (VL_API_GBP_RECIRC_DETAILS + GBP_MSG_BASE);
656 mp->context = ctx->context;
658 mp->recirc.sclass = ntohs (gr->gr_sclass);
659 mp->recirc.sw_if_index = ntohl (gr->gr_sw_if_index);
660 mp->recirc.is_ext = gr->gr_is_ext;
662 vl_api_send_msg (ctx->reg, (u8 *) mp);
664 return (WALK_CONTINUE);
668 vl_api_gbp_recirc_dump_t_handler (vl_api_gbp_recirc_dump_t * mp)
670 vl_api_registration_t *reg;
672 reg = vl_api_client_index_to_registration (mp->client_index);
676 gbp_walk_ctx_t ctx = {
678 .context = mp->context,
681 gbp_recirc_walk (gbp_recirc_send_details, &ctx);
685 vl_api_gbp_ext_itf_add_del_t_handler (vl_api_gbp_ext_itf_add_del_t * mp)
687 vl_api_gbp_ext_itf_add_del_reply_t *rmp;
688 u32 sw_if_index = ~0;
689 vl_api_gbp_ext_itf_t *ext_itf;
692 ext_itf = &mp->ext_itf;
694 sw_if_index = ntohl (ext_itf->sw_if_index);
696 if (!vnet_sw_if_index_is_api_valid (sw_if_index))
697 goto bad_sw_if_index;
700 rv = gbp_ext_itf_add (sw_if_index,
701 ntohl (ext_itf->bd_id), ntohl (ext_itf->rd_id),
702 ntohl (ext_itf->flags));
704 rv = gbp_ext_itf_delete (sw_if_index);
706 BAD_SW_IF_INDEX_LABEL;
708 REPLY_MACRO (VL_API_GBP_EXT_ITF_ADD_DEL_REPLY + GBP_MSG_BASE);
712 gbp_ext_itf_send_details (gbp_ext_itf_t * gx, void *args)
714 vl_api_gbp_ext_itf_details_t *mp;
718 mp = vl_msg_api_alloc (sizeof (*mp));
722 clib_memset (mp, 0, sizeof (*mp));
723 mp->_vl_msg_id = ntohs (VL_API_GBP_EXT_ITF_DETAILS + GBP_MSG_BASE);
724 mp->context = ctx->context;
726 mp->ext_itf.flags = ntohl (gx->gx_flags);
727 mp->ext_itf.bd_id = ntohl (gbp_bridge_domain_get_bd_id (gx->gx_bd));
728 mp->ext_itf.rd_id = ntohl (gbp_route_domain_get_rd_id (gx->gx_rd));
729 mp->ext_itf.sw_if_index = ntohl (gbp_itf_get_sw_if_index (gx->gx_itf));
731 vl_api_send_msg (ctx->reg, (u8 *) mp);
733 return (WALK_CONTINUE);
737 vl_api_gbp_ext_itf_dump_t_handler (vl_api_gbp_ext_itf_dump_t * mp)
739 vl_api_registration_t *reg;
741 reg = vl_api_client_index_to_registration (mp->client_index);
745 gbp_walk_ctx_t ctx = {
747 .context = mp->context,
750 gbp_ext_itf_walk (gbp_ext_itf_send_details, &ctx);
754 gbp_contract_rule_action_deocde (vl_api_gbp_rule_action_t in,
755 gbp_rule_action_t * out)
757 in = clib_net_to_host_u32 (in);
761 case GBP_API_RULE_PERMIT:
762 *out = GBP_RULE_PERMIT;
764 case GBP_API_RULE_DENY:
765 *out = GBP_RULE_DENY;
767 case GBP_API_RULE_REDIRECT:
768 *out = GBP_RULE_REDIRECT;
776 gbp_hash_mode_decode (vl_api_gbp_hash_mode_t in, gbp_hash_mode_t * out)
778 in = clib_net_to_host_u32 (in);
782 case GBP_API_HASH_MODE_SRC_IP:
783 *out = GBP_HASH_MODE_SRC_IP;
785 case GBP_API_HASH_MODE_DST_IP:
786 *out = GBP_HASH_MODE_DST_IP;
788 case GBP_API_HASH_MODE_SYMMETRIC:
789 *out = GBP_HASH_MODE_SYMMETRIC;
797 gbp_next_hop_decode (const vl_api_gbp_next_hop_t * in, index_t * gnhi)
803 gbd = gbp_bridge_domain_find_and_lock (ntohl (in->bd_id));
805 if (INDEX_INVALID == gbd)
806 return (VNET_API_ERROR_BD_NOT_MODIFIABLE);
808 grd = gbp_route_domain_find_and_lock (ntohl (in->rd_id));
810 if (INDEX_INVALID == grd)
811 return (VNET_API_ERROR_NO_SUCH_FIB);
813 ip_address_decode (&in->ip, &ip);
814 mac_address_decode (in->mac, &mac);
816 *gnhi = gbp_next_hop_alloc (&ip, grd, &mac, gbd);
822 gbp_next_hop_set_decode (const vl_api_gbp_next_hop_set_t * in,
823 gbp_hash_mode_t * hash_mode, index_t ** out)
826 index_t *gnhis = NULL;
830 rv = gbp_hash_mode_decode (in->hash_mode, hash_mode);
835 vec_validate (gnhis, in->n_nhs - 1);
837 for (ii = 0; ii < in->n_nhs; ii++)
839 rv = gbp_next_hop_decode (&in->nhs[ii], &gnhis[ii]);
853 gbp_contract_rule_decode (const vl_api_gbp_rule_t * in, index_t * gui)
855 gbp_hash_mode_t hash_mode;
856 gbp_rule_action_t action;
860 rv = gbp_contract_rule_action_deocde (in->action, &action);
865 if (GBP_RULE_REDIRECT == action)
867 rv = gbp_next_hop_set_decode (&in->nh_set, &hash_mode, &nhs);
874 hash_mode = GBP_HASH_MODE_SRC_IP;
877 *gui = gbp_rule_alloc (action, hash_mode, nhs);
883 gbp_contract_rules_decode (u8 n_rules,
884 const vl_api_gbp_rule_t * rules, index_t ** out)
886 index_t *guis = NULL;
896 vec_validate (guis, n_rules - 1);
898 for (ii = 0; ii < n_rules; ii++)
900 rv = gbp_contract_rule_decode (&rules[ii], &guis[ii]);
905 vec_foreach (gui, guis) gbp_rule_free (*gui);
916 vl_api_gbp_contract_add_del_t_handler (vl_api_gbp_contract_add_del_t * mp)
918 vl_api_gbp_contract_add_del_reply_t *rmp;
919 u16 *allowed_ethertypes;
920 u32 stats_index = ~0;
927 rv = gbp_contract_rules_decode (mp->contract.n_rules,
928 mp->contract.rules, &rules);
932 allowed_ethertypes = NULL;
935 * allowed ether types
937 n_et = mp->contract.n_ether_types;
938 vec_validate (allowed_ethertypes, n_et - 1);
940 for (ii = 0; ii < n_et; ii++)
942 /* leave the ether types in network order */
943 allowed_ethertypes[ii] = mp->contract.allowed_ethertypes[ii];
946 rv = gbp_contract_update (ntohs (mp->contract.scope),
947 ntohs (mp->contract.sclass),
948 ntohs (mp->contract.dclass),
949 ntohl (mp->contract.acl_index),
950 rules, allowed_ethertypes, &stats_index);
953 rv = gbp_contract_delete (ntohs (mp->contract.scope),
954 ntohs (mp->contract.sclass),
955 ntohs (mp->contract.dclass));
959 REPLY_MACRO2 (VL_API_GBP_CONTRACT_ADD_DEL_REPLY + GBP_MSG_BASE,
961 rmp->stats_index = htonl (stats_index);
967 gbp_contract_send_details (gbp_contract_t * gbpc, void *args)
969 vl_api_gbp_contract_details_t *mp;
973 mp = vl_msg_api_alloc (sizeof (*mp));
977 clib_memset (mp, 0, sizeof (*mp));
978 mp->_vl_msg_id = ntohs (VL_API_GBP_CONTRACT_DETAILS + GBP_MSG_BASE);
979 mp->context = ctx->context;
981 mp->contract.sclass = ntohs (gbpc->gc_key.gck_src);
982 mp->contract.dclass = ntohs (gbpc->gc_key.gck_dst);
983 mp->contract.acl_index = ntohl (gbpc->gc_acl_index);
984 mp->contract.scope = ntohs (gbpc->gc_key.gck_scope);
986 vl_api_send_msg (ctx->reg, (u8 *) mp);
992 vl_api_gbp_contract_dump_t_handler (vl_api_gbp_contract_dump_t * mp)
994 vl_api_registration_t *reg;
996 reg = vl_api_client_index_to_registration (mp->client_index);
1000 gbp_walk_ctx_t ctx = {
1002 .context = mp->context,
1005 gbp_contract_walk (gbp_contract_send_details, &ctx);
1009 gbp_vxlan_tunnel_mode_2_layer (vl_api_gbp_vxlan_tunnel_mode_t mode,
1010 gbp_vxlan_tunnel_layer_t * l)
1012 mode = clib_net_to_host_u32 (mode);
1016 case GBP_VXLAN_TUNNEL_MODE_L2:
1017 *l = GBP_VXLAN_TUN_L2;
1019 case GBP_VXLAN_TUNNEL_MODE_L3:
1020 *l = GBP_VXLAN_TUN_L3;
1027 vl_api_gbp_vxlan_tunnel_add_t_handler (vl_api_gbp_vxlan_tunnel_add_t * mp)
1029 vl_api_gbp_vxlan_tunnel_add_reply_t *rmp;
1030 gbp_vxlan_tunnel_layer_t layer;
1035 ip4_address_decode (mp->tunnel.src, &src);
1036 rv = gbp_vxlan_tunnel_mode_2_layer (mp->tunnel.mode, &layer);
1041 rv = gbp_vxlan_tunnel_add (ntohl (mp->tunnel.vni),
1043 ntohl (mp->tunnel.bd_rd_id), &src, &sw_if_index);
1047 REPLY_MACRO2 (VL_API_GBP_VXLAN_TUNNEL_ADD_REPLY + GBP_MSG_BASE,
1049 rmp->sw_if_index = htonl (sw_if_index);
1055 vl_api_gbp_vxlan_tunnel_del_t_handler (vl_api_gbp_vxlan_tunnel_add_t * mp)
1057 vl_api_gbp_vxlan_tunnel_del_reply_t *rmp;
1060 rv = gbp_vxlan_tunnel_del (ntohl (mp->tunnel.vni));
1062 REPLY_MACRO (VL_API_GBP_VXLAN_TUNNEL_DEL_REPLY + GBP_MSG_BASE);
1065 static vl_api_gbp_vxlan_tunnel_mode_t
1066 gbp_vxlan_tunnel_layer_2_mode (gbp_vxlan_tunnel_layer_t layer)
1068 vl_api_gbp_vxlan_tunnel_mode_t mode = GBP_VXLAN_TUNNEL_MODE_L2;
1072 case GBP_VXLAN_TUN_L2:
1073 mode = GBP_VXLAN_TUNNEL_MODE_L2;
1075 case GBP_VXLAN_TUN_L3:
1076 mode = GBP_VXLAN_TUNNEL_MODE_L3;
1079 mode = clib_host_to_net_u32 (mode);
1085 gbp_vxlan_tunnel_send_details (gbp_vxlan_tunnel_t * gt, void *args)
1087 vl_api_gbp_vxlan_tunnel_details_t *mp;
1088 gbp_walk_ctx_t *ctx;
1091 mp = vl_msg_api_alloc (sizeof (*mp));
1095 memset (mp, 0, sizeof (*mp));
1096 mp->_vl_msg_id = htons (VL_API_GBP_VXLAN_TUNNEL_DETAILS + GBP_MSG_BASE);
1097 mp->context = ctx->context;
1099 mp->tunnel.vni = htonl (gt->gt_vni);
1100 mp->tunnel.mode = gbp_vxlan_tunnel_layer_2_mode (gt->gt_layer);
1101 mp->tunnel.bd_rd_id = htonl (gt->gt_bd_rd_id);
1103 vl_api_send_msg (ctx->reg, (u8 *) mp);
1109 vl_api_gbp_vxlan_tunnel_dump_t_handler (vl_api_gbp_vxlan_tunnel_dump_t * mp)
1111 vl_api_registration_t *reg;
1113 reg = vl_api_client_index_to_registration (mp->client_index);
1117 gbp_walk_ctx_t ctx = {
1119 .context = mp->context,
1122 gbp_vxlan_walk (gbp_vxlan_tunnel_send_details, &ctx);
1125 #include <gbp/gbp.api.c>
1126 static clib_error_t *
1127 gbp_init (vlib_main_t * vm)
1129 gbp_main_t *gbpm = &gbp_main;
1131 gbpm->gbp_acl_user_id = ~0;
1133 /* Ask for a correctly-sized block of API message decode slots */
1134 msg_id_base = setup_message_id_table ();
1139 VLIB_API_INIT_FUNCTION (gbp_init);
1142 VLIB_PLUGIN_REGISTER () = {
1143 .version = VPP_BUILD_VER,
1144 .description = "Group Based Policy (GBP)",
1150 * fd.io coding-style-patch-verification: ON
1153 * eval: (c-set-style "gnu")