summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Pieuchot <mpi@cvs.openbsd.org>2015-08-30 10:39:17 +0000
committerMartin Pieuchot <mpi@cvs.openbsd.org>2015-08-30 10:39:17 +0000
commitc5ed706420c17da185f0a1a7e72edff6c520216f (patch)
tree9483bb4766af0434a5541f6f21a9cbf02f75c4ad
parent1a2bdead7e7f29549e2927b099891f0827544aac (diff)
Use a global table for domains instead of building a list at run time.
As a side effect there's no need to run if_attachdomain() after the list of domains has been built. ok claudio@, reyk@
-rw-r--r--sys/kern/init_main.c3
-rw-r--r--sys/kern/uipc_domain.c68
-rw-r--r--sys/net/if.c29
-rw-r--r--sys/net/if.h3
-rw-r--r--sys/net/pfkey.c3
-rw-r--r--sys/net/radix.c14
-rw-r--r--sys/net/route.c13
-rw-r--r--sys/netinet/in_proto.c4
-rw-r--r--sys/netinet6/in6_proto.c4
-rw-r--r--sys/netmpls/mpls_proto.c4
-rw-r--r--sys/sys/domain.h5
11 files changed, 72 insertions, 78 deletions
diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c
index 6ed31016794..e2505ea549d 100644
--- a/sys/kern/init_main.c
+++ b/sys/kern/init_main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: init_main.c,v 1.243 2015/07/09 19:45:37 miod Exp $ */
+/* $OpenBSD: init_main.c,v 1.244 2015/08/30 10:39:16 mpi Exp $ */
/* $NetBSD: init_main.c,v 1.84.4.1 1996/06/02 09:08:06 mrg Exp $ */
/*
@@ -398,7 +398,6 @@ main(void *framep)
s = splnet();
netisr_init();
domaininit();
- if_attachdomain();
splx(s);
initconsbuf();
diff --git a/sys/kern/uipc_domain.c b/sys/kern/uipc_domain.c
index 65cf5eadea0..cfc2da7a6f5 100644
--- a/sys/kern/uipc_domain.c
+++ b/sys/kern/uipc_domain.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uipc_domain.c,v 1.41 2015/07/17 18:31:08 blambert Exp $ */
+/* $OpenBSD: uipc_domain.c,v 1.42 2015/08/30 10:39:16 mpi Exp $ */
/* $NetBSD: uipc_domain.c,v 1.14 1996/02/09 19:00:44 christos Exp $ */
/*
@@ -45,18 +45,33 @@
#include "bpfilter.h"
#include "pflow.h"
-struct domain *domains;
+extern struct domain routedomain;
+extern struct domain mplsdomain;
+extern struct domain pfkeydomain;
+extern struct domain inet6domain;
+extern struct domain inetdomain;
+extern struct domain unixdomain;
+
+struct domain *domains[] = {
+ &routedomain,
+#ifdef MPLS
+ &mplsdomain,
+#endif
+#if defined (KEY) || defined (IPSEC) || defined (TCP_SIGNATURE)
+ &pfkeydomain,
+#endif
+#ifdef INET6
+ &inet6domain,
+#endif /* INET6 */
+ &inetdomain,
+ &unixdomain,
+ NULL
+};
void pffasttimo(void *);
void pfslowtimo(void *);
struct domain * pffinddomain(int);
-#define ADDDOMAIN(x) { \
- extern struct domain __CONCAT(x,domain); \
- __CONCAT(x,domain.dom_next) = domains; \
- domains = &__CONCAT(x,domain); \
-}
-
void
domaininit(void)
{
@@ -64,26 +79,9 @@ domaininit(void)
struct protosw *pr;
static struct timeout pffast_timeout;
static struct timeout pfslow_timeout;
+ int i;
-#undef unix
- /*
- * KAME NOTE: ADDDOMAIN(route) is moved to the last part so that
- * it will be initialized as the *first* element. confusing!
- */
- ADDDOMAIN(unix);
- ADDDOMAIN(inet);
-#ifdef INET6
- ADDDOMAIN(inet6);
-#endif /* INET6 */
-#if defined (KEY) || defined (IPSEC) || defined (TCP_SIGNATURE)
- ADDDOMAIN(pfkey);
-#endif
-#ifdef MPLS
- ADDDOMAIN(mpls);
-#endif
- ADDDOMAIN(route);
-
- for (dp = domains; dp; dp = dp->dom_next) {
+ for (i = 0; (dp = domains[i]) != NULL; i++) {
if (dp->dom_init)
(*dp->dom_init)();
for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
@@ -104,10 +102,12 @@ struct domain *
pffinddomain(int family)
{
struct domain *dp;
+ int i;
- for (dp = domains; dp != NULL; dp = dp->dom_next)
+ for (i = 0; (dp = domains[i]) != NULL; i++) {
if (dp->dom_family == family)
return (dp);
+ }
return (NULL);
}
@@ -212,11 +212,13 @@ pfctlinput(int cmd, struct sockaddr *sa)
{
struct domain *dp;
struct protosw *pr;
+ int i;
- for (dp = domains; dp; dp = dp->dom_next)
+ for (i = 0; (dp = domains[i]) != NULL; i++) {
for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
if (pr->pr_ctlinput)
(*pr->pr_ctlinput)(cmd, sa, 0, NULL);
+ }
}
void
@@ -225,11 +227,13 @@ pfslowtimo(void *arg)
struct timeout *to = (struct timeout *)arg;
struct domain *dp;
struct protosw *pr;
+ int i;
- for (dp = domains; dp; dp = dp->dom_next)
+ for (i = 0; (dp = domains[i]) != NULL; i++) {
for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
if (pr->pr_slowtimo)
(*pr->pr_slowtimo)();
+ }
timeout_add_msec(to, 500);
}
@@ -239,10 +243,12 @@ pffasttimo(void *arg)
struct timeout *to = (struct timeout *)arg;
struct domain *dp;
struct protosw *pr;
+ int i;
- for (dp = domains; dp; dp = dp->dom_next)
+ for (i = 0; (dp = domains[i]) != NULL; i++) {
for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
if (pr->pr_fasttimo)
(*pr->pr_fasttimo)();
+ }
timeout_add_msec(to, 200);
}
diff --git a/sys/net/if.c b/sys/net/if.c
index 946fd0460d0..cd46aad3b21 100644
--- a/sys/net/if.c
+++ b/sys/net/if.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if.c,v 1.361 2015/08/23 10:01:27 dlg Exp $ */
+/* $OpenBSD: if.c,v 1.362 2015/08/30 10:39:16 mpi Exp $ */
/* $NetBSD: if.c,v 1.35 1996/05/07 05:26:04 thorpej Exp $ */
/*
@@ -125,7 +125,7 @@
#endif
void if_attachsetup(struct ifnet *);
-void if_attachdomain1(struct ifnet *);
+void if_attachdomain(struct ifnet *);
void if_attach_common(struct ifnet *);
void if_detached_start(struct ifnet *);
@@ -265,8 +265,7 @@ if_attachsetup(struct ifnet *ifp)
if (ifp->if_snd.ifq_maxlen == 0)
IFQ_SET_MAXLEN(&ifp->if_snd, IFQ_MAXLEN);
- if (domains)
- if_attachdomain1(ifp);
+ if_attachdomain(ifp);
#if NPF > 0
pfi_attach_ifnet(ifp);
#endif
@@ -332,28 +331,16 @@ if_free_sadl(struct ifnet *ifp)
}
void
-if_attachdomain()
-{
- struct ifnet *ifp;
- int s;
-
- s = splnet();
- TAILQ_FOREACH(ifp, &ifnet, if_list)
- if_attachdomain1(ifp);
- splx(s);
-}
-
-void
-if_attachdomain1(struct ifnet *ifp)
+if_attachdomain(struct ifnet *ifp)
{
struct domain *dp;
- int s;
+ int i, s;
s = splnet();
/* address family dependent data region */
bzero(ifp->if_afdata, sizeof(ifp->if_afdata));
- for (dp = domains; dp; dp = dp->dom_next) {
+ for (i = 0; (dp = domains[i]) != NULL; i++) {
if (dp->dom_ifattach)
ifp->if_afdata[dp->dom_family] =
(*dp->dom_ifattach)(ifp);
@@ -603,7 +590,7 @@ if_detach(struct ifnet *ifp)
struct ifaddr *ifa;
struct ifg_list *ifg;
struct domain *dp;
- int s;
+ int i, s;
/* Undo pseudo-driver changes. */
if_deactivate(ifp);
@@ -669,7 +656,7 @@ if_detach(struct ifnet *ifp)
free(ifp->if_slowtimo, M_TEMP, sizeof(*ifp->if_slowtimo));
free(ifp->if_linkstatetask, M_TEMP, sizeof(*ifp->if_linkstatetask));
- for (dp = domains; dp; dp = dp->dom_next) {
+ for (i = 0; (dp = domains[i]) != NULL; i++) {
if (dp->dom_ifdetach && ifp->if_afdata[dp->dom_family])
(*dp->dom_ifdetach)(ifp,
ifp->if_afdata[dp->dom_family]);
diff --git a/sys/net/if.h b/sys/net/if.h
index 49ec165bb72..c4962b8df80 100644
--- a/sys/net/if.h
+++ b/sys/net/if.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: if.h,v 1.164 2015/06/07 12:02:28 jsg Exp $ */
+/* $OpenBSD: if.h,v 1.165 2015/08/30 10:39:16 mpi Exp $ */
/* $NetBSD: if.h,v 1.23 1996/05/07 02:40:27 thorpej Exp $ */
/*
@@ -443,7 +443,6 @@ struct ifnet;
void if_alloc_sadl(struct ifnet *);
void if_free_sadl(struct ifnet *);
void if_attach(struct ifnet *);
-void if_attachdomain(void);
void if_attachtail(struct ifnet *);
void if_attachhead(struct ifnet *);
void if_deactivate(struct ifnet *);
diff --git a/sys/net/pfkey.c b/sys/net/pfkey.c
index 41ebf76d95a..ac1f4dbc40b 100644
--- a/sys/net/pfkey.c
+++ b/sys/net/pfkey.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pfkey.c,v 1.25 2015/07/17 18:31:08 blambert Exp $ */
+/* $OpenBSD: pfkey.c,v 1.26 2015/08/30 10:39:16 mpi Exp $ */
/*
* @(#)COPYRIGHT 1.1 (NRL) 17 January 1995
@@ -269,7 +269,6 @@ struct domain pfkeydomain = {
NULL, /* dispose */
NULL, /* protosw */
NULL, /* protoswNPROTOSW */
- NULL, /* dom_next */
NULL, /* dom_rtattach */
16, /* rtoffset */
sizeof(struct sockaddr_encap) /* maxrtkey */
diff --git a/sys/net/radix.c b/sys/net/radix.c
index 37df8eace75..267b481895e 100644
--- a/sys/net/radix.c
+++ b/sys/net/radix.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: radix.c,v 1.46 2015/07/16 18:17:27 claudio Exp $ */
+/* $OpenBSD: radix.c,v 1.47 2015/08/30 10:39:16 mpi Exp $ */
/* $NetBSD: radix.c,v 1.20 2003/08/07 16:32:56 agc Exp $ */
/*
@@ -1193,17 +1193,19 @@ rn_init(void)
{
char *cp, *cplim;
struct domain *dom;
+ int i;
+
+ if (rn_zeros != NULL)
+ return;
pool_init(&rtmask_pool, sizeof(struct radix_mask), 0, 0, 0, "rtmask",
NULL);
- for (dom = domains; dom; dom = dom->dom_next)
+ for (i = 0; (dom = domains[i]) != NULL; i++) {
if (dom->dom_maxrtkey > max_keylen)
max_keylen = dom->dom_maxrtkey;
- if (max_keylen == 0) {
- log(LOG_ERR,
- "rn_init: radix functions require max_keylen be set\n");
- return;
}
+ if (max_keylen == 0)
+ panic("radix functions require max_keylen be set");
rn_zeros = mallocarray(3, max_keylen, M_RTABLE, M_NOWAIT | M_ZERO);
if (rn_zeros == NULL)
panic("rn_init");
diff --git a/sys/net/route.c b/sys/net/route.c
index 69d128d1608..051497eb2c0 100644
--- a/sys/net/route.c
+++ b/sys/net/route.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: route.c,v 1.225 2015/08/24 22:11:33 mpi Exp $ */
+/* $OpenBSD: route.c,v 1.226 2015/08/30 10:39:16 mpi Exp $ */
/* $NetBSD: route.c,v 1.14 1996/02/13 22:00:46 christos Exp $ */
/*
@@ -173,17 +173,18 @@ rtable_alloc(void ***table, u_int id)
{
void **p;
struct domain *dom;
- u_int8_t i;
+ int i;
if ((p = mallocarray(rtafidx_max + 1, sizeof(void *), M_RTABLE,
M_NOWAIT|M_ZERO)) == NULL)
return (ENOMEM);
/* 2nd pass: attach */
- for (dom = domains; dom != NULL; dom = dom->dom_next)
+ for (i = 0; (dom = domains[i]) != NULL; i++) {
if (dom->dom_rtattach)
dom->dom_rtattach(&p[af2rtafidx[dom->dom_family]],
dom->dom_rtoffset);
+ }
for (i = 0; i < rtafidx_max; i++)
rtable_setid(p, id, i);
@@ -196,7 +197,8 @@ rtable_alloc(void ***table, u_int id)
void
route_init(void)
{
- struct domain *dom;
+ struct domain *dom;
+ int i;
pool_init(&rtentry_pool, sizeof(struct rtentry), 0, 0, 0, "rtentry",
NULL);
@@ -206,9 +208,10 @@ route_init(void)
rtafidx_max = 1; /* must have NULL at index 0, so start at 1 */
/* find out how many tables to allocate */
- for (dom = domains; dom != NULL; dom = dom->dom_next)
+ for (i = 0; (dom = domains[i]) != NULL; i++) {
if (dom->dom_rtattach)
af2rtafidx[dom->dom_family] = rtafidx_max++;
+ }
if (rtable_add(0) != 0)
panic("route_init rtable_add");
diff --git a/sys/netinet/in_proto.c b/sys/netinet/in_proto.c
index 1e074a11ab6..79771853451 100644
--- a/sys/netinet/in_proto.c
+++ b/sys/netinet/in_proto.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: in_proto.c,v 1.64 2015/07/18 15:51:17 mpi Exp $ */
+/* $OpenBSD: in_proto.c,v 1.65 2015/08/30 10:39:16 mpi Exp $ */
/* $NetBSD: in_proto.c,v 1.14 1996/02/18 18:58:32 christos Exp $ */
/*
@@ -309,6 +309,6 @@ struct protosw inetsw[] = {
struct domain inetdomain =
{ AF_INET, "internet", 0, 0, 0,
- inetsw, &inetsw[nitems(inetsw)], 0,
+ inetsw, &inetsw[nitems(inetsw)],
rtable_attach,
32, sizeof(struct sockaddr_in) };
diff --git a/sys/netinet6/in6_proto.c b/sys/netinet6/in6_proto.c
index de32544d985..d4c2fe6106e 100644
--- a/sys/netinet6/in6_proto.c
+++ b/sys/netinet6/in6_proto.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: in6_proto.c,v 1.78 2015/07/18 15:51:17 mpi Exp $ */
+/* $OpenBSD: in6_proto.c,v 1.79 2015/08/30 10:39:16 mpi Exp $ */
/* $KAME: in6_proto.c,v 1.66 2000/10/10 15:35:47 itojun Exp $ */
/*
@@ -245,7 +245,7 @@ struct ip6protosw inet6sw[] = {
struct domain inet6domain =
{ AF_INET6, "internet6", 0, 0, 0,
(struct protosw *)inet6sw,
- (struct protosw *)&inet6sw[nitems(inet6sw)], 0,
+ (struct protosw *)&inet6sw[nitems(inet6sw)],
rtable_attach,
offsetof(struct sockaddr_in6, sin6_addr) << 3,
sizeof(struct sockaddr_in6),
diff --git a/sys/netmpls/mpls_proto.c b/sys/netmpls/mpls_proto.c
index d81f98a337c..9d49e797e7c 100644
--- a/sys/netmpls/mpls_proto.c
+++ b/sys/netmpls/mpls_proto.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mpls_proto.c,v 1.10 2015/07/18 15:51:17 mpi Exp $ */
+/* $OpenBSD: mpls_proto.c,v 1.11 2015/08/30 10:39:16 mpi Exp $ */
/*
* Copyright (C) 1999, 2000 and 2001 AYAME Project, WIDE Project.
@@ -67,7 +67,7 @@ struct protosw mplssw[] = {
struct domain mplsdomain = {
AF_MPLS, "mpls", mpls_init, 0, 0,
mplssw,
- &mplssw[nitems(mplssw)], 0,
+ &mplssw[nitems(mplssw)],
rtable_attach,
offsetof(struct sockaddr_mpls, smpls_label) << 3,
sizeof(struct sockaddr_mpls)
diff --git a/sys/sys/domain.h b/sys/sys/domain.h
index 8173b04802a..6aa6c6a0506 100644
--- a/sys/sys/domain.h
+++ b/sys/sys/domain.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: domain.h,v 1.13 2014/12/23 03:26:24 tedu Exp $ */
+/* $OpenBSD: domain.h,v 1.14 2015/08/30 10:39:16 mpi Exp $ */
/* $NetBSD: domain.h,v 1.10 1996/02/09 18:25:07 christos Exp $ */
/*
@@ -56,7 +56,6 @@ struct domain {
/* dispose of internalized rights */
void (*dom_dispose)(struct mbuf *);
struct protosw *dom_protosw, *dom_protoswNPROTOSW;
- struct domain *dom_next;
/* initialize routing table */
int (*dom_rtattach)(void **, int);
int dom_rtoffset; /* an arg to rtattach, in bits */
@@ -67,7 +66,7 @@ struct domain {
};
#ifdef _KERNEL
-extern struct domain *domains;
+extern struct domain *domains[];
void domaininit(void);
extern struct domain inetdomain;