From owner-freebsd-hackers Thu Jun 8 1:27:20 2000 Delivered-To: freebsd-hackers@freebsd.org Received: from mail.carrel.org (darjeeling.carrel.org [216.173.212.202]) by hub.freebsd.org (Postfix) with ESMTP id 0F07D37BF40 for ; Thu, 8 Jun 2000 01:27:11 -0700 (PDT) (envelope-from cysgod@carrel.org) Received: from cysgod by mail.carrel.org with local (Exim 3.14 #1) id 12zxeX-00005X-00; Thu, 08 Jun 2000 01:27:01 -0700 Date: Thu, 8 Jun 2000 01:27:00 -0700 From: William Carrel To: freebsd-gnats-submit@Carrel.ORG, william.a@carrel.org, freebsd-hackers@freebsd.org Subject: Re: kern/16318: Fix for wrong interface when adding new routes Message-ID: <20000608012700.A319@Carrel.ORG> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2i X-PGP-Fingerprint: 2B8F 1F3F AF96 596B F089 8EB8 1FC5 D606 413E F58A X-PGP-URL: unavailable at the moment X-RSA-Fingerprint: 473C 5B19 CE55 2BC6 28BE 927C 97F6 DC25 X-RSA-URL: unavailable at the moment X-Superfluous-Header: quizshow Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG This problem still affects the FreeBSD kernel in 4.0 and 5.0. A patch file for 4.0-STABLE follows, I've tested this on 4.0-RELEASE and 4.0-STABLE (incl. SMP for what it's worth). There is no difference between route.c at HEAD(5.0-current) and RELENG_4(4.0-stable) so this patch should work effectively in both of the aforementioned. And it does still fix my routing troubles. --- route.c.orig Sat May 27 14:48:42 2000 +++ route.c Sat May 27 15:01:43 2000 @@ -400,6 +400,9 @@ struct sockaddr *dst, *gateway; { register struct ifaddr *ifa; + struct rtentry *rt; + + ifa = 0; if ((flags & RTF_GATEWAY) == 0) { /* * If we are adding a route to an interface, @@ -408,7 +411,6 @@ * as our clue to the interface. Otherwise * we can use the local address. */ - ifa = 0; if (flags & RTF_HOST) { ifa = ifa_ifwithdstaddr(dst); } @@ -425,18 +427,33 @@ if (ifa == 0) ifa = ifa_ifwithnet(gateway); if (ifa == 0) { - struct rtentry *rt = rtalloc1(dst, 0, 0UL); - if (rt == 0) - return (0); - rt->rt_refcnt--; - if ((ifa = rt->rt_ifa) == 0) - return (0); + rt = rtalloc1(dst, 0, 0UL); + if (rt) { + rt->rt_refcnt--; + if (rt->rt_ifa) + ifa = rt->rt_ifa; + } } - if (ifa->ifa_addr->sa_family != dst->sa_family) { + if ((ifa) && (ifa->ifa_addr->sa_family != dst->sa_family)) { struct ifaddr *oifa = ifa; ifa = ifaof_ifpforaddr(dst, ifa->ifa_ifp); if (ifa == 0) ifa = oifa; + } + /* + * If we are adding a gateway, it is quite + * possible that the routing table has a static + * entry in place for the gateway, that may + * not agree with the info from the interfaces. + * The routing table should carry more precedence + * than the interfaces in this matter. + * Must be careful not to stomp on new entries from + * rtinit, hence (ifa->ifa_addr !=gateway). + */ + if ((ifa == 0 || ifa->ifa_addr != gateway) && + (rt = rtalloc1(gateway,0,0UL))) { + rt->rt_refcnt--; + ifa = rt->rt_ifa; } return (ifa); } To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message