diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2007-12-14 18:35:47 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2007-12-14 18:35:47 +0000 |
commit | ce45fd275665d6471b8c9fbeeb283d1b1aea4beb (patch) | |
tree | 1bea19ae8cc3a620014e7a91f0beaf04c677fee2 /usr.bin | |
parent | 3d4f2590efbb3139894368b615391ed13bc12ad1 (diff) |
remove 21 nlist variables, and instead use sysctl to query the kernel
turn on INET6 the default (remove the #ifdef's)
ok claudio reyk
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/netstat/Makefile | 7 | ||||
-rw-r--r-- | usr.bin/netstat/atalk.c | 18 | ||||
-rw-r--r-- | usr.bin/netstat/if.c | 10 | ||||
-rw-r--r-- | usr.bin/netstat/inet.c | 188 | ||||
-rw-r--r-- | usr.bin/netstat/inet6.c | 60 | ||||
-rw-r--r-- | usr.bin/netstat/main.c | 222 | ||||
-rw-r--r-- | usr.bin/netstat/mroute.c | 55 | ||||
-rw-r--r-- | usr.bin/netstat/mroute6.c | 119 | ||||
-rw-r--r-- | usr.bin/netstat/netstat.h | 63 | ||||
-rw-r--r-- | usr.bin/netstat/route.c | 11 | ||||
-rw-r--r-- | usr.bin/netstat/show.c | 4 |
11 files changed, 343 insertions, 414 deletions
diff --git a/usr.bin/netstat/Makefile b/usr.bin/netstat/Makefile index c0e99be5a5c..cb1f81d8324 100644 --- a/usr.bin/netstat/Makefile +++ b/usr.bin/netstat/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.18 2007/06/04 12:20:24 henning Exp $ +# $OpenBSD: Makefile,v 1.19 2007/12/14 18:35:46 deraadt Exp $ PROG= netstat SRCS= if.c inet.c inet6.c main.c mbuf.c mroute.c route.c \ @@ -7,10 +7,5 @@ BINGRP= kmem BINMODE=2555 LDADD= -lkvm DPADD= ${LIBKVM} -INET6?= yes - -.if (${INET6} != "no") -CPPFLAGS+= -DINET6 -.endif .include <bsd.prog.mk> diff --git a/usr.bin/netstat/atalk.c b/usr.bin/netstat/atalk.c index 48ebeb7e3a7..e989ff5b82e 100644 --- a/usr.bin/netstat/atalk.c +++ b/usr.bin/netstat/atalk.c @@ -1,4 +1,4 @@ -/* $OpenBSD: atalk.c,v 1.14 2005/03/30 06:45:34 deraadt Exp $ */ +/* $OpenBSD: atalk.c,v 1.15 2007/12/14 18:35:46 deraadt Exp $ */ /* $NetBSD: atalk.c,v 1.2 1997/05/22 17:21:26 christos Exp $ */ /* @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "from @(#)atalk.c 1.1 (Whistle) 6/6/96"; #else -static char rcsid[] = "$OpenBSD: atalk.c,v 1.14 2005/03/30 06:45:34 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: atalk.c,v 1.15 2007/12/14 18:35:46 deraadt Exp $"; #endif #endif /* not lint */ @@ -44,6 +44,7 @@ static char rcsid[] = "$OpenBSD: atalk.c,v 1.14 2005/03/30 06:45:34 deraadt Exp #include <sys/socketvar.h> #include <sys/mbuf.h> #include <sys/protosw.h> +#include <sys/sysctl.h> #include <netdb.h> #include <net/route.h> @@ -305,14 +306,19 @@ atalkprotopr(u_long off, char *name) * Dump DDP statistics structure. */ void -ddp_stats(u_long off, char *name) +ddp_stats(char *name) { struct ddpstat ddpstat; + int mib[] = { CTL_NET, AF_APPLETALK, ATPROTO_DDP, DDPCTL_STATS }; + size_t len = sizeof(ddpstat); - if (off == 0) - return; - if (kread(off, &ddpstat, sizeof(ddpstat)) < 0) + if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), + &ddpstat, &len, NULL, 0) == -1) { + if (errno != ENOPROTOOPT) + warn(name); return; + } + printf("%s:\n", name); p(ddps_short, "\t%ld packet%s with short headers\n"); p(ddps_long, "\t%ld packet%s with long headers\n"); diff --git a/usr.bin/netstat/if.c b/usr.bin/netstat/if.c index bd5a77b21a3..9e08b602b92 100644 --- a/usr.bin/netstat/if.c +++ b/usr.bin/netstat/if.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if.c,v 1.53 2007/09/11 16:14:41 mk Exp $ */ +/* $OpenBSD: if.c,v 1.54 2007/12/14 18:35:46 deraadt Exp $ */ /* $NetBSD: if.c,v 1.16.4.2 1996/06/07 21:46:46 thorpej Exp $ */ /* @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "from: @(#)if.c 8.2 (Berkeley) 2/21/94"; #else -static char *rcsid = "$OpenBSD: if.c,v 1.53 2007/09/11 16:14:41 mk Exp $"; +static char *rcsid = "$OpenBSD: if.c,v 1.54 2007/12/14 18:35:46 deraadt Exp $"; #endif #endif /* not lint */ @@ -77,9 +77,7 @@ intpr(int interval, u_long ifnetaddr) union { struct ifaddr ifa; struct in_ifaddr in; -#ifdef INET6 struct in6_ifaddr in6; -#endif } ifaddr; u_int64_t total; u_long ifaddraddr; @@ -120,9 +118,7 @@ intpr(int interval, u_long ifnetaddr) ifaddraddr = 0; while (ifnetaddr || ifaddraddr) { struct sockaddr_in *sin; -#ifdef INET6 struct sockaddr_in6 *sin6; -#endif char *cp; int n, m; @@ -212,7 +208,6 @@ intpr(int interval, u_long ifnetaddr) } } break; -#ifdef INET6 case AF_INET6: sin6 = (struct sockaddr_in6 *)sa; #ifdef __KAME__ @@ -270,7 +265,6 @@ intpr(int interval, u_long ifnetaddr) } } break; -#endif case AF_APPLETALK: printf("atlk:%-12s",atalk_print(sa,0x10) ); printf("%-12s ",atalk_print(sa,0x0b) ); diff --git a/usr.bin/netstat/inet.c b/usr.bin/netstat/inet.c index f3db9d55909..5d78195ee5c 100644 --- a/usr.bin/netstat/inet.c +++ b/usr.bin/netstat/inet.c @@ -1,4 +1,4 @@ -/* $OpenBSD: inet.c,v 1.102 2007/12/13 20:00:53 reyk Exp $ */ +/* $OpenBSD: inet.c,v 1.103 2007/12/14 18:35:46 deraadt Exp $ */ /* $NetBSD: inet.c,v 1.14 1995/10/03 21:42:37 thorpej Exp $ */ /* @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "from: @(#)inet.c 8.4 (Berkeley) 4/20/94"; #else -static const char *rcsid = "$OpenBSD: inet.c,v 1.102 2007/12/13 20:00:53 reyk Exp $"; +static const char *rcsid = "$OpenBSD: inet.c,v 1.103 2007/12/14 18:35:46 deraadt Exp $"; #endif #endif /* not lint */ @@ -77,6 +77,10 @@ static const char *rcsid = "$OpenBSD: inet.c,v 1.102 2007/12/13 20:00:53 reyk Ex #include <net/pfvar.h> #include <net/if_pfsync.h> +#include <rpc/rpc.h> +#include <rpc/pmap_prot.h> +#include <rpc/pmap_clnt.h> + #include <arpa/inet.h> #include <limits.h> #include <netdb.h> @@ -84,12 +88,9 @@ static const char *rcsid = "$OpenBSD: inet.c,v 1.102 2007/12/13 20:00:53 reyk Ex #include <string.h> #include <unistd.h> #include <stdlib.h> +#include <errno.h> #include "netstat.h" -#include <rpc/rpc.h> -#include <rpc/pmap_prot.h> -#include <rpc/pmap_clnt.h> - struct inpcb inpcb; struct tcpcb tcpcb; struct socket sockb; @@ -98,10 +99,8 @@ static void protopr0(u_long, char *, int); char *inetname(struct in_addr *); void inetprint(struct in_addr *, in_port_t, char *, int); -#ifdef INET6 char *inet6name(struct in6_addr *); void inet6print(struct in6_addr *, int, char *, int); -#endif /* * Print a summary of connections related to an Internet @@ -115,13 +114,11 @@ protopr(u_long off, char *name) protopr0(off, name, AF_INET); } -#ifdef INET6 void ip6protopr(u_long off, char *name) { protopr0(off, name, AF_INET6); } -#endif static void protopr0(u_long off, char *name, int af) @@ -196,25 +193,20 @@ protopr0(u_long off, char *name, int af) else printf("%*p ", PLEN, prev); } -#ifdef INET6 if (inpcb.inp_flags & INP_IPV6 && !israw) { strlcpy(namebuf, name0, sizeof namebuf); strlcat(namebuf, "6", sizeof namebuf); name = namebuf; } else name = name0; -#endif printf("%-5.5s %6ld %6ld ", name, sockb.so_rcv.sb_cc, sockb.so_snd.sb_cc); -#ifdef INET6 if (inpcb.inp_flags & INP_IPV6) { inet6print(&inpcb.inp_laddr6, (int)inpcb.inp_lport, name, 1); inet6print(&inpcb.inp_faddr6, (int)inpcb.inp_fport, name, 0); - } else -#endif - { + } else { inetprint(&inpcb.inp_laddr, (int)inpcb.inp_lport, name, 1); inetprint(&inpcb.inp_faddr, (int)inpcb.inp_fport, @@ -227,11 +219,10 @@ protopr0(u_long off, char *name, int af) printf(" %s", tcpstates[tcpcb.t_state]); } else if (israw) { u_int8_t proto; -#ifdef INET6 + if (inpcb.inp_flags & INP_IPV6) proto = inpcb.inp_ipv6.ip6_nxt; else -#endif proto = inpcb.inp_ip.ip_p; printf(" %u", proto); } @@ -243,19 +234,16 @@ protopr0(u_long off, char *name, int af) * Dump TCP statistics structure. */ void -tcp_stats(u_long off, char *name) +tcp_stats(char *name) { struct tcpstat tcpstat; - size_t len; int mib[] = { CTL_NET, AF_INET, IPPROTO_TCP, TCPCTL_STATS }; + size_t len = sizeof(tcpstat); - if (off == 0) - return; - - len = sizeof(tcpstat); if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), &tcpstat, &len, NULL, 0) == -1) { - warn(name); + if (errno != ENOPROTOOPT) + warn(name); return; } @@ -376,20 +364,17 @@ tcp_stats(u_long off, char *name) * Dump UDP statistics structure. */ void -udp_stats(u_long off, char *name) +udp_stats(char *name) { struct udpstat udpstat; u_long delivered; - size_t len; int mib[] = { CTL_NET, AF_INET, IPPROTO_UDP, UDPCTL_STATS }; + size_t len = sizeof(udpstat); - if (off == 0) - return; - - len = sizeof(udpstat); if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), &udpstat, &len, NULL, 0) == -1) { - warn(name); + if (errno != ENOPROTOOPT) + warn(name); return; } @@ -426,19 +411,16 @@ udp_stats(u_long off, char *name) * Dump IP statistics structure. */ void -ip_stats(u_long off, char *name) +ip_stats(char *name) { struct ipstat ipstat; - size_t len; int mib[] = { CTL_NET, AF_INET, IPPROTO_IP, IPCTL_STATS }; + size_t len = sizeof(ipstat);; - if (off == 0) - return; - - len = sizeof(ipstat); if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), &ipstat, &len, NULL, 0) == -1) { - warn(name); + if (errno != ENOPROTOOPT) + warn(name); return; } @@ -532,20 +514,17 @@ static char *icmpnames[ICMP_MAXTYPE + 1] = { * Dump ICMP statistics. */ void -icmp_stats(u_long off, char *name) +icmp_stats(char *name) { struct icmpstat icmpstat; int i, first; int mib[] = { CTL_NET, AF_INET, IPPROTO_ICMP, ICMPCTL_STATS }; - size_t len; - - if (off == 0) - return; + size_t len = sizeof(icmpstat); - len = sizeof(icmpstat); if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), &icmpstat, &len, NULL, 0) == -1) { - warn(name); + if (errno != ENOPROTOOPT) + warn(name); return; } @@ -592,15 +571,20 @@ icmp_stats(u_long off, char *name) * Dump IGMP statistics structure. */ void -igmp_stats(u_long off, char *name) +igmp_stats(char *name) { struct igmpstat igmpstat; + int mib[] = { CTL_NET, AF_INET, IPPROTO_IGMP, IGMPCTL_STATS }; + size_t len = sizeof(igmpstat); - if (off == 0) + if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), + &igmpstat, &len, NULL, 0) == -1) { + if (errno != ENOPROTOOPT) + warn(name); return; - kread(off, &igmpstat, sizeof (igmpstat)); - printf("%s:\n", name); + } + printf("%s:\n", name); #define p(f, m) if (igmpstat.f || sflag <= 1) \ printf(m, igmpstat.f, plural(igmpstat.f)) #define py(f, m) if (igmpstat.f || sflag <= 1) \ @@ -623,19 +607,20 @@ igmp_stats(u_long off, char *name) * Dump PIM statistics structure. */ void -pim_stats(u_long off, char *name) +pim_stats(char *name) { struct pimstat pimstat; + int mib[] = { CTL_NET, AF_INET, IPPROTO_PIM, PIMCTL_STATS }; + size_t len = sizeof(pimstat); - if (off == 0) - return; - if (kread(off, &pimstat, sizeof (pimstat)) != 0) { - /* XXX: PIM is probably not enabled in the kernel */ + if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), + &pimstat, &len, NULL, 0) == -1) { + if (errno != ENOPROTOOPT) + warn(name); return; } printf("%s:\n", name); - #define p(f, m) if (pimstat.f || sflag <= 1) \ printf(m, pimstat.f, plural(pimstat.f)) #define py(f, m) if (pimstat.f || sflag <= 1) \ @@ -816,15 +801,20 @@ inetname(struct in_addr *inp) * Dump AH statistics structure. */ void -ah_stats(u_long off, char *name) +ah_stats(char *name) { struct ahstat ahstat; + int mib[] = { CTL_NET, AF_INET, IPPROTO_AH, AHCTL_STATS }; + size_t len = sizeof(ahstat); - if (off == 0) + if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), + &ahstat, &len, NULL, 0) == -1) { + if (errno != ENOPROTOOPT) + warn(name); return; - kread(off, &ahstat, sizeof (ahstat)); - printf("%s:\n", name); + } + printf("%s:\n", name); #define p(f, m) if (ahstat.f || sflag <= 1) \ printf(m, ahstat.f, plural(ahstat.f)) #define p1(f, m) if (ahstat.f || sflag <= 1) \ @@ -857,15 +847,20 @@ ah_stats(u_long off, char *name) * Dump etherip statistics structure. */ void -etherip_stats(u_long off, char *name) +etherip_stats(char *name) { struct etheripstat etheripstat; + int mib[] = { CTL_NET, AF_INET, IPPROTO_ETHERIP, ETHERIPCTL_STATS }; + size_t len = sizeof(etheripstat); - if (off == 0) + if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), + ðeripstat, &len, NULL, 0) == -1) { + if (errno != ENOPROTOOPT) + warn(name); return; - kread(off, ðeripstat, sizeof (etheripstat)); - printf("%s:\n", name); + } + printf("%s:\n", name); #define p(f, m) if (etheripstat.f || sflag <= 1) \ printf(m, etheripstat.f, plural(etheripstat.f)) @@ -885,15 +880,20 @@ etherip_stats(u_long off, char *name) * Dump ESP statistics structure. */ void -esp_stats(u_long off, char *name) +esp_stats(char *name) { struct espstat espstat; + int mib[] = { CTL_NET, AF_INET, IPPROTO_ESP, ESPCTL_STATS }; + size_t len = sizeof(espstat); - if (off == 0) + if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), + &espstat, &len, NULL, 0) == -1) { + if (errno != ENOPROTOOPT) + warn(name); return; - kread(off, &espstat, sizeof (espstat)); - printf("%s:\n", name); + } + printf("%s:\n", name); #define p(f, m) if (espstat.f || sflag <= 1) \ printf(m, espstat.f, plural(espstat.f)) @@ -927,15 +927,20 @@ esp_stats(u_long off, char *name) * Dump IP-in-IP statistics structure. */ void -ipip_stats(u_long off, char *name) +ipip_stats(char *name) { struct ipipstat ipipstat; + int mib[] = { CTL_NET, AF_INET, IPPROTO_IPIP, IPIPCTL_STATS }; + size_t len = sizeof(ipipstat); - if (off == 0) + if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), + &ipipstat, &len, NULL, 0) == -1) { + if (errno != ENOPROTOOPT) + warn(name); return; - kread(off, &ipipstat, sizeof (ipipstat)); - printf("%s:\n", name); + } + printf("%s:\n", name); #define p(f, m) if (ipipstat.f || sflag <= 1) \ printf(m, ipipstat.f, plural(ipipstat.f)) @@ -956,15 +961,20 @@ ipip_stats(u_long off, char *name) * Dump CARP statistics structure. */ void -carp_stats(u_long off, char *name) +carp_stats(char *name) { struct carpstats carpstat; + int mib[] = { CTL_NET, AF_INET, IPPROTO_CARP, CARPCTL_STATS }; + size_t len = sizeof(carpstat); - if (off == 0) + if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), + &carpstat, &len, NULL, 0) == -1) { + if (errno != ENOPROTOOPT) + warn(name); return; - kread(off, &carpstat, sizeof(carpstat)); - printf("%s:\n", name); + } + printf("%s:\n", name); #define p(f, m) if (carpstat.f || sflag <= 1) \ printf(m, carpstat.f, plural(carpstat.f)) #define p2(f, m) if (carpstat.f || sflag <= 1) \ @@ -993,15 +1003,20 @@ carp_stats(u_long off, char *name) * Dump pfsync statistics structure. */ void -pfsync_stats(u_long off, char *name) +pfsync_stats(char *name) { struct pfsyncstats pfsyncstat; + int mib[] = { CTL_NET, AF_INET, IPPROTO_PFSYNC, PFSYNCCTL_STATS }; + size_t len = sizeof(pfsyncstat); - if (off == 0) + if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), + &pfsyncstat, &len, NULL, 0) == -1) { + if (errno != ENOPROTOOPT) + warn(name); return; - kread(off, &pfsyncstat, sizeof(pfsyncstat)); - printf("%s:\n", name); + } + printf("%s:\n", name); #define p(f, m) if (pfsyncstat.f || sflag <= 1) \ printf(m, pfsyncstat.f, plural(pfsyncstat.f)) #define p2(f, m) if (pfsyncstat.f || sflag <= 1) \ @@ -1031,15 +1046,20 @@ pfsync_stats(u_long off, char *name) * Dump IPCOMP statistics structure. */ void -ipcomp_stats(u_long off, char *name) +ipcomp_stats(char *name) { struct ipcompstat ipcompstat; + int mib[] = { CTL_NET, AF_INET, IPPROTO_IPCOMP, IPCOMPCTL_STATS }; + size_t len = sizeof(ipcompstat); - if (off == 0) + if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), + &ipcompstat, &len, NULL, 0) == -1) { + if (errno != ENOPROTOOPT) + warn(name); return; - kread(off, &ipcompstat, sizeof (ipcompstat)); - printf("%s:\n", name); + } + printf("%s:\n", name); #define p(f, m) if (ipcompstat.f || sflag <= 1) \ printf(m, ipcompstat.f, plural(ipcompstat.f)) diff --git a/usr.bin/netstat/inet6.c b/usr.bin/netstat/inet6.c index 3554cdbdbf4..600b3cb417b 100644 --- a/usr.bin/netstat/inet6.c +++ b/usr.bin/netstat/inet6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: inet6.c,v 1.34 2007/09/11 18:16:48 henning Exp $ */ +/* $OpenBSD: inet6.c,v 1.35 2007/12/14 18:35:46 deraadt Exp $ */ /* BSDI inet.c,v 2.3 1995/10/24 02:19:29 prb Exp */ /* * Copyright (c) 1983, 1988, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)inet.c 8.4 (Berkeley) 4/20/94"; #else -/*__RCSID("$OpenBSD: inet6.c,v 1.34 2007/09/11 18:16:48 henning Exp $");*/ +/*__RCSID("$OpenBSD: inet6.c,v 1.35 2007/12/14 18:35:46 deraadt Exp $");*/ /*__RCSID("KAME Id: inet6.c,v 1.10 2000/02/09 10:49:31 itojun Exp");*/ #endif #endif /* not lint */ @@ -45,6 +45,7 @@ static char sccsid[] = "@(#)inet.c 8.4 (Berkeley) 4/20/94"; #include <sys/ioctl.h> #include <sys/mbuf.h> #include <sys/protosw.h> +#include <sys/sysctl.h> #include <net/route.h> #include <net/if.h> @@ -70,10 +71,9 @@ static char sccsid[] = "@(#)inet.c 8.4 (Berkeley) 4/20/94"; #include <stdio.h> #include <string.h> #include <unistd.h> +#include <errno.h> #include "netstat.h" -#ifdef INET6 - struct socket sockb; char *inet6name(struct in6_addr *); @@ -342,19 +342,23 @@ static char *ip6nh[] = { * Dump IP6 statistics structure. */ void -ip6_stats(u_long off, char *name) +ip6_stats(char *name) { struct ip6stat ip6stat; int first, i; struct protoent *ep; const char *n; + int mib[] = { CTL_NET, AF_INET6, IPPROTO_IPV6, IPV6CTL_STATS }; + size_t len = sizeof(ip6stat); - if (off == 0) + if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), + &ip6stat, &len, NULL, 0) == -1) { + if (errno != ENOPROTOOPT) + warn(name); return; + } - kread(off, &ip6stat, sizeof (ip6stat)); printf("%s:\n", name); - #define p(f, m) if (ip6stat.f || sflag <= 1) \ printf(m, (unsigned long long)ip6stat.f, plural(ip6stat.f)) #define p1(f, m) if (ip6stat.f || sflag <= 1) \ @@ -821,16 +825,21 @@ static char *icmp6names[] = { * Dump ICMPv6 statistics. */ void -icmp6_stats(u_long off, char *name) +icmp6_stats(char *name) { struct icmp6stat icmp6stat; int i, first; + int mib[] = { CTL_NET, AF_INET6, IPPROTO_ICMPV6, ICMPV6CTL_STATS }; + size_t len = sizeof(icmp6stat); - if (off == 0) + if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), + &icmp6stat, &len, NULL, 0) == -1) { + if (errno != ENOPROTOOPT) + warn(name); return; - kread(off, &icmp6stat, sizeof (icmp6stat)); - printf("%s:\n", name); + } + printf("%s:\n", name); #define p(f, m) if (icmp6stat.f || sflag <= 1) \ printf(m, (unsigned long long)icmp6stat.f, plural(icmp6stat.f)) #define p_5(f, m) if (icmp6stat.f || sflag <= 1) \ @@ -962,15 +971,20 @@ icmp6_ifstats(char *ifname) * Dump PIM statistics structure. */ void -pim6_stats(u_long off, char *name) +pim6_stats(char *name) { struct pim6stat pim6stat; + int mib[] = { CTL_NET, AF_INET6, IPPROTO_PIM, PIM6CTL_STATS }; + size_t len = sizeof(pim6stat); - if (off == 0) + if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), + &pim6stat, &len, NULL, 0) == -1) { + if (errno != ENOPROTOOPT) + warn(name); return; - kread(off, &pim6stat, sizeof(pim6stat)); - printf("%s:\n", name); + } + printf("%s:\n", name); #define p(f, m) if (pim6stat.f || sflag <= 1) \ printf(m, (unsigned long long)pim6stat.f, plural(pim6stat.f)) @@ -988,14 +1002,20 @@ pim6_stats(u_long off, char *name) * Dump raw ip6 statistics structure. */ void -rip6_stats(u_long off, char *name) +rip6_stats(char *name) { struct rip6stat rip6stat; u_int64_t delivered; + int mib[] = { CTL_NET, AF_INET6, IPPROTO_RAW, RIPV6CTL_STATS }; + size_t len = sizeof(rip6stat); - if (off == 0) + if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), + &rip6stat, &len, NULL, 0) == -1) { + if (errno != ENOPROTOOPT) + warn(name); return; - kread(off, &rip6stat, sizeof(rip6stat)); + } + printf("%s:\n", name); #define p(f, m) if (rip6stat.f || sflag <= 1) \ @@ -1183,5 +1203,3 @@ tcp6_dump(u_long pcbaddr) tcp6cb.ts_recent, tcp6cb.ts_recent_age, tcp6cb.last_ack_sent); } #endif - -#endif /*INET6*/ diff --git a/usr.bin/netstat/main.c b/usr.bin/netstat/main.c index 4c214fafb44..941f4fc42aa 100644 --- a/usr.bin/netstat/main.c +++ b/usr.bin/netstat/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.70 2007/12/11 20:14:45 deraadt Exp $ */ +/* $OpenBSD: main.c,v 1.71 2007/12/14 18:35:46 deraadt 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.70 2007/12/11 20:14:45 deraadt Exp $"; +static char *rcsid = "$OpenBSD: main.c,v 1.71 2007/12/14 18:35:46 deraadt Exp $"; #endif #endif /* not lint */ @@ -67,163 +67,90 @@ static char *rcsid = "$OpenBSD: main.c,v 1.70 2007/12/11 20:14:45 deraadt Exp $" #include "netstat.h" struct nlist nl[] = { -#define N_IPSTAT 0 - { "_ipstat" }, -#define N_TCBTABLE 1 +#define N_TCBTABLE 0 { "_tcbtable" }, -#define N_TCPSTAT 2 - { "_tcpstat" }, -#define N_UDBTABLE 3 +#define N_UDBTABLE 1 { "_udbtable" }, -#define N_UDPSTAT 4 - { "_udpstat" }, -#define N_IFNET 5 +#define N_DDPCB 2 + { "_ddpcb"}, +#define N_IFNET 3 { "_ifnet" }, -#define N_ICMPSTAT 6 - { "_icmpstat" }, -#define N_RTSTAT 7 - { "_rtstat" }, -#define N_UNIXSW 8 +#define N_UNIXSW 4 { "_unixsw" }, -#define N_RTREE 9 - { "_rt_tables"}, -#define N_FILE 10 - { "_file" }, -#define N_IGMPSTAT 11 - { "_igmpstat" }, -#define N_MRTPROTO 12 - { "_ip_mrtproto" }, -#define N_MRTSTAT 13 - { "_mrtstat" }, -#define N_MFCHASHTBL 14 + +#define N_MFCHASHTBL 5 { "_mfchashtbl" }, -#define N_MFCHASH 15 +#define N_MFCHASH 6 { "_mfchash" }, -#define N_VIFTABLE 16 +#define N_VIFTABLE 7 { "_viftable" }, -#define N_AHSTAT 17 - { "_ahstat"}, -#define N_ESPSTAT 18 - { "_espstat"}, -#define N_IP4STAT 19 - { "_ipipstat"}, -#define N_DDPSTAT 20 - { "_ddpstat"}, -#define N_DDPCB 21 - { "_ddpcb"}, -#define N_ETHERIPSTAT 22 - { "_etheripstat"}, -#define N_IP6STAT 23 - { "_ip6stat" }, -#define N_ICMP6STAT 24 - { "_icmp6stat" }, -#define N_PIM6STAT 25 - { "_pim6stat" }, -#define N_MRT6PROTO 26 - { "_ip6_mrtproto" }, -#define N_MRT6STAT 27 - { "_mrt6stat" }, -#define N_MF6CTABLE 28 + +#define N_MF6CTABLE 8 { "_mf6ctable" }, -#define N_MIF6TABLE 29 +#define N_MIF6TABLE 9 { "_mif6table" }, -#define N_IPCOMPSTAT 30 - { "_ipcompstat" }, -#define N_RIP6STAT 31 - { "_rip6stat" }, -#define N_CARPSTAT 32 - { "_carpstats" }, -#define N_RAWIPTABLE 33 - { "_rawcbtable" }, -#define N_RAWIP6TABLE 34 - { "_rawin6pcbtable" }, -#define N_PFSYNCSTAT 35 - { "_pfsyncstats" }, -#define N_PIMSTAT 36 - { "_pimstat" }, -#define N_AF2RTAFIDX 37 + +#define N_RTREE 10 + { "_rt_tables"}, +#define N_RTMASK 11 + { "_mask_rnhead" }, +#define N_AF2RTAFIDX 12 { "_af2rtafidx" }, -#define N_RTBLIDMAX 38 +#define N_RTBLIDMAX 13 { "_rtbl_id_max" }, -#define N_RTMASK 39 - { "_mask_rnhead" }, + +#define N_RAWIPTABLE 14 + { "_rawcbtable" }, +#define N_RAWIP6TABLE 15 + { "_rawin6pcbtable" }, + +#define N_RTSTAT 16 + { "_rtstat" }, + { ""} }; struct protox { u_char pr_index; /* index into nlist of cb head */ - u_char pr_sindex; /* index into nlist of stat block */ - u_char pr_wanted; /* 1 if wanted, 0 otherwise */ void (*pr_cblocks)(u_long, char *); /* control blocks printing routine */ - void (*pr_stats)(u_long, char *); /* statistics printing routine */ + void (*pr_stats)(char *); /* statistics printing routine */ void (*pr_dump)(u_long); /* pcb printing routine */ char *pr_name; /* well-known name */ } protox[] = { - { N_TCBTABLE, N_TCPSTAT, 1, protopr, - tcp_stats, tcp_dump, "tcp" }, - { N_UDBTABLE, N_UDPSTAT, 1, protopr, - udp_stats, 0, "udp" }, - { N_RAWIPTABLE, N_IPSTAT, 1, protopr, - ip_stats, 0, "ip" }, - { -1, N_ICMPSTAT, 1, 0, - icmp_stats, 0, "icmp" }, - { -1, N_IGMPSTAT, 1, 0, - igmp_stats, 0, "igmp" }, - { -1, N_AHSTAT, 1, 0, - ah_stats, 0, "ah" }, - { -1, N_ESPSTAT, 1, 0, - esp_stats, 0, "esp" }, - { -1, N_IP4STAT, 1, 0, - ipip_stats, 0, "ipencap" }, - { -1, N_ETHERIPSTAT, 1, 0, - etherip_stats,0, "etherip" }, - { -1, N_IPCOMPSTAT, 1, 0, - ipcomp_stats, 0, "ipcomp" }, - { -1, N_CARPSTAT, 1, 0, - carp_stats, 0, "carp" }, - { -1, N_PFSYNCSTAT, 1, 0, - pfsync_stats, 0, "pfsync" }, - { -1, N_PIMSTAT, 1, 0, - pim_stats, 0, "pim" }, - { -1, -1, 0, 0, - 0, 0, 0 } + { N_TCBTABLE, protopr, tcp_stats, tcp_dump, "tcp" }, + { N_UDBTABLE, protopr, udp_stats, NULL, "udp" }, + { N_RAWIPTABLE, protopr, ip_stats, NULL, "ip" }, + { -1, NULL, icmp_stats, NULL, "icmp" }, + { -1, NULL, igmp_stats, NULL, "igmp" }, + { -1, NULL, ah_stats, NULL, "ah" }, + { -1, NULL, esp_stats, NULL, "esp" }, + { -1, NULL, ipip_stats, NULL, "ipencap" }, + { -1, NULL, etherip_stats, NULL, "etherip" }, + { -1, NULL, ipcomp_stats, NULL, "ipcomp" }, + { -1, NULL, carp_stats, NULL, "carp" }, + { -1, NULL, pfsync_stats, NULL, "pfsync" }, + { -1, NULL, pim_stats, NULL, "pim" }, + { -1, NULL, NULL, NULL, NULL } }; -#ifdef INET6 struct protox ip6protox[] = { - { N_TCBTABLE, N_TCPSTAT, 1, ip6protopr, - 0, tcp_dump, "tcp" }, - { N_UDBTABLE, N_UDPSTAT, 1, ip6protopr, - 0, 0, "udp" }, - { N_RAWIP6TABLE,N_IP6STAT, 1, ip6protopr, - ip6_stats, 0, "ip6" }, - { -1, N_ICMP6STAT, 1, 0, - icmp6_stats, 0, "icmp6" }, - { -1, N_PIM6STAT, 1, 0, - pim6_stats, 0, "pim6" }, - { -1, N_RIP6STAT, 1, 0, - rip6_stats, 0, "rip6" }, - { -1, -1, 0, 0, - 0, 0, 0 } + { N_TCBTABLE, ip6protopr, NULL, tcp_dump, "tcp" }, + { N_UDBTABLE, ip6protopr, NULL, NULL, "udp" }, + { N_RAWIP6TABLE,ip6protopr, ip6_stats, NULL, "ip6" }, + { -1, NULL, icmp6_stats, NULL, "icmp6" }, + { -1, NULL, pim6_stats, NULL, "pim6" }, + { -1, NULL, rip6_stats, NULL, "rip6" }, + { -1, NULL, NULL, NULL, NULL } }; -#endif struct protox atalkprotox[] = { - { N_DDPCB, N_DDPSTAT, 1, atalkprotopr, - ddp_stats, 0, "ddp" }, - { -1, -1, 0, 0, - 0, 0, 0 } + { N_DDPCB, atalkprotopr, ddp_stats, NULL, "ddp" }, + { -1, NULL, NULL, NULL, NULL } }; -#ifndef INET6 -struct protox *protoprotox[] = { - protox, atalkprotox, NULL -}; -#else struct protox *protoprotox[] = { protox, ip6protox, atalkprotox, NULL }; -#endif static void printproto(struct protox *, char *); static void usage(void); @@ -463,7 +390,7 @@ main(int argc, char *argv[]) */ sethostent(1); setnetent(1); - + if (iflag) { intpr(interval, nl[N_IFNET].n_value); exit(0); @@ -479,25 +406,17 @@ main(int argc, char *argv[]) if (gflag) { if (sflag) { if (af == AF_INET || af == AF_UNSPEC) - mrt_stats(nl[N_MRTPROTO].n_value, - nl[N_MRTSTAT].n_value); -#ifdef INET6 + mrt_stats(); if (af == AF_INET6 || af == AF_UNSPEC) - mrt6_stats(nl[N_MRT6PROTO].n_value, - nl[N_MRT6STAT].n_value); -#endif + mrt6_stats(); } else { if (af == AF_INET || af == AF_UNSPEC) - mroutepr(nl[N_MRTPROTO].n_value, - nl[N_MFCHASHTBL].n_value, + mroutepr(nl[N_MFCHASHTBL].n_value, nl[N_MFCHASH].n_value, nl[N_VIFTABLE].n_value); -#ifdef INET6 if (af == AF_INET6 || af == AF_UNSPEC) - mroute6pr(nl[N_MRT6PROTO].n_value, - nl[N_MF6CTABLE].n_value, + mroute6pr(nl[N_MF6CTABLE].n_value, nl[N_MIF6TABLE].n_value); -#endif } exit(0); } @@ -509,17 +428,15 @@ main(int argc, char *argv[]) for (tp = protox; tp->pr_name; tp++) if (strcmp(tp->pr_name, p->p_name) == 0) break; - if (tp->pr_name == 0 || tp->pr_wanted == 0) + if (tp->pr_name == 0) continue; printproto(tp, p->p_name); } endprotoent(); } -#ifdef INET6 if (af == AF_INET6 || af == AF_UNSPEC) for (tp = ip6protox; tp->pr_name; tp++) printproto(tp, tp->pr_name); -#endif if ((af == AF_UNIX || af == AF_UNSPEC) && !sflag) unixpr(nl[N_UNIXSW].n_value); if (af == AF_APPLETALK || af == AF_UNSPEC) @@ -536,19 +453,16 @@ main(int argc, char *argv[]) static void printproto(struct protox *tp, char *name) { - void (*pr)(u_long, char *); - u_char i; - if (sflag) { - pr = tp->pr_stats; - i = tp->pr_sindex; + if (tp->pr_stats != NULL) + (*tp->pr_stats)(name); } else { - pr = tp->pr_cblocks; - i = tp->pr_index; + u_char i = tp->pr_index; + if (tp->pr_cblocks != NULL && + i < sizeof(nl) / sizeof(nl[0]) && + (nl[i].n_value || af != AF_UNSPEC)) + (*tp->pr_cblocks)(nl[i].n_value, name); } - if (pr != NULL && i < sizeof(nl) / sizeof(nl[0]) && - (nl[i].n_value || af != AF_UNSPEC)) - (*pr)(nl[i].n_value, name); } /* diff --git a/usr.bin/netstat/mroute.c b/usr.bin/netstat/mroute.c index 200d70cacb2..e11be3c2aba 100644 --- a/usr.bin/netstat/mroute.c +++ b/usr.bin/netstat/mroute.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mroute.c,v 1.16 2006/05/27 19:16:37 claudio Exp $ */ +/* $OpenBSD: mroute.c,v 1.17 2007/12/14 18:35:46 deraadt Exp $ */ /* $NetBSD: mroute.c,v 1.10 1996/05/11 13:51:27 mycroft Exp $ */ /* @@ -46,6 +46,7 @@ #include <sys/socket.h> #include <sys/socketvar.h> #include <sys/protosw.h> +#include <sys/sysctl.h> #include <net/if.h> #include <net/route.h> @@ -58,6 +59,7 @@ #include <limits.h> #include <stdio.h> #include <stdlib.h> +#include <errno.h> #include "netstat.h" static void print_bw_meter(struct bw_meter *bw_meter, int *banner_printed); @@ -83,35 +85,31 @@ pktscale(u_long n) } void -mroutepr(u_long mrpaddr, u_long mfchashtbladdr, u_long mfchashaddr, u_long vifaddr) +mroutepr(u_long mfchashtbladdr, u_long mfchashaddr, u_long vifaddr) { u_int mrtproto; LIST_HEAD(, mfc) *mfchashtbl; u_long mfchash; - struct vif viftable[MAXVIFS]; + struct vif viftable[MAXVIFS], *v; struct mfc *mfcp, mfc; - struct vif *v; vifi_t vifi; - int i; - int banner_printed; - int saved_nflag; - int numvifs; + int mib[] = { CTL_NET, AF_INET, IPPROTO_IP, IPCTL_MRTPROTO }; + size_t len = sizeof(int); + int i, banner_printed = 0, saved_nflag, numvifs = 0; int nmfc; /* No. of cache entries */ - if (mrpaddr == 0) { - printf("ip_mrtproto: symbol not in namelist\n"); + if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), + &mrtproto, &len, NULL, 0) == -1) { + if (errno != ENOPROTOOPT) + warn("mroute"); return; } - - kread(mrpaddr, &mrtproto, sizeof(mrtproto)); switch (mrtproto) { case 0: printf("no multicast routing compiled into this system\n"); return; - case IGMP_DVMRP: break; - default: printf("multicast routing protocol %u, unknown\n", mrtproto); return; @@ -134,8 +132,6 @@ mroutepr(u_long mrpaddr, u_long mfchashtbladdr, u_long mfchashaddr, u_long vifad nflag = 1; kread(vifaddr, &viftable, sizeof(viftable)); - banner_printed = 0; - numvifs = 0; for (vifi = 0, v = viftable; vifi < MAXVIFS; ++vifi, ++v) { if (v->v_lcl_addr.s_addr == 0) @@ -157,7 +153,7 @@ mroutepr(u_long mrpaddr, u_long mfchashtbladdr, u_long mfchashaddr, u_long vifad v->v_pkt_in, v->v_pkt_out); } if (!banner_printed) - printf("\nVirtual Interface Table is empty\n"); + printf("Virtual Interface Table is empty\n"); kread(mfchashtbladdr, &mfchashtbl, sizeof(mfchashtbl)); kread(mfchashaddr, &mfchash, sizeof(mfchash)); @@ -213,7 +209,7 @@ mroutepr(u_long mrpaddr, u_long mfchashtbladdr, u_long mfchashaddr, u_long vifad } } if (!banner_printed) - printf("\nMulticast Forwarding Cache is empty\n"); + printf("Multicast Forwarding Cache is empty\n"); else printf("\nTotal no. of entries in cache: %d\n", nmfc); @@ -299,17 +295,20 @@ print_bw_meter(struct bw_meter *bw_meter, int *banner_printed) } void -mrt_stats(u_long mrpaddr, u_long mstaddr) +mrt_stats(void) { u_int mrtproto; struct mrtstat mrtstat; - - if (mrpaddr == 0) { - printf("ip_mrtproto: symbol not in namelist\n"); + int mib[] = { CTL_NET, AF_INET, IPPROTO_IP, IPCTL_MRTPROTO }; + int mib2[] = { CTL_NET, AF_INET, IPPROTO_IP, IPCTL_MRTSTATS }; + size_t len = sizeof(int); + + if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), + &mrtproto, &len, NULL, 0) == -1) { + if (errno != ENOPROTOOPT) + warn("mroute"); return; } - - kread(mrpaddr, &mrtproto, sizeof(mrtproto)); switch (mrtproto) { case 0: printf("no multicast routing compiled into this system\n"); @@ -323,12 +322,14 @@ mrt_stats(u_long mrpaddr, u_long mstaddr) return; } - if (mstaddr == 0) { - printf("mrtstat: symbol not in namelist\n"); + len = sizeof(mrtstat); + if (sysctl(mib2, sizeof(mib2) / sizeof(mib2[0]), + &mrtstat, &len, NULL, 0) == -1) { + if (errno != ENOPROTOOPT) + warn("mroute"); return; } - kread(mstaddr, &mrtstat, sizeof(mrtstat)); printf("multicast routing:\n"); printf("\t%lu datagram%s with no route for origin\n", mrtstat.mrts_no_route, plural(mrtstat.mrts_no_route)); diff --git a/usr.bin/netstat/mroute6.c b/usr.bin/netstat/mroute6.c index 5a47ad153d6..154ae0f3df9 100644 --- a/usr.bin/netstat/mroute6.c +++ b/usr.bin/netstat/mroute6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mroute6.c,v 1.9 2007/09/11 18:16:48 henning Exp $ */ +/* $OpenBSD: mroute6.c,v 1.10 2007/12/14 18:35:46 deraadt Exp $ */ /* * Copyright (C) 1998 WIDE Project. @@ -69,6 +69,7 @@ #include <sys/socket.h> #include <sys/socketvar.h> #include <sys/protosw.h> +#include <sys/sysctl.h> #include <net/if.h> @@ -79,15 +80,14 @@ #undef _KERNEL #include <stdio.h> +#include <errno.h> #include "netstat.h" -#ifdef INET6 - #define WID_ORG (lflag ? 39 : (nflag ? 29 : 18)) /* width of origin column */ #define WID_GRP (lflag ? 18 : (nflag ? 16 : 18)) /* width of group column */ void -mroute6pr(u_long mrpaddr, u_long mfcaddr, u_long mifaddr) +mroute6pr(u_long mfcaddr, u_long mifaddr) { int banner_printed, saved_nflag, waitings, i; struct mf6c *mf6ctable[MF6CTBLSIZ], *mfcp; @@ -96,22 +96,21 @@ mroute6pr(u_long mrpaddr, u_long mfcaddr, u_long mifaddr) mifi_t maxmif = 0, mifi; struct mf6c mfc; u_int mrtproto; + int mib[] = { CTL_NET, AF_INET6, IPPROTO_IPV6, IPV6CTL_MRTPROTO }; + size_t len = sizeof(int); - if (mrpaddr == 0) { - printf("mroute6pr: symbol not in namelist\n"); + if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), + &mrtproto, &len, NULL, 0) == -1) { + if (errno != ENOPROTOOPT) + warn("mroute"); return; } - - kread(mrpaddr, &mrtproto, sizeof(mrtproto)); switch (mrtproto) { - case 0: printf("no IPv6 multicast routing compiled into this system\n"); return; - case IPPROTO_PIM: break; - default: printf("IPv6 multicast routing protocol %u, unknown\n", mrtproto); @@ -156,7 +155,7 @@ mroute6pr(u_long mrpaddr, u_long mfcaddr, u_long mifaddr) printf(" %9llu %9llu\n", mifp->m6_pkt_in, mifp->m6_pkt_out); } if (!banner_printed) - printf("\nIPv6 Multicast Interface Table is empty\n"); + printf("IPv6 Multicast Interface Table is empty\n"); kread(mfcaddr, &mf6ctable, sizeof(mf6ctable)); banner_printed = 0; @@ -165,7 +164,7 @@ mroute6pr(u_long mrpaddr, u_long mfcaddr, u_long mifaddr) while (mfcp) { kread((u_long)mfcp, &mfc, sizeof(mfc)); if (!banner_printed) { - printf ("\nIPv6 Multicast Forwarding Cache\n"); + printf("\nIPv6 Multicast Forwarding Cache\n"); printf(" %-*.*s %-*.*s %s", WID_ORG, WID_ORG, "Origin", WID_GRP, WID_GRP, "Group", @@ -200,70 +199,72 @@ mroute6pr(u_long mrpaddr, u_long mfcaddr, u_long mifaddr) } } if (!banner_printed) - printf("\nIPv6 Multicast Routing Table is empty\n"); + printf("IPv6 Multicast Routing Table is empty"); printf("\n"); nflag = saved_nflag; } void -mrt6_stats(u_long mrpaddr, u_long mstaddr) +mrt6_stats(void) { - struct mrt6stat mrtstat; - u_int mrtproto; - - if (mrpaddr == 0) { - printf("mrt6_stats: symbol not in namelist\n"); + struct mrt6stat mrt6stat; + u_int mrt6proto; + int mib[] = { CTL_NET, AF_INET6, IPPROTO_IPV6, IPV6CTL_MRTPROTO }; + int mib2[] = { CTL_NET, AF_INET6, IPPROTO_IPV6, IPV6CTL_MRTSTATS }; + size_t len = sizeof(int); + + if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), + &mrt6proto, &len, NULL, 0) == -1) { + if (errno != ENOPROTOOPT) + warn("mroute"); return; } - - kread(mrpaddr, &mrtproto, sizeof(mrtproto)); - switch (mrtproto) { + switch (mrt6proto) { case 0: - printf("no IPv6 multicast routing compiled into this system\n"); - return; - + printf("no IPv6 multicast routing compiled into this system\n"); + return; case IPPROTO_PIM: - break; - + break; default: printf("IPv6 multicast routing protocol %u, unknown\n", - mrtproto); + mrt6proto); return; } - if (mstaddr == 0) { - printf("mrt6_stats: symbol not in namelist\n"); + len = sizeof(mrt6stat); + if (sysctl(mib2, sizeof(mib2) / sizeof(mib2[0]), + &mrt6stat, &len, NULL, 0) == -1) { + if (errno != ENOPROTOOPT) + warn("mroute"); return; } - kread(mstaddr, &mrtstat, sizeof(mrtstat)); printf("multicast forwarding:\n"); - printf(" %10llu multicast forwarding cache lookup%s\n", - mrtstat.mrt6s_mfc_lookups, plural(mrtstat.mrt6s_mfc_lookups)); - printf(" %10llu multicast forwarding cache miss%s\n", - mrtstat.mrt6s_mfc_misses, plurales(mrtstat.mrt6s_mfc_misses)); - printf(" %10llu upcall%s to mrouted\n", - mrtstat.mrt6s_upcalls, plural(mrtstat.mrt6s_upcalls)); - printf(" %10llu upcall queue overflow%s\n", - mrtstat.mrt6s_upq_ovflw, plural(mrtstat.mrt6s_upq_ovflw)); - printf(" %10llu upcall%s dropped due to full socket buffer\n", - mrtstat.mrt6s_upq_sockfull, plural(mrtstat.mrt6s_upq_sockfull)); - printf(" %10llu cache cleanup%s\n", - mrtstat.mrt6s_cache_cleanups, plural(mrtstat.mrt6s_cache_cleanups)); - printf(" %10llu datagram%s with no route for origin\n", - mrtstat.mrt6s_no_route, plural(mrtstat.mrt6s_no_route)); - printf(" %10llu datagram%s arrived with bad tunneling\n", - mrtstat.mrt6s_bad_tunnel, plural(mrtstat.mrt6s_bad_tunnel)); - printf(" %10llu datagram%s could not be tunneled\n", - mrtstat.mrt6s_cant_tunnel, plural(mrtstat.mrt6s_cant_tunnel)); - printf(" %10llu datagram%s arrived on wrong interface\n", - mrtstat.mrt6s_wrong_if, plural(mrtstat.mrt6s_wrong_if)); - printf(" %10llu datagram%s selectively dropped\n", - mrtstat.mrt6s_drop_sel, plural(mrtstat.mrt6s_drop_sel)); - printf(" %10llu datagram%s dropped due to queue overflow\n", - mrtstat.mrt6s_q_overflow, plural(mrtstat.mrt6s_q_overflow)); - printf(" %10llu datagram%s dropped for being too large\n", - mrtstat.mrt6s_pkt2large, plural(mrtstat.mrt6s_pkt2large)); + printf("\t%llu multicast forwarding cache lookup%s\n", + mrt6stat.mrt6s_mfc_lookups, plural(mrt6stat.mrt6s_mfc_lookups)); + printf("\t%llu multicast forwarding cache miss%s\n", + mrt6stat.mrt6s_mfc_misses, plurales(mrt6stat.mrt6s_mfc_misses)); + printf("\t%llu upcall%s to mrouted\n", + mrt6stat.mrt6s_upcalls, plural(mrt6stat.mrt6s_upcalls)); + printf("\t%llu upcall queue overflow%s\n", + mrt6stat.mrt6s_upq_ovflw, plural(mrt6stat.mrt6s_upq_ovflw)); + printf("\t%llu upcall%s dropped due to full socket buffer\n", + mrt6stat.mrt6s_upq_sockfull, plural(mrt6stat.mrt6s_upq_sockfull)); + printf("\t%llu cache cleanup%s\n", + mrt6stat.mrt6s_cache_cleanups, plural(mrt6stat.mrt6s_cache_cleanups)); + printf("\t%llu datagram%s with no route for origin\n", + mrt6stat.mrt6s_no_route, plural(mrt6stat.mrt6s_no_route)); + printf("\t%llu datagram%s arrived with bad tunneling\n", + mrt6stat.mrt6s_bad_tunnel, plural(mrt6stat.mrt6s_bad_tunnel)); + printf("\t%llu datagram%s could not be tunneled\n", + mrt6stat.mrt6s_cant_tunnel, plural(mrt6stat.mrt6s_cant_tunnel)); + printf("\t%llu datagram%s arrived on wrong interface\n", + mrt6stat.mrt6s_wrong_if, plural(mrt6stat.mrt6s_wrong_if)); + printf("\t%llu datagram%s selectively dropped\n", + mrt6stat.mrt6s_drop_sel, plural(mrt6stat.mrt6s_drop_sel)); + printf("\t%llu datagram%s dropped due to queue overflow\n", + mrt6stat.mrt6s_q_overflow, plural(mrt6stat.mrt6s_q_overflow)); + printf("\t%llu datagram%s dropped for being too large\n", + mrt6stat.mrt6s_pkt2large, plural(mrt6stat.mrt6s_pkt2large)); } -#endif /*INET6*/ diff --git a/usr.bin/netstat/netstat.h b/usr.bin/netstat/netstat.h index a11bd871a36..d8abfe8baa9 100644 --- a/usr.bin/netstat/netstat.h +++ b/usr.bin/netstat/netstat.h @@ -1,4 +1,4 @@ -/* $OpenBSD: netstat.h,v 1.44 2007/12/11 20:14:45 deraadt Exp $ */ +/* $OpenBSD: netstat.h,v 1.45 2007/12/14 18:35:46 deraadt Exp $ */ /* $NetBSD: netstat.h,v 1.6 1996/05/07 02:55:05 thorpej Exp $ */ /* @@ -70,23 +70,22 @@ char *plural(int); char *plurales(int); void protopr(u_long, char *); -#ifdef INET6 void ip6protopr(u_long, char *); -#endif -void tcp_stats(u_long, char *); -void udp_stats(u_long, char *); -void ip_stats(u_long, char *); -void icmp_stats(u_long, char *); -void igmp_stats(u_long, char *); -void pim_stats(u_long, char *); -void ah_stats(u_long, char *); -void esp_stats(u_long, char *); -void ipip_stats(u_long, char *); -void carp_stats (u_long, char *); -void pfsync_stats (u_long, char *); -void etherip_stats(u_long, char *); +void tcp_stats(char *); +void udp_stats(char *); +void ip_stats(char *); +void icmp_stats(char *); +void igmp_stats(char *); +void pim_stats(char *); +void ah_stats(char *); +void esp_stats(char *); +void ipip_stats(char *); +void carp_stats (char *); +void pfsync_stats (char *); +void etherip_stats(char *); +void ipcomp_stats(char *); + void protopr(u_long, char *); -void ipcomp_stats(u_long, char *); void net80211_ifstats(char *); @@ -102,21 +101,19 @@ void pr_rthdr(int, int); void pr_encaphdr(void); void pr_family(int); -#ifdef INET6 struct in6_addr; struct sockaddr_in6; void ip6protopr(u_long, char *); -void ip6_stats(u_long, char *); +void ip6_stats(char *); void ip6_ifstats(char *); -void icmp6_stats(u_long, char *); +void icmp6_stats(char *); void icmp6_ifstats(char *); -void pim6_stats(u_long, char *); -void rip6_stats(u_long, char *); -void mroute6pr(u_long, u_long, u_long); -void mrt6_stats(u_long, u_long); +void pim6_stats(char *); +void rip6_stats(char *); +void mroute6pr(u_long, u_long); +void mrt6_stats(void); char *routename6(struct sockaddr_in6 *); char *netname6(struct sockaddr_in6 *, struct sockaddr_in6 *); -#endif /*INET6*/ void p_rttables(int, u_int); void p_flags(int, char *); @@ -130,27 +127,15 @@ char *netname4(in_addr_t, in_addr_t); void routepr(u_long, u_long, u_long, u_long); void nsprotopr(u_long, char *); -void spp_stats(u_long, char *); -void idp_stats(u_long, char *); -void nserr_stats(u_long, char *); void intpr(int, u_long); void unixpr(u_long); -void esis_stats(u_long, char *); -void clnp_stats(u_long, char *); -void cltp_stats(u_long, char *); -void iso_protopr(u_long, char *); -void iso_protopr1(u_long, int); -void tp_protopr(u_long, char *); -void tp_inproto(u_long); -void tp_stats(u_long, char *); - -void mroutepr(u_long, u_long, u_long, u_long); -void mrt_stats(u_long, u_long); +void mroutepr(u_long, u_long, u_long); +void mrt_stats(void); void atalkprotopr(u_long, char *); -void ddp_stats(u_long, char *); +void ddp_stats(char *); char *atalk_print(const struct sockaddr *, int); char *atalk_print2(const struct sockaddr *, const struct sockaddr *, int); diff --git a/usr.bin/netstat/route.c b/usr.bin/netstat/route.c index 86eed5945b4..d2a184f4f1b 100644 --- a/usr.bin/netstat/route.c +++ b/usr.bin/netstat/route.c @@ -1,4 +1,4 @@ -/* $OpenBSD: route.c,v 1.75 2007/09/05 20:29:05 claudio Exp $ */ +/* $OpenBSD: route.c,v 1.76 2007/12/14 18:35:46 deraadt 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.75 2007/09/05 20:29:05 claudio Exp $"; +static char *rcsid = "$OpenBSD: route.c,v 1.76 2007/12/14 18:35:46 deraadt Exp $"; #endif #endif /* not lint */ @@ -324,7 +324,7 @@ rt_stats(int usesysctl, u_long off) struct rtstat rtstat; int mib[6]; size_t size; - + if (usesysctl) { mib[0] = CTL_NET; mib[1] = PF_ROUTE; @@ -362,10 +362,7 @@ encap_print(struct rtentry *rt) { struct sockaddr_encap sen1, sen2, sen3; struct ipsec_policy ipo; - -#ifdef INET6 struct sockaddr_in6 s61, s62; -#endif /* INET6 */ bcopy(kgetsa(rt_key(rt)), &sen1, sizeof(sen1)); bcopy(kgetsa(rt_mask(rt)), &sen2, sizeof(sen2)); @@ -379,7 +376,6 @@ encap_print(struct rtentry *rt) ntohs(sen1.sen_dport), sen1.sen_proto); } -#ifdef INET6 if (sen1.sen_type == SENT_IP6) { bzero(&s61, sizeof(s61)); bzero(&s62, sizeof(s62)); @@ -441,7 +437,6 @@ encap_print(struct rtentry *rt) printf("%-42s %-5u %-5u ", netname6(&s61, &s62), ntohs(sen1.sen_ip6_dport), sen1.sen_ip6_proto); } -#endif /* INET6 */ if (sen3.sen_type == SENT_IPSP) { char hostn[NI_MAXHOST]; diff --git a/usr.bin/netstat/show.c b/usr.bin/netstat/show.c index c8f263a7056..19c93f75f9b 100644 --- a/usr.bin/netstat/show.c +++ b/usr.bin/netstat/show.c @@ -1,4 +1,4 @@ -/* $OpenBSD: show.c,v 1.11 2007/09/05 20:29:05 claudio Exp $ */ +/* $OpenBSD: show.c,v 1.12 2007/12/14 18:35:46 deraadt Exp $ */ /* $NetBSD: show.c,v 1.1 1996/11/15 18:01:41 gwr Exp $ */ /* @@ -191,7 +191,7 @@ p_rttables(int af, u_int tableid) } } -/* +/* * column widths; each followed by one space * width of destination/gateway column * strlen("fe80::aaaa:bbbb:cccc:dddd@gif0") == 30, strlen("/128") == 4 |