X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvnet%2Fmpls%2Fmpls_api.c;h=a55daa2b0c474a3c0cf59439f8c873b9deef05eb;hb=810086d8fd08445919ae03bf36161037e53a712a;hp=2af6af8fd4863e5b1c038f4f66dc4e8aa150c561;hpb=28ab9cc13bb0b6adf68277f12cfcd33b69f40b00;p=vpp.git diff --git a/src/vnet/mpls/mpls_api.c b/src/vnet/mpls/mpls_api.c index 2af6af8fd48..a55daa2b0c4 100644 --- a/src/vnet/mpls/mpls_api.c +++ b/src/vnet/mpls/mpls_api.c @@ -58,6 +58,29 @@ _(MPLS_FIB_DUMP, mpls_fib_dump) extern void stats_dslock_with_hint (int hint, int tag); extern void stats_dsunlock (void); +void +mpls_table_delete (u32 table_id, u8 is_api) +{ + u32 fib_index; + + /* + * The MPLS defult table must also be explicitly created via the API. + * So in contrast to IP, it gets no special treatment here. + * + * The API holds only one lock on the table. + * i.e. it can be added many times via the API but needs to be + * deleted only once. + */ + fib_index = fib_table_find (FIB_PROTOCOL_MPLS, table_id); + + if (~0 != fib_index) + { + fib_table_unlock (fib_index, + FIB_PROTOCOL_MPLS, + (is_api ? FIB_SOURCE_API : FIB_SOURCE_CLI)); + } +} + void vl_api_mpls_table_add_del_t_handler (vl_api_mpls_table_add_del_t * mp) { @@ -68,8 +91,12 @@ vl_api_mpls_table_add_del_t_handler (vl_api_mpls_table_add_del_t * mp) vnm = vnet_get_main (); vnm->api_errno = 0; + if (mp->mt_is_add) + mpls_table_create (ntohl (mp->mt_table_id), 1, mp->mt_name); + else + mpls_table_delete (ntohl (mp->mt_table_id), 1); - rv = (rv == 0) ? vnm->api_errno : rv; + // NB: Nothing sets rv; none of the above returns an error REPLY_MACRO (VL_API_MPLS_TABLE_ADD_DEL_REPLY); } @@ -85,14 +112,7 @@ mpls_ip_bind_unbind_handler (vnet_main_t * vnm, if (~0 == mpls_fib_index) { - if (mp->mb_create_table_if_needed) - { - mpls_fib_index = - fib_table_find_or_create_and_lock (FIB_PROTOCOL_MPLS, - ntohl (mp->mb_mpls_table_id)); - } - else - return VNET_API_ERROR_NO_SUCH_FIB; + return VNET_API_ERROR_NO_SUCH_FIB; } ip_fib_index = fib_table_find ((mp->mb_is_ip4 ? @@ -173,7 +193,6 @@ mpls_route_add_del_t_handler (vnet_main_t * vnm, mp->mr_next_hop_sw_if_index, pfx.fp_payload_proto, mp->mr_next_hop_table_id, - mp->mr_create_table_if_needed, mp->mr_is_rpf_id, &fib_index, &next_hop_fib_index); @@ -200,25 +219,32 @@ mpls_route_add_del_t_handler (vnet_main_t * vnm, label_stack[ii] = ntohl (mp->mr_next_hop_out_label_stack[ii]); } - return (add_del_route_t_handler (mp->mr_is_multipath, mp->mr_is_add, 0, // mp->is_drop, + /* *INDENT-OFF* */ + return (add_del_route_t_handler (mp->mr_is_multipath, mp->mr_is_add, + 0, // mp->is_drop, 0, // mp->is_unreach, 0, // mp->is_prohibit, 0, // mp->is_local, mp->mr_is_multicast, - mp->mr_is_classify, - mp->mr_classify_table_index, - mp->mr_is_resolve_host, - mp->mr_is_resolve_attached, - mp->mr_is_interface_rx, - mp->mr_is_rpf_id, + mp->mr_is_classify, + mp->mr_classify_table_index, + mp->mr_is_resolve_host, + mp->mr_is_resolve_attached, + mp->mr_is_interface_rx, + mp->mr_is_rpf_id, + 0, // l2_bridged + 0, // is source_lookup + 0, // is_udp_encap fib_index, &pfx, mp->mr_next_hop_proto, - &nh, ntohl (mp->mr_next_hop_sw_if_index), + &nh, ~0, // next_hop_id + ntohl (mp->mr_next_hop_sw_if_index), next_hop_fib_index, mp->mr_next_hop_weight, mp->mr_next_hop_preference, ntohl (mp->mr_next_hop_via_label), label_stack)); + /* *INDENT-ON* */ } void @@ -238,6 +264,33 @@ vl_api_mpls_route_add_del_t_handler (vl_api_mpls_route_add_del_t * mp) REPLY_MACRO (VL_API_MPLS_ROUTE_ADD_DEL_REPLY); } +void +mpls_table_create (u32 table_id, u8 is_api, const u8 * name) +{ + u32 fib_index; + + /* + * The MPLS defult table must also be explicitly created via the API. + * So in contrast to IP, it gets no special treatment here. + */ + + /* + * The API holds only one lock on the table. + * i.e. it can be added many times via the API but needs to be + * deleted only once. + */ + fib_index = fib_table_find (FIB_PROTOCOL_MPLS, table_id); + + if (~0 == fib_index) + { + fib_table_find_or_create_and_lock_w_name (FIB_PROTOCOL_MPLS, + table_id, + (is_api ? + FIB_SOURCE_API : + FIB_SOURCE_CLI), name); + } +} + static void vl_api_mpls_tunnel_add_del_t_handler (vl_api_mpls_tunnel_add_del_t * mp) { @@ -379,7 +432,8 @@ vl_api_mpls_tunnel_dump_t_handler (vl_api_mpls_tunnel_dump_t * mp) static void send_mpls_fib_details (vpe_api_main_t * am, unix_shared_memory_queue_t * q, - u32 table_id, u32 label, u32 eos, + const fib_table_t * table, + u32 label, u32 eos, fib_route_path_encode_t * api_rpaths, u32 context) { vl_api_mpls_fib_details_t *mp; @@ -395,7 +449,9 @@ send_mpls_fib_details (vpe_api_main_t * am, mp->_vl_msg_id = ntohs (VL_API_MPLS_FIB_DETAILS); mp->context = context; - mp->table_id = htonl (table_id); + mp->table_id = htonl (table->ft_table_id); + memcpy (mp->table_name, table->ft_desc, + clib_min (vec_len (table->ft_desc), sizeof (mp->table_name))); mp->eos_bit = eos; mp->label = htonl (label); @@ -467,8 +523,8 @@ vl_api_mpls_fib_dump_t_handler (vl_api_mpls_fib_dump_t * mp) api_rpaths = NULL; fib_entry_encode (*lfeip, &api_rpaths); send_mpls_fib_details (am, q, - fib_table->ft_table_id, - pfx.fp_label, pfx.fp_eos, api_rpaths, mp->context); + fib_table, pfx.fp_label, + pfx.fp_eos, api_rpaths, mp->context); vec_free (api_rpaths); }