summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorClaudio Jeker <claudio@cvs.openbsd.org>2015-07-16 18:17:28 +0000
committerClaudio Jeker <claudio@cvs.openbsd.org>2015-07-16 18:17:28 +0000
commite6d6ce9be69ad8242a8dc9b2d22cdaaba84ac614 (patch)
treed9d7684edd938ba72d0fb96e4418f75750217044 /sys
parent3cd32cddfb3af2de65659dbba3328b5cedccdf69 (diff)
Fix rn_match and there for the expoerted lookup functions in radix.c
to never return the internal RNF_ROOT nodes. This removes the checks in the callee to verify that not an RNF_ROOT node was returned. OK mpi@
Diffstat (limited to 'sys')
-rw-r--r--sys/kern/vfs_subr.c4
-rw-r--r--sys/net/pf_table.c17
-rw-r--r--sys/net/radix.c33
-rw-r--r--sys/net/radix_mpath.c4
-rw-r--r--sys/net/route.c5
-rw-r--r--sys/net/rtsock.c8
6 files changed, 30 insertions, 41 deletions
diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c
index 2c1da15cba6..a3ab3ad90b9 100644
--- a/sys/kern/vfs_subr.c
+++ b/sys/kern/vfs_subr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vfs_subr.c,v 1.231 2015/05/12 09:30:35 mikeb Exp $ */
+/* $OpenBSD: vfs_subr.c,v 1.232 2015/07/16 18:17:27 claudio Exp $ */
/* $NetBSD: vfs_subr.c,v 1.53 1996/04/22 01:39:13 christos Exp $ */
/*
@@ -1470,8 +1470,6 @@ vfs_export_lookup(struct mount *mp, struct netexport *nep, struct mbuf *nam)
np = (struct netcred *)
(*rnh->rnh_matchaddr)((caddr_t)saddr,
rnh);
- if (np && np->netc_rnodes->rn_flags & RNF_ROOT)
- np = NULL;
}
}
/*
diff --git a/sys/net/pf_table.c b/sys/net/pf_table.c
index 005d99fe41f..5cc61130438 100644
--- a/sys/net/pf_table.c
+++ b/sys/net/pf_table.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pf_table.c,v 1.109 2015/06/07 12:02:28 jsg Exp $ */
+/* $OpenBSD: pf_table.c,v 1.110 2015/07/16 18:17:27 claudio Exp $ */
/*
* Copyright (c) 2002 Cedric Berger
@@ -94,8 +94,6 @@
#define AF_BITS(af) (((af)==AF_INET)?32:128)
#define ADDR_NETWORK(ad) ((ad)->pfra_net < AF_BITS((ad)->pfra_af))
#define KENTRY_NETWORK(ke) ((ke)->pfrke_net < AF_BITS((ke)->pfrke_af))
-#define KENTRY_RNF_ROOT(ke) \
- ((((struct radix_node *)(ke))->rn_flags & RNF_ROOT) != 0)
#define NO_ADDRESSES (-1)
#define ENQUEUE_UNMARKED_ONLY (1)
@@ -809,12 +807,8 @@ pfr_lookup_addr(struct pfr_ktable *kt, struct pfr_addr *ad, int exact)
s = splsoftnet(); /* rn_lookup makes use of globals */
ke = (struct pfr_kentry *)rn_lookup(&sa, &mask, head);
splx(s);
- if (ke && KENTRY_RNF_ROOT(ke))
- ke = NULL;
} else {
ke = (struct pfr_kentry *)rn_match(&sa, head);
- if (ke && KENTRY_RNF_ROOT(ke))
- ke = NULL;
if (exact && ke && KENTRY_NETWORK(ke))
ke = NULL;
}
@@ -2076,15 +2070,11 @@ pfr_match_addr(struct pfr_ktable *kt, struct pf_addr *a, sa_family_t af)
case AF_INET:
pfr_sin.sin_addr.s_addr = a->addr32[0];
ke = (struct pfr_kentry *)rn_match(&pfr_sin, kt->pfrkt_ip4);
- if (ke && KENTRY_RNF_ROOT(ke))
- ke = NULL;
break;
#ifdef INET6
case AF_INET6:
bcopy(a, &pfr_sin6.sin6_addr, sizeof(pfr_sin6.sin6_addr));
ke = (struct pfr_kentry *)rn_match(&pfr_sin6, kt->pfrkt_ip6);
- if (ke && KENTRY_RNF_ROOT(ke))
- ke = NULL;
break;
#endif /* INET6 */
}
@@ -2115,15 +2105,11 @@ pfr_update_stats(struct pfr_ktable *kt, struct pf_addr *a, struct pf_pdesc *pd,
case AF_INET:
pfr_sin.sin_addr.s_addr = a->addr32[0];
ke = (struct pfr_kentry *)rn_match(&pfr_sin, kt->pfrkt_ip4);
- if (ke && KENTRY_RNF_ROOT(ke))
- ke = NULL;
break;
#ifdef INET6
case AF_INET6:
bcopy(a, &pfr_sin6.sin6_addr, sizeof(pfr_sin6.sin6_addr));
ke = (struct pfr_kentry *)rn_match(&pfr_sin6, kt->pfrkt_ip6);
- if (ke && KENTRY_RNF_ROOT(ke))
- ke = NULL;
break;
#endif /* INET6 */
default:
@@ -2326,7 +2312,6 @@ pfr_pool_get(struct pf_pool *rpool, struct pf_addr **raddr,
else if (af == AF_INET6)
ke2 = (struct pfr_kentry *)rn_match(&pfr_sin6,
kt->pfrkt_ip6);
- /* no need to check KENTRY_RNF_ROOT() here */
if (ke2 == ke) {
/* lookup return the same block - perfect */
if (rpool->addr.type == PF_ADDR_DYNIFTL &&
diff --git a/sys/net/radix.c b/sys/net/radix.c
index 23e44b9c65f..37df8eace75 100644
--- a/sys/net/radix.c
+++ b/sys/net/radix.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: radix.c,v 1.45 2015/07/07 09:39:28 mpi Exp $ */
+/* $OpenBSD: radix.c,v 1.46 2015/07/16 18:17:27 claudio Exp $ */
/* $NetBSD: radix.c,v 1.20 2003/08/07 16:32:56 agc Exp $ */
/*
@@ -261,8 +261,10 @@ rn_match(void *v_arg, struct radix_node_head *head)
* This extra grot is in case we are explicitly asked
* to look up the default. Ugh!
*/
- if ((t->rn_flags & RNF_ROOT) && t->rn_dupedkey)
+ if (t->rn_flags & RNF_ROOT)
t = t->rn_dupedkey;
+
+ KASSERT(t == NULL || (t->rn_flags & RNF_ROOT) == 0);
return t;
on1:
test = (*cp ^ *cp2) & 0xff; /* find first bit that differs */
@@ -284,10 +286,14 @@ on1:
* a route to a net.
*/
if (t->rn_flags & RNF_NORMAL) {
- if (rn_b <= t->rn_b)
- return t;
- } else if (rn_satisfies_leaf(v, t, matched_off))
+ if (rn_b <= t->rn_b) {
+ KASSERT((t->rn_flags & RNF_ROOT) == 0);
return t;
+ }
+ } else if (rn_satisfies_leaf(v, t, matched_off)) {
+ KASSERT((t->rn_flags & RNF_ROOT) == 0);
+ return t;
+ }
t = saved_t;
/* start searching up the tree */
do {
@@ -302,16 +308,21 @@ on1:
* calculation of "off" back before the "do".
*/
if (m->rm_flags & RNF_NORMAL) {
- if (rn_b <= m->rm_b)
+ if (rn_b <= m->rm_b) {
+ KASSERT((m->rm_leaf->rn_flags &
+ RNF_ROOT) == 0);
return (m->rm_leaf);
+ }
} else {
struct radix_node *x;
off = min(t->rn_off, matched_off);
x = rn_search_m(v, t, m->rm_mask);
while (x && x->rn_mask != m->rm_mask)
x = x->rn_dupedkey;
- if (x && rn_satisfies_leaf(v, x, off))
+ if (x && rn_satisfies_leaf(v, x, off)) {
+ KASSERT((x->rn_flags & RNF_ROOT) == 0);
return x;
+ }
}
m = m->rm_mklist;
}
@@ -961,7 +972,7 @@ rn_delete(void *v_arg, void *n_arg, struct radix_node_head *head,
tt = rn_search(v, top);
/* make sure the key is a perfect match */
if (memcmp(v + off, tt->rn_key + off, vlen - off))
- return (0);
+ return (NULL);
/*
* Here, tt is the deletion target, and
@@ -978,11 +989,11 @@ rn_delete(void *v_arg, void *n_arg, struct radix_node_head *head,
struct radix_node *tm;
if ((tm = rn_addmask(netmask, 1, off)) == NULL)
- return (0);
+ return (NULL);
netmask = tm->rn_key;
while (tt->rn_mask != netmask)
if ((tt = tt->rn_dupedkey) == NULL)
- return (0);
+ return (NULL);
}
/* save start of multi path chain for later use */
@@ -998,7 +1009,7 @@ rn_delete(void *v_arg, void *n_arg, struct radix_node_head *head,
/* remove possible radix_mask */
if (rn_del_radix_mask(tt))
- return (0);
+ return (NULL);
/*
* Finally eliminate us from tree
diff --git a/sys/net/radix_mpath.c b/sys/net/radix_mpath.c
index 9560fd6d9bc..e8921f5db17 100644
--- a/sys/net/radix_mpath.c
+++ b/sys/net/radix_mpath.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: radix_mpath.c,v 1.29 2015/03/04 15:53:29 claudio Exp $ */
+/* $OpenBSD: radix_mpath.c,v 1.30 2015/07/16 18:17:27 claudio Exp $ */
/* $KAME: radix_mpath.c,v 1.13 2002/10/28 21:05:59 itojun Exp $ */
/*
@@ -216,7 +216,7 @@ rt_mpath_conflict(struct radix_node_head *rnh, struct sockaddr *dst,
int same, l, skip;
rn1 = rnh->rnh_lookup(dst, netmask, rnh);
- if (!rn1 || rn1->rn_flags & RNF_ROOT)
+ if (!rn1)
return 0;
/*
diff --git a/sys/net/route.c b/sys/net/route.c
index 2a06b2e4b27..738b49cb8fb 100644
--- a/sys/net/route.c
+++ b/sys/net/route.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: route.c,v 1.215 2015/06/29 11:04:16 mpi Exp $ */
+/* $OpenBSD: route.c,v 1.216 2015/07/16 18:17:27 claudio Exp $ */
/* $NetBSD: route.c,v 1.14 1996/02/13 22:00:46 christos Exp $ */
/*
@@ -307,8 +307,7 @@ rtalloc(struct sockaddr *dst, int flags, unsigned int tableid)
info.rti_info[RTAX_DST] = dst;
rnh = rtable_get(tableid, dst->sa_family);
- if (rnh && (rn = rnh->rnh_matchaddr((caddr_t)dst, rnh)) &&
- ((rn->rn_flags & RNF_ROOT) == 0)) {
+ if (rnh && (rn = rnh->rnh_matchaddr((caddr_t)dst, rnh))) {
newrt = rt = (struct rtentry *)rn;
if ((rt->rt_flags & RTF_CLONING) && ISSET(flags, RT_RESOLVE)) {
err = rtrequest1(RTM_RESOLVE, &info, RTP_DEFAULT,
diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c
index 56a6a3c6d64..fdfec18b13c 100644
--- a/sys/net/rtsock.c
+++ b/sys/net/rtsock.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rtsock.c,v 1.162 2015/07/15 22:16:42 deraadt Exp $ */
+/* $OpenBSD: rtsock.c,v 1.163 2015/07/16 18:17:27 claudio Exp $ */
/* $NetBSD: rtsock.c,v 1.18 1996/03/29 00:32:10 cgd Exp $ */
/*
@@ -443,7 +443,6 @@ int
route_output(struct mbuf *m, ...)
{
struct rt_msghdr *rtm = NULL;
- struct radix_node *rn = NULL;
struct rtentry *rt = NULL;
struct rtentry *saved_nrt = NULL;
struct radix_node_head *rnh;
@@ -625,10 +624,8 @@ route_output(struct mbuf *m, ...)
}
rt = rt_lookup(info.rti_info[RTAX_DST],
info.rti_info[RTAX_NETMASK], tableid);
- rn = (struct radix_node *)rt;
- if (rn == NULL || (rn->rn_flags & RNF_ROOT) != 0) {
+ if (rt == NULL) {
error = ESRCH;
- rt = NULL;
goto flush;
}
#ifndef SMALL_KERNEL
@@ -667,7 +664,6 @@ route_output(struct mbuf *m, ...)
goto flush;
}
}
- rn = (struct radix_node *)rt;
}
#endif
rt->rt_refcnt++;