aboutsummaryrefslogtreecommitdiff
path: root/sys/net/rtsock.c
diff options
context:
space:
mode:
authorSam Leffler <sam@FreeBSD.org>2003-10-04 03:44:50 +0000
committerSam Leffler <sam@FreeBSD.org>2003-10-04 03:44:50 +0000
commitd1dd20be6e083b93b09d4a34c292fc935aa2a225 (patch)
tree7bd40aa381e3ec3f09e84ae6cc70b74bf5683aa2 /sys/net/rtsock.c
parentc303328741662e0c1e59c9a0ad267c212567c8bc (diff)
downloadsrc-d1dd20be6e083b93b09d4a34c292fc935aa2a225.tar.gz
src-d1dd20be6e083b93b09d4a34c292fc935aa2a225.zip
Locking for updates to routing table entries. Each rtentry gets a mutex
that covers updates to the contents. Note this is separate from holding a reference and/or locking the routing table itself. Other/related changes: o rtredirect loses the final parameter by which an rtentry reference may be returned; this was never used and added unwarranted complexity for locking. o minor style cleanups to routing code (e.g. ansi-fy function decls) o remove the logic to bump the refcnt on the parent of cloned routes, we assume the parent will remain as long as the clone; doing this avoids a circularity in locking during delete o convert some timeouts to MPSAFE callouts Notes: 1. rt_mtx in struct rtentry is guarded by #ifdef _KERNEL as user-level applications cannot/do-no know about mutex's. Doing this requires that the mutex be the last element in the structure. A better solution is to introduce an externalized version of struct rtentry but this is a major task because of the intertwining of rtentry and other data structures that are visible to user applications. 2. There are known LOR's that are expected to go away with forthcoming work to eliminate many held references. If not these will be resolved prior to release. 3. ATM changes are untested. Sponsored by: FreeBSD Foundation Obtained from: BSD/OS (partly)
Notes
Notes: svn path=/head/; revision=120727
Diffstat (limited to 'sys/net/rtsock.c')
-rw-r--r--sys/net/rtsock.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c
index 4af77ecf4cfe..201e4a9630ca 100644
--- a/sys/net/rtsock.c
+++ b/sys/net/rtsock.c
@@ -351,6 +351,7 @@ route_output(m, so)
saved_nrt = 0;
error = rtrequest1(RTM_ADD, &info, &saved_nrt);
if (error == 0 && saved_nrt) {
+ RT_LOCK(saved_nrt);
rt_setmetrics(rtm->rtm_inits,
&rtm->rtm_rmx, &saved_nrt->rt_rmx);
saved_nrt->rt_rmx.rmx_locks &= ~(rtm->rtm_inits);
@@ -358,6 +359,7 @@ route_output(m, so)
(rtm->rtm_inits & rtm->rtm_rmx.rmx_locks);
saved_nrt->rt_refcnt--;
saved_nrt->rt_genmask = info.rti_info[RTAX_GENMASK];
+ RT_UNLOCK(saved_nrt);
}
break;
@@ -365,6 +367,7 @@ route_output(m, so)
saved_nrt = 0;
error = rtrequest1(RTM_DELETE, &info, &saved_nrt);
if (error == 0) {
+ RT_LOCK(saved_nrt);
rt = saved_nrt;
goto report;
}
@@ -382,12 +385,14 @@ route_output(m, so)
RADIX_NODE_HEAD_UNLOCK(rnh);
if (rt == NULL) /* XXX looks bogus */
senderr(ESRCH);
+ RT_LOCK(rt);
rt->rt_refcnt++;
switch(rtm->rtm_type) {
case RTM_GET:
report:
+ RT_LOCK_ASSERT(rt);
info.rti_info[RTAX_DST] = rt_key(rt);
info.rti_info[RTAX_GATEWAY] = rt->rt_gateway;
info.rti_info[RTAX_NETMASK] = rt_mask(rt);
@@ -413,6 +418,7 @@ route_output(m, so)
struct rt_msghdr *new_rtm;
R_Malloc(new_rtm, struct rt_msghdr *, len);
if (new_rtm == 0) {
+ RT_UNLOCK(rt);
senderr(ENOBUFS);
}
Bcopy(rtm, new_rtm, rtm->rtm_msglen);
@@ -438,12 +444,14 @@ route_output(m, so)
!sa_equal(info.rti_info[RTAX_IFA],
rt->rt_ifa->ifa_addr))) {
if ((error = rt_getifa(&info)) != 0) {
+ RT_UNLOCK(rt);
senderr(error);
}
}
if (info.rti_info[RTAX_GATEWAY] != NULL &&
(error = rt_setgate(rt, rt_key(rt),
info.rti_info[RTAX_GATEWAY])) != 0) {
+ RT_UNLOCK(rt);
senderr(error);
}
if ((ifa = info.rti_ifa) != NULL) {
@@ -474,6 +482,7 @@ route_output(m, so)
(rtm->rtm_inits & rtm->rtm_rmx.rmx_locks);
break;
}
+ RT_UNLOCK(rt);
break;
default: