diff options
author | Bjoern A. Zeeb <bz@FreeBSD.org> | 2009-06-01 15:49:42 +0000 |
---|---|---|
committer | Bjoern A. Zeeb <bz@FreeBSD.org> | 2009-06-01 15:49:42 +0000 |
commit | c2c2a7c11ee7cdc9d33dc3cdabff4a25dbcbca13 (patch) | |
tree | 743a83cdd0c6416f952293952e112bd315518157 /usr.bin/netstat | |
parent | b01c90a31af487bfb796c57b6f199eae730939fd (diff) | |
download | src-c2c2a7c11ee7cdc9d33dc3cdabff4a25dbcbca13.tar.gz src-c2c2a7c11ee7cdc9d33dc3cdabff4a25dbcbca13.zip |
Convert the two dimensional array to be malloced and introduce
an accessor function to get the correct rnh pointer back.
Update netstat to get the correct pointer using kvm_read()
as well.
This not only fixes the ABI problem depending on the kernel
option but also permits the tunable to overwrite the kernel
option at boot time up to MAXFIBS, enlarging the number of
FIBs without having to recompile. So people could just use
GENERIC now.
Reviewed by: julian, rwatson, zec
X-MFC: not possible
Notes
Notes:
svn path=/head/; revision=193232
Diffstat (limited to 'usr.bin/netstat')
-rw-r--r-- | usr.bin/netstat/route.c | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/usr.bin/netstat/route.c b/usr.bin/netstat/route.c index 596fcd5eccc0..735612b867a9 100644 --- a/usr.bin/netstat/route.c +++ b/usr.bin/netstat/route.c @@ -122,12 +122,7 @@ int do_rtent = 0; struct rtentry rtentry; struct radix_node rnode; struct radix_mask rmask; -struct rtline { - struct radix_node_head *tables[AF_MAX+1]; /*xxx*/ -}; -struct rtline *rt_tables; - -struct radix_node_head *rt_tables_line[1][AF_MAX+1]; /*xxx*/ +struct radix_node_head **rt_tables; int NewTree = 0; @@ -155,7 +150,7 @@ static void domask(char *, in_addr_t, u_long); void routepr(u_long rtree) { - struct radix_node_head *rnh, head; + struct radix_node_head **rnhp, *rnh, head; size_t intsize; int i; int numfibs; @@ -165,7 +160,8 @@ routepr(u_long rtree) fibnum = 0; if (sysctlbyname("net.fibs", &numfibs, &intsize, NULL, 0) == -1) numfibs = 1; - rt_tables = calloc(numfibs, sizeof(struct rtline)); + rt_tables = calloc(numfibs * (AF_MAX+1), + sizeof(struct radix_node_head *)); if (rt_tables == NULL) err(EX_OSERR, "memory allocation failed"); /* @@ -186,8 +182,8 @@ routepr(u_long rtree) return; } - if (kread((u_long)(rtree), (char *)(rt_tables), - (numfibs * sizeof(struct rtline))) != 0) + if (kread((u_long)(rtree), (char *)(rt_tables), (numfibs * + (AF_MAX+1) * sizeof(struct radix_node_head *))) != 0) return; for (i = 0; i <= AF_MAX; i++) { int tmpfib; @@ -195,8 +191,15 @@ routepr(u_long rtree) tmpfib = 0; else tmpfib = fibnum; - if ((rnh = rt_tables[tmpfib].tables[i]) == 0) + rnhp = (struct radix_node_head **)*rt_tables; + /* Calculate the in-kernel address. */ + rnhp += tmpfib * (AF_MAX+1) + i; + /* Read the in kernel rhn pointer. */ + if (kget(rnhp, rnh) != 0) + continue; + if (rnh == NULL) continue; + /* Read the rnh data. */ if (kget(rnh, head) != 0) continue; if (i == AF_UNSPEC) { |