Update stats in struct icmpstat and icmp6stat using four new

macros: ICMPSTAT_ADD(), ICMPSTAT_INC(), ICMP6STAT_ADD(), and
ICMP6STAT_INC(), rather than directly manipulating the fields
of these structures across the kernel.  This will make it
easier to change the implementation of these statistics,
such as using per-CPU versions of the data structures.

In on case, icmp6stat members are manipulated indirectly, by
icmp6_errcount(), and this will require further work to fix
for per-CPU stats.

MFC after:	3 days
This commit is contained in:
Robert Watson 2009-04-12 13:22:33 +00:00
parent f68f9f77fe
commit e27b0c8775
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=190964
10 changed files with 73 additions and 63 deletions

View File

@ -6647,14 +6647,14 @@ pf_check_proto_cksum(struct mbuf *m, int off, int len, u_int8_t p, sa_family_t a
case IPPROTO_ICMP:
{
INIT_VNET_INET(curvnet);
V_icmpstat.icps_checksum++;
ICMPSTAT_INC(icps_checksum);
break;
}
#ifdef INET6
case IPPROTO_ICMPV6:
{
INIT_VNET_INET6(curvnet);
V_icmp6stat.icp6s_checksum++;
ICMP6STAT_INC(icp6s_checksum);
break;
}
#endif /* INET6 */
@ -6747,11 +6747,11 @@ pf_check_proto_cksum(struct mbuf *m, int off, int len, u_int8_t p,
UDPSTAT_INC(udps_badsum);
break;
case IPPROTO_ICMP:
V_icmpstat.icps_checksum++;
ICMPSTAT_INC(icps_checksum);
break;
#ifdef INET6
case IPPROTO_ICMPV6:
V_icmp6stat.icp6s_checksum++;
ICMP6STAT_INC(icp6s_checksum);
break;
#endif /* INET6 */
}

View File

@ -596,6 +596,11 @@ struct icmp6stat {
u_quad_t icp6s_badredirect; /* bad redirect message */
};
#ifdef _KERNEL
#define ICMP6STAT_ADD(name, val) V_icmp6stat.name += (val)
#define ICMP6STAT_INC(name) ICMP6STAT_ADD(name, 1)
#endif
/*
* Names for ICMP sysctl objects
*/

View File

@ -57,6 +57,11 @@ struct icmpstat {
u_long icps_noroute; /* no route back */
};
#ifdef _KERNEL
#define ICMPSTAT_ADD(name, val) V_icmpstat.name += (val)
#define ICMPSTAT_INC(name) ICMPSTAT_ADD(name, 1)
#endif
/*
* Names for ICMP sysctl objects
*/

View File

@ -180,7 +180,7 @@ icmp_error(struct mbuf *n, int type, int code, uint32_t dest, int mtu)
printf("icmp_error(%p, %x, %d)\n", oip, type, code);
#endif
if (type != ICMP_REDIRECT)
V_icmpstat.icps_error++;
ICMPSTAT_INC(icps_error);
/*
* Don't send error:
* if the original packet was encrypted.
@ -197,7 +197,7 @@ icmp_error(struct mbuf *n, int type, int code, uint32_t dest, int mtu)
if (oip->ip_p == IPPROTO_ICMP && type != ICMP_REDIRECT &&
n->m_len >= oiphlen + ICMP_MINLEN &&
!ICMP_INFOTYPE(((struct icmp *)((caddr_t)oip + oiphlen))->icmp_type)) {
V_icmpstat.icps_oldicmp++;
ICMPSTAT_INC(icps_oldicmp);
goto freeit;
}
/* Drop if IP header plus 8 bytes is not contignous in first mbuf. */
@ -257,7 +257,7 @@ stdreply: icmpelen = max(8, min(V_icmp_quotelen, oip->ip_len - oiphlen));
*/
M_SETFIB(m, M_GETFIB(n));
icp = mtod(m, struct icmp *);
V_icmpstat.icps_outhist[type]++;
ICMPSTAT_INC(icps_outhist[type]);
icp->icmp_type = type;
if (type == ICMP_REDIRECT)
icp->icmp_gwaddr.s_addr = dest;
@ -340,12 +340,12 @@ icmp_input(struct mbuf *m, int off)
}
#endif
if (icmplen < ICMP_MINLEN) {
V_icmpstat.icps_tooshort++;
ICMPSTAT_INC(icps_tooshort);
goto freeit;
}
i = hlen + min(icmplen, ICMP_ADVLENMIN);
if (m->m_len < i && (m = m_pullup(m, i)) == 0) {
V_icmpstat.icps_tooshort++;
ICMPSTAT_INC(icps_tooshort);
return;
}
ip = mtod(m, struct ip *);
@ -353,7 +353,7 @@ icmp_input(struct mbuf *m, int off)
m->m_data += hlen;
icp = mtod(m, struct icmp *);
if (in_cksum(m, icmplen)) {
V_icmpstat.icps_checksum++;
ICMPSTAT_INC(icps_checksum);
goto freeit;
}
m->m_len += hlen;
@ -395,7 +395,7 @@ icmp_input(struct mbuf *m, int off)
icmpgw.sin_len = sizeof(struct sockaddr_in);
icmpgw.sin_family = AF_INET;
V_icmpstat.icps_inhist[icp->icmp_type]++;
ICMPSTAT_INC(icps_inhist[icp->icmp_type]);
code = icp->icmp_code;
switch (icp->icmp_type) {
@ -460,7 +460,7 @@ icmp_input(struct mbuf *m, int off)
*/
if (icmplen < ICMP_ADVLENMIN || icmplen < ICMP_ADVLEN(icp) ||
icp->icmp_ip.ip_hl < (sizeof(struct ip) >> 2)) {
V_icmpstat.icps_badlen++;
ICMPSTAT_INC(icps_badlen);
goto freeit;
}
icp->icmp_ip.ip_len = ntohs(icp->icmp_ip.ip_len);
@ -483,13 +483,13 @@ icmp_input(struct mbuf *m, int off)
break;
badcode:
V_icmpstat.icps_badcode++;
ICMPSTAT_INC(icps_badcode);
break;
case ICMP_ECHO:
if (!V_icmpbmcastecho
&& (m->m_flags & (M_MCAST | M_BCAST)) != 0) {
V_icmpstat.icps_bmcastecho++;
ICMPSTAT_INC(icps_bmcastecho);
break;
}
icp->icmp_type = ICMP_ECHOREPLY;
@ -501,11 +501,11 @@ icmp_input(struct mbuf *m, int off)
case ICMP_TSTAMP:
if (!V_icmpbmcastecho
&& (m->m_flags & (M_MCAST | M_BCAST)) != 0) {
V_icmpstat.icps_bmcasttstamp++;
ICMPSTAT_INC(icps_bmcasttstamp);
break;
}
if (icmplen < ICMP_TSLEN) {
V_icmpstat.icps_badlen++;
ICMPSTAT_INC(icps_badlen);
break;
}
icp->icmp_type = ICMP_TSTAMPREPLY;
@ -554,8 +554,8 @@ icmp_input(struct mbuf *m, int off)
}
reflect:
ip->ip_len += hlen; /* since ip_input deducts this */
V_icmpstat.icps_reflect++;
V_icmpstat.icps_outhist[icp->icmp_type]++;
ICMPSTAT_INC(icps_reflect);
ICMPSTAT_INC(icps_outhist[icp->icmp_type]);
icmp_reflect(m);
return;
@ -585,7 +585,7 @@ icmp_input(struct mbuf *m, int off)
goto badcode;
if (icmplen < ICMP_ADVLENMIN || icmplen < ICMP_ADVLEN(icp) ||
icp->icmp_ip.ip_hl < (sizeof(struct ip) >> 2)) {
V_icmpstat.icps_badlen++;
ICMPSTAT_INC(icps_badlen);
break;
}
/*
@ -660,7 +660,7 @@ icmp_reflect(struct mbuf *m)
IN_EXPERIMENTAL(ntohl(ip->ip_src.s_addr)) ||
IN_ZERONET(ntohl(ip->ip_src.s_addr)) ) {
m_freem(m); /* Bad return address */
V_icmpstat.icps_badaddr++;
ICMPSTAT_INC(icps_badaddr);
goto done; /* Ip_output() will check for broadcast */
}
@ -729,7 +729,7 @@ icmp_reflect(struct mbuf *m)
ia = ip_rtaddr(ip->ip_dst, M_GETFIB(m));
if (ia == NULL) {
m_freem(m);
V_icmpstat.icps_noroute++;
ICMPSTAT_INC(icps_noroute);
goto done;
}
match:

