From owner-freebsd-net@FreeBSD.ORG Mon Sep 10 11:24:36 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 B2AE616A418; Mon, 10 Sep 2007 11:24:36 +0000 (UTC) (envelope-from keramida@FreeBSD.org) Received: from igloo.linux.gr (igloo.linux.gr [62.1.205.36]) by mx1.freebsd.org (Postfix) with ESMTP id 7C61113C459; Mon, 10 Sep 2007 11:24:35 +0000 (UTC) (envelope-from keramida@FreeBSD.org) Received: from kobe.laptop (vader.bytemobile.ondsl.gr [83.235.244.135]) (authenticated bits=128) by igloo.linux.gr (8.14.1/8.14.1/Debian-9) with ESMTP id l8AB5jLY019880 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Mon, 10 Sep 2007 14:05:54 +0300 Received: from kobe.laptop (kobe.laptop [127.0.0.1]) by kobe.laptop (8.14.1/8.14.1) with ESMTP id l8AB5Tsf002713; Mon, 10 Sep 2007 14:05:44 +0300 (EEST) (envelope-from keramida@FreeBSD.org) Received: (from keramida@localhost) by kobe.laptop (8.14.1/8.14.1/Submit) id l8AB5SIV002712; Mon, 10 Sep 2007 14:05:28 +0300 (EEST) (envelope-from keramida@FreeBSD.org) Date: Mon, 10 Sep 2007 14:05:28 +0300 From: Giorgos Keramidas To: Nuno Antunes Message-ID: <20070910110528.GB2476@kobe.laptop> References: <46E11515.8090007@tomjudge.com> <46E174DB.8070004@FreeBSD.org> <20070907185757.GA25624@kobe.laptop> <262949390709091803s507265e6mf3929c4dd26ecc56@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <262949390709091803s507265e6mf3929c4dd26ecc56@mail.gmail.com> X-Hellug-MailScanner: Found to be clean X-Hellug-MailScanner-SpamCheck: not spam, SpamAssassin (not cached, score=-4.073, required 5, autolearn=not spam, ALL_TRUSTED -1.80, AWL 0.33, BAYES_00 -2.60) X-Hellug-MailScanner-From: keramida@freebsd.org X-Spam-Status: No Cc: Tom Judge , freebsd-net@FreeBSD.org, "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, 10 Sep 2007 11:24:36 -0000 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; - 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: # locks: inits: # sockaddrs: # 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: # locks: inits: # sockaddrs: # 128.0.0.0 127.0.0.1 (255) ffff ff