Module Name:    src
Committed By:   kefren
Date:           Sun Jun 27 06:52:38 UTC 2010

Modified Files:
        src/usr.bin/netstat: main.c netstat.1 netstat.h route.c show.c

Log Message:
Add -T flag, that shows tags in route output


To generate a diff of this commit:
cvs rdiff -u -r1.74 -r1.75 src/usr.bin/netstat/main.c \
    src/usr.bin/netstat/route.c
cvs rdiff -u -r1.55 -r1.56 src/usr.bin/netstat/netstat.1
cvs rdiff -u -r1.40 -r1.41 src/usr.bin/netstat/netstat.h
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/netstat/show.c

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

Modified files:

Index: src/usr.bin/netstat/main.c
diff -u src/usr.bin/netstat/main.c:1.74 src/usr.bin/netstat/main.c:1.75
--- src/usr.bin/netstat/main.c:1.74	Wed Feb 24 11:00:27 2010
+++ src/usr.bin/netstat/main.c	Sun Jun 27 06:52:37 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.74 2010/02/24 11:00:27 pooka Exp $	*/
+/*	$NetBSD: main.c,v 1.75 2010/06/27 06:52:37 kefren Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -39,7 +39,7 @@
 #if 0
 static char sccsid[] = "from: @(#)main.c	8.4 (Berkeley) 3/1/94";
 #else
-__RCSID("$NetBSD: main.c,v 1.74 2010/02/24 11:00:27 pooka Exp $");
+__RCSID("$NetBSD: main.c,v 1.75 2010/06/27 06:52:37 kefren Exp $");
 #endif
 #endif /* not lint */
 
