From: vivek Date: Fri, 26 Feb 2016 19:13:34 +0000 (+0000) Subject: Zebra: Fix static NHT to work properly in a VRF X-Git-Tag: frr-2.0-rc1~1094 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=d82ae0dedc6b995309a7590ed3bb6a17970206a8;p=mirror%2Ffrr.git Zebra: Fix static NHT to work properly in a VRF Implement VRF support for static nexthop resolution (NHT). This is achieved by ensuring the correct VRF is passed as a parameter to the NHT functions and is stored in the registered nexthop data structure. Signed-off-by: Vivek Venkatraman Reviewed-by: Donald Sharp Reviewed-by: Don Slice Ticket: CM-9457 Reviewed By: CCR-4185 Testing Done: Manual verification --- diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c index 39b9d452ca..9679afe068 100644 --- a/zebra/zebra_rib.c +++ b/zebra/zebra_rib.c @@ -308,7 +308,7 @@ nexthop_active_ipv4 (struct rib *rib, struct nexthop *nexthop, int set, if (set) { UNSET_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE); - zebra_deregister_rnh_static_nexthops(nexthop->resolved, top); + zebra_deregister_rnh_static_nexthops(rib->vrf_id, nexthop->resolved, top); nexthops_free(nexthop->resolved); nexthop->resolved = NULL; } @@ -532,7 +532,7 @@ nexthop_active_ipv6 (struct rib *rib, struct nexthop *nexthop, int set, if (set) { UNSET_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE); - zebra_deregister_rnh_static_nexthops (nexthop->resolved, top); + zebra_deregister_rnh_static_nexthops (rib->vrf_id, nexthop->resolved, top); nexthops_free(nexthop->resolved); nexthop->resolved = NULL; } @@ -1964,7 +1964,7 @@ rib_unlink (struct route_node *rn, struct rib *rib) } /* free RIB and nexthops */ - zebra_deregister_rnh_static_nexthops (rib->nexthop, rn); + zebra_deregister_rnh_static_nexthops (rib->vrf_id, rib->nexthop, rn); nexthops_free(rib->nexthop); XFREE (MTYPE_RIB, rib); @@ -2560,7 +2560,7 @@ static_install_route (afi_t afi, safi_t safi, struct prefix *p, struct static_ro nh_p.family = AF_INET; nh_p.prefixlen = IPV4_MAX_BITLEN; nh_p.u.prefix4 = si->addr.ipv4; - zebra_register_rnh_static_nh(&nh_p, rn); + zebra_register_rnh_static_nh(si->vrf_id, &nh_p, rn); break; case STATIC_IFINDEX: rib_nexthop_ifindex_add (rib, si->ifindex); @@ -2573,7 +2573,7 @@ static_install_route (afi_t afi, safi_t safi, struct prefix *p, struct static_ro nh_p.family = AF_INET6; nh_p.prefixlen = IPV6_MAX_BITLEN; nh_p.u.prefix6 = si->addr.ipv6; - zebra_register_rnh_static_nh(&nh_p, rn); + zebra_register_rnh_static_nh(si->vrf_id, &nh_p, rn); break; case STATIC_IPV6_GATEWAY_IFINDEX: rib_nexthop_ipv6_ifindex_add (rib, &si->addr.ipv6, si->ifindex); @@ -2618,7 +2618,7 @@ static_install_route (afi_t afi, safi_t safi, struct prefix *p, struct static_ro nh_p.family = AF_INET; nh_p.prefixlen = IPV4_MAX_BITLEN; nh_p.u.prefix4 = si->addr.ipv4; - zebra_register_rnh_static_nh(&nh_p, rn); + zebra_register_rnh_static_nh(si->vrf_id, &nh_p, rn); break; case STATIC_IFINDEX: rib_nexthop_ifindex_add (rib, si->ifindex); @@ -2631,7 +2631,7 @@ static_install_route (afi_t afi, safi_t safi, struct prefix *p, struct static_ro nh_p.family = AF_INET6; nh_p.prefixlen = IPV6_MAX_BITLEN; nh_p.u.prefix6 = si->addr.ipv6; - zebra_register_rnh_static_nh(&nh_p, rn); + zebra_register_rnh_static_nh(si->vrf_id, &nh_p, rn); break; case STATIC_IPV6_GATEWAY_IFINDEX: rib_nexthop_ipv6_ifindex_add (rib, &si->addr.ipv6, si->ifindex); @@ -2788,7 +2788,7 @@ static_uninstall_route (afi_t afi, safi_t safi, struct prefix *p, struct static_ nh_p.u.prefix6 = nexthop->gate.ipv6; } rib_nexthop_delete (rib, nexthop); - zebra_deregister_rnh_static_nh(&nh_p, rn); + zebra_deregister_rnh_static_nh(si->vrf_id, &nh_p, rn); nexthop_free (nexthop); } /* Unlock node. */ diff --git a/zebra/zebra_rnh.c b/zebra/zebra_rnh.c index 74e63d9467..a10b31c2af 100644 --- a/zebra/zebra_rnh.c +++ b/zebra/zebra_rnh.c @@ -49,7 +49,7 @@ /* Default rtm_table for all clients */ extern struct zebra_t zebrad; -static void free_state(struct rib *rib, struct route_node *rn); +static void free_state(vrf_id_t vrf_id, struct rib *rib, struct route_node *rn); static void copy_state(struct rnh *rnh, struct rib *rib, struct route_node *rn); #define lookup_rnh_table(v, f) \ @@ -127,6 +127,7 @@ zebra_add_rnh (struct prefix *p, vrf_id_t vrfid, rnh_type_t type) { rnh = XCALLOC(MTYPE_RNH, sizeof(struct rnh)); rnh->client_list = list_new(); + rnh->vrf_id = vrfid; rnh->zebra_static_route_list = list_new(); route_lock_node (rn); rn->info = rnh; @@ -176,7 +177,7 @@ zebra_delete_rnh (struct rnh *rnh, rnh_type_t type) rnh->flags |= ZEBRA_NHT_DELETED; list_free(rnh->client_list); list_free(rnh->zebra_static_route_list); - free_state(rnh->state, rn); + free_state(rnh->vrf_id, rnh->state, rn); XFREE(MTYPE_RNH, rn->info); rn->info = NULL; route_unlock_node (rn); @@ -218,11 +219,12 @@ zebra_remove_rnh_client (struct rnh *rnh, struct zserv *client, rnh_type_t type) } void -zebra_register_rnh_static_nh(struct prefix *nh, struct route_node *static_rn) +zebra_register_rnh_static_nh(vrf_id_t vrf_id, struct prefix *nh, + struct route_node *static_rn) { struct rnh *rnh; - rnh = zebra_add_rnh(nh, 0, RNH_NEXTHOP_TYPE); + rnh = zebra_add_rnh(nh, vrf_id, RNH_NEXTHOP_TYPE); if (rnh && !listnode_lookup(rnh->zebra_static_route_list, static_rn)) { listnode_add(rnh->zebra_static_route_list, static_rn); @@ -230,11 +232,12 @@ zebra_register_rnh_static_nh(struct prefix *nh, struct route_node *static_rn) } void -zebra_deregister_rnh_static_nh(struct prefix *nh, struct route_node *static_rn) +zebra_deregister_rnh_static_nh(vrf_id_t vrf_id, struct prefix *nh, + struct route_node *static_rn) { struct rnh *rnh; - rnh = zebra_lookup_rnh(nh, 0, RNH_NEXTHOP_TYPE); + rnh = zebra_lookup_rnh(nh, vrf_id, RNH_NEXTHOP_TYPE); if (!rnh || (rnh->flags & ZEBRA_NHT_DELETED)) return; @@ -246,7 +249,8 @@ zebra_deregister_rnh_static_nh(struct prefix *nh, struct route_node *static_rn) } void -zebra_deregister_rnh_static_nexthops (struct nexthop *nexthop, struct route_node *rn) +zebra_deregister_rnh_static_nexthops (vrf_id_t vrf_id, struct nexthop *nexthop, + struct route_node *rn) { struct nexthop *nh; struct prefix nh_p; @@ -265,7 +269,7 @@ zebra_deregister_rnh_static_nexthops (struct nexthop *nexthop, struct route_node nh_p.prefixlen = IPV6_MAX_BITLEN; nh_p.u.prefix6 = nh->gate.ipv6; } - zebra_deregister_rnh_static_nh(&nh_p, rn); + zebra_deregister_rnh_static_nh(vrf_id, &nh_p, rn); } } @@ -788,14 +792,14 @@ zebra_cleanup_rnh_client (vrf_id_t vrfid, int family, struct zserv *client, * free_state - free up the rib structure associated with the rnh. */ static void -free_state (struct rib *rib, struct route_node *rn) +free_state (vrf_id_t vrf_id, struct rib *rib, struct route_node *rn) { if (!rib) return; /* free RIB and nexthops */ - zebra_deregister_rnh_static_nexthops (rib->nexthop, rn); + zebra_deregister_rnh_static_nexthops (vrf_id, rib->nexthop, rn); nexthops_free(rib->nexthop); XFREE (MTYPE_RIB, rib); } @@ -808,7 +812,7 @@ copy_state (struct rnh *rnh, struct rib *rib, struct route_node *rn) if (rnh->state) { - free_state(rnh->state, rn); + free_state(rnh->vrf_id, rnh->state, rn); rnh->state = NULL; } diff --git a/zebra/zebra_rnh.h b/zebra/zebra_rnh.h index b76651aa76..0732a4f927 100644 --- a/zebra/zebra_rnh.h +++ b/zebra/zebra_rnh.h @@ -35,6 +35,9 @@ struct rnh #define ZEBRA_NHT_DELETED 0x2 #define ZEBRA_NHT_EXACT_MATCH 0x4 + /* VRF identifier. */ + vrf_id_t vrf_id; + struct rib *state; struct prefix resolved_route; struct list *client_list; @@ -59,9 +62,10 @@ extern struct rnh *zebra_lookup_rnh(struct prefix *p, vrf_id_t vrfid, extern void zebra_delete_rnh(struct rnh *rnh, rnh_type_t type); extern void zebra_add_rnh_client(struct rnh *rnh, struct zserv *client, rnh_type_t type, vrf_id_t vrfid); -extern void zebra_register_rnh_static_nh(struct prefix *, struct route_node *); -extern void zebra_deregister_rnh_static_nexthops (struct nexthop *nexthop, struct route_node *rn); -extern void zebra_deregister_rnh_static_nh(struct prefix *, struct route_node *); +extern void zebra_register_rnh_static_nh(vrf_id_t, struct prefix *, struct route_node *); +extern void zebra_deregister_rnh_static_nexthops (vrf_id_t, struct nexthop *nexthop, + struct route_node *rn); +extern void zebra_deregister_rnh_static_nh(vrf_id_t, struct prefix *, struct route_node *); extern void zebra_remove_rnh_client(struct rnh *rnh, struct zserv *client, rnh_type_t type); extern void zebra_evaluate_rnh(vrf_id_t vrfid, int family, int force, rnh_type_t type, diff --git a/zebra/zebra_rnh_null.c b/zebra/zebra_rnh_null.c index f4a651c778..3ec8be027d 100644 --- a/zebra/zebra_rnh_null.c +++ b/zebra/zebra_rnh_null.c @@ -14,11 +14,12 @@ void zebra_print_rnh_table (vrf_id_t vrfid, int family, struct vty *vty, rnh_type_t type) {} -void zebra_register_rnh_static_nh(struct prefix *p, struct route_node *rn) +void zebra_register_rnh_static_nh(vrf_id_t vrfid, struct prefix *p, struct route_node *rn) {} -void zebra_deregister_rnh_static_nh(struct prefix *p, struct route_node *rn) +void zebra_deregister_rnh_static_nh(vrf_id_t vrfid, struct prefix *p, struct route_node *rn) {} -void zebra_deregister_rnh_static_nexthops (struct nexthop *nexthop, struct route_node *rn) +void zebra_deregister_rnh_static_nexthops (vrf_id_t vrfid, struct nexthop *nexthop, + struct route_node *rn) {}