/* Update the tunnel-ip hash */
bgp_tip_del(bgp, &vpn->originator_ip);
- bgp_tip_add(bgp, &originator_ip);
-
- /* filter routes as martian nexthop db has changed */
- bgp_filter_evpn_routes_upon_martian_nh_change(bgp);
+ if (bgp_tip_add(bgp, &originator_ip))
+ /* The originator_ip was not already present in the
+ * bgp martian next-hop table as a tunnel-ip, so we
+ * need to go back and filter routes matching the new
+ * martian next-hop.
+ */
+ bgp_filter_evpn_routes_upon_martian_nh_change(bgp);
/* Need to withdraw type-3 route as the originator IP is part
* of the key.
SET_FLAG(vpn->flags, VNI_FLAG_LIVE);
/* tunnel is now active, add tunnel-ip to db */
- bgp_tip_add(bgp, &originator_ip);
-
- /* filter routes as nexthop database has changed */
- bgp_filter_evpn_routes_upon_martian_nh_change(bgp);
+ if (bgp_tip_add(bgp, &originator_ip))
+ /* The originator_ip was not already present in the
+ * bgp martian next-hop table as a tunnel-ip, so we
+ * need to go back and filter routes matching the new
+ * martian next-hop.
+ */
+ bgp_filter_evpn_routes_upon_martian_nh_change(bgp);
/*
* Create EVPN type-3 route and schedule for processing.
bgp->tip_hash = NULL;
}
-void bgp_tip_add(struct bgp *bgp, struct in_addr *tip)
+/* Add/Update Tunnel-IP entry of bgp martian next-hop table.
+ *
+ * Returns true only if we add a _new_ TIP so the caller knows that an
+ * actionable change has occurred. If we find an existing TIP then we
+ * only need to update the refcnt, since the collection of known TIPs
+ * has not changed.
+ */
+bool bgp_tip_add(struct bgp *bgp, struct in_addr *tip)
{
struct tip_addr tmp;
struct tip_addr *addr;
+ bool tip_added = false;
tmp.addr = *tip;
- addr = hash_get(bgp->tip_hash, &tmp, bgp_tip_hash_alloc);
+ addr = hash_lookup(bgp->tip_hash, &tmp);
+ if (!addr) {
+ addr = hash_get(bgp->tip_hash, &tmp, bgp_tip_hash_alloc);
+ tip_added = true;
+ }
+
addr->refcnt++;
+
+ return tip_added;
}
void bgp_tip_del(struct bgp *bgp, struct in_addr *tip)
extern void bgp_scan_vty_init(void);
extern void bgp_address_init(struct bgp *bgp);
extern void bgp_address_destroy(struct bgp *bgp);
-extern void bgp_tip_add(struct bgp *bgp, struct in_addr *tip);
+extern bool bgp_tip_add(struct bgp *bgp, struct in_addr *tip);
extern void bgp_tip_del(struct bgp *bgp, struct in_addr *tip);
extern void bgp_tip_hash_init(struct bgp *bgp);
extern void bgp_tip_hash_destroy(struct bgp *bgp);