From f7f9047fbe33d7b438e297274fef3d59fdb2067f Mon Sep 17 00:00:00 2001 From: bluhm Date: Fri, 29 Dec 2023 11:43:04 +0000 Subject: [PATCH] Make loopback interface counters MP safe. Create and use the MP safe version of the interface counters for lo(4). Input packets were counted twice. As interface input queue is already counting, remove input count in if_input_local(). Multicast and siplex packets are counted at the ethernet interface. Add a comment that this not MP safe. OK mvs@ --- sys/net/if.c | 15 +++++++++------ sys/net/if_loop.c | 5 +++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/sys/net/if.c b/sys/net/if.c index 61c24afb31f..bb1b8919e92 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if.c,v 1.713 2023/12/23 10:52:54 bluhm Exp $ */ +/* $OpenBSD: if.c,v 1.714 2023/12/29 11:43:04 bluhm Exp $ */ /* $NetBSD: if.c,v 1.35 1996/05/07 05:26:04 thorpej Exp $ */ /* @@ -839,11 +839,14 @@ if_input_local(struct ifnet *ifp, struct mbuf *m, sa_family_t af) if (ISSET(keepcksum, M_ICMP_CSUM_OUT)) m->m_pkthdr.csum_flags |= M_ICMP_CSUM_IN_OK; - ifp->if_opackets++; - ifp->if_obytes += m->m_pkthdr.len; - - ifp->if_ipackets++; - ifp->if_ibytes += m->m_pkthdr.len; + if (ifp->if_counters == NULL) { + /* XXXSMP multicast loopback and simplex interfaces */ + ifp->if_opackets++; + ifp->if_obytes += m->m_pkthdr.len; + } else { + counters_pkt(ifp->if_counters, ifc_opackets, ifc_obytes, + m->m_pkthdr.len); + } switch (af) { case AF_INET: diff --git a/sys/net/if_loop.c b/sys/net/if_loop.c index 1c771d1bfd5..6a22baf4b35 100644 --- a/sys/net/if_loop.c +++ b/sys/net/if_loop.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_loop.c,v 1.97 2023/07/21 22:24:41 bluhm Exp $ */ +/* $OpenBSD: if_loop.c,v 1.98 2023/12/29 11:43:04 bluhm Exp $ */ /* $NetBSD: if_loop.c,v 1.15 1996/05/07 02:40:33 thorpej Exp $ */ /* @@ -185,6 +185,7 @@ loop_clone_create(struct if_clone *ifc, int unit) ifp->if_output = looutput; ifp->if_type = IFT_LOOP; ifp->if_hdrlen = sizeof(u_int32_t); + if_counters_alloc(ifp); if (unit == 0) { if_attachhead(ifp); if_addgroup(ifp, ifc->ifc_name); @@ -250,7 +251,7 @@ loinput(struct ifnet *ifp, struct mbuf *m) error = if_input_local(ifp, m, m->m_pkthdr.ph_family); if (error) - ifp->if_ierrors++; + counters_inc(ifp->if_counters, ifc_ierrors); } int -- 2.20.1