Module Name:    src
Committed By:   thorpej
Date:           Wed Jan 29 04:28:27 UTC 2020

Modified Files:
        src/sys/net: if_ppp.c if_pppoe.c if_sl.c if_spppsubr.c if_srt.c
            if_stf.c if_tap.c if_vlan.c ppp_tty.c

Log Message:
Adopt <net/if_stats.h>.


To generate a diff of this commit:
cvs rdiff -u -r1.166 -r1.167 src/sys/net/if_ppp.c
cvs rdiff -u -r1.147 -r1.148 src/sys/net/if_pppoe.c
cvs rdiff -u -r1.131 -r1.132 src/sys/net/if_sl.c
cvs rdiff -u -r1.184 -r1.185 src/sys/net/if_spppsubr.c
cvs rdiff -u -r1.30 -r1.31 src/sys/net/if_srt.c
cvs rdiff -u -r1.106 -r1.107 src/sys/net/if_stf.c
cvs rdiff -u -r1.115 -r1.116 src/sys/net/if_tap.c
cvs rdiff -u -r1.149 -r1.150 src/sys/net/if_vlan.c
cvs rdiff -u -r1.66 -r1.67 src/sys/net/ppp_tty.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/if_ppp.c
diff -u src/sys/net/if_ppp.c:1.166 src/sys/net/if_ppp.c:1.167
--- src/sys/net/if_ppp.c:1.166	Fri Sep 20 08:45:29 2019
+++ src/sys/net/if_ppp.c	Wed Jan 29 04:28:27 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_ppp.c,v 1.166 2019/09/20 08:45:29 maxv Exp $	*/
+/*	$NetBSD: if_ppp.c,v 1.167 2020/01/29 04:28:27 thorpej Exp $	*/
 /*	Id: if_ppp.c,v 1.6 1997/03/04 03:33:00 paulus Exp 	*/
 
 /*
@@ -102,7 +102,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_ppp.c,v 1.166 2019/09/20 08:45:29 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ppp.c,v 1.167 2020/01/29 04:28:27 thorpej Exp $");
 
 #ifdef _KERNEL_OPT
 #include "ppp.h"
@@ -1013,14 +1013,13 @@ pppoutput(struct ifnet *ifp, struct mbuf
 		ifq = (m0->m_flags & M_HIGHPRI) ? &sc->sc_fastq : NULL;
 		if ((error = ifq_enqueue2(&sc->sc_if, ifq, m0)) != 0) {
 			splx(s);
-			sc->sc_if.if_oerrors++;
+			if_statinc(&sc->sc_if, if_oerrors);
 			sc->sc_stats.ppp_oerrors++;
 			return (error);
 		}
 		ppp_restart(sc);
 	}
-	ifp->if_opackets++;
-	ifp->if_obytes += len;
+	if_statadd2(ifp, if_opackets, 1, if_obytes, len);
 
 	splx(s);
 	return (0);
@@ -1065,7 +1064,7 @@ ppp_requeue(struct ppp_softc *sc)
 			m->m_nextpkt = NULL;
 			ifq = (m->m_flags & M_HIGHPRI) ? &sc->sc_fastq : NULL;
 			if ((error = ifq_enqueue2(&sc->sc_if, ifq, m)) != 0) {
-				sc->sc_if.if_oerrors++;
+				if_statinc(&sc->sc_if, if_oerrors);
 				sc->sc_stats.ppp_oerrors++;
 			}
 			break;
@@ -1715,11 +1714,10 @@ ppp_inproc(struct ppp_softc *sc, struct 
 	if (__predict_true(pktq)) {
 		if (__predict_false(!pktq_enqueue(pktq, m, 0))) {
 			splx(s);
-			ifp->if_iqdrops++;
+			if_statinc(ifp, if_iqdrops);
 			goto bad;
 		}
-		ifp->if_ipackets++;
-		ifp->if_ibytes += ilen;
+		if_statadd2(ifp, if_ipackets, 1, if_ibytes, ilen);
 		splx(s);
 		return;
 	}
@@ -1734,13 +1732,12 @@ ppp_inproc(struct ppp_softc *sc, struct 
 		splx(s);
 		if (sc->sc_flags & SC_DEBUG)
 			printf("%s: input queue full\n", ifp->if_xname);
-		ifp->if_iqdrops++;
+		if_statinc(ifp, if_iqdrops);
 		goto bad;
 	}
 	IF_ENQUEUE(inq, m);
 	splx(s);
-	ifp->if_ipackets++;
-	ifp->if_ibytes += ilen;
+	if_statadd2(ifp, if_ipackets, 1, if_ibytes, ilen);
 
 	(*sc->sc_ctlp)(sc);
 
@@ -1748,7 +1745,7 @@ ppp_inproc(struct ppp_softc *sc, struct 
 
 bad:
 	m_freem(m);
-	sc->sc_if.if_ierrors++;
+	if_statinc(&sc->sc_if, if_ierrors);
 	sc->sc_stats.ppp_ierrors++;
 }
 

Index: src/sys/net/if_pppoe.c
diff -u src/sys/net/if_pppoe.c:1.147 src/sys/net/if_pppoe.c:1.148
--- src/sys/net/if_pppoe.c:1.147	Mon Mar 18 11:38:03 2019
+++ src/sys/net/if_pppoe.c	Wed Jan 29 04:28:27 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: if_pppoe.c,v 1.147 2019/03/18 11:38:03 msaitoh Exp $ */
+/* $NetBSD: if_pppoe.c,v 1.148 2020/01/29 04:28:27 thorpej Exp $ */
 
 /*
  * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.147 2019/03/18 11:38:03 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.148 2020/01/29 04:28:27 thorpej Exp $");
 
 #ifdef _KERNEL_OPT
 #include "pppoe.h"
@@ -1125,7 +1125,7 @@ pppoe_data_input(struct mbuf *m)
 	m_set_rcvif(m, &sc->sc_sppp.pp_if);
 
 	/* pass packet up and account for it */
