Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 3 Feb 2012 15:26:55 +0000 (UTC)
From:      "Bjoern A. Zeeb" <bz@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-projects@freebsd.org
Subject:   svn commit: r230947 - projects/multi-fibv6/head/usr.bin/netstat
Message-ID:  <201202031526.q13FQt4w092984@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: bz
Date: Fri Feb  3 15:26:55 2012
New Revision: 230947
URL: http://svn.freebsd.org/changeset/base/230947

Log:
  Teach netstat -r (display contents of routing tables) about multi-FIB for
  IPv6 in addition to IPv4.
  While here harmonize naming of variables a bit with what we use in kernel.
  
  Sponsored by:	Cisco Systems, Inc.

Modified:
  projects/multi-fibv6/head/usr.bin/netstat/route.c

Modified: projects/multi-fibv6/head/usr.bin/netstat/route.c
==============================================================================
--- projects/multi-fibv6/head/usr.bin/netstat/route.c	Fri Feb  3 13:54:25 2012	(r230946)
+++ projects/multi-fibv6/head/usr.bin/netstat/route.c	Fri Feb  3 15:26:55 2012	(r230947)
@@ -113,7 +113,6 @@ typedef union {
 
 static sa_u pt_u;
 
-int	fibnum;
 int	do_rtent = 0;
 struct	rtentry rtentry;
 struct	radix_node rnode;
@@ -148,8 +147,7 @@ routepr(u_long rtree)
 {
 	struct radix_node_head **rnhp, *rnh, head;
 	size_t intsize;
-	int i;
-	int numfibs;
+	int fam, fibnum, numfibs;
 
 	intsize = sizeof(int);
 	if (sysctlbyname("net.my_fibnum", &fibnum, &intsize, NULL, 0) == -1)
@@ -181,15 +179,20 @@ routepr(u_long rtree)
 		if (kread((u_long)(rtree), (char *)(rt_tables), (numfibs *
 		    (AF_MAX+1) * sizeof(struct radix_node_head *))) != 0)
 			return;
-		for (i = 0; i <= AF_MAX; i++) {
+		for (fam = 0; fam <= AF_MAX; fam++) {
 			int tmpfib;
-			if (i != AF_INET)
-				tmpfib = 0;
-			else
+
+			switch (fam) {
+			case AF_INET6:
+			case AF_INET:
 				tmpfib = fibnum;
+				break;
+			default:
+				tmpfib = 0;
+			}
 			rnhp = (struct radix_node_head **)*rt_tables;
 			/* Calculate the in-kernel address. */
-			rnhp += tmpfib * (AF_MAX+1) + i;
+			rnhp += tmpfib * (AF_MAX+1) + fam;
 			/* Read the in kernel rhn pointer. */
 			if (kget(rnhp, rnh) != 0)
 				continue;
@@ -198,16 +201,16 @@ routepr(u_long rtree)
 			/* Read the rnh data. */
 			if (kget(rnh, head) != 0)
 				continue;
-			if (i == AF_UNSPEC) {
+			if (fam == AF_UNSPEC) {
 				if (Aflag && af == 0) {
 					printf("Netmasks:\n");
 					p_tree(head.rnh_treetop);
 				}
-			} else if (af == AF_UNSPEC || af == i) {
-				size_cols(i, head.rnh_treetop);
-				pr_family(i);
+			} else if (af == AF_UNSPEC || af == fam) {
+				size_cols(fam, head.rnh_treetop);
+				pr_family(fam);
 				do_rtent = 1;
-				pr_rthdr(i);
+				pr_rthdr(fam);
 				p_tree(head.rnh_treetop);
 			}
 		}



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