From nobody@FreeBSD.org  Wed Jan 19 18:04:35 2011
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 6AF841065673
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 19 Jan 2011 18:04:35 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (unknown [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id 405FE8FC12
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 19 Jan 2011 18:04:35 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.4/8.14.4) with ESMTP id p0JI4YCt012438
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 19 Jan 2011 18:04:34 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id p0JI4Y0K012437;
	Wed, 19 Jan 2011 18:04:34 GMT
	(envelope-from nobody)
Message-Id: <201101191804.p0JI4Y0K012437@red.freebsd.org>
Date: Wed, 19 Jan 2011 18:04:34 GMT
From: Petr Lampa <lampa@fit.vutbr.cz>
To: freebsd-gnats-submit@FreeBSD.org
Subject: netstat -ian leaking out embedded scope index
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         154147
>Category:       bin
>Synopsis:       netstat -ian leaking out embedded scope index
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    ume
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Jan 19 18:10:12 UTC 2011
>Closed-Date:    Thu Jan 20 15:51:16 UTC 2011
>Last-Modified:  Thu Jan 20 15:51:16 UTC 2011
>Originator:     Petr Lampa
>Release:        8.2-PRERELEASE
>Organization:
BUT FIT 
>Environment:
FreeBSD XXX 8.2-PRERELEASE FreeBSD 8.2-PRERELEASE #18: Tue Jan 18 15:59:42 CET 2011     XXX@XXX:/usr/src/sys/i386/compile/GUTA  i386
>Description:

netstat -ian
em0    1500 2001:718:802: 2001:718:802:809:    22110     -     -    25384     -     -
                          ff05::1:3          (refs: 1)
                          ff02:1::1:2        (refs: 1)
                          ff02:1::202        (refs: 1)
                          ff02:1::1:ffe5:913 (refs: 1)
                          ff02:1::1:ffe5:90b (refs: 1)
                          ff01:1::1          (refs: 1)
                          ff02:1::2:7d68:cd71(refs: 1)
                          ff02:1::1          (refs: 1)
                          ff02:1::1:ff30:8646(refs: 1)

Some multicast addresses have embedded scope index in output.
Original report is here:
http://docs.freebsd.org/cgi/getmsg.cgi?fetch=280697+0+current/freebsd-net
>How-To-Repeat:
netstat -ian

>Fix:
/usr/src/usr.bin/netstat

*** if.c.old    2011-01-19 18:41:32.000000000 +0100
--- if.c        2011-01-19 18:53:18.000000000 +0100
***************
*** 475,480 ****
--- 475,487 ----
                                        break;
  #ifdef INET6
                                case AF_INET6:
+                                       if (IN6_IS_ADDR_LINKLOCAL(&msa.in6.sin6_addr) ||
+                                           IN6_IS_ADDR_MC_NODELOCAL(&msa.in6.sin6_addr) ||
+                                           IN6_IS_ADDR_MC_LINKLOCAL(&msa.in6.sin6_addr)) {
+
+                                               msa.in6.sin6_addr.s6_addr[2] = 0;
+                                               msa.in6.sin6_addr.s6_addr[3] = 0;
+                                       }
                                        printf("%*s %-19.19s(refs: %d)\n",
                                               Wflag ? 27 : 25, "",
                                               inet_ntop(AF_INET6,


Patch attached with submission follows:

*** usr.bin/netstat/if.c.old	2011-01-19 18:41:32.000000000 +0100
--- usr.bin/netstat/if.c	2011-01-19 18:53:18.000000000 +0100
***************
*** 475,480 ****
--- 475,487 ----
  					break;
  #ifdef INET6
  				case AF_INET6:
+ 					if (IN6_IS_ADDR_LINKLOCAL(&msa.in6.sin6_addr) ||
+ 					    IN6_IS_ADDR_MC_NODELOCAL(&msa.in6.sin6_addr) ||
+ 					    IN6_IS_ADDR_MC_LINKLOCAL(&msa.in6.sin6_addr)) {
+ 					    
+ 						msa.in6.sin6_addr.s6_addr[2] = 0;
+ 						msa.in6.sin6_addr.s6_addr[3] = 0;
+ 					}
  					printf("%*s %-19.19s(refs: %d)\n",
  					       Wflag ? 27 : 25, "",
  					       inet_ntop(AF_INET6,


>Release-Note:
>Audit-Trail:

From: Petr Lampa <lampa@fit.vutbr.cz>
To: bug-followup@FreeBSD.org, lampa@fit.vutbr.cz
Cc:  
Subject: Re: bin/154147: netstat -ian leaking out embedded scope index
Date: Thu, 20 Jan 2011 13:38:54 +0100

 I've just found yet another case of leaking out embedded scope index:
 
 netstat -i
 em0    1500 fe80:1::230:4 fe80:1::230:48ff:      943     -     -     9907     - 
 lo0   16384 fe80:3::1     fe80:3::1                0     -     -        0     - 
 
 should be:
 em0    1500 fe80::230:48f fe80::230:48ff:fe      943     -     -     9913     -
 lo0   16384 fe80::1       fe80::1                  0     -     -        0     -
 
 Here is the second patch:
 
 *** if.c.old    2011-01-19 18:41:32.000000000 +0100 
 --- if.c        2011-01-20 13:32:10.000000000 +0100
 ***************
 *** 347,352 ****
 --- 347,358 ----
   #ifdef INET6
                         case AF_INET6:
                                 sockin6 = (struct sockaddr_in6 *)sa;
 +                               if (IN6_IS_ADDR_LINKLOCAL(&sockin6->sin6_addr) |
 |
 +                                   IN6_IS_ADDR_MC_NODELOCAL(&sockin6->sin6_addr
 ) ||
 +                                   IN6_IS_ADDR_MC_LINKLOCAL(&sockin6->sin6_addr
 )) {
 +                                       sockin6->sin6_addr.s6_addr[2] = 0;
 +                                       sockin6->sin6_addr.s6_addr[3] = 0;
 +                               }
                                 printf("%-13.13s ",
                                        netname6(&ifaddr.in6.ia_addr,
                                                 &ifaddr.in6.ia_prefixmask.sin6_addr));
 
 Petr Lampa
 
 -- 
 Computer Centre                             E-mail: lampa@fit.vutbr.cz
 Faculty of Information Technology           Web: http://www.fit.vutbr.cz/
 Brno University of Technology               Fax:  +420 54114-1270
 Bozetechova 2, 612 66 Brno, Czech Republic  Phone: +420 54114-1225
State-Changed-From-To: open->closed 
State-Changed-By: ume 
State-Changed-When: Thu Jan 20 15:48:52 UTC 2011 
State-Changed-Why:  
Thank you for the PR.  However, I committed to fix this 
problem by slightly different way. 


Responsible-Changed-From-To: freebsd-bugs->ume 
Responsible-Changed-By: ume 
Responsible-Changed-When: Thu Jan 20 15:48:52 UTC 2011 
Responsible-Changed-Why:  
Thank you for the PR.  However, I committed to fix this 
problem by slightly different way. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=154147 
>Unformatted:
