Subject: RFC: route(8) host/bits vs. net/bits
To: None <tech-net@NetBSD.org>
From: Brian Ginsbach <ginsbach@NetBSD.org>
List: tech-net
Date: 05/12/2005 03:18:16
Does anyone else out there find it odd that for IPv4 addresses
route(8) expects host/bits format while netstat(8) displays routes
in net/bits format?  For example, netstat -rn displays a route like:

172.31.73/24       link#1             UC          3        0      -  fxp0

This address can not be fed back in to say route get because it is
treated as a host address, using inet_addr(3).  The address is then
misinterpreted as 172.31.0.73.

Is the current behavior really expected?  IMHO seems to violate POLA.

Are there any objections to making this work like FreeBSD's route(8)?
It uses net/bits, inet_network(3), which in this case does the
right thing.  Proposed change:

Index: route.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
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 02:32:11 -0000
@@ -1289,8 +1289,8 @@
=20
 	if ((t =3D strchr(s, '/')) !=3D NULL && which =3D=3D RTA_DST) {
 		*t =3D '\0';
-		if ((val =3D inet_addr(s)) !=3D INADDR_NONE) {
-			inet_makenetandmask(htonl(val), &su->sin);
+		if ((val =3D inet_network(s)) !=3D INADDR_NONE) {
+			inet_makenetandmask(val, &su->sin);
 			return prefixlen(&t[1]);
 		}
 		*t =3D '/';


I suppose if the current behavior is desirable (i.e.  specifying
addresses using the inet_addr(3) rules) then maybe  additional
logic could be added so that -host 172.31.73/24 really would result
in 172.31.0.73/24.

Thanks