[quagga-dev 4585] [PATCH] use more intelligent IPv4 nexthop on IPv6 BGP peerings

David Lamparter lists at diac24.net
Fri Feb 23 15:39:34 GMT 2007


Hi,


the attached patch changes the nexthop that is sent for IPv4 routes
exchanged over an IPv6 BGP peering.

Previously, when an IPv4 route would be transmitted over an IPv6
peering, the bgp router-id would end up being used as nexthop value.
Instead, with this patch, the interface used is first being looked
upon, and if there are IPv4 addresses on it, the lowest one is used.
If there are no IPv4 addresses on the interface, it falls back to
the router-id.

It still is possible to override this default via a route-map and
set ip next-hop. This only changes the default to a (IMHO) more
sensible way.


Please consider applying,


David Lamparter

Attached: Patch against quagga CVS 2007-02-23

-------------- next part --------------
This patch fixes the nexthop used when transporting IPv4 routes over an
IPv6 BGP peering. Previously, the bgp router id was used; with this patch,
the lowest IP from the interface is used.

Patch by David Lamparter <equinox-quagga at diac24.net>, 2007-02-23

--- quagga/bgpd/bgp_zebra.c.orig	2006-11-30 17:36:57.000000000 +0100
+++ quagga/bgpd/bgp_zebra.c	2007-02-23 04:01:51.456015851 +0100
@@ -432,6 +432,28 @@
   return NULL;
 }
 
+static int
+if_get_ipv4 (struct interface *ifp, struct in_addr *addr)
+{
+  struct listnode *cnode;
+  struct connected *connected;
+  struct prefix *cp; 
+  int hit = 0;
+  
+  for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, connected))
+    {
+      cp = connected->address;
+	    
+      if (cp->family == AF_INET)
+	if (!hit || ntohl(cp->u.prefix4.s_addr) < ntohl(addr->s_addr))
+	  {
+	    memcpy (addr, &cp->u.prefix4, IPV4_MAX_BYTELEN);
+	    hit = 1;
+	  }
+    }
+  return hit;
+}
+
 #ifdef HAVE_IPV6
 struct interface *
 if_lookup_by_ipv6 (struct in6_addr *addr)
@@ -586,7 +608,8 @@
       struct interface *direct = NULL;
 
       /* IPv4 nexthop.  I don't care about it. */
-      if (peer->local_id.s_addr)
+      ret = if_get_ipv4 (ifp, &nexthop->v4);
+      if (!ret && peer->local_id.s_addr)
 	nexthop->v4 = peer->local_id;
 
       /* Global address*/


More information about the Quagga-dev mailing list