From owner-cvs-all@FreeBSD.ORG Wed Oct 31 12:42:02 2007 Return-Path: Delivered-To: cvs-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0B27916A468; Wed, 31 Oct 2007 12:42:02 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from mail35.syd.optusnet.com.au (mail35.syd.optusnet.com.au [211.29.133.51]) by mx1.freebsd.org (Postfix) with ESMTP id 7EEA313C4D1; Wed, 31 Oct 2007 12:42:01 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from c211-30-219-213.carlnfd3.nsw.optusnet.com.au (c211-30-219-213.carlnfd3.nsw.optusnet.com.au [211.30.219.213]) by mail35.syd.optusnet.com.au (8.13.1/8.13.1) with ESMTP id l9VCf0Hn026876 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 31 Oct 2007 23:41:01 +1100 Date: Wed, 31 Oct 2007 23:41:08 +1100 (EST) From: Bruce Evans X-X-Sender: bde@delplex.bde.org To: Giorgos Keramidas In-Reply-To: <20071030201036.GA1413@kobe.laptop> Message-ID: <20071031214125.V3526@delplex.bde.org> References: <200710290008.l9T08Odw067359@repoman.freebsd.org> <20071030201036.GA1413@kobe.laptop> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: cvs-src@FreeBSD.org, Mike Makonnen , src-committers@FreeBSD.org, cvs-all@FreeBSD.org Subject: Re: cvs commit: src/sbin/route route.c X-BeenThere: cvs-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: CVS commit messages for the entire tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 31 Oct 2007 12:42:03 -0000 On Tue, 30 Oct 2007, Giorgos Keramidas wrote: > On 2007-10-29 00:08, Mike Makonnen wrote: >> mtm 2007-10-29 00:08:24 UTC >> >> FreeBSD src repository >> >> Modified files: >> sbin/route route.c >> Log: >> Fix an error in bit shifting logic for network addresses. The route >> command would add incorrect routing entries if network numbers weren't >> fully "spelled" out according to their class. For example: >> # route add 128.0/16 (works) >> # route add 128/16 (doesn't work) Isn't this supposed to be handled by inet_net_pton(3)? >> [...] >> Submitted by: Nuno Antunes (mostly) >> MFC after: 1 week >> >> Revision Changes Path >> 1.82 +24 -20 src/sbin/route/route.c > > Thank you Mike! Almost identical to the patch I was testing a while > back, including better netmask handling parts :-) > > Nuno has also mentioned that `netstat -rn' gets things wrong; do you > have a WIP for that too? Do you need help with testing? I don't know much about this, but noticed some related bugs in netstat going away, which I though was due to the libary being improved. Actually, the problems in netstat are smaller, since it just needs to print addresses in a standard format. It uses inet_ntoa() and inet_ntop(), and these seem to be inferior in most ways to inet_net_*(). In particular, /N is only documented to be handled by inet_net_pton(), and then only for full quad addresses. However, inet_net_pton() seems to do the right thing for shorter addresses (it does the same thing for 128/16 as for 128/16; the result on little-endian machines is 16 bits with value 0x0080; printing this result using inet_net_ntop() gives 128.0/16). OTOH, inet_net_pton() doesn't support hex numbers in dotted-quad format (it only accepts a leading 0x and then wants no dots). The man pages aren't very clear about this. FreeBSD's libc/net/in_addr.c was cleaned up significantly in rev.1.8, but the changes were clobbered by less significant changes in the ISC version. E.g., where 1.8 version uses strtoul() and actually checks for errors, rev.1.7 uses a home-made number parser that silently overflows for large (invalid) numbers, while the current FreeBSD=ISC version is identical with 1.7 except for cosmetic changes and 2 fixes for bugs other than the overflow bugs in the parser. The history is hard to follow because the current version is in a different directory (libc/inet). The inet_net_*() functions are in a different file and don't seem to have ever been changed significantly by FreeBSD. They have the usual home-made number parser with overflow bugs. Their non-support for dotted-hex numbers may be just a bug. A comment in the code says that hex octets are supported, and the man page says that all "parts" of an address may be a number in C format, including hex and octal. The implementation is completely missing support for octal (e.g., 010 is interpreted as decimal 10 by inet_net_ntop() but as decimal 8 by inet_ntop()). However, their man page seems to have been cloned from inet.3, so it might not be authoritative. Bruce