From owner-p4-projects@FreeBSD.ORG Thu Jul 30 19:28:41 2009 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id D67311065673; Thu, 30 Jul 2009 19:28:40 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 7D7DD1065670 for ; Thu, 30 Jul 2009 19:28:40 +0000 (UTC) (envelope-from pgj@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 6ADC48FC13 for ; Thu, 30 Jul 2009 19:28:40 +0000 (UTC) (envelope-from pgj@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id n6UJSeXC012476 for ; Thu, 30 Jul 2009 19:28:40 GMT (envelope-from pgj@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id n6UJSeuN012474 for perforce@freebsd.org; Thu, 30 Jul 2009 19:28:40 GMT (envelope-from pgj@FreeBSD.org) Date: Thu, 30 Jul 2009 19:28:40 GMT Message-Id: <200907301928.n6UJSeuN012474@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to pgj@FreeBSD.org using -f From: Gabor Pali To: Perforce Change Reviews Cc: Subject: PERFORCE change 166830 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 30 Jul 2009 19:28:41 -0000 http://perforce.freebsd.org/chv.cgi?CH=166830 Change 166830 by pgj@petymeg-current on 2009/07/30 19:27:55 Use libnetstat(3) in netstat(1) for pfsync statistics. Affected files ... .. //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/extern.h#25 edit .. //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/if.c#4 edit .. //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/main.c#33 edit Differences ... ==== //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/extern.h#25 (text+ko) ==== @@ -85,7 +85,7 @@ 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); +void pfsync_stats(const struct stat_type *); #ifdef IPSEC void ipsec_stats(u_long, const char *, int, int); void esp_stats(u_long, const char *, int, int); ==== //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/if.c#4 (text+ko) ==== @@ -86,46 +86,31 @@ * Dump pfsync statistics structure. */ void -pfsync_stats(u_long off, const char *name, int af1 __unused, int proto __unused) +pfsync_stats(const struct stat_type *sttp) { - struct pfsyncstats pfsyncstat, zerostat; - size_t len = sizeof(struct pfsyncstats); + const struct pfsync_stat *s; - if (live) { - if (zflag) - memset(&zerostat, 0, len); - if (sysctlbyname("net.inet.pfsync.stats", &pfsyncstat, &len, - zflag ? &zerostat : NULL, zflag ? len : 0) < 0) { - if (errno != ENOENT) - warn("sysctl: net.inet.pfsync.stats"); - return; - } - } else - kread(off, &pfsyncstat, len); - - printf("%s:\n", name); - -#define p(f, m) if (pfsyncstat.f || sflag <= 1) \ - printf(m, (uintmax_t)pfsyncstat.f, plural(pfsyncstat.f)) -#define p2(f, m) if (pfsyncstat.f || sflag <= 1) \ - printf(m, (uintmax_t)pfsyncstat.f) - - p(pfsyncs_ipackets, "\t%ju packet%s received (IPv4)\n"); - p(pfsyncs_ipackets6, "\t%ju packet%s received (IPv6)\n"); - p(pfsyncs_badif, "\t\t%ju packet%s discarded for bad interface\n"); - p(pfsyncs_badttl, "\t\t%ju packet%s discarded for bad ttl\n"); - p(pfsyncs_hdrops, "\t\t%ju packet%s shorter than header\n"); - p(pfsyncs_badver, "\t\t%ju packet%s discarded for bad version\n"); - p(pfsyncs_badauth, "\t\t%ju packet%s discarded for bad HMAC\n"); - p(pfsyncs_badact,"\t\t%ju packet%s discarded for bad action\n"); - p(pfsyncs_badlen, "\t\t%ju packet%s discarded for short packet\n"); - p(pfsyncs_badval, "\t\t%ju state%s discarded for bad values\n"); - p(pfsyncs_stale, "\t\t%ju stale state%s\n"); - p(pfsyncs_badstate, "\t\t%ju failed state lookup/insert%s\n"); - p(pfsyncs_opackets, "\t%ju packet%s sent (IPv4)\n"); - p(pfsyncs_opackets6, "\t%ju packet%s sent (IPv6)\n"); - p2(pfsyncs_onomem, "\t\t%ju send failed due to mbuf memory error\n"); - p2(pfsyncs_oerrors, "\t\t%ju send error\n"); + s = netstat_get_pfsyncstats(sttp); +#define p(f, m) if (netstat_pfsyncs_get_##f(s) || sflag <= 1) \ + printf(m, netstat_pfsyncs_get_##f(s), plural(netstat_pfsyncs_get_##f(s))) +#define p2(f, m) if (netstat_pfsyncs_get_##f(s) || sflag <= 1) \ + printf(m, netstat_pfsyncs_get_##f(s)) + p(ipackets, "\t%ju packet%s received (IPv4)\n"); + p(ipackets6, "\t%ju packet%s received (IPv6)\n"); + p(badif, "\t\t%ju packet%s discarded for bad interface\n"); + p(badttl, "\t\t%ju packet%s discarded for bad ttl\n"); + p(hdrops, "\t\t%ju packet%s shorter than header\n"); + p(badver, "\t\t%ju packet%s discarded for bad version\n"); + p(badauth, "\t\t%ju packet%s discarded for bad HMAC\n"); + p(badact,"\t\t%ju packet%s discarded for bad action\n"); + p(badlen, "\t\t%ju packet%s discarded for short packet\n"); + p(badval, "\t\t%ju state%s discarded for bad values\n"); + p(stale, "\t\t%ju stale state%s\n"); + p(badstate, "\t\t%ju failed state lookup/insert%s\n"); + p(opackets, "\t%ju packet%s sent (IPv4)\n"); + p(opackets6, "\t%ju packet%s sent (IPv6)\n"); + p2(onomem, "\t\t%ju send failed due to mbuf memory error\n"); + p2(oerrors, "\t\t%ju send error\n"); #undef p #undef p2 } ==== //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/main.c#33 (text+ko) ==== @@ -109,15 +109,13 @@ { .n_name = "_pfkeystat" }, #define N_RTTRASH 15 { .n_name = "_rttrash" }, -#define N_PFSYNCSTAT 16 - { .n_name = "_pfsyncstats" }, -#define N_AHSTAT 17 +#define N_AHSTAT 16 { .n_name = "_ahstat" }, -#define N_ESPSTAT 18 +#define N_ESPSTAT 17 { .n_name = "_espstat" }, -#define N_IPCOMPSTAT 19 +#define N_IPCOMPSTAT 18 { .n_name = "_ipcompstat" }, -#define N_MFCTABLESIZE 20 +#define N_MFCTABLESIZE 19 { .n_name = "_mfctablesize" }, { .n_name = NULL }, }; @@ -167,8 +165,8 @@ NULL, NULL, "pim", 1, IPPROTO_PIM }, { -1, 0, 1, NULL, carp_stats, stat_CARP, NULL, NULL, "carp", 1, 0 }, - { -1, N_PFSYNCSTAT, 1, NULL, NULL, stat_MAX, - pfsync_stats, NULL, "pfsync", 1, 0 }, + { -1, 0, 1, NULL, pfsync_stats, stat_pfsync, + NULL, NULL, "pfsync", 1, 0 }, { -1, -1, 0, NULL, NULL, stat_MAX, NULL, NULL, NULL, 0, 0 } };