Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 6 Jan 2000 19:49:16 -0800 (PST)
From:      "Rodney W. Grimes" <freebsd@gndrsh.dnsmgr.net>
To:        brian@FreeBSD.org (Brian Somers)
Cc:        cvs-committers@FreeBSD.org, cvs-all@FreeBSD.org
Subject:   Small patch to netstat/route.c for review
Message-ID:  <200001070349.TAA10179@gndrsh.dnsmgr.net>
In-Reply-To: <200001070311.TAA40907@freefall.freebsd.org> from Brian Somers at "Jan 6, 2000 07:11:32 pm"

next in thread | previous in thread | raw e-mail | index | archive | help
While working with zebra and some of the folks on the mailling list
over there a small bug in FreeBSD's netstat -r command was found.
Specifically if you have any route 0.0.0.0 independent of what
netmask is applied to it netstat -r miss-reported it as ``default''.

This is not quite correct, the only real default route is 0.0.0.0/0,
or 0.0.0.0 netmask 0.0.0.0.  This small patch fixes things so that
``default'' is only returned if the route is infact a true default
with a mask of 0.0.0.0.  Other routes of the form 0.0.0.0/X are
reported as 0/X like they should be:

root{304}# netstat -ran
Routing tables

Internet:
Destination        Gateway            Flags      Netif Expire
0/32               127.0.0.1          UGSc        lo0 =>
0/16               127.0.0.1          UGSc        lo0 =>
0                  127.0.0.1          UGSc        lo0 =>
default            198.145.92.1       UGSc        de0

Arguable the ``0'' route above looks a bit weird, but due to the
fact it is 0/8 and that matches the classfull subnet netstat -r
drops the /8.  (Which I would really like to see go away, classful
routing is dead and it makes it harder on humans who deal with
everything as a cidr net, even if it matches the classful address,
a royal pain in the head when reading long netstat -r output :-()

Please send any comments, I plan to commit this tomarrow barring
objects, or sooner if I get the right acks for this small, but
important change.

Index: route.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/netstat/route.c,v
retrieving revision 1.40
diff -u -r1.40 route.c
--- route.c	1999/12/28 02:37:02	1.40
+++ route.c	2000/01/07 03:34:22
@@ -434,8 +434,11 @@
 	    {
 		register struct sockaddr_in *sin = (struct sockaddr_in *)sa;
 
-		if (sin->sin_addr.s_addr == INADDR_ANY)
-			cp = "default";
+		if ((sin->sin_addr.s_addr == INADDR_ANY) &&
+			mask &&
+			ntohl(((struct sockaddr_in *)mask)->sin_addr.s_addr)
+				==0L)
+				cp = "default" ;
 		else if (flags & RTF_HOST)
 			cp = routename(sin->sin_addr.s_addr);
 		else if (mask)

-- 
Rod Grimes - KD7CAX @ CN85sl - (RWG25)               rgrimes@gndrsh.dnsmgr.net


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe cvs-all" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200001070349.TAA10179>