Subject: Re: RFC: route(8) host/bits vs. net/bits
To: Christopher W. Richardson <cwr@nexthop.com>
From: Brian Ginsbach <ginsbach@NetBSD.org>
List: tech-net
Date: 05/12/2005 17:19:47
--AqsLC8rIMeq19msA
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

On Thu, May 12, 2005 at 11:09:32AM -0400, Christopher W. Richardson wrote:
> It may violate POLA, but it is expected if you've been around
> networking a while.  That address is by default a class B. The
> /24 makes it a subnet, and one would expect it to be 172.31.0.73.

I know it is expected when using inet_addr(3).  But that is not
what I was asking about.  I was asking is it really expected that
combining old style short hand with modern CIDR style addresses.

It only violates POLA because netstat(8) and route(8) do (display)
things differently.

Would you agree that route should at least honor -net 172.31.73/24?
(See attached patch.)

> Probably the correct change is for route to display
> 172.31.73.0/24, so that it is clear.  If I type in 10.1 as an
> address, I expect that to be interpreted as 10.0.0.1.

No, I believe netstat(8) would need to be changed.  As you suggest
2.0 and later route(8) already DTRT when it displays such a network
address.  I've been looking at a 1.6.2 system so maybe netstat has
changed as well but from looking at the current code I'd say no.
Compare netstat/route.c:netname() with route/route.c:netname() and note
that the latter no longer shortens networks to the "correct" number
of quads.

Later,
Brian

--AqsLC8rIMeq19msA
Content-Type: text/plain; charset=us-ascii
Content-Description: patch
Content-Disposition: attachment; filename="route.patch2"

Index: route.c
===================================================================
RCS file: /cvsroot/src/sbin/route/route.c,v
retrieving revision 1.76
diff -u -r1.76 route.c
--- route.c	10 May 2005 18:12:22 -0000	1.76
+++ route.c	12 May 2005 16:38:09 -0000
@@ -1289,9 +1289,16 @@
 
 	if ((t = strchr(s, '/')) != NULL && which == RTA_DST) {
 		*t = '\0';
-		if ((val = inet_addr(s)) != INADDR_NONE) {
-			inet_makenetandmask(htonl(val), &su->sin);
-			return prefixlen(&t[1]);
+		if (forcenet == 0) {
+			if ((val = inet_addr(s)) != INADDR_NONE) {
+				inet_makenetandmask(htonl(val), &su->sin);
+				return prefixlen(&t[1]);
+			}
+		} else {
+			if ((val = inet_network(s)) != INADDR_NONE) {
+				inet_makenetandmask(val, &su->sin);
+				return prefixlen(&t[1]);
+			}
 		}
 		*t = '/';
 	}

--AqsLC8rIMeq19msA--