View File

@ -254,14 +254,14 @@ icmp6_error(struct mbuf *m, int type, int code, int param)
int off;
int nxt;
V_icmp6stat.icp6s_error++;
ICMP6STAT_INC(icp6s_error);
/* count per-type-code statistics */
icmp6_errcount(&V_icmp6stat.icp6s_outerrhist, type, code);
#ifdef M_DECRYPTED /*not openbsd*/
if (m->m_flags & M_DECRYPTED) {
V_icmp6stat.icp6s_canterror++;
ICMP6STAT_INC(icp6s_canterror);
goto freeit;
}
#endif
@ -319,7 +319,7 @@ icmp6_error(struct mbuf *m, int type, int code, int param)
IP6_EXTHDR_GET(icp, struct icmp6_hdr *, m, off,
sizeof(*icp));
if (icp == NULL) {
V_icmp6stat.icp6s_tooshort++;
ICMP6STAT_INC(icp6s_tooshort);
return;
}
#endif
@ -330,7 +330,7 @@ icmp6_error(struct mbuf *m, int type, int code, int param)
* Special case: for redirect (which is
* informational) we must not send icmp6 error.
*/
V_icmp6stat.icp6s_canterror++;
ICMP6STAT_INC(icp6s_canterror);
goto freeit;
} else {
/* ICMPv6 informational - send the error */
@ -343,7 +343,7 @@ icmp6_error(struct mbuf *m, int type, int code, int param)
/* Finally, do rate limitation check. */
if (icmp6_ratelimit(&oip6->ip6_src, type, code)) {
V_icmp6stat.icp6s_toofreq++;
ICMP6STAT_INC(icp6s_toofreq);
goto freeit;
}
@ -384,7 +384,7 @@ icmp6_error(struct mbuf *m, int type, int code, int param)
*/
m->m_pkthdr.rcvif = NULL;
V_icmp6stat.icp6s_outhist[type]++;
ICMP6STAT_INC(icp6s_outhist[type]);
icmp6_reflect(m, sizeof(struct ip6_hdr)); /* header order: IPv6 - ICMPv6 */
return;
@ -424,7 +424,7 @@ icmp6_input(struct mbuf **mp, int *offp, int proto)
ip6 = mtod(m, struct ip6_hdr *);
if (icmp6len < sizeof(struct icmp6_hdr)) {
V_icmp6stat.icp6s_tooshort++;
ICMP6STAT_INC(icp6s_tooshort);
goto freeit;
}
@ -436,7 +436,7 @@ icmp6_input(struct mbuf **mp, int *offp, int proto)
#else
IP6_EXTHDR_GET(icmp6, struct icmp6_hdr *, m, off, sizeof(*icmp6));
if (icmp6 == NULL) {
V_icmp6stat.icp6s_tooshort++;
ICMP6STAT_INC(icp6s_tooshort);
return IPPROTO_DONE;
}
#endif
@ -447,7 +447,7 @@ icmp6_input(struct mbuf **mp, int *offp, int proto)
"ICMP6 checksum error(%d|%x) %s\n",
icmp6->icmp6_type, sum,
ip6_sprintf(ip6bufs, &ip6->ip6_src)));
V_icmp6stat.icp6s_checksum++;
ICMP6STAT_INC(icp6s_checksum);
goto freeit;
}
@ -467,7 +467,7 @@ icmp6_input(struct mbuf **mp, int *offp, int proto)
}
}
V_icmp6stat.icp6s_inhist[icmp6->icmp6_type]++;
ICMP6STAT_INC(icp6s_inhist[icmp6->icmp6_type]);
icmp6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_msg);
if (icmp6->icmp6_type < ICMP6_INFOMSG_MASK)
icmp6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_error);
@ -601,8 +601,8 @@ icmp6_input(struct mbuf **mp, int *offp, int proto)
nicmp6->icmp6_type = ICMP6_ECHO_REPLY;
nicmp6->icmp6_code = 0;
if (n) {
V_icmp6stat.icp6s_reflect++;
V_icmp6stat.icp6s_outhist[ICMP6_ECHO_REPLY]++;
ICMP6STAT_INC(icp6s_reflect);
ICMP6STAT_INC(icp6s_outhist[ICMP6_ECHO_REPLY]);
icmp6_reflect(n, noff);
}
break;
@ -734,8 +734,8 @@ icmp6_input(struct mbuf **mp, int *offp, int proto)
}
#undef hostnamelen
if (n) {
V_icmp6stat.icp6s_reflect++;
V_icmp6stat.icp6s_outhist[ICMP6_WRUREPLY]++;
ICMP6STAT_INC(icp6s_reflect);
ICMP6STAT_INC(icp6s_outhist[ICMP6_WRUREPLY]);
icmp6_reflect(n, noff);
}
break;
@ -856,11 +856,11 @@ icmp6_input(struct mbuf **mp, int *offp, int proto)
break;
badcode:
V_icmp6stat.icp6s_badcode++;
ICMP6STAT_INC(icp6s_badcode);
break;
badlen:
V_icmp6stat.icp6s_badlen++;
ICMP6STAT_INC(icp6s_badlen);
break;
}
@ -885,7 +885,7 @@ icmp6_notify_error(struct mbuf **mp, int off, int icmp6len, int code)
struct sockaddr_in6 icmp6src, icmp6dst;
if (icmp6len < sizeof(struct icmp6_hdr) + sizeof(struct ip6_hdr)) {
V_icmp6stat.icp6s_tooshort++;
ICMP6STAT_INC(icp6s_tooshort);
goto freeit;
}
#ifndef PULLDOWN_TEST
@ -896,7 +896,7 @@ icmp6_notify_error(struct mbuf **mp, int off, int icmp6len, int code)
IP6_EXTHDR_GET(icmp6, struct icmp6_hdr *, m, off,
sizeof(*icmp6) + sizeof(struct ip6_hdr));
if (icmp6 == NULL) {
V_icmp6stat.icp6s_tooshort++;
ICMP6STAT_INC(icp6s_tooshort);
return (-1);
}
#endif
@ -931,7 +931,7 @@ icmp6_notify_error(struct mbuf **mp, int off, int icmp6len, int code)
IP6_EXTHDR_GET(eh, struct ip6_ext *, m,
eoff, sizeof(*eh));
if (eh == NULL) {
V_icmp6stat.icp6s_tooshort++;
ICMP6STAT_INC(icp6s_tooshort);
return (-1);
}
#endif
@ -959,7 +959,7 @@ icmp6_notify_error(struct mbuf **mp, int off, int icmp6len, int code)
IP6_EXTHDR_GET(rth, struct ip6_rthdr *, m,
eoff, sizeof(*rth));
if (rth == NULL) {
V_icmp6stat.icp6s_tooshort++;
ICMP6STAT_INC(icp6s_tooshort);
return (-1);
}
#endif
@ -985,7 +985,7 @@ icmp6_notify_error(struct mbuf **mp, int off, int icmp6len, int code)
struct ip6_rthdr0 *, m,
eoff, rthlen);
if (rth0 == NULL) {
V_icmp6stat.icp6s_tooshort++;
ICMP6STAT_INC(icp6s_tooshort);
return (-1);
}
#endif
@ -1007,7 +1007,7 @@ icmp6_notify_error(struct mbuf **mp, int off, int icmp6len, int code)
IP6_EXTHDR_GET(fh, struct ip6_frag *, m,
eoff, sizeof(*fh));
if (fh == NULL) {
V_icmp6stat.icp6s_tooshort++;
ICMP6STAT_INC(icp6s_tooshort);
return (-1);
}
#endif
@ -1042,7 +1042,7 @@ icmp6_notify_error(struct mbuf **mp, int off, int icmp6len, int code)
IP6_EXTHDR_GET(icmp6, struct icmp6_hdr *, m, off,
sizeof(*icmp6) + sizeof(struct ip6_hdr));
if (icmp6 == NULL) {
V_icmp6stat.icp6s_tooshort++;
ICMP6STAT_INC(icp6s_tooshort);
return (-1);
}
#endif
@ -1156,7 +1156,7 @@ icmp6_mtudisc_update(struct ip6ctlparam *ip6cp, int validated)
if (mtu < tcp_maxmtu6(&inc, NULL)) {
tcp_hc_updatemtu(&inc, mtu);
V_icmp6stat.icp6s_pmtuchg++;
ICMP6STAT_INC(icp6s_pmtuchg);
}
}
@ -2276,7 +2276,7 @@ icmp6_redirect_input(struct mbuf *m, int off)
#else
IP6_EXTHDR_GET(nd_rd, struct nd_redirect *, m, off, icmp6len);
if (nd_rd == NULL) {
V_icmp6stat.icp6s_tooshort++;
ICMP6STAT_INC(icp6s_tooshort);
return;
}
#endif
@ -2439,7 +2439,7 @@ icmp6_redirect_input(struct mbuf *m, int off)
return;
bad:
V_icmp6stat.icp6s_badredirect++;
ICMP6STAT_INC(icp6s_badredirect);
m_freem(m);
}
@ -2715,7 +2715,7 @@ noredhdropt:;
icmp6_ifstat_inc(outif, ifs6_out_msg);
icmp6_ifstat_inc(outif, ifs6_out_redirect);
}
V_icmp6stat.icp6s_outhist[ND_REDIRECT]++;
ICMP6STAT_INC(icp6s_outhist[ND_REDIRECT]);
return;

