Hi, While trying to determine how to print out routes via kvm for net-snmp, I noticed that there's a chunk of code from the 4.4 BSD Lite days that isn't executed in netstat as NewTree is always 0. The following patch removes that dead code and gets the FreeBSD source for netstat more in line with NetBSD and OpenBSD's copy. Thanks! -Garrett
Index: usr.bin/netstat/route.c =================================================================== --- usr.bin/netstat/route.c (revision 223824) +++ usr.bin/netstat/route.c (working copy) @@ -120,8 +120,6 @@ struct radix_mask rmask; struct radix_node_head **rt_tables; -int NewTree = 0; - struct timespec uptime; static struct sockaddr *kgetsa(struct sockaddr *); @@ -130,8 +128,6 @@ static void size_cols_rtentry(struct rtentry *rt); static void p_tree(struct radix_node *); static void p_rtnode(void); -static void ntreestuff(void); -static void np_rtentry(struct rt_msghdr *); static void p_sockaddr(struct sockaddr *, struct sockaddr *, int, int); static const char *fmt_sockaddr(struct sockaddr *sa, struct sockaddr *mask, int flags); @@ -170,46 +166,41 @@ printf("Routing tables\n"); - if (Aflag == 0 && NewTree) - ntreestuff(); - else { - if (rtree == 0) { - printf("rt_tables: symbol not in namelist\n"); - return; - } + if (rtree == 0) { + printf("rt_tables: symbol not in namelist\n"); + return; + } - 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; - if (i != AF_INET) - tmpfib = 0; - else - tmpfib = fibnum; - 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) { - if (Aflag && af == 0) { - printf("Netmasks:\n"); - p_tree(head.rnh_treetop); - } - } else if (af == AF_UNSPEC || af == i) { - size_cols(i, head.rnh_treetop); - pr_family(i); - do_rtent = 1; - pr_rthdr(i); + 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; + if (i != AF_INET) + tmpfib = 0; + else + tmpfib = fibnum; + 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) { + if (Aflag && af == 0) { + printf("Netmasks:\n"); p_tree(head.rnh_treetop); } + } else if (af == AF_UNSPEC || af == i) { + size_cols(i, head.rnh_treetop); + pr_family(i); + do_rtent = 1; + pr_rthdr(i); } } } @@ -513,76 +504,6 @@ } static void -ntreestuff(void) -{ - size_t needed; - int mib[6]; - char *buf, *next, *lim; - struct rt_msghdr *rtm; - - mib[0] = CTL_NET; - mib[1] = PF_ROUTE; - mib[2] = 0; - mib[3] = 0; - mib[4] = NET_RT_DUMP; - mib[5] = 0; - if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0) { - err(1, "sysctl: net.route.0.0.dump estimate"); - } - - if ((buf = malloc(needed)) == 0) { - errx(2, "malloc(%lu)", (unsigned long)needed); - } - if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0) { - err(1, "sysctl: net.route.0.0.dump"); - } - lim = buf + needed; - for (next = buf; next < lim; next += rtm->rtm_msglen) { - rtm = (struct rt_msghdr *)next; - np_rtentry(rtm); - } -} - -static void -np_rtentry(struct rt_msghdr *rtm) -{ - struct sockaddr *sa = (struct sockaddr *)(rtm + 1); -#ifdef notdef - static int masks_done, banner_printed; -#endif - static int old_af; - int af1 = 0, interesting = RTF_UP | RTF_GATEWAY | RTF_HOST; - -#ifdef notdef - /* for the moment, netmasks are skipped over */ - if (!banner_printed) { - printf("Netmasks:\n"); - banner_printed = 1; - } - if (masks_done == 0) { - if (rtm->rtm_addrs != RTA_DST ) { - masks_done = 1; - af1 = sa->sa_family; - } - } else -#endif - af1 = sa->sa_family; - if (af1 != old_af) { - pr_family(af1); - old_af = af1; - } - if (rtm->rtm_addrs == RTA_DST) - p_sockaddr(sa, NULL, 0, 36); - else { - p_sockaddr(sa, NULL, rtm->rtm_flags, 16); - sa = (struct sockaddr *)(SA_SIZE(sa) + (char *)sa); - p_sockaddr(sa, NULL, 0, 18); - } - p_flags(rtm->rtm_flags & interesting, "%-6.6s "); - putchar('\n'); -} - -static void p_sockaddr(struct sockaddr *sa, struct sockaddr *mask, int flags, int width) { const char *cp;
_______________________________________________ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"