summaryrefslogtreecommitdiff
path: root/sys/net
diff options
context:
space:
mode:
authorMartin Pieuchot <mpi@cvs.openbsd.org>2015-10-22 17:19:39 +0000
committerMartin Pieuchot <mpi@cvs.openbsd.org>2015-10-22 17:19:39 +0000
commitfc19a686339eb476057c8b3b989db339efea3f4c (patch)
treeba852253c2f461f23d56b3539c8669e49b403d63 /sys/net
parent2edfccc2dfab288140ad019eedf2f35b3bf81d2d (diff)
Use only one refcounting mechanism for route entries.
ok bluhm@, dlg@, claudio@
Diffstat (limited to 'sys/net')
-rw-r--r--sys/net/route.c15
-rw-r--r--sys/net/rtable.c8
-rw-r--r--sys/net/rtable.h4
-rw-r--r--sys/net/rtsock.c5
4 files changed, 16 insertions, 16 deletions
diff --git a/sys/net/route.c b/sys/net/route.c
index c71cc910153..e49e7aa2097 100644
--- a/sys/net/route.c
+++ b/sys/net/route.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: route.c,v 1.257 2015/10/22 16:49:26 mpi Exp $ */
+/* $OpenBSD: route.c,v 1.258 2015/10/22 17:19:38 mpi Exp $ */
/* $NetBSD: route.c,v 1.14 1996/02/13 22:00:46 christos Exp $ */
/*
@@ -348,13 +348,9 @@ rtfree(struct rtentry *rt)
if (rt == NULL)
return;
- rt->rt_refcnt--;
-
- if (rt->rt_refcnt <= 0 && (rt->rt_flags & RTF_UP) == 0) {
- if (rt->rt_refcnt == 0 && RT_ACTIVE(rt))
- return; /* route still active but currently down */
- if (RT_ACTIVE(rt) || RT_ROOT(rt))
- panic("rtfree 2");
+ if (--rt->rt_refcnt <= 0) {
+ KASSERT(!ISSET(rt->rt_flags, RTF_UP));
+ KASSERT(!RT_ROOT(rt));
rttrash--;
if (rt->rt_refcnt < 0) {
printf("rtfree: %p not freed (neg refs)\n", rt);
@@ -846,6 +842,7 @@ rtrequest1(int req, struct rt_addrinfo *info, u_int8_t prio,
return (ENOBUFS);
}
+ rt->rt_refcnt = 1;
rt->rt_flags = info->rti_flags | RTF_UP;
rt->rt_tableid = tableid;
rt->rt_priority = prio; /* init routing priority */
@@ -931,7 +928,7 @@ rtrequest1(int req, struct rt_addrinfo *info, u_int8_t prio,
rt->rt_rmx = (*ret_nrt)->rt_rmx; /* copy metrics */
rt->rt_priority = (*ret_nrt)->rt_priority;
rt->rt_parent = *ret_nrt; /* Back ptr. to parent. */
- rt->rt_parent->rt_refcnt++;
+ rtref(rt->rt_parent);
}
/*
diff --git a/sys/net/rtable.c b/sys/net/rtable.c
index ae13f2ff0a5..dfbdc6975bb 100644
--- a/sys/net/rtable.c
+++ b/sys/net/rtable.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rtable.c,v 1.13 2015/10/21 08:47:01 mpi Exp $ */
+/* $OpenBSD: rtable.c,v 1.14 2015/10/22 17:19:38 mpi Exp $ */
/*
* Copyright (c) 2014-2015 Martin Pieuchot
@@ -329,6 +329,9 @@ rtable_delete(unsigned int rtableid, struct sockaddr *dst,
if (rn->rn_flags & (RNF_ACTIVE | RNF_ROOT))
panic("active node flags=%x", rn->rn_flags);
+ rt = ((struct rtentry *)rn);
+ rtfree(rt);
+
return (0);
}
@@ -654,7 +657,8 @@ rtable_delete(unsigned int rtableid, struct sockaddr *dst,
rt->rt_node = NULL;
rt->rt_mask = NULL;
LIST_REMOVE(rt, rt_next);
- KASSERT(rt->rt_refcnt >= 0);
+ KASSERT(rt->rt_refcnt >= 1);
+ rtfree(rt);
#ifndef SMALL_KERNEL
if ((rt = LIST_FIRST(&an->an_rtlist)) != NULL) {
diff --git a/sys/net/rtable.h b/sys/net/rtable.h
index 66c62000957..678d0e7940f 100644
--- a/sys/net/rtable.h
+++ b/sys/net/rtable.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: rtable.h,v 1.6 2015/10/07 11:39:49 mpi Exp $ */
+/* $OpenBSD: rtable.h,v 1.7 2015/10/22 17:19:38 mpi Exp $ */
/*
* Copyright (c) 2014-2015 Martin Pieuchot
@@ -31,7 +31,6 @@
#define rt_key(rt) (((struct sockaddr *)(rt)->rt_nodes[0].rn_key))
#define rt_mask(rt) (((struct sockaddr *)(rt)->rt_nodes[0].rn_mask))
-#define RT_ACTIVE(rt) ((rt)->rt_nodes[0].rn_flags & RNF_ACTIVE)
#define RT_ROOT(rt) ((rt)->rt_nodes[0].rn_flags & RNF_ROOT)
#else /* ART */
@@ -44,7 +43,6 @@
#define rt_key(rt) ((rt)->rt_dest)
#define rt_mask(rt) ((rt)->rt_mask)
-#define RT_ACTIVE(rt) ((rt)->rt_node != NULL)
#define RT_ROOT(rt) (0)
#endif /* ART */
diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c
index 15448a3fa93..4f7d6261fac 100644
--- a/sys/net/rtsock.c
+++ b/sys/net/rtsock.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rtsock.c,v 1.172 2015/10/22 15:37:47 bluhm Exp $ */
+/* $OpenBSD: rtsock.c,v 1.173 2015/10/22 17:19:38 mpi Exp $ */
/* $NetBSD: rtsock.c,v 1.18 1996/03/29 00:32:10 cgd Exp $ */
/*
@@ -1246,7 +1246,8 @@ sysctl_dumpentry(struct rtentry *rt, void *v, unsigned int id)
rtm->rtm_flags = rt->rt_flags;
rtm->rtm_priority = rt->rt_priority & RTP_MASK;
rt_getmetrics(&rt->rt_rmx, &rtm->rtm_rmx);
- rtm->rtm_rmx.rmx_refcnt = rt->rt_refcnt;
+ /* Do not account the routing table's reference. */
+ rtm->rtm_rmx.rmx_refcnt = rt->rt_refcnt - 1;
rtm->rtm_index = rt->rt_ifp->if_index;
rtm->rtm_addrs = info.rti_addrs;
rtm->rtm_tableid = id;