Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/netstat Add -T flag, that shows tags in route output



details:   https://anonhg.NetBSD.org/src/rev/d3bb1cddaf13
branches:  trunk
changeset: 755899:d3bb1cddaf13
user:      kefren <kefren%NetBSD.org@localhost>
date:      Sun Jun 27 06:52:37 2010 +0000

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

diffstat:

 usr.bin/netstat/main.c    |   9 ++++++---
 usr.bin/netstat/netstat.1 |   6 ++++--
 usr.bin/netstat/netstat.h |   3 ++-
 usr.bin/netstat/route.c   |  20 ++++++++++++++++++--
 usr.bin/netstat/show.c    |  39 ++++++++++++++++++++++++++++++++-------
 5 files changed, 62 insertions(+), 15 deletions(-)

diffs (203 lines):

diff -r b9f4ce5c649d -r d3bb1cddaf13 usr.bin/netstat/main.c
--- a/usr.bin/netstat/main.c    Sun Jun 27 06:48:40 2010 +0000
+++ b/usr.bin/netstat/main.c    Sun Jun 27 06:52:37 2010 +0000
@@ -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;
diff -r b9f4ce5c649d -r d3bb1cddaf13 usr.bin/netstat/netstat.1
--- a/usr.bin/netstat/netstat.1 Sun Jun 27 06:48:40 2010 +0000
+++ b/usr.bin/netstat/netstat.1 Sun Jun 27 06:52:37 2010 +0000
@@ -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 ,
diff -r b9f4ce5c649d -r d3bb1cddaf13 usr.bin/netstat/netstat.h
--- a/usr.bin/netstat/netstat.h Sun Jun 27 06:48:40 2010 +0000
+++ b/usr.bin/netstat/netstat.h Sun Jun 27 06:52:37 2010 +0000
@@ -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 */
 
diff -r b9f4ce5c649d -r d3bb1cddaf13 usr.bin/netstat/route.c
--- a/usr.bin/netstat/route.c   Sun Jun 27 06:48:40 2010 +0000
+++ b/usr.bin/netstat/route.c   Sun Jun 27 06:52:37 2010 +0000
@@ -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);
diff -r b9f4ce5c649d -r d3bb1cddaf13 usr.bin/netstat/show.c
--- a/usr.bin/netstat/show.c    Sun Jun 27 06:48:40 2010 +0000
+++ b/usr.bin/netstat/show.c    Sun Jun 27 06:52:37 2010 +0000
@@ -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];
 



Home | Main Index | Thread Index | Old Index