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.5 2004/09/17 01:03:58 joerg 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/systm.h>
46 #include <vm/vm_zone.h>
49 * System initialization
51 * Note: domain initialization wants to take place on a per domain basis
52 * as a result of traversing a linker set. Most likely, each domain
53 * want to call a registration function rather than being handled here
54 * in domaininit(). Probably this will look like:
56 * SYSINIT(unique, SI_SUB_PROTO_DOMAIN, SI_ORDER_ANY, domain_add, xxx)
58 * Where 'xxx' is replaced by the address of a parameter struct to be
59 * passed to the doamin_add() function.
62 static void domaininit (void *);
63 SYSINIT(domain, SI_SUB_PROTO_DOMAIN, SI_ORDER_FIRST, domaininit, NULL)
65 static void pffasttimo (void *);
66 static void pfslowtimo (void *);
68 struct domain *domains;
70 static struct callout pffasttimo_ch;
71 static struct callout pfslowtimo_ch;
74 * Add a new protocol domain to the list of supported domains
75 * Note: you cant unload it again because a socket may be using it.
76 * XXX can't fail at this time.
79 net_init_domain(struct domain *dp)
87 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++){
88 if (pr->pr_usrreqs == 0)
89 panic("domaininit: %ssw[%d] has no usrreqs!",
91 (int)(pr - dp->dom_protosw));
96 * update global informatio about maximums
98 max_hdr = max_linkhdr + max_protohdr;
99 max_datalen = MHLEN - max_hdr;
104 * Add a new protocol domain to the list of supported domains
105 * Note: you cant unload it again because a socket may be using it.
106 * XXX can't fail at this time.
109 net_add_domain(void *data)
114 dp = (struct domain *)data;
116 dp->dom_next = domains;
124 domaininit(void *dummy)
127 * Before we do any setup, make sure to initialize the
128 * zone allocator we get struct sockets from. The obvious
129 * maximum number of sockets is `maxfiles', but it is possible
130 * to have a socket without an open file (e.g., a connection waiting
131 * to be accept(2)ed). Rather than think up and define a
132 * better value, we just use nmbclusters, since that's what people
133 * are told to increase first when the network runs out of memory.
134 * Perhaps we should have two pools, one of unlimited size
135 * for use during socreate(), and one ZONE_INTERRUPT pool for
136 * use in sonewconn().
138 socket_zone = zinit("socket", sizeof(struct socket), maxsockets,
141 if (max_linkhdr < 16) /* XXX */
144 callout_init(&pffasttimo_ch);
145 callout_init(&pfslowtimo_ch);
146 callout_reset(&pffasttimo_ch, 1, pffasttimo, NULL);
147 callout_reset(&pfslowtimo_ch, 1, pfslowtimo, NULL);
152 pffindtype(family, type)
159 for (dp = domains; dp; dp = dp->dom_next)
160 if (dp->dom_family == family)
164 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
165 if (pr->pr_type && pr->pr_type == type)
171 pffindproto(family, protocol, type)
178 struct protosw *maybe = 0;
182 for (dp = domains; dp; dp = dp->dom_next)
183 if (dp->dom_family == family)
187 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) {
188 if ((pr->pr_protocol == protocol) && (pr->pr_type == type))
191 if (type == SOCK_RAW && pr->pr_type == SOCK_RAW &&
192 pr->pr_protocol == 0 && maybe == (struct protosw *)0)
206 for (dp = domains; dp; dp = dp->dom_next)
207 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
209 (*pr->pr_ctlinput)(cmd, sa, (void *)0);
213 pfctlinput2(cmd, sa, ctlparam)
223 for (dp = domains; dp; dp = dp->dom_next) {
225 * the check must be made by xx_ctlinput() anyways, to
226 * make sure we use data item pointed to by ctlparam in
227 * correct way. the following check is made just for safety.
229 if (dp->dom_family != sa->sa_family)
232 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
234 (*pr->pr_ctlinput)(cmd, sa, ctlparam);
245 for (dp = domains; dp; dp = dp->dom_next)
246 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
248 (*pr->pr_slowtimo)();
249 callout_reset(&pfslowtimo_ch, hz / 2, pfslowtimo, NULL);
259 for (dp = domains; dp; dp = dp->dom_next)
260 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
262 (*pr->pr_fasttimo)();
263 callout_reset(&pffasttimo_ch, hz / 5, pffasttimo, NULL);