-	sc->sc_sppp.pp_if.if_ipackets++;
+	if_statinc(&sc->sc_sppp.pp_if, if_ipackets);
 	sppp_input(&sc->sc_sppp.pp_if, m);
 	return;
 
@@ -1161,7 +1161,7 @@ pppoe_output(struct pppoe_softc *sc, str
 #endif
 
 	m->m_flags &= ~(M_BCAST|M_MCAST);
-	sc->sc_sppp.pp_if.if_opackets++;
+	if_statinc(&sc->sc_sppp.pp_if, if_opackets);
 	return if_output_lock(sc->sc_eth_if, sc->sc_eth_if, m, &dst, NULL);
 }
 
@@ -1865,7 +1865,7 @@ pppoe_start(struct ifnet *ifp)
 		len = m->m_pkthdr.len;
 		M_PREPEND(m, PPPOE_HEADERLEN, M_DONTWAIT);
 		if (m == NULL) {
-			ifp->if_oerrors++;
+			if_statinc(ifp, if_oerrors);
 			continue;
 		}
 		p = mtod(m, uint8_t *);
@@ -1901,7 +1901,7 @@ pppoe_transmit(struct ifnet *ifp, struct
 	M_PREPEND(m, PPPOE_HEADERLEN, M_DONTWAIT);
 	if (m == NULL) {
 		PPPOE_UNLOCK(sc);
-		ifp->if_oerrors++;
+		if_statinc(ifp, if_oerrors);
 		return ENETDOWN;
 	}
 	p = mtod(m, uint8_t *);

Index: src/sys/net/if_sl.c
diff -u src/sys/net/if_sl.c:1.131 src/sys/net/if_sl.c:1.132
--- src/sys/net/if_sl.c:1.131	Thu Jan 24 09:33:03 2019
+++ src/sys/net/if_sl.c	Wed Jan 29 04:28:27 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_sl.c,v 1.131 2019/01/24 09:33:03 knakahara Exp $	*/
+/*	$NetBSD: if_sl.c,v 1.132 2020/01/29 04:28:27 thorpej Exp $	*/
 
 /*
  * Copyright (c) 1987, 1989, 1992, 1993
@@ -60,7 +60,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_sl.c,v 1.131 2019/01/24 09:33:03 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_sl.c,v 1.132 2020/01/29 04:28:27 thorpej Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -485,7 +485,7 @@ sloutput(struct ifnet *ifp, struct mbuf 
 		printf("%s: af%d not supported\n", sc->sc_if.if_xname,
 		    dst->sa_family);
 		m_freem(m);
-		sc->sc_if.if_noproto++;
+		if_statinc(&sc->sc_if, if_noproto);
 		return EAFNOSUPPORT;
 	}
 
@@ -625,7 +625,7 @@ slinput(int c, struct tty *tp)
 	}
 	c &= TTY_CHARMASK;
 
-	++sc->sc_if.if_ibytes;
+	if_statinc(&sc->sc_if, if_ibytes);
 
 	if (sc->sc_if.if_flags & IFF_DEBUG) {
 		if (c == ABT_ESC) {
@@ -697,7 +697,7 @@ slinput(int c, struct tty *tp)
 	sc->sc_flags |= SC_ERROR;
 
 error:
-	sc->sc_if.if_ierrors++;
+	if_statinc(&sc->sc_if, if_ierrors);
 newpack:
 	sc->sc_mp = sc->sc_pktstart = (u_char *)sc->sc_mbuf->m_ext.ext_buf +
 	    BUFOFFSET;
@@ -746,7 +746,7 @@ slintr(void *arg)
 		s = splnet();
 		IF_DEQUEUE(&sc->sc_fastq, m);
 		if (m)
-			sc->sc_if.if_omcasts++;	/* XXX */
+			if_statinc(&sc->sc_if, if_omcasts);	/* XXX */
 		else
 			IFQ_DEQUEUE(&sc->sc_if.if_snd, m);
 		splx(s);
@@ -794,7 +794,7 @@ slintr(void *arg)
 		 * some time.
 		 */
 		if (tp->t_outq.c_cc == 0) {
-			sc->sc_if.if_obytes++;
+			if_statinc(&sc->sc_if, if_obytes);
 			(void)putc(FRAME_END, &tp->t_outq);
 		}
 
@@ -825,7 +825,8 @@ slintr(void *arg)
 					 */
 					if (b_to_q(bp, cp - bp, &tp->t_outq))
 						break;
-					sc->sc_if.if_obytes += cp - bp;
+					if_statadd(&sc->sc_if, if_obytes,
+					    cp - bp);
 				}
 				/*
 				 * If there are characters left in
@@ -843,7 +844,7 @@ slintr(void *arg)
 						(void)unputc(&tp->t_outq);
 						break;
 					}
-					sc->sc_if.if_obytes += 2;
+					if_statadd(&sc->sc_if, if_obytes, 2);
 				}
 				bp = cp;
 			}
@@ -861,10 +862,9 @@ slintr(void *arg)
 			 */
 			(void)unputc(&tp->t_outq);
 			(void)putc(FRAME_END, &tp->t_outq);
