On Sat, Feb 06, 2021 at 04:44:08PM +0100, Alexander Bluhm wrote: > Or should we go with a self crafted ++ -- refcounting?
This would look like this, also fine with me. kasserts are also in refcnt_... API. ok? bluhm Index: net/if.c =================================================================== RCS file: /data/mirror/openbsd/cvs/src/sys/net/if.c,v retrieving revision 1.626 diff -u -p -r1.626 if.c --- net/if.c 1 Feb 2021 07:43:33 -0000 1.626 +++ net/if.c 6 Feb 2021 16:26:51 -0000 @@ -2601,7 +2601,7 @@ if_creategroup(const char *groupname) return (NULL); strlcpy(ifg->ifg_group, groupname, sizeof(ifg->ifg_group)); - ifg->ifg_refcnt = 0; + ifg->ifg_refcnt = 1; ifg->ifg_carp_demoted = 0; TAILQ_INIT(&ifg->ifg_members); #if NPF > 0 @@ -2642,13 +2642,18 @@ if_addgroup(struct ifnet *ifp, const cha if (!strcmp(ifg->ifg_group, groupname)) break; - if (ifg == NULL && (ifg = if_creategroup(groupname)) == NULL) { + if (ifg == NULL) + ifg = if_creategroup(groupname); + else + ifg->ifg_refcnt++; + KASSERT(ifg->ifg_refcnt != 0); + + if (ifg == NULL) { free(ifgl, M_TEMP, sizeof(*ifgl)); free(ifgm, M_TEMP, sizeof(*ifgm)); return (ENOMEM); } - ifg->ifg_refcnt++; ifgl->ifgl_group = ifg; ifgm->ifgm_ifp = ifp; @@ -2692,6 +2697,7 @@ if_delgroup(struct ifnet *ifp, const cha pfi_group_change(groupname); #endif + KASSERT(ifgl->ifgl_group->ifg_refcnt != 0); if (--ifgl->ifgl_group->ifg_refcnt == 0) { TAILQ_REMOVE(&ifg_head, ifgl->ifgl_group, ifg_next); #if NPF > 0 Index: netinet/ip_carp.c =================================================================== RCS file: /data/mirror/openbsd/cvs/src/sys/netinet/ip_carp.c,v retrieving revision 1.351 diff -u -p -r1.351 ip_carp.c --- netinet/ip_carp.c 21 Jan 2021 13:18:07 -0000 1.351 +++ netinet/ip_carp.c 6 Feb 2021 14:45:34 -0000 @@ -786,10 +786,7 @@ carp_sysctl(int *name, u_int namelen, vo void carpattach(int n) { - struct ifg_group *ifg; - - if ((ifg = if_creategroup("carp")) != NULL) - ifg->ifg_refcnt++; /* keep around even if empty */ + if_creategroup("carp"); /* keep around even if empty */ if_clone_attach(&carp_cloner); carpcounters = counters_alloc(carps_ncounters); }