void pfkey_stats(u_long off, const char *name, int family __unused, int proto __unused) { struct pfkeystat pfkeystat; unsigned first, type; if (off == 0) return; printf ("%s:\n", name); kread_counters(off, (char *)&pfkeystat, sizeof(pfkeystat)); #define p(f, m) if (pfkeystat.f || sflag <= 1) \ printf(m, (uintmax_t)pfkeystat.f, plural(pfkeystat.f)) /* userland -> kernel */ p(out_total, "\t%ju request%s sent from userland\n"); p(out_bytes, "\t%ju byte%s sent from userland\n"); for (first = 1, type = 0; type < sizeof(pfkeystat.out_msgtype)/sizeof(pfkeystat.out_msgtype[0]); type++) { if (pfkeystat.out_msgtype[type] <= 0) continue; if (first) { printf("\thistogram by message type:\n"); first = 0; } printf("\t\t%s: %ju\n", pfkey_msgtype_names(type), (uintmax_t)pfkeystat.out_msgtype[type]); } p(out_invlen, "\t%ju message%s with invalid length field\n"); p(out_invver, "\t%ju message%s with invalid version field\n"); p(out_invmsgtype, "\t%ju message%s with invalid message type field\n"); p(out_tooshort, "\t%ju message%s too short\n"); p(out_nomem, "\t%ju message%s with memory allocation failure\n"); p(out_dupext, "\t%ju message%s with duplicate extension\n"); p(out_invexttype, "\t%ju message%s with invalid extension type\n"); p(out_invsatype, "\t%ju message%s with invalid sa type\n"); p(out_invaddr, "\t%ju message%s with invalid address extension\n"); /* kernel -> userland */ p(in_total, "\t%ju request%s sent to userland\n"); p(in_bytes, "\t%ju byte%s sent to userland\n"); for (first = 1, type = 0; type < sizeof(pfkeystat.in_msgtype)/sizeof(pfkeystat.in_msgtype[0]); type++) { if (pfkeystat.in_msgtype[type] <= 0) continue; if (first) { printf("\thistogram by message type:\n"); first = 0; } printf("\t\t%s: %ju\n", pfkey_msgtype_names(type), (uintmax_t)pfkeystat.in_msgtype[type]); } p(in_msgtarget[KEY_SENDUP_ONE], "\t%ju message%s toward single socket\n"); p(in_msgtarget[KEY_SENDUP_ALL], "\t%ju message%s toward all sockets\n"); p(in_msgtarget[KEY_SENDUP_REGISTERED], "\t%ju message%s toward registered sockets\n"); p(in_nomem, "\t%ju message%s with memory allocation failure\n"); #undef p }
void pfkey_stats(u_long off, const char *name) { uint64_t pfkeystat[PFKEY_NSTATS]; int first, type; if (use_sysctl) { size_t size = sizeof(pfkeystat); if (sysctlbyname("net.key.stats", pfkeystat, &size, NULL, 0) == -1) return; } else { warnx("%s stats not available via KVM.", name); return; } printf ("%s:\n", name); #define p(f, m) if (pfkeystat[f] || sflag <= 1) \ printf(m, (unsigned long long)pfkeystat[f], plural(pfkeystat[f])) /* userland -> kernel */ p(PFKEY_STAT_OUT_TOTAL, "\t%llu request%s sent from userland\n"); p(PFKEY_STAT_OUT_BYTES, "\t%llu byte%s sent from userland\n"); for (first = 1, type = 0; type < 256; type++) { if (pfkeystat[PFKEY_STAT_OUT_MSGTYPE + type] == 0) continue; if (first) { printf("\thistogram by message type:\n"); first = 0; } printf("\t\t%s: %llu\n", pfkey_msgtype_names(type), (unsigned long long)pfkeystat[PFKEY_STAT_OUT_MSGTYPE + type]); } p(PFKEY_STAT_OUT_INVLEN, "\t%llu message%s with invalid length field\n"); p(PFKEY_STAT_OUT_INVVER, "\t%llu message%s with invalid version field\n"); p(PFKEY_STAT_OUT_INVMSGTYPE, "\t%llu message%s with invalid message type field\n"); p(PFKEY_STAT_OUT_TOOSHORT, "\t%llu message%s too short\n"); p(PFKEY_STAT_OUT_NOMEM, "\t%llu message%s with memory allocation failure\n"); p(PFKEY_STAT_OUT_DUPEXT, "\t%llu message%s with duplicate extension\n"); p(PFKEY_STAT_OUT_INVEXTTYPE, "\t%llu message%s with invalid extension type\n"); p(PFKEY_STAT_OUT_INVSATYPE, "\t%llu message%s with invalid sa type\n"); p(PFKEY_STAT_OUT_INVADDR, "\t%llu message%s with invalid address extension\n"); /* kernel -> userland */ p(PFKEY_STAT_IN_TOTAL, "\t%llu request%s sent to userland\n"); p(PFKEY_STAT_IN_BYTES, "\t%llu byte%s sent to userland\n"); for (first = 1, type = 0; type < 256; type++) { if (pfkeystat[PFKEY_STAT_IN_MSGTYPE + type] == 0) continue; if (first) { printf("\thistogram by message type:\n"); first = 0; } printf("\t\t%s: %llu\n", pfkey_msgtype_names(type), (unsigned long long)pfkeystat[PFKEY_STAT_IN_MSGTYPE + type]); } p(PFKEY_STAT_IN_MSGTARGET + KEY_SENDUP_ONE, "\t%llu message%s toward single socket\n"); p(PFKEY_STAT_IN_MSGTARGET + KEY_SENDUP_ALL, "\t%llu message%s toward all sockets\n"); p(PFKEY_STAT_IN_MSGTARGET + KEY_SENDUP_REGISTERED, "\t%llu message%s toward registered sockets\n"); p(PFKEY_STAT_IN_NOMEM, "\t%llu message%s with memory allocation failure\n"); #undef p }
void pfkey_stats(uint32_t off __unused, char *name, int af __unused) { static struct pfkeystat ppfkeystat; struct pfkeystat pfkeystat; unsigned first, type; size_t len; len = sizeof(struct pfkeystat); if (sysctlbyname("net.key.pfkeystat", &pfkeystat, &len, 0, 0) == -1) return; if (interval && vflag > 0) print_time(); printf ("%s:\n", name); #define PFKEYDIFF(f) (pfkeystat.f - ppfkeystat.f) #define p(f, m) if (PFKEYDIFF(f) || sflag <= 1) \ printf(m, (CAST)PFKEYDIFF(f), plural(PFKEYDIFF(f))) /* kernel -> userland */ p(out_total, "\t" LLU " request%s sent to userland\n"); p(out_bytes, "\t" LLU " byte%s sent to userland\n"); for (first = 1, type = 0; type < sizeof(pfkeystat.out_msgtype)/sizeof(pfkeystat.out_msgtype[0]); type++) { if (PFKEYDIFF(out_msgtype[type]) <= 0) continue; if (first) { printf("\thistogram by message type:\n"); first = 0; } printf("\t\t%s: " LLU "\n", pfkey_msgtype_names(type), (CAST)PFKEYDIFF(out_msgtype[type])); } p(out_invlen, "\t" LLU " message%s with invalid length field\n"); p(out_invver, "\t" LLU " message%s with invalid version field\n"); p(out_invmsgtype, "\t" LLU " message%s with invalid message type field\n"); p(out_tooshort, "\t" LLU " message%s too short\n"); p(out_nomem, "\t" LLU " message%s with memory allocation failure\n"); p(out_dupext, "\t" LLU " message%s with duplicate extension\n"); p(out_invexttype, "\t" LLU " message%s with invalid extension type\n"); p(out_invsatype, "\t" LLU " message%s with invalid sa type\n"); p(out_invaddr, "\t" LLU " message%s with invalid address extension\n"); /* userland -> kernel */ p(in_total, "\t" LLU " request%s sent from userland\n"); p(in_bytes, "\t" LLU " byte%s sent from userland\n"); for (first = 1, type = 0; type < sizeof(pfkeystat.in_msgtype)/sizeof(pfkeystat.in_msgtype[0]); type++) { if (PFKEYDIFF(in_msgtype[type]) <= 0) continue; if (first) { printf("\thistogram by message type:\n"); first = 0; } printf("\t\t%s: " LLU "\n", pfkey_msgtype_names(type), (CAST)PFKEYDIFF(in_msgtype[type])); } p(in_msgtarget[KEY_SENDUP_ONE], "\t" LLU " message%s toward single socket\n"); p(in_msgtarget[KEY_SENDUP_ALL], "\t" LLU " message%s toward all sockets\n"); p(in_msgtarget[KEY_SENDUP_REGISTERED], "\t" LLU " message%s toward registered sockets\n"); p(in_nomem, "\t" LLU " message%s with memory allocation failure\n"); if (interval > 0) bcopy(&pfkeystat, &ppfkeystat, len); #undef PFKEYDIFF #undef p }