From cc54cfee3a67aa0192c62736cd567b562bb5597b Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Thu, 31 Aug 2017 20:36:14 -0300 Subject: zebra: remove refcnt from the route_entry structure This reference counter was introduced in 2001, apparently to solve a problem with connected routes being added/removed multiple times. The RIB code changed a lot since then, and giving the current callers of rib_add() and rib_delete() it's safe to assume that we don't need this anymore. Signed-off-by: Renato Westphal --- zebra/zebra_rib.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) (limited to 'zebra/zebra_rib.c') diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c index bcf21783ae..c9e770e204 100644 --- a/zebra/zebra_rib.c +++ b/zebra/zebra_rib.c @@ -2061,10 +2061,9 @@ void _route_entry_dump(const char *func, union prefixconstptr pp, is_srcdst ? prefix2str(src_pp, srcaddr, sizeof(srcaddr)) : "", re->vrf_id); - zlog_debug( - "%s: refcnt == %lu, uptime == %lu, type == %u, instance == %d, table == %d", - func, re->refcnt, (unsigned long)re->uptime, re->type, - re->instance, re->table); + zlog_debug("%s: uptime == %lu, type == %u, instance == %d, table == %d", + func, (unsigned long)re->uptime, re->type, re->instance, + re->table); zlog_debug( "%s: metric == %u, mtu == %u, distance == %u, flags == %u, status == %u", func, re->metric, re->mtu, re->distance, re->flags, re->status); @@ -2335,12 +2334,6 @@ void rib_delete(afi_t afi, safi_t safi, vrf_id_t vrf_id, int type, && rtnh->type == NEXTHOP_TYPE_IFINDEX && nh) { if (rtnh->ifindex != nh->ifindex) continue; - if (re->refcnt) { - re->refcnt--; - route_unlock_node(rn); - route_unlock_node(rn); - return; - } same = re; break; } @@ -2480,7 +2473,6 @@ int rib_add(afi_t afi, safi_t safi, vrf_id_t vrf_id, int type, u_short instance, && rtnh->type == NEXTHOP_TYPE_IFINDEX && rtnh->ifindex == nh->ifindex && !CHECK_FLAG(re->status, ROUTE_ENTRY_REMOVED)) { - re->refcnt++; return 0; } } -- cgit v1.2.3 From a3d18ce6b0810ad91e3d99bcb86e56cb6d6903a0 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Thu, 31 Aug 2017 17:28:05 -0300 Subject: zebra: fix detection of duplicate system routes Fixes the following bugs: 1) % ip -6 route add 5000::/64 via 3000::2 % ip -6 route replace 5000::/64 via 3000::2 % ip -6 route replace 5000::/64 via 3000::2 % ip -6 route replace 5000::/64 via 3000::2 % ip -6 route replace 5000::/64 via 3000::2 % % vtysh -c "show ipv6 route" [snip] K * 5000::/64 [0/1024] via 3000::2, rt1-eth0 K * 5000::/64 [0/1024] via 3000::2, rt1-eth0 K * 5000::/64 [0/1024] via 3000::2, rt1-eth0 K * 5000::/64 [0/1024] via 3000::2, rt1-eth0 K>* 5000::/64 [0/1024] via 3000::2, rt1-eth0 2) % ip -6 route add 7000::/64 via 3000::2 % ip -6 route replace 7000::/64 via 3000::3 % ip -6 ro | grep 7000 7000::/64 via 3000::3 dev rt1-eth0 metric 1024 pref medium % % vtysh -c "show ipv6 route" [snip] K * 7000::/64 [0/1024] via 3000::3, rt1-eth0 K>* 7000::/64 [0/1024] via 3000::2, rt1-eth0 NOTE: the check for ROUTE_ENTRY_REMOVED was redundant as it was already performed at the beginning of the loop. Signed-off-by: Renato Westphal --- zebra/zebra_rib.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'zebra/zebra_rib.c') diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c index c9e770e204..59b693435d 100644 --- a/zebra/zebra_rib.c +++ b/zebra/zebra_rib.c @@ -2469,12 +2469,11 @@ int rib_add(afi_t afi, safi_t safi, vrf_id_t vrf_id, int type, u_short instance, break; } /* Duplicate system route comes in. */ - else if ((rtnh = re->nexthop) - && rtnh->type == NEXTHOP_TYPE_IFINDEX - && rtnh->ifindex == nh->ifindex - && !CHECK_FLAG(re->status, ROUTE_ENTRY_REMOVED)) { + rtnh = re->nexthop; + if (nexthop_same_no_recurse(rtnh, nh)) return 0; - } + else + same = re; } /* Allocate new re structure. */ -- cgit v1.2.3 From 5f20552d51647a7ab672b9e7dbdf7de757c9fb29 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Fri, 1 Sep 2017 11:44:22 -0300 Subject: zebra: add an exception for link-local connected routes Link-local routes are unique in the sense that they all have the same prefix but have different nexthops (local interfaces). Add an exception in rib_add() to allows us to keep track of all of them. Signed-off-by: Renato Westphal --- zebra/zebra_rib.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'zebra/zebra_rib.c') diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c index 59b693435d..deb434bd35 100644 --- a/zebra/zebra_rib.c +++ b/zebra/zebra_rib.c @@ -2472,7 +2472,12 @@ int rib_add(afi_t afi, safi_t safi, vrf_id_t vrf_id, int type, u_short instance, rtnh = re->nexthop; if (nexthop_same_no_recurse(rtnh, nh)) return 0; - else + /* + * Nexthop is different. Remove the old route unless it's + * a link-local route. + */ + else if (afi != AFI_IP6 + || !IN6_IS_ADDR_LINKLOCAL(&p->u.prefix6)) same = re; } -- cgit v1.2.3