From: James Li <[email protected]>

When a routing protocol sends a NEXTHOP_TYPE_IPV4_IFINDEX
and the interface is unnumbered, treat the nexthop as ONLINK.

Additionally trust the passed route does not need to be
tested for correctness.

This patch originated from Denis Ovsienko <[email protected]>
https://github.com/Quagga-RE/quagga-RE/commit/b9c1e9ac3e261231d8f1f72e3942c9be775ff2de
  -> At this point in time it is mainly historical as that we've had
     to massage the patch multiple times to get it to work properly

Signed-off-by: James Li <[email protected]>
Signed-off-by: Dinesh Dutt <[email protected]>
Signed-off-by: Donald Sharp <[email protected]>
Reviewed-by: JR Rivers <[email protected]>
---
 zebra/connected.c | 16 ++++++++++++++++
 zebra/connected.h |  1 +
 zebra/zebra_rib.c | 27 +++++++++++++++++++++++++++
 3 files changed, 44 insertions(+)

diff --git a/zebra/connected.c b/zebra/connected.c
index 21a3b6f..e3ed7f7 100644
--- a/zebra/connected.c
+++ b/zebra/connected.c
@@ -472,4 +472,20 @@ connected_delete_ipv6 (struct interface *ifp, struct 
in6_addr *address,
 
   rib_update (ifp->vrf_id);
 }
+
+int
+connected_is_unnumbered (struct interface *ifp)
+{
+  struct connected *connected;
+  struct listnode *node;
+
+  for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, connected))
+    {
+      if (CHECK_FLAG (connected->conf, ZEBRA_IFC_REAL) &&
+         connected->address->family == AF_INET)
+       return CHECK_FLAG(connected->flags, ZEBRA_IFA_UNNUMBERED);
+    }
+  return 0;
+}
+
 #endif /* HAVE_IPV6 */
diff --git a/zebra/connected.h b/zebra/connected.h
index 9595ddb..c589bd6 100644
--- a/zebra/connected.h
+++ b/zebra/connected.h
@@ -52,4 +52,5 @@ extern void connected_down_ipv6 (struct interface *ifp, 
struct connected *);
 
 #endif /* HAVE_IPV6 */
 
+extern int connected_is_unnumbered (struct interface *);
 #endif /*_ZEBRA_CONNECTED_H */
diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c
index 084af38..ece9fe6 100644
--- a/zebra/zebra_rib.c
+++ b/zebra/zebra_rib.c
@@ -36,6 +36,7 @@
 #include "routemap.h"
 #include "vrf.h"
 
+#include "zebra/connected.h"
 #include "zebra/rib.h"
 #include "zebra/rt.h"
 #include "zebra/zserv.h"
@@ -246,6 +247,7 @@ nexthop_ipv4_ifindex_add (struct rib *rib, struct in_addr 
*ipv4,
                           struct in_addr *src, unsigned int ifindex)
 {
   struct nexthop *nexthop;
+  struct interface *ifp;
 
   nexthop = XCALLOC (MTYPE_NEXTHOP, sizeof (struct nexthop));
   nexthop->type = NEXTHOP_TYPE_IPV4_IFINDEX;
@@ -253,6 +255,11 @@ nexthop_ipv4_ifindex_add (struct rib *rib, struct in_addr 
*ipv4,
   if (src)
     nexthop->src.ipv4 = *src;
   nexthop->ifindex = ifindex;
+  ifp = if_lookup_by_index (nexthop->ifindex);
+  if (connected_is_unnumbered(ifp))
+    {
+      SET_FLAG(nexthop->flags, NEXTHOP_FLAG_ONLINK);
+    }
 
   nexthop_add (rib, nexthop);
 
@@ -352,6 +359,7 @@ nexthop_active_ipv4 (struct rib *rib, struct nexthop 
*nexthop, int set,
   int resolved;
   struct nexthop *newhop;
   struct nexthop *resolved_hop;
+  struct interface *ifp;
 
   if (nexthop->type == NEXTHOP_TYPE_IPV4)
     nexthop->ifindex = 0;
@@ -363,6 +371,25 @@ nexthop_active_ipv4 (struct rib *rib, struct nexthop 
*nexthop, int set,
       nexthop->resolved = NULL;
     }
 
+  /*
+   * Check to see if we should trust the passed in information
+   * for UNNUMBERED interfaces as that we won't find the GW
+   * address in the routing table.
+   */
+  if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_ONLINK))
+    {
+      ifp = if_lookup_by_index (nexthop->ifindex);
+      if (ifp && connected_is_unnumbered(ifp))
+       {
+         if (if_is_operative(ifp))
+           return 1;
+         else
+           return 0;
+       }
+      else
+       return 0;
+    }
+
   /* Make lookup prefix. */
   memset (&p, 0, sizeof (struct prefix_ipv4));
   p.family = AF_INET;
-- 
1.9.1


_______________________________________________
Quagga-dev mailing list
[email protected]
https://lists.quagga.net/mailman/listinfo/quagga-dev

Reply via email to