Beispiel #1
0
/*
 * Dump IP6 statistics structure.
 */
void
ip6_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
{
	struct ip6stat ip6stat, zerostat;
	int first, i;
	size_t len;

	len = sizeof ip6stat;
	if (live) {
		memset(&ip6stat, 0, len);
		if (zflag)
			memset(&zerostat, 0, len);
		if (sysctlbyname("net.inet6.ip6.stats", &ip6stat, &len,
		    zflag ? &zerostat : NULL, zflag ? len : 0) < 0) {
			if (errno != ENOENT)
				warn("sysctl: net.inet6.ip6.stats");
			return;
		}
	} else
		kread_counters(off, &ip6stat, len);

	printf("%s:\n", name);

#define	p(f, m) if (ip6stat.f || sflag <= 1) \
    printf(m, (uintmax_t)ip6stat.f, plural(ip6stat.f))
#define	p1a(f, m) if (ip6stat.f || sflag <= 1) \
    printf(m, (uintmax_t)ip6stat.f)

	p(ip6s_total, "\t%ju total packet%s received\n");
	p1a(ip6s_toosmall, "\t%ju with size smaller than minimum\n");
	p1a(ip6s_tooshort, "\t%ju with data size < data length\n");
	p1a(ip6s_badoptions, "\t%ju with bad options\n");
	p1a(ip6s_badvers, "\t%ju with incorrect version number\n");
	p(ip6s_fragments, "\t%ju fragment%s received\n");
	p(ip6s_fragdropped, "\t%ju fragment%s dropped (dup or out of space)\n");
	p(ip6s_fragtimeout, "\t%ju fragment%s dropped after timeout\n");
	p(ip6s_fragoverflow, "\t%ju fragment%s that exceeded limit\n");
	p(ip6s_reassembled, "\t%ju packet%s reassembled ok\n");
	p(ip6s_delivered, "\t%ju packet%s for this host\n");
	p(ip6s_forward, "\t%ju packet%s forwarded\n");
	p(ip6s_cantforward, "\t%ju packet%s not forwardable\n");
	p(ip6s_redirectsent, "\t%ju redirect%s sent\n");
	p(ip6s_localout, "\t%ju packet%s sent from this host\n");
	p(ip6s_rawout, "\t%ju packet%s sent with fabricated ip header\n");
	p(ip6s_odropped, "\t%ju output packet%s dropped due to no bufs, etc.\n");
	p(ip6s_noroute, "\t%ju output packet%s discarded due to no route\n");
	p(ip6s_fragmented, "\t%ju output datagram%s fragmented\n");
	p(ip6s_ofragments, "\t%ju fragment%s created\n");
	p(ip6s_cantfrag, "\t%ju datagram%s that can't be fragmented\n");
	p(ip6s_badscope, "\t%ju packet%s that violated scope rules\n");
	p(ip6s_notmember, "\t%ju multicast packet%s which we don't join\n");
	for (first = 1, i = 0; i < IP6S_HDRCNT; i++)
		if (ip6stat.ip6s_nxthist[i] != 0) {
			if (first) {
				printf("\tInput histogram:\n");
				first = 0;
			}
			printf("\t\t%s: %ju\n", ip6nh[i],
			    (uintmax_t)ip6stat.ip6s_nxthist[i]);
		}
	printf("\tMbuf statistics:\n");
	printf("\t\t%ju one mbuf\n", (uintmax_t)ip6stat.ip6s_m1);
	for (first = 1, i = 0; i < IP6S_M2MMAX; i++) {
		char ifbuf[IFNAMSIZ];
		if (ip6stat.ip6s_m2m[i] != 0) {
			if (first) {
				printf("\t\ttwo or more mbuf:\n");
				first = 0;
			}
			printf("\t\t\t%s= %ju\n",
			    if_indextoname(i, ifbuf),
			    (uintmax_t)ip6stat.ip6s_m2m[i]);
		}
	}
	printf("\t\t%ju one ext mbuf\n",
	    (uintmax_t)ip6stat.ip6s_mext1);
	printf("\t\t%ju two or more ext mbuf\n",
	    (uintmax_t)ip6stat.ip6s_mext2m);
	p(ip6s_exthdrtoolong,
	    "\t%ju packet%s whose headers are not contiguous\n");
	p(ip6s_nogif, "\t%ju tunneling packet%s that can't find gif\n");
	p(ip6s_toomanyhdr,
	    "\t%ju packet%s discarded because of too many headers\n");

	/* for debugging source address selection */
#define	PRINT_SCOPESTAT(s,i) do {\
		switch(i) { /* XXX hardcoding in each case */\
		case 1:\
			p(s, "\t\t%ju interface-local%s\n");\
			break;\
		case 2:\
			p(s,"\t\t%ju link-local%s\n");\
			break;\
		case 5:\
			p(s,"\t\t%ju site-local%s\n");\
			break;\
		case 14:\
			p(s,"\t\t%ju global%s\n");\
			break;\
		default:\
			printf("\t\t%ju addresses scope=%x\n",\
			    (uintmax_t)ip6stat.s, i);\
		}\
	} while (0);

	p(ip6s_sources_none,
	  "\t%ju failure%s of source address selection\n");
	for (first = 1, i = 0; i < IP6S_SCOPECNT; i++) {
		if (ip6stat.ip6s_sources_sameif[i]) {
			if (first) {
				printf("\tsource addresses on an outgoing I/F\n");
				first = 0;
			}
			PRINT_SCOPESTAT(ip6s_sources_sameif[i], i);
		}
	}
	for (first = 1, i = 0; i < IP6S_SCOPECNT; i++) {
		if (ip6stat.ip6s_sources_otherif[i]) {
			if (first) {
				printf("\tsource addresses on a non-outgoing I/F\n");
				first = 0;
			}
			PRINT_SCOPESTAT(ip6s_sources_otherif[i], i);
		}
	}
	for (first = 1, i = 0; i < IP6S_SCOPECNT; i++) {
		if (ip6stat.ip6s_sources_samescope[i]) {
			if (first) {
				printf("\tsource addresses of same scope\n");
				first = 0;
			}
			PRINT_SCOPESTAT(ip6s_sources_samescope[i], i);
		}
	}
	for (first = 1, i = 0; i < IP6S_SCOPECNT; i++) {
		if (ip6stat.ip6s_sources_otherscope[i]) {
			if (first) {
				printf("\tsource addresses of a different scope\n");
				first = 0;
			}
			PRINT_SCOPESTAT(ip6s_sources_otherscope[i], i);
		}
	}
	for (first = 1, i = 0; i < IP6S_SCOPECNT; i++) {
		if (ip6stat.ip6s_sources_deprecated[i]) {
			if (first) {
				printf("\tdeprecated source addresses\n");
				first = 0;
			}
			PRINT_SCOPESTAT(ip6s_sources_deprecated[i], i);
		}
	}

	printf("\tSource addresses selection rule applied:\n");
	for (i = 0; i < IP6S_RULESMAX; i++) {
		if (ip6stat.ip6s_sources_rule[i])
			printf("\t\t%ju %s\n",
			       (uintmax_t)ip6stat.ip6s_sources_rule[i],
			       srcrule_str[i]);
	}