-			sc->sc_if.if_collisions++;
+			if_statinc(&sc->sc_if, if_collisions);
 		} else {
-			sc->sc_if.if_obytes++;
-			sc->sc_if.if_opackets++;
+			if_statadd2(&sc->sc_if, if_obytes, 1, if_opackets, 1);
 		}
 
 		/*
@@ -959,14 +959,13 @@ slintr(void *arg)
 			m = n;
 		}
 
-		sc->sc_if.if_ipackets++;
+		if_statinc(&sc->sc_if, if_ipackets);
 		getbinuptime(&sc->sc_lastpacket);
 
 #ifdef INET
 		s = splnet();
 		if (__predict_false(!pktq_enqueue(ip_pktq, m, 0))) {
-			sc->sc_if.if_ierrors++;
-			sc->sc_if.if_iqdrops++;
+			if_statadd2(&sc->sc_if, if_ierrors, 1, if_iqdrops, 1);
 			m_freem(m);
 		}
 		splx(s);
@@ -1032,15 +1031,18 @@ slioctl(struct ifnet *ifp, u_long cmd, v
 		}
 		break;
 
-	case SIOCGPPPSTATS:
+	case SIOCGPPPSTATS: {
+		struct if_data ifi;
+
+		if_export_if_data(&sc->sc_if, &ifi, false);
 		psp = &((struct ifpppstatsreq *) data)->stats;
 		(void)memset(psp, 0, sizeof(*psp));
-		psp->p.ppp_ibytes = sc->sc_if.if_ibytes;
-		psp->p.ppp_ipackets = sc->sc_if.if_ipackets;
-		psp->p.ppp_ierrors = sc->sc_if.if_ierrors;
-		psp->p.ppp_obytes = sc->sc_if.if_obytes;
-		psp->p.ppp_opackets = sc->sc_if.if_opackets;
-		psp->p.ppp_oerrors = sc->sc_if.if_oerrors;
+		psp->p.ppp_ibytes = ifi.ifi_ibytes;
+		psp->p.ppp_ipackets = ifi.ifi_ipackets;
+		psp->p.ppp_ierrors = ifi.ifi_ierrors;
+		psp->p.ppp_obytes = ifi.ifi_obytes;
+		psp->p.ppp_opackets = ifi.ifi_opackets;
+		psp->p.ppp_oerrors = ifi.ifi_oerrors;
 #ifdef INET
 		psp->vj.vjs_packets = sc->sc_comp.sls_packets;
 		psp->vj.vjs_compressed = sc->sc_comp.sls_compressed;
@@ -1051,6 +1053,7 @@ slioctl(struct ifnet *ifp, u_long cmd, v
 		psp->vj.vjs_errorin = sc->sc_comp.sls_errorin;
 		psp->vj.vjs_tossed = sc->sc_comp.sls_tossed;
 #endif
+	    }
 		break;
 
 	case SIOCGPPPCSTATS:

Index: src/sys/net/if_spppsubr.c
diff -u src/sys/net/if_spppsubr.c:1.184 src/sys/net/if_spppsubr.c:1.185
--- src/sys/net/if_spppsubr.c:1.184	Fri Sep 13 07:55:07 2019
+++ src/sys/net/if_spppsubr.c	Wed Jan 29 04:28:27 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_spppsubr.c,v 1.184 2019/09/13 07:55:07 msaitoh Exp $	 */
+/*	$NetBSD: if_spppsubr.c,v 1.185 2020/01/29 04:28:27 thorpej Exp $	 */
 
 /*
  * Synchronous PPP/Cisco link level subroutines.
@@ -41,7 +41,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.184 2019/09/13 07:55:07 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.185 2020/01/29 04:28:27 thorpej Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -532,7 +532,7 @@ sppp_input(struct ifnet *ifp, struct mbu
 
 	if (ifp->if_flags & IFF_UP) {
 		/* Count received bytes, add hardware framing */
-		ifp->if_ibytes += m->m_pkthdr.len + sp->pp_framebytes;
+		if_statadd(ifp, if_ibytes, m->m_pkthdr.len + sp->pp_framebytes);
 		/* Note time of last receive */
 		sp->pp_last_receive = time_uptime;
 	}
@@ -544,8 +544,7 @@ sppp_input(struct ifnet *ifp, struct mbu
 			    "%s: input packet is too small, %d bytes\n",
 			    ifp->if_xname, m->m_pkthdr.len);
 	  drop:
