summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorclaudio <claudio@openbsd.org>2006-08-29 21:51:13 +0000
committerclaudio <claudio@openbsd.org>2006-08-29 21:51:13 +0000
commit0dad96934e5acb87924cfae22fe01d7af4191ba7 (patch)
treefeae6ba7da510fa442282af69f811666176f3ec0
parentfix output location of truncated files test (diff)
downloadwireguard-openbsd-0dad96934e5acb87924cfae22fe01d7af4191ba7.tar.xz
wireguard-openbsd-0dad96934e5acb87924cfae22fe01d7af4191ba7.zip
Fix KVM snooping code of netstat that got broken by the multiple table
"support". This makes netstat -A work again. OK markus@ henning@
-rw-r--r--usr.bin/netstat/main.c15
-rw-r--r--usr.bin/netstat/netstat.h4
-rw-r--r--usr.bin/netstat/route.c51
3 files changed, 53 insertions, 17 deletions
diff --git a/usr.bin/netstat/main.c b/usr.bin/netstat/main.c
index d743d41c3b6..aa0b3c92ccc 100644
--- a/usr.bin/netstat/main.c
+++ b/usr.bin/netstat/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.62 2006/05/27 19:16:37 claudio Exp $ */
+/* $OpenBSD: main.c,v 1.63 2006/08/29 21:51:13 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.62 2006/05/27 19:16:37 claudio Exp $";
+static char *rcsid = "$OpenBSD: main.c,v 1.63 2006/08/29 21:51:13 claudio Exp $";
#endif
#endif /* not lint */
@@ -152,6 +152,12 @@ struct nlist nl[] = {
{ "_pfsyncstats" },
#define N_PIMSTAT 42
{ "_pimstat" },
+#define N_AF2RTAFIDX 43
+ { "_af2rtafidx" },
+#define N_RTBLIDMAX 44
+ { "_rtbl_id_max" },
+#define N_RTMASK 45
+ { "_mask_rnhead" },
{ ""}
};
@@ -290,6 +296,8 @@ main(int argc, char *argv[])
af = PF_KEY;
else if (strcmp(optarg, "atalk") == 0)
af = AF_APPLETALK;
+ else if (strcmp(optarg, "mask") == 0)
+ af = 0xff;
else {
(void)fprintf(stderr,
"%s: %s: unknown address family\n",
@@ -477,7 +485,8 @@ main(int argc, char *argv[])
if (sflag)
rt_stats(0, nl[N_RTSTAT].n_value);
else
- routepr(nl[N_RTREE].n_value);
+ routepr(nl[N_RTREE].n_value, nl[N_RTMASK].n_value,
+ nl[N_AF2RTAFIDX].n_value, nl[N_RTBLIDMAX].n_value);
exit(0);
}
if (gflag) {
diff --git a/usr.bin/netstat/netstat.h b/usr.bin/netstat/netstat.h
index 9a7698ef0d7..2b724ff6e48 100644
--- a/usr.bin/netstat/netstat.h
+++ b/usr.bin/netstat/netstat.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: netstat.h,v 1.38 2006/07/05 00:40:22 brad Exp $ */
+/* $OpenBSD: netstat.h,v 1.39 2006/08/29 21:51:13 claudio Exp $ */
/* $NetBSD: netstat.h,v 1.6 1996/05/07 02:55:05 thorpej Exp $ */
/*
@@ -127,7 +127,7 @@ char *routename4(in_addr_t);
char *netname(struct sockaddr *, struct sockaddr *);
char *netname4(in_addr_t, in_addr_t);
char *ipx_print(struct sockaddr *);
-void routepr(u_long);
+void routepr(u_long, u_long, u_long, u_long);
void nsprotopr(u_long, char *);
void spp_stats(u_long, char *);
diff --git a/usr.bin/netstat/route.c b/usr.bin/netstat/route.c
index 86072fd2756..c0688220b0b 100644
--- a/usr.bin/netstat/route.c
+++ b/usr.bin/netstat/route.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: route.c,v 1.72 2006/05/27 19:16:37 claudio Exp $ */
+/* $OpenBSD: route.c,v 1.73 2006/08/29 21:51:13 claudio Exp $ */
/* $NetBSD: route.c,v 1.15 1996/05/07 02:55:06 thorpej Exp $ */
/*
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "from: @(#)route.c 8.3 (Berkeley) 3/9/94";
#else
-static char *rcsid = "$OpenBSD: route.c,v 1.72 2006/05/27 19:16:37 claudio Exp $";
+static char *rcsid = "$OpenBSD: route.c,v 1.73 2006/08/29 21:51:13 claudio Exp $";
#endif
#endif /* not lint */
@@ -76,7 +76,10 @@ static char *rcsid = "$OpenBSD: route.c,v 1.72 2006/05/27 19:16:37 claudio Exp $
((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
#define ADVANCE(x, n) (x += ROUNDUP((n)->sa_len))
-struct radix_node_head *rt_tables[AF_MAX+1];
+struct radix_node_head ***rt_head;
+struct radix_node_head ***rnt; /* provides enough space */
+struct radix_node_head *rt_tables[AF_MAX+1]; /* provides enough space */
+u_int8_t af2rtafidx[AF_MAX+1];
static union {
struct sockaddr u_sa;
@@ -100,29 +103,53 @@ static void encap_print(struct rtentry *);
* Print routing tables.
*/
void
-routepr(u_long rtree)
+routepr(u_long rtree, u_long mtree, u_long af2idx, u_long rtbl_id_max)
{
struct radix_node_head *rnh, head;
- int i;
+ int i, idxmax = 0;
+ u_int rtidxmax;
printf("Routing tables\n");
- if (rtree == 0) {
+ if (rtree == 0 || af2idx == 0) {
printf("rt_tables: symbol not in namelist\n");
return;
}
- kget(rtree, rt_tables);
+ kget(rtree, rt_head);
+ kget(rtbl_id_max, rtidxmax);
+ kget(af2idx, af2rtafidx);
+
+ for (i = 0; i <= AF_MAX; i++) {
+ if (af2rtafidx[i] > idxmax)
+ idxmax = af2rtafidx[i];
+ }
+
+ if ((rnt = calloc(rtidxmax + 1, sizeof(struct radix_node_head **))) ==
+ NULL)
+ err(1, NULL);
+
+ kread((u_long)rt_head, rnt, (rtidxmax + 1) *
+ sizeof(struct radix_node_head **));
+ kread((u_long)rnt[0], rt_tables, (idxmax + 1) * sizeof(rnh));
+
for (i = 0; i <= AF_MAX; i++) {
- if ((rnh = rt_tables[i]) == 0)
- continue;
- kget(rnh, head);
if (i == AF_UNSPEC) {
- if (Aflag && (af == 0 || af == 0xff)) {
+ if (Aflag && (af == AF_UNSPEC || af == 0xff)) {
+ kget(mtree, rnh);
+ kget(rnh, head);
printf("Netmasks:\n");
p_tree(head.rnh_treetop);
}
- } else if (af == AF_UNSPEC || af == i) {
+ continue;
+ }
+ if (af2rtafidx[i] == 0)
+ /* no table for this AF */
+ continue;
+ if ((rnh = rt_tables[af2rtafidx[i]]) == 0)
+ continue;
+ kget(rnh, head);
+ if (af == AF_UNSPEC || af == i) {
pr_family(i);
do_rtent = 1;
pr_rthdr(i, Aflag);