summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKlemens Nanni <kn@cvs.openbsd.org>2023-06-28 11:49:50 +0000
committerKlemens Nanni <kn@cvs.openbsd.org>2023-06-28 11:49:50 +0000
commit812b56460473ca2f4b3f38cd0ff1e9c8e7a3bae6 (patch)
tree8d8a6967d2941c25ea991ce9d7fb614743345cc8
parent552589a2e6e87e68d0bb6e929b8053561289de19 (diff)
use refcnt API for multicast addresses, add tracepoint:refcnt:ifmaddr probe
Replace hand-rolled reference counting with refcnt_init(9) and hook it up with a new dt(4) probe. OK bluhm mvs
-rw-r--r--sys/dev/dt/dt_prov_static.c4
-rw-r--r--sys/net/if_var.h4
-rw-r--r--sys/netinet/in.c8
-rw-r--r--sys/netinet6/in6.c8
-rw-r--r--sys/sys/refcnt.h9
5 files changed, 18 insertions, 15 deletions
diff --git a/sys/dev/dt/dt_prov_static.c b/sys/dev/dt/dt_prov_static.c
index 5bd926dfbcf..e446844f575 100644
--- a/sys/dev/dt/dt_prov_static.c
+++ b/sys/dev/dt/dt_prov_static.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dt_prov_static.c,v 1.18 2023/04/28 20:03:13 mvs Exp $ */
+/* $OpenBSD: dt_prov_static.c,v 1.19 2023/06/28 11:49:49 kn Exp $ */
/*
* Copyright (c) 2019 Martin Pieuchot <mpi@openbsd.org>
@@ -93,6 +93,7 @@ DT_STATIC_PROBE2(smr, thread, "uint64_t", "uint64_t");
*/
DT_STATIC_PROBE0(refcnt, none);
DT_STATIC_PROBE3(refcnt, ifaddr, "void *", "int", "int");
+DT_STATIC_PROBE3(refcnt, ifmaddr, "void *", "int", "int");
DT_STATIC_PROBE3(refcnt, inpcb, "void *", "int", "int");
DT_STATIC_PROBE3(refcnt, rtentry, "void *", "int", "int");
DT_STATIC_PROBE3(refcnt, tdb, "void *", "int", "int");
@@ -140,6 +141,7 @@ struct dt_probe *const dtps_static[] = {
/* refcnt */
&_DT_STATIC_P(refcnt, none),
&_DT_STATIC_P(refcnt, ifaddr),
+ &_DT_STATIC_P(refcnt, ifmaddr),
&_DT_STATIC_P(refcnt, inpcb),
&_DT_STATIC_P(refcnt, rtentry),
&_DT_STATIC_P(refcnt, tdb),
diff --git a/sys/net/if_var.h b/sys/net/if_var.h
index 4152d3a3704..a4eabc52ca0 100644
--- a/sys/net/if_var.h
+++ b/sys/net/if_var.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_var.h,v 1.127 2023/05/30 08:30:01 jsg Exp $ */
+/* $OpenBSD: if_var.h,v 1.128 2023/06/28 11:49:49 kn Exp $ */
/* $NetBSD: if.h,v 1.23 1996/05/07 02:40:27 thorpej Exp $ */
/*
@@ -255,7 +255,7 @@ struct ifaddr {
struct ifmaddr {
struct sockaddr *ifma_addr; /* Protocol address */
unsigned int ifma_ifidx; /* Index of the interface */
- unsigned int ifma_refcnt; /* Count of references */
+ struct refcnt ifma_refcnt; /* Count of references */
TAILQ_ENTRY(ifmaddr) ifma_list; /* Per-interface list */
};
diff --git a/sys/netinet/in.c b/sys/netinet/in.c
index 624c67db34f..d2207b3e124 100644
--- a/sys/netinet/in.c
+++ b/sys/netinet/in.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: in.c,v 1.184 2023/04/24 12:11:56 kn Exp $ */
+/* $OpenBSD: in.c,v 1.185 2023/06/28 11:49:49 kn Exp $ */
/* $NetBSD: in.c,v 1.26 1996/02/13 23:41:39 christos Exp $ */
/*
@@ -839,7 +839,7 @@ in_addmulti(struct in_addr *ap, struct ifnet *ifp)
/*
* Found it; just increment the reference count.
*/
- ++inm->inm_refcnt;
+ refcnt_take(&inm->inm_refcnt);
} else {
/*
* New address; allocate a new multicast record
@@ -849,7 +849,7 @@ in_addmulti(struct in_addr *ap, struct ifnet *ifp)
inm->inm_sin.sin_len = sizeof(struct sockaddr_in);
inm->inm_sin.sin_family = AF_INET;
inm->inm_sin.sin_addr = *ap;
- inm->inm_refcnt = 1;
+ refcnt_init_trace(&inm->inm_refcnt, DT_REFCNT_IDX_IFMADDR);
inm->inm_ifidx = ifp->if_index;
inm->inm_ifma.ifma_addr = sintosa(&inm->inm_sin);
@@ -890,7 +890,7 @@ in_delmulti(struct in_multi *inm)
NET_ASSERT_LOCKED();
- if (--inm->inm_refcnt != 0)
+ if (refcnt_rele(&inm->inm_refcnt) == 0)
return;
ifp = if_get(inm->inm_ifidx);
diff --git a/sys/netinet6/in6.c b/sys/netinet6/in6.c
index 3651a5f23f6..1266354e202 100644
--- a/sys/netinet6/in6.c
+++ b/sys/netinet6/in6.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: in6.c,v 1.261 2023/04/21 00:41:13 kn Exp $ */
+/* $OpenBSD: in6.c,v 1.262 2023/06/28 11:49:49 kn Exp $ */
/* $KAME: in6.c,v 1.372 2004/06/14 08:14:21 itojun Exp $ */
/*
@@ -1032,7 +1032,7 @@ in6_addmulti(struct in6_addr *maddr6, struct ifnet *ifp, int *errorp)
/*
* Found it; just increment the reference count.
*/
- in6m->in6m_refcnt++;
+ refcnt_take(&in6m->in6m_refcnt);
} else {
/*
* New address; allocate a new multicast record
@@ -1047,7 +1047,7 @@ in6_addmulti(struct in6_addr *maddr6, struct ifnet *ifp, int *errorp)
in6m->in6m_sin.sin6_len = sizeof(struct sockaddr_in6);
in6m->in6m_sin.sin6_family = AF_INET6;
in6m->in6m_sin.sin6_addr = *maddr6;
- in6m->in6m_refcnt = 1;
+ refcnt_init_trace(&in6m->in6m_refcnt, DT_REFCNT_IDX_IFMADDR);
in6m->in6m_ifidx = ifp->if_index;
in6m->in6m_ifma.ifma_addr = sin6tosa(&in6m->in6m_sin);
@@ -1088,7 +1088,7 @@ in6_delmulti(struct in6_multi *in6m)
NET_ASSERT_LOCKED();
- if (--in6m->in6m_refcnt == 0) {
+ if (refcnt_rele(&in6m->in6m_refcnt) != 0) {
/*
* No remaining claims to this record; let MLD6 know
* that we are leaving the multicast group.
diff --git a/sys/sys/refcnt.h b/sys/sys/refcnt.h
index 447973817f4..47a40f61bef 100644
--- a/sys/sys/refcnt.h
+++ b/sys/sys/refcnt.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: refcnt.h,v 1.9 2023/04/28 20:03:14 mvs Exp $ */
+/* $OpenBSD: refcnt.h,v 1.10 2023/06/28 11:49:49 kn Exp $ */
/*
* Copyright (c) 2015 David Gwynne <dlg@openbsd.org>
@@ -45,9 +45,10 @@ unsigned int refcnt_read(struct refcnt *);
/* sorted alphabetically, keep in sync with dev/dt/dt_prov_static.c */
#define DT_REFCNT_IDX_IFADDR 1
-#define DT_REFCNT_IDX_INPCB 2
-#define DT_REFCNT_IDX_RTENTRY 3
-#define DT_REFCNT_IDX_TDB 4
+#define DT_REFCNT_IDX_IFMADDR 2
+#define DT_REFCNT_IDX_INPCB 3
+#define DT_REFCNT_IDX_RTENTRY 4
+#define DT_REFCNT_IDX_TDB 5
#endif /* _KERNEL */