summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorMartin Pieuchot <mpi@cvs.openbsd.org>2015-09-04 08:43:40 +0000
committerMartin Pieuchot <mpi@cvs.openbsd.org>2015-09-04 08:43:40 +0000
commit9afff0521bd3161bdbce6695ee2c75154d7858d1 (patch)
treecdb4de2031848165d23d257d661869003247ecc6 /sys
parent3329517806969b15b0dbe4ca265bbe649c3aef4a (diff)
Make every subsystem using a radix tree call rn_init() and pass the
length of the key as argument. This way every consumer of the radix tree has a chance to explicitly initialize the shared data structures and no longer rely on another subsystem to do the initialization. As a bonus ``dom_maxrtkey'' is no longer used an die. ART kernels should now be fully usable because pf(4) and IPSEC properly initialized the radix tree. ok chris@, reyk@
Diffstat (limited to 'sys')
-rw-r--r--sys/kern/uipc_domain.c6
-rw-r--r--sys/kern/vfs_subr.c4
-rw-r--r--sys/net/pf_table.c4
-rw-r--r--sys/net/pfkey.c7
-rw-r--r--sys/net/pipex.c7
-rw-r--r--sys/net/radix.c64
-rw-r--r--sys/net/radix.h4
-rw-r--r--sys/net/route.c18
-rw-r--r--sys/net/rtable.c8
-rw-r--r--sys/net/rtable.h4
-rw-r--r--sys/netinet/in_proto.c4
-rw-r--r--sys/netinet6/in6_proto.c3
-rw-r--r--sys/netmpls/mpls_proto.c5
-rw-r--r--sys/sys/domain.h3
14 files changed, 89 insertions, 52 deletions
diff --git a/sys/kern/uipc_domain.c b/sys/kern/uipc_domain.c
index cfc2da7a6f5..28915420c4b 100644
--- a/sys/kern/uipc_domain.c
+++ b/sys/kern/uipc_domain.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uipc_domain.c,v 1.42 2015/08/30 10:39:16 mpi Exp $ */
+/* $OpenBSD: uipc_domain.c,v 1.43 2015/09/04 08:43:39 mpi Exp $ */
/* $NetBSD: uipc_domain.c,v 1.14 1996/02/09 19:00:44 christos Exp $ */
/*
@@ -45,15 +45,14 @@
#include "bpfilter.h"
#include "pflow.h"
-extern struct domain routedomain;
extern struct domain mplsdomain;
extern struct domain pfkeydomain;
extern struct domain inet6domain;
extern struct domain inetdomain;
extern struct domain unixdomain;
+extern struct domain routedomain;
struct domain *domains[] = {
- &routedomain,
#ifdef MPLS
&mplsdomain,
#endif
@@ -65,6 +64,7 @@ struct domain *domains[] = {
#endif /* INET6 */
&inetdomain,
&unixdomain,
+ &routedomain,
NULL
};
diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c
index a3ab3ad90b9..6157a923ab2 100644
--- a/sys/kern/vfs_subr.c
+++ b/sys/kern/vfs_subr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vfs_subr.c,v 1.232 2015/07/16 18:17:27 claudio Exp $ */
+/* $OpenBSD: vfs_subr.c,v 1.233 2015/09/04 08:43:39 mpi Exp $ */
/* $NetBSD: vfs_subr.c,v 1.53 1996/04/22 01:39:13 christos Exp $ */
/*
@@ -154,6 +154,8 @@ vntblinit(void)
* Initialize the filesystem syncer.
*/
vn_initialize_syncerd();
+
+ rn_init(sizeof(struct sockaddr_in));
}
/*
diff --git a/sys/net/pf_table.c b/sys/net/pf_table.c
index a830fd180fe..86907f06fa1 100644
--- a/sys/net/pf_table.c
+++ b/sys/net/pf_table.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pf_table.c,v 1.113 2015/07/20 18:42:08 jsg Exp $ */
+/* $OpenBSD: pf_table.c,v 1.114 2015/09/04 08:43:39 mpi Exp $ */
/*
* Copyright (c) 2002 Cedric Berger
@@ -213,6 +213,8 @@ pfr_gcd(int m, int n)
void
pfr_initialize(void)
{
+ rn_init(sizeof(struct sockaddr_in6));
+
pool_init(&pfr_ktable_pl, sizeof(struct pfr_ktable), 0, 0, 0,
"pfrktable", NULL);
pool_init(&pfr_kentry_pl[PFRKE_PLAIN], sizeof(struct pfr_kentry),
diff --git a/sys/net/pfkey.c b/sys/net/pfkey.c
index ac1f4dbc40b..7428983e595 100644
--- a/sys/net/pfkey.c
+++ b/sys/net/pfkey.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pfkey.c,v 1.26 2015/08/30 10:39:16 mpi Exp $ */
+/* $OpenBSD: pfkey.c,v 1.27 2015/09/04 08:43:39 mpi Exp $ */
/*
* @(#)COPYRIGHT 1.1 (NRL) 17 January 1995
@@ -270,8 +270,7 @@ struct domain pfkeydomain = {
NULL, /* protosw */
NULL, /* protoswNPROTOSW */
NULL, /* dom_rtattach */
- 16, /* rtoffset */
- sizeof(struct sockaddr_encap) /* maxrtkey */
+ 16 /* rtoffset */
};
static struct protosw pfkey_protosw_template = {
@@ -341,6 +340,8 @@ pfkey_buildprotosw(void)
void
pfkey_init(void)
{
+ rn_init(sizeof(struct sockaddr_encap));
+
if (pfkey_buildprotosw() != 0)
return;
diff --git a/sys/net/pipex.c b/sys/net/pipex.c
index 9786a23794c..6df81e9033e 100644
--- a/sys/net/pipex.c
+++ b/sys/net/pipex.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pipex.c,v 1.74 2015/09/01 21:24:04 bluhm Exp $ */
+/* $OpenBSD: pipex.c,v 1.75 2015/09/04 08:43:39 mpi Exp $ */
/*-
* Copyright (c) 2009 Internet Initiative Japan Inc.
@@ -125,11 +125,12 @@ void
pipex_init(void)
{
int i;
- extern int max_keylen; /* for radix.c */
if (pipex_softintr != NULL)
return;
+ rn_init(sizeof(struct sockaddr_in6));
+
pool_init(&pipex_session_pool, sizeof(struct pipex_session), 0, 0, 0,
"ppxss", NULL);
pool_init(&mppe_key_pool, PIPEX_MPPE_KEYLEN * PIPEX_MPPE_NOLDKEY, 0, 0,
@@ -138,8 +139,6 @@ pipex_init(void)
LIST_INIT(&pipex_session_list);
LIST_INIT(&pipex_close_wait_list);
- if (sizeof(struct sockaddr_in) > max_keylen)
- max_keylen = sizeof(struct sockaddr_in);
for (i = 0; i < nitems(pipex_id_hashtable); i++)
LIST_INIT(&pipex_id_hashtable[i]);
for (i = 0; i < nitems(pipex_peer_addr_hashtable); i++)
diff --git a/sys/net/radix.c b/sys/net/radix.c
index 267b481895e..24fa00d3885 100644
--- a/sys/net/radix.c
+++ b/sys/net/radix.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: radix.c,v 1.47 2015/08/30 10:39:16 mpi Exp $ */
+/* $OpenBSD: radix.c,v 1.48 2015/09/04 08:43:39 mpi Exp $ */
/* $NetBSD: radix.c,v 1.20 2003/08/07 16:32:56 agc Exp $ */
/*
@@ -39,7 +39,6 @@
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/malloc.h>
-#include <sys/domain.h>
#include <sys/syslog.h>
#include <sys/pool.h>
#include <net/radix.h>
@@ -50,7 +49,7 @@
#include <net/radix_mpath.h>
#endif
-int max_keylen;
+static unsigned int max_keylen;
struct radix_node_head *mask_rnhead;
static char *addmask_key;
static char normal_chars[] = {0, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, -1};
@@ -1151,17 +1150,38 @@ rn_walktree(struct radix_node_head *h, int (*f)(struct radix_node *, void *,
}
int
+rn_initmask(void)
+{
+ if (mask_rnhead != NULL)
+ return (0);
+
+ KASSERT(max_keylen > 0);
+
+ mask_rnhead = malloc(sizeof(*mask_rnhead), M_RTABLE, M_NOWAIT);
+ if (mask_rnhead == NULL)
+ return (1);
+
+ rn_inithead0(mask_rnhead, 0);
+ return (0);
+}
+
+int
rn_inithead(void **head, int off)
{
struct radix_node_head *rnh;
- if (*head)
+ if (*head != NULL)
return (1);
+
+ if (rn_initmask())
+ panic("failed to initialize the mask tree");
+
rnh = malloc(sizeof(*rnh), M_RTABLE, M_NOWAIT);
if (rnh == NULL)
return (0);
*head = rnh;
- return rn_inithead0(rnh, off);
+ rn_inithead0(rnh, off);
+ return (1);
}
int
@@ -1188,31 +1208,33 @@ rn_inithead0(struct radix_node_head *rnh, int off)
return (1);
}
+/*
+ * rn_init() can be called multiple time with a different key length
+ * as long as not radix tree head has been allocated.
+ */
void
-rn_init(void)
+rn_init(unsigned int keylen)
{
char *cp, *cplim;
- struct domain *dom;
- int i;
- if (rn_zeros != NULL)
+ if (max_keylen == 0) {
+ pool_init(&rtmask_pool, sizeof(struct radix_mask), 0, 0, 0,
+ "rtmask", NULL);
+ }
+
+ if (keylen <= max_keylen)
return;
- pool_init(&rtmask_pool, sizeof(struct radix_mask), 0, 0, 0, "rtmask",
- NULL);
- for (i = 0; (dom = domains[i]) != NULL; i++) {
- if (dom->dom_maxrtkey > max_keylen)
- max_keylen = dom->dom_maxrtkey;
- }
- if (max_keylen == 0)
- panic("radix functions require max_keylen be set");
- rn_zeros = mallocarray(3, max_keylen, M_RTABLE, M_NOWAIT | M_ZERO);
+ KASSERT(mask_rnhead == NULL);
+
+ free(rn_zeros, M_RTABLE, 3 * max_keylen);
+ rn_zeros = mallocarray(3, keylen, M_RTABLE, M_NOWAIT | M_ZERO);
if (rn_zeros == NULL)
- panic("rn_init");
+ panic("cannot initialize a radix tree without memory");
+ max_keylen = keylen;
+
rn_ones = cp = rn_zeros + max_keylen;
addmask_key = cplim = rn_ones + max_keylen;
while (cp < cplim)
*cp++ = -1;
- if (rn_inithead((void *)&mask_rnhead, 0) == 0)
- panic("rn_init 2");
}
diff --git a/sys/net/radix.h b/sys/net/radix.h
index cf8ff8a0108..cdb7ca9d995 100644
--- a/sys/net/radix.h
+++ b/sys/net/radix.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: radix.h,v 1.25 2014/05/27 19:38:15 claudio Exp $ */
+/* $OpenBSD: radix.h,v 1.26 2015/09/04 08:43:39 mpi Exp $ */
/* $NetBSD: radix.h,v 1.8 1996/02/13 22:00:37 christos Exp $ */
/*
@@ -115,7 +115,7 @@ struct radix_node_head {
#ifdef _KERNEL
-void rn_init(void);
+void rn_init(unsigned int);
int rn_inithead(void **, int);
int rn_inithead0(struct radix_node_head *, int);
int rn_refines(void *, void *);
diff --git a/sys/net/route.c b/sys/net/route.c
index 05a2cfe955f..64e1df22c6d 100644
--- a/sys/net/route.c
+++ b/sys/net/route.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: route.c,v 1.229 2015/09/03 09:50:26 mpi Exp $ */
+/* $OpenBSD: route.c,v 1.230 2015/09/04 08:43:39 mpi Exp $ */
/* $NetBSD: route.c,v 1.14 1996/02/13 22:00:46 christos Exp $ */
/*
@@ -198,11 +198,25 @@ void
route_init(void)
{
struct domain *dom;
+ unsigned int keylen;
int i;
pool_init(&rtentry_pool, sizeof(struct rtentry), 0, 0, 0, "rtentry",
NULL);
- rtable_init(); /* initialize all zeroes, all ones, mask table */
+
+ /*
+ * Compute the maximum supported key length in case the routing
+ * table backend needs it.
+ */
+ keylen = sizeof(struct sockaddr_in);
+#ifdef INET6
+ keylen = max(keylen, (sizeof(struct sockaddr_in6)));
+#endif
+#ifdef MPLS
+ keylen = max(keylen, (sizeof(struct sockaddr_mpls)));
+#endif
+
+ rtable_init(keylen);
bzero(af2rtafidx, sizeof(af2rtafidx));
rtafidx_max = 1; /* must have NULL at index 0, so start at 1 */
diff --git a/sys/net/rtable.c b/sys/net/rtable.c
index d918eb0fccb..3a4ff39cd47 100644
--- a/sys/net/rtable.c
+++ b/sys/net/rtable.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rtable.c,v 1.3 2015/08/20 12:51:10 mpi Exp $ */
+/* $OpenBSD: rtable.c,v 1.4 2015/09/04 08:43:39 mpi Exp $ */
/*
* Copyright (c) 2014-2015 Martin Pieuchot
@@ -29,9 +29,9 @@
#ifndef ART
void
-rtable_init(void)
+rtable_init(unsigned int keylen)
{
- rn_init();
+ rn_init(keylen); /* initialize all zeroes, all ones, mask table */
}
int
@@ -216,7 +216,7 @@ static inline int satoplen(struct art_root *, struct sockaddr *);
static inline uint8_t *satoaddr(struct art_root *, struct sockaddr *);
void
-rtable_init(void)
+rtable_init(unsigned int keylen)
{
pool_init(&an_pool, sizeof(struct art_node), 0, 0, 0, "art node", NULL);
}
diff --git a/sys/net/rtable.h b/sys/net/rtable.h
index df07c538945..19b559c9055 100644
--- a/sys/net/rtable.h
+++ b/sys/net/rtable.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: rtable.h,v 1.2 2015/08/20 12:39:43 mpi Exp $ */
+/* $OpenBSD: rtable.h,v 1.3 2015/09/04 08:43:39 mpi Exp $ */
/*
* Copyright (c) 2014-2015 Martin Pieuchot
@@ -49,7 +49,7 @@
#endif /* ART */
-void rtable_init(void);
+void rtable_init(unsigned int);
int rtable_attach(void **, int);
struct rtentry *rtable_lookup(unsigned int, struct sockaddr *,
struct sockaddr *);
diff --git a/sys/netinet/in_proto.c b/sys/netinet/in_proto.c
index 79771853451..d8dea422e47 100644
--- a/sys/netinet/in_proto.c
+++ b/sys/netinet/in_proto.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: in_proto.c,v 1.65 2015/08/30 10:39:16 mpi Exp $ */
+/* $OpenBSD: in_proto.c,v 1.66 2015/09/04 08:43:39 mpi Exp $ */
/* $NetBSD: in_proto.c,v 1.14 1996/02/18 18:58:32 christos Exp $ */
/*
@@ -311,4 +311,4 @@ struct domain inetdomain =
{ AF_INET, "internet", 0, 0, 0,
inetsw, &inetsw[nitems(inetsw)],
rtable_attach,
- 32, sizeof(struct sockaddr_in) };
+ 32 };
diff --git a/sys/netinet6/in6_proto.c b/sys/netinet6/in6_proto.c
index d4c2fe6106e..3c29cdeb568 100644
--- a/sys/netinet6/in6_proto.c
+++ b/sys/netinet6/in6_proto.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: in6_proto.c,v 1.79 2015/08/30 10:39:16 mpi Exp $ */
+/* $OpenBSD: in6_proto.c,v 1.80 2015/09/04 08:43:39 mpi Exp $ */
/* $KAME: in6_proto.c,v 1.66 2000/10/10 15:35:47 itojun Exp $ */
/*
@@ -248,7 +248,6 @@ struct domain inet6domain =
(struct protosw *)&inet6sw[nitems(inet6sw)],
rtable_attach,
offsetof(struct sockaddr_in6, sin6_addr) << 3,
- sizeof(struct sockaddr_in6),
in6_domifattach, in6_domifdetach, };
/*
diff --git a/sys/netmpls/mpls_proto.c b/sys/netmpls/mpls_proto.c
index 9d49e797e7c..1bba66cf7d4 100644
--- a/sys/netmpls/mpls_proto.c
+++ b/sys/netmpls/mpls_proto.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mpls_proto.c,v 1.11 2015/08/30 10:39:16 mpi Exp $ */
+/* $OpenBSD: mpls_proto.c,v 1.12 2015/09/04 08:43:39 mpi Exp $ */
/*
* Copyright (C) 1999, 2000 and 2001 AYAME Project, WIDE Project.
@@ -69,6 +69,5 @@ struct domain mplsdomain = {
mplssw,
&mplssw[nitems(mplssw)],
rtable_attach,
- offsetof(struct sockaddr_mpls, smpls_label) << 3,
- sizeof(struct sockaddr_mpls)
+ offsetof(struct sockaddr_mpls, smpls_label) << 3
};
diff --git a/sys/sys/domain.h b/sys/sys/domain.h
index 6aa6c6a0506..84f1463ab8a 100644
--- a/sys/sys/domain.h
+++ b/sys/sys/domain.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: domain.h,v 1.14 2015/08/30 10:39:16 mpi Exp $ */
+/* $OpenBSD: domain.h,v 1.15 2015/09/04 08:43:39 mpi Exp $ */
/* $NetBSD: domain.h,v 1.10 1996/02/09 18:25:07 christos Exp $ */
/*
@@ -59,7 +59,6 @@ struct domain {
/* initialize routing table */
int (*dom_rtattach)(void **, int);
int dom_rtoffset; /* an arg to rtattach, in bits */
- int dom_maxrtkey; /* for routing layer */
void *(*dom_ifattach)(struct ifnet *);
void (*dom_ifdetach)(struct ifnet *, void *);
/* af-dependent data on ifnet */