1 | /* |
---|
2 | * Copyright (c) 1982, 1986, 1993 |
---|
3 | * The Regents of the University of California. All rights reserved. |
---|
4 | * |
---|
5 | * Redistribution and use in source and binary forms, with or without |
---|
6 | * modification, are permitted provided that the following conditions |
---|
7 | * are met: |
---|
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. |
---|
20 | * |
---|
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 |
---|
31 | * SUCH DAMAGE. |
---|
32 | * |
---|
33 | * @(#)uipc_domain.c 8.2 (Berkeley) 10/18/93 |
---|
34 | */ |
---|
35 | |
---|
36 | #include <sys/param.h> |
---|
37 | #include <sys/socket.h> |
---|
38 | #include <sys/protosw.h> |
---|
39 | #include <sys/domain.h> |
---|
40 | #include <sys/mbuf.h> |
---|
41 | #include <sys/kernel.h> |
---|
42 | #include <sys/systm.h> |
---|
43 | |
---|
44 | /* |
---|
45 | * System initialization |
---|
46 | * |
---|
47 | * Note: domain initialization wants to take place on a per domain basis |
---|
48 | * as a result of traversing a linker set. Most likely, each domain |
---|
49 | * want to call a registration function rather than being handled here |
---|
50 | * in domaininit(). Probably this will look like: |
---|
51 | * |
---|
52 | * SYSINIT(unique, SI_SUB_PROTO_DOMAI, SI_ORDER_ANY, domain_add, xxx) |
---|
53 | * |
---|
54 | * Where 'xxx' is replaced by the address of a parameter struct to be |
---|
55 | * passed to the doamin_add() function. |
---|
56 | */ |
---|
57 | |
---|
58 | #if !defined(__rtems__) |
---|
59 | static int x_save_spl; /* used by kludge*/ |
---|
60 | static void kludge_splimp(void *); |
---|
61 | static void kludge_splx(void *); |
---|
62 | void domaininit(void *); |
---|
63 | SYSINIT(splimp, SI_SUB_PROTO_BEGIN, SI_ORDER_FIRST, kludge_splimp, &x_save_spl) |
---|
64 | SYSINIT(domain, SI_SUB_PROTO_DOMAIN, SI_ORDER_FIRST, domaininit, NULL) |
---|
65 | SYSINIT(splx, SI_SUB_PROTO_END, SI_ORDER_FIRST, kludge_splx, &x_save_spl) |
---|
66 | #endif |
---|
67 | |
---|
68 | static void pffasttimo(void *); |
---|
69 | static void pfslowtimo(void *); |
---|
70 | |
---|
71 | struct domain *domains; |
---|
72 | |
---|
73 | #define ADDDOMAIN(x) { \ |
---|
74 | __CONCAT(x,domain.dom_next) = domains; \ |
---|
75 | domains = &__CONCAT(x,domain); \ |
---|
76 | } |
---|
77 | |
---|
78 | /* ARGSUSED*/ |
---|
79 | void |
---|
80 | domaininit(void *dummy) |
---|
81 | { |
---|
82 | register struct domain *dp; |
---|
83 | register struct protosw *pr; |
---|
84 | |
---|
85 | /* - not in our sources |
---|
86 | #ifdef ISDN |
---|
87 | ADDDOMAIN(isdn); |
---|
88 | #endif |
---|
89 | */ |
---|
90 | |
---|
91 | for (dp = domains; dp; dp = dp->dom_next) { |
---|
92 | if (dp->dom_init) |
---|
93 | (*dp->dom_init)(); |
---|
94 | for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++){ |
---|
95 | #ifdef PRU_OLDSTYLE |
---|
96 | /* See comments in uipc_socket2.c. */ |
---|
97 | if (pr->pr_usrreqs == 0 && pr->pr_ousrreq) |
---|
98 | pr->pr_usrreqs = &pru_oldstyle; |
---|
99 | #endif |
---|
100 | if (pr->pr_init) |
---|
101 | (*pr->pr_init)(); |
---|
102 | } |
---|
103 | } |
---|
104 | |
---|
105 | if (max_linkhdr < 16) /* XXX */ |
---|
106 | max_linkhdr = 16; |
---|
107 | max_hdr = max_linkhdr + max_protohdr; |
---|
108 | max_datalen = MHLEN - max_hdr; |
---|
109 | timeout(pffasttimo, (void *)0, 1); |
---|
110 | timeout(pfslowtimo, (void *)0, 1); |
---|
111 | } |
---|
112 | |
---|
113 | |
---|
114 | #if !defined(__rtems__) |
---|
115 | /* |
---|
116 | * The following two operations are kludge code. Most likely, they should |
---|
117 | * be done as a "domainpreinit()" for the first function and then rolled |
---|
118 | * in as the last act of "domaininit()" for the second. |
---|
119 | * |
---|
120 | * In point of fact, it is questionable why other initialization prior |
---|
121 | * to this does not also take place at splimp by default. |
---|
122 | */ |
---|
123 | static void |
---|
124 | kludge_splimp(void *udata) |
---|
125 | { |
---|
126 | int *savesplp = udata; |
---|
127 | |
---|
128 | *savesplp = splimp(); |
---|
129 | } |
---|
130 | |
---|
131 | static void |
---|
132 | kludge_splx(void *udata) |
---|
133 | { |
---|
134 | int *savesplp = udata; |
---|
135 | |
---|
136 | splx( *savesplp); |
---|
137 | } |
---|
138 | #endif /* !defined(__rtems__) */ |
---|
139 | |
---|
140 | struct protosw * |
---|
141 | pffindtype(int family, int type) |
---|
142 | { |
---|
143 | register struct domain *dp; |
---|
144 | register struct protosw *pr; |
---|
145 | |
---|
146 | for (dp = domains; dp; dp = dp->dom_next) |
---|
147 | if (dp->dom_family == family) |
---|
148 | goto found; |
---|
149 | return (0); |
---|
150 | found: |
---|
151 | for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) |
---|
152 | if (pr->pr_type && pr->pr_type == type) |
---|
153 | return (pr); |
---|
154 | return (0); |
---|
155 | } |
---|
156 | |
---|
157 | struct protosw * |
---|
158 | pffindproto(int family, int protocol, int type) |
---|
159 | { |
---|
160 | register struct domain *dp; |
---|
161 | register struct protosw *pr; |
---|
162 | struct protosw *maybe = 0; |
---|
163 | |
---|
164 | if (family == 0) |
---|
165 | return (0); |
---|
166 | for (dp = domains; dp; dp = dp->dom_next) |
---|
167 | if (dp->dom_family == family) |
---|
168 | goto found; |
---|
169 | return (0); |
---|
170 | found: |
---|
171 | for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) { |
---|
172 | if ((pr->pr_protocol == protocol) && (pr->pr_type == type)) |
---|
173 | return (pr); |
---|
174 | |
---|
175 | if (type == SOCK_RAW && pr->pr_type == SOCK_RAW && |
---|
176 | pr->pr_protocol == 0 && maybe == (struct protosw *)0) |
---|
177 | maybe = pr; |
---|
178 | } |
---|
179 | return (maybe); |
---|
180 | } |
---|
181 | |
---|
182 | void |
---|
183 | pfctlinput(int cmd, struct sockaddr *sa) |
---|
184 | { |
---|
185 | register struct domain *dp; |
---|
186 | register struct protosw *pr; |
---|
187 | |
---|
188 | for (dp = domains; dp; dp = dp->dom_next) |
---|
189 | for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) |
---|
190 | if (pr->pr_ctlinput) |
---|
191 | (*pr->pr_ctlinput)(cmd, sa, (void *)0); |
---|
192 | } |
---|
193 | |
---|
194 | static void |
---|
195 | pfslowtimo(void *arg) |
---|
196 | { |
---|
197 | register struct domain *dp; |
---|
198 | register struct protosw *pr; |
---|
199 | |
---|
200 | for (dp = domains; dp; dp = dp->dom_next) |
---|
201 | for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) |
---|
202 | if (pr->pr_slowtimo) |
---|
203 | (*pr->pr_slowtimo)(); |
---|
204 | timeout(pfslowtimo, (void *)0, hz/2); |
---|
205 | } |
---|
206 | |
---|
207 | static void |
---|
208 | pffasttimo(void *arg) |
---|
209 | { |
---|
210 | register struct domain *dp; |
---|
211 | register struct protosw *pr; |
---|
212 | |
---|
213 | for (dp = domains; dp; dp = dp->dom_next) |
---|
214 | for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) |
---|
215 | if (pr->pr_fasttimo) |
---|
216 | (*pr->pr_fasttimo)(); |
---|
217 | timeout(pffasttimo, (void *)0, hz/5); |
---|
218 | } |
---|