X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fplugins%2Fgbp%2Fgbp_endpoint.c;h=9ef0890404141f48a07a8cbb1bb6b04d03578a92;hb=cbe25aab3be72154f2c706c39eeba6a77f34450f;hp=79c140ff91657bc3fd27168bfb22e0b5b21d940c;hpb=93cc3ee3b3a9c9224a1446625882205f3282a949;p=vpp.git diff --git a/src/plugins/gbp/gbp_endpoint.c b/src/plugins/gbp/gbp_endpoint.c index 79c140ff916..9ef08904041 100644 --- a/src/plugins/gbp/gbp_endpoint.c +++ b/src/plugins/gbp/gbp_endpoint.c @@ -24,13 +24,14 @@ #include #include -#include #include #include #include #include #include -#include +#include +#include +#include static const char *gbp_endpoint_attr_names[] = GBP_ENDPOINT_ATTR_NAMES; @@ -39,7 +40,10 @@ static const char *gbp_endpoint_attr_names[] = GBP_ENDPOINT_ATTR_NAMES; */ gbp_ep_db_t gbp_ep_db; -vlib_log_class_t gbp_ep_logger; +static fib_source_t gbp_fib_source_hi; +static fib_source_t gbp_fib_source_low; +static fib_node_type_t gbp_endpoint_fib_type; +static vlib_log_class_t gbp_ep_logger; #define GBP_ENDPOINT_DBG(...) \ vlib_log_debug (gbp_ep_logger, __VA_ARGS__); @@ -47,13 +51,6 @@ vlib_log_class_t gbp_ep_logger; #define GBP_ENDPOINT_INFO(...) \ vlib_log_notice (gbp_ep_logger, __VA_ARGS__); -/** - * GBP Endpoint inactive timeout (in seconds) - * If a dynamically learned Endpoint has not been heard from in this - * amount of time it is considered inactive and discarded - */ -static u32 GBP_ENDPOINT_INACTIVE_TIME = 30; - /** * Pool of GBP endpoints */ @@ -89,14 +86,36 @@ format_gbp_endpoint_flags (u8 * s, va_list * args) int gbp_endpoint_is_remote (const gbp_endpoint_t * ge) { - return (ge->ge_flags & GBP_ENDPOINT_FLAG_REMOTE); + return (! !(ge->ge_fwd.gef_flags & GBP_ENDPOINT_FLAG_REMOTE)); +} + +int +gbp_endpoint_is_local (const gbp_endpoint_t * ge) +{ + return (!(ge->ge_fwd.gef_flags & GBP_ENDPOINT_FLAG_REMOTE)); +} + +int +gbp_endpoint_is_external (const gbp_endpoint_t * ge) +{ + return (! !(ge->ge_fwd.gef_flags & GBP_ENDPOINT_FLAG_EXTERNAL)); +} + +int +gbp_endpoint_is_learnt (const gbp_endpoint_t * ge) +{ + if (0 == vec_len (ge->ge_locs)) + return 0; + + /* DP is the highest source so if present it will be first */ + return (ge->ge_locs[0].gel_src == GBP_ENDPOINT_SRC_DP); } static void gbp_endpoint_extract_key_mac_itf (const clib_bihash_kv_16_8_t * key, mac_address_t * mac, u32 * sw_if_index) { - mac_address_from_u64 (key->key[0], mac); + mac_address_from_u64 (mac, key->key[0]); *sw_if_index = key->key[1]; } @@ -188,268 +207,539 @@ gbp_endpoint_index (const gbp_endpoint_t * ge) return (ge - gbp_endpoint_pool); } -static ip46_type_t -ip46_address_get_type (const ip46_address_t * a) +static int +gbp_endpoint_ip_is_equal (const fib_prefix_t * fp, const ip46_address_t * ip) { - return (ip46_address_is_ip4 (a) ? IP46_TYPE_IP4 : IP46_TYPE_IP6); + return (ip46_address_is_equal (ip, &fp->fp_addr)); } -static ip46_type_t -ip46_address_get_len (const ip46_address_t * a) +static void +gbp_endpoint_ips_update (gbp_endpoint_t * ge, + const ip46_address_t * ips, + const gbp_route_domain_t * grd) { - return (ip46_address_is_ip4 (a) ? 32 : 128); + const ip46_address_t *ip; + index_t gei, grdi; + + gei = gbp_endpoint_index (ge); + grdi = gbp_route_domain_index (grd); + + ASSERT ((ge->ge_key.gek_grd == INDEX_INVALID) || + (ge->ge_key.gek_grd == grdi)); + + vec_foreach (ip, ips) + { + if (~0 == vec_search_with_function (ge->ge_key.gek_ips, ip, + gbp_endpoint_ip_is_equal)) + { + fib_prefix_t *pfx; + + vec_add2 (ge->ge_key.gek_ips, pfx, 1); + fib_prefix_from_ip46_addr (ip, pfx); + + gbp_endpoint_add_ip (&pfx->fp_addr, + grd->grd_fib_index[pfx->fp_proto], gei); + } + ge->ge_key.gek_grd = grdi; + } } static gbp_endpoint_t * -gbp_endpoint_alloc (epg_id_t epg_id, - index_t ggi, u32 sw_if_index, gbp_endpoint_flags_t flags, - const ip46_address_t * tun_src, - const ip46_address_t * tun_dst) +gbp_endpoint_alloc (const ip46_address_t * ips, + const gbp_route_domain_t * grd, + const mac_address_t * mac, + const gbp_bridge_domain_t * gbd) { gbp_endpoint_t *ge; + index_t gei; pool_get_zero (gbp_endpoint_pool, ge); - ge->ge_epg = ggi; - ge->ge_epg_id = epg_id; - ge->ge_flags = flags; - ge->ge_sw_if_index = sw_if_index; + fib_node_init (&ge->ge_node, gbp_endpoint_fib_type); + gei = gbp_endpoint_index (ge); + ge->ge_key.gek_gbd = + ge->ge_key.gek_grd = ge->ge_fwd.gef_fib_index = INDEX_INVALID; + gbp_itf_hdl_reset (&ge->ge_fwd.gef_itf); ge->ge_last_time = vlib_time_now (vlib_get_main ()); + ge->ge_key.gek_gbd = gbp_bridge_domain_index (gbd); + + if (NULL != mac) + { + mac_address_copy (&ge->ge_key.gek_mac, mac); + gbp_endpoint_add_mac (mac, gbd->gb_bd_index, gei); + } + gbp_endpoint_ips_update (ge, ips, grd); + + return (ge); +} + +static int +gbp_endpoint_loc_is_equal (gbp_endpoint_loc_t * a, gbp_endpoint_loc_t * b) +{ + return (a->gel_src == b->gel_src); +} + +static int +gbp_endpoint_loc_cmp_for_sort (gbp_endpoint_loc_t * a, gbp_endpoint_loc_t * b) +{ + return (a->gel_src - b->gel_src); +} + +static gbp_endpoint_loc_t * +gbp_endpoint_loc_find (gbp_endpoint_t * ge, gbp_endpoint_src_t src) +{ + gbp_endpoint_loc_t gel = { + .gel_src = src, + }; + u32 pos; + + pos = vec_search_with_function (ge->ge_locs, &gel, + gbp_endpoint_loc_is_equal); + + if (~0 != pos) + return (&ge->ge_locs[pos]); + + return NULL; +} + +static int +gbp_endpoint_loc_unlock (gbp_endpoint_t * ge, gbp_endpoint_loc_t * gel) +{ + u32 pos; + + gel->gel_locks--; + + if (0 == gel->gel_locks) + { + pos = gel - ge->ge_locs; + + vec_del1 (ge->ge_locs, pos); + if (vec_len (ge->ge_locs) > 1) + vec_sort_with_function (ge->ge_locs, gbp_endpoint_loc_cmp_for_sort); + + /* This could be the last lock, so don't access the EP from + * this point on */ + fib_node_unlock (&ge->ge_node); + + return (1); + } + return (0); +} + +static void +gbp_endpoint_loc_destroy (gbp_endpoint_loc_t * gel) +{ + gbp_endpoint_group_unlock (gel->gel_epg); + gbp_itf_unlock (&gel->gel_itf); +} + +static gbp_endpoint_loc_t * +gbp_endpoint_loc_find_or_add (gbp_endpoint_t * ge, gbp_endpoint_src_t src) +{ + gbp_endpoint_loc_t gel = { + .gel_src = src, + .gel_epg = INDEX_INVALID, + .gel_itf = GBP_ITF_HDL_INVALID, + .gel_locks = 0, + }; + u32 pos; + + pos = vec_search_with_function (ge->ge_locs, &gel, + gbp_endpoint_loc_is_equal); + + if (~0 == pos) + { + vec_add1 (ge->ge_locs, gel); + + if (vec_len (ge->ge_locs) > 1) + { + vec_sort_with_function (ge->ge_locs, gbp_endpoint_loc_cmp_for_sort); + + pos = vec_search_with_function (ge->ge_locs, &gel, + gbp_endpoint_loc_is_equal); + } + else + pos = 0; + + /* + * it's the sources and children that lock the endpoints + */ + fib_node_lock (&ge->ge_node); + } + + return (&ge->ge_locs[pos]); +} + +/** + * Find an EP inthe DBs and check that if we find it in the L2 DB + * it has the same IPs as this update + */ +static int +gbp_endpoint_find_for_update (const ip46_address_t * ips, + const gbp_route_domain_t * grd, + const mac_address_t * mac, + const gbp_bridge_domain_t * gbd, + gbp_endpoint_t ** ge) +{ + gbp_endpoint_t *l2_ge, *l3_ge, *tmp; - gbp_endpoint_group_find_and_lock (epg_id); + l2_ge = l3_ge = NULL; - if (gbp_endpoint_is_remote (ge)) + if (NULL != mac && !mac_address_is_zero (mac)) + { + ASSERT (gbd); + l2_ge = gbp_endpoint_find_mac (mac->bytes, gbd->gb_bd_index); + } + if (NULL != ips && !ip46_address_is_zero (ips)) + { + const ip46_address_t *ip; + fib_protocol_t fproto; + + ASSERT (grd); + vec_foreach (ip, ips) + { + fproto = fib_proto_from_ip46 (ip46_address_get_type (ip)); + + tmp = gbp_endpoint_find_ip (ip, grd->grd_fib_index[fproto]); + + if (NULL == tmp) + /* not found */ + continue; + else if (NULL == l3_ge) + /* first match against an IP address */ + l3_ge = tmp; + else if (tmp == l3_ge) + /* another match against IP address that is the same endpoint */ + continue; + else + { + /* + * a match agains a different endpoint. + * this means the KEY of the EP is changing which is not allowed + */ + return (-1); + } + } + } + + if (NULL == l2_ge && NULL == l3_ge) + /* not found */ + *ge = NULL; + else if (NULL == l2_ge) + /* found at L3 */ + *ge = l3_ge; + else if (NULL == l3_ge) + /* found at L2 */ + *ge = l2_ge; + else + { + /* found both L3 and L2 - they must be the same else the KEY + * is changing + */ + if (l2_ge == l3_ge) + *ge = l2_ge; + else + return (-1); + } + + return (0); +} + +static gbp_endpoint_src_t +gbp_endpoint_get_best_src (const gbp_endpoint_t * ge) +{ + if (0 == vec_len (ge->ge_locs)) + return (GBP_ENDPOINT_SRC_MAX); + + return (ge->ge_locs[0].gel_src); +} + +static void +gbp_endpoint_n_learned (int n) +{ + gbp_n_learnt_endpoints += n; + + if (n > 0 && 1 == gbp_n_learnt_endpoints) + { + vlib_process_signal_event (vlib_get_main (), + gbp_scanner_node.index, + GBP_ENDPOINT_SCAN_START, 0); + } + if (n < 0 && 0 == gbp_n_learnt_endpoints) + { + vlib_process_signal_event (vlib_get_main (), + gbp_scanner_node.index, + GBP_ENDPOINT_SCAN_STOP, 0); + } +} + +static void +gbp_endpoint_loc_update (const gbp_endpoint_t * ge, + gbp_endpoint_loc_t * gel, + const gbp_bridge_domain_t * gb, + u32 sw_if_index, + index_t ggi, + gbp_endpoint_flags_t flags, + const ip46_address_t * tun_src, + const ip46_address_t * tun_dst) +{ + int was_learnt, is_learnt; + + gel->gel_locks++; + was_learnt = ! !(gel->gel_flags & GBP_ENDPOINT_FLAG_REMOTE); + gel->gel_flags = flags; + is_learnt = ! !(gel->gel_flags & GBP_ENDPOINT_FLAG_REMOTE); + + gbp_endpoint_n_learned (is_learnt - was_learnt); + + /* + * update the EPG + */ + gbp_endpoint_group_lock (ggi); + gbp_endpoint_group_unlock (gel->gel_epg); + gel->gel_epg = ggi; + + if (gel->gel_flags & GBP_ENDPOINT_FLAG_REMOTE) { if (NULL != tun_src) - ip46_address_copy (&ge->tun.ge_src, tun_src); + ip46_address_copy (&gel->tun.gel_src, tun_src); if (NULL != tun_dst) - ip46_address_copy (&ge->tun.ge_dst, tun_dst); + ip46_address_copy (&gel->tun.gel_dst, tun_dst); + + if (ip46_address_is_multicast (&gel->tun.gel_src)) + { + /* + * we learnt the EP from the multicast tunnel. + * Create a unicast TEP from the packet's source + * and the fixed address of the BD's parent tunnel + */ + const gbp_vxlan_tunnel_t *gt; + + gt = gbp_vxlan_tunnel_get (gb->gb_vni); + + if (NULL != gt) + { + ip46_address_copy (&gel->tun.gel_src, >->gt_src); + sw_if_index = gt->gt_sw_if_index; + } + } /* * the input interface may be the parent GBP-vxlan interface, * create a child vlxan-gbp tunnel and use that as the endpoint's * interface. */ + gbp_itf_hdl_t old = gel->gel_itf; + switch (gbp_vxlan_tunnel_get_type (sw_if_index)) { case GBP_VXLAN_TEMPLATE_TUNNEL: - ge->tun.ge_parent_sw_if_index = sw_if_index; - ge->ge_sw_if_index = - gbp_vxlan_tunnel_clone_and_lock (sw_if_index, tun_src, tun_dst); + gel->tun.gel_parent_sw_if_index = sw_if_index; + gel->gel_itf = gbp_vxlan_tunnel_clone_and_lock (sw_if_index, + &gel->tun.gel_src, + &gel->tun.gel_dst); break; case VXLAN_GBP_TUNNEL: - ge->tun.ge_parent_sw_if_index = + gel->tun.gel_parent_sw_if_index = vxlan_gbp_tunnel_get_parent (sw_if_index); - ge->ge_sw_if_index = sw_if_index; - vxlan_gbp_tunnel_lock (ge->ge_sw_if_index); + gel->gel_itf = vxlan_gbp_tunnel_lock_itf (sw_if_index); break; } - } - return (ge); + gbp_itf_unlock (&old); + } + else + { + gel->gel_itf = gbp_itf_l2_add_and_lock (sw_if_index, + ge->ge_key.gek_gbd); + } } -int -gbp_endpoint_update (u32 sw_if_index, - const ip46_address_t * ips, - const mac_address_t * mac, - epg_id_t epg_id, - gbp_endpoint_flags_t flags, - const ip46_address_t * tun_src, - const ip46_address_t * tun_dst, u32 * handle) +static void +gbb_endpoint_fwd_reset (gbp_endpoint_t * ge) { - gbp_endpoint_group_t *gg; - gbp_endpoint_t *ge; - index_t ggi, gei; + const gbp_route_domain_t *grd; + const gbp_bridge_domain_t *gbd; + gbp_endpoint_fwd_t *gef; + const fib_prefix_t *pfx; + index_t *ai; - if (~0 == sw_if_index) - return (VNET_API_ERROR_INVALID_SW_IF_INDEX); + gbd = gbp_bridge_domain_get (ge->ge_key.gek_gbd); + gef = &ge->ge_fwd; - ge = NULL; - ggi = gbp_endpoint_group_find_and_lock (epg_id); + vec_foreach (pfx, ge->ge_key.gek_ips) + { + u32 fib_index; - if (INDEX_INVALID == ggi) - return (VNET_API_ERROR_NO_SUCH_ENTRY); + grd = gbp_route_domain_get (ge->ge_key.gek_grd); + fib_index = grd->grd_fib_index[pfx->fp_proto]; - gg = gbp_endpoint_group_get (ggi); + bd_add_del_ip_mac (gbd->gb_bd_index, fib_proto_to_ip46 (pfx->fp_proto), + &pfx->fp_addr, &ge->ge_key.gek_mac, 0); - /* - * L2 EP - */ - if (NULL != mac && !mac_address_is_zero (mac)) - { - /* - * find an existing endpoint matching one of the key types - */ - ge = gbp_endpoint_find_mac (mac->bytes, gg->gg_bd_index); - if (NULL == ge) - { - /* - * new entry - */ - ge = gbp_endpoint_alloc (epg_id, ggi, sw_if_index, flags, - tun_src, tun_dst); - gei = gbp_endpoint_index (ge); - mac_address_copy (&ge->ge_mac, mac); - - ge->ge_itf = gbp_itf_add_and_lock (ge->ge_sw_if_index, - gg->gg_bd_index); + /* + * remove a host route + */ + if (gbp_endpoint_is_remote (ge)) + { + fib_table_entry_special_remove (fib_index, pfx, gbp_fib_source_hi); + } - gbp_itf_set_l2_input_feature (ge->ge_itf, gei, - L2INPUT_FEAT_GBP_FWD); + fib_table_entry_delete (fib_index, pfx, gbp_fib_source_low); + } + vec_foreach (ai, gef->gef_adjs) + { + adj_unlock (*ai); + } - if (gbp_endpoint_is_remote (ge)) - { - gbp_itf_set_l2_output_feature (ge->ge_itf, gei, - L2OUTPUT_FEAT_GBP_POLICY_MAC); - } - else - { - gbp_endpoint_add_itf (ge->ge_sw_if_index, gei); - gbp_itf_set_l2_output_feature (ge->ge_itf, gei, - L2OUTPUT_FEAT_GBP_POLICY_PORT); - } + if (gbp_itf_hdl_is_valid (gef->gef_itf)) + { + l2fib_del_entry (ge->ge_key.gek_mac.bytes, + gbd->gb_bd_index, + gbp_itf_get_sw_if_index (gef->gef_itf)); + } - gbp_endpoint_add_mac (mac, gg->gg_bd_index, gei); + gbp_itf_unlock (&gef->gef_itf); + vec_free (gef->gef_adjs); +} - l2fib_add_entry (mac->bytes, gg->gg_bd_index, ge->ge_sw_if_index, - L2FIB_ENTRY_RESULT_FLAG_STATIC); - } - else - { - /* - * update existing entry.. - */ - ge->ge_flags = flags; - gei = gbp_endpoint_index (ge); - goto out; - } - } +static void +gbb_endpoint_fwd_recalc (gbp_endpoint_t * ge) +{ + const gbp_bridge_domain_t *gbd; + const gbp_endpoint_group_t *gg; + const gbp_route_domain_t *grd; + gbp_endpoint_loc_t *gel; + gbp_endpoint_fwd_t *gef; + const fib_prefix_t *pfx; + index_t gei; /* - * L3 EP + * locations are sort in source priority order */ - if (NULL != ips && !ip46_address_is_zero (ips)) + gei = gbp_endpoint_index (ge); + gel = &ge->ge_locs[0]; + gef = &ge->ge_fwd; + gbd = gbp_bridge_domain_get (ge->ge_key.gek_gbd); + + gef->gef_flags = gel->gel_flags; + + if (INDEX_INVALID != gel->gel_epg) { - const ip46_address_t *ip; - fib_protocol_t fproto; - gbp_endpoint_t *l3_ge; - u32 ii; + gg = gbp_endpoint_group_get (gel->gel_epg); + gef->gef_sclass = gg->gg_sclass; + } + else + { + gg = NULL; + } - /* - * look for a matching EP by any of the address - * An EP's IP addresses cannot change so we can search based on - * the first - */ - fproto = fib_proto_from_ip46 (ip46_address_get_type (&ips[0])); + gef->gef_itf = gbp_itf_clone_and_lock (gel->gel_itf); - l3_ge = gbp_endpoint_find_ip (&ips[0], - gbp_endpoint_group_get_fib_index (gg, - fproto)); - if (NULL == l3_ge) + if (!mac_address_is_zero (&ge->ge_key.gek_mac)) + { + gbp_itf_l2_set_input_feature (gef->gef_itf, L2INPUT_FEAT_GBP_FWD); + + if (gbp_endpoint_is_remote (ge) || gbp_endpoint_is_external (ge)) { - if (NULL == ge) - { - ge = gbp_endpoint_alloc (epg_id, ggi, sw_if_index, flags, - tun_src, tun_dst); - ge->ge_itf = gbp_itf_add_and_lock (sw_if_index, ~0); - } - else - /* L2 EP with IPs */ - gei = gbp_endpoint_index (ge); + /* + * bridged packets to external endpoints should be classifed + * based on the EP's/BD's EPG + */ + gbp_itf_l2_set_output_feature (gef->gef_itf, + L2OUTPUT_FEAT_GBP_POLICY_MAC); } else { - /* modify */ - ge = l3_ge; - ge->ge_flags = flags; - gei = gbp_endpoint_index (ge); - goto out; + gbp_endpoint_add_itf (gbp_itf_get_sw_if_index (gef->gef_itf), gei); + gbp_itf_l2_set_output_feature (gef->gef_itf, + L2OUTPUT_FEAT_GBP_POLICY_PORT); } + l2fib_add_entry (ge->ge_key.gek_mac.bytes, + gbd->gb_bd_index, + gbp_itf_get_sw_if_index (gef->gef_itf), + L2FIB_ENTRY_RESULT_FLAG_STATIC); + } - gei = gbp_endpoint_index (ge); - ge->ge_ips = ips; - vec_validate (ge->ge_adjs, vec_len (ips) - 1); - - vec_foreach_index (ii, ge->ge_ips) + vec_foreach (pfx, ge->ge_key.gek_ips) + { + ethernet_header_t *eth; + u32 ip_sw_if_index; + u32 fib_index; + u8 *rewrite; + index_t ai; + + rewrite = NULL; + grd = gbp_route_domain_get (ge->ge_key.gek_grd); + fib_index = grd->grd_fib_index[pfx->fp_proto]; + gef->gef_fib_index = fib_index; + + bd_add_del_ip_mac (gbd->gb_bd_index, fib_proto_to_ip46 (pfx->fp_proto), + &pfx->fp_addr, &ge->ge_key.gek_mac, 1); + + /* + * add a host route via the EPG's BVI we need this because the + * adj fib does not install, due to cover refinement check, since + * the BVI's prefix is /32 + */ + vec_validate (rewrite, sizeof (*eth) - 1); + eth = (ethernet_header_t *) rewrite; + + eth->type = clib_host_to_net_u16 ((pfx->fp_proto == FIB_PROTOCOL_IP4 ? + ETHERNET_TYPE_IP4 : + ETHERNET_TYPE_IP6)); + + if (gbp_endpoint_is_remote (ge)) { - ethernet_header_t *eth; - ip46_type_t ip_type; - u32 ip_sw_if_index; - u8 *rewrite; - - rewrite = NULL; - ip = &ge->ge_ips[ii]; - ip_type = ip46_address_get_type (ip); - fproto = fib_proto_from_ip46 (ip_type); - - bd_add_del_ip_mac (gg->gg_bd_index, ip_type, ip, &ge->ge_mac, 1); - - // FIXME - check error - gbp_endpoint_add_ip (ip, - gbp_endpoint_group_get_fib_index (gg, fproto), - gei); - /* - * add a host route via the EPG's BVI we need this because the - * adj fib does not install, due to cover refinement check, since - * the BVI's prefix is /32 + * for dynamic EPs we must add the IP adjacency via the learned + * tunnel since the BD will not contain the EP's MAC since it was + * L3 learned. The dst MAC address used is the 'BD's MAC'. */ - fib_prefix_t pfx = { - .fp_proto = fproto, - .fp_len = ip46_address_get_len (ip), - .fp_addr = *ip, - }; - vec_validate (rewrite, sizeof (*eth) - 1); - eth = (ethernet_header_t *) rewrite; - - eth->type = clib_host_to_net_u16 ((fproto == FIB_PROTOCOL_IP4 ? - ETHERNET_TYPE_IP4 : - ETHERNET_TYPE_IP6)); - - if (gbp_endpoint_is_remote (ge)) - { - /* - * for dynamic EPs we msut add the IP adjacency via the learned - * tunnel since the BD will not contain the EP's MAC since it was - * L3 learned. The dst MAC address used is the 'BD's MAC'. - */ - ip_sw_if_index = ge->ge_sw_if_index; - - mac_address_to_bytes (gbp_route_domain_get_local_mac (), - eth->src_address); - mac_address_to_bytes (gbp_route_domain_get_remote_mac (), - eth->dst_address); - } - else - { - /* - * for the static EPs we add the IP adjacency via the BVI - * knowing that the BD has the MAC address to route to and - * that policy will be applied on egress to the EP's port - */ - ip_sw_if_index = gbp_endpoint_group_get_bvi (gg); - - clib_memcpy (eth->src_address, - vnet_sw_interface_get_hw_address (vnet_get_main (), - ip_sw_if_index), - sizeof (eth->src_address)); - mac_address_to_bytes (&ge->ge_mac, eth->dst_address); - } + ip_sw_if_index = gbp_itf_get_sw_if_index (gef->gef_itf); - fib_table_entry_path_add - (gbp_endpoint_group_get_fib_index (gg, fproto), - &pfx, FIB_SOURCE_PLUGIN_LOW, - FIB_ENTRY_FLAG_NONE, - fib_proto_to_dpo (fproto), ip, ip_sw_if_index, - ~0, 1, NULL, FIB_ROUTE_PATH_FLAG_NONE); + mac_address_to_bytes (gbp_route_domain_get_local_mac (), + eth->src_address); + mac_address_to_bytes (gbp_route_domain_get_remote_mac (), + eth->dst_address); + } + else + { + /* + * for the static EPs we add the IP adjacency via the BVI + * knowing that the BD has the MAC address to route to and + * that policy will be applied on egress to the EP's port + */ + ip_sw_if_index = gbd->gb_bvi_sw_if_index; - ge->ge_adjs[ii] = adj_nbr_add_or_lock_w_rewrite (fproto, - fib_proto_to_link - (fproto), ip, - ip_sw_if_index, - rewrite); + clib_memcpy (eth->src_address, + vnet_sw_interface_get_hw_address (vnet_get_main (), + ip_sw_if_index), + sizeof (eth->src_address)); + mac_address_to_bytes (&ge->ge_key.gek_mac, eth->dst_address); + } + fib_table_entry_path_add (fib_index, pfx, + gbp_fib_source_low, + FIB_ENTRY_FLAG_NONE, + fib_proto_to_dpo (pfx->fp_proto), + &pfx->fp_addr, ip_sw_if_index, + ~0, 1, NULL, FIB_ROUTE_PATH_FLAG_NONE); + + ai = adj_nbr_add_or_lock_w_rewrite (pfx->fp_proto, + fib_proto_to_link (pfx->fp_proto), + &pfx->fp_addr, + ip_sw_if_index, rewrite); + vec_add1 (gef->gef_adjs, ai); + + /* + * if the endpoint is external then routed packet to it must be + * classifed to the BD's EPG. but this will happen anyway with + * the GBP_MAC classification. + */ + + if (NULL != gg) + { if (gbp_endpoint_is_remote (ge)) { dpo_id_t policy_dpo = DPO_INVALID; @@ -458,13 +748,15 @@ gbp_endpoint_update (u32 sw_if_index, * interpose a policy DPO from the endpoint so that policy * is applied */ - gbp_policy_dpo_add_or_lock (fib_proto_to_dpo (fproto), - gg->gg_id, ~0, &policy_dpo); - - fib_table_entry_special_dpo_add - (gbp_endpoint_group_get_fib_index (gg, fproto), - &pfx, - FIB_SOURCE_PLUGIN_HI, FIB_ENTRY_FLAG_INTERPOSE, &policy_dpo); + gbp_policy_dpo_add_or_lock (fib_proto_to_dpo (pfx->fp_proto), + grd->grd_scope, + gg->gg_sclass, ~0, &policy_dpo); + + fib_table_entry_special_dpo_add (fib_index, pfx, + gbp_fib_source_hi, + FIB_ENTRY_FLAG_INTERPOSE, + &policy_dpo); + dpo_reset (&policy_dpo); } /* @@ -472,68 +764,154 @@ gbp_endpoint_update (u32 sw_if_index, * that if this EP has moved from some other place in the * 'fabric', upstream devices are informed */ - if (!(gbp_endpoint_is_remote (ge)) && ~0 != gg->gg_uplink_sw_if_index) + if (gbp_endpoint_is_local (ge) && ~0 != gg->gg_uplink_sw_if_index) { - gbp_endpoint_add_itf (sw_if_index, gei); - if (ip46_address_is_ip4 (ip)) - send_ip4_garp_w_addr (vlib_get_main (), - &ip->ip4, gg->gg_uplink_sw_if_index); - else - send_ip6_na_w_addr (vlib_get_main (), - &ip->ip6, gg->gg_uplink_sw_if_index); + gbp_endpoint_add_itf (gbp_itf_get_sw_if_index (gef->gef_itf), + gei); + ip_neighbor_advertise (vlib_get_main (), + (FIB_PROTOCOL_IP4 == pfx->fp_proto ? + IP46_TYPE_IP4 : + IP46_TYPE_IP6), + &pfx->fp_addr, gg->gg_uplink_sw_if_index); } } - } - - if (NULL == ge) - return (0); + } - /* - * count the number of dynamic entries and kick off the scanner - * process is this is our first. - */ - if (gbp_endpoint_is_remote (ge)) + if (gbp_endpoint_is_external (ge)) { - gbp_n_learnt_endpoints++; - - if (1 == gbp_n_learnt_endpoints) - { - vlib_process_signal_event (vlib_get_main (), - gbp_scanner_node.index, - GBP_ENDPOINT_SCAN_START, 0); - } + gbp_itf_l2_set_input_feature (gef->gef_itf, + L2INPUT_FEAT_GBP_LPM_CLASSIFY); } - else + else if (gbp_endpoint_is_local (ge)) { /* * non-remote endpoints (i.e. those not arriving on iVXLAN * tunnels) need to be classifed based on the the input interface. - * We enable the GBP-FWD feature only is the group has an uplink + * We enable the GBP-FWD feature only if the group has an uplink * interface (on which the GBP-FWD feature would send UU traffic). + * External endpoints get classified based on an LPM match */ l2input_feat_masks_t feats = L2INPUT_FEAT_GBP_SRC_CLASSIFY; - if (~0 != gg->gg_uplink_sw_if_index) + if (NULL != gg && ~0 != gg->gg_uplink_sw_if_index) feats |= L2INPUT_FEAT_GBP_FWD; - gbp_itf_set_l2_input_feature (ge->ge_itf, gbp_endpoint_index (ge), - feats); + gbp_itf_l2_set_input_feature (gef->gef_itf, feats); + } + + /* + * update children with the new forwarding info + */ + fib_node_back_walk_ctx_t bw_ctx = { + .fnbw_reason = FIB_NODE_BW_REASON_FLAG_EVALUATE, + .fnbw_flags = FIB_NODE_BW_FLAG_FORCE_SYNC, + }; + + fib_walk_sync (gbp_endpoint_fib_type, gei, &bw_ctx); +} + +int +gbp_endpoint_update_and_lock (gbp_endpoint_src_t src, + u32 sw_if_index, + const ip46_address_t * ips, + const mac_address_t * mac, + index_t gbdi, index_t grdi, + sclass_t sclass, + gbp_endpoint_flags_t flags, + const ip46_address_t * tun_src, + const ip46_address_t * tun_dst, u32 * handle) +{ + gbp_bridge_domain_t *gbd; + gbp_endpoint_group_t *gg; + gbp_endpoint_src_t best; + gbp_route_domain_t *grd; + gbp_endpoint_loc_t *gel; + gbp_endpoint_t *ge; + index_t ggi, gei; + int rv; + + if (~0 == sw_if_index) + return (VNET_API_ERROR_INVALID_SW_IF_INDEX); + + ge = NULL; + gg = NULL; + + /* + * we need to determine the bridge-domain, either from the EPG or + * the BD passed + */ + if (SCLASS_INVALID != sclass) + { + ggi = gbp_endpoint_group_find (sclass); + + if (INDEX_INVALID == ggi) + return (VNET_API_ERROR_NO_SUCH_ENTRY); + + gg = gbp_endpoint_group_get (ggi); + gbdi = gg->gg_gbd; + grdi = gg->gg_rd; + } + else + { + if (INDEX_INVALID == gbdi) + return (VNET_API_ERROR_NO_SUCH_ENTRY); + if (INDEX_INVALID == grdi) + return (VNET_API_ERROR_NO_SUCH_FIB); + ggi = INDEX_INVALID; + } + + gbd = gbp_bridge_domain_get (gbdi); + grd = gbp_route_domain_get (grdi); + rv = gbp_endpoint_find_for_update (ips, grd, mac, gbd, &ge); + + if (0 != rv) + return (rv); + + if (NULL == ge) + { + ge = gbp_endpoint_alloc (ips, grd, mac, gbd); + } + else + { + gbp_endpoint_ips_update (ge, ips, grd); + } + + best = gbp_endpoint_get_best_src (ge); + gei = gbp_endpoint_index (ge); + gel = gbp_endpoint_loc_find_or_add (ge, src); + + gbp_endpoint_loc_update (ge, gel, gbd, sw_if_index, ggi, flags, + tun_src, tun_dst); + + if (src <= best) + { + /* + * either the best source has been updated or we have a new best source + */ + gbb_endpoint_fwd_reset (ge); + gbb_endpoint_fwd_recalc (ge); + } + else + { + /* + * an update to a lower priority source, so we need do nothing + */ } -out: if (handle) - *handle = (ge - gbp_endpoint_pool); + *handle = gei; - gbp_endpoint_group_unlock (ggi); GBP_ENDPOINT_INFO ("update: %U", format_gbp_endpoint, gei); return (0); } void -gbp_endpoint_delete (index_t gei) +gbp_endpoint_unlock (gbp_endpoint_src_t src, index_t gei) { - gbp_endpoint_group_t *gg; + gbp_endpoint_loc_t *gel, gel_copy; + gbp_endpoint_src_t best; gbp_endpoint_t *ge; + int removed; if (pool_is_free_index (gbp_endpoint_pool, gei)) return; @@ -541,86 +919,90 @@ gbp_endpoint_delete (index_t gei) GBP_ENDPOINT_INFO ("delete: %U", format_gbp_endpoint, gei); ge = gbp_endpoint_get (gei); - gg = gbp_endpoint_group_get (ge->ge_epg); - - gbp_endpoint_del_mac (&ge->ge_mac, gg->gg_bd_index); - l2fib_del_entry (ge->ge_mac.bytes, gg->gg_bd_index, ge->ge_sw_if_index); - gbp_itf_set_l2_input_feature (ge->ge_itf, gei, (L2INPUT_FEAT_NONE)); - gbp_itf_set_l2_output_feature (ge->ge_itf, gei, L2OUTPUT_FEAT_NONE); - - if (NULL != ge->ge_ips) - { - const ip46_address_t *ip; - index_t *ai; - - vec_foreach (ai, ge->ge_adjs) - { - adj_unlock (*ai); - } - vec_foreach (ip, ge->ge_ips) - { - fib_protocol_t fproto; - ip46_type_t ip_type; - ip_type = ip46_address_get_type (ip); - fproto = fib_proto_from_ip46 (ip_type); + gel = gbp_endpoint_loc_find (ge, src); - gbp_endpoint_del_ip (ip, - gbp_endpoint_group_get_fib_index (gg, fproto)); - - bd_add_del_ip_mac (gg->gg_bd_index, ip_type, ip, &ge->ge_mac, 0); + if (NULL == gel) + return; - /* - * remove a host route via the EPG's BVI - */ - fib_prefix_t pfx = { - .fp_proto = fproto, - .fp_len = ip46_address_get_len (ip), - .fp_addr = *ip, - }; + /* + * lock the EP so we can control when it is deleted + */ + fib_node_lock (&ge->ge_node); + best = gbp_endpoint_get_best_src (ge); - if (gbp_endpoint_is_remote (ge)) - { - fib_table_entry_special_remove - (gbp_endpoint_group_get_fib_index (gg, fproto), - &pfx, FIB_SOURCE_PLUGIN_HI); - } + /* + * copy the location info since we'll lose it when it's removed from + * the vector + */ + clib_memcpy (&gel_copy, gel, sizeof (gel_copy)); - fib_table_entry_path_remove - (gbp_endpoint_group_get_fib_index (gg, fproto), - &pfx, FIB_SOURCE_PLUGIN_LOW, - fib_proto_to_dpo (fproto), ip, - (gbp_endpoint_is_remote (ge) ? - ge->ge_sw_if_index : - gbp_endpoint_group_get_bvi (gg)), - ~0, 1, FIB_ROUTE_PATH_FLAG_NONE); - } - } + /* + * remove the source we no longer need + */ + removed = gbp_endpoint_loc_unlock (ge, gel); - if (ge->ge_flags & GBP_ENDPOINT_FLAG_LEARNT) + if (src == best) { - gbp_n_learnt_endpoints--; - - if (0 == gbp_n_learnt_endpoints) + /* + * we have removed the old best source => recalculate fwding + */ + if (0 == vec_len (ge->ge_locs)) { - vlib_process_signal_event (vlib_get_main (), - gbp_scanner_node.index, - GBP_ENDPOINT_SCAN_STOP, 0); + /* + * if there are no more sources left, then we need only release + * the fwding resources held and then this EP is gawn. + */ + gbb_endpoint_fwd_reset (ge); + } + else + { + /* + * else there are more sources. release the old and get new + * fwding objects + */ + gbb_endpoint_fwd_reset (ge); + gbb_endpoint_fwd_recalc (ge); } } + /* + * else + * we removed a lower priority source so we need to do nothing + */ - gbp_itf_unlock (ge->ge_itf); - if (gbp_endpoint_is_remote (ge)) - { - vxlan_gbp_tunnel_unlock (ge->ge_sw_if_index); - } - gbp_endpoint_group_unlock (ge->ge_epg); - pool_put (gbp_endpoint_pool, ge); + /* + * clear up any resources held by the source + */ + if (removed) + gbp_endpoint_loc_destroy (&gel_copy); + + /* + * remove the lock taken above + */ + fib_node_unlock (&ge->ge_node); + /* + * We may have removed the last source and so this EP is now TOAST + * DO NOTHING BELOW HERE + */ +} + +u32 +gbp_endpoint_child_add (index_t gei, + fib_node_type_t type, fib_node_index_t index) +{ + return (fib_node_child_add (gbp_endpoint_fib_type, gei, type, index)); +} + +void +gbp_endpoint_child_remove (index_t gei, u32 sibling) +{ + return (fib_node_child_remove (gbp_endpoint_fib_type, gei, sibling)); } typedef struct gbp_endpoint_flush_ctx_t_ { u32 sw_if_index; + gbp_endpoint_src_t src; index_t *geis; } gbp_endpoint_flush_ctx_t; @@ -628,12 +1010,13 @@ static walk_rc_t gbp_endpoint_flush_cb (index_t gei, void *args) { gbp_endpoint_flush_ctx_t *ctx = args; + gbp_endpoint_loc_t *gel; gbp_endpoint_t *ge; ge = gbp_endpoint_get (gei); + gel = gbp_endpoint_loc_find (ge, ctx->src); - if (gbp_endpoint_is_remote (ge) && - ctx->sw_if_index == ge->tun.ge_parent_sw_if_index) + if ((NULL != gel) && ctx->sw_if_index == gel->tun.gel_parent_sw_if_index) { vec_add1 (ctx->geis, gei); } @@ -645,18 +1028,23 @@ gbp_endpoint_flush_cb (index_t gei, void *args) * remove all learnt endpoints using the interface */ void -gbp_endpoint_flush (u32 sw_if_index) +gbp_endpoint_flush (gbp_endpoint_src_t src, u32 sw_if_index) { gbp_endpoint_flush_ctx_t ctx = { .sw_if_index = sw_if_index, + .src = src, }; index_t *gei; + GBP_ENDPOINT_INFO ("flush: %U %U", + format_gbp_endpoint_src, src, + format_vnet_sw_if_index_name, vnet_get_main (), + sw_if_index); gbp_endpoint_walk (gbp_endpoint_flush_cb, &ctx); vec_foreach (gei, ctx.geis) { - gbp_endpoint_delete (*gei); + gbp_endpoint_unlock (src, *gei); } vec_free (ctx.geis); @@ -683,9 +1071,10 @@ gbp_endpoint_cli (vlib_main_t * vm, ip46_address_t ip = ip46_address_initializer, *ips = NULL; mac_address_t mac = ZERO_MAC_ADDRESS; vnet_main_t *vnm = vnet_get_main (); - u32 epg_id = EPG_INVALID; + u32 sclass = SCLASS_INVALID; u32 handle = INDEX_INVALID; u32 sw_if_index = ~0; + u32 flags = GBP_ENDPOINT_FLAG_NONE; u8 add = 1; int rv; @@ -700,7 +1089,7 @@ gbp_endpoint_cli (vlib_main_t * vm, add = 1; else if (unformat (input, "del")) add = 0; - else if (unformat (input, "epg %d", &epg_id)) + else if (unformat (input, "sclass %d", &sclass)) ; else if (unformat (input, "handle %d", &handle)) ; @@ -710,6 +1099,8 @@ gbp_endpoint_cli (vlib_main_t * vm, vec_add1 (ips, ip); else if (unformat (input, "mac %U", unformat_mac_address, &mac)) ; + else if (unformat (input, "flags 0x%x", &flags)) + ; else break; } @@ -718,12 +1109,14 @@ gbp_endpoint_cli (vlib_main_t * vm, { if (~0 == sw_if_index) return clib_error_return (0, "interface must be specified"); - if (EPG_INVALID == epg_id) - return clib_error_return (0, "EPG-ID must be specified"); + if (SCLASS_INVALID == sclass) + return clib_error_return (0, "SCLASS must be specified"); rv = - gbp_endpoint_update (sw_if_index, ips, &mac, epg_id, - GBP_ENDPOINT_FLAG_NONE, NULL, NULL, &handle); + gbp_endpoint_update_and_lock (GBP_ENDPOINT_SRC_CP, + sw_if_index, ips, &mac, + INDEX_INVALID, INDEX_INVALID, + sclass, flags, NULL, NULL, &handle); if (rv) return clib_error_return (0, "GBP Endpoint update returned %d", rv); @@ -735,7 +1128,7 @@ gbp_endpoint_cli (vlib_main_t * vm, if (INDEX_INVALID == handle) return clib_error_return (0, "handle must be specified"); - gbp_endpoint_delete (handle); + gbp_endpoint_unlock (GBP_ENDPOINT_SRC_CP, handle); } vec_free (ips); @@ -743,50 +1136,114 @@ gbp_endpoint_cli (vlib_main_t * vm, return (NULL); } - /*? * Configure a GBP Endpoint * * @cliexpar - * @cliexstart{set gbp endpoint [del] epg ip } + * @cliexstart{gbp endpoint del | [add] sclass ip mac [flags ]} * @cliexend ?*/ /* *INDENT-OFF* */ VLIB_CLI_COMMAND (gbp_endpoint_cli_node, static) = { .path = "gbp endpoint", - .short_help = "gbp endpoint [del] epg ip mac ", + .short_help = "gbp endpoint del | [add] sclass ip mac [flags ]", .function = gbp_endpoint_cli, }; /* *INDENT-ON* */ u8 * -format_gbp_endpoint (u8 * s, va_list * args) +format_gbp_endpoint_src (u8 * s, va_list * args) { - index_t gei = va_arg (*args, index_t); - const ip46_address_t *ip; - gbp_endpoint_t *ge; + gbp_endpoint_src_t action = va_arg (*args, gbp_endpoint_src_t); - ge = gbp_endpoint_get (gei); + switch (action) + { +#define _(v,a) case GBP_ENDPOINT_SRC_##v: return (format (s, "%s", a)); + foreach_gbp_endpoint_src +#undef _ + } + + return (format (s, "unknown")); +} + +static u8 * +format_gbp_endpoint_fwd (u8 * s, va_list * args) +{ + gbp_endpoint_fwd_t *gef = va_arg (*args, gbp_endpoint_fwd_t *); + + s = format (s, "fwd:"); + s = format (s, "\n itf:[%U]", format_gbp_itf_hdl, gef->gef_itf); + if (GBP_ENDPOINT_FLAG_NONE != gef->gef_flags) + { + s = format (s, " flags:%U", format_gbp_endpoint_flags, gef->gef_flags); + } - s = format (s, "[@%d] ", gei); - s = format (s, "IPs:["); + return (s); +} - vec_foreach (ip, ge->ge_ips) +static u8 * +format_gbp_endpoint_key (u8 * s, va_list * args) +{ + gbp_endpoint_key_t *gek = va_arg (*args, gbp_endpoint_key_t *); + const fib_prefix_t *pfx; + + s = format (s, "ips:["); + + vec_foreach (pfx, gek->gek_ips) { - s = format (s, "%U, ", format_ip46_address, ip, IP46_TYPE_ANY); + s = format (s, "%U, ", format_fib_prefix, pfx); } s = format (s, "]"); - s = format (s, " MAC:%U", format_mac_address_t, &ge->ge_mac); - s = format (s, " EPG-ID:%d", ge->ge_epg_id); - if (GBP_ENDPOINT_FLAG_NONE != ge->ge_flags) + s = format (s, " mac:%U", format_mac_address_t, &gek->gek_mac); + + return (s); +} + +static u8 * +format_gbp_endpoint_loc (u8 * s, va_list * args) +{ + gbp_endpoint_loc_t *gel = va_arg (*args, gbp_endpoint_loc_t *); + + s = format (s, "%U", format_gbp_endpoint_src, gel->gel_src); + s = format (s, "\n EPG:%d [%U]", gel->gel_epg, + format_gbp_itf_hdl, gel->gel_itf); + + if (GBP_ENDPOINT_FLAG_NONE != gel->gel_flags) { - s = format (s, " flags:%U", format_gbp_endpoint_flags, ge->ge_flags); + s = format (s, " flags:%U", format_gbp_endpoint_flags, gel->gel_flags); } + if (GBP_ENDPOINT_FLAG_REMOTE & gel->gel_flags) + { + s = format (s, " tun:["); + s = format (s, "parent:%U", format_vnet_sw_if_index_name, + vnet_get_main (), gel->tun.gel_parent_sw_if_index); + s = format (s, " {%U,%U}]", + format_ip46_address, &gel->tun.gel_src, IP46_TYPE_ANY, + format_ip46_address, &gel->tun.gel_dst, IP46_TYPE_ANY); + } + + return (s); +} - s = format (s, " itf:[%U]", format_gbp_itf, ge->ge_itf); +u8 * +format_gbp_endpoint (u8 * s, va_list * args) +{ + index_t gei = va_arg (*args, index_t); + gbp_endpoint_loc_t *gel; + gbp_endpoint_t *ge; + + ge = gbp_endpoint_get (gei); + + s = format (s, "[@%d] %U", gei, format_gbp_endpoint_key, &ge->ge_key); s = format (s, " last-time:[%f]", ge->ge_last_time); + vec_foreach (gel, ge->ge_locs) + { + s = format (s, "\n %U", format_gbp_endpoint_loc, gel); + } + s = format (s, "\n %U", format_gbp_endpoint_fwd, &ge->ge_fwd); + return s; } @@ -801,8 +1258,8 @@ gbp_endpoint_show_one (index_t gei, void *ctx) return (WALK_CONTINUE); } -static void -gbp_endpoint_walk_ip_itf (const clib_bihash_kv_24_8_t * kvp, void *arg) +static int +gbp_endpoint_walk_ip_itf (clib_bihash_kv_24_8_t * kvp, void *arg) { ip46_address_t ip; vlib_main_t *vm; @@ -816,10 +1273,11 @@ gbp_endpoint_walk_ip_itf (const clib_bihash_kv_24_8_t * kvp, void *arg) format_ip46_address, &ip, IP46_TYPE_ANY, format_vnet_sw_if_index_name, vnet_get_main (), sw_if_index, kvp->value); + return (BIHASH_WALK_CONTINUE); } -static void -gbp_endpoint_walk_mac_itf (const clib_bihash_kv_16_8_t * kvp, void *arg) +static int +gbp_endpoint_walk_mac_itf (clib_bihash_kv_16_8_t * kvp, void *arg) { mac_address_t mac; vlib_main_t *vm; @@ -833,6 +1291,7 @@ gbp_endpoint_walk_mac_itf (const clib_bihash_kv_16_8_t * kvp, void *arg) format_mac_address_t, &mac, format_vnet_sw_if_index_name, vnet_get_main (), sw_if_index, kvp->value); + return (BIHASH_WALK_CONTINUE); } static clib_error_t * @@ -893,16 +1352,22 @@ VLIB_CLI_COMMAND (gbp_endpoint_show_node, static) = { static void gbp_endpoint_check (index_t gei, f64 start_time) { + gbp_endpoint_group_t *gg; + gbp_endpoint_loc_t *gel; gbp_endpoint_t *ge; ge = gbp_endpoint_get (gei); + gel = gbp_endpoint_loc_find (ge, GBP_ENDPOINT_SRC_DP); - GBP_ENDPOINT_DBG ("scan at:%f -> %U", start_time, format_gbp_endpoint, gei); - - if ((ge->ge_flags & GBP_ENDPOINT_FLAG_LEARNT) && - ((start_time - ge->ge_last_time) > GBP_ENDPOINT_INACTIVE_TIME)) + if (NULL != gel) { - gbp_endpoint_delete (gei); + gg = gbp_endpoint_group_get (gel->gel_epg); + + if ((start_time - ge->ge_last_time) > + gg->gg_retention.remote_ep_timeout) + { + gbp_endpoint_unlock (GBP_ENDPOINT_SRC_DP, gei); + } } } @@ -913,6 +1378,9 @@ gbp_endpoint_scan_l2 (vlib_main_t * vm) f64 last_start, start_time, delta_t; int i, j, k; + if (!gte_table->instantiated) + return; + delta_t = 0; last_start = start_time = vlib_time_now (vm); @@ -965,6 +1433,9 @@ gbp_endpoint_scan_l3 (vlib_main_t * vm) f64 last_start, start_time, delta_t; int i, j, k; + if (!gte_table->instantiated) + return; + delta_t = 0; last_start = start_time = vlib_time_now (vm); @@ -1017,24 +1488,77 @@ gbp_endpoint_scan (vlib_main_t * vm) gbp_endpoint_scan_l3 (vm); } -void -gbp_learn_set_inactive_threshold (u32 threshold) +static fib_node_t * +gbp_endpoint_get_node (fib_node_index_t index) { - GBP_ENDPOINT_INACTIVE_TIME = threshold; + gbp_endpoint_t *ge; + + ge = gbp_endpoint_get (index); + + return (&ge->ge_node); } -f64 -gbp_endpoint_scan_threshold (void) +static gbp_endpoint_t * +gbp_endpoint_from_fib_node (fib_node_t * node) { - return (GBP_ENDPOINT_INACTIVE_TIME); + ASSERT (gbp_endpoint_fib_type == node->fn_type); + return ((gbp_endpoint_t *) node); } -#define GBP_EP_HASH_NUM_BUCKETS (2 * 1024) -#define GBP_EP_HASH_MEMORY_SIZE (1 << 20) +static void +gbp_endpoint_last_lock_gone (fib_node_t * node) +{ + const gbp_bridge_domain_t *gbd; + const gbp_route_domain_t *grd; + const fib_prefix_t *pfx; + gbp_endpoint_t *ge; + + ge = gbp_endpoint_from_fib_node (node); + + ASSERT (0 == vec_len (ge->ge_locs)); + + gbd = gbp_bridge_domain_get (ge->ge_key.gek_gbd); + + /* + * we have removed the last source. this EP is toast + */ + if (INDEX_INVALID != ge->ge_key.gek_gbd) + { + gbp_endpoint_del_mac (&ge->ge_key.gek_mac, gbd->gb_bd_index); + } + vec_foreach (pfx, ge->ge_key.gek_ips) + { + grd = gbp_route_domain_get (ge->ge_key.gek_grd); + gbp_endpoint_del_ip (&pfx->fp_addr, grd->grd_fib_index[pfx->fp_proto]); + } + pool_put (gbp_endpoint_pool, ge); +} + +static fib_node_back_walk_rc_t +gbp_endpoint_back_walk_notify (fib_node_t * node, + fib_node_back_walk_ctx_t * ctx) +{ + ASSERT (0); + + return (FIB_NODE_BACK_WALK_CONTINUE); +} + +/* + * The FIB path's graph node virtual function table + */ +static const fib_node_vft_t gbp_endpoint_vft = { + .fnv_get = gbp_endpoint_get_node, + .fnv_last_lock = gbp_endpoint_last_lock_gone, + .fnv_back_walk = gbp_endpoint_back_walk_notify, + // .fnv_mem_show = fib_path_memory_show, +}; static clib_error_t * gbp_endpoint_init (vlib_main_t * vm) { +#define GBP_EP_HASH_NUM_BUCKETS (2 * 1024) +#define GBP_EP_HASH_MEMORY_SIZE (1 << 20) + clib_bihash_init_24_8 (&gbp_ep_db.ged_by_ip_rd, "GBP Endpoints - IP/RD", GBP_EP_HASH_NUM_BUCKETS, GBP_EP_HASH_MEMORY_SIZE); @@ -1044,6 +1568,13 @@ gbp_endpoint_init (vlib_main_t * vm) GBP_EP_HASH_NUM_BUCKETS, GBP_EP_HASH_MEMORY_SIZE); gbp_ep_logger = vlib_log_register_class ("gbp", "ep"); + gbp_endpoint_fib_type = fib_node_register_new_type (&gbp_endpoint_vft); + gbp_fib_source_hi = fib_source_allocate ("gbp-endpoint-hi", + FIB_SOURCE_PRIORITY_HI, + FIB_SOURCE_BH_SIMPLE); + gbp_fib_source_low = fib_source_allocate ("gbp-endpoint-low", + FIB_SOURCE_PRIORITY_LOW, + FIB_SOURCE_BH_SIMPLE); return (NULL); }