Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 8 Sep 2006 09:02:47 -0700 (PDT)
From:      Doug Ambrisko <ambrisko@ambrisko.com>
To:        Oleg Bulyzhin <oleg@freebsd.org>
Cc:        freebsd-net@freebsd.org
Subject:   Re: patch to not route on down interfaces
Message-ID:  <200609081602.k88G2lNZ002237@ambrisko.com>
In-Reply-To: <20060908090844.GB14414@lath.rinet.ru>

next in thread | previous in thread | raw e-mail | index | archive | help
Oleg Bulyzhin writes:
| On Thu, Sep 07, 2006 at 11:30:55AM -0700, Doug Ambrisko wrote:
| > Hi guys,
| > 
| > We "hack" a feature to have 2 NIC's configured with the same IP and
| > netmask.  We down one and up the other to bounce between then.  We
| > also set the MAC's to be the same.  This fixes a few routing problems
| > in which the route would be tied to the down interface and not the
| > up one :-(
| 
| I guess this one is wrong:
| > +		if (!ifp->if_flags & IFF_UP)
| 
| it would lead to ((!ifp->if_flags) & IFF_UP), whereas it should be:
| (!(ifp->if_flags & IFF_UP))

Fixed it.  It seems that with how things are different now versus
4.x we almost never hit the if.c part mostly just the in.c change.

Here is the new one:

--- ../src/sys/net/if.c	Tue Feb 14 19:37:15 2006
+++ ./sys/net/if.c	Tue Sep  5 12:21:46 2006
@@ -986,7 +986,9 @@ ifa_ifwithaddr(struct sockaddr *addr)
 	struct ifaddr *ifa;
 
 	IFNET_RLOCK();
-	TAILQ_FOREACH(ifp, &ifnet, if_link)
+	TAILQ_FOREACH(ifp, &ifnet, if_link) {
+		if (!(ifp->if_flags & IFF_UP))
+			continue;
 		TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
 			if (ifa->ifa_addr->sa_family != addr->sa_family)
 				continue;
@@ -999,6 +1001,7 @@ ifa_ifwithaddr(struct sockaddr *addr)
 			    sa_equal(ifa->ifa_broadaddr, addr))
 				goto done;
 		}
+	}
 	ifa = NULL;
 done:
 	IFNET_RUNLOCK();
@@ -1017,6 +1020,8 @@ ifa_ifwithdstaddr(struct sockaddr *addr)
 
 	IFNET_RLOCK();
 	TAILQ_FOREACH(ifp, &ifnet, if_link) {
+		if (!(ifp->if_flags & IFF_UP))
+			continue;
 		if ((ifp->if_flags & IFF_POINTOPOINT) == 0)
 			continue;
 		TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
@@ -1062,6 +1067,8 @@ ifa_ifwithnet(struct sockaddr *addr)
 	 */
 	IFNET_RLOCK();
 	TAILQ_FOREACH(ifp, &ifnet, if_link) {
+		if (!(ifp->if_flags & IFF_UP))
+			continue;
 		TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
 			char *cp, *cp2, *cp3;
 
--- ../src/sys/netinet/in.c	Tue Jan 31 08:11:37 2006
+++ ./sys/netinet/in.c	Tue Sep  5 16:09:00 2006
@@ -870,6 +871,8 @@ in_scrubprefix(target)
 	}
 
 	TAILQ_FOREACH(ia, &in_ifaddrhead, ia_link) {
+		if (ia->ia_ifp && !(ia->ia_ifp->if_flags & IFF_UP))
+			continue;
 		if (rtinitflags(ia))
 			p = ia->ia_dstaddr.sin_addr;
 		else {

Thanks,

Doug A.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200609081602.k88G2lNZ002237>