svn commit: r190951 - in head/sys: contrib/pf/net net netinet

Robert Watson rwatson at FreeBSD.org
Sat Apr 11 23:35:22 UTC 2009


Author: rwatson
Date: Sat Apr 11 23:35:20 2009
New Revision: 190951
URL: http://svn.freebsd.org/changeset/base/190951

Log:
  Update stats in struct ipstat using four new macros, IPSTAT_ADD(),
  IPSTAT_INC(), IPSTAT_SUB(), and IPSTAT_DEC(), rather than directly
  manipulating the fields 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.
  
  MFC after:	3 days

Modified:
  head/sys/contrib/pf/net/pf.c
  head/sys/net/if_bridge.c
  head/sys/netinet/igmp.c
  head/sys/netinet/in_gif.c
  head/sys/netinet/ip_divert.c
  head/sys/netinet/ip_fastfwd.c
  head/sys/netinet/ip_input.c
  head/sys/netinet/ip_ipsec.c
  head/sys/netinet/ip_options.c
  head/sys/netinet/ip_output.c
  head/sys/netinet/ip_var.h
  head/sys/netinet/raw_ip.c
  head/sys/netinet/udp_usrreq.c

Modified: head/sys/contrib/pf/net/pf.c
==============================================================================
--- head/sys/contrib/pf/net/pf.c	Sat Apr 11 22:39:38 2009	(r190950)
+++ head/sys/contrib/pf/net/pf.c	Sat Apr 11 23:35:20 2009	(r190951)
@@ -6153,7 +6153,7 @@ pf_route(struct mbuf **m, struct pf_rule
 	if (r->rt == PF_FASTROUTE) {
 		in_rtalloc(ro, 0);
 		if (ro->ro_rt == 0) {
-			V_ipstat.ips_noroute++;
+			IPSTAT_INC(ips_noroute);
 			goto bad;
 		}
 
@@ -6284,7 +6284,7 @@ pf_route(struct mbuf **m, struct pf_rule
 		if ((ifp->if_capabilities & IFCAP_CSUM_IPv4) &&
 		    ifp->if_bridge == NULL) {
 			m0->m_pkthdr.csum_flags |= M_IPV4_CSUM_OUT;
-			V_ipstat.ips_outhwcsum++;
+			IPSTAT_INC(ips_outhwcsum);
 		} else {
 			ip->ip_sum = 0;
 			ip->ip_sum = in_cksum(m0, ip->ip_hl << 2);
@@ -6303,7 +6303,7 @@ pf_route(struct mbuf **m, struct pf_rule
 	 * Must be able to put at least 8 bytes per fragment.
 	 */
 	if (ip->ip_off & htons(IP_DF)) {
-		V_ipstat.ips_cantfrag++;
+		IPSTAT_INC(ips_cantfrag);
 		if (r->rt != PF_DUPTO) {
 #ifdef __FreeBSD__
 			/* icmp_error() expects host byte ordering */
@@ -6360,7 +6360,7 @@ pf_route(struct mbuf **m, struct pf_rule
 	}
 
 	if (error == 0)
-		V_ipstat.ips_fragmented++;
+		IPSTAT_INC(ips_fragmented);
 
 done:
 	if (r->rt != PF_DUPTO)

Modified: head/sys/net/if_bridge.c
==============================================================================
--- head/sys/net/if_bridge.c	Sat Apr 11 22:39:38 2009	(r190950)
+++ head/sys/net/if_bridge.c	Sat Apr 11 23:35:20 2009	(r190951)
@@ -3243,12 +3243,12 @@ bridge_ip_checkbasic(struct mbuf **mp)
 		if ((m = m_copyup(m, sizeof(struct ip),
 			(max_linkhdr + 3) & ~3)) == NULL) {
 			/* XXXJRT new stat, please */
-			V_ipstat.ips_toosmall++;
+			IPSTAT_INC(ips_toosmall);
 			goto bad;
 		}
 	} else if (__predict_false(m->m_len < sizeof (struct ip))) {
 		if ((m = m_pullup(m, sizeof (struct ip))) == NULL) {
-			V_ipstat.ips_toosmall++;
+			IPSTAT_INC(ips_toosmall);
 			goto bad;
 		}
 	}
@@ -3256,17 +3256,17 @@ bridge_ip_checkbasic(struct mbuf **mp)
 	if (ip == NULL) goto bad;
 
 	if (ip->ip_v != IPVERSION) {
-		V_ipstat.ips_badvers++;
+		IPSTAT_INC(ips_badvers);
 		goto bad;
 	}
 	hlen = ip->ip_hl << 2;
 	if (hlen < sizeof(struct ip)) { /* minimum header length */
-		V_ipstat.ips_badhlen++;
+		IPSTAT_INC(ips_badhlen);
 		goto bad;
 	}
 	if (hlen > m->m_len) {
 		if ((m = m_pullup(m, hlen)) == 0) {
-			V_ipstat.ips_badhlen++;
+			IPSTAT_INC(ips_badhlen);
 			goto bad;
 		}
 		ip = mtod(m, struct ip *);
@@ -3283,7 +3283,7 @@ bridge_ip_checkbasic(struct mbuf **mp)
 		}
 	}
 	if (sum) {
-		V_ipstat.ips_badsum++;
+		IPSTAT_INC(ips_badsum);
 		goto bad;
 	}
 
@@ -3294,7 +3294,7 @@ bridge_ip_checkbasic(struct mbuf **mp)
 	 * Check for additional length bogosity
 	 */
 	if (len < hlen) {
-		V_ipstat.ips_badlen++;
+		IPSTAT_INC(ips_badlen);
 		goto bad;
 	}
 
@@ -3304,7 +3304,7 @@ bridge_ip_checkbasic(struct mbuf **mp)
 	 * Drop packet if shorter than we expect.
 	 */
 	if (m->m_pkthdr.len < len) {
-		V_ipstat.ips_tooshort++;
+		IPSTAT_INC(ips_tooshort);
 		goto bad;
 	}
 
@@ -3419,7 +3419,7 @@ bridge_fragment(struct ifnet *ifp, struc
 	}
 
 	if (error == 0)
-		V_ipstat.ips_fragmented++;
+		IPSTAT_INC(ips_fragmented);
 
 	return (error);
 

Modified: head/sys/netinet/igmp.c
==============================================================================
--- head/sys/netinet/igmp.c	Sat Apr 11 22:39:38 2009	(r190950)
+++ head/sys/netinet/igmp.c	Sat Apr 11 23:35:20 2009	(r190951)
@@ -3413,7 +3413,7 @@ igmp_intr(struct mbuf *m)
 		CTR3(KTR_IGMPV3, "%s: dropped %p as ifindex %u went away.",
 		    __func__, m, ifindex);
 		m_freem(m);
-		V_ipstat.ips_noroute++;
+		IPSTAT_INC(ips_noroute);
 		goto out;
 	}
 
@@ -3441,7 +3441,7 @@ igmp_intr(struct mbuf *m)
 		if (m0 == NULL) {
 			CTR2(KTR_IGMPV3, "%s: dropped %p", __func__, m);
 			m_freem(m);
-			V_ipstat.ips_odropped++;
+			IPSTAT_INC(ips_odropped);
 			goto out;
 		}
 	}

Modified: head/sys/netinet/in_gif.c
==============================================================================
--- head/sys/netinet/in_gif.c	Sat Apr 11 22:39:38 2009	(r190950)
+++ head/sys/netinet/in_gif.c	Sat Apr 11 23:35:20 2009	(r190951)
@@ -273,14 +273,14 @@ in_gif_input(struct mbuf *m, int off)
 	sc = (struct gif_softc *)encap_getarg(m);
 	if (sc == NULL) {
 		m_freem(m);
-		V_ipstat.ips_nogif++;
+		IPSTAT_INC(ips_nogif);
 		return;
 	}
 
 	gifp = GIF2IFP(sc);
 	if (gifp == NULL || (gifp->if_flags & IFF_UP) == 0) {
 		m_freem(m);
-		V_ipstat.ips_nogif++;
+		IPSTAT_INC(ips_nogif);
 		return;
 	}
 
@@ -340,7 +340,7 @@ in_gif_input(struct mbuf *m, int off)
  		break;	
 
 	default:
-		V_ipstat.ips_nogif++;
+		IPSTAT_INC(ips_nogif);
 		m_freem(m);
 		return;
 	}

Modified: head/sys/netinet/ip_divert.c
==============================================================================
--- head/sys/netinet/ip_divert.c	Sat Apr 11 22:39:38 2009	(r190950)
+++ head/sys/netinet/ip_divert.c	Sat Apr 11 23:35:20 2009	(r190951)
@@ -186,7 +186,7 @@ div_input(struct mbuf *m, int off)
 {
 	INIT_VNET_INET(curvnet);
 
-	V_ipstat.ips_noproto++;
+	IPSTAT_INC(ips_noproto);
 	m_freem(m);
 }
 
@@ -307,8 +307,8 @@ divert_packet(struct mbuf *m, int incomi
 	INP_INFO_RUNLOCK(&V_divcbinfo);
 	if (sa == NULL) {
 		m_freem(m);
-		V_ipstat.ips_noproto++;
-		V_ipstat.ips_delivered--;
+		IPSTAT_INC(ips_noproto);
+		IPSTAT_DEC(ips_delivered);
         }
 }
 
@@ -394,7 +394,7 @@ div_output(struct socket *so, struct mbu
 			ip->ip_off = ntohs(ip->ip_off);
 
 			/* Send packet to output processing */
-			V_ipstat.ips_rawout++;			/* XXX */
+			IPSTAT_INC(ips_rawout);			/* XXX */
 
 #ifdef MAC
 			mac_inpcb_create_mbuf(inp, m);
@@ -570,7 +570,7 @@ div_send(struct socket *so, int flags, s
 	/* Packet must have a header (but that's about it) */
 	if (m->m_len < sizeof (struct ip) &&
 	    (m = m_pullup(m, sizeof (struct ip))) == 0) {
-		V_ipstat.ips_toosmall++;
+		IPSTAT_INC(ips_toosmall);
 		m_freem(m);
 		return EINVAL;
 	}

Modified: head/sys/netinet/ip_fastfwd.c
==============================================================================
--- head/sys/netinet/ip_fastfwd.c	Sat Apr 11 22:39:38 2009	(r190950)
+++ head/sys/netinet/ip_fastfwd.c	Sat Apr 11 23:35:20 2009	(r190951)
@@ -140,8 +140,8 @@ ip_findroute(struct route *ro, struct in
 		if (rt->rt_flags & RTF_GATEWAY)
 			dst = (struct sockaddr_in *)rt->rt_gateway;
 	} else {
-		V_ipstat.ips_noroute++;
-		V_ipstat.ips_cantforward++;
+		IPSTAT_INC(ips_noroute);
+		IPSTAT_INC(ips_cantforward);
 		if (rt)
 			RTFREE(rt);
 		icmp_error(m, ICMP_UNREACH, ICMP_UNREACH_HOST, 0, 0);
@@ -193,7 +193,7 @@ ip_fastforward(struct mbuf *m)
 	 * Is entire packet big enough?
 	 */
 	if (m->m_pkthdr.len < sizeof(struct ip)) {
-		V_ipstat.ips_tooshort++;
+		IPSTAT_INC(ips_tooshort);
 		goto drop;
 	}
 
@@ -202,7 +202,7 @@ ip_fastforward(struct mbuf *m)
 	 */
 	if (m->m_len < sizeof (struct ip) &&
 	   (m = m_pullup(m, sizeof (struct ip))) == NULL) {
-		V_ipstat.ips_toosmall++;
+		IPSTAT_INC(ips_toosmall);
 		return NULL;	/* mbuf already free'd */
 	}
 
@@ -212,7 +212,7 @@ ip_fastforward(struct mbuf *m)
 	 * Is it IPv4?
 	 */
 	if (ip->ip_v != IPVERSION) {
-		V_ipstat.ips_badvers++;
+		IPSTAT_INC(ips_badvers);
 		goto drop;
 	}
 
@@ -221,12 +221,12 @@ ip_fastforward(struct mbuf *m)
 	 */
 	hlen = ip->ip_hl << 2;
 	if (hlen < sizeof(struct ip)) {	/* minimum header length */
-		V_ipstat.ips_badlen++;
+		IPSTAT_INC(ips_badlen);
 		goto drop;
 	}
 	if (hlen > m->m_len) {
 		if ((m = m_pullup(m, hlen)) == NULL) {
-			V_ipstat.ips_badhlen++;
+			IPSTAT_INC(ips_badhlen);
 			return NULL;	/* mbuf already free'd */
 		}
 		ip = mtod(m, struct ip *);
@@ -244,7 +244,7 @@ ip_fastforward(struct mbuf *m)
 			sum = in_cksum(m, hlen);
 	}
 	if (sum) {
-		V_ipstat.ips_badsum++;
+		IPSTAT_INC(ips_badsum);
 		goto drop;
 	}
 
@@ -259,7 +259,7 @@ ip_fastforward(struct mbuf *m)
 	 * Is IP length longer than packet we have got?
 	 */
 	if (m->m_pkthdr.len < ip_len) {
-		V_ipstat.ips_tooshort++;
+		IPSTAT_INC(ips_tooshort);
 		goto drop;
 	}
 
@@ -279,7 +279,7 @@ ip_fastforward(struct mbuf *m)
 	 */
 	if ((ntohl(ip->ip_dst.s_addr) >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET ||
 	    (ntohl(ip->ip_src.s_addr) >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET) {
-		V_ipstat.ips_badaddr++;
+		IPSTAT_INC(ips_badaddr);
 		goto drop;
 	}
 
@@ -337,7 +337,7 @@ ip_fastforward(struct mbuf *m)
 	if (in_localip(ip->ip_dst))
 		return m;
 
-	V_ipstat.ips_total++;
+	IPSTAT_INC(ips_total);
 
 	/*
 	 * Step 3: incoming packet firewall processing
@@ -519,7 +519,7 @@ passout:
 	 */
 	if ((ifp->if_snd.ifq_len + ip->ip_len / ifp->if_mtu + 1) >=
 	    ifp->if_snd.ifq_maxlen) {
-		V_ipstat.ips_odropped++;
+		IPSTAT_INC(ips_odropped);
 		/* would send source quench here but that is depreciated */
 		goto drop;
 	}
@@ -558,7 +558,7 @@ passout:
 		 * Handle EMSGSIZE with icmp reply needfrag for TCP MTU discovery
 		 */
 		if (ip->ip_off & IP_DF) {
-			V_ipstat.ips_cantfrag++;
+			IPSTAT_INC(ips_cantfrag);
 			icmp_error(m, ICMP_UNREACH, ICMP_UNREACH_NEEDFRAG,
 				0, mtu);
 			goto consumed;
@@ -596,16 +596,16 @@ passout:
 					m_freem(m);
 				}
 			} else
-				V_ipstat.ips_fragmented++;
+				IPSTAT_INC(ips_fragmented);
 		}
 	}
 
 	if (error != 0)
-		V_ipstat.ips_odropped++;
+		IPSTAT_INC(ips_odropped);
 	else {
 		ro.ro_rt->rt_rmx.rmx_pksent++;
-		V_ipstat.ips_forward++;
-		V_ipstat.ips_fastforward++;
+		IPSTAT_INC(ips_forward);
+		IPSTAT_INC(ips_fastforward);
 	}
 consumed:
 	RTFREE(ro.ro_rt);

Modified: head/sys/netinet/ip_input.c
==============================================================================
--- head/sys/netinet/ip_input.c	Sat Apr 11 22:39:38 2009	(r190950)
+++ head/sys/netinet/ip_input.c	Sat Apr 11 23:35:20 2009	(r190951)
@@ -381,31 +381,31 @@ ip_input(struct mbuf *m)
 		goto ours;
 	}
 
-	V_ipstat.ips_total++;
+	IPSTAT_INC(ips_total);
 
 	if (m->m_pkthdr.len < sizeof(struct ip))
 		goto tooshort;
 
 	if (m->m_len < sizeof (struct ip) &&
 	    (m = m_pullup(m, sizeof (struct ip))) == NULL) {
-		V_ipstat.ips_toosmall++;
+		IPSTAT_INC(ips_toosmall);
 		return;
 	}
 	ip = mtod(m, struct ip *);
 
 	if (ip->ip_v != IPVERSION) {
-		V_ipstat.ips_badvers++;
+		IPSTAT_INC(ips_badvers);
 		goto bad;
 	}
 
 	hlen = ip->ip_hl << 2;
 	if (hlen < sizeof(struct ip)) {	/* minimum header length */
-		V_ipstat.ips_badhlen++;
+		IPSTAT_INC(ips_badhlen);
 		goto bad;
 	}
 	if (hlen > m->m_len) {
 		if ((m = m_pullup(m, hlen)) == NULL) {
-			V_ipstat.ips_badhlen++;
+			IPSTAT_INC(ips_badhlen);
 			return;
 		}
 		ip = mtod(m, struct ip *);
@@ -415,7 +415,7 @@ ip_input(struct mbuf *m)
 	if ((ntohl(ip->ip_dst.s_addr) >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET ||
 	    (ntohl(ip->ip_src.s_addr) >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET) {
 		if ((m->m_pkthdr.rcvif->if_flags & IFF_LOOPBACK) == 0) {
-			V_ipstat.ips_badaddr++;
+			IPSTAT_INC(ips_badaddr);
 			goto bad;
 		}
 	}
@@ -430,7 +430,7 @@ ip_input(struct mbuf *m)
 		}
 	}
 	if (sum) {
-		V_ipstat.ips_badsum++;
+		IPSTAT_INC(ips_badsum);
 		goto bad;
 	}
 
@@ -445,7 +445,7 @@ ip_input(struct mbuf *m)
 	 */
 	ip->ip_len = ntohs(ip->ip_len);
 	if (ip->ip_len < hlen) {
-		V_ipstat.ips_badlen++;
+		IPSTAT_INC(ips_badlen);
 		goto bad;
 	}
 	ip->ip_off = ntohs(ip->ip_off);
@@ -458,7 +458,7 @@ ip_input(struct mbuf *m)
 	 */
 	if (m->m_pkthdr.len < ip->ip_len) {
 tooshort:
-		V_ipstat.ips_tooshort++;
+		IPSTAT_INC(ips_tooshort);
 		goto bad;
 	}
 	if (m->m_pkthdr.len > ip->ip_len) {
@@ -609,7 +609,7 @@ passin:
 	}
 	/* RFC 3927 2.7: Do not forward datagrams for 169.254.0.0/16. */
 	if (IN_LINKLOCAL(ntohl(ip->ip_dst.s_addr))) {
-		V_ipstat.ips_cantforward++;
+		IPSTAT_INC(ips_cantforward);
 		m_freem(m);
 		return;
 	}
@@ -625,7 +625,7 @@ passin:
 			 */
 			if (ip_mforward &&
 			    ip_mforward(ip, m->m_pkthdr.rcvif, m, 0) != 0) {
-				V_ipstat.ips_cantforward++;
+				IPSTAT_INC(ips_cantforward);
 				m_freem(m);
 				return;
 			}
@@ -637,7 +637,7 @@ passin:
 			 */
 			if (ip->ip_p == IPPROTO_IGMP)
 				goto ours;
-			V_ipstat.ips_forward++;
+			IPSTAT_INC(ips_forward);
 		}
 		/*
 		 * Assume the packet is for us, to avoid prematurely taking
@@ -667,7 +667,7 @@ passin:
 	 * Not for us; forward if possible and desirable.
 	 */
 	if (V_ipforwarding == 0) {
-		V_ipstat.ips_cantforward++;
+		IPSTAT_INC(ips_cantforward);
 		m_freem(m);
 	} else {
 #ifdef IPSEC
@@ -727,7 +727,7 @@ ours:
 	/*
 	 * Switch out to protocol's input routine.
 	 */
-	V_ipstat.ips_delivered++;
+	IPSTAT_INC(ips_delivered);
 
 	(*inetsw[ip_protox[ip->ip_p]].pr_input)(m, hlen);
 	return;
@@ -825,8 +825,8 @@ ip_reass(struct mbuf *m)
 
 	/* If maxnipq or maxfragsperpacket are 0, never accept fragments. */
 	if (V_maxnipq == 0 || V_maxfragsperpacket == 0) {
-		V_ipstat.ips_fragments++;
-		V_ipstat.ips_fragdropped++;
+		IPSTAT_INC(ips_fragments);
+		IPSTAT_INC(ips_fragdropped);
 		m_freem(m);
 		return (NULL);
 	}
@@ -868,14 +868,14 @@ ip_reass(struct mbuf *m)
 			for (i = 0; i < IPREASS_NHASH; i++) {
 				struct ipq *r = TAILQ_LAST(&V_ipq[i], ipqhead);
 				if (r) {
-					V_ipstat.ips_fragtimeout +=
-					    r->ipq_nfrags;
+					IPSTAT_ADD(ips_fragtimeout,
+					    r->ipq_nfrags);
 					ip_freef(&V_ipq[i], r);
 					break;
 				}
 			}
 		} else {
-			V_ipstat.ips_fragtimeout += q->ipq_nfrags;
+			IPSTAT_ADD(ips_fragtimeout, q->ipq_nfrags);
 			ip_freef(head, q);
 		}
 	}
@@ -892,7 +892,7 @@ found:
 		 * that's a non-zero multiple of 8 bytes.
 		 */
 		if (ip->ip_len == 0 || (ip->ip_len & 0x7) != 0) {
-			V_ipstat.ips_toosmall++; /* XXX */
+			IPSTAT_INC(ips_toosmall); /* XXX */
 			goto dropfrag;
 		}
 		m->m_flags |= M_FRAG;
@@ -905,7 +905,7 @@ found:
 	 * Attempt reassembly; if it succeeds, proceed.
 	 * ip_reass() will return a different mbuf.
 	 */
-	V_ipstat.ips_fragments++;
+	IPSTAT_INC(ips_fragments);
 	m->m_pkthdr.header = ip;
 
 	/* Previous ip_reass() started here. */
@@ -1016,7 +1016,7 @@ found:
 		}
 		nq = q->m_nextpkt;
 		m->m_nextpkt = nq;
-		V_ipstat.ips_fragdropped++;
+		IPSTAT_INC(ips_fragdropped);
 		fp->ipq_nfrags--;
 		m_freem(q);
 	}
