summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudio Jeker <claudio@cvs.openbsd.org>2007-12-19 08:49:24 +0000
committerClaudio Jeker <claudio@cvs.openbsd.org>2007-12-19 08:49:24 +0000
commitfdcad8977d034d7477cd7aba570a3b7b41adfc22 (patch)
tree1d01c44e3be93450d4f3573114a57f2b7f46ed2a
parent4a22d11d475ee19787ed5bb5525aa71e344eddb2 (diff)
Remove the kvm code in rt_stats() and use the sysctl code all the time.
While there remove the ugly rflag checks and make it more consistent with the rest of the code. Another step in making netstat setgid free. OK deraadt@
-rw-r--r--usr.bin/netstat/main.c22
-rw-r--r--usr.bin/netstat/netstat.h4
-rw-r--r--usr.bin/netstat/route.c34
3 files changed, 22 insertions, 38 deletions
diff --git a/usr.bin/netstat/main.c b/usr.bin/netstat/main.c
index 76734f0c8f4..038df34494e 100644
--- a/usr.bin/netstat/main.c
+++ b/usr.bin/netstat/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.72 2007/12/19 01:47:00 deraadt Exp $ */
+/* $OpenBSD: main.c,v 1.73 2007/12/19 08:49:23 claudio Exp $ */
/* $NetBSD: main.c,v 1.9 1996/05/07 02:55:02 thorpej Exp $ */
/*
@@ -90,9 +90,6 @@ struct nlist nl[] = {
#define N_RAWIP6TABLE 15
{ "_rawin6pcbtable" },
-#define N_RTSTAT 16
- { "_rtstat" },
-
{ ""}
};
@@ -305,16 +302,7 @@ main(int argc, char *argv[])
if (nlistf != NULL || memf != NULL || Pflag)
if (setresgid(gid, gid, gid) == -1)
err(1, "setresgid");
- if (nlistf == NULL && memf == NULL && rflag && !Aflag) {
- /* printing the routing table no longer needs kvm */
- if (setresgid(gid, gid, gid) == -1)
- err(1, "setresgid");
- if (sflag)
- rt_stats(1, 0);
- else
- p_rttables(af, tableid);
- exit(0);
- }
+
if ((kvmd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY,
buf)) == NULL) {
fprintf(stderr, "%s: kvm_open: %s\n", __progname, buf);
@@ -383,10 +371,12 @@ main(int argc, char *argv[])
}
if (rflag) {
if (sflag)
- rt_stats(0, nl[N_RTSTAT].n_value);
- else
+ rt_stats();
+ else if (Aflag || nlistf != NULL || memf != NULL)
routepr(nl[N_RTREE].n_value, nl[N_RTMASK].n_value,
nl[N_AF2RTAFIDX].n_value, nl[N_RTBLIDMAX].n_value);
+ else
+ p_rttables(af, tableid);
exit(0);
}
if (gflag) {
diff --git a/usr.bin/netstat/netstat.h b/usr.bin/netstat/netstat.h
index d8abfe8baa9..37b57699af2 100644
--- a/usr.bin/netstat/netstat.h
+++ b/usr.bin/netstat/netstat.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: netstat.h,v 1.45 2007/12/14 18:35:46 deraadt Exp $ */
+/* $OpenBSD: netstat.h,v 1.46 2007/12/19 08:49:23 claudio Exp $ */
/* $NetBSD: netstat.h,v 1.6 1996/05/07 02:55:05 thorpej Exp $ */
/*
@@ -96,7 +96,7 @@ void mbpr(void);
void hostpr(u_long, u_long);
void impstats(u_long, u_long);
-void rt_stats(int, u_long);
+void rt_stats(void);
void pr_rthdr(int, int);
void pr_encaphdr(void);
void pr_family(int);
diff --git a/usr.bin/netstat/route.c b/usr.bin/netstat/route.c
index c549ce118eb..686fc33c302 100644
--- a/usr.bin/netstat/route.c
+++ b/usr.bin/netstat/route.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: route.c,v 1.77 2007/12/19 01:47:00 deraadt Exp $ */
+/* $OpenBSD: route.c,v 1.78 2007/12/19 08:49:23 claudio Exp $ */
/* $NetBSD: route.c,v 1.15 1996/05/07 02:55:06 thorpej Exp $ */
/*
@@ -311,30 +311,24 @@ p_krtentry(struct rtentry *rt)
* Print routing statistics
*/
void
-rt_stats(int usesysctl, u_long off)
+rt_stats(void)
{
struct rtstat rtstat;
int mib[6];
size_t size;
- if (usesysctl) {
- mib[0] = CTL_NET;
- mib[1] = PF_ROUTE;
- mib[2] = 0;
- mib[3] = 0;
- mib[4] = NET_RT_STATS;
- mib[5] = 0;
- size = sizeof (rtstat);
-
- if (sysctl(mib, 6, &rtstat, &size, NULL, 0) < 0) {
- perror("sysctl of routing table statistics");
- exit(1);
- }
- } else if (off == 0) {
- printf("rtstat: symbol not in namelist\n");
- return;
- } else
- kread(off, &rtstat, sizeof (rtstat));
+ mib[0] = CTL_NET;
+ mib[1] = PF_ROUTE;
+ mib[2] = 0;
+ mib[3] = 0;
+ mib[4] = NET_RT_STATS;
+ mib[5] = 0;
+ size = sizeof (rtstat);
+
+ if (sysctl(mib, 6, &rtstat, &size, NULL, 0) < 0) {
+ perror("sysctl of routing table statistics");
+ exit(1);
+ }
printf("routing:\n");
printf("\t%u bad routing redirect%s\n",