Date: Mon, 10 Sep 2007 14:05:28 +0300 From: Giorgos Keramidas <keramida@FreeBSD.org> To: Nuno Antunes <nuno.antunes@gmail.com> Cc: Tom Judge <tom@tomjudge.com>, freebsd-net@FreeBSD.org, "Bruce M. Simpson" <bms@FreeBSD.org> Subject: Re: Strange behaviour of route command Message-ID: <20070910110528.GB2476@kobe.laptop> In-Reply-To: <262949390709091803s507265e6mf3929c4dd26ecc56@mail.gmail.com> References: <46E11515.8090007@tomjudge.com> <46E174DB.8070004@FreeBSD.org> <20070907185757.GA25624@kobe.laptop> <262949390709091803s507265e6mf3929c4dd26ecc56@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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; - 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); %%% With this version, I can successfully add *and* delete a route for 128/8 on my laptop and route -nv monitor reports: # got message of size 132 on Mon Sep 10 14:03:56 2007 # RTM_ADD: Add Route: len 132, pid: 2698, seq 1, errno 0, # flags:<UP,GATEWAY,DONE,STATIC> # locks: inits: # sockaddrs: <DST,GATEWAY,NETMASK> # 128.0.0.0 127.0.0.1 (0) 0 ff # # got message of size 132 on Mon Sep 10 14:03:57 2007 # RTM_DELETE: Delete Route: len 132, pid: 2702, seq 1, errno 0, # flags:<GATEWAY,DONE,STATIC> # locks: inits: # sockaddrs: <DST,GATEWAY,NETMASK> # 128.0.0.0 127.0.0.1 (255) ffff ff
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20070910110528.GB2476>