@@ -1035,7 +1035,7 @@ found:
 	for (p = NULL, q = fp->ipq_frags; q; p = q, q = q->m_nextpkt) {
 		if (GETIP(q)->ip_off != next) {
 			if (fp->ipq_nfrags > V_maxfragsperpacket) {
-				V_ipstat.ips_fragdropped += fp->ipq_nfrags;
+				IPSTAT_ADD(ips_fragdropped, fp->ipq_nfrags);
 				ip_freef(head, fp);
 			}
 			goto done;
@@ -1045,7 +1045,7 @@ found:
 	/* Make sure the last packet didn't have the IP_MF flag */
 	if (p->m_flags & M_FRAG) {
 		if (fp->ipq_nfrags > V_maxfragsperpacket) {
-			V_ipstat.ips_fragdropped += fp->ipq_nfrags;
+			IPSTAT_ADD(ips_fragdropped, fp->ipq_nfrags);
 			ip_freef(head, fp);
 		}
 		goto done;
@@ -1057,8 +1057,8 @@ found:
 	q = fp->ipq_frags;
 	ip = GETIP(q);
 	if (next + (ip->ip_hl << 2) > IP_MAXPACKET) {
-		V_ipstat.ips_toolong++;
-		V_ipstat.ips_fragdropped += fp->ipq_nfrags;
+		IPSTAT_INC(ips_toolong);
+		IPSTAT_ADD(ips_fragdropped, fp->ipq_nfrags);
 		ip_freef(head, fp);
 		goto done;
 	}
@@ -1107,12 +1107,12 @@ found:
 	/* some debugging cruft by sklower, below, will go away soon */
 	if (m->m_flags & M_PKTHDR)	/* XXX this should be done elsewhere */
 		m_fixhdr(m);
-	V_ipstat.ips_reassembled++;
+	IPSTAT_INC(ips_reassembled);
 	IPQ_UNLOCK();
 	return (m);
 
 dropfrag:
-	V_ipstat.ips_fragdropped++;
+	IPSTAT_INC(ips_fragdropped);
 	if (fp != NULL)
 		fp->ipq_nfrags--;
 	m_freem(m);
@@ -1169,8 +1169,8 @@ ip_slowtimo(void)
 				fpp = fp;
 				fp = TAILQ_NEXT(fp, ipq_list);
 				if(--fpp->ipq_ttl == 0) {
-					V_ipstat.ips_fragtimeout +=
-					    fpp->ipq_nfrags;
+					IPSTAT_ADD(ips_fragtimeout,
+					    fpp->ipq_nfrags);
 					ip_freef(&V_ipq[i], fpp);
 				}
 			}
@@ -1184,8 +1184,8 @@ ip_slowtimo(void)
 			for (i = 0; i < IPREASS_NHASH; i++) {
 				while (V_nipq > V_maxnipq &&
 				    !TAILQ_EMPTY(&V_ipq[i])) {
-					V_ipstat.ips_fragdropped +=
-					    TAILQ_FIRST(&V_ipq[i])->ipq_nfrags;
+					IPSTAT_ADD(ips_fragdropped,
+					    TAILQ_FIRST(&V_ipq[i])->ipq_nfrags);
 					ip_freef(&V_ipq[i],
 					    TAILQ_FIRST(&V_ipq[i]));
 				}
@@ -1213,8 +1213,8 @@ ip_drain(void)
 		INIT_VNET_INET(vnet_iter);
 		for (i = 0; i < IPREASS_NHASH; i++) {
 			while(!TAILQ_EMPTY(&V_ipq[i])) {
-				V_ipstat.ips_fragdropped +=
-				    TAILQ_FIRST(&V_ipq[i])->ipq_nfrags;
+				IPSTAT_ADD(ips_fragdropped,
+				    TAILQ_FIRST(&V_ipq[i])->ipq_nfrags);
 				ip_freef(&V_ipq[i], TAILQ_FIRST(&V_ipq[i]));
 			}
 		}
@@ -1346,7 +1346,7 @@ ip_forward(struct mbuf *m, int srcrt)
 	int error, type = 0, code = 0, mtu = 0;
 
 	if (m->m_flags & (M_BCAST|M_MCAST) || in_canforward(ip->ip_dst) == 0) {
-		V_ipstat.ips_cantforward++;
+		IPSTAT_INC(ips_cantforward);
 		m_freem(m);
 		return;
 	}
@@ -1465,11 +1465,11 @@ ip_forward(struct mbuf *m, int srcrt)
 		RTFREE(ro.ro_rt);
 
 	if (error)
-		V_ipstat.ips_cantforward++;
+		IPSTAT_INC(ips_cantforward);
 	else {
-		V_ipstat.ips_forward++;
+		IPSTAT_INC(ips_forward);
 		if (type)
-			V_ipstat.ips_redirectsent++;
+			IPSTAT_INC(ips_redirectsent);
 		else {
 			if (mcopy)
 				m_freem(mcopy);
@@ -1521,7 +1521,7 @@ ip_forward(struct mbuf *m, int srcrt)
 			else
 				mtu = ip_next_mtu(ip->ip_len, 0);
 		}
-		V_ipstat.ips_cantfrag++;
+		IPSTAT_INC(ips_cantfrag);
 		break;
 
 	case ENOBUFS:

Modified: head/sys/netinet/ip_ipsec.c
==============================================================================
--- head/sys/netinet/ip_ipsec.c	Sat Apr 11 22:39:38 2009	(r190950)
+++ head/sys/netinet/ip_ipsec.c	Sat Apr 11 23:35:20 2009	(r190951)
@@ -129,7 +129,7 @@ ip_ipsec_fwd(struct mbuf *m)
 	KEY_FREESP(&sp);
 	splx(s);
 	if (error) {
-		V_ipstat.ips_cantforward++;
+		IPSTAT_INC(ips_cantforward);
 		return 1;
 	}
 #endif /* IPSEC */

Modified: head/sys/netinet/ip_options.c
==============================================================================
--- head/sys/netinet/ip_options.c	Sat Apr 11 22:39:38 2009	(r190950)
+++ head/sys/netinet/ip_options.c	Sat Apr 11 23:35:20 2009	(r190951)
@@ -218,7 +218,7 @@ nosourcerouting:
 #ifdef IPSTEALTH
 dropit:
 #endif
-					V_ipstat.ips_cantforward++;
+					IPSTAT_INC(ips_cantforward);
 					m_freem(m);
 					return (1);
 				}
@@ -366,7 +366,7 @@ dropit:
 	return (0);
 bad:
 	icmp_error(m, type, code, 0, 0);
-	V_ipstat.ips_badoptions++;
+	IPSTAT_INC(ips_badoptions);
 	return (1);
 }
 

Modified: head/sys/netinet/ip_output.c
==============================================================================
--- head/sys/netinet/ip_output.c	Sat Apr 11 22:39:38 2009	(r190950)
+++ head/sys/netinet/ip_output.c	Sat Apr 11 23:35:20 2009	(r190951)
@@ -182,7 +182,7 @@ ip_output(struct mbuf *m, struct mbuf *o
 		ip->ip_v = IPVERSION;
 		ip->ip_hl = hlen >> 2;
 		ip->ip_id = ip_newid();
-		V_ipstat.ips_localout++;
+		IPSTAT_INC(ips_localout);
 	} else {
 		hlen = ip->ip_hl << 2;
 	}
@@ -221,7 +221,7 @@ again:
 	if (flags & IP_SENDONES) {
 		if ((ia = ifatoia(ifa_ifwithbroadaddr(sintosa(dst)))) == NULL &&
 		    (ia = ifatoia(ifa_ifwithdstaddr(sintosa(dst)))) == NULL) {
-			V_ipstat.ips_noroute++;
+			IPSTAT_INC(ips_noroute);
 			error = ENETUNREACH;
 			goto bad;
 		}
@@ -233,7 +233,7 @@ again:
 	} else if (flags & IP_ROUTETOIF) {
 		if ((ia = ifatoia(ifa_ifwithdstaddr(sintosa(dst)))) == NULL &&
 		    (ia = ifatoia(ifa_ifwithnet(sintosa(dst)))) == NULL) {
-			V_ipstat.ips_noroute++;
+			IPSTAT_INC(ips_noroute);
 			error = ENETUNREACH;
 			goto bad;
 		}
@@ -265,7 +265,7 @@ again:
 			    inp ? inp->inp_inc.inc_fibnum : M_GETFIB(m));
 #endif
 		if (ro->ro_rt == NULL) {
-			V_ipstat.ips_noroute++;
+			IPSTAT_INC(ips_noroute);
 			error = EHOSTUNREACH;
 			goto bad;
 		}
@@ -322,7 +322,7 @@ again:
 		 */
 		if ((imo == NULL) || (imo->imo_multicast_vif == -1)) {
 			if ((ifp->if_flags & IFF_MULTICAST) == 0) {
-				V_ipstat.ips_noroute++;
+				IPSTAT_INC(ips_noroute);
 				error = ENETUNREACH;
 				goto bad;
 			}
@@ -420,7 +420,7 @@ again:
 #endif /* ALTQ */
 	{
 		error = ENOBUFS;
-		V_ipstat.ips_odropped++;
+		IPSTAT_INC(ips_odropped);
 		ifp->if_snd.ifq_drops += (ip->ip_len / ifp->if_mtu + 1);
 		goto bad;
 	}
@@ -538,7 +538,7 @@ passout:
 	if ((ntohl(ip->ip_dst.s_addr) >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET ||
 	    (ntohl(ip->ip_src.s_addr) >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET) {
 		if ((ifp->if_flags & IFF_LOOPBACK) == 0) {
-			V_ipstat.ips_badaddr++;
+			IPSTAT_INC(ips_badaddr);
 			error = EADDRNOTAVAIL;
 			goto bad;
 		}
@@ -602,7 +602,7 @@ passout:
 	/* Balk when DF bit is set or the interface didn't support TSO. */
 	if ((ip->ip_off & IP_DF) || (m->m_pkthdr.csum_flags & CSUM_TSO)) {
 		error = EMSGSIZE;
-		V_ipstat.ips_cantfrag++;
+		IPSTAT_INC(ips_cantfrag);
 		goto bad;
 	}
 
@@ -635,7 +635,7 @@ passout:
 	}
 
 	if (error == 0)
-		V_ipstat.ips_fragmented++;
+		IPSTAT_INC(ips_fragmented);
 
 done:
 	if (ro == &iproute && ro->ro_rt) {
@@ -671,7 +671,7 @@ ip_fragment(struct ip *ip, struct mbuf *
 	int nfrags;
 
 	if (ip->ip_off & IP_DF) {	/* Fragmentation not allowed */
-		V_ipstat.ips_cantfrag++;
+		IPSTAT_INC(ips_cantfrag);
 		return EMSGSIZE;
 	}
 
@@ -752,7 +752,7 @@ smart_frag_failure:
 		MGETHDR(m, M_DONTWAIT, MT_DATA);
 		if (m == NULL) {
 			error = ENOBUFS;
-			V_ipstat.ips_odropped++;
+			IPSTAT_INC(ips_odropped);
 			goto done;
 		}
 		m->m_flags |= (m0->m_flags & M_MCAST) | M_FRAG;
@@ -782,7 +782,7 @@ smart_frag_failure:
 		if (m->m_next == NULL) {	/* copy failed */
 			m_free(m);
 			error = ENOBUFS;	/* ??? */
-			V_ipstat.ips_odropped++;
+			IPSTAT_INC(ips_odropped);
 			goto done;
 		}
 		m->m_pkthdr.len = mhlen + len;
@@ -798,7 +798,7 @@ smart_frag_failure:
 		*mnext = m;
 		mnext = &m->m_nextpkt;
 	}
-	V_ipstat.ips_ofragments += nfrags;
+	IPSTAT_ADD(ips_ofragments, nfrags);
 
 	/* set first marker for fragment chain */
 	m0->m_flags |= M_FIRSTFRAG | M_FRAG;

Modified: head/sys/netinet/ip_var.h
==============================================================================
--- head/sys/netinet/ip_var.h	Sat Apr 11 22:39:38 2009	(r190950)
+++ head/sys/netinet/ip_var.h	Sat Apr 11 23:35:20 2009	(r190951)
@@ -132,6 +132,11 @@ struct	ipstat {
 
 #ifdef _KERNEL
 
+#define	IPSTAT_ADD(name, val)	V_ipstat.name += (val)
+#define	IPSTAT_SUB(name, val)	V_ipstat.name -= (val)
+#define	IPSTAT_INC(name)	IPSTAT_ADD(name, 1)
+#define	IPSTAT_DEC(name)	IPSTAT_SUB(name, 1)
+
 /* flags passed to ip_output as last parameter */
 #define	IP_FORWARDING		0x1		/* most of ip header exists */
 #define	IP_RAWOUTPUT		0x2		/* raw ip header exists */

Modified: head/sys/netinet/raw_ip.c
==============================================================================
--- head/sys/netinet/raw_ip.c	Sat Apr 11 22:39:38 2009	(r190950)
+++ head/sys/netinet/raw_ip.c	Sat Apr 11 23:35:20 2009	(r190951)
@@ -345,7 +345,7 @@ rip_input(struct mbuf *m, int off)
 			    (struct sockaddr *)&group,
 			    (struct sockaddr *)&ripsrc);
 			if (blocked != MCAST_PASS) {
-				V_ipstat.ips_notmember++;
+				IPSTAT_INC(ips_notmember);
 				continue;
 			}
 		}
@@ -364,12 +364,12 @@ rip_input(struct mbuf *m, int off)
 	INP_INFO_RUNLOCK(&V_ripcbinfo);
 	if (last != NULL) {
 		if (rip_append(last, ip, m, &ripsrc) != 0)
-			V_ipstat.ips_delivered--;
+			IPSTAT_INC(ips_delivered);
 		INP_RUNLOCK(last);
 	} else {
 		m_freem(m);
-		V_ipstat.ips_noproto++;
-		V_ipstat.ips_delivered--;
+		IPSTAT_INC(ips_noproto);
+		IPSTAT_DEC(ips_delivered);
 	}
 }
 
@@ -450,7 +450,7 @@ rip_output(struct mbuf *m, struct socket
 		 * XXX prevent ip_output from overwriting header fields.
 		 */
 		flags |= IP_RAWOUTPUT;
-		V_ipstat.ips_rawout++;
+		IPSTAT_INC(ips_rawout);
 	}
 
 	if (inp->inp_flags & INP_ONESBCAST)

Modified: head/sys/netinet/udp_usrreq.c
==============================================================================
--- head/sys/netinet/udp_usrreq.c	Sat Apr 11 22:39:38 2009	(r190950)
+++ head/sys/netinet/udp_usrreq.c	Sat Apr 11 23:35:20 2009	(r190951)
@@ -439,7 +439,7 @@ udp_input(struct mbuf *m, int off)
 					(struct sockaddr *)&udp_in);
 				if (blocked != MCAST_PASS) {
 					if (blocked == MCAST_NOTGMEMBER)
-						V_ipstat.ips_notmember++;
+						IPSTAT_INC(ips_notmember);
 					if (blocked == MCAST_NOTSMEMBER ||
 					    blocked == MCAST_MUTED)
 						V_udpstat.udps_filtermcast++;


More information about the svn-src-head mailing list