-		++ifp->if_ierrors;
-		++ifp->if_iqdrops;
+		if_statadd2(ifp, if_ierrors, 1, if_iqdrops, 1);
 		m_freem(m);
 		SPPP_UNLOCK(sp);
 		return;
@@ -589,7 +588,7 @@ sppp_input(struct ifnet *ifp, struct mbu
 			}
 			switch (ntohs(h->protocol)) {
 			default:
-				++ifp->if_noproto;
+				if_statinc(ifp, if_noproto);
 				goto invalid;
 			case CISCO_KEEPALIVE:
 				SPPP_UNLOCK(sp);
@@ -636,7 +635,7 @@ sppp_input(struct ifnet *ifp, struct mbu
 			log(LOG_DEBUG,
 			    "%s: invalid input protocol "
 			    "<proto=0x%x>\n", ifp->if_xname, ntohs(protocol));
-		++ifp->if_noproto;
+		if_statinc(ifp, if_noproto);
 		goto drop;
 	case PPP_LCP:
 		SPPP_UNLOCK(sp);
@@ -850,7 +849,7 @@ sppp_output(struct ifnet *ifp, struct mb
 			if (ifp->if_flags & IFF_DEBUG)
 				log(LOG_DEBUG, "%s: no memory for transmit header\n",
 					ifp->if_xname);
-			++ifp->if_oerrors;
+			if_statinc(ifp, if_oerrors);
 			SPPP_UNLOCK(sp);
 			splx(s);
 			return (ENOBUFS);
@@ -912,7 +911,7 @@ sppp_output(struct ifnet *ifp, struct mb
 #endif
 	default:
 		m_freem(m);
-		++ifp->if_oerrors;
+		if_statinc(ifp, if_oerrors);
 		SPPP_UNLOCK(sp);
 		splx(s);
 		return (EAFNOSUPPORT);
@@ -924,7 +923,7 @@ sppp_output(struct ifnet *ifp, struct mb
 			if (ifp->if_flags & IFF_DEBUG)
 				log(LOG_DEBUG, "%s: no memory for transmit header\n",
 					ifp->if_xname);
-			++ifp->if_oerrors;
+			if_statinc(ifp, if_oerrors);
 			SPPP_UNLOCK(sp);
 			splx(s);
 			return (ENOBUFS);
@@ -940,7 +939,7 @@ sppp_output(struct ifnet *ifp, struct mb
 	error = if_transmit_lock(ifp, m);
 	SPPP_LOCK(sp, RW_READER);
 	if (error == 0)
-		ifp->if_obytes += pktlen + sp->pp_framebytes;
+		if_statadd(ifp, if_obytes, pktlen + sp->pp_framebytes);
 #else /* !SPPPSUBR_MPSAFE */
 	error = ifq_enqueue2(ifp, ifq, m);
 
@@ -955,7 +954,7 @@ sppp_output(struct ifnet *ifp, struct mb
 			if_start_lock(ifp);
 			SPPP_LOCK(sp, RW_READER);
 		}
-		ifp->if_obytes += pktlen + sp->pp_framebytes;
+		if_statadd(ifp, if_obytes, pktlen + sp->pp_framebytes);
 	}
 #endif /* !SPPPSUBR_MPSAFE */
 	SPPP_UNLOCK(sp);
@@ -1419,11 +1418,11 @@ sppp_cisco_send(struct sppp *sp, int typ
 		IF_DROP(&sp->pp_fastq);
 		IF_DROP(&ifp->if_snd);
 		m_freem(m);
-		++ifp->if_oerrors;
+		if_statinc(ifp, if_oerrors);
 		return;
 	}
 
-	ifp->if_obytes += m->m_pkthdr.len + sp->pp_framebytes;
+	if_statadd(ifp, if_obytes, m->m_pkthdr.len + sp->pp_framebytes);
 	IF_ENQUEUE(&sp->pp_cpq, m);
 
 	if (! (ifp->if_flags & IFF_OACTIVE)) {
@@ -1492,11 +1491,11 @@ sppp_cp_send(struct sppp *sp, u_short pr
 		IF_DROP(&sp->pp_fastq);
 		IF_DROP(&ifp->if_snd);
 		m_freem(m);
-		++ifp->if_oerrors;
+		if_statinc(ifp, if_oerrors);
 		return;
 	}
 
-	ifp->if_obytes += m->m_pkthdr.len + sp->pp_framebytes;
+	if_statadd(ifp, if_obytes, m->m_pkthdr.len + sp->pp_framebytes);
 	IF_ENQUEUE(&sp->pp_cpq, m);
 
 
@@ -1554,7 +1553,7 @@ sppp_cp_input(const struct cp *cp, struc
 				addlog("%s: %s invalid conf-req length %d\n",
 				       ifp->if_xname, cp->name,
 				       len);
-			++ifp->if_ierrors;
+			if_statinc(ifp, if_ierrors);
 			break;
 		}
 		/* handle states where RCR doesn't get a SCA/SCN */
@@ -1609,7 +1608,7 @@ sppp_cp_input(const struct cp *cp, struc
 			       ifp->if_xname, cp->name,
 			       sppp_cp_type_name(h->type),
 			       sppp_state_name(sp->state[cp->protoidx]));
-			++ifp->if_ierrors;
+			if_statinc(ifp, if_ierrors);
 		}
 		break;
 	case CONF_ACK:
@@ -1618,7 +1617,7 @@ sppp_cp_input(const struct cp *cp, struc
 				addlog("%s: %s id mismatch 0x%x != 0x%x\n",
 				       ifp->if_xname, cp->name,
 				       h->ident, sp->confid[cp->protoidx]);
-			++ifp->if_ierrors;
+			if_statinc(ifp, if_ierrors);
 			break;
 		}
 		switch (sp->state[cp->protoidx]) {
@@ -1653,7 +1652,7 @@ sppp_cp_input(const struct cp *cp, struc
 			       ifp->if_xname, cp->name,
 			       sppp_cp_type_name(h->type),
 			       sppp_state_name(sp->state[cp->protoidx]));
-			++ifp->if_ierrors;
+			if_statinc(ifp, if_ierrors);
 		}
 		break;
 	case CONF_NAK:
@@ -1663,7 +1662,7 @@ sppp_cp_input(const struct cp *cp, struc
 				addlog("%s: %s id mismatch 0x%x != 0x%x\n",
 				       ifp->if_xname, cp->name,
 				       h->ident, sp->confid[cp->protoidx]);
-			++ifp->if_ierrors;
+			if_statinc(ifp, if_ierrors);
 			break;
 		}
 		if (h->type == CONF_NAK)
@@ -1696,7 +1695,7 @@ sppp_cp_input(const struct cp *cp, struc
 			       ifp->if_xname, cp->name,
 			       sppp_cp_type_name(h->type),
 			       sppp_state_name(sp->state[cp->protoidx]));
-			++ifp->if_ierrors;
+			if_statinc(ifp, if_ierrors);
 		}
 		break;
 
@@ -1728,7 +1727,7 @@ sppp_cp_input(const struct cp *cp, struc
 			       ifp->if_xname, cp->name,
 			       sppp_cp_type_name(h->type),
 			       sppp_state_name(sp->state[cp->protoidx]));
-			++ifp->if_ierrors;
+			if_statinc(ifp, if_ierrors);
 		}
 		break;
 	case TERM_ACK:
@@ -1761,7 +1760,7 @@ sppp_cp_input(const struct cp *cp, struc
 			       ifp->if_xname, cp->name,
 			       sppp_cp_type_name(h->type),
 			       sppp_state_name(sp->state[cp->protoidx]));
-			++ifp->if_ierrors;
+			if_statinc(ifp, if_ierrors);
 		}
 		break;
 	case CODE_REJ:
@@ -1788,7 +1787,7 @@ sppp_cp_input(const struct cp *cp, struc
 			       ifp->if_xname, cp->name,
 			       sppp_cp_type_name(h->type),
 			       sppp_state_name(sp->state[cp->protoidx]));
-			++ifp->if_ierrors;
+			if_statinc(ifp, if_ierrors);
 		}
 		break;
 	case PROTO_REJ:
@@ -1847,7 +1846,7 @@ sppp_cp_input(const struct cp *cp, struc
 			       ifp->if_xname, cp->name,
 			       sppp_cp_type_name(h->type),
 			       sppp_state_name(sp->state[cp->protoidx]));
-			++ifp->if_ierrors;
+			if_statinc(ifp, if_ierrors);
 		}
 		break;
 	    }
