PERFORCE change 166689 for review
Gabor Pali
pgj at FreeBSD.org
Tue Jul 28 18:59:46 UTC 2009
http://perforce.freebsd.org/chv.cgi?CH=166689
Change 166689 by pgj at petymeg-current on 2009/07/28 18:59:10
Make netstat(1) use libnetstat(3) for working with IGMP statistics.
Affected files ...
.. //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/extern.h#17 edit
.. //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/inet.c#32 edit
.. //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/main.c#25 edit
Differences ...
==== //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/extern.h#17 (text+ko) ====
@@ -82,7 +82,7 @@
#endif
void ip_stats(const struct stat_type *);
void icmp_stats(const struct stat_type *);
-void igmp_stats(u_long, const char *, int, int);
+void igmp_stats(const struct stat_type *);
void pim_stats(const struct stat_type *);
void carp_stats(const struct stat_type *);
void pfsync_stats(u_long, const char *, int, int);
==== //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/inet.c#32 (text+ko) ====
@@ -551,125 +551,38 @@
netstat_icmp_get_maskrepl(NULL) ? "en" : "dis");
}
-#ifndef BURN_BRIDGES
/*
- * Dump IGMP statistics structure (pre 8.x kernel).
- */
-static void
-igmp_stats_live_old(u_long off, const char *name)
-{
- struct oigmpstat oigmpstat, zerostat;
- size_t len = sizeof(oigmpstat);
-
- if (zflag)
- memset(&zerostat, 0, len);
- if (sysctlbyname("net.inet.igmp.stats", &oigmpstat, &len,
- zflag ? &zerostat : NULL, zflag ? len : 0) < 0) {
- warn("sysctl: net.inet.igmp.stats");
- return;
- }
-
- printf("%s:\n", name);
-
-#define p(f, m) if (oigmpstat.f || sflag <= 1) \
- printf(m, oigmpstat.f, plural(oigmpstat.f))
-#define py(f, m) if (oigmpstat.f || sflag <= 1) \
- printf(m, oigmpstat.f, oigmpstat.f != 1 ? "ies" : "y")
- p(igps_rcv_total, "\t%u message%s received\n");
- p(igps_rcv_tooshort, "\t%u message%s received with too few bytes\n");
- p(igps_rcv_badsum, "\t%u message%s received with bad checksum\n");
- py(igps_rcv_queries, "\t%u membership quer%s received\n");
- py(igps_rcv_badqueries,
- "\t%u membership quer%s received with invalid field(s)\n");
- p(igps_rcv_reports, "\t%u membership report%s received\n");
- p(igps_rcv_badreports,
- "\t%u membership report%s received with invalid field(s)\n");
- p(igps_rcv_ourreports,
-"\t%u membership report%s received for groups to which we belong\n");
- p(igps_snd_reports, "\t%u membership report%s sent\n");
-#undef p
-#undef py
-}
-#endif /* !BURN_BRIDGES */
-
-/*
* Dump IGMP statistics structure.
*/
void
-igmp_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
+igmp_stats(const struct stat_type *sttp)
{
- struct igmpstat igmpstat, zerostat;
- size_t len;
+ const struct igmp_stat *s;
-#ifndef BURN_BRIDGES
- if (live) {
- /*
- * Detect if we are being run against a pre-IGMPv3 kernel.
- * We cannot do this for a core file as the legacy
- * struct igmpstat has no size field, nor does it
- * export it in any readily-available symbols.
- */
- len = 0;
- if (sysctlbyname("net.inet.igmp.stats", NULL, &len, NULL,
- 0) < 0) {
- warn("sysctl: net.inet.igmp.stats");
- return;
- }
- if (len < sizeof(igmpstat)) {
- igmp_stats_live_old(off, name);
- return;
- }
- }
-#endif /* !BURN_BRIDGES */
-
- len = sizeof(igmpstat);
- if (live) {
- if (zflag)
- memset(&zerostat, 0, len);
- if (sysctlbyname("net.inet.igmp.stats", &igmpstat, &len,
- zflag ? &zerostat : NULL, zflag ? len : 0) < 0) {
- warn("sysctl: net.inet.igmp.stats");
- return;
- }
- } else {
- len = sizeof(igmpstat);
- kread(off, &igmpstat, len);
- }
-
- if (igmpstat.igps_version != IGPS_VERSION_3) {
- warnx("%s: version mismatch (%d != %d)", __func__,
- igmpstat.igps_version, IGPS_VERSION_3);
- }
- if (igmpstat.igps_len != IGPS_VERSION3_LEN) {
- warnx("%s: size mismatch (%d != %d)", __func__,
- igmpstat.igps_len, IGPS_VERSION3_LEN);
- }
-
- printf("%s:\n", name);
-
-#define p64(f, m) if (igmpstat.f || sflag <= 1) \
- printf(m, (uintmax_t) igmpstat.f, plural(igmpstat.f))
-#define py64(f, m) if (igmpstat.f || sflag <= 1) \
- printf(m, (uintmax_t) igmpstat.f, pluralies(igmpstat.f))
- p64(igps_rcv_total, "\t%ju message%s received\n");
- p64(igps_rcv_tooshort, "\t%ju message%s received with too few bytes\n");
- p64(igps_rcv_badttl, "\t%ju message%s received with wrong TTL\n");
- p64(igps_rcv_badsum, "\t%ju message%s received with bad checksum\n");
- py64(igps_rcv_v1v2_queries, "\t%ju V1/V2 membership quer%s received\n");
- py64(igps_rcv_v3_queries, "\t%ju V3 membership quer%s received\n");
- py64(igps_rcv_badqueries,
+ s = netstat_get_igmpstats(sttp);
+#define p64(f, m) if (netstat_igmps_get_##f(s) || sflag <= 1) \
+ printf(m, netstat_igmps_get_##f(s), plural(netstat_igmps_get_##f(s)))
+#define py64(f, m) if (netstat_igmps_get_##f(s) || sflag <= 1) \
+ printf(m, netstat_igmps_get_##f(s), pluralies(netstat_igmps_get_##f(s)))
+ p64(rcv_total, "\t%ju message%s received\n");
+ p64(rcv_tooshort, "\t%ju message%s received with too few bytes\n");
+ p64(rcv_badttl, "\t%ju message%s received with wrong TTL\n");
+ p64(rcv_badsum, "\t%ju message%s received with bad checksum\n");
+ py64(rcv_v1v2_queries, "\t%ju V1/V2 membership quer%s received\n");
+ py64(rcv_v3_queries, "\t%ju V3 membership quer%s received\n");
+ py64(rcv_badqueries,
"\t%ju membership quer%s received with invalid field(s)\n");
- py64(igps_rcv_gen_queries, "\t%ju general quer%s received\n");
- py64(igps_rcv_group_queries, "\t%ju group quer%s received\n");
- py64(igps_rcv_gsr_queries, "\t%ju group-source quer%s received\n");
- py64(igps_drop_gsr_queries, "\t%ju group-source quer%s dropped\n");
- p64(igps_rcv_reports, "\t%ju membership report%s received\n");
- p64(igps_rcv_badreports,
+ py64(rcv_gen_queries, "\t%ju general quer%s received\n");
+ py64(rcv_group_queries, "\t%ju group quer%s received\n");
+ py64(rcv_gsr_queries, "\t%ju group-source quer%s received\n");
+ py64(drop_gsr_queries, "\t%ju group-source quer%s dropped\n");
+ p64(rcv_reports, "\t%ju membership report%s received\n");
+ p64(rcv_badreports,
"\t%ju membership report%s received with invalid field(s)\n");
- p64(igps_rcv_ourreports,
+ p64(rcv_ourreports,
"\t%ju membership report%s received for groups to which we belong\n");
- p64(igps_rcv_nora, "\t%ju V3 report%s received without Router Alert\n");
- p64(igps_snd_reports, "\t%ju membership report%s sent\n");
+ p64(rcv_nora, "\t%ju V3 report%s received without Router Alert\n");
+ p64(snd_reports, "\t%ju membership report%s sent\n");
#undef p64
#undef py64
}
==== //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/main.c#25 (text+ko) ====
@@ -127,13 +127,11 @@
{ .n_name = "_espstat" },
#define N_IPCOMPSTAT 24
{ .n_name = "_ipcompstat" },
-#define N_IGMPSTAT 25
- { .n_name = "_igmpstat" },
-#define N_RIP6STAT 26
+#define N_RIP6STAT 25
{ .n_name = "_rip6stat" },
-#define N_SCTPSTAT 27
+#define N_SCTPSTAT 26
{ .n_name = "_sctpstat" },
-#define N_MFCTABLESIZE 28
+#define N_MFCTABLESIZE 27
{ .n_name = "_mfctablesize" },
{ .n_name = NULL },
};
@@ -167,8 +165,8 @@
NULL, NULL, "ip", 1, IPPROTO_RAW },
{ 0, 0, 1, NULL, icmp_stats, stat_ICMP,
NULL, NULL, "icmp", 1, IPPROTO_ICMP },
- { 0, N_IGMPSTAT, 1, NULL, NULL, stat_MAX,
- igmp_stats, NULL, "igmp", 1, IPPROTO_IGMP },
+ { 0, 0, 1, NULL, igmp_stats, stat_IGMP,
+ NULL, NULL, "igmp", 1, IPPROTO_IGMP },
#ifdef IPSEC
{ -1, N_IPSECSTAT, 1, NULL, NULL, stat_MAX, /* keep as compat */
ipsec_stats, NULL, "ipsec", 0, 0},
More information about the p4-projects
mailing list