Browse Source

zebra: return route_node from rib_match_ipv4_safi

The multicast code needs to know the route_node in addition to the rib
entry in order to perform distance or prefix-length comparisons.  Add it
as optional "out" pointer parameter.

Cc: Everton Marques <everton.marques@gmail.com>
Cc: Balaji G <balajig81@gmail.com>
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
David Lamparter 5 years ago
parent
commit
24480d4260
3 changed files with 18 additions and 10 deletions
  1. 2 1
      zebra/rib.h
  2. 14 7
      zebra/zebra_rib.c
  3. 2 2
      zebra/zserv.c

+ 2 - 1
zebra/rib.h

@@ -418,7 +418,8 @@ extern int rib_delete_ipv4 (int type, int flags, struct prefix_ipv4 *p,
 		            struct in_addr *gate, unsigned int ifindex, 
 		            u_int32_t, safi_t safi);
 
-extern struct rib *rib_match_ipv4_safi (struct in_addr addr, safi_t safi, int skip_bgp);
+extern struct rib *rib_match_ipv4_safi (struct in_addr addr, safi_t safi,
+					int skip_bgp, struct route_node **rn_out);
 
 extern struct rib *rib_lookup_ipv4 (struct prefix_ipv4 *);
 

+ 14 - 7
zebra/zebra_rib.c

@@ -719,7 +719,8 @@ nexthop_active_ipv6 (struct rib *rib, struct nexthop *nexthop, int set,
 #endif /* HAVE_IPV6 */
 
 struct rib *
-rib_match_ipv4_safi (struct in_addr addr, safi_t safi, int skip_bgp)
+rib_match_ipv4_safi (struct in_addr addr, safi_t safi, int skip_bgp,
+		     struct route_node **rn_out)
 {
   struct route_table *table;
   struct route_node *rn;
@@ -759,16 +760,22 @@ rib_match_ipv4_safi (struct in_addr addr, safi_t safi, int skip_bgp)
 	}
       else
 	{
-	  if (match->type == ZEBRA_ROUTE_CONNECT)
-	    /* Directly point connected route. */
-	    return match;
-	  else
+	  if (match->type != ZEBRA_ROUTE_CONNECT)
 	    {
+	      int found = 0;
 	      for (ALL_NEXTHOPS_RO(match->nexthop, newhop, tnewhop, recursing))
 		if (CHECK_FLAG (newhop->flags, NEXTHOP_FLAG_FIB))
-		  return match;
-	      return NULL;
+		  {
+		    found = 1;
+		    break;
+		  }
+	      if (!found)
+		return NULL;
 	    }
+
+	  if (rn_out)
+	    *rn_out = rn;
+	  return match;
 	}
     }
   return NULL;

+ 2 - 2
zebra/zserv.c

@@ -540,7 +540,7 @@ zsend_ipv4_nexthop_lookup (struct zserv *client, struct in_addr addr)
   struct nexthop *nexthop;
 
   /* Lookup nexthop - eBGP excluded */
-  rib = rib_match_ipv4_safi (addr, SAFI_UNICAST, 1);
+  rib = rib_match_ipv4_safi (addr, SAFI_UNICAST, 1, NULL);
 
   /* Get output stream. */
   s = client->obuf;
@@ -615,7 +615,7 @@ zsend_ipv4_nexthop_lookup_mrib (struct zserv *client, struct in_addr addr)
   int skip_bgp = 0; /* bool */
 
   /* Lookup nexthop. */
-  rib = rib_match_ipv4_safi (addr, SAFI_MULTICAST, skip_bgp);
+  rib = rib_match_ipv4_safi (addr, SAFI_MULTICAST, skip_bgp, NULL);
 
   if (IS_ZEBRA_DEBUG_PACKET && IS_ZEBRA_DEBUG_RECV)
     zlog_debug("%s: %s mrib entry found.", __func__, rib ? "Matching" : "No matching");