@@ -429,7 +429,7 @@
 	pcbaddr = 0;
 
 	while ((ch = getopt(argc, argv,
-	    "AabBdf:ghI:LliM:mN:nP:p:qrsStuvw:X")) != -1)
+	    "AabBdf:ghI:LliM:mN:nP:p:qrsStTuvw:X")) != -1)
 		switch (ch) {
 		case 'A':
 			Aflag = 1;
@@ -528,6 +528,9 @@
 		case 't':
 			tflag = 1;
 			break;
+		case 'T':
+			tagflag = 1;
+			break;
 		case 'u':
 			af = AF_LOCAL;
 			break;
Index: src/usr.bin/netstat/route.c
diff -u src/usr.bin/netstat/route.c:1.74 src/usr.bin/netstat/route.c:1.75
--- src/usr.bin/netstat/route.c:1.74	Thu Apr 22 14:32:30 2010
+++ src/usr.bin/netstat/route.c	Sun Jun 27 06:52:38 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: route.c,v 1.74 2010/04/22 14:32:30 plunky Exp $	*/
+/*	$NetBSD: route.c,v 1.75 2010/06/27 06:52:38 kefren Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)route.c	8.3 (Berkeley) 3/9/94";
 #else
-__RCSID("$NetBSD: route.c,v 1.74 2010/04/22 14:32:30 plunky Exp $");
+__RCSID("$NetBSD: route.c,v 1.75 2010/06/27 06:52:38 kefren Exp $");
 #endif
 #endif /* not lint */
 
@@ -52,6 +52,7 @@
 #include <netinet/in.h>
 #include <netatalk/at.h>
 #include <netiso/iso.h>
+#include <netmpls/mpls.h>
 
 #include <sys/sysctl.h>
 
@@ -272,6 +273,21 @@
 	else
 		printf("%6s", "-");
 	putchar((rt->rt_rmx.rmx_locks & RTV_MTU) ? 'L' : ' ');
+	if (tagflag == 1) {
+		if (rt->rt_tag != NULL) {
+			const struct sockaddr_mpls *sampls = 
+			    (const struct sockaddr_mpls*)kgetsa(rt->rt_tag);
+			union mpls_shim shim;
+
+			if (sampls->smpls_family == AF_MPLS) {
+				shim.s_addr = ntohl(sampls->smpls_addr.s_addr);
+				printf("%7d", shim.shim.label);
+			}
+			else
+				printf("%7s", "-");
+		} else
+			printf("%7s", "-");
+	}
 	if (rt->rt_ifp) {
 		if (rt->rt_ifp != lastif) {
 			kget(rt->rt_ifp, ifnet);

Index: src/usr.bin/netstat/netstat.1
diff -u src/usr.bin/netstat/netstat.1:1.55 src/usr.bin/netstat/netstat.1:1.56
--- src/usr.bin/netstat/netstat.1:1.55	Wed Feb 24 11:00:27 2010
+++ src/usr.bin/netstat/netstat.1	Sun Jun 27 06:52:37 2010
@@ -1,4 +1,4 @@
-.\"	$NetBSD: netstat.1,v 1.55 2010/02/24 11:00:27 pooka Exp $
+.\"	$NetBSD: netstat.1,v 1.56 2010/06/27 06:52:37 kefren Exp $
 .\"
 .\" Copyright (c) 1983, 1990, 1992, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -42,7 +42,7 @@
 .Op Fl M Ar core
 .Op Fl N Ar system
 .Nm
-.Op Fl bdghiLmnqrSsv
+.Op Fl bdghiLmnqrSsTv
 .Op Fl f Ar address_family
 .Op Fl M Ar core
 .Op Fl N Ar system
@@ -264,6 +264,8 @@
 .It Fl s
 Show per-protocol statistics.
 If this option is repeated, counters with a value of zero are suppressed.
+.It Fl T
+Show MPLS Tags for the routing tables.
 .It Fl v
 Show extra (verbose) detail for the routing tables
 .Pq Fl r ,

Index: src/usr.bin/netstat/netstat.h
diff -u src/usr.bin/netstat/netstat.h:1.40 src/usr.bin/netstat/netstat.h:1.41
--- src/usr.bin/netstat/netstat.h:1.40	Wed Feb 24 11:00:27 2010
+++ src/usr.bin/netstat/netstat.h	Sun Jun 27 06:52:37 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: netstat.h,v 1.40 2010/02/24 11:00:27 pooka Exp $	*/
+/*	$NetBSD: netstat.h,v 1.41 2010/06/27 06:52:37 kefren Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -54,6 +54,7 @@
 int	qflag;		/* show softintrq */
 int	rflag;		/* show routing tables (or routing stats) */
 int	sflag;		/* show protocol statistics */
+int	tagflag;	/* show route tags */
 int	tflag;		/* show i/f watchdog timers */
 int	vflag;		/* verbose route information or don't truncate names */
 

Index: src/usr.bin/netstat/show.c
diff -u src/usr.bin/netstat/show.c:1.9 src/usr.bin/netstat/show.c:1.10
--- src/usr.bin/netstat/show.c:1.9	Sat Jun 26 14:30:31 2010
+++ src/usr.bin/netstat/show.c	Sun Jun 27 06:52:38 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: show.c,v 1.9 2010/06/26 14:30:31 kefren Exp $	*/
+/*	$NetBSD: show.c,v 1.10 2010/06/27 06:52:38 kefren Exp $	*/
 /*	$OpenBSD: show.c,v 1.1 2006/05/27 19:16:37 claudio Exp $	*/
 
 /*
@@ -103,6 +103,7 @@
 void	 p_sockaddr(struct sockaddr *, struct sockaddr *, int, int);
 char	*routename4(in_addr_t);
 char	*routename6(struct sockaddr_in6 *);
+static void p_tag(const struct sockaddr *sa);
 
 /*
  * Print routing tables.
@@ -201,12 +202,18 @@
 {
 	if (pAflag)
 		printf("%-*.*s ", PLEN, PLEN, "Address");
-	if (paf != PF_KEY)
-		printf("%-*.*s %-*.*s %-6.6s %6.6s %8.8s %6.6s  %s\n",
-		    WID_DST(paf), WID_DST(paf), "Destination",
-		    WID_GW(paf), WID_GW(paf), "Gateway",
-		    "Flags", "Refs", "Use", "Mtu", "Interface");
-	else
+	if (paf != PF_KEY) {
+		if (tagflag == 1)
+			printf("%-*.*s %-*.*s %-6.6s %6.6s %8.8s %6.6s %7.7s"
+			    " %s\n", WID_DST(paf), WID_DST(paf), "Destination",
+			    WID_GW(paf), WID_GW(paf), "Gateway",
+			    "Flags", "Refs", "Use", "Mtu", "Tag", "Interface");
+		else
+			printf("%-*.*s %-*.*s %-6.6s %6.6s %8.8s %6.6s %s\n",
+			    WID_DST(paf), WID_DST(paf), "Destination",
+			    WID_GW(paf), WID_GW(paf), "Gateway",
+			    "Flags", "Refs", "Use", "Mtu", "Interface");
+	} else
 		printf("%-18s %-5s %-18s %-5s %-5s %-22s\n",
 		    "Source", "Port", "Destination",
 		    "Port", "Proto", "SA(Address/Proto/Type/Direction)");
@@ -265,6 +272,8 @@
 	else
 		printf("%6s", "-");
 	putchar((rtm->rtm_rmx.rmx_locks & RTV_MTU) ? 'L' : ' ');
+	if (tagflag == 1)
+		p_tag(rti_info[RTAX_TAG]);
 	printf(" %.16s", if_indextoname(rtm->rtm_index, ifbuf));
 	putchar('\n');
 }
@@ -373,6 +382,22 @@
 	printf(format, name);
 }
 
+static void
+p_tag(const struct sockaddr *sa)
+{
+	const struct sockaddr_mpls *sampls =
+	    (const struct sockaddr_mpls *)sa;
+	union mpls_shim mshim;
+
+	if (sa == NULL || sa->sa_family != AF_MPLS) {
+		printf("%7s", "-");
+		return;
+	}
+
+	mshim.s_addr = ntohl(sampls->smpls_addr.s_addr);
+	printf("%7d", mshim.shim.label);
+}
+
 static char line[MAXHOSTNAMELEN];
 static char domain[MAXHOSTNAMELEN];
 

Reply via email to