summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorClaudio Jeker <claudio@cvs.openbsd.org>2007-07-25 11:50:48 +0000
committerClaudio Jeker <claudio@cvs.openbsd.org>2007-07-25 11:50:48 +0000
commit8bb62f9b32f78e8065bc6894edfd23a6c929d9d3 (patch)
tree655c7183a63772b09004d21f3fefd80d17f4de15 /usr.bin
parentf61f154c8ef589df49ac609b531ca67d71d1c4ae (diff)
Make it possible to show alternate routing tables in netstat. This mostly
comes from route(8) which already had the -T option. OK henning@
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/netstat/main.c18
-rw-r--r--usr.bin/netstat/netstat.17
-rw-r--r--usr.bin/netstat/netstat.h4
-rw-r--r--usr.bin/netstat/show.c13
4 files changed, 27 insertions, 15 deletions
diff --git a/usr.bin/netstat/main.c b/usr.bin/netstat/main.c
index 96c6951ed1f..267b0a32f2a 100644
--- a/usr.bin/netstat/main.c
+++ b/usr.bin/netstat/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.67 2007/06/28 14:27:02 claudio Exp $ */
+/* $OpenBSD: main.c,v 1.68 2007/07/25 11:50:47 claudio Exp $ */
/* $NetBSD: main.c,v 1.9 1996/05/07 02:55:02 thorpej Exp $ */
/*
@@ -40,7 +40,7 @@ char copyright[] =
#if 0
static char sccsid[] = "from: @(#)main.c 8.4 (Berkeley) 3/1/94";
#else
-static char *rcsid = "$OpenBSD: main.c,v 1.67 2007/06/28 14:27:02 claudio Exp $";
+static char *rcsid = "$OpenBSD: main.c,v 1.68 2007/07/25 11:50:47 claudio Exp $";
#endif
#endif /* not lint */
@@ -49,6 +49,7 @@ static char *rcsid = "$OpenBSD: main.c,v 1.67 2007/06/28 14:27:02 claudio Exp $"
#include <sys/protosw.h>
#include <sys/socket.h>
+#include <net/route.h>
#include <netinet/in.h>
#include <ctype.h>
@@ -242,6 +243,7 @@ main(int argc, char *argv[])
{
extern char *optarg;
extern int optind;
+ const char *errstr;
struct protoent *p;
struct protox *tp = NULL; /* for printing cblocks & stats */
int ch;
@@ -249,10 +251,11 @@ main(int argc, char *argv[])
char buf[_POSIX2_LINE_MAX];
gid_t gid;
u_long pcbaddr = 0;
+ u_int tableid = 0;
af = AF_UNSPEC;
- while ((ch = getopt(argc, argv, "AabdFf:gI:ilM:mN:np:P:qrstuvW:w:")) != -1)
+ while ((ch = getopt(argc, argv, "AabdFf:gI:ilM:mN:np:P:qrsT:tuvW:w:")) != -1)
switch (ch) {
case 'A':
Aflag = 1;
@@ -346,6 +349,11 @@ main(int argc, char *argv[])
case 's':
++sflag;
break;
+ case 'T':
+ tableid = strtonum(optarg, 0, RT_TABLEID_MAX, &errstr);
+ if (errstr)
+ errx(1, "invalid table id: %s", errstr);
+ break;
case 't':
tflag = 1;
break;
@@ -397,7 +405,7 @@ main(int argc, char *argv[])
if (sflag)
rt_stats(1, 0);
else
- p_rttables(af);
+ p_rttables(af, tableid);
exit(0);
}
if ((kvmd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY,
@@ -628,7 +636,7 @@ usage(void)
{
(void)fprintf(stderr,
"usage: %s [-Aan] [-f address_family] [-M core] [-N system]\n"
- " %s [-bdFgilmnqrstu] [-f address_family] [-M core] [-N system]\n"
+ " %s [-bdFgilmnqrstu] [-f address_family] [-M core] [-N system] [-T tableid]\n"
" %s [-bdn] [-I interface] [-M core] [-N system] [-w wait]\n"
" %s [-M core] [-N system] -P pcbaddr\n"
" %s [-s] [-M core] [-N system] [-p protocol]\n"
diff --git a/usr.bin/netstat/netstat.1 b/usr.bin/netstat/netstat.1
index 8e5c4869a74..3cf7caa89e8 100644
--- a/usr.bin/netstat/netstat.1
+++ b/usr.bin/netstat/netstat.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: netstat.1,v 1.50 2007/06/04 12:20:24 henning Exp $
+.\" $OpenBSD: netstat.1,v 1.51 2007/07/25 11:50:47 claudio Exp $
.\" $NetBSD: netstat.1,v 1.11 1995/10/03 21:42:43 thorpej Exp $
.\"
.\" Copyright (c) 1983, 1990, 1992, 1993
@@ -30,7 +30,7 @@
.\"
.\" from: @(#)netstat.1 8.8 (Berkeley) 4/18/94
.\"
-.Dd $Mdocdate: June 4 2007 $
+.Dd $Mdocdate: July 25 2007 $
.Dt NETSTAT 1
.Os
.Sh NAME
@@ -245,6 +245,9 @@ option is also specified, show routing statistics instead.
.It Fl s
Show per-protocol statistics.
If this option is repeated, counters with a value of zero are suppressed.
+.It Fl T Ar tableid
+Select an alternate routing table to modify or query.
+Table 0 is the default table.
.It Fl t
With the
.Fl i
diff --git a/usr.bin/netstat/netstat.h b/usr.bin/netstat/netstat.h
index 6e57b6dc731..b2fdaba1f0b 100644
--- a/usr.bin/netstat/netstat.h
+++ b/usr.bin/netstat/netstat.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: netstat.h,v 1.42 2007/06/19 05:30:19 ray Exp $ */
+/* $OpenBSD: netstat.h,v 1.43 2007/07/25 11:50:47 claudio Exp $ */
/* $NetBSD: netstat.h,v 1.6 1996/05/07 02:55:05 thorpej Exp $ */
/*
@@ -118,7 +118,7 @@ char *routename6(struct sockaddr_in6 *);
char *netname6(struct sockaddr_in6 *, struct sockaddr_in6 *);
#endif /*INET6*/
-void p_rttables(int);
+void p_rttables(int, u_int);
void p_flags(int, char *);
void p_addr(struct sockaddr *, struct sockaddr *, int);
void p_gwaddr(struct sockaddr *, int);
diff --git a/usr.bin/netstat/show.c b/usr.bin/netstat/show.c
index 173f60c3115..e8f94b8582c 100644
--- a/usr.bin/netstat/show.c
+++ b/usr.bin/netstat/show.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: show.c,v 1.9 2007/07/24 20:36:34 claudio Exp $ */
+/* $OpenBSD: show.c,v 1.10 2007/07/25 11:50:47 claudio Exp $ */
/* $NetBSD: show.c,v 1.1 1996/11/15 18:01:41 gwr Exp $ */
/*
@@ -95,7 +95,6 @@ static const struct bits bits[] = {
{ 0 }
};
-void pr_rthdr(int, int);
void p_rtentry(struct rt_msghdr *);
void p_pfkentry(struct sadb_msg *);
void pr_family(int);
@@ -112,13 +111,13 @@ void index_pfk(struct sadb_msg *, void **);
* Print routing tables.
*/
void
-p_rttables(int af)
+p_rttables(int af, u_int tableid)
{
struct rt_msghdr *rtm;
struct sadb_msg *msg;
char *buf = NULL, *next, *lim = NULL;
size_t needed;
- int mib[6];
+ int mib[7];
struct sockaddr *sa;
mib[0] = CTL_NET;
@@ -127,12 +126,14 @@ p_rttables(int af)
mib[3] = af;
mib[4] = NET_RT_DUMP;
mib[5] = 0;
- if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0)
+ mib[6] = tableid;
+
+ if (sysctl(mib, 7, NULL, &needed, NULL, 0) < 0)
err(1, "route-sysctl-estimate");
if (needed > 0) {
if ((buf = malloc(needed)) == 0)
err(1, NULL);
- if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0)
+ if (sysctl(mib, 7, buf, &needed, NULL, 0) < 0)
err(1, "sysctl of routing table");
lim = buf + needed;
}