From owner-freebsd-net@FreeBSD.ORG Mon Sep 17 09:45:48 2007 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 5668A16A41A for ; Mon, 17 Sep 2007 09:45:48 +0000 (UTC) (envelope-from tom@tomjudge.com) Received: from s200aog14.obsmtp.com (s200aog14.obsmtp.com [207.126.144.128]) by mx1.freebsd.org (Postfix) with SMTP id A3D8413C457 for ; Mon, 17 Sep 2007 09:45:46 +0000 (UTC) (envelope-from tom@tomjudge.com) Received: from source ([217.206.187.80]) by eu1sys200aob014.postini.com ([207.126.147.11]) with SMTP; Mon, 17 Sep 2007 09:45:45 UTC Received: from [10.0.0.89] (bill.mintel.co.uk [10.0.0.89]) by rodney.mintel.co.uk (Postfix) with ESMTP id B4BD618141F; Mon, 17 Sep 2007 10:45:44 +0100 (BST) Message-ID: <46EE4CC8.4000906@tomjudge.com> Date: Mon, 17 Sep 2007 10:45:44 +0100 From: Tom Judge User-Agent: Thunderbird 1.5.0.12 (X11/20070604) MIME-Version: 1.0 To: Giorgos Keramidas References: <46E11515.8090007@tomjudge.com> <46E174DB.8070004@FreeBSD.org> <20070907185757.GA25624@kobe.laptop> <262949390709091803s507265e6mf3929c4dd26ecc56@mail.gmail.com> <20070910110528.GB2476@kobe.laptop> <20070910115636.GA8326@kobe.laptop> In-Reply-To: <20070910115636.GA8326@kobe.laptop> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: freebsd-net@freebsd.org, Nuno Antunes , "Bruce M. Simpson" Subject: Re: Strange behaviour of route command X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 17 Sep 2007 09:45:48 -0000 Giorgos Keramidas wrote: > On 2007-09-10 14:05, Giorgos Keramidas wrote: >> On 2007-09-10 02:03, Nuno Antunes wrote: >>>>> Tom Judge wrote: >>>>>> Hi, >>>>>> While making some changes to the routing table on one of our routers >>>>>> today I noticed that "route add" was showing some strange >>>>>> behaviour. When adding a route for 128/8 to the table rather than >>>>>> adding 128.0.0.0/8 it would add 0.0.0.0/8, however adding 10/9 works >>>>>> correctly. >>>>>> >>>>>> Is this a bug in route or the routing table? >>> Hi, >>> Can you take a look at this patch, please? >>> >>> http://leaf.dragonflybsd.org/mailarchive/submit/2007-09/msg00000.html >> Fantastic, thanks for the pointer! :-) >> >> Skimming fast through the diff it seems to be ok. It doesn't apply >> cleanly over HEAD so some merging was required to get this version >> instead: >> >> %%% >> diff -r 3624c4072e63 sbin/route/route.c >> --- a/sbin/route/route.c Fri Sep 07 09:19:22 2007 +0000 >> +++ b/sbin/route/route.c Mon Sep 10 14:02:01 2007 +0300 >> @@ -799,18 +799,19 @@ inet_makenetandmask(net, sin, bits) >> rtm_addrs |= RTA_NETMASK; >> if (net == 0) >> mask = addr = 0; >> [snip] >> + else { >> + if (net <= 0xff) >> + addr = net << IN_CLASSA_NSHIFT; >> + else if (net < 0xffff) >> + addr = net << IN_CLASSB_NSHIFT; >> + else if (net < 0xffffff) >> + addr = net << IN_CLASSC_NSHIFT; > > ... which will fail for 0xffff and 0xffffff comparisons. I apologize > for not testing all the possible address lengths before emailing the > first patch. > > I should have used <= here, so an updated patch is: Is there any chance of getting this commited, or should I raise a PR about this? Tom > > %%% > diff -r 3624c4072e63 sbin/route/route.c > --- a/sbin/route/route.c Fri Sep 07 09:19:22 2007 +0000 > +++ b/sbin/route/route.c Mon Sep 10 14:55:16 2007 +0300 > @@ -799,18 +799,19 @@ inet_makenetandmask(net, sin, bits) > rtm_addrs |= RTA_NETMASK; > if (net == 0) > mask = addr = 0; > - else if (net < 128) { > - addr = net << IN_CLASSA_NSHIFT; > - mask = IN_CLASSA_NET; > - } else if (net < 65536) { > - addr = net << IN_CLASSB_NSHIFT; > - mask = IN_CLASSB_NET; > - } else if (net < 16777216L) { > - addr = net << IN_CLASSC_NSHIFT; > - mask = IN_CLASSC_NET; > - } else { > - addr = net; > - if ((addr & IN_CLASSA_HOST) == 0) > + else { > + if (net <= 0xff) > + addr = net << IN_CLASSA_NSHIFT; > + else if (net <= 0xffff) > + addr = net << IN_CLASSB_NSHIFT; > + else if (net <= 0xffffff) > + addr = net << IN_CLASSC_NSHIFT; > + else > + addr = net; > + > + if (bits) > + mask = 0xffffffff << (32 - bits); > + else if ((addr & IN_CLASSA_HOST) == 0) > mask = IN_CLASSA_NET; > else if ((addr & IN_CLASSB_HOST) == 0) > mask = IN_CLASSB_NET; > @@ -819,8 +820,6 @@ inet_makenetandmask(net, sin, bits) > else > mask = -1; > } > - if (bits) > - mask = 0xffffffff << (32 - bits); > sin->sin_addr.s_addr = htonl(addr); > sin = &so_mask.sin; > sin->sin_addr.s_addr = htonl(mask); > %%% > _______________________________________________ > freebsd-net@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-net > To unsubscribe, send any mail to "freebsd-net-unsubscribe@freebsd.org"