View File

@ -288,7 +288,7 @@ mld6_input(struct mbuf *m, int off)
#else
IP6_EXTHDR_GET(mldh, struct mld_hdr *, m, off, sizeof(*mldh));
if (mldh == NULL) {
V_icmp6stat.icp6s_tooshort++;
ICMP6STAT_INC(icp6s_tooshort);
return;
}
#endif
@ -517,7 +517,7 @@ mld6_sendpkt(struct in6_multi *in6m, int type, const struct in6_addr *dst)
im6o.im6o_multicast_loop = (ip6_mrouter != NULL);
/* increment output statictics */
V_icmp6stat.icp6s_outhist[type]++;
ICMP6STAT_INC(icp6s_outhist[type]);
ip6_output(mh, &V_ip6_opts, NULL, 0, &im6o, &outif, NULL);
if (outif) {

View File

@ -374,7 +374,7 @@ nd6_options(union nd_opts *ndopts)
* Message validation requires that all included
* options have a length that is greater than zero.
*/
V_icmp6stat.icp6s_nd_badopt++;
ICMP6STAT_INC(icp6s_nd_badopt);
bzero(ndopts, sizeof(*ndopts));
return -1;
}
@ -418,7 +418,7 @@ nd6_options(union nd_opts *ndopts)
skip1:
i++;
if (i > V_nd6_maxndopt) {
V_icmp6stat.icp6s_nd_toomanyopt++;
ICMP6STAT_INC(icp6s_nd_toomanyopt);
nd6log((LOG_INFO, "too many loop in nd opt\n"));
break;
}

