replace explicit changes to rt_refcnt by RT_ADDREF and RT_REMREF
macros that expand to include assertions when the system is built with INVARIANTS Supported by: FreeBSD Foundation
This commit is contained in:
parent
00bd917263
commit
7138d65c3f
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=122334
@ -154,7 +154,7 @@ rtalloc1(struct sockaddr *dst, int report, u_long ignflags)
|
||||
*/
|
||||
newrt = rt; /* existing route */
|
||||
RT_LOCK(newrt);
|
||||
newrt->rt_refcnt++;
|
||||
RT_ADDREF(newrt);
|
||||
goto miss;
|
||||
}
|
||||
KASSERT(newrt, ("no route and no error"));
|
||||
@ -180,7 +180,7 @@ rtalloc1(struct sockaddr *dst, int report, u_long ignflags)
|
||||
} else {
|
||||
KASSERT(rt == newrt, ("locking wrong route"));
|
||||
RT_LOCK(newrt);
|
||||
newrt->rt_refcnt++;
|
||||
RT_ADDREF(newrt);
|
||||
}
|
||||
RADIX_NODE_HEAD_UNLOCK(rnh);
|
||||
} else {
|
||||
@ -228,7 +228,8 @@ rtfree(struct rtentry *rt)
|
||||
* decrement the reference count by one and if it reaches 0,
|
||||
* and there is a close function defined, call the close function
|
||||
*/
|
||||
if (--rt->rt_refcnt > 0)
|
||||
RT_REMREF(rt);
|
||||
if (rt->rt_refcnt > 0)
|
||||
goto done;
|
||||
|
||||
/*
|
||||
@ -442,7 +443,7 @@ ifa_ifwithroute(int flags, struct sockaddr *dst, struct sockaddr *gateway)
|
||||
struct rtentry *rt = rtalloc1(gateway, 0, 0UL);
|
||||
if (rt == 0)
|
||||
return (0);
|
||||
--rt->rt_refcnt;
|
||||
RT_REMREF(rt);
|
||||
RT_UNLOCK(rt);
|
||||
if ((ifa = rt->rt_ifa) == 0)
|
||||
return (0);
|
||||
@ -661,7 +662,7 @@ rtrequest1(int req, struct rt_addrinfo *info, struct rtentry **ret_nrt)
|
||||
panic ("rtrequest delete");
|
||||
rt = (struct rtentry *)rn;
|
||||
RT_LOCK(rt);
|
||||
rt->rt_refcnt++;
|
||||
RT_ADDREF(rt);
|
||||
rt->rt_flags &= ~RTF_UP;
|
||||
|
||||
/*
|
||||
@ -861,7 +862,7 @@ rtrequest1(int req, struct rt_addrinfo *info, struct rtentry **ret_nrt)
|
||||
*/
|
||||
if (ret_nrt) {
|
||||
*ret_nrt = rt;
|
||||
rt->rt_refcnt++;
|
||||
RT_ADDREF(rt);
|
||||
}
|
||||
RT_UNLOCK(rt);
|
||||
break;
|
||||
@ -1229,7 +1230,7 @@ rtinit(struct ifaddr *ifa, int cmd, int flags)
|
||||
* We just wanted to add it.. we don't actually
|
||||
* need a reference.
|
||||
*/
|
||||
rt->rt_refcnt--;
|
||||
RT_REMREF(rt);
|
||||
}
|
||||
RT_UNLOCK(rt);
|
||||
}
|
||||
@ -1269,7 +1270,7 @@ rt_check(struct rtentry **lrt, struct rtentry **lrt0, struct sockaddr *dst)
|
||||
RT_UNLOCK(rt);
|
||||
rt = rtalloc1(dst, 1, 0UL);
|
||||
if (rt != NULL) {
|
||||
rt->rt_refcnt--;
|
||||
RT_REMREF(rt);
|
||||
RT_UNLOCK(rt);
|
||||
} else
|
||||
senderr(EHOSTUNREACH);
|
||||
|
@ -266,19 +266,32 @@ struct rt_addrinfo {
|
||||
#define RT_LOCK_DESTROY(_rt) mtx_destroy(&(_rt)->rt_mtx)
|
||||
#define RT_LOCK_ASSERT(_rt) mtx_assert(&(_rt)->rt_mtx, MA_OWNED)
|
||||
|
||||
#define RTFREE_LOCKED(_rt) do { \
|
||||
if ((_rt)->rt_refcnt <= 1) \
|
||||
rtfree(_rt); \
|
||||
else { \
|
||||
(_rt)->rt_refcnt--; \
|
||||
RT_UNLOCK(_rt); \
|
||||
} \
|
||||
/* guard against invalid refs */ \
|
||||
_rt = 0; \
|
||||
#define RT_ADDREF(_rt) do { \
|
||||
RT_LOCK_ASSERT(_rt); \
|
||||
KASSERT((_rt)->rt_refcnt >= 0, \
|
||||
("negative refcnt %ld", (_rt)->rt_refcnt)); \
|
||||
(_rt)->rt_refcnt++; \
|
||||
} while (0);
|
||||
#define RT_REMREF(_rt) do { \
|
||||
RT_LOCK_ASSERT(_rt); \
|
||||
KASSERT((_rt)->rt_refcnt > 0, \
|
||||
("bogus refcnt %ld", (_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); \
|
||||
#define RTFREE(_rt) do { \
|
||||
RT_LOCK(_rt); \
|
||||
RTFREE_LOCKED(_rt); \
|
||||
} while (0)
|
||||
|
||||
extern struct radix_node_head *rt_tables[AF_MAX+1];
|
||||
|
@ -357,7 +357,7 @@ route_output(m, so)
|
||||
saved_nrt->rt_rmx.rmx_locks &= ~(rtm->rtm_inits);
|
||||
saved_nrt->rt_rmx.rmx_locks |=
|
||||
(rtm->rtm_inits & rtm->rtm_rmx.rmx_locks);
|
||||
saved_nrt->rt_refcnt--;
|
||||
RT_REMREF(saved_nrt);
|
||||
saved_nrt->rt_genmask = info.rti_info[RTAX_GENMASK];
|
||||
RT_UNLOCK(saved_nrt);
|
||||
}
|
||||
@ -386,7 +386,7 @@ route_output(m, so)
|
||||
if (rt == NULL) /* XXX looks bogus */
|
||||
senderr(ESRCH);
|
||||
RT_LOCK(rt);
|
||||
rt->rt_refcnt++;
|
||||
RT_ADDREF(rt);
|
||||
|
||||
switch(rtm->rtm_type) {
|
||||
|
||||
|
@ -320,7 +320,7 @@ atmresolve(struct rtentry *rt, struct mbuf *m, struct sockaddr *dst,
|
||||
rt = RTALLOC1(dst, 0);
|
||||
if (rt == NULL)
|
||||
goto bad; /* failed */
|
||||
rt->rt_refcnt--; /* don't keep LL references */
|
||||
RT_REMREF(rt); /* don't keep LL references */
|
||||
if ((rt->rt_flags & RTF_GATEWAY) != 0 ||
|
||||
(rt->rt_flags & RTF_LLINFO) == 0 ||
|
||||
/* XXX: are we using LLINFO? */
|
||||
|
@ -954,7 +954,7 @@ arplookup(addr, create, proxy)
|
||||
return (0);
|
||||
#undef ISDYNCLONE
|
||||
} else {
|
||||
rt->rt_refcnt--;
|
||||
RT_REMREF(rt);
|
||||
RT_UNLOCK(rt);
|
||||
return ((struct llinfo_arp *)rt->rt_llinfo);
|
||||
}
|
||||
|
@ -1197,9 +1197,7 @@ dummynet_io(struct mbuf *m, int pipe_nr, int dir, struct ip_fw_args *fwa)
|
||||
pkt->ro = *(fwa->ro);
|
||||
if (pkt->ro.ro_rt) {
|
||||
RT_LOCK(pkt->ro.ro_rt);
|
||||
pkt->ro.ro_rt->rt_refcnt++ ;
|
||||
KASSERT(pkt->ro.ro_rt->rt_refcnt > 0,
|
||||
("bogus refcnt %ld", pkt->ro.ro_rt->rt_refcnt));
|
||||
RT_ADDREF(pkt->ro.ro_rt) ;
|
||||
RT_UNLOCK(pkt->ro.ro_rt);
|
||||
}
|
||||
if (fwa->dst == (struct sockaddr_in *)&fwa->ro->ro_dst) /* dst points into ro */
|
||||
|
@ -353,7 +353,7 @@ ipflow_create(const struct route *ro, struct mbuf *m)
|
||||
*/
|
||||
ipf->ipf_ro = *ro;
|
||||
RT_LOCK(ro->ro_rt);
|
||||
ro->ro_rt->rt_refcnt++;
|
||||
RT_ADDREF(ro->ro_rt);
|
||||
RT_UNLOCK(ro->ro_rt);
|
||||
ipf->ipf_timer = IPFLOW_TIMER;
|
||||
/*
|
||||
|
@ -237,7 +237,7 @@ static struct rtcache {
|
||||
*(_ro) = ip_fwdcache.rc_ro; \
|
||||
if ((rt = (_ro)->ro_rt) != NULL) { \
|
||||
RT_LOCK(rt); \
|
||||
rt->rt_refcnt++; \
|
||||
RT_ADDREF(rt); \
|
||||
RT_UNLOCK(rt); \
|
||||
} \
|
||||
RTCACHE_UNLOCK(); \
|
||||
|
@ -197,7 +197,7 @@ in6_ifloop_request(int cmd, struct ifaddr *ifa)
|
||||
rtfree(nrt);
|
||||
} else {
|
||||
/* the cmd must be RTM_ADD here */
|
||||
nrt->rt_refcnt--;
|
||||
RT_REMREF(nrt);
|
||||
RT_UNLOCK(nrt);
|
||||
}
|
||||
}
|
||||
|
@ -2908,7 +2908,7 @@ ip6_setpktoptions(control, opt, stickyopt, priv, needcopy, uproto)
|
||||
*opt = *stickyopt;
|
||||
if (opt->ip6po_nextroute.ro_rt) {
|
||||
RT_LOCK(opt->ip6po_nextroute.ro_rt);
|
||||
opt->ip6po_nextroute.ro_rt->rt_refcnt++;
|
||||
RT_ADDREF(opt->ip6po_nextroute.ro_rt);
|
||||
RT_UNLOCK(opt->ip6po_nextroute.ro_rt);
|
||||
}
|
||||
} else
|
||||
|
@ -838,7 +838,7 @@ nd6_lookup(addr6, create, ifp)
|
||||
return (NULL);
|
||||
}
|
||||
RT_LOCK_ASSERT(rt);
|
||||
rt->rt_refcnt--;
|
||||
RT_REMREF(rt);
|
||||
/*
|
||||
* Validation for the entry.
|
||||
* Note that the check for rt_llinfo is necessary because a cloned
|
||||
@ -1834,7 +1834,7 @@ nd6_output(ifp, origifp, m0, dst, rt0)
|
||||
if ((rt->rt_flags & RTF_UP) == 0) {
|
||||
rt0 = rt = rtalloc1((struct sockaddr *)dst, 1, 0UL);
|
||||
if (rt != NULL) {
|
||||
rt->rt_refcnt--;
|
||||
RT_REMREF(rt);
|
||||
RT_UNLOCK(rt);
|
||||
if (rt->rt_ifp != ifp) {
|
||||
/* XXX: loop care? */
|
||||
|
@ -478,7 +478,7 @@ defrouter_addreq(new)
|
||||
if (newrt) {
|
||||
RT_LOCK(newrt);
|
||||
nd6_rtmsg(RTM_ADD, newrt); /* tell user process */
|
||||
newrt->rt_refcnt--;
|
||||
RT_REMREF(newrt);
|
||||
RT_UNLOCK(newrt);
|
||||
}
|
||||
return;
|
||||
@ -524,7 +524,7 @@ defrouter_addifreq(ifp)
|
||||
if (newrt) {
|
||||
RT_LOCK(newrt);
|
||||
nd6_rtmsg(RTM_ADD, newrt);
|
||||
newrt->rt_refcnt--;
|
||||
RT_REMREF(newrt);
|
||||
RT_UNLOCK(newrt);
|
||||
}
|
||||
}
|
||||
@ -1470,7 +1470,7 @@ nd6_prefix_onlink(pr)
|
||||
|
||||
if (rt != NULL) {
|
||||
RT_LOCK(rt);
|
||||
rt->rt_refcnt--;
|
||||
RT_REMREF(rt);
|
||||
RT_UNLOCK(rt);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user