@@ -1863,7 +1862,7 @@ sppp_cp_input(const struct cp *cp, struc
 			if (debug)
 				addlog("%s: lcp echo req but lcp closed\n",
 				       ifp->if_xname);
-			++ifp->if_ierrors;
+			if_statinc(ifp, if_ierrors);
 			break;
 		}
 		if (len < 8) {
@@ -1901,7 +1900,7 @@ sppp_cp_input(const struct cp *cp, struc
 		if (cp->proto != PPP_LCP)
 			goto illegal;
 		if (h->ident != sp->lcp.echoid) {
-			++ifp->if_ierrors;
+			if_statinc(ifp, if_ierrors);
 			break;
 		}
 		if (len < 8) {
@@ -1926,7 +1925,7 @@ sppp_cp_input(const struct cp *cp, struc
 			       ifp->if_xname, cp->name, h->type);
 		sppp_cp_send(sp, cp->proto, CODE_REJ,
 		    ++sp->pp_seq[cp->protoidx], m->m_pkthdr.len, h);
-		++ifp->if_ierrors;
+		if_statinc(ifp, if_ierrors);
 	}
 
 	SPPP_UNLOCK(sp);
@@ -5094,11 +5093,11 @@ sppp_auth_send(const struct cp *cp, stru
 		IF_DROP(&sp->pp_fastq);
 		IF_DROP(&ifp->if_snd);
 		m_freem(m);
-		++ifp->if_oerrors;
+		if_statinc(ifp, if_oerrors);
 		return;
 	}
 
-	ifp->if_obytes += m->m_pkthdr.len + sp->pp_framebytes;
+	if_statadd(ifp, if_obytes, m->m_pkthdr.len + sp->pp_framebytes);
 	IF_ENQUEUE(&sp->pp_cpq, m);
 
 	if (! (ifp->if_flags & IFF_OACTIVE)) {

Index: src/sys/net/if_srt.c
diff -u src/sys/net/if_srt.c:1.30 src/sys/net/if_srt.c:1.31
--- src/sys/net/if_srt.c:1.30	Sat Apr 27 06:18:15 2019
+++ src/sys/net/if_srt.c	Wed Jan 29 04:28:27 2020
@@ -1,8 +1,8 @@
-/* $NetBSD: if_srt.c,v 1.30 2019/04/27 06:18:15 pgoyette Exp $ */
+/* $NetBSD: if_srt.c,v 1.31 2020/01/29 04:28:27 thorpej Exp $ */
 /* This file is in the public domain. */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_srt.c,v 1.30 2019/04/27 06:18:15 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_srt.c,v 1.31 2020/01/29 04:28:27 thorpej Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -246,9 +246,9 @@ srt_if_output(
 	}
 	/* XXX Do we need to bpf_tap?  Or do higher layers now handle that? */
 	/* if_gif.c seems to imply the latter. */
-	ifp->if_opackets ++;
+	if_statinc(ifp, if_opackets);
 	if (! r) {
-		ifp->if_oerrors ++;
+		if_statinc(ifp, if_oerrors);
 		m_freem(m);
 		return 0;
 	}
@@ -257,7 +257,7 @@ srt_if_output(
 		m_freem(m);
 		return 0;
 	}
-	ifp->if_obytes += m->m_pkthdr.len;
+	if_statadd(ifp, if_obytes, m->m_pkthdr.len);
 	if (! (r->u.dstifp->if_flags & IFF_UP)) {
 		m_freem(m);
 		return 0; /* XXX ENETDOWN? */

Index: src/sys/net/if_stf.c
diff -u src/sys/net/if_stf.c:1.106 src/sys/net/if_stf.c:1.107
--- src/sys/net/if_stf.c:1.106	Fri Apr 26 11:51:56 2019
+++ src/sys/net/if_stf.c	Wed Jan 29 04:28:27 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_stf.c,v 1.106 2019/04/26 11:51:56 pgoyette Exp $	*/
+/*	$NetBSD: if_stf.c,v 1.107 2020/01/29 04:28:27 thorpej Exp $	*/
 /*	$KAME: if_stf.c,v 1.62 2001/06/07 22:32:16 itojun Exp $ */
 
 /*
@@ -75,7 +75,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_stf.c,v 1.106 2019/04/26 11:51:56 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_stf.c,v 1.107 2020/01/29 04:28:27 thorpej Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -392,14 +392,14 @@ stf_output(struct ifnet *ifp, struct mbu
 	ia6 = stf_getsrcifa6(ifp);
 	if (ia6 == NULL) {
 		m_freem(m);
-		ifp->if_oerrors++;
+		if_statinc(ifp, if_oerrors);
 		return ENETDOWN;
 	}
 
 	if (m->m_len < sizeof(*ip6)) {
 		m = m_pullup(m, sizeof(*ip6));
 		if (m == NULL) {
-			ifp->if_oerrors++;
+			if_statinc(ifp, if_oerrors);
 			return ENOBUFS;
 		}
 	}
@@ -416,7 +416,7 @@ stf_output(struct ifnet *ifp, struct mbu
 		in4 = GET_V4(&dst6->sin6_addr);
 	else {
 		m_freem(m);
-		ifp->if_oerrors++;
+		if_statinc(ifp, if_oerrors);
 		return ENETUNREACH;
 	}
 
@@ -426,7 +426,7 @@ stf_output(struct ifnet *ifp, struct mbu
 	if (m && m->m_len < sizeof(struct ip))
 		m = m_pullup(m, sizeof(struct ip));
 	if (m == NULL) {
-		ifp->if_oerrors++;
+		if_statinc(ifp, if_oerrors);
 		return ENOBUFS;
 	}
 	ip = mtod(m, struct ip *);
@@ -447,7 +447,7 @@ stf_output(struct ifnet *ifp, struct mbu
 	sockaddr_in_init(&u.dst4, &ip->ip_dst, 0);
 	if ((rt = rtcache_lookup(&sc->sc_ro, &u.dst)) == NULL) {
 		m_freem(m);
-		ifp->if_oerrors++;
+		if_statinc(ifp, if_oerrors);
 		return ENETUNREACH;
 	}
 
@@ -456,13 +456,13 @@ stf_output(struct ifnet *ifp, struct mbu
 		rtcache_unref(rt, &sc->sc_ro);
 		rtcache_free(&sc->sc_ro);
 		m_freem(m);
-		ifp->if_oerrors++;
+		if_statinc(ifp, if_oerrors);
 		return ENETUNREACH;
 	}
 	rtcache_unref(rt, &sc->sc_ro);
 
-	ifp->if_opackets++;
-	ifp->if_obytes += m->m_pkthdr.len - sizeof(struct ip);
+	if_statadd2(ifp, if_opackets, 1,
+	    if_obytes, m->m_pkthdr.len - sizeof(struct ip));
 	return ip_output(m, NULL, &sc->sc_ro, 0, NULL, NULL);
 }
 
@@ -667,8 +667,7 @@ in_stf_input(struct mbuf *m, int off, in
 
 	s = splnet();
 	if (__predict_true(pktq_enqueue(ip6_pktq, m, 0))) {
-		ifp->if_ipackets++;
-		ifp->if_ibytes += pktlen;
+		if_statadd2(ifp, if_ipackets, 1, if_ibytes, pktlen);
 	} else {
 		m_freem(m);
 	}

Index: src/sys/net/if_tap.c
diff -u src/sys/net/if_tap.c:1.115 src/sys/net/if_tap.c:1.116
--- src/sys/net/if_tap.c:1.115	Mon Jan  6 20:31:35 2020
+++ src/sys/net/if_tap.c	Wed Jan 29 04:28:27 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_tap.c,v 1.115 2020/01/06 20:31:35 christos Exp $	*/
+/*	$NetBSD: if_tap.c,v 1.116 2020/01/29 04:28:27 thorpej Exp $	*/
 
 /*
  *  Copyright (c) 2003, 2004, 2008, 2009 The NetBSD Foundation.
@@ -33,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_tap.c,v 1.115 2020/01/06 20:31:35 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_tap.c,v 1.116 2020/01/29 04:28:27 thorpej Exp $");
 
 #if defined(_KERNEL_OPT)
 
@@ -524,8 +524,7 @@ tap_start(struct ifnet *ifp)
 			if (m0 == NULL)
 				goto done;
 
-			ifp->if_opackets++;
-			ifp->if_obytes += m0->m_len;
+			if_statadd2(ifp, if_opackets, 1, if_obytes, m0->m_len);
 			bpf_mtap(ifp, m0, BPF_D_OUT);
 
 			m_freem(m0);
@@ -893,8 +892,7 @@ tap_dev_close(struct tap_softc *sc)
 			if (m == NULL)
 				break;
 
-			ifp->if_opackets++;
-			ifp->if_obytes += m->m_len;
+			if_statadd2(ifp, if_opackets, 1, if_obytes, m->m_len);
 			bpf_mtap(ifp, m, BPF_D_OUT);
 			m_freem(m);
 		}
@@ -980,8 +978,8 @@ tap_dev_read(int unit, struct uio *uio, 
 		goto out;
 	}
 
-	ifp->if_opackets++;
-	ifp->if_obytes += m->m_len; // XXX: only first in chain
+	if_statadd2(ifp, if_opackets, 1,
+	    if_obytes, m->m_len);		/* XXX only first in chain */
 	bpf_mtap(ifp, m, BPF_D_OUT);
 	if ((error = pfil_run_hooks(ifp->if_pfil, &m, ifp, PFIL_OUT)) != 0)
 		goto out;
@@ -1069,7 +1067,7 @@ tap_dev_write(int unit, struct uio *uio,
 	/* One write, one packet, that's the rule */
 	MGETHDR(m, M_DONTWAIT, MT_DATA);
 	if (m == NULL) {
-		ifp->if_ierrors++;
+		if_statinc(ifp, if_ierrors);
 		return ENOBUFS;
 	}
 	m->m_pkthdr.len = uio->uio_resid;
@@ -1089,15 +1087,14 @@ tap_dev_write(int unit, struct uio *uio,
 		mp = &(*mp)->m_next;
 	}
 	if (error) {
-		ifp->if_ierrors++;
+		if_statinc(ifp, if_ierrors);
 		m_freem(m);
 		return error;
 	}
 
 	m_set_rcvif(m, ifp);
 
-	ifp->if_ipackets++;
-	ifp->if_ibytes += len;
+	if_statadd2(ifp, if_ipackets, 1, if_ibytes, len);
 	bpf_mtap(ifp, m, BPF_D_IN);
 	if ((error = pfil_run_hooks(ifp->if_pfil, &m, ifp, PFIL_IN)) != 0)
 		return error;

Index: src/sys/net/if_vlan.c
diff -u src/sys/net/if_vlan.c:1.149 src/sys/net/if_vlan.c:1.150
--- src/sys/net/if_vlan.c:1.149	Thu Dec 12 02:15:43 2019
+++ src/sys/net/if_vlan.c	Wed Jan 29 04:28:27 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vlan.c,v 1.149 2019/12/12 02:15:43 pgoyette Exp $	*/
+/*	$NetBSD: if_vlan.c,v 1.150 2020/01/29 04:28:27 thorpej Exp $	*/
 
 /*
  * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc.
@@ -78,7 +78,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.149 2019/12/12 02:15:43 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.150 2020/01/29 04:28:27 thorpej Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1391,7 +1391,7 @@ vlan_start(struct ifnet *ifp)
 			if (m == NULL) {
 				printf("%s: unable to prepend encap header",
 				    p->if_xname);
-				ifp->if_oerrors++;
+				if_statinc(ifp, if_oerrors);
 				continue;
 			}
 
@@ -1406,7 +1406,7 @@ vlan_start(struct ifnet *ifp)
 				if (m == NULL) {
 					printf("%s: unable to pullup encap "
 					    "header", p->if_xname);
-					ifp->if_oerrors++;
+					if_statinc(ifp, if_oerrors);
 					continue;
 				}
 
@@ -1455,10 +1455,10 @@ vlan_start(struct ifnet *ifp)
 		error = if_transmit_lock(p, m);
 		if (error) {
 			/* mbuf is already freed */
-			ifp->if_oerrors++;
+			if_statinc(ifp, if_oerrors);
 			continue;
 		}
-		ifp->if_opackets++;
+		if_statinc(ifp, if_opackets);
 	}
 
 	ifp->if_flags &= ~IFF_OACTIVE;
@@ -1509,7 +1509,7 @@ vlan_transmit(struct ifnet *ifp, struct 
 		if (m == NULL) {
 			printf("%s: unable to prepend encap header",
 			    p->if_xname);
-			ifp->if_oerrors++;
+			if_statinc(ifp, if_oerrors);
 			error = ENOBUFS;
 			goto out;
 		}
@@ -1525,7 +1525,7 @@ vlan_transmit(struct ifnet *ifp, struct 
 			if (m == NULL) {
 				printf("%s: unable to pullup encap "
 				    "header", p->if_xname);
-				ifp->if_oerrors++;
+				if_statinc(ifp, if_oerrors);
 				error = ENOBUFS;
 				goto out;
 			}
@@ -1574,16 +1574,17 @@ vlan_transmit(struct ifnet *ifp, struct 
 	}
 
 	error = if_transmit_lock(p, m);
+	net_stat_ref_t nsr = IF_STAT_GETREF(ifp);
 	if (error) {
 		/* mbuf is already freed */
-		ifp->if_oerrors++;
+		if_statinc_ref(nsr, if_oerrors);
 	} else {
-
-		ifp->if_opackets++;
-		ifp->if_obytes += pktlen;
+		if_statinc_ref(nsr, if_opackets);
+		if_statadd_ref(nsr, if_obytes, pktlen);
 		if (mcast)
-			ifp->if_omcasts++;
+			if_statinc_ref(nsr, if_omcasts);
 	}
+	IF_STAT_PUTREF(ifp);
 
 out:
 	/* Remove reference to mib before release */
@@ -1639,7 +1640,7 @@ vlan_input(struct ifnet *ifp, struct mbu
 	mib = vlan_lookup_tag_psref(ifp, vid, &psref);
 	if (mib == NULL) {
 		m_freem(m);
-		ifp->if_noproto++;
+		if_statinc(ifp, if_noproto);
 		return;
 	}
 	KASSERT(mib->ifvm_encaplen == ETHER_VLAN_ENCAP_LEN);
@@ -1648,7 +1649,7 @@ vlan_input(struct ifnet *ifp, struct mbu
 	if ((ifv->ifv_if.if_flags & (IFF_UP | IFF_RUNNING)) !=
 	    (IFF_UP | IFF_RUNNING)) {
 		m_freem(m);
-		ifp->if_noproto++;
+		if_statinc(ifp, if_noproto);
 		goto out;
 	}
 

Index: src/sys/net/ppp_tty.c
diff -u src/sys/net/ppp_tty.c:1.66 src/sys/net/ppp_tty.c:1.67
--- src/sys/net/ppp_tty.c:1.66	Fri Sep 20 08:45:29 2019
+++ src/sys/net/ppp_tty.c	Wed Jan 29 04:28:27 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ppp_tty.c,v 1.66 2019/09/20 08:45:29 maxv Exp $	*/
+/*	$NetBSD: ppp_tty.c,v 1.67 2020/01/29 04:28:27 thorpej Exp $	*/
 /*	Id: ppp_tty.c,v 1.3 1996/07/01 01:04:11 paulus Exp 	*/
 
 /*
@@ -93,7 +93,7 @@
 /* from NetBSD: if_ppp.c,v 1.15.2.2 1994/07/28 05:17:58 cgd Exp */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ppp_tty.c,v 1.66 2019/09/20 08:45:29 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ppp_tty.c,v 1.67 2020/01/29 04:28:27 thorpej Exp $");
 
 #ifdef _KERNEL_OPT
 #include "ppp.h"
@@ -1035,7 +1035,7 @@ pppinput(int c, struct tty *tp)
 		if (sc->sc_flags & SC_DEBUG)
 		    printf("%s: bad fcs %x\n", sc->sc_if.if_xname,
 			sc->sc_fcs);
-		sc->sc_if.if_ierrors++;
+		if_statinc(&sc->sc_if, if_ierrors);
 		sc->sc_stats.ppp_ierrors++;
 	    } else
 		sc->sc_flags &= ~(SC_FLUSH | SC_ESCAPED);
@@ -1048,7 +1048,7 @@ pppinput(int c, struct tty *tp)
 		if (sc->sc_flags & SC_DEBUG)
 		    printf("%s: too short (%d)\n", sc->sc_if.if_xname, ilen);
 		s = spltty();
-		sc->sc_if.if_ierrors++;
+		if_statinc(&sc->sc_if, if_ierrors);
 		sc->sc_stats.ppp_ierrors++;
 		sc->sc_flags |= SC_PKTLOST;
 		splx(s);
@@ -1192,7 +1192,7 @@ pppinput(int c, struct tty *tp)
  flush:
     if (!(sc->sc_flags & SC_FLUSH)) {
 	s = spltty();
-	sc->sc_if.if_ierrors++;
+	if_statinc(&sc->sc_if, if_ierrors);
 	sc->sc_stats.ppp_ierrors++;
 	sc->sc_flags |= SC_FLUSH;
 	splx(s);

Reply via email to