View File

@ -128,7 +128,7 @@ nd6_ns_input(struct mbuf *m, int off, int icmp6len)
#else
IP6_EXTHDR_GET(nd_ns, struct nd_neighbor_solicit *, m, off, icmp6len);
if (nd_ns == NULL) {
V_icmp6stat.icp6s_tooshort++;
ICMP6STAT_INC(icp6s_tooshort);
return;
}
#endif
@ -365,7 +365,7 @@ nd6_ns_input(struct mbuf *m, int off, int icmp6len)
ip6_sprintf(ip6bufs, &daddr6)));
nd6log((LOG_ERR, "nd6_ns_input: tgt=%s\n",
ip6_sprintf(ip6bufs, &taddr6)));
V_icmp6stat.icp6s_badns++;
ICMP6STAT_INC(icp6s_badns);
m_freem(m);
}
@ -563,7 +563,7 @@ nd6_ns_output(struct ifnet *ifp, const struct in6_addr *daddr6,
ip6_output(m, NULL, &ro, dad ? IPV6_UNSPECSRC : 0, &im6o, NULL, NULL);
icmp6_ifstat_inc(ifp, ifs6_out_msg);
icmp6_ifstat_inc(ifp, ifs6_out_neighborsolicit);
V_icmp6stat.icp6s_outhist[ND_NEIGHBOR_SOLICIT]++;
ICMP6STAT_INC(icp6s_outhist[ND_NEIGHBOR_SOLICIT]);
if (ro.ro_rt) { /* we don't cache this route. */
RTFREE(ro.ro_rt);
@ -625,7 +625,7 @@ nd6_na_input(struct mbuf *m, int off, int icmp6len)
#else
IP6_EXTHDR_GET(nd_na, struct nd_neighbor_advert *, m, off, icmp6len);
if (nd_na == NULL) {
V_icmp6stat.icp6s_tooshort++;
ICMP6STAT_INC(icp6s_tooshort);
return;
}
#endif
@ -897,7 +897,7 @@ nd6_na_input(struct mbuf *m, int off, int icmp6len)
if (ln != NULL)
LLE_WUNLOCK(ln);
V_icmp6stat.icp6s_badna++;
ICMP6STAT_INC(icp6s_badna);
m_freem(m);
}
@ -1065,7 +1065,7 @@ nd6_na_output(struct ifnet *ifp, const struct in6_addr *daddr6_0,
ip6_output(m, NULL, &ro, 0, &im6o, NULL, NULL);
icmp6_ifstat_inc(ifp, ifs6_out_msg);
icmp6_ifstat_inc(ifp, ifs6_out_neighboradvert);
V_icmp6stat.icp6s_outhist[ND_NEIGHBOR_ADVERT]++;
ICMP6STAT_INC(icp6s_outhist[ND_NEIGHBOR_ADVERT]);
if (ro.ro_rt) { /* we don't cache this route. */
RTFREE(ro.ro_rt);

View File

@ -155,7 +155,7 @@ nd6_rs_input(struct mbuf *m, int off, int icmp6len)
#else
IP6_EXTHDR_GET(nd_rs, struct nd_router_solicit *, m, off, icmp6len);
if (nd_rs == NULL) {
V_icmp6stat.icp6s_tooshort++;
ICMP6STAT_INC(icp6s_tooshort);
return;
}
#endif
@ -190,7 +190,7 @@ nd6_rs_input(struct mbuf *m, int off, int icmp6len)
return;
bad:
V_icmp6stat.icp6s_badrs++;
ICMP6STAT_INC(icp6s_badrs);
m_freem(m);
}
@ -246,7 +246,7 @@ nd6_ra_input(struct mbuf *m, int off, int icmp6len)
#else
IP6_EXTHDR_GET(nd_ra, struct nd_router_advert *, m, off, icmp6len);
if (nd_ra == NULL) {
V_icmp6stat.icp6s_tooshort++;
ICMP6STAT_INC(icp6s_tooshort);
return;
}
#endif
@ -422,7 +422,7 @@ nd6_ra_input(struct mbuf *m, int off, int icmp6len)
return;
bad:
V_icmp6stat.icp6s_badra++;
ICMP6STAT_INC(icp6s_badra);
m_freem(m);
}

View File

@ -477,7 +477,7 @@ rip6_output(m, va_alist)
if (so->so_proto->pr_protocol == IPPROTO_ICMPV6) {
if (oifp)
icmp6_ifoutstat_inc(oifp, type, code);
V_icmp6stat.icp6s_outhist[type]++;
ICMP6STAT_INC(icp6s_outhist[type]);
} else
V_rip6stat.rip6s_opackets++;