NetBSD Problem Report #38093

From dieter.NetBSD@pandora.be  Sat Feb 23 21:15:18 2008
Return-Path: <dieter.NetBSD@pandora.be>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
	by narn.NetBSD.org (Postfix) with ESMTP id EBA5F63B853
	for <gnats-bugs@gnats.NetBSD.org>; Sat, 23 Feb 2008 21:15:17 +0000 (UTC)
Message-Id: <20080223211530.DDEC8182B4@simult.amelgem.be>
Date: Sat, 23 Feb 2008 22:15:30 +0100 (CET)
From: dieter.NetBSD@pandora.be
Reply-To: dieter.NetBSD@pandora.be
To: gnats-bugs@gnats.NetBSD.org
Subject: netstat shows server sockets when not asked
X-Send-Pr-Version: 3.95

>Number:         38093
>Category:       bin
>Synopsis:       netstat shows server sockets when not asked
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    dholland
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Feb 23 21:20:00 +0000 2008
>Closed-Date:    Sat Apr 04 21:57:42 +0000 2009
>Last-Modified:  Sat Apr 04 21:57:42 +0000 2009
>Originator:     dieter roelants
>Release:        NetBSD 4.99.54, NetBSD 4.0_STABLE
>Organization:
>Environment:
System: NetBSD simult.amelgem.be 4.99.54 NetBSD 4.99.54 (SIMULT) #57: Wed Feb 13 20:48:11 CET 2008 dieter@simult.amelgem.be:/build/obj.i386.current/sys/arch/i386/compile/SIMULT i386
Architecture: i386
Machine: i386
>Description:
	According to the man page, netstat doesn't show server
	sockets unless the -a option is used. This is not the case.
	When sysctl is used to gather the information from the
	kernel, all sockets are displayed. When the info comes from
	/dev/kmem, server sockets not bound to the any addr are
	also shown.
>How-To-Repeat:
	Run netstat without -a on a machine with listening sockets.
	See them being displayed.
>Fix:

(The patch to iso.c is compile-tested only.)

Index: inet.c
===================================================================
RCS file: /cvsroot/src/usr.bin/netstat/inet.c,v
retrieving revision 1.78
diff -u -r1.78 inet.c
--- inet.c	10 Jul 2007 21:12:33 -0000	1.78
+++ inet.c	23 Feb 2008 21:10:03 -0000
@@ -222,6 +222,9 @@
 				first = 0;
 			}

+			if (!aflag && inet_lnaof(dst.sin_addr) == INADDR_ANY)
+				continue;
+
 	                protopr0((intptr_t) pcblist[i].ki_ppcbaddr,
 				 pcblist[i].ki_rcvq, pcblist[i].ki_sndq,
 				 &src.sin_addr, src.sin_port,
@@ -254,7 +257,7 @@
 			continue;

 		if (!aflag &&
-		    inet_lnaof(inpcb.inp_laddr) == INADDR_ANY)
+		    inet_lnaof(inpcb.inp_faddr) == INADDR_ANY)
 			continue;
 		kread((u_long)inpcb.inp_socket, (char *)&sockb, sizeof (sockb));
 		if (istcp) {
Index: inet6.c
===================================================================
RCS file: /cvsroot/src/usr.bin/netstat/inet6.c,v
retrieving revision 1.42
diff -u -r1.42 inet6.c
--- inet6.c	7 Mar 2007 22:22:50 -0000	1.42
+++ inet6.c	23 Feb 2008 21:10:18 -0000
@@ -280,6 +280,9 @@
 				first = 0;
 			}

+			if (!aflag && IN6_IS_ADDR_UNSPECIFIED(&dst.sin6_addr))
+				continue;
+
 			ip6protopr0((intptr_t) pcblist[i].ki_ppcbaddr,
 			    pcblist[i].ki_rcvq, pcblist[i].ki_sndq,
 			    &src.sin6_addr, src.sin6_port,
@@ -311,7 +314,7 @@
 		if (in6pcb.in6p_af != AF_INET6)
 			continue;

-		if (!aflag && IN6_IS_ADDR_UNSPECIFIED(&in6pcb.in6p_laddr))
+		if (!aflag && IN6_IS_ADDR_UNSPECIFIED(&in6pcb.in6p_faddr))
 			continue;
 		kread((u_long)in6pcb.in6p_socket, (char *)&sockb, 
 		    sizeof (sockb));
Index: iso.c
===================================================================
RCS file: /cvsroot/src/usr.bin/netstat/iso.c,v
retrieving revision 1.27
diff -u -r1.27 iso.c
--- iso.c	18 Feb 2007 01:56:17 -0000	1.27
+++ iso.c	23 Feb 2008 21:10:18 -0000
@@ -376,7 +376,7 @@
 	struct inpcb inpcb;

 	kget(tpcb.tp_npcb, inpcb);
-	if (!aflag && inet_lnaof(inpcb.inp_laddr) == INADDR_ANY)
+	if (!aflag && inet_lnaof(inpcb.inp_faddr) == INADDR_ANY)
 		return;
 	if (Aflag)
 		printf("%8lx ", pcb);

>Release-Note:

>Audit-Trail:
From: "David A. Holland" <dholland@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/38093 CVS commit: src/usr.bin/netstat
Date: Sun, 22 Feb 2009 07:43:01 +0000 (UTC)

 Module Name:	src
 Committed By:	dholland
 Date:		Sun Feb 22 07:43:01 UTC 2009

 Modified Files:
 	src/usr.bin/netstat: inet.c inet6.c iso.c

 Log Message:
 Make netstat handle -a properly; that is, don't show unconnected
 listener sockets unless -a was given. (It was checking the local
 address instead of the remote address for being INADDR_ANY or
 equivalent.)

 PR 38093 from Dieter Roelants; I adjusted the patch a little.

 This needs pullups for both -4 and -5.


 To generate a diff of this commit:
 cvs rdiff -r1.88 -r1.89 src/usr.bin/netstat/inet.c
 cvs rdiff -r1.50 -r1.51 src/usr.bin/netstat/inet6.c
 cvs rdiff -r1.30 -r1.31 src/usr.bin/netstat/iso.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: open->pending-pullups
State-Changed-By: dholland@NetBSD.org
State-Changed-When: Sun, 22 Feb 2009 07:45:46 +0000
State-Changed-Why:
Fixed in head; pullups needed.


Responsible-Changed-From-To: bin-bug-people->dholland
Responsible-Changed-By: dholland@NetBSD.org
Responsible-Changed-When: Sun, 22 Feb 2009 07:45:59 +0000
Responsible-Changed-Why:
I applied it


From: David Holland <dholland-bugs@netbsd.org>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: bin/38093 (netstat shows server sockets when not asked)
Date: Tue, 24 Mar 2009 21:40:52 +0000

 On Sun, Feb 22, 2009 at 07:45:47AM +0000, dholland@NetBSD.org wrote:
  > State-Changed-From-To: open->pending-pullups
  > State-Changed-By: dholland@NetBSD.org
  > State-Changed-When: Sun, 22 Feb 2009 07:45:46 +0000
  > State-Changed-Why:
  > Fixed in head; pullups needed.

 Nearly forgot about this... that would have been poor.

 pullup-5 #608
 pullup-4 #1292

 -- 
 David A. Holland
 dholland@netbsd.org

State-Changed-From-To: pending-pullups->closed
State-Changed-By: dholland@NetBSD.org
State-Changed-When: Sat, 04 Apr 2009 21:57:42 +0000
State-Changed-Why:
Pullups completed.


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.