#undef p
#undef p1a
}
Beispiel #2
0
/*
 * Dump ICMP6 statistics.
 */
void
icmp6_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
{
	struct icmp6stat icmp6stat, zerostat;
	int i, first;
	size_t len;

	len = sizeof icmp6stat;
	if (live) {
		memset(&icmp6stat, 0, len);
		if (zflag)
			memset(&zerostat, 0, len);
		if (sysctlbyname("net.inet6.icmp6.stats", &icmp6stat, &len,
		    zflag ? &zerostat : NULL, zflag ? len : 0) < 0) {
			if (errno != ENOENT)
				warn("sysctl: net.inet6.icmp6.stats");
			return;
		}
	} else
		kread_counters(off, &icmp6stat, len);

	printf("%s:\n", name);

#define	p(f, m) if (icmp6stat.f || sflag <= 1) \
    printf(m, (uintmax_t)icmp6stat.f, plural(icmp6stat.f))
#define	p_5(f, m) if (icmp6stat.f || sflag <= 1) \
    printf(m, (uintmax_t)icmp6stat.f)

	p(icp6s_error, "\t%ju call%s to icmp6_error\n");
	p(icp6s_canterror,
	    "\t%ju error%s not generated in response to an icmp6 message\n");
	p(icp6s_toofreq,
	  "\t%ju error%s not generated because of rate limitation\n");
#define	NELEM (int)(sizeof(icmp6stat.icp6s_outhist)/sizeof(icmp6stat.icp6s_outhist[0]))
	for (first = 1, i = 0; i < NELEM; i++)
		if (icmp6stat.icp6s_outhist[i] != 0) {
			if (first) {
				printf("\tOutput histogram:\n");
				first = 0;
			}
			printf("\t\t%s: %ju\n", icmp6names[i],
			    (uintmax_t)icmp6stat.icp6s_outhist[i]);
		}
#undef NELEM
	p(icp6s_badcode, "\t%ju message%s with bad code fields\n");
	p(icp6s_tooshort, "\t%ju message%s < minimum length\n");
	p(icp6s_checksum, "\t%ju bad checksum%s\n");
	p(icp6s_badlen, "\t%ju message%s with bad length\n");
#define	NELEM (int)(sizeof(icmp6stat.icp6s_inhist)/sizeof(icmp6stat.icp6s_inhist[0]))
	for (first = 1, i = 0; i < NELEM; i++)
		if (icmp6stat.icp6s_inhist[i] != 0) {
			if (first) {
				printf("\tInput histogram:\n");
				first = 0;
			}
			printf("\t\t%s: %ju\n", icmp6names[i],
			    (uintmax_t)icmp6stat.icp6s_inhist[i]);
		}
#undef NELEM
	printf("\tHistogram of error messages to be generated:\n");
	p_5(icp6s_odst_unreach_noroute, "\t\t%ju no route\n");
	p_5(icp6s_odst_unreach_admin, "\t\t%ju administratively prohibited\n");
	p_5(icp6s_odst_unreach_beyondscope, "\t\t%ju beyond scope\n");
	p_5(icp6s_odst_unreach_addr, "\t\t%ju address unreachable\n");
	p_5(icp6s_odst_unreach_noport, "\t\t%ju port unreachable\n");
	p_5(icp6s_opacket_too_big, "\t\t%ju packet too big\n");
	p_5(icp6s_otime_exceed_transit, "\t\t%ju time exceed transit\n");
	p_5(icp6s_otime_exceed_reassembly, "\t\t%ju time exceed reassembly\n");
	p_5(icp6s_oparamprob_header, "\t\t%ju erroneous header field\n");
	p_5(icp6s_oparamprob_nextheader, "\t\t%ju unrecognized next header\n");
	p_5(icp6s_oparamprob_option, "\t\t%ju unrecognized option\n");
	p_5(icp6s_oredirect, "\t\t%ju redirect\n");
	p_5(icp6s_ounknown, "\t\t%ju unknown\n");

	p(icp6s_reflect, "\t%ju message response%s generated\n");
	p(icp6s_nd_toomanyopt, "\t%ju message%s with too many ND options\n");
	p(icp6s_nd_badopt, "\t%ju message%s with bad ND options\n");
	p(icp6s_badns, "\t%ju bad neighbor solicitation message%s\n");
	p(icp6s_badna, "\t%ju bad neighbor advertisement message%s\n");
	p(icp6s_badrs, "\t%ju bad router solicitation message%s\n");
	p(icp6s_badra, "\t%ju bad router advertisement message%s\n");
	p(icp6s_badredirect, "\t%ju bad redirect message%s\n");
	p(icp6s_pmtuchg, "\t%ju path MTU change%s\n");
#undef p
#undef p_5
}
Beispiel #3
0
/*
 * Dump IP6 statistics structure.
 */
