X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fplugins%2Fmap%2Fmap_api.c;h=7327732c6a7457d1e58d46b7dcc2d7c3cd6a9e94;hb=59f71132e;hp=ac1665e53840f967c0bac4f274d47de7ca8cec15;hpb=f34597fc86c64d054073bf614761beea020c2244;p=vpp.git diff --git a/src/plugins/map/map_api.c b/src/plugins/map/map_api.c index ac1665e5384..7327732c6a7 100644 --- a/src/plugins/map/map_api.c +++ b/src/plugins/map/map_api.c @@ -17,31 +17,17 @@ *------------------------------------------------------------------ */ +#include #include -#include +#include +#include #include +#include +#include +#include #include #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 - #define REPLY_MSG_ID_BASE mm->msg_id_base #include @@ -54,20 +40,16 @@ vl_api_map_add_domain_t_handler (vl_api_map_add_domain_t * mp) u32 index; u8 flags = 0; - if (mp->is_translation) - flags |= MAP_DOMAIN_TRANSLATION; - - if (mp->is_rfc6052) - flags |= MAP_DOMAIN_RFC6052; - + mp->tag[ARRAY_LEN (mp->tag) - 1] = '\0'; rv = - map_create_domain ((ip4_address_t *) & mp->ip4_prefix.prefix, + map_create_domain ((ip4_address_t *) & mp->ip4_prefix.address, mp->ip4_prefix.len, - (ip6_address_t *) & mp->ip6_prefix.prefix, + (ip6_address_t *) & mp->ip6_prefix.address, mp->ip6_prefix.len, - (ip6_address_t *) & mp->ip6_src.prefix, + (ip6_address_t *) & mp->ip6_src.address, mp->ip6_src.len, mp->ea_bits_len, mp->psid_offset, - mp->psid_length, &index, ntohs (mp->mtu), flags); + mp->psid_length, &index, ntohs (mp->mtu), flags, + mp->tag); /* *INDENT-OFF* */ REPLY_MACRO2(VL_API_MAP_ADD_DOMAIN_REPLY, @@ -109,7 +91,9 @@ vl_api_map_domain_dump_t_handler (vl_api_map_domain_dump_t * mp) vl_api_map_domain_details_t *rmp; map_main_t *mm = &map_main; map_domain_t *d; + map_domain_extra_t *de; vl_api_registration_t *reg; + u32 map_domain_index; if (pool_elts (mm->domains) == 0) return; @@ -121,14 +105,19 @@ vl_api_map_domain_dump_t_handler (vl_api_map_domain_dump_t * mp) /* *INDENT-OFF* */ pool_foreach(d, mm->domains, ({ + map_domain_index = d - mm->domains; + de = vec_elt_at_index(mm->domain_extras, map_domain_index); + int tag_len = clib_min(ARRAY_LEN(rmp->tag), vec_len(de->tag) + 1); + /* Make sure every field is initiated (or don't skip the clib_memset()) */ - rmp = vl_msg_api_alloc (sizeof (*rmp)); + rmp = vl_msg_api_alloc (sizeof (*rmp) + tag_len); + rmp->_vl_msg_id = htons(VL_API_MAP_DOMAIN_DETAILS + mm->msg_id_base); rmp->context = mp->context; - rmp->domain_index = htonl(d - mm->domains); - clib_memcpy(&rmp->ip6_prefix.prefix, &d->ip6_prefix, sizeof(rmp->ip6_prefix.prefix)); - clib_memcpy(&rmp->ip4_prefix.prefix, &d->ip4_prefix, sizeof(rmp->ip4_prefix.prefix)); - clib_memcpy(&rmp->ip6_src.prefix, &d->ip6_src, sizeof(rmp->ip6_src.prefix)); + rmp->domain_index = htonl(map_domain_index); + clib_memcpy(&rmp->ip6_prefix.address, &d->ip6_prefix, sizeof(rmp->ip6_prefix.address)); + clib_memcpy(&rmp->ip4_prefix.address, &d->ip4_prefix, sizeof(rmp->ip4_prefix.address)); + clib_memcpy(&rmp->ip6_src.address, &d->ip6_src, sizeof(rmp->ip6_src.address)); rmp->ip6_prefix.len = d->ip6_prefix_len; rmp->ip4_prefix.len = d->ip4_prefix_len; rmp->ip6_src.len = d->ip6_src_len; @@ -137,7 +126,8 @@ vl_api_map_domain_dump_t_handler (vl_api_map_domain_dump_t * mp) rmp->psid_length = d->psid_length; rmp->flags = d->flags; rmp->mtu = htons(d->mtu); - rmp->is_translation = (d->flags & MAP_DOMAIN_TRANSLATION); // Redundant + memcpy(rmp->tag, de->tag, tag_len-1); + rmp->tag[tag_len-1] = '\0'; vl_api_send_msg (reg, (u8 *) rmp); })); @@ -342,140 +332,6 @@ static void REPLY_MACRO (VL_API_MAP_PARAM_ADD_DEL_PRE_RESOLVE_REPLY); } - -int -map_param_set_reassembly (bool is_ipv6, - u16 lifetime_ms, - u16 pool_size, - u32 buffers, - f64 ht_ratio, u32 * reass, u32 * packets) -{ - u32 ps_reass = 0, ps_packets = 0; - u32 ht_reass = 0, ht_packets = 0; - - if (is_ipv6) - { - if (pool_size != (u16) ~ 0) - { - if (pool_size > MAP_IP6_REASS_CONF_POOL_SIZE_MAX) - return MAP_ERR_BAD_POOL_SIZE; - if (map_ip6_reass_conf_pool_size - (pool_size, &ps_reass, &ps_packets)) - return MAP_ERR_BAD_POOL_SIZE; - } - - if (ht_ratio != (MAP_IP6_REASS_CONF_HT_RATIO_MAX + 1)) - { - if (ht_ratio > MAP_IP6_REASS_CONF_HT_RATIO_MAX) - return MAP_ERR_BAD_HT_RATIO; - if (map_ip6_reass_conf_ht_ratio (ht_ratio, &ht_reass, &ht_packets)) - return MAP_ERR_BAD_HT_RATIO; - } - - if (lifetime_ms != (u16) ~ 0) - { - if (lifetime_ms > MAP_IP6_REASS_CONF_LIFETIME_MAX) - return MAP_ERR_BAD_LIFETIME; - if (map_ip6_reass_conf_lifetime (lifetime_ms)) - return MAP_ERR_BAD_LIFETIME; - } - - if (buffers != ~0) - { - if (buffers > MAP_IP6_REASS_CONF_BUFFERS_MAX) - return MAP_ERR_BAD_BUFFERS; - if (map_ip6_reass_conf_buffers (buffers)) - return MAP_ERR_BAD_BUFFERS; - } - - if (map_main.ip6_reass_conf_buffers > - map_main.ip6_reass_conf_pool_size * - MAP_IP6_REASS_MAX_FRAGMENTS_PER_REASSEMBLY) - { - return MAP_ERR_BAD_BUFFERS_TOO_LARGE; - } - } - else - { - if (pool_size != (u16) ~ 0) - { - if (pool_size > MAP_IP4_REASS_CONF_POOL_SIZE_MAX) - return MAP_ERR_BAD_POOL_SIZE; - if (map_ip4_reass_conf_pool_size - (pool_size, &ps_reass, &ps_packets)) - return MAP_ERR_BAD_POOL_SIZE; - } - - if (ht_ratio != (MAP_IP4_REASS_CONF_HT_RATIO_MAX + 1)) - { - if (ht_ratio > MAP_IP4_REASS_CONF_HT_RATIO_MAX) - return MAP_ERR_BAD_HT_RATIO; - if (map_ip4_reass_conf_ht_ratio (ht_ratio, &ht_reass, &ht_packets)) - return MAP_ERR_BAD_HT_RATIO; - } - - if (lifetime_ms != (u16) ~ 0) - { - if (lifetime_ms > MAP_IP4_REASS_CONF_LIFETIME_MAX) - return MAP_ERR_BAD_LIFETIME; - if (map_ip4_reass_conf_lifetime (lifetime_ms)) - return MAP_ERR_BAD_LIFETIME; - } - - if (buffers != ~0) - { - if (buffers > MAP_IP4_REASS_CONF_BUFFERS_MAX) - return MAP_ERR_BAD_BUFFERS; - if (map_ip4_reass_conf_buffers (buffers)) - return MAP_ERR_BAD_BUFFERS; - } - - if (map_main.ip4_reass_conf_buffers > - map_main.ip4_reass_conf_pool_size * - MAP_IP4_REASS_MAX_FRAGMENTS_PER_REASSEMBLY) - { - return MAP_ERR_BAD_BUFFERS_TOO_LARGE; - } - } - - if (reass) - *reass = ps_reass + ht_reass; - - if (packets) - *packets = ps_packets + ht_packets; - - return 0; -} - - -static void - vl_api_map_param_set_reassembly_t_handler - (vl_api_map_param_set_reassembly_t * mp) -{ - map_main_t *mm = &map_main; - vl_api_map_param_set_reassembly_reply_t *rmp; - u32 reass = 0, packets = 0; - int rv; - f64 ht_ratio; - - ht_ratio = (f64) clib_net_to_host_u64 (mp->ht_ratio); - if (ht_ratio == ~0) - ht_ratio = MAP_IP6_REASS_CONF_HT_RATIO_MAX + 1; - - rv = map_param_set_reassembly (mp->is_ip6, - clib_net_to_host_u16 (mp->lifetime_ms), - clib_net_to_host_u16 (mp->pool_size), - clib_net_to_host_u32 (mp->buffers), - ht_ratio, &reass, &packets); - - /* - * FIXME: Should the lost reass and packet counts be returned in the API? - */ - - REPLY_MACRO (VL_API_MAP_PARAM_SET_REASSEMBLY_REPLY); -} - - int map_param_set_security_check (bool enable, bool fragments) { @@ -520,7 +376,7 @@ static void vl_api_map_param_set_traffic_class_reply_t *rmp; int rv; - rv = map_param_set_traffic_class (mp->copy, mp->class); + rv = map_param_set_traffic_class (mp->copy, mp->tc_class); REPLY_MACRO (VL_API_MAP_PARAM_SET_TRAFFIC_CLASS_REPLY); } @@ -580,20 +436,6 @@ vl_api_map_param_get_t_handler (vl_api_map_param_get_t * mp) clib_memset (&rmp->ip4_nh_address, 0, sizeof (rmp->ip4_nh_address)); clib_memset (&rmp->ip6_nh_address, 0, sizeof (rmp->ip6_nh_address)); - rmp->ip4_lifetime_ms = - clib_net_to_host_u16 (mm->ip4_reass_conf_lifetime_ms); - rmp->ip4_pool_size = clib_net_to_host_u16 (mm->ip4_reass_conf_pool_size); - rmp->ip4_buffers = clib_net_to_host_u32 (mm->ip4_reass_conf_buffers); - rmp->ip4_ht_ratio = - clib_net_to_host_u64 ((u64) mm->ip4_reass_conf_ht_ratio); - - rmp->ip6_lifetime_ms = - clib_net_to_host_u16 (mm->ip6_reass_conf_lifetime_ms); - rmp->ip6_pool_size = clib_net_to_host_u16 (mm->ip6_reass_conf_pool_size); - rmp->ip6_buffers = clib_net_to_host_u32 (mm->ip6_reass_conf_buffers); - rmp->ip6_ht_ratio = - clib_net_to_host_u64 ((u64) mm->ip6_reass_conf_ht_ratio); - rmp->sec_check_enable = mm->sec_check; rmp->sec_check_fragments = mm->sec_check_frag; @@ -607,20 +449,52 @@ vl_api_map_param_get_t_handler (vl_api_map_param_get_t * mp) int map_if_enable_disable (bool is_enable, u32 sw_if_index, bool is_translation) { + map_main_t *mm = &map_main; + + if (pool_is_free_index (mm->vnet_main->interface_main.sw_interfaces, + sw_if_index)) + return VNET_API_ERROR_INVALID_SW_IF_INDEX; + + is_enable = ! !is_enable; + + if (is_translation) + { + if (clib_bitmap_get (mm->bm_trans_enabled_by_sw_if, sw_if_index) + == is_enable) + return 0; + } + else + { + if (clib_bitmap_get (mm->bm_encap_enabled_by_sw_if, sw_if_index) + == is_enable) + return 0; + } + if (is_translation == false) { + ip4_sv_reass_enable_disable_with_refcnt (sw_if_index, is_enable); + ip6_full_reass_enable_disable_with_refcnt (sw_if_index, is_enable); vnet_feature_enable_disable ("ip4-unicast", "ip4-map", sw_if_index, is_enable ? 1 : 0, 0, 0); vnet_feature_enable_disable ("ip6-unicast", "ip6-map", sw_if_index, is_enable ? 1 : 0, 0, 0); + mm->bm_encap_enabled_by_sw_if = + clib_bitmap_set (mm->bm_encap_enabled_by_sw_if, sw_if_index, + is_enable); } else { + ip4_sv_reass_enable_disable_with_refcnt (sw_if_index, is_enable); + ip6_sv_reass_enable_disable_with_refcnt (sw_if_index, is_enable); vnet_feature_enable_disable ("ip4-unicast", "ip4-map-t", sw_if_index, is_enable ? 1 : 0, 0, 0); vnet_feature_enable_disable ("ip6-unicast", "ip6-map-t", sw_if_index, is_enable ? 1 : 0, 0, 0); + mm->bm_trans_enabled_by_sw_if = + clib_bitmap_set (mm->bm_trans_enabled_by_sw_if, sw_if_index, + is_enable); } + return 0; } @@ -642,65 +516,17 @@ vl_api_map_if_enable_disable_t_handler (vl_api_map_if_enable_disable_t * mp) REPLY_MACRO (VL_API_MAP_IF_ENABLE_DISABLE_REPLY); } - -#define foreach_map_plugin_api_msg \ -_(MAP_ADD_DOMAIN, map_add_domain) \ -_(MAP_DEL_DOMAIN, map_del_domain) \ -_(MAP_ADD_DEL_RULE, map_add_del_rule) \ -_(MAP_DOMAIN_DUMP, map_domain_dump) \ -_(MAP_RULE_DUMP, map_rule_dump) \ -_(MAP_IF_ENABLE_DISABLE, map_if_enable_disable) \ -_(MAP_SUMMARY_STATS, map_summary_stats) \ -_(MAP_PARAM_SET_FRAGMENTATION, map_param_set_fragmentation) \ -_(MAP_PARAM_SET_ICMP, map_param_set_icmp) \ -_(MAP_PARAM_SET_ICMP6, map_param_set_icmp6) \ -_(MAP_PARAM_ADD_DEL_PRE_RESOLVE, map_param_add_del_pre_resolve) \ -_(MAP_PARAM_SET_REASSEMBLY, map_param_set_reassembly) \ -_(MAP_PARAM_SET_SECURITY_CHECK, map_param_set_security_check) \ -_(MAP_PARAM_SET_TRAFFIC_CLASS, map_param_set_traffic_class) \ -_(MAP_PARAM_SET_TCP, map_param_set_tcp) \ -_(MAP_PARAM_GET, map_param_get) - -#define vl_msg_name_crc_list -#include -#undef vl_msg_name_crc_list - -static void -setup_message_id_table (map_main_t * mm, api_main_t * am) -{ -#define _(id,n,crc) \ - vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + mm->msg_id_base); - foreach_vl_msg_name_crc_map; -#undef _ -} +/* API definitions */ +#include +#include /* Set up the API message handling tables */ clib_error_t * map_plugin_api_hookup (vlib_main_t * vm) { map_main_t *mm = &map_main; - u8 *name = format (0, "map_%08x%c", api_version, 0); - - /* Ask for a correctly-sized block of API message decode slots */ - mm->msg_id_base = - vl_msg_api_get_msg_ids ((char *) name, VL_MSG_FIRST_AVAILABLE); -#define _(N,n) \ - vl_msg_api_set_handlers((VL_API_##N + mm->msg_id_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_map_plugin_api_msg; -#undef _ - - /* - * Set up the (msg_name, crc, message-id) table - */ - setup_message_id_table (mm, &api_main); - vec_free (name); + mm->msg_id_base = setup_message_id_table (); return 0; }