Index: head/sys/net/route.c =================================================================== --- head/sys/net/route.c +++ head/sys/net/route.c @@ -439,39 +439,8 @@ RT_LOCK_ASSERT(rt); - /* - * The callers should use RTFREE_LOCKED() or RTFREE(), so - * we should come here exactly with the last reference. - */ - RT_REMREF(rt); - if (rt->rt_refcnt > 0) { - log(LOG_DEBUG, "%s: %p has %d refs\n", __func__, rt, rt->rt_refcnt); - goto done; - } - - /* - * If we are no longer "up" (and ref == 0) - * then we can free the resources associated - * with the route. - */ - if ((rt->rt_flags & RTF_UP) == 0) { - if (rt->rt_nodes->rn_flags & (RNF_ACTIVE | RNF_ROOT)) - panic("rtfree 2"); -#ifdef DIAGNOSTIC - if (rt->rt_refcnt < 0) { - printf("rtfree: %p not freed (neg refs)\n", rt); - goto done; - } -#endif - epoch_call(net_epoch_preempt, destroy_rtentry_epoch, - &rt->rt_epoch_ctx); - - /* - * FALLTHROUGH to RT_UNLOCK() so the reporting functions - * have consistent behaviour of operating on unlocked entry. - */ - } -done: + epoch_call(net_epoch_preempt, destroy_rtentry_epoch, + &rt->rt_epoch_ctx); RT_UNLOCK(rt); } @@ -958,7 +927,7 @@ if (report) rt_routemsg(RTM_DELETE, rt, rt->rt_nhop->nh_ifp, 0, fibnum); - RTFREE_LOCKED(rt); + rtfree(rt); } } @@ -1114,7 +1083,6 @@ rt = RNTORT(rn); RT_LOCK(rt); - RT_ADDREF(rt); rt->rt_flags &= ~RTF_UP; *perror = 0; @@ -1569,8 +1537,10 @@ } RIB_WUNLOCK(rnh); - if (rt_old != NULL) - RT_UNLOCK(rt_old); + if (rt_old != NULL) { + rt_notifydelete(rt_old, info); + rtfree(rt_old); + } /* * If it still failed to go into the tree, @@ -1582,11 +1552,6 @@ return (EEXIST); } - if (rt_old != NULL) { - rt_notifydelete(rt_old, info); - RTFREE(rt_old); - } - /* * If this protocol has something to add to this then * allow it to do that as well. @@ -1639,7 +1604,7 @@ if (ret_nrt) *ret_nrt = rt; - RTFREE_LOCKED(rt); + rtfree(rt); return (0); } Index: head/sys/net/route/route_var.h =================================================================== --- head/sys/net/route/route_var.h +++ head/sys/net/route/route_var.h @@ -143,7 +143,6 @@ }; int rt_flags; /* up/down?, host/net */ - int rt_refcnt; /* # held references */ u_long rt_weight; /* absolute weight */ u_long rt_expire; /* lifetime for route, e.g. redirect */ #define rt_endzero rt_mtx @@ -161,36 +160,6 @@ #define RT_UNLOCK_COND(_rt) do { \ if (mtx_owned(&(_rt)->rt_mtx)) \ mtx_unlock(&(_rt)->rt_mtx); \ -} while (0) - -#define RT_ADDREF(_rt) do { \ - RT_LOCK_ASSERT(_rt); \ - KASSERT((_rt)->rt_refcnt >= 0, \ - ("negative refcnt %d", (_rt)->rt_refcnt)); \ - (_rt)->rt_refcnt++; \ -} while (0) - -#define RT_REMREF(_rt) do { \ - RT_LOCK_ASSERT(_rt); \ - KASSERT((_rt)->rt_refcnt > 0, \ - ("bogus refcnt %d", (_rt)->rt_refcnt)); \ - (_rt)->rt_refcnt--; \ -} while (0) - -#define RTFREE_LOCKED(_rt) do { \ - if ((_rt)->rt_refcnt <= 1) \ - rtfree(_rt); \ - else { \ - RT_REMREF(_rt); \ - RT_UNLOCK(_rt); \ - } \ - /* guard against invalid refs */ \ - _rt = 0; \ -} while (0) - -#define RTFREE(_rt) do { \ - RT_LOCK(_rt); \ - RTFREE_LOCKED(_rt); \ } while (0) /*