| Summary: | Added a command-line switch to netstat to output the number of routes in the routing table. | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| Product: | Base System | Reporter: | Benjamin April <ben> | ||||||||
| Component: | bin | Assignee: | freebsd-bugs (Nobody) <bugs> | ||||||||
| Status: | Closed FIXED | ||||||||||
| Severity: | Affects Only Me | ||||||||||
| Priority: | Normal | ||||||||||
| Version: | 3.1-RELEASE | ||||||||||
| Hardware: | Any | ||||||||||
| OS: | Any | ||||||||||
| Attachments: |
|
||||||||||
Basicly runnign netstat -c is a faster version of netstat -rn|wc. -c follows about the same code path as -rn does but -c only outputs the total number of routes in each type(IP/appletak ect...) How-To-Repeat: N/A The diffs done correctly.
--- main.c.old Sat Jul 24 12:12:53 1999
+++ main.c Sun Jul 25 22:02:16 1999
@@ -221,7 +221,7 @@
af = AF_UNSPEC;
- while ((ch = getopt(argc, argv, "Aabdf:ghI:iM:mN:np:rstuw:")) !=
-1)
+ while ((ch = getopt(argc, argv, "Aabcdf:ghI:iM:mN:np:rstuw:"))
!= -1)
switch(ch) {
case 'A':
Aflag = 1;
@@ -232,6 +232,10 @@
case 'b':
bflag = 1;
break;
+ case 'c':
+ cflag = 1;
+ nflag = 1;
+ break;
case 'd':
dflag = 1;
break;
@@ -377,6 +381,11 @@
intpr(interval, nl[N_IFNET].n_value);
exit(0);
}
+ if (cflag) {
+ kread(0, 0, 0);
+ routecount(nl[N_RTREE].n_value);
+ exit(0);
+ }
if (rflag) {
kread(0, 0, 0);
if (sflag)
@@ -562,11 +571,12 @@
static void
usage()
{
- (void)fprintf(stderr, "%s\n%s\n%s\n%s\n",
+ (void)fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n",
"usage: netstat [-Aan] [-f address_family] [-M core] [-N system]",
" netstat [-bdghimnrs] [-f address_family] [-M core] [-N
system]",
" netstat [-bdn] [-I interface] [-M core] [-N system] [-w wait]",
-" netstat [-M core] [-N system] [-p protocol]");
+" netstat [-M core] [-N system] [-p protocol]",
+" netstat [-c]");
exit(1);
}
--- netstat.1.old Sat Jul 24 13:21:41 1999
+++ netstat.1 Mon Jul 26 07:52:39 1999
@@ -58,6 +58,8 @@
.Op Fl p Ar protocol
.Op Fl M Ar core
.Op Fl N Ar system
+.Nm netstat
+.Op Fl c
.Sh DESCRIPTION
The
.Nm netstat
@@ -92,6 +94,14 @@
.Fl i
, as described below),
show the number of bytes in and out.
+.It Fl c
+prints the number of routes in the kernel table to stdout.
+A faster equivlant to
+.Nm netstat
+.Fl rn
+|
+.Nm wc
+.Fl l
.It Fl d
With either interface display (option
.Fl i
--- route.c.old Sat Jul 24 12:10:49 1999
+++ route.c Sat Jul 24 14:16:41 1999
@@ -114,15 +114,18 @@
struct radix_node_head *rt_tables[AF_MAX+1];
int NewTree = 0;
+int total = 0;
static struct sockaddr *kgetsa __P((struct sockaddr *));
static void p_tree __P((struct radix_node *));
+static void c_tree __P((struct radix_node *));
static void p_rtnode __P((void));
static void ntreestuff __P((void));
static void np_rtentry __P((struct rt_msghdr *));
static void p_sockaddr __P((struct sockaddr *, struct sockaddr *, int,
int));
static void p_flags __P((int, char *));
static void p_rtentry __P((struct rtentry *));
+static void c_rtentry __P((struct rtentry *));
static u_long forgemask __P((u_long));
static void domask __P((char *, u_long, u_long));
@@ -877,4 +880,89 @@
*p += ('A' - 'a');
break;
}
+}
+
+void
+routecount(rtree)
+ u_long rtree;
+{
+ struct radix_node_head *rnh, head;
+ int i;
+
+ printf("Routing tables\n");
+
+ if (Aflag == 0 && NewTree)
+ ntreestuff();
+ else {
+ if (rtree == 0) {
+ printf("rt_tables: symbol not in namelist\n");
+ return;
+ }
+
+ kget(rtree, rt_tables);
+ 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) {
+ printf("Netmasks:\n");
+ c_tree(head.rnh_treetop);
+ }
+ } else if (af == AF_UNSPEC || af == i) {
+ pr_family(i);
+ do_rtent = 1;
+ total=0;
+ c_tree(head.rnh_treetop);
+ printf("%d Routes\n",total);
+ }
+ }
+ }
+}
+
+static void
+c_tree(rn)
+ struct radix_node *rn;
+{
+
+again:
+ kget(rn, rnode);
+ if (rnode.rn_b < 0) {
+ if (Aflag)
+ printf("%-8.8lx ", (u_long)rn);
+ if (rnode.rn_flags & RNF_ROOT) {
+ if (Aflag)
+ printf("(root node)%s",
+ rnode.rn_dupedkey ? " =>\n" :
"\n");
+ } else if (do_rtent) {
+ kget(rn, rtentry);
+ c_rtentry(&rtentry);
+ if (Aflag)
+ p_rtnode();
+ } else {
+ p_sockaddr(kgetsa((struct sockaddr
*)rnode.rn_key),
+ NULL, 0, 44);
+ putchar('\n');
+ }
+ if ((rn = rnode.rn_dupedkey))
+ goto again;
+ } else {
+ if (Aflag && do_rtent) {
+ printf("%-8.8lx ", (u_long)rn);
+ p_rtnode();
+ }
+ rn = rnode.rn_r;
+ c_tree(rnode.rn_l);
+ c_tree(rn);
+ }
+}
+
+
+static void
+c_rtentry(rt)
+ register struct rtentry *rt;
+{
+ if (!(rt->rt_parent && !aflag)) {
+ ++total;
+ }
}
State Changed From-To: open->closed Sorry, but this smells more like a bloat. |
On Sat, 31 Jul 1999, Benjamin April wrote: > *** main.c Sun Jul 25 22:02:16 1999 > --- ./main.c.old Sat Jul 24 12:12:53 1999 This patch is reversed.