-/* $OpenBSD: if.c,v 1.712 2023/12/22 23:01:50 mvs Exp $ */
+/* $OpenBSD: if.c,v 1.713 2023/12/23 10:52:54 bluhm Exp $ */
/* $NetBSD: if.c,v 1.35 1996/05/07 05:26:04 thorpej Exp $ */
/*
"%s: if_qstart not set with MPSAFE set", ifp->if_xname);
}
- ifp->if_counters = counters_alloc(ifc_ncounters);
-
if_idxmap_alloc(ifp);
ifq_init(&ifp->if_snd, ifp, 0);
/* Announce that the interface is gone. */
rtm_ifannounce(ifp, IFAN_DEPARTURE);
- counters_free(ifp->if_counters, ifc_ncounters);
+ if (ifp->if_counters != NULL)
+ if_counters_free(ifp);
for (i = 0; i < ifp->if_nifqs; i++)
ifq_destroy(ifp->if_ifqs[i]);
return (error);
}
+void
+if_counters_alloc(struct ifnet *ifp)
+{
+ KASSERT(ifp->if_counters == NULL);
+
+ ifp->if_counters = counters_alloc(ifc_ncounters);
+}
+
+void
+if_counters_free(struct ifnet *ifp)
+{
+ KASSERT(ifp->if_counters != NULL);
+
+ counters_free(ifp->if_counters, ifc_ncounters);
+ ifp->if_counters = NULL;
+}
+
void
if_getdata(struct ifnet *ifp, struct if_data *data)
{
- uint64_t counters[ifc_ncounters];
unsigned int i;
*data = ifp->if_data;
- counters_read(ifp->if_counters, counters, nitems(counters), NULL);
-
- data->ifi_ipackets += counters[ifc_ipackets];
- data->ifi_ierrors += counters[ifc_ierrors];
- data->ifi_opackets += counters[ifc_opackets];
- data->ifi_oerrors += counters[ifc_oerrors];
- data->ifi_collisions += counters[ifc_collisions];
- data->ifi_ibytes += counters[ifc_ibytes];
- data->ifi_obytes += counters[ifc_obytes];
- data->ifi_imcasts += counters[ifc_imcasts];
- data->ifi_omcasts += counters[ifc_omcasts];
- data->ifi_iqdrops += counters[ifc_iqdrops];
- data->ifi_oqdrops += counters[ifc_oqdrops];
- data->ifi_noproto += counters[ifc_noproto];
+ if (ifp->if_counters != NULL) {
+ uint64_t counters[ifc_ncounters];
+
+ counters_read(ifp->if_counters, counters, nitems(counters),
+ NULL);
+
+ data->ifi_ipackets += counters[ifc_ipackets];
+ data->ifi_ierrors += counters[ifc_ierrors];
+ data->ifi_opackets += counters[ifc_opackets];
+ data->ifi_oerrors += counters[ifc_oerrors];
+ data->ifi_collisions += counters[ifc_collisions];
+ data->ifi_ibytes += counters[ifc_ibytes];
+ data->ifi_obytes += counters[ifc_obytes];
+ data->ifi_imcasts += counters[ifc_imcasts];
+ data->ifi_omcasts += counters[ifc_omcasts];
+ data->ifi_iqdrops += counters[ifc_iqdrops];
+ data->ifi_oqdrops += counters[ifc_oqdrops];
+ data->ifi_noproto += counters[ifc_noproto];
+ }
for (i = 0; i < ifp->if_nifqs; i++) {
struct ifqueue *ifq = ifp->if_ifqs[i];
-/* $OpenBSD: if_aggr.c,v 1.41 2023/12/22 23:01:50 mvs Exp $ */
+/* $OpenBSD: if_aggr.c,v 1.42 2023/12/23 10:52:54 bluhm Exp $ */
/*
* Copyright (c) 2019 The University of Queensland
ifp->if_link_state = LINK_STATE_DOWN;
ether_fakeaddr(ifp);
+ if_counters_alloc(ifp);
if_attach(ifp);
ether_ifattach(ifp);
-/* $OpenBSD: if_bpe.c,v 1.21 2023/12/22 23:01:50 mvs Exp $ */
+/* $OpenBSD: if_bpe.c,v 1.22 2023/12/23 10:52:54 bluhm Exp $ */
/*
* Copyright (c) 2018 David Gwynne <dlg@openbsd.org>
*
ifp->if_xflags = IFXF_CLONED;
ether_fakeaddr(ifp);
+ if_counters_alloc(ifp);
if_attach(ifp);
ether_ifattach(ifp);
-/* $OpenBSD: if_etherip.c,v 1.53 2023/12/22 23:01:50 mvs Exp $ */
+/* $OpenBSD: if_etherip.c,v 1.54 2023/12/23 10:52:54 bluhm Exp $ */
/*
* Copyright (c) 2015 Kazuya GODA <goda@openbsd.org>
*
ifmedia_add(&sc->sc_media, IFM_ETHER | IFM_AUTO, 0, NULL);
ifmedia_set(&sc->sc_media, IFM_ETHER | IFM_AUTO);
+ if_counters_alloc(ifp);
if_attach(ifp);
ether_ifattach(ifp);
-/* $OpenBSD: if_gif.c,v 1.135 2023/12/22 23:01:50 mvs Exp $ */
+/* $OpenBSD: if_gif.c,v 1.136 2023/12/23 10:52:54 bluhm Exp $ */
/* $KAME: if_gif.c,v 1.43 2001/02/20 08:51:07 itojun Exp $ */
/*
if_attach(ifp);
if_alloc_sadl(ifp);
+ if_counters_alloc(ifp);
#if NBPFILTER > 0
bpfattach(&ifp->if_bpf, ifp, DLT_LOOP, sizeof(uint32_t));
-/* $OpenBSD: if_gre.c,v 1.177 2023/12/22 23:01:50 mvs Exp $ */
+/* $OpenBSD: if_gre.c,v 1.178 2023/12/23 10:52:54 bluhm Exp $ */
/* $NetBSD: if_gre.c,v 1.9 1999/10/25 19:18:11 drochner Exp $ */
/*
timeout_set_proc(&sc->sc_ka_hold, gre_keepalive_hold, sc);
sc->sc_ka_state = GRE_KA_NONE;
+ if_counters_alloc(ifp);
if_attach(ifp);
if_alloc_sadl(ifp);
sc->sc_tunnel.t_df = htons(0);
sc->sc_tunnel.t_ecn = ECN_ALLOWED;
+ if_counters_alloc(ifp);
if_attach(ifp);
if_alloc_sadl(ifp);
ifmedia_add(&sc->sc_media, IFM_ETHER | IFM_AUTO, 0, NULL);
ifmedia_set(&sc->sc_media, IFM_ETHER | IFM_AUTO);
+ if_counters_alloc(ifp);
if_attach(ifp);
ether_ifattach(ifp);
ifmedia_add(&sc->sc_media, IFM_ETHER | IFM_AUTO, 0, NULL);
ifmedia_set(&sc->sc_media, IFM_ETHER | IFM_AUTO);
+ if_counters_alloc(ifp);
if_attach(ifp);
ether_ifattach(ifp);
ifmedia_add(&sc->sc_media, IFM_ETHER | IFM_AUTO, 0, NULL);
ifmedia_set(&sc->sc_media, IFM_ETHER | IFM_AUTO);
+ if_counters_alloc(ifp);
if_attach(ifp);
ether_ifattach(ifp);
-/* $OpenBSD: if_mpe.c,v 1.103 2023/12/22 23:01:50 mvs Exp $ */
+/* $OpenBSD: if_mpe.c,v 1.104 2023/12/23 10:52:54 bluhm Exp $ */
/*
* Copyright (c) 2008 Pierre-Yves Ritschard <pyr@spootnik.org>
if_attach(ifp);
if_alloc_sadl(ifp);
+ if_counters_alloc(ifp);
#if NBPFILTER > 0
bpfattach(&ifp->if_bpf, ifp, DLT_LOOP, sizeof(u_int32_t));
-/* $OpenBSD: if_mpip.c,v 1.17 2023/12/22 23:01:50 mvs Exp $ */
+/* $OpenBSD: if_mpip.c,v 1.18 2023/12/23 10:52:54 bluhm Exp $ */
/*
* Copyright (c) 2015 Rafael Zalamena <rzalamena@openbsd.org>
ifp->if_hardmtu = 65535;
if_attach(ifp);
+ if_counters_alloc(ifp);
if_alloc_sadl(ifp);
#if NBPFILTER > 0
-/* $OpenBSD: if_mpw.c,v 1.64 2023/12/22 23:01:50 mvs Exp $ */
+/* $OpenBSD: if_mpw.c,v 1.65 2023/12/23 10:52:54 bluhm Exp $ */
/*
* Copyright (c) 2015 Rafael Zalamena <rzalamena@openbsd.org>
sc->sc_dead = 0;
+ if_counters_alloc(ifp);
if_attach(ifp);
ether_ifattach(ifp);
-/* $OpenBSD: if_pflow.c,v 1.108 2023/12/22 23:01:50 mvs Exp $ */
+/* $OpenBSD: if_pflow.c,v 1.109 2023/12/23 10:52:54 bluhm Exp $ */
/*
* Copyright (c) 2011 Florian Obser <florian@narrans.de>
task_set(&pflowif->sc_outputtask, pflow_output_process, pflowif);
+ if_counters_alloc(ifp);
if_attach(ifp);
if_alloc_sadl(ifp);
-/* $OpenBSD: if_pfsync.c,v 1.323 2023/12/22 23:01:50 mvs Exp $ */
+/* $OpenBSD: if_pfsync.c,v 1.324 2023/12/23 10:52:54 bluhm Exp $ */
/*
* Copyright (c) 2002 Michael Shalayeff
#endif
}
+ if_counters_alloc(ifp);
if_attach(ifp);
if_alloc_sadl(ifp);
-/* $OpenBSD: if_pppx.c,v 1.127 2023/12/22 23:01:50 mvs Exp $ */
+/* $OpenBSD: if_pppx.c,v 1.128 2023/12/23 10:52:54 bluhm Exp $ */
/*
* Copyright (c) 2010 Claudio Jeker <claudio@openbsd.org>
ifp->if_type = IFT_PPP;
ifp->if_softc = pxi;
/* ifp->if_rdomain = req->pr_rdomain; */
+ if_counters_alloc(ifp);
if_attach(ifp);
ifp->if_qstart = pppac_qstart;
ifp->if_ioctl = pppac_ioctl;
+ if_counters_alloc(ifp);
if_attach(ifp);
if_alloc_sadl(ifp);
-/* $OpenBSD: if_sec.c,v 1.8 2023/12/22 23:01:50 mvs Exp $ */
+/* $OpenBSD: if_sec.c,v 1.9 2023/12/23 10:52:54 bluhm Exp $ */
/*
* Copyright (c) 2022 The University of Queensland
ifp->if_ioctl = sec_ioctl;
ifp->if_rtrequest = p2p_rtrequest;
+ if_counters_alloc(ifp);
if_attach(ifp);
if_alloc_sadl(ifp);
-/* $OpenBSD: if_tpmr.c,v 1.34 2023/12/22 23:01:50 mvs Exp $ */
+/* $OpenBSD: if_tpmr.c,v 1.35 2023/12/23 10:52:54 bluhm Exp $ */
/*
* Copyright (c) 2019 The University of Queensland
ifp->if_xflags = IFXF_CLONED | IFXF_MPSAFE;
ifp->if_link_state = LINK_STATE_DOWN;
+ if_counters_alloc(ifp);
if_attach(ifp);
if_alloc_sadl(ifp);
-/* $OpenBSD: if_trunk.c,v 1.153 2023/12/22 23:01:50 mvs Exp $ */
+/* $OpenBSD: if_trunk.c,v 1.154 2023/12/23 10:52:54 bluhm Exp $ */
/*
* Copyright (c) 2005, 2006, 2007 Reyk Floeter <reyk@openbsd.org>
* Attach as an ordinary ethernet device, children will be attached
* as special device IFT_IEEE8023ADLAG.
*/
+ if_counters_alloc(ifp);
if_attach(ifp);
ether_ifattach(ifp);
-/* $OpenBSD: if_tun.c,v 1.239 2023/12/22 23:01:50 mvs Exp $ */
+/* $OpenBSD: if_tun.c,v 1.240 2023/12/23 10:52:54 bluhm Exp $ */
/* $NetBSD: if_tun.c,v 1.24 1996/05/07 02:40:48 thorpej Exp $ */
/*
ifp->if_hardmtu = TUNMRU;
ifp->if_link_state = LINK_STATE_DOWN;
+ if_counters_alloc(ifp);
+
if ((flags & TUN_LAYER2) == 0) {
#if NBPFILTER > 0
ifp->if_bpf_mtap = bpf_mtap;
-/* $OpenBSD: if_var.h,v 1.131 2023/12/22 23:01:50 mvs Exp $ */
+/* $OpenBSD: if_var.h,v 1.132 2023/12/23 10:52:54 bluhm Exp $ */
/* $NetBSD: if.h,v 1.23 1996/05/07 02:40:27 thorpej Exp $ */
/*
int if_rxr_ioctl(struct if_rxrinfo *, const char *, u_int,
struct if_rxring *);
+void if_counters_alloc(struct ifnet *);
+void if_counters_free(struct ifnet *);
+
int if_txhprio_l2_check(int);
int if_txhprio_l3_check(int);
int if_rxhprio_l2_check(int);
-/* $OpenBSD: if_veb.c,v 1.33 2023/12/22 23:01:50 mvs Exp $ */
+/* $OpenBSD: if_veb.c,v 1.34 2023/12/23 10:52:54 bluhm Exp $ */
/*
* Copyright (c) 2021 David Gwynne <dlg@openbsd.org>
ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
ifp->if_xflags = IFXF_CLONED | IFXF_MPSAFE;
+ if_counters_alloc(ifp);
if_attach(ifp);
if_alloc_sadl(ifp);
ifp->if_xflags = IFXF_CLONED | IFXF_MPSAFE;
ether_fakeaddr(ifp);
+ if_counters_alloc(ifp);
if_attach(ifp);
ether_ifattach(ifp);
-/* $OpenBSD: if_vlan.c,v 1.217 2023/12/22 23:01:50 mvs Exp $ */
+/* $OpenBSD: if_vlan.c,v 1.218 2023/12/23 10:52:54 bluhm Exp $ */
/*
* Copyright 1998 Massachusetts Institute of Technology
ifp->if_hardmtu = 0xffff;
ifp->if_link_state = LINK_STATE_DOWN;
+ if_counters_alloc(ifp);
if_attach(ifp);
ether_ifattach(ifp);
ifp->if_hdrlen = EVL_ENCAPLEN;
-/* $OpenBSD: if_vxlan.c,v 1.98 2023/12/22 23:01:50 mvs Exp $ */
+/* $OpenBSD: if_vxlan.c,v 1.99 2023/12/23 10:52:54 bluhm Exp $ */
/*
* Copyright (c) 2021 David Gwynne <dlg@openbsd.org>
ifp->if_xflags = IFXF_CLONED | IFXF_MPSAFE;
ether_fakeaddr(ifp);
+ if_counters_alloc(ifp);
if_attach(ifp);
ether_ifattach(ifp);
-/* $OpenBSD: if_wg.c,v 1.33 2023/12/22 23:01:50 mvs Exp $ */
+/* $OpenBSD: if_wg.c,v 1.34 2023/12/23 10:52:54 bluhm Exp $ */
/*
* Copyright (C) 2015-2020 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
if_attach(ifp);
if_alloc_sadl(ifp);
+ if_counters_alloc(ifp);
#if NBPFILTER > 0
bpfattach(&ifp->if_bpf, ifp, DLT_LOOP, sizeof(uint32_t));
-/* $OpenBSD: ip_carp.c,v 1.359 2023/12/22 23:01:50 mvs Exp $ */
+/* $OpenBSD: ip_carp.c,v 1.360 2023/12/23 10:52:54 bluhm Exp $ */
/*
* Copyright (c) 2002 Michael Shalayeff. All rights reserved.
ifp->if_start = carp_start;
ifp->if_enqueue = carp_enqueue;
ifp->if_xflags = IFXF_CLONED;
+ if_counters_alloc(ifp);
if_attach(ifp);
ether_ifattach(ifp);
ifp->if_type = IFT_CARP;