X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fplugins%2Fgbp%2Fgbp_api.c;h=aea03d8022684e45071d5c836b0218f6ac411b62;hb=59f71132e;hp=8878119d7662a75684ab869e70282232afc93b1a;hpb=fa0ac2c5668cb8f387a8e16dcf8d2d7154a09fe2;p=vpp.git diff --git a/src/plugins/gbp/gbp_api.c b/src/plugins/gbp/gbp_api.c index 8878119d766..aea03d80226 100644 --- a/src/plugins/gbp/gbp_api.c +++ b/src/plugins/gbp/gbp_api.c @@ -31,58 +31,18 @@ #include #include #include +#include #include #include /* define message IDs */ -#include - -#define vl_typedefs /* define message structures */ -#include -#undef vl_typedefs - -#define vl_endianfun /* define message structures */ -#include -#undef vl_endianfun - -/* instantiate all the print functions we know about */ -#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__) -#define vl_printfun -#include -#undef vl_printfun - -/* Get the API version number */ -#define vl_api_version(n,v) static u32 api_version=(v); -#include -#undef vl_api_version - +#include +#include +#include #include - -#define foreach_gbp_api_msg \ - _(GBP_ENDPOINT_ADD, gbp_endpoint_add) \ - _(GBP_ENDPOINT_DEL, gbp_endpoint_del) \ - _(GBP_ENDPOINT_DUMP, gbp_endpoint_dump) \ - _(GBP_SUBNET_ADD_DEL, gbp_subnet_add_del) \ - _(GBP_SUBNET_DUMP, gbp_subnet_dump) \ - _(GBP_ENDPOINT_GROUP_ADD, gbp_endpoint_group_add) \ - _(GBP_ENDPOINT_GROUP_DEL, gbp_endpoint_group_del) \ - _(GBP_ENDPOINT_GROUP_DUMP, gbp_endpoint_group_dump) \ - _(GBP_BRIDGE_DOMAIN_ADD, gbp_bridge_domain_add) \ - _(GBP_BRIDGE_DOMAIN_DEL, gbp_bridge_domain_del) \ - _(GBP_BRIDGE_DOMAIN_DUMP, gbp_bridge_domain_dump) \ - _(GBP_ROUTE_DOMAIN_ADD, gbp_route_domain_add) \ - _(GBP_ROUTE_DOMAIN_DEL, gbp_route_domain_del) \ - _(GBP_ROUTE_DOMAIN_DUMP, gbp_route_domain_dump) \ - _(GBP_RECIRC_ADD_DEL, gbp_recirc_add_del) \ - _(GBP_RECIRC_DUMP, gbp_recirc_dump) \ - _(GBP_EXT_ITF_ADD_DEL, gbp_ext_itf_add_del) \ - _(GBP_EXT_ITF_DUMP, gbp_ext_itf_dump) \ - _(GBP_CONTRACT_ADD_DEL, gbp_contract_add_del) \ - _(GBP_CONTRACT_DUMP, gbp_contract_dump) \ - _(GBP_VXLAN_TUNNEL_ADD, gbp_vxlan_tunnel_add) \ - _(GBP_VXLAN_TUNNEL_DEL, gbp_vxlan_tunnel_del) \ - _(GBP_VXLAN_TUNNEL_DUMP, gbp_vxlan_tunnel_dump) +#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__) +#include "gbp_api_print.h" gbp_main_t gbp_main; @@ -139,6 +99,8 @@ vl_api_gbp_endpoint_add_t_handler (vl_api_gbp_endpoint_add_t * mp) mac_address_t mac; int rv = 0, ii; + handle = INDEX_INVALID; + VALIDATE_SW_IF_INDEX (&(mp->endpoint)); gef = gbp_endpoint_flags_decode (mp->endpoint.flags), ips = NULL; @@ -239,13 +201,16 @@ gbp_endpoint_send_details (index_t gei, void *args) } else { - mp->endpoint.sw_if_index = ntohl (gef->gef_itf); + mp->endpoint.sw_if_index = + ntohl (gbp_itf_get_sw_if_index (gef->gef_itf)); } mp->endpoint.sclass = ntohs (ge->ge_fwd.gef_sclass); mp->endpoint.n_ips = n_ips; mp->endpoint.flags = gbp_endpoint_flags_encode (gef->gef_flags); mp->handle = htonl (gei); - mp->age = vlib_time_now (vlib_get_main ()) - ge->ge_last_time; + mp->age = + clib_host_to_net_f64 (vlib_time_now (vlib_get_main ()) - + ge->ge_last_time); mac_address_encode (&ge->ge_key.gek_mac, mp->endpoint.mac); vec_foreach_index (ii, ge->ge_key.gek_ips) @@ -325,6 +290,12 @@ gbp_bridge_domain_flags_from_api (vl_api_gbp_bridge_domain_flags_t a) if (a & GBP_BD_API_FLAG_DO_NOT_LEARN) g |= GBP_BD_FLAG_DO_NOT_LEARN; + if (a & GBP_BD_API_FLAG_UU_FWD_DROP) + g |= GBP_BD_FLAG_UU_FWD_DROP; + if (a & GBP_BD_API_FLAG_MCAST_DROP) + g |= GBP_BD_FLAG_MCAST_DROP; + if (a & GBP_BD_API_FLAG_UCAST_ARP) + g |= GBP_BD_FLAG_UCAST_ARP; return (g); } @@ -336,6 +307,7 @@ vl_api_gbp_bridge_domain_add_t_handler (vl_api_gbp_bridge_domain_add_t * mp) int rv = 0; rv = gbp_bridge_domain_add_and_lock (ntohl (mp->bd.bd_id), + ntohl (mp->bd.rd_id), gbp_bridge_domain_flags_from_api (mp->bd.flags), ntohl (mp->bd.bvi_sw_if_index), @@ -363,6 +335,7 @@ vl_api_gbp_route_domain_add_t_handler (vl_api_gbp_route_domain_add_t * mp) int rv = 0; rv = gbp_route_domain_add_and_lock (ntohl (mp->rd.rd_id), + ntohs (mp->rd.scope), ntohl (mp->rd.ip4_table_id), ntohl (mp->rd.ip6_table_id), ntohl (mp->rd.ip4_uu_sw_if_index), @@ -395,6 +368,9 @@ gub_subnet_type_from_api (vl_api_gbp_subnet_type_t a, gbp_subnet_type_t * t) case GBP_API_SUBNET_L3_OUT: *t = GBP_SUBNET_L3_OUT; return (0); + case GBP_API_SUBNET_ANON_L3_OUT: + *t = GBP_SUBNET_ANON_L3_OUT; + return (0); case GBP_API_SUBNET_STITCHED_INTERNAL: *t = GBP_SUBNET_STITCHED_INTERNAL; return (0); @@ -452,6 +428,9 @@ gub_subnet_type_to_api (gbp_subnet_type_t t) case GBP_SUBNET_L3_OUT: a = GBP_API_SUBNET_L3_OUT; break; + case GBP_SUBNET_ANON_L3_OUT: + a = GBP_API_SUBNET_ANON_L3_OUT; + break; } a = clib_host_to_net_u32 (a); @@ -553,6 +532,7 @@ static int gbp_bridge_domain_send_details (gbp_bridge_domain_t * gb, void *args) { vl_api_gbp_bridge_domain_details_t *mp; + gbp_route_domain_t *gr; gbp_walk_ctx_t *ctx; ctx = args; @@ -564,10 +544,14 @@ gbp_bridge_domain_send_details (gbp_bridge_domain_t * gb, void *args) mp->_vl_msg_id = ntohs (VL_API_GBP_BRIDGE_DOMAIN_DETAILS + GBP_MSG_BASE); mp->context = ctx->context; + gr = gbp_route_domain_get (gb->gb_rdi); + mp->bd.bd_id = ntohl (gb->gb_bd_id); + mp->bd.rd_id = ntohl (gr->grd_id); mp->bd.bvi_sw_if_index = ntohl (gb->gb_bvi_sw_if_index); mp->bd.uu_fwd_sw_if_index = ntohl (gb->gb_uu_fwd_sw_if_index); - mp->bd.bm_flood_sw_if_index = ntohl (gb->gb_bm_flood_sw_if_index); + mp->bd.bm_flood_sw_if_index = + ntohl (gbp_itf_get_sw_if_index (gb->gb_bm_flood_itf)); vl_api_send_msg (ctx->reg, (u8 *) mp); @@ -714,7 +698,8 @@ vl_api_gbp_ext_itf_add_del_t_handler (vl_api_gbp_ext_itf_add_del_t * mp) if (mp->is_add) rv = gbp_ext_itf_add (sw_if_index, - ntohl (ext_itf->bd_id), ntohl (ext_itf->rd_id)); + ntohl (ext_itf->bd_id), ntohl (ext_itf->rd_id), + ntohl (ext_itf->flags)); else rv = gbp_ext_itf_delete (sw_if_index); @@ -738,9 +723,10 @@ gbp_ext_itf_send_details (gbp_ext_itf_t * gx, void *args) mp->_vl_msg_id = ntohs (VL_API_GBP_EXT_ITF_DETAILS + GBP_MSG_BASE); mp->context = ctx->context; + mp->ext_itf.flags = ntohl (gx->gx_flags); mp->ext_itf.bd_id = ntohl (gbp_bridge_domain_get_bd_id (gx->gx_bd)); mp->ext_itf.rd_id = ntohl (gbp_route_domain_get_rd_id (gx->gx_rd)); - mp->ext_itf.sw_if_index = ntohl (gx->gx_itf); + mp->ext_itf.sw_if_index = ntohl (gbp_itf_get_sw_if_index (gx->gx_itf)); vl_api_send_msg (ctx->reg, (u8 *) mp); @@ -915,6 +901,8 @@ gbp_contract_rules_decode (u8 n_rules, if (0 != rv) { + index_t *gui; + vec_foreach (gui, guis) gbp_rule_free (*gui); vec_free (guis); return (rv); } @@ -929,6 +917,7 @@ vl_api_gbp_contract_add_del_t_handler (vl_api_gbp_contract_add_del_t * mp) { vl_api_gbp_contract_add_del_reply_t *rmp; u16 *allowed_ethertypes; + u32 stats_index = ~0; index_t *rules; int ii, rv = 0; u8 n_et; @@ -954,17 +943,24 @@ vl_api_gbp_contract_add_del_t_handler (vl_api_gbp_contract_add_del_t * mp) allowed_ethertypes[ii] = mp->contract.allowed_ethertypes[ii]; } - rv = gbp_contract_update (ntohs (mp->contract.sclass), + rv = gbp_contract_update (ntohs (mp->contract.scope), + ntohs (mp->contract.sclass), ntohs (mp->contract.dclass), ntohl (mp->contract.acl_index), - rules, allowed_ethertypes); + rules, allowed_ethertypes, &stats_index); } else - rv = gbp_contract_delete (ntohs (mp->contract.sclass), + rv = gbp_contract_delete (ntohs (mp->contract.scope), + ntohs (mp->contract.sclass), ntohs (mp->contract.dclass)); out: - REPLY_MACRO (VL_API_GBP_CONTRACT_ADD_DEL_REPLY + GBP_MSG_BASE); + /* *INDENT-OFF* */ + REPLY_MACRO2 (VL_API_GBP_CONTRACT_ADD_DEL_REPLY + GBP_MSG_BASE, + ({ + rmp->stats_index = htonl (stats_index); + })); + /* *INDENT-ON* */ } static int @@ -985,6 +981,7 @@ gbp_contract_send_details (gbp_contract_t * gbpc, void *args) mp->contract.sclass = ntohs (gbpc->gc_key.gck_src); mp->contract.dclass = ntohs (gbpc->gc_key.gck_dst); mp->contract.acl_index = ntohl (gbpc->gc_acl_index); + mp->contract.scope = ntohs (gbpc->gc_key.gck_scope); vl_api_send_msg (ctx->reg, (u8 *) mp); @@ -1125,59 +1122,17 @@ vl_api_gbp_vxlan_tunnel_dump_t_handler (vl_api_gbp_vxlan_tunnel_dump_t * mp) gbp_vxlan_walk (gbp_vxlan_tunnel_send_details, &ctx); } -/* - * gbp_api_hookup - * Add vpe's API message handlers to the table. - * vlib has already mapped shared memory and - * added the client registration handlers. - * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process() - */ -#define vl_msg_name_crc_list -#include -#undef vl_msg_name_crc_list - -static void -setup_message_id_table (api_main_t * am) -{ -#define _(id,n,crc) \ - vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + GBP_MSG_BASE); - foreach_vl_msg_name_crc_gbp; -#undef _ -} - -static void -gbp_api_hookup (vlib_main_t * vm) -{ -#define _(N,n) \ - vl_msg_api_set_handlers(VL_API_##N + GBP_MSG_BASE, \ - #n, \ - vl_api_##n##_t_handler, \ - vl_noop_handler, \ - vl_api_##n##_t_endian, \ - vl_api_##n##_t_print, \ - sizeof(vl_api_##n##_t), 1); - foreach_gbp_api_msg; -#undef _ -} - +#include static clib_error_t * gbp_init (vlib_main_t * vm) { - api_main_t *am = &api_main; gbp_main_t *gbpm = &gbp_main; - u8 *name = format (0, "gbp_%08x%c", api_version, 0); gbpm->gbp_acl_user_id = ~0; /* Ask for a correctly-sized block of API message decode slots */ - msg_id_base = vl_msg_api_get_msg_ids ((char *) name, - VL_MSG_FIRST_AVAILABLE); - gbp_api_hookup (vm); - - /* Add our API messages to the global name_crc hash table */ - setup_message_id_table (am); + msg_id_base = setup_message_id_table (); - vec_free (name); return (NULL); } @@ -1186,7 +1141,7 @@ VLIB_API_INIT_FUNCTION (gbp_init); /* *INDENT-OFF* */ VLIB_PLUGIN_REGISTER () = { .version = VPP_BUILD_VER, - .description = "Group Based Policy", + .description = "Group Based Policy (GBP)", }; /* *INDENT-ON* */