Date: Mon, 17 Sep 2007 10:45:44 +0100 From: Tom Judge <tom@tomjudge.com> To: Giorgos Keramidas <keramida@freebsd.org> Cc: freebsd-net@freebsd.org, Nuno Antunes <nuno.antunes@gmail.com>, "Bruce M. Simpson" <bms@freebsd.org> Subject: Re: Strange behaviour of route command Message-ID: <46EE4CC8.4000906@tomjudge.com> In-Reply-To: <20070910115636.GA8326@kobe.laptop> 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>
next in thread | previous in thread | raw e-mail | index | archive | help
Giorgos Keramidas wrote: > On 2007-09-10 14:05, Giorgos Keramidas <keramida@freebsd.org> wrote: >> On 2007-09-10 02:03, Nuno Antunes <nuno.antunes@gmail.com> 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"
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?46EE4CC8.4000906>