Print newly exported pfsync statistics with netstat(8).

Requested by:	glebius
MFC after:	1 week
This commit is contained in:
Max Laier 2005-07-14 22:42:35 +00:00
parent 6de8d9dc52
commit 2e37c5a333
3 changed files with 51 additions and 0 deletions

View File

@ -52,12 +52,16 @@ __FBSDID("$FreeBSD$");
#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>
#include <err.h>
#include <errno.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
@ -118,8 +122,50 @@ bdg_stats(u_long dummy __unused, const char *name, int af1 __unused)
}
}
/*
* Dump pfsync statistics structure.
*/
void
pfsync_stats(u_long off __unused, const char *name, int af1 __unused)
{
struct pfsyncstats pfsyncstat, zerostat;
size_t len = sizeof(struct pfsyncstats);
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;
}
printf("%s:\n", name);
#define p(f, m) if (pfsyncstat.f || sflag <= 1) \
printf(m, (unsigned long long)pfsyncstat.f, plural(pfsyncstat.f))
#define p2(f, m) if (pfsyncstat.f || sflag <= 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
}
/*
* Display a formatted value, or a '-' in the same space.

View File

@ -138,6 +138,8 @@ static struct nlist nl[] = {
{ "_clust_lowm" },
#define N_CARPSTAT 33
{ "_carpstats" },
#define N_PFSYNCSTAT 34
{ "_pfsyncstats" },
{ "" },
};
@ -175,6 +177,8 @@ struct protox {
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 }
};

View File

@ -72,6 +72,7 @@ void icmp_stats(u_long, const char *, int);
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