From owner-freebsd-arch@FreeBSD.ORG Wed Nov 17 22:02:56 2004 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id A1B5C16A4CE; Wed, 17 Nov 2004 22:02:56 +0000 (GMT) Received: from tigra.ip.net.ua (tigra.ip.net.ua [82.193.96.10]) by mx1.FreeBSD.org (Postfix) with ESMTP id D8BC843D46; Wed, 17 Nov 2004 22:02:55 +0000 (GMT) (envelope-from ru@ip.net.ua) Received: from localhost (rocky.ip.net.ua [82.193.96.2]) by tigra.ip.net.ua (8.12.11/8.12.11) with ESMTP id iAHM2mhK047963; Thu, 18 Nov 2004 00:02:48 +0200 (EET) (envelope-from ru@ip.net.ua) Received: from tigra.ip.net.ua ([82.193.96.10]) by localhost (rocky.ipnet [82.193.96.2]) (amavisd-new, port 10024) with LMTP id 83815-14; Thu, 18 Nov 2004 00:02:47 +0200 (EET) Received: from heffalump.ip.net.ua (heffalump.ip.net.ua [82.193.96.213]) by tigra.ip.net.ua (8.12.11/8.12.11) with ESMTP id iAHM2kFo047960 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 18 Nov 2004 00:02:47 +0200 (EET) (envelope-from ru@ip.net.ua) Received: (from ru@localhost) by heffalump.ip.net.ua (8.13.1/8.13.1) id iAHM2m7B081982; Thu, 18 Nov 2004 00:02:48 +0200 (EET) (envelope-from ru) Date: Thu, 18 Nov 2004 00:02:47 +0200 From: Ruslan Ermilov To: Vladimir Grebenschikov Message-ID: <20041117220247.GA60793@ip.net.ua> References: <200411112124.12616.max@love2party.net> <1100710232.47346.5.camel@localhost> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="VS++wcV0S1rZb1Fb" Content-Disposition: inline In-Reply-To: <1100710232.47346.5.camel@localhost> User-Agent: Mutt/1.5.6i X-Virus-Scanned: by amavisd-new at ip.net.ua cc: Max Laier cc: freebsd-arch@FreeBSD.org cc: freebsd-net@FreeBSD.org Subject: Re: in.c autoadding prefix route [PATCH] X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 17 Nov 2004 22:02:56 -0000 --VS++wcV0S1rZb1Fb Content-Type: text/plain; charset=koi8-r Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Nov 17, 2004 at 07:50:32PM +0300, Vladimir Grebenschikov wrote: > =F7 =DE=D4, 11/11/2004 =D7 21:24 +0100, Max Laier =D0=C9=DB=C5=D4:=20 > > All, > >=20 > > I know I have sent this a couple of times before, but never got anywher= e. This=20 > > time I am set to commit! > >=20 > > The attached patch (http://people.freebsd.org/~mlaier/in.c.patch) deriv= ed from=20 > > WIDE via OpenBSD in.c, rev 1.21 improves the handling of automatic pref= ix=20 > > routes. > >=20 > > Right now you can't have two legs into the same network. If you want to= , you=20 > > must give on of the interfaces a host address only (netmask /32). This = way it=20 > > is not possible to hand over the route if one of the interfaces is=20 > > "removed" (however this is done in the special case). > >=20 > > The patch allows to add more than on IPv4 address with the same prefix.= In the=20 > > case that there is a route already, we leave it alone and add the new a= ddress=20 > > without the IFA_ROUTE flag. When we remove an address later on, that ha= s a=20 > > route associated, we try to find an alternative address to use for the = route=20 > > and hand it over. > >=20 > > This is required for CARP, but should be helpful for other situations a= s well. > >=20 > > Any objections? >=20 > This change actually broke one simple thing: >=20 > # ifconfig lo0 alias 10.0.16.111/32 > # ping 10.0.16.111 > PING 10.0.16.111 (10.0.16.111): 56 data bytes > ping: sendto: No route to host > ^C > # >=20 > You should (anyway should) add routing of interface address itself to > loop-back interface, like it usually done in all other cases. >=20 > Please fix. >=20 This bug was borrowed from OpenBSD (they still have it). The problem is that in "struct in_ifaddr", initially ia_ifa.ifa_addr points to ia_addr - and - ia_ifa.ifa_dstaddr points to ia_dstaddr and the IFF_LOOPBACK code in in_ifinit() just resets the ia_ifa.ifa_dstaddr pointer to point to ia_ifa.ifa_addr. But new in_addprefix() code ignores this fact, and just uses INET fields directly, i.e., ia_dstaddr (which happens to be 0.0.0.0). Then all the havoc happens (it matches another interface address (ia_addr=3D127.0.0.1, ia_dstaddr=3D0) and refuses to install a host route. The fix is a one line change, and as I later found out, it also corresponds to NetBSD revision 1.83: http://www.freebsd.org/cgi/cvsweb.cgi/src/sys/netinet/in.c.diff?r1=3D1.82&r= 2=3D1.83&cvsroot=3Dnetbsd %%% Index: in.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /home/ncvs/src/sys/netinet/in.c,v retrieving revision 1.78 diff -u -p -r1.78 in.c --- in.c 12 Nov 2004 20:53:51 -0000 1.78 +++ in.c 17 Nov 2004 21:42:44 -0000 @@ -759,7 +759,7 @@ in_ifinit(ifp, ia, sin, scrub) ia->ia_netbroadcast.s_addr =3D htonl(ia->ia_net | ~ ia->ia_netmask); } else if (ifp->if_flags & IFF_LOOPBACK) { - ia->ia_ifa.ifa_dstaddr =3D ia->ia_ifa.ifa_addr; + ia->ia_dstaddr =3D ia->ia_addr; flags |=3D RTF_HOST; } else if (ifp->if_flags & IFF_POINTOPOINT) { if (ia->ia_dstaddr.sin_family !=3D AF_INET) %%% An alternative would be to fix in_addprefix() to pay attention to ia_ifa pointers, but as this bug shows, this is error prone. It's much easier to just initialize the ia_dstaddr as appropriate. =09 Cheers, --=20 Ruslan Ermilov ru@FreeBSD.org FreeBSD committer --VS++wcV0S1rZb1Fb Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.6 (FreeBSD) iD8DBQFBm8qHqRfpzJluFF4RAjApAJ9/D86FqpwPvb6oLRmyd41zjyWZQQCeKXuy A6+YwAicxvtMT+7Os1KcZvk= =I3CA -----END PGP SIGNATURE----- --VS++wcV0S1rZb1Fb--