1 //==========================================================================
3 // src/sys/kern/uipc_domain.c
5 //==========================================================================
6 //####BSDCOPYRIGHTBEGIN####
8 // -------------------------------------------
10 // Portions of this software may have been derived from OpenBSD,
11 // FreeBSD or other sources, and are covered by the appropriate
12 // copyright disclaimers included herein.
14 // Portions created by Red Hat are
15 // Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
17 // -------------------------------------------
19 //####BSDCOPYRIGHTEND####
20 //==========================================================================
23 * Copyright (c) 1982, 1986, 1993
24 * The Regents of the University of California. All rights reserved.
26 * Redistribution and use in source and binary forms, with or without
27 * modification, are permitted provided that the following conditions
29 * 1. Redistributions of source code must retain the above copyright
30 * notice, this list of conditions and the following disclaimer.
31 * 2. Redistributions in binary form must reproduce the above copyright
32 * notice, this list of conditions and the following disclaimer in the
33 * documentation and/or other materials provided with the distribution.
34 * 3. All advertising materials mentioning features or use of this software
35 * must display the following acknowledgement:
36 * This product includes software developed by the University of
37 * California, Berkeley and its contributors.
38 * 4. Neither the name of the University nor the names of its contributors
39 * may be used to endorse or promote products derived from this software
40 * without specific prior written permission.
42 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
43 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
45 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
46 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
47 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
48 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
49 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
50 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
51 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
54 * @(#)uipc_domain.c 8.2 (Berkeley) 10/18/93
55 * $FreeBSD: src/sys/kern/uipc_domain.c,v 1.22.2.1 2001/07/03 11:01:37 ume Exp $
58 #include <sys/param.h>
59 #include <sys/socket.h>
60 #include <sys/protosw.h>
61 #include <sys/domain.h>
63 #include <sys/socketvar.h>
66 * System initialization
68 * Note: domain initialization wants to take place on a per domain basis
69 * as a result of traversing a linker set. Most likely, each domain
70 * want to call a registration function rather than being handled here
71 * in domaininit(). Probably this will look like:
73 * SYSINIT(unique, SI_SUB_PROTO_DOMAIN, SI_ORDER_ANY, domain_add, xxx)
75 * Where 'xxx' is replaced by the address of a parameter struct to be
76 * passed to the doamin_add() function.
79 static void domaininit __P((void *));
80 SYSINIT(domain, SI_SUB_PROTO_DOMAIN, SI_ORDER_FIRST, domaininit, NULL)
82 static void pffasttimo __P((void *));
83 static void pfslowtimo __P((void *));
85 struct domain *domains;
88 * Add a new protocol domain to the list of supported domains
89 * Note: you cant unload it again because a socket may be using it.
90 * XXX can't fail at this time.
93 net_init_domain(struct domain *dp)
95 register struct protosw *pr;
99 log(LOG_INIT, "New domain %s at %p\n", dp->dom_name, dp->dom_init);
102 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++){
103 if (pr->pr_usrreqs == 0)
104 panic("domaininit: %ssw[%d] has no usrreqs!",
106 (int)(pr - dp->dom_protosw));
111 * update global informatio about maximums
113 max_hdr = max_linkhdr + max_protohdr;
114 max_datalen = MHLEN - max_hdr;
119 * Add a new protocol domain to the list of supported domains
120 * Note: you cant unload it again because a socket may be using it.
121 * XXX can't fail at this time.
124 net_add_domain(void *data)
129 dp = (struct domain *)data;
131 dp->dom_next = domains;
139 domaininit(void *dummy)
142 * Before we do any setup, make sure to initialize the
143 * zone allocator we get struct sockets from. The obvious
144 * maximum number of sockets is `maxfiles', but it is possible
145 * to have a socket without an open file (e.g., a connection waiting
146 * to be accept(2)ed). Rather than think up and define a
147 * better value, we just use nmbclusters, since that's what people
148 * are told to increase first when the network runs out of memory.
149 * Perhaps we should have two pools, one of unlimited size
150 * for use during socreate(), and one ZONE_INTERRUPT pool for
151 * use in sonewconn().
153 socket_zone = zinit("socket", sizeof(struct socket), maxsockets,
156 if (max_linkhdr < 16) /* XXX */
159 timeout(pffasttimo, (void *)0, 1);
160 timeout(pfslowtimo, (void *)0, 1);
165 pffindtype(family, type)
169 register struct domain *dp;
170 register struct protosw *pr;
172 for (dp = domains; dp; dp = dp->dom_next)
173 if (dp->dom_family == family)
177 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
178 if (pr->pr_type && pr->pr_type == type)
184 pffindproto(family, protocol, type)
189 register struct domain *dp;
190 register struct protosw *pr;
191 struct protosw *maybe = 0;
195 for (dp = domains; dp; dp = dp->dom_next)
196 if (dp->dom_family == family)
200 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) {
201 if ((pr->pr_protocol == protocol) && (pr->pr_type == type))
204 if (type == SOCK_RAW && pr->pr_type == SOCK_RAW &&
205 pr->pr_protocol == 0 && maybe == (struct protosw *)0)
216 register struct domain *dp;
217 register struct protosw *pr;
219 for (dp = domains; dp; dp = dp->dom_next)
220 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
222 (*pr->pr_ctlinput)(cmd, sa, (void *)0);
226 pfctlinput2(cmd, sa, ctlparam)
236 for (dp = domains; dp; dp = dp->dom_next) {
238 * the check must be made by xx_ctlinput() anyways, to
239 * make sure we use data item pointed to by ctlparam in
240 * correct way. the following check is made just for safety.
242 if (dp->dom_family != sa->sa_family)
245 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
247 (*pr->pr_ctlinput)(cmd, sa, ctlparam);
255 register struct domain *dp;
256 register struct protosw *pr;
258 for (dp = domains; dp; dp = dp->dom_next)
259 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
261 (*pr->pr_slowtimo)();
262 timeout(pfslowtimo, (void *)0, hz/2);
269 register struct domain *dp;
270 register struct protosw *pr;
272 for (dp = domains; dp; dp = dp->dom_next)
273 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
275 (*pr->pr_fasttimo)();
276 timeout(pffasttimo, (void *)0, hz/5);