PERFORCE change 166624 for review
Gabor Pali
pgj at FreeBSD.org
Mon Jul 27 14:48:52 UTC 2009
http://perforce.freebsd.org/chv.cgi?CH=166624
Change 166624 by pgj at petymeg-current on 2009/07/27 14:47:50
Teach netstat(1) to use libnetstat(3) for UDP statistics.
Affected files ...
.. //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/extern.h#11 edit
.. //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/inet.c#26 edit
.. //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/main.c#19 edit
Differences ...
==== //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/extern.h#11 (text+ko) ====
@@ -75,7 +75,7 @@
void inetppr(const struct socket_type *);
void unixdomainpr(const struct socket_type *);
void tcp_stats(void *, const char *);
-void udp_stats(u_long, const char *, int, int);
+void udp_stats(void *, const char *);
#ifdef SCTP
void sctp_protopr(u_long, const char *, int, int);
void sctp_stats(u_long, const char *, int, int);
==== //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/inet.c#26 (text+ko) ====
@@ -405,11 +405,11 @@
* Dump UDP statistics structure.
*/
void
-udp_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
+udp_stats(void *kvmd, const char *name)
{
- struct udpstat udpstat, zerostat;
- size_t len = sizeof udpstat;
- u_long delivered;
+ const struct udp_stat *s;
+ struct stat_type *sttp;
+ int stt_flags, error;
#ifdef INET6
if (udp_done != 0)
@@ -418,45 +418,54 @@
udp_done = 1;
#endif
- if (live) {
- if (zflag)
- memset(&zerostat, 0, len);
- if (sysctlbyname("net.inet.udp.stats", &udpstat, &len,
- zflag ? &zerostat : NULL, zflag ? len : 0) < 0) {
- warn("sysctl: net.inet.udp.stats");
- return;
- }
- } else
- kread(off, &udpstat, len);
+ if (zflag) {
+ netstat_zerostat(stat_UDP);
+ return;
+ }
+
+ stt_flags = 0;
+ if (!live)
+ stt_flags |= NETSTAT_STAT_KVM;
+
+ sttp = netstat_stat_alloc();
+ if (sttp == NULL) {
+ warn("netstat_stat_alloc");
+ return;
+ }
+
+ if (netstat_stat(stat_UDP, sttp, stt_flags, kvmd) < 0) {
+ error = netstat_stat_geterror(sttp);
+ if (error == NETSTAT_ERROR_KVM)
+ warnx("netstat_stat: %s", kvm_geterr(kvmd));
+ else
+ warnx("netstat_stat: %s", netstat_strerror(error));
+ goto out;
+ }
+
+ s = netstat_get_udpstats(sttp);
printf("%s:\n", name);
-#define p(f, m) if (udpstat.f || sflag <= 1) \
- printf(m, udpstat.f, plural(udpstat.f))
-#define p1a(f, m) if (udpstat.f || sflag <= 1) \
- printf(m, udpstat.f)
- p(udps_ipackets, "\t%lu datagram%s received\n");
- p1a(udps_hdrops, "\t%lu with incomplete header\n");
- p1a(udps_badlen, "\t%lu with bad data length field\n");
- p1a(udps_badsum, "\t%lu with bad checksum\n");
- p1a(udps_nosum, "\t%lu with no checksum\n");
- p1a(udps_noport, "\t%lu dropped due to no socket\n");
- p(udps_noportbcast,
- "\t%lu broadcast/multicast datagram%s undelivered\n");
- p1a(udps_fullsock, "\t%lu dropped due to full socket buffers\n");
- p1a(udpps_pcbhashmiss, "\t%lu not for hashed pcb\n");
- delivered = udpstat.udps_ipackets -
- udpstat.udps_hdrops -
- udpstat.udps_badlen -
- udpstat.udps_badsum -
- udpstat.udps_noport -
- udpstat.udps_noportbcast -
- udpstat.udps_fullsock;
- if (delivered || sflag <= 1)
- printf("\t%lu delivered\n", delivered);
- p(udps_opackets, "\t%lu datagram%s output\n");
+#define p(f, m) if (netstat_udps_get_##f(s) || sflag <= 1) \
+ printf(m, netstat_udps_get_##f(s), plural(netstat_udps_get_##f(s)))
+#define p1a(f, m) if (netstat_udps_get_##f(s) || sflag <= 1) \
+ printf(m, netstat_udps_get_##f(s))
+ p(ipackets, "\t%ju datagram%s received\n");
+ p1a(hdrops, "\t%ju with incomplete header\n");
+ p1a(badlen, "\t%ju with bad data length field\n");
+ p1a(badsum, "\t%ju with bad checksum\n");
+ p1a(nosum, "\t%ju with no checksum\n");
+ p1a(noport, "\t%ju dropped due to no socket\n");
+ p(noportbcast,
+ "\t%ju broadcast/multicast datagram%s undelivered\n");
+ p1a(fullsock, "\t%ju dropped due to full socket buffers\n");
+ p1a(pcbhashmiss, "\t%ju not for hashed pcb\n");
+ p1a(delivered, "\t%ju delivered\n");
+ p(opackets, "\t%ju datagram%s output\n");
/* the next statistic is cumulative in udps_noportbcast */
- p(udps_filtermcast,
- "\t%lu time%s multicast source filter matched\n");
+ p(filtermcast,
+ "\t%ju time%s multicast source filter matched\n");
+out:
+ netstat_stat_free(sttp);
#undef p
#undef p1a
}
==== //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/main.c#19 (text+ko) ====
@@ -129,21 +129,19 @@
{ .n_name = "_espstat" },
#define N_IPCOMPSTAT 25
{ .n_name = "_ipcompstat" },
-#define N_UDPSTAT 26
- { .n_name = "_udpstat" },
-#define N_IPSTAT 27
+#define N_IPSTAT 26
{ .n_name = "_ipstat" },
-#define N_ICMPSTAT 28
+#define N_ICMPSTAT 27
{ .n_name = "_icmpstat" },
-#define N_IGMPSTAT 29
+#define N_IGMPSTAT 28
{ .n_name = "_igmpstat" },
-#define N_PIMSTAT 30
+#define N_PIMSTAT 29
{ .n_name = "_pimstat" },
-#define N_RIP6STAT 31
+#define N_RIP6STAT 30
{ .n_name = "_rip6stat" },
-#define N_SCTPSTAT 32
+#define N_SCTPSTAT 31
{ .n_name = "_sctpstat" },
-#define N_MFCTABLESIZE 33
+#define N_MFCTABLESIZE 32
{ .n_name = "_mfctablesize" },
{ .n_name = NULL },
};
@@ -163,8 +161,8 @@
} protox[] = {
{ 0, 0, 1, NULL,
NULL, NULL, "tcp", 1, IPPROTO_TCP },
- { 0, N_UDPSTAT, 1, NULL,
- udp_stats, NULL, "udp", 1, IPPROTO_UDP },
+ { 0, 0, 1, NULL,
+ NULL, NULL, "udp", 1, IPPROTO_UDP },
#ifdef SCTP
{ -1, N_SCTPSTAT, 1, sctp_protopr,
sctp_stats, NULL, "sctp", 1, IPPROTO_SCTP },
@@ -201,8 +199,8 @@
struct protox ip6protox[] = {
{ 0, 0, 1, NULL,
NULL, NULL, "tcp", 1, IPPROTO_TCP },
- { 0, N_UDPSTAT, 1, NULL,
- udp_stats, NULL, "udp", 1, IPPROTO_UDP },
+ { 0, 0, 1, NULL,
+ NULL, NULL, "udp", 1, IPPROTO_UDP },
{ 0, N_IP6STAT, 1, NULL,
ip6_stats, ip6_ifstats, "ip6", 1, IPPROTO_RAW },
{ 0, N_ICMP6STAT, 1, NULL,
@@ -657,6 +655,9 @@
case IPPROTO_TCP:
tcp_stats(kvmd, "tcp");
break;
+ case IPPROTO_UDP:
+ udp_stats(kvmd, "udp");
+ break;
default:
pr = tp->pr_stats;
if (!pr) {
More information about the p4-projects
mailing list