Date: Fri, 8 Jul 2005 15:04:10 +0200 From: Max Laier <max@love2party.net> To: freebsd-pf@freebsd.org Subject: Export pfsync statistics to netstat Message-ID: <200507081504.16363.max@love2party.net>
next in thread | raw e-mail | index | archive | help
--nextPart4431019.7DtTJ9QfDD Content-Type: multipart/mixed; boundary="Boundary-01=_LnnzC5+8raykqbM" Content-Transfer-Encoding: 7bit Content-Disposition: inline --Boundary-01=_LnnzC5+8raykqbM Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline All, can you please give the attached patch a try? It's relative to CURRENT and= =20 should enable you to say: $ netstat -sp pfsync to get pfsync statistics. You need to recompile the kernel and netstat of= =20 course. Thanks for your reports! =2D-=20 /"\ Best regards, | mlaier@freebsd.org \ / Max Laier | ICQ #67774661 X http://pf4freebsd.love2party.net/ | mlaier@EFnet / \ ASCII Ribbon Campaign | Against HTML Mail and News --Boundary-01=_LnnzC5+8raykqbM Content-Type: text/x-diff; charset="us-ascii"; name="pfsyncstat.diff" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="pfsyncstat.diff" Index: usr.bin/netstat/if.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /usr/store/mlaier/fcvs/src/usr.bin/netstat/if.c,v retrieving revision 1.58 diff -u -r1.58 if.c =2D-- usr.bin/netstat/if.c 26 Jul 2004 20:18:11 -0000 1.58 +++ usr.bin/netstat/if.c 7 Jul 2005 17:36:51 -0000 @@ -52,12 +52,16 @@ #include <net/if_types.h> #include <net/bridge.h> #include <net/ethernet.h> +#include <net/pfvar.h> +#include <net/if_pfsync.h> #include <netinet/in.h> #include <netinet/in_var.h> #include <netipx/ipx.h> #include <netipx/ipx_if.h> #include <arpa/inet.h> =20 +#include <err.h> +#include <errno.h> #include <signal.h> #include <stdio.h> #include <stdlib.h> @@ -118,8 +122,50 @@ } } =20 +/*=20 + * Dump pfsync statistics structure. + */ +void +pfsync_stats(u_long off __unused, const char *name, int af1 __unused) +{ + struct pfsyncstats pfsyncstat, zerostat; + size_t len =3D sizeof(struct pfsyncstats); =20 + if (zflag) + memset(&zerostat, 0, len); + if (sysctlbyname("net.inet.pfsync.stats", &pfsyncstat, &len, + zflag ? &zerostat : NULL, zflag ? len : 0) < 0) { + if (errno !=3D ENOENT) + warn("sysctl: net.inet.pfsync.stats"); + return; + } + + printf("%s:\n", name); =20 +#define p(f, m) if (pfsyncstat.f || sflag <=3D 1) \ + printf(m, (unsigned long long)pfsyncstat.f, plural(pfsyncstat.f)) +#define p2(f, m) if (pfsyncstat.f || sflag <=3D 1) \ + printf(m, (unsigned long long)pfsyncstat.f) + + p(pfsyncs_ipackets, "\t%llu packet%s received (IPv4)\n"); + p(pfsyncs_ipackets6, "\t%llu packet%s received (IPv6)\n"); + p(pfsyncs_badif, "\t\t%llu packet%s discarded for bad interface\n"); + p(pfsyncs_badttl, "\t\t%llu packet%s discarded for bad ttl\n"); + p(pfsyncs_hdrops, "\t\t%llu packet%s shorter than header\n"); + p(pfsyncs_badver, "\t\t%llu packet%s discarded for bad version\n"); + p(pfsyncs_badauth, "\t\t%llu packet%s discarded for bad HMAC\n"); + p(pfsyncs_badact,"\t\t%llu packet%s discarded for bad action\n"); + p(pfsyncs_badlen, "\t\t%llu packet%s discarded for short packet\n"); + p(pfsyncs_badval, "\t\t%llu state%s discarded for bad values\n"); + p(pfsyncs_stale, "\t\t%llu stale state%s\n"); + p(pfsyncs_badstate, "\t\t%llu failed state lookup/insert%s\n"); + p(pfsyncs_opackets, "\t%llu packet%s sent (IPv4)\n"); + p(pfsyncs_opackets6, "\t%llu packet%s sent (IPv6)\n"); + p2(pfsyncs_onomem, "\t\t%llu send failed due to mbuf memory error\n"); + p2(pfsyncs_oerrors, "\t\t%llu send error\n"); +#undef p +#undef p2 +} =20 /* * Display a formatted value, or a '-' in the same space. Index: usr.bin/netstat/main.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /usr/store/mlaier/fcvs/src/usr.bin/netstat/main.c,v retrieving revision 1.72 diff -u -r1.72 main.c =2D-- usr.bin/netstat/main.c 22 Feb 2005 13:04:04 -0000 1.72 +++ usr.bin/netstat/main.c 7 Jul 2005 17:28:08 -0000 @@ -138,6 +138,8 @@ { "_clust_lowm" }, #define N_CARPSTAT 33 { "_carpstats" }, +#define N_PFSYNCSTAT 34 + { "_pfsyncstats" }, { "" }, }; =20 @@ -175,6 +177,8 @@ pim_stats, NULL, "pim", IPPROTO_PIM }, { -1, N_CARPSTAT, 1, 0, carp_stats, NULL, "carp", 0}, + { -1, -1, 1, NULL, + pfsync_stats, NULL, "pfsync", 1}, { -1, -1, 0, NULL, NULL, NULL, NULL, 0 } }; Index: usr.bin/netstat/netstat.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /usr/store/mlaier/fcvs/src/usr.bin/netstat/netstat.h,v retrieving revision 1.41 diff -u -r1.41 netstat.h =2D-- usr.bin/netstat/netstat.h 22 Feb 2005 13:04:05 -0000 1.41 +++ usr.bin/netstat/netstat.h 7 Jul 2005 17:23:39 -0000 @@ -72,6 +72,7 @@ void igmp_stats(u_long, const char *, int); void pim_stats(u_long, const char *, int); void carp_stats (u_long, const char *, int); +void pfsync_stats (u_long, const char *, int); #ifdef IPSEC void ipsec_stats(u_long, const char *, int); #endif Index: sys/contrib/pf/net/if_pfsync.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /usr/store/mlaier/fcvs/src/sys/contrib/pf/net/if_pfsync.c,v retrieving revision 1.19 diff -u -r1.19 if_pfsync.c =2D-- sys/contrib/pf/net/if_pfsync.c 26 Jun 2005 21:00:52 -0000 1.19 +++ sys/contrib/pf/net/if_pfsync.c 7 Jul 2005 16:40:21 -0000 @@ -119,8 +119,10 @@ struct pfsync_softc pfsyncif; #endif struct pfsyncstats pfsyncstats; =2D #ifdef __FreeBSD__ +SYSCTL_STRUCT(_net_inet_pfsync, 0, stats, CTLFLAG_RW, + &pfsyncstats, pfsyncstats, + "PFSYNC statistics (struct pfsyncstats, net/if_pfsync.h)"); =20 /* * Locking notes: --Boundary-01=_LnnzC5+8raykqbM-- --nextPart4431019.7DtTJ9QfDD Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (FreeBSD) iD8DBQBCznnQXyyEoT62BG0RAjMZAJ9fOxn2x7RCmdhwduiBMJ2NbgwYvACggRq7 C9XUvsV3dtj8R/ZzUgskLM0= =Oo/4 -----END PGP SIGNATURE----- --nextPart4431019.7DtTJ9QfDD--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200507081504.16363.max>