]> git.puffer.fish Git - mirror/frr.git/commitdiff
nhrpd: replace nhrp route nexthop with onlink route when prefix=nh 8047/head
authorPhilippe Guibert <philippe.guibert@6wind.com>
Thu, 30 Jul 2020 16:16:16 +0000 (18:16 +0200)
committerPhilippe Guibert <philippe.guibert@6wind.com>
Tue, 9 Feb 2021 20:45:36 +0000 (21:45 +0100)
There are cases where nhrp wants to create a nhrp route to gre interface
with the nexthop which is the same the prefix. This is the case with
ipv6:

ipv6 route a:ff::ff:4/128 via a:ff::ff:4:/128 dev gre1

This route entry is false from zebra point of view, and to avoid that,
the nexthop is ignored in nhrp only if the prefix equals the nexthop.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
nhrpd/nhrp_route.c

index bbb2b0d6227f9cc2c6b5b8d5793c6c18409f701b..3ecc441124a91173033e7a99e3372568e0d57670 100644 (file)
@@ -99,6 +99,7 @@ void nhrp_route_announce(int add, enum nhrp_cache_type type,
 {
        struct zapi_route api;
        struct zapi_nexthop *api_nh;
+       union sockunion *nexthop_ref = (union sockunion *)nexthop;
 
        if (zclient->sock < 0)
                return;
@@ -134,8 +135,14 @@ void nhrp_route_announce(int add, enum nhrp_cache_type type,
 
        switch (api.prefix.family) {
        case AF_INET:
-               if (nexthop) {
-                       api_nh->gate.ipv4 = nexthop->sin.sin_addr;
+               if (api.prefix.prefixlen == IPV4_MAX_BITLEN &&
+                   nexthop_ref &&
+                   memcmp(&nexthop_ref->sin.sin_addr, &api.prefix.u.prefix4,
+                          sizeof(struct in_addr)) == 0) {
+                       nexthop_ref = NULL;
+               }
+               if (nexthop_ref) {
+                       api_nh->gate.ipv4 = nexthop_ref->sin.sin_addr;
                        api_nh->type = NEXTHOP_TYPE_IPV4;
                }
                if (ifp) {
@@ -147,8 +154,14 @@ void nhrp_route_announce(int add, enum nhrp_cache_type type,
                }
                break;
        case AF_INET6:
-               if (nexthop) {
-                       api_nh->gate.ipv6 = nexthop->sin6.sin6_addr;
+               if (api.prefix.prefixlen == IPV6_MAX_BITLEN &&
+                   nexthop_ref &&
+                   memcmp(&nexthop_ref->sin6.sin6_addr, &api.prefix.u.prefix6,
+                          sizeof(struct in6_addr)) == 0) {
+                       nexthop_ref = NULL;
+               }
+               if (nexthop_ref) {
+                       api_nh->gate.ipv6 = nexthop_ref->sin6.sin6_addr;
                        api_nh->type = NEXTHOP_TYPE_IPV6;
                }
                if (ifp) {
@@ -172,9 +185,10 @@ void nhrp_route_announce(int add, enum nhrp_cache_type type,
                zlog_debug(
                        "Zebra send: route %s %s nexthop %s metric %u count %d dev %s",
                        add ? "add" : "del", buf[0],
-                       nexthop ? inet_ntop(api.prefix.family, &api_nh->gate,
-                                           buf[1], sizeof(buf[1]))
-                               : "<onlink>",
+                       nexthop_ref ? inet_ntop(api.prefix.family,
+                                               &api_nh->gate,
+                                               buf[1], sizeof(buf[1]))
+                       : "<onlink>",
                        api.metric, api.nexthop_num, ifp ? ifp->name : "none");
        }