Index: route.c =================================================================== RCS file: /cvs/src/sys/net/route.c,v retrieving revision 1.402 diff -u -p -r1.402 route.c --- route.c 22 Feb 2022 01:15:02 -0000 1.402 +++ route.c 18 Mar 2022 12:14:49 -0000 @@ -489,26 +489,19 @@ rt_putgwroute(struct rtentry *rt) void rtref(struct rtentry *rt) { - atomic_inc_int(&rt->rt_refcnt); + refcnt_take(&rt->rt_refcnt); } void rtfree(struct rtentry *rt) { - int refcnt; - if (rt == NULL) return; - refcnt = (int)atomic_dec_int_nv(&rt->rt_refcnt); - if (refcnt <= 0) { + if (refcnt_rele(&rt->rt_refcnt)) { KASSERT(!ISSET(rt->rt_flags, RTF_UP)); KASSERT(!RT_ROOT(rt)); atomic_dec_int(&rttrash); - if (refcnt < 0) { - printf("rtfree: %p not freed (neg refs)\n", rt); - return; - } KERNEL_LOCK(); rt_timer_remove_all(rt); @@ -878,7 +871,7 @@ rtrequest(int req, struct rt_addrinfo *i return (ENOBUFS); } - rt->rt_refcnt = 1; + refcnt_init(&rt->rt_refcnt); rt->rt_flags = info->rti_flags | RTF_UP; rt->rt_priority = prio; /* init routing priority */ LIST_INIT(&rt->rt_timer); @@ -1850,8 +1843,9 @@ db_show_rtentry(struct rtentry *rt, void { db_printf("rtentry=%p", rt); - db_printf(" flags=0x%x refcnt=%d use=%llu expire=%lld rtableid=%u\n", - rt->rt_flags, rt->rt_refcnt, rt->rt_use, rt->rt_expire, id); + db_printf(" flags=0x%x refcnt=%u use=%llu expire=%lld rtableid=%u\n", + rt->rt_flags, refcnt_read(&rt->rt_refcnt), rt->rt_use, + rt->rt_expire, id); db_printf(" key="); db_print_sa(rt_key(rt)); db_printf(" plen=%d", rt_plen(rt)); Index: route.h =================================================================== RCS file: /cvs/src/sys/net/route.h,v retrieving revision 1.187 diff -u -p -r1.187 route.h --- route.h 12 Nov 2021 15:49:41 -0000 1.187 +++ route.h 18 Mar 2022 12:14:49 -0000 @@ -113,7 +113,7 @@ struct rtentry { struct rt_kmetrics rt_rmx; /* metrics used by rx'ing protocols */ unsigned int rt_ifidx; /* the answer: interface to use */ unsigned int rt_flags; /* up/down?, host/net */ - int rt_refcnt; /* # held references */ + struct refcnt rt_refcnt; /* # held references */ int rt_plen; /* prefix length */ uint16_t rt_labelid; /* route label ID */ uint8_t rt_priority; /* routing priority to use */ Index: rtable.c =================================================================== RCS file: /cvs/src/sys/net/rtable.c,v retrieving revision 1.76 diff -u -p -r1.76 rtable.c --- rtable.c 2 Jan 2022 22:36:04 -0000 1.76 +++ rtable.c 18 Mar 2022 12:14:49 -0000 @@ -678,7 +678,7 @@ rtable_delete(unsigned int rtableid, str npaths++; if (npaths > 1) { - KASSERT(rt->rt_refcnt >= 1); + KASSERT(refcnt_read(&rt->rt_refcnt) >= 1); SRPL_REMOVE_LOCKED(&rt_rc, &an->an_rtlist, rt, rtentry, rt_next); @@ -692,7 +692,7 @@ rtable_delete(unsigned int rtableid, str if (art_delete(ar, an, addr, plen) == NULL) panic("art_delete failed to find node %p", an); - KASSERT(rt->rt_refcnt >= 1); + KASSERT(refcnt_read(&rt->rt_refcnt) >= 1); SRPL_REMOVE_LOCKED(&rt_rc, &an->an_rtlist, rt, rtentry, rt_next); art_put(an); Index: rtsock.c =================================================================== RCS file: /cvs/src/sys/net/rtsock.c,v retrieving revision 1.327 diff -u -p -r1.327 rtsock.c --- rtsock.c 9 Mar 2022 17:29:52 -0000 1.327 +++ rtsock.c 18 Mar 2022 12:14:49 -0000 @@ -1993,7 +1993,7 @@ sysctl_dumpentry(struct rtentry *rt, voi rtm->rtm_priority = rt->rt_priority & RTP_MASK; rtm_getmetrics(&rt->rt_rmx, &rtm->rtm_rmx); /* Do not account the routing table's reference. */ - rtm->rtm_rmx.rmx_refcnt = rt->rt_refcnt - 1; + rtm->rtm_rmx.rmx_refcnt = refcnt_read(&rt->rt_refcnt) - 1; rtm->rtm_index = rt->rt_ifidx; rtm->rtm_addrs = info.rti_addrs; rtm->rtm_tableid = id;