2 * Copyright (c) 1982, 1986, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * @(#)uipc_domain.c 8.2 (Berkeley) 10/18/93
34 * $FreeBSD: src/sys/kern/uipc_domain.c,v 1.22.2.1 2001/07/03 11:01:37 ume Exp $
35 * $DragonFly: src/sys/kern/uipc_domain.c,v 1.13 2008/10/27 02:56:30 sephe Exp $
38 #include <sys/param.h>
39 #include <sys/socket.h>
40 #include <sys/protosw.h>
41 #include <sys/domain.h>
43 #include <sys/kernel.h>
44 #include <sys/socketvar.h>
45 #include <sys/socketops.h>
46 #include <sys/systm.h>
47 #include <vm/vm_zone.h>
49 #include <sys/thread2.h>
52 * System initialization
54 * Note: domain initialization wants to take place on a per domain basis
55 * as a result of traversing a linker set. Most likely, each domain
56 * want to call a registration function rather than being handled here
57 * in domaininit(). Probably this will look like:
59 * SYSINIT(unique, SI_SUB_PROTO_DOMAIN, SI_ORDER_ANY, domain_add, xxx)
61 * Where 'xxx' is replaced by the address of a parameter struct to be
62 * passed to the doamin_add() function.
65 static void domaininit (void *);
66 SYSINIT(domain, SI_SUB_PROTO_DOMAIN, SI_ORDER_FIRST, domaininit, NULL)
68 static void pffasttimo (void *);
69 static void pfslowtimo (void *);
71 struct domainlist domains;
73 static struct callout pffasttimo_ch;
74 static struct callout pfslowtimo_ch;
77 * Add a new protocol domain to the list of supported domains
78 * Note: you cant unload it again because a socket may be using it.
79 * XXX can't fail at this time.
82 net_init_domain(struct domain *dp)
89 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) {
90 if (pr->pr_usrreqs == NULL)
91 panic("domaininit: %ssw[%d] has no usrreqs!",
92 dp->dom_name, pr - dp->dom_protosw);
97 * update global information about maximums
99 max_hdr = max_linkhdr + max_protohdr;
100 max_datalen = MHLEN - max_hdr;
105 * Add a new protocol domain to the list of supported domains
106 * Note: you cant unload it again because a socket may be using it.
107 * XXX can't fail at this time.
110 net_add_domain(void *data)
112 struct domain *dp = data;
115 SLIST_INSERT_HEAD(&domains, dp, dom_next);
122 domaininit(void *dummy)
124 if (max_linkhdr < 16) /* XXX */
127 callout_init(&pffasttimo_ch);
128 callout_init(&pfslowtimo_ch);
129 callout_reset(&pffasttimo_ch, 1, pffasttimo, NULL);
130 callout_reset(&pfslowtimo_ch, 1, pfslowtimo, NULL);
135 pffindtype(int family, int type)
140 SLIST_FOREACH(dp, &domains, dom_next)
141 if (dp->dom_family == family)
146 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
147 if (pr->pr_type && pr->pr_type == type)
153 pffindproto(int family, int protocol, int type)
157 struct protosw *maybe = NULL;
161 SLIST_FOREACH(dp, &domains, dom_next)
162 if (dp->dom_family == family)
167 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) {
168 if ((pr->pr_protocol == protocol) && (pr->pr_type == type))
171 if (type == SOCK_RAW && pr->pr_type == SOCK_RAW &&
172 pr->pr_protocol == 0 && maybe == (struct protosw *)NULL)
179 kpfctlinput(int cmd, struct sockaddr *sa)
184 SLIST_FOREACH(dp, &domains, dom_next) {
185 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
186 so_pru_ctlinput(pr, cmd, sa, NULL);
191 kpfctlinput2(int cmd, struct sockaddr *sa, void *ctlparam)
198 SLIST_FOREACH(dp, &domains, dom_next) {
200 * the check must be made by xx_ctlinput() anyways, to
201 * make sure we use data item pointed to by ctlparam in
202 * correct way. the following check is made just for safety.
204 if (dp->dom_family != sa->sa_family)
207 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
208 so_pru_ctlinput(pr, cmd, sa, ctlparam);
213 pfslowtimo(void *arg)
218 SLIST_FOREACH(dp, &domains, dom_next)
219 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
221 (*pr->pr_slowtimo)();
222 callout_reset(&pfslowtimo_ch, hz / 2, pfslowtimo, NULL);
226 pffasttimo(void *arg)
231 SLIST_FOREACH(dp, &domains, dom_next)
232 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
234 (*pr->pr_fasttimo)();
235 callout_reset(&pffasttimo_ch, hz / 5, pffasttimo, NULL);