Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 21 Mar 2001 13:36:11 +0200
From:      Ruslan Ermilov <ru@FreeBSD.org>
To:        Garrett Wollman <wollman@FreeBSD.org>
Cc:        net@FreeBSD.org
Subject:   Indirect routes with indirect gateways, bugfix
Message-ID:  <20010321133611.A62997@sunbay.com>

next in thread | raw e-mail | index | archive | help

--GvXjxJ+pjyke8COw
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Hi!

The routing code (bogusly?) allows to add an indirect route with
also indirect gateway.  This results in some nasty bugs:

: Script started on Wed Mar 21 13:17:47 2001
: 
: freebsd# netstat -rn
: Routing tables
: 
: Internet:
: Destination        Gateway            Flags     Refs     Use     Netif Expire
: 127.0.0.1          127.0.0.1          UH          0        0      lo0
: 192.168.1          link#1             UC          0        0      rl0 =>
: 
: freebsd# route add -net 10 1.2.3.4
: route: writing to routing socket: Network is unreachable
: add net 10: gateway 1.2.3.4: Network is unreachable
: 
: freebsd# route add default 192.168.1.1
: add net default: gateway 192.168.1.1
: 
: freebsd# route add -net 10 1.2.3.4
: add net 10: gateway 1.2.3.4
: 
: freebsd# ping -c1 10.0.0.1
: PING 10.0.0.1 (10.0.0.1): 56 data bytes
: 
: --- 10.0.0.1 ping statistics ---
: 1 packets transmitted, 0 packets received, 100% packet loss
: 
: freebsd# dmesg | tail -2
: arplookup 1.2.3.4 failed: host is not on local network
: arpresolve: can't allocate llinfo for 1.2.3.4rt
: freebsd# 
: 
: Script done on Wed Mar 21 13:19:00 2001

I have searched the CSRG SCCS logs, and found that the relevant code
was added in route.c, version 7.22 (well, 7.22 is actually a part of
7.23 that went into Net/2 release).  I have marked the relevant text
from the commit log with circumflexes:

CSRG> D 7.23  91/06/27 18:52:33 sklower       69 68   00059/00029/00452
CSRG> mostly changes to merge arp and routing tables; save space by
CSRG> separately allocated dst and gateway sockaddrs from rest of rtentry;
CSRG> also have routing layer look up route to gateway and cache it when
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
CSRG> installing RTF_GATEWAY type routes.
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
CSRG> 
CSRG> D 7.22  91/06/27 18:48:09 sklower       68 66   00016/00002/00465
CSRG> fixes from following version for net2 release
CSRG> 
CSRG> SCCS/s.route.c: 7.21 vs. 7.22
CSRG> --- /tmp/get.860.7.21	Mon Mar 19 18:46:00 2001
CSRG> +++ /tmp/get.860.7.22	Mon Mar 19 18:46:00 2001
CSRG> @@ -1,5 +1,5 @@
CSRG>  /*
CSRG> - * Copyright (c) 1980, 1986 Regents of the University of California.
CSRG> + * Copyright (c) 1980, 1986, 1991 Regents of the University of California.
CSRG>   * All rights reserved.
CSRG>   *
CSRG>   * %sccs.include.redist.c%
CSRG> @@ -275,7 +275,7 @@
CSRG>  int	flags;
CSRG>  struct sockaddr	*dst, *gateway;
CSRG>  {
CSRG> -	struct ifaddr *ifa;
CSRG> +	register struct ifaddr *ifa;
CSRG>  	if ((flags & RTF_GATEWAY) == 0) {
CSRG>  		/*
CSRG>  		 * If we are adding a route to an interface,
CSRG> @@ -299,6 +299,20 @@
CSRG>  	}
CSRG>  	if (ifa == 0)
CSRG>  		ifa = ifa_ifwithnet(gateway);
CSRG> +	if (ifa == 0) {
CSRG> +		struct rtentry *rt = rtalloc1(dst, 0);
CSRG> +		if (rt == 0)
CSRG> +			return (0);
CSRG> +		rt->rt_refcnt--;
CSRG> +		if ((ifa = rt->rt_ifa) == 0)
CSRG> +			return (0);
CSRG> +	}
CSRG> +	if (ifa->ifa_addr->sa_family != dst->sa_family) {
CSRG> +		struct ifaddr *oifa = ifa, *ifaof_ifpforaddr();
CSRG> +		ifa = ifaof_ifpforaddr(dst, ifa->ifa_ifp);
CSRG> +		if (ifa == 0)
CSRG> +			ifa = oifa;
CSRG> +	}
CSRG>  	return (ifa);
CSRG>  }


Unless someone has a good motivation for not doing this, I am going
to commit the attached patch that disallows indirect routes with
indirect gateways.
 

Cheers,
-- 
Ruslan Ermilov		Oracle Developer/DBA,
ru@sunbay.com		Sunbay Software AG,
ru@FreeBSD.org		FreeBSD committer,
+380.652.512.251	Simferopol, Ukraine

http://www.FreeBSD.org	The Power To Serve
http://www.oracle.com	Enabling The Information Age

--GvXjxJ+pjyke8COw
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=p

Index: route.c
===================================================================
RCS file: /home/ncvs/src/sys/net/route.c,v
retrieving revision 1.61
diff -u -p -7 -r1.61 route.c
--- route.c	2001/03/15 14:52:11	1.61
+++ route.c	2001/03/19 16:45:00
@@ -420,28 +420,30 @@ ifa_ifwithroute(flags, dst, gateway)
 		 * or host, the gateway may still be on the
 		 * other end of a pt to pt link.
 		 */
 		ifa = ifa_ifwithdstaddr(gateway);
 	}
 	if (ifa == 0)
 		ifa = ifa_ifwithnet(gateway);
+#if 0
 	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);
 	}
 	if (ifa->ifa_addr->sa_family != dst->sa_family) {
 		struct ifaddr *oifa = ifa;
 		ifa = ifaof_ifpforaddr(dst, ifa->ifa_ifp);
 		if (ifa == 0)
 			ifa = oifa;
 	}
+#endif
 	return (ifa);
 }
 
 #define ROUNDUP(a) (a>0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
 
 static int rt_fixdelete __P((struct radix_node *, void *));
 static int rt_fixchange __P((struct radix_node *, void *));

--GvXjxJ+pjyke8COw--

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-net" in the body of the message




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