void
ip6_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
{
	struct ip6stat ip6stat, zerostat;
	int first, i;
	size_t len;

	len = sizeof ip6stat;
	if (live) {
		memset(&ip6stat, 0, len);
		if (zflag)
			memset(&zerostat, 0, len);
		if (sysctlbyname("net.inet6.ip6.stats", &ip6stat, &len,
		    zflag ? &zerostat : NULL, zflag ? len : 0) < 0) {
			if (errno != ENOENT)
				xo_warn("sysctl: net.inet6.ip6.stats");
			return;
		}
	} else
		kread_counters(off, &ip6stat, len);
	xo_open_container(name);
	xo_emit("{T:/%s}:\n", name);

#define	p(f, m) if (ip6stat.f || sflag <= 1) \
	xo_emit(m, (uintmax_t)ip6stat.f, plural(ip6stat.f))
#define	p1a(f, m) if (ip6stat.f || sflag <= 1) \
	xo_emit(m, (uintmax_t)ip6stat.f)

	p(ip6s_total, "\t{:received-packets/%ju} "
	    "{N:/total packet%s received}\n");
	p1a(ip6s_toosmall, "\t{:dropped-below-minimum-size/%ju} "
	    "{N:/with size smaller than minimum}\n");
	p1a(ip6s_tooshort, "\t{:dropped-short-packets/%ju} "
	    "{N:/with data size < data length}\n");
	p1a(ip6s_badoptions, "\t{:dropped-bad-options/%ju} "
	    "{N:/with bad options}\n");
	p1a(ip6s_badvers, "\t{:dropped-bad-version/%ju} "
	    "{N:/with incorrect version number}\n");
	p(ip6s_fragments, "\t{:received-fragments/%ju} "
	    "{N:/fragment%s received}\n");
	p(ip6s_fragdropped, "\t{:dropped-fragment/%ju} "
	    "{N:/fragment%s dropped (dup or out of space)}\n");
	p(ip6s_fragtimeout, "\t{:dropped-fragment-after-timeout/%ju} "
	    "{N:/fragment%s dropped after timeout}\n");
	p(ip6s_fragoverflow, "\t{:dropped-fragments-overflow/%ju} "
	    "{N:/fragment%s that exceeded limit}\n");
	p(ip6s_reassembled, "\t{:reassembled-packets/%ju} "
	    "{N:/packet%s reassembled ok}\n");
	p(ip6s_delivered, "\t{:received-local-packets/%ju} "
	    "{N:/packet%s for this host}\n");
	p(ip6s_forward, "\t{:forwarded-packets/%ju} "
	    "{N:/packet%s forwarded}\n");
	p(ip6s_cantforward, "\t{:packets-not-forwardable/%ju} "
	    "{N:/packet%s not forwardable}\n");
	p(ip6s_redirectsent, "\t{:sent-redirects/%ju} "
	    "{N:/redirect%s sent}\n");
	p(ip6s_localout, "\t{:sent-packets/%ju} "
	    "{N:/packet%s sent from this host}\n");
	p(ip6s_rawout, "\t{:send-packets-fabricated-header/%ju} "
	    "{N:/packet%s sent with fabricated ip header}\n");
	p(ip6s_odropped, "\t{:discard-no-mbufs/%ju} "
	    "{N:/output packet%s dropped due to no bufs, etc.}\n");
	p(ip6s_noroute, "\t{:discard-no-route/%ju} "
	    "{N:/output packet%s discarded due to no route}\n");
	p(ip6s_fragmented, "\t{:sent-fragments/%ju} "
	    "{N:/output datagram%s fragmented}\n");
	p(ip6s_ofragments, "\t{:fragments-created/%ju} "
	    "{N:/fragment%s created}\n");
	p(ip6s_cantfrag, "\t{:discard-cannot-fragment/%ju} "
	    "{N:/datagram%s that can't be fragmented}\n");
	p(ip6s_badscope, "\t{:discard-scope-violations/%ju} "
	    "{N:/packet%s that violated scope rules}\n");
	p(ip6s_notmember, "\t{:multicast-no-join-packets/%ju} "
	    "{N:/multicast packet%s which we don't join}\n");
	for (first = 1, i = 0; i < IP6S_HDRCNT; i++)
		if (ip6stat.ip6s_nxthist[i] != 0) {
			if (first) {
				xo_emit("\t{T:Input histogram}:\n");
				xo_open_list("input-histogram");
				first = 0;
			}
			xo_open_instance("input-histogram");
			xo_emit("\t\t{k:name/%s}: {:count/%ju}\n", ip6nh[i],
			    (uintmax_t)ip6stat.ip6s_nxthist[i]);
			xo_close_instance("input-histogram");
		}
	if (!first)
		xo_close_list("input-histogram");

	xo_open_container("mbuf-statistics");
	xo_emit("\t{T:Mbuf statistics}:\n");
	xo_emit("\t\t{:one-mbuf/%ju} {N:/one mbuf}\n",
	    (uintmax_t)ip6stat.ip6s_m1);
	for (first = 1, i = 0; i < IP6S_M2MMAX; i++) {
		char ifbuf[IFNAMSIZ];
		if (ip6stat.ip6s_m2m[i] != 0) {
			if (first) {
				xo_emit("\t\t{N:two or more mbuf}:\n");
				xo_open_list("mbuf-data");
				first = 0;
			}
			xo_open_instance("mbuf-data");
			xo_emit("\t\t\t{k:name/%s}= {:count/%ju}\n",
			    if_indextoname(i, ifbuf),
			    (uintmax_t)ip6stat.ip6s_m2m[i]);
			xo_close_instance("mbuf-data");
		}
	}
	if (!first)
		xo_close_list("mbuf-data");
	xo_emit("\t\t{:one-extra-mbuf/%ju} {N:one ext mbuf}\n",
	    (uintmax_t)ip6stat.ip6s_mext1);
	xo_emit("\t\t{:two-or-more-extra-mbufs/%ju} "
	    "{N:/two or more ext mbuf}\n", (uintmax_t)ip6stat.ip6s_mext2m);
	xo_close_container("mbuf-statistics");

	p(ip6s_exthdrtoolong, "\t{:dropped-header-too-long/%ju} "
	    "{N:/packet%s whose headers are not contiguous}\n");
	p(ip6s_nogif, "\t{:discard-tunnel-no-gif/%ju} "
	    "{N:/tunneling packet%s that can't find gif}\n");
	p(ip6s_toomanyhdr, "\t{:dropped-too-many-headers/%ju} "
	    "{N:/packet%s discarded because of too many headers}\n");

	/* for debugging source address selection */
#define	PRINT_SCOPESTAT(s,i) do {\
		switch(i) { /* XXX hardcoding in each case */\
		case 1:\
			p(s, "\t\t{ke:name/interface-locals}{:count/%ju} " \
			  "{N:/interface-local%s}\n");	\
			break;\
		case 2:\
			p(s,"\t\t{ke:name/link-locals}{:count/%ju} " \
			"{N:/link-local%s}\n"); \
			break;\
		case 5:\
			p(s,"\t\t{ke:name/site-locals}{:count/%ju} " \
			  "{N:/site-local%s}\n");\
			break;\
		case 14:\
			p(s,"\t\t{ke:name/globals}{:count/%ju} " \
			  "{N:/global%s}\n");\
			break;\
		default:\
			xo_emit("\t\t{qke:name/%x}{:count/%ju} " \
				"addresses scope=%x\n",\
				i, (uintmax_t)ip6stat.s, i);	   \
		}\
	} while (0);

	xo_open_container("source-address-selection");
	p(ip6s_sources_none, "\t{:address-selection-failures/%ju} "
	    "{N:/failure%s of source address selection}\n");

	for (first = 1, i = 0; i < IP6S_SCOPECNT; i++) {
		if (ip6stat.ip6s_sources_sameif[i]) {
			if (first) {
				xo_open_list("outgoing-interface");
				xo_emit("\tsource addresses on an outgoing "
				    "I/F\n");
				first = 0;
			}
			xo_open_instance("outgoing-interface");
			PRINT_SCOPESTAT(ip6s_sources_sameif[i], i);
			xo_close_instance("outgoing-interface");
		}
	}
	if (!first)
		xo_close_list("outgoing-interface");

	for (first = 1, i = 0; i < IP6S_SCOPECNT; i++) {
		if (ip6stat.ip6s_sources_otherif[i]) {
			if (first) {
				xo_open_list("non-outgoing-interface");
				xo_emit("\tsource addresses on a non-outgoing "
				    "I/F\n");
				first = 0;
			}
			xo_open_instance("non-outgoing-interface");
			PRINT_SCOPESTAT(ip6s_sources_otherif[i], i);
			xo_close_instance("non-outgoing-interface");
		}
	}
	if (!first)
		xo_close_list("non-outgoing-interface");

	for (first = 1, i = 0; i < IP6S_SCOPECNT; i++) {
		if (ip6stat.ip6s_sources_samescope[i]) {
			if (first) {
				xo_open_list("same-source");
				xo_emit("\tsource addresses of same scope\n");
				first = 0;
			}
			xo_open_instance("same-source");
			PRINT_SCOPESTAT(ip6s_sources_samescope[i], i);
			xo_close_instance("same-source");
		}
	}
	if (!first)
		xo_close_list("same-source");

	for (first = 1, i = 0; i < IP6S_SCOPECNT; i++) {
		if (ip6stat.ip6s_sources_otherscope[i]) {
			if (first) {
				xo_open_list("different-scope");
				xo_emit("\tsource addresses of a different "
				    "scope\n");
				first = 0;
			}
			xo_open_instance("different-scope");
			PRINT_SCOPESTAT(ip6s_sources_otherscope[i], i);
			xo_close_instance("different-scope");
		}
	}
	if (!first)
		xo_close_list("different-scope");

	for (first = 1, i = 0; i < IP6S_SCOPECNT; i++) {
		if (ip6stat.ip6s_sources_deprecated[i]) {
			if (first) {
				xo_open_list("deprecated-source");
				xo_emit("\tdeprecated source addresses\n");
				first = 0;
			}
			xo_open_instance("deprecated-source");
			PRINT_SCOPESTAT(ip6s_sources_deprecated[i], i);
			xo_close_instance("deprecated-source");
		}
	}
	if (!first)
		xo_close_list("deprecated-source");

	for (first = 1, i = 0; i < IP6S_RULESMAX; i++) {
		if (ip6stat.ip6s_sources_rule[i]) {
			if (first) {
				xo_open_list("rules-applied");
				xo_emit("\t{T:Source addresses selection "
				    "rule applied}:\n");
				first = 0;
			}
			xo_open_instance("rules-applied");
			xo_emit("\t\t{ke:name/%s}{:count/%ju} {d:name/%s}\n",
			    srcrule_str[i],
			    (uintmax_t)ip6stat.ip6s_sources_rule[i],
			    srcrule_str[i]);
			xo_close_instance("rules-applied");
		}
	}
	if (!first)
		xo_close_list("rules-applied");

	xo_close_container("source-address-selection");

#undef p
#undef p1a
	xo_close_container(name);
}
Beispiel #4
0
/*
 * Dump ICMP6 statistics.
 */
void
icmp6_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
{
	struct icmp6stat icmp6stat, zerostat;
	int i, first;
	size_t len;

	len = sizeof icmp6stat;
	if (live) {
		memset(&icmp6stat, 0, len);
		if (zflag)
			memset(&zerostat, 0, len);
		if (sysctlbyname("net.inet6.icmp6.stats", &icmp6stat, &len,
		    zflag ? &zerostat : NULL, zflag ? len : 0) < 0) {
			if (errno != ENOENT)
				xo_warn("sysctl: net.inet6.icmp6.stats");
			return;
		}
	} else
		kread_counters(off, &icmp6stat, len);

	xo_emit("{T:/%s}:\n", name);
	xo_open_container(name);

#define	p(f, m) if (icmp6stat.f || sflag <= 1) \
	xo_emit(m, (uintmax_t)icmp6stat.f, plural(icmp6stat.f))
#define	p_5(f, m) if (icmp6stat.f || sflag <= 1) \
	xo_emit(m, (uintmax_t)icmp6stat.f)

	p(icp6s_error, "\t{:icmp6-calls/%ju} "
	    "{N:/call%s to icmp6_error}\n");
	p(icp6s_canterror, "\t{:errors-not-generated-from-message/%ju} "
	    "{N:/error%s not generated in response to an icmp6 message}\n");
	p(icp6s_toofreq, "\t{:errors-discarded-by-rate-limitation/%ju} "
	    "{N:/error%s not generated because of rate limitation}\n");
#define	NELEM (int)(sizeof(icmp6stat.icp6s_outhist)/sizeof(icmp6stat.icp6s_outhist[0]))
	for (first = 1, i = 0; i < NELEM; i++)
		if (icmp6stat.icp6s_outhist[i] != 0) {
			if (first) {
				xo_open_list("output-histogram");
				xo_emit("\t{T:Output histogram}:\n");
				first = 0;
			}
			xo_open_instance("output-histogram");
			xo_emit("\t\t{k:name/%s}: {:count/%ju}\n",
			    icmp6names[i],
			    (uintmax_t)icmp6stat.icp6s_outhist[i]);
			xo_close_instance("output-histogram");
		}
	if (!first)
		xo_close_list("output-histogram");
#undef NELEM

	p(icp6s_badcode, "\t{:dropped-bad-code/%ju} "
	    "{N:/message%s with bad code fields}\n");
	p(icp6s_tooshort, "\t{:dropped-too-short/%ju} "
	    "{N:/message%s < minimum length}\n");
	p(icp6s_checksum, "\t{:dropped-bad-checksum/%ju} "
	    "{N:/bad checksum%s}\n");
	p(icp6s_badlen, "\t{:dropped-bad-length/%ju} "
	    "{N:/message%s with bad length}\n");
#define	NELEM (int)(sizeof(icmp6stat.icp6s_inhist)/sizeof(icmp6stat.icp6s_inhist[0]))
	for (first = 1, i = 0; i < NELEM; i++)
		if (icmp6stat.icp6s_inhist[i] != 0) {
			if (first) {
				xo_open_list("input-histogram");
				xo_emit("\t{T:Input histogram}:\n");
				first = 0;
			}
			xo_open_instance("input-histogram");
			xo_emit("\t\t{k:name/%s}: {:count/%ju}\n",
			    icmp6names[i],
			    (uintmax_t)icmp6stat.icp6s_inhist[i]);
			xo_close_instance("input-histogram");
		}
	if (!first)
		xo_close_list("input-histogram");
#undef NELEM
	xo_emit("\t{T:Histogram of error messages to be generated}:\n");
	xo_open_container("errors");
	p_5(icp6s_odst_unreach_noroute, "\t\t{:no-route/%ju} "
	    "{N:/no route}\n");
	p_5(icp6s_odst_unreach_admin, "\t\t{:admin-prohibited/%ju} "
	    "{N:/administratively prohibited}\n");
	p_5(icp6s_odst_unreach_beyondscope, "\t\t{:beyond-scope/%ju} "
	    "{N:/beyond scope}\n");
	p_5(icp6s_odst_unreach_addr, "\t\t{:address-unreachable/%ju} "
	    "{N:/address unreachable}\n");
	p_5(icp6s_odst_unreach_noport, "\t\t{:port-unreachable/%ju} "
	    "{N:/port unreachable}\n");
	p_5(icp6s_opacket_too_big, "\t\t{:packet-too-big/%ju} "
	    "{N:/packet too big}\n");
	p_5(icp6s_otime_exceed_transit, "\t\t{:time-exceed-transmit/%ju} "
	    "{N:/time exceed transit}\n");
	p_5(icp6s_otime_exceed_reassembly, "\t\t{:time-exceed-reassembly/%ju} "
	    "{N:/time exceed reassembly}\n");
	p_5(icp6s_oparamprob_header, "\t\t{:bad-header/%ju} "
	    "{N:/erroneous header field}\n");
	p_5(icp6s_oparamprob_nextheader, "\t\t{:bad-next-header/%ju} "
	    "{N:/unrecognized next header}\n");
	p_5(icp6s_oparamprob_option, "\t\t{:bad-option/%ju} "
	    "{N:/unrecognized option}\n");
	p_5(icp6s_oredirect, "\t\t{:redirects/%ju} "
	    "{N:/redirect}\n");
	p_5(icp6s_ounknown, "\t\t{:unknown/%ju} {N:unknown}\n");

	p(icp6s_reflect, "\t{:reflect/%ju} "
	    "{N:/message response%s generated}\n");
	p(icp6s_nd_toomanyopt, "\t{:too-many-nd-options/%ju} "
	    "{N:/message%s with too many ND options}\n");
	p(icp6s_nd_badopt, "\t{:bad-nd-options/%ju} "
	    "{N:/message%s with bad ND options}\n");
	p(icp6s_badns, "\t{:bad-neighbor-solicitation/%ju} "
	    "{N:/bad neighbor solicitation message%s}\n");
	p(icp6s_badna, "\t{:bad-neighbor-advertisement/%ju} "
	    "{N:/bad neighbor advertisement message%s}\n");
	p(icp6s_badrs, "\t{:bad-router-solicitation/%ju} "
	    "{N:/bad router solicitation message%s}\n");
	p(icp6s_badra, "\t{:bad-router-advertisement/%ju} "
	    "{N:/bad router advertisement message%s}\n");
	p(icp6s_badredirect, "\t{:bad-redirect/%ju} "
	    "{N:/bad redirect message%s}\n");
	xo_close_container("errors");
	p(icp6s_pmtuchg, "\t{:path-mtu-changes/%ju} {N:/path MTU change%s}\n");
#undef p
#undef p_5
	xo_close_container(name);
}
Beispiel #5
0
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
}