Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src Add netstat rump client. For now, it always sets -X, i.e. will
details: https://anonhg.NetBSD.org/src/rev/b300ff0f9263
branches: trunk
changeset: 759618:b300ff0f9263
user: pooka <pooka%NetBSD.org@localhost>
date: Mon Dec 13 21:15:30 2010 +0000
description:
Add netstat rump client. For now, it always sets -X, i.e. will
use only sysctl and no kvm (implementing /dev/mem for a rump kernel
would probably not be hard, but still a non-zero effort).
Note: since there is absolutely no network activity in a fresh rump
kernel, rump.netstat usually displays exactly nothing when invoked
without parameters. Arguments like -r, -bi, -p icmp etc. produce
more stuff.
diffstat:
distrib/sets/lists/base/mi | 3 +-
distrib/sets/lists/comp/mi | 3 +-
usr.bin/netstat/Makefile | 10 ++++++-
usr.bin/netstat/bpf.c | 8 ++++--
usr.bin/netstat/if.c | 13 +++++-----
usr.bin/netstat/inet.c | 13 +++++-----
usr.bin/netstat/inet6.c | 11 +++++----
usr.bin/netstat/main.c | 11 +++++++-
usr.bin/netstat/mbuf.c | 17 ++++++++-----
usr.bin/netstat/netstat_hostops.c | 41 ++++++++++++++++++++++++++++++++++
usr.bin/netstat/netstat_rumpops.c | 46 +++++++++++++++++++++++++++++++++++++++
usr.bin/netstat/prog_ops.h | 45 ++++++++++++++++++++++++++++++++++++++
usr.bin/netstat/show.c | 11 +++++----
usr.bin/netstat/unix.c | 11 +++++----
14 files changed, 200 insertions(+), 43 deletions(-)
diffs (truncated from 586 to 300 lines):
diff -r a2d44fb4ad03 -r b300ff0f9263 distrib/sets/lists/base/mi
--- a/distrib/sets/lists/base/mi Mon Dec 13 21:08:37 2010 +0000
+++ b/distrib/sets/lists/base/mi Mon Dec 13 21:15:30 2010 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.903 2010/12/13 20:51:11 pooka Exp $
+# $NetBSD: mi,v 1.904 2010/12/13 21:15:30 pooka Exp $
#
# Note: Don't delete entries from here - mark them as "obsolete" instead,
# unless otherwise stated below.
@@ -534,6 +534,7 @@
./usr/bin/netpgpkeys base-crypto-bin crypto
./usr/bin/netpgpverify base-crypto-bin crypto
./usr/bin/netstat base-netutil-bin
+./usr/bin/rump.netstat base-netutil-bin
./usr/bin/newaliases base-mailwrapper-bin
./usr/bin/newgrp base-util-bin
./usr/bin/newsyslog base-util-bin
diff -r a2d44fb4ad03 -r b300ff0f9263 distrib/sets/lists/comp/mi
--- a/distrib/sets/lists/comp/mi Mon Dec 13 21:08:37 2010 +0000
+++ b/distrib/sets/lists/comp/mi Mon Dec 13 21:15:30 2010 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1540 2010/12/13 20:51:11 pooka Exp $
+# $NetBSD: mi,v 1.1541 2010/12/13 21:15:30 pooka Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@@ -3271,6 +3271,7 @@
./usr/libdata/debug/usr/bin/netpgpkeys.debug comp-crypto-debug crypto,debug
./usr/libdata/debug/usr/bin/netpgpverify.debug comp-crypto-debug crypto,debug
./usr/libdata/debug/usr/bin/netstat.debug comp-netutil-debug debug
+./usr/libdata/debug/usr/bin/rump.netstat.debug comp-netutil-debug debug
./usr/libdata/debug/usr/bin/newgrp.debug comp-util-debug debug
./usr/libdata/debug/usr/bin/newsyslog.debug comp-util-debug debug
./usr/libdata/debug/usr/bin/nfsstat.debug comp-nfsclient-debug debug
diff -r a2d44fb4ad03 -r b300ff0f9263 usr.bin/netstat/Makefile
--- a/usr.bin/netstat/Makefile Mon Dec 13 21:08:37 2010 +0000
+++ b/usr.bin/netstat/Makefile Mon Dec 13 21:15:30 2010 +0000
@@ -1,11 +1,11 @@
-# $NetBSD: Makefile,v 1.29 2009/09/14 10:36:50 degroote Exp $
+# $NetBSD: Makefile,v 1.30 2010/12/13 21:15:30 pooka Exp $
# from: @(#)Makefile 8.1 (Berkeley) 6/12/93
.include <bsd.own.mk>
USE_FORT?= yes # setgid
-PROG= netstat
+RUMPPRG=netstat
SRCS= atalk.c bpf.c fast_ipsec.c if.c inet.c inet6.c ipsec.c iso.c \
main.c mbuf.c mroute.c mroute6.c show.c route.c tp_astring.c \
unix.c
@@ -17,6 +17,12 @@
CPPFLAGS+= -DIPSEC
CPPFLAGS+= -I${NETBSDSRCDIR}/sys/dist/pf
+.PATH: ${.CURDIR}/../../lib/libc/gen
+.PATH: ${.CURDIR}/../../lib/libc/net
+CPPFLAGS+= -DRUMP_ACTION
+RUMPSRCS+= sysctlbyname.c sysctlgetmibinfo.c sysctlnametomib.c
+RUMPSRCS+= if_indextoname.c getifaddrs.c
+
.if (${USE_INET6} != "no")
CPPFLAGS+= -DINET6
.endif
diff -r a2d44fb4ad03 -r b300ff0f9263 usr.bin/netstat/bpf.c
--- a/usr.bin/netstat/bpf.c Mon Dec 13 21:08:37 2010 +0000
+++ b/usr.bin/netstat/bpf.c Mon Dec 13 21:15:30 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: bpf.c,v 1.9 2009/04/12 16:08:37 lukem Exp $ */
+/* $NetBSD: bpf.c,v 1.10 2010/12/13 21:15:30 pooka Exp $ */
/*
* Copyright (c) 2005 The NetBSD Foundation, Inc.
@@ -44,6 +44,7 @@
#include <net/bpfdesc.h>
#include <net/bpf.h>
#include "netstat.h"
+#include "prog_ops.h"
void
bpf_stats(void)
@@ -92,7 +93,8 @@
v = NULL;
sz = 0;
do {
- rc = sysctl(&name[0], namelen, v, &sz, NULL, 0);
+ rc = prog_sysctl(&name[0], namelen,
+ v, &sz, NULL, 0);
if (rc == -1 && errno != ENOMEM)
err(1, "sysctl: net.bpf.peers");
if (rc == -1 && v != NULL) {
@@ -158,7 +160,7 @@
name[namelen++] = szproc;
name[namelen++] = 1;
- if (sysctl(&name[0], namelen, &p, &szproc,
+ if (prog_sysctl(&name[0], namelen, &p, &szproc,
NULL, 0) == -1)
printf("-\n");
else
diff -r a2d44fb4ad03 -r b300ff0f9263 usr.bin/netstat/if.c
--- a/usr.bin/netstat/if.c Mon Dec 13 21:08:37 2010 +0000
+++ b/usr.bin/netstat/if.c Mon Dec 13 21:15:30 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if.c,v 1.69 2010/07/09 07:04:30 enami Exp $ */
+/* $NetBSD: if.c,v 1.70 2010/12/13 21:15:30 pooka Exp $ */
/*
* Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "from: @(#)if.c 8.2 (Berkeley) 2/21/94";
#else
-__RCSID("$NetBSD: if.c,v 1.69 2010/07/09 07:04:30 enami Exp $");
+__RCSID("$NetBSD: if.c,v 1.70 2010/12/13 21:15:30 pooka Exp $");
#endif
#endif /* not lint */
@@ -65,6 +65,7 @@
#include <err.h>
#include "netstat.h"
+#include "prog_ops.h"
#define MAXIF 100
@@ -163,11 +164,11 @@
size_t len;
char name[IFNAMSIZ + 1]; /* + 1 for `*' */
- if (sysctl(mib, 6, NULL, &len, NULL, 0) == -1)
+ if (prog_sysctl(mib, 6, NULL, &len, NULL, 0) == -1)
err(1, "sysctl");
if ((buf = malloc(len)) == NULL)
err(1, NULL);
- if (sysctl(mib, 6, buf, &len, NULL, 0) == -1)
+ if (prog_sysctl(mib, 6, buf, &len, NULL, 0) == -1)
err(1, "sysctl");
intpr_header();
@@ -983,11 +984,11 @@
char name[IFNAMSIZ];
size_t len;
- if (sysctl(mib, 6, NULL, &len, NULL, 0) == -1)
+ if (prog_sysctl(mib, 6, NULL, &len, NULL, 0) == -1)
err(1, "sysctl");
if ((buf = malloc(len)) == NULL)
err(1, NULL);
- if (sysctl(mib, 6, buf, &len, NULL, 0) == -1)
+ if (prog_sysctl(mib, 6, buf, &len, NULL, 0) == -1)
err(1, "sysctl");
lim = buf + len;
diff -r a2d44fb4ad03 -r b300ff0f9263 usr.bin/netstat/inet.c
--- a/usr.bin/netstat/inet.c Mon Dec 13 21:08:37 2010 +0000
+++ b/usr.bin/netstat/inet.c Mon Dec 13 21:15:30 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: inet.c,v 1.92 2009/12/07 18:48:45 christos Exp $ */
+/* $NetBSD: inet.c,v 1.93 2010/12/13 21:15:30 pooka Exp $ */
/*
* Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "from: @(#)inet.c 8.4 (Berkeley) 4/20/94";
#else
-__RCSID("$NetBSD: inet.c,v 1.92 2009/12/07 18:48:45 christos Exp $");
+__RCSID("$NetBSD: inet.c,v 1.93 2010/12/13 21:15:30 pooka Exp $");
#endif
#endif /* not lint */
@@ -88,6 +88,7 @@
#include <stdlib.h>
#include <err.h>
#include "netstat.h"
+#include "prog_ops.h"
char *inetname(struct in_addr *);
void inetprint(struct in_addr *, u_int16_t, const char *, int);
@@ -194,8 +195,8 @@
if (sysctlnametomib(mibname, mib, &namelen) == -1)
err(1, "sysctlnametomib: %s", mibname);
- if (sysctl(mib, sizeof(mib) / sizeof(*mib), NULL, &size,
- NULL, 0) == -1)
+ if (prog_sysctl(mib, sizeof(mib) / sizeof(*mib),
+ NULL, &size, NULL, 0) == -1)
err(1, "sysctl (query)");
if ((pcblist = malloc(size)) == NULL)
@@ -205,8 +206,8 @@
mib[6] = sizeof(*pcblist);
mib[7] = size / sizeof(*pcblist);
- if (sysctl(mib, sizeof(mib) / sizeof(*mib), pcblist,
- &size, NULL, 0) == -1)
+ if (prog_sysctl(mib, sizeof(mib) / sizeof(*mib),
+ pcblist, &size, NULL, 0) == -1)
err(1, "sysctl (copy)");
for (i = 0; i < size / sizeof(*pcblist); i++) {
diff -r a2d44fb4ad03 -r b300ff0f9263 usr.bin/netstat/inet6.c
--- a/usr.bin/netstat/inet6.c Mon Dec 13 21:08:37 2010 +0000
+++ b/usr.bin/netstat/inet6.c Mon Dec 13 21:15:30 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: inet6.c,v 1.52 2009/04/12 16:08:37 lukem Exp $ */
+/* $NetBSD: inet6.c,v 1.53 2010/12/13 21:15:30 pooka Exp $ */
/* BSDI inet.c,v 2.3 1995/10/24 02:19:29 prb Exp */
/*
@@ -64,7 +64,7 @@
#if 0
static char sccsid[] = "@(#)inet.c 8.4 (Berkeley) 4/20/94";
#else
-__RCSID("$NetBSD: inet6.c,v 1.52 2009/04/12 16:08:37 lukem Exp $");
+__RCSID("$NetBSD: inet6.c,v 1.53 2010/12/13 21:15:30 pooka Exp $");
#endif
#endif /* not lint */
@@ -129,6 +129,7 @@
#include <string.h>
#include <unistd.h>
#include "netstat.h"
+#include "prog_ops.h"
#ifdef INET6
@@ -252,8 +253,8 @@
err(1, "sysctlnametomib: %s", mibname);
}
- if (sysctl(mib, sizeof(mib) / sizeof(*mib), NULL, &size,
- NULL, 0) == -1)
+ if (prog_sysctl(mib, sizeof(mib) / sizeof(*mib),
+ NULL, &size, NULL, 0) == -1)
err(1, "sysctl (query)");
if ((pcblist = malloc(size)) == NULL)
@@ -263,7 +264,7 @@
mib[6] = sizeof(*pcblist);
mib[7] = size / sizeof(*pcblist);
- if (sysctl(mib, sizeof(mib) / sizeof(*mib), pcblist,
+ if (prog_sysctl(mib, sizeof(mib) / sizeof(*mib), pcblist,
&size, NULL, 0) == -1)
err(1, "sysctl (copy)");
diff -r a2d44fb4ad03 -r b300ff0f9263 usr.bin/netstat/main.c
--- a/usr.bin/netstat/main.c Mon Dec 13 21:08:37 2010 +0000
+++ b/usr.bin/netstat/main.c Mon Dec 13 21:15:30 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.76 2010/06/29 12:38:12 kefren Exp $ */
+/* $NetBSD: main.c,v 1.77 2010/12/13 21:15:30 pooka 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.76 2010/06/29 12:38:12 kefren Exp $");
+__RCSID("$NetBSD: main.c,v 1.77 2010/12/13 21:15:30 pooka Exp $");
#endif
#endif /* not lint */
@@ -64,6 +64,7 @@
#include <string.h>
#include <unistd.h>
#include "netstat.h"
+#include "prog_ops.h"
struct nlist nl[] = {
#define N_MBSTAT 0
@@ -422,6 +423,12 @@
char *cp;
u_long pcbaddr;
+ if (prog_init) {
+ if (prog_init() == -1)
+ err(1, "init failed");
+ force_sysctl = 1; /* cheap trick */
+ }
+
egid = getegid();
(void)setegid(getgid());
tp = NULL;
diff -r a2d44fb4ad03 -r b300ff0f9263 usr.bin/netstat/mbuf.c
--- a/usr.bin/netstat/mbuf.c Mon Dec 13 21:08:37 2010 +0000
+++ b/usr.bin/netstat/mbuf.c Mon Dec 13 21:15:30 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mbuf.c,v 1.29 2009/04/12 16:08:37 lukem Exp $ */
+/* $NetBSD: mbuf.c,v 1.30 2010/12/13 21:15:30 pooka Exp $ */
/*
* Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "from: @(#)mbuf.c 8.1 (Berkeley) 6/6/93";
#else
Home |
Main Index |
Thread Index |
Old Index