summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
Diffstat (limited to 'sys')
-rw-r--r--sys/net/route.c17
-rw-r--r--sys/net/route.h37
-rw-r--r--sys/net/rtsock.c4
-rw-r--r--sys/netinet/if_atm.c2
-rw-r--r--sys/netinet/if_ether.c2
-rw-r--r--sys/netinet/ip_dummynet.c4
-rw-r--r--sys/netinet/ip_flow.c2
-rw-r--r--sys/netinet/ip_input.c2
-rw-r--r--sys/netinet6/in6.c2
-rw-r--r--sys/netinet6/ip6_output.c2
-rw-r--r--sys/netinet6/nd6.c4
-rw-r--r--sys/netinet6/nd6_rtr.c6
12 files changed, 48 insertions, 36 deletions
diff --git a/sys/net/route.c b/sys/net/route.c
index 75fcde9..648fa32 100644
--- a/sys/net/route.c
+++ b/sys/net/route.c
@@ -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 @@ bad:
* 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);
diff --git a/sys/net/route.h b/sys/net/route.h
index 2c60780..54f706d 100644
--- a/sys/net/route.h
+++ b/sys/net/route.h
@@ -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];
diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c
index 484bfe8..ffde557 100644
--- a/sys/net/rtsock.c
+++ b/sys/net/rtsock.c
@@ -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) {
diff --git a/sys/netinet/if_atm.c b/sys/netinet/if_atm.c
index 5a9e53e..b19502a 100644
--- a/sys/netinet/if_atm.c
+++ b/sys/netinet/if_atm.c
@@ -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? */
diff --git a/sys/netinet/if_ether.c b/sys/netinet/if_ether.c
index b6dafe7..c5238cf 100644
--- a/sys/netinet/if_ether.c
+++ b/sys/netinet/if_ether.c
@@ -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);
}
diff --git a/sys/netinet/ip_dummynet.c b/sys/netinet/ip_dummynet.c
index 3a9c99c..7a37677 100644
--- a/sys/netinet/ip_dummynet.c
+++ b/sys/netinet/ip_dummynet.c
@@ -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 */
diff --git a/sys/netinet/ip_flow.c b/sys/netinet/ip_flow.c
index 25b8fce..a1e8743 100644
--- a/sys/netinet/ip_flow.c
+++ b/sys/netinet/ip_flow.c
@@ -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;
/*
diff --git a/sys/netinet/ip_input.c b/sys/netinet/ip_input.c
index 2f2dc96..f09c477 100644
--- a/sys/netinet/ip_input.c
+++ b/sys/netinet/ip_input.c
@@ -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(); \
diff --git a/sys/netinet6/in6.c b/sys/netinet6/in6.c
index ae01112..e8e8652 100644
--- a/sys/netinet6/in6.c
+++ b/sys/netinet6/in6.c
@@ -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);
}
}
diff --git a/sys/netinet6/ip6_output.c b/sys/netinet6/ip6_output.c
index 1885bc3..9cc55bb 100644
--- a/sys/netinet6/ip6_output.c
+++ b/sys/netinet6/ip6_output.c
@@ -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
diff --git a/sys/netinet6/nd6.c b/sys/netinet6/nd6.c
index 192b4ea..cceb885 100644
--- a/sys/netinet6/nd6.c
+++ b/sys/netinet6/nd6.c
@@ -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? */
diff --git a/sys/netinet6/nd6_rtr.c b/sys/netinet6/nd6_rtr.c
index 858b5da..ef2c90b 100644
--- a/sys/netinet6/nd6_rtr.c
+++ b/sys/netinet6/nd6_rtr.c
@@ -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);
}
OpenPOWER on IntegriCloud