From cc54cfee3a67aa0192c62736cd567b562bb5597b Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Thu, 31 Aug 2017 20:36:14 -0300 Subject: [PATCH 1/4] 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/rib.h | 3 --- zebra/zebra_rib.c | 14 +++----------- zebra/zebra_vty.c | 2 -- 3 files changed, 3 insertions(+), 16 deletions(-) diff --git a/zebra/rib.h b/zebra/rib.h index 9b1ce23b08..4cc69377d8 100644 --- a/zebra/rib.h +++ b/zebra/rib.h @@ -45,9 +45,6 @@ struct route_entry { /* Nexthop structure */ struct nexthop *nexthop; - /* Refrence count. */ - unsigned long refcnt; - /* Tag */ route_tag_t tag; 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; } } diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index 98ce985344..95ba19b1f6 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -402,8 +402,6 @@ static void vty_show_ip_route_detail(struct vty *vty, struct route_node *rn, } if (CHECK_FLAG(re->flags, ZEBRA_FLAG_SELECTED)) vty_out(vty, ", best"); - if (re->refcnt) - vty_out(vty, ", refcnt %ld", re->refcnt); vty_out(vty, "\n"); if (re->type == ZEBRA_ROUTE_RIP || re->type == ZEBRA_ROUTE_OSPF From a3d18ce6b0810ad91e3d99bcb86e56cb6d6903a0 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Thu, 31 Aug 2017 17:28:05 -0300 Subject: [PATCH 2/4] 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(-) 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. */ From 8ba5bd58aa7bb8de6c18dd4ebddecf142ae4012e Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Thu, 31 Aug 2017 21:13:23 -0300 Subject: [PATCH 3/4] zebra: allow blackhole routes from the kernel to be deleted Fixes the following bug: % ip -6 route add unreachable 4000::/64 % ip -6 route del unreachable 4000::/64 % vtysh -c "show ipv6 route" [snip] K>* 4000::/64 [0/1024] unreachable (ICMP unreachable) Signed-off-by: Renato Westphal --- zebra/rt_netlink.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/zebra/rt_netlink.c b/zebra/rt_netlink.c index c58a7aa2fa..f05025e630 100644 --- a/zebra/rt_netlink.c +++ b/zebra/rt_netlink.c @@ -491,17 +491,26 @@ static int netlink_route_change_read_unicast(struct sockaddr_nl *snl, size_t sz = (afi == AFI_IP) ? 4 : 16; memset(&nh, 0, sizeof(nh)); - if (index && !gate) - nh.type = NEXTHOP_TYPE_IFINDEX; - else if (index && gate) - nh.type = (afi == AFI_IP) - ? NEXTHOP_TYPE_IPV4_IFINDEX - : NEXTHOP_TYPE_IPV6_IFINDEX; - else if (!index && gate) - nh.type = (afi == AFI_IP) ? NEXTHOP_TYPE_IPV4 + if (bh_type == BLACKHOLE_UNSPEC) { + if (index && !gate) + nh.type = NEXTHOP_TYPE_IFINDEX; + else if (index && gate) + nh.type = + (afi == AFI_IP) + ? NEXTHOP_TYPE_IPV4_IFINDEX + : NEXTHOP_TYPE_IPV6_IFINDEX; + else if (!index && gate) + nh.type = (afi == AFI_IP) + ? NEXTHOP_TYPE_IPV4 : NEXTHOP_TYPE_IPV6; - else + else { + nh.type = NEXTHOP_TYPE_BLACKHOLE; + nh.bh_type = BLACKHOLE_UNSPEC; + } + } else { nh.type = NEXTHOP_TYPE_BLACKHOLE; + nh.bh_type = bh_type; + } nh.ifindex = index; if (gate) memcpy(&nh.gate, gate, sz); From 5f20552d51647a7ab672b9e7dbdf7de757c9fb29 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Fri, 1 Sep 2017 11:44:22 -0300 Subject: [PATCH 4/4] 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(-) 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; }