Put sound into multimedia and rename it to audio because it is "MoreCorrect©"
[reactos.git] / reactos / drivers / lib / oskittcp / oskittcp / uipc_domain.c
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/time.h>
42 #include <sys/kernel.h>
43 #include <sys/systm.h>
44 #include <sys/proc.h>
45 #include <vm/vm.h>
46 #include <sys/sysctl.h>
47
48 void pffasttimo __P((void *));
49 void pfslowtimo __P((void *));
50
51 struct domain *domains;
52
53 #define ADDDOMAIN(x) { \
54 extern struct domain __CONCAT(x,domain); \
55 __CONCAT(x,domain.dom_next) = domains; \
56 domains = &__CONCAT(x,domain); \
57 }
58
59 extern struct linker_set domain_set;
60
61 void
62 domaininit()
63 {
64 register struct domain *dp, **dpp;
65 register struct protosw *pr;
66
67 //printf("domaininit starting\n");
68
69 /*
70 * NB - local domain is always present.
71 */
72 ADDDOMAIN(local);
73 ADDDOMAIN(inet);
74
75 for (dpp = (struct domain **)domain_set.ls_items; *dpp; dpp++) {
76 //printf("(1) Domain %s counting\n", (**dpp).dom_name);
77 (**dpp).dom_next = domains;
78 domains = *dpp;
79 }
80
81 /* - not in our sources
82 #ifdef ISDN
83 ADDDOMAIN(isdn);
84 #endif
85 */
86 for (dp = domains; dp; dp = dp->dom_next) {
87 //printf("(1) Domain %s initializing\n", dp->dom_name);
88 if (dp->dom_init)
89 (*dp->dom_init)();
90 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) {
91 //printf("Registering protocols for %s\n", dp->dom_name);
92 if (pr->pr_init)
93 (*pr->pr_init)();
94 }
95 if( dp->dom_next && !dp->dom_next->dom_name )
96 dp->dom_next = 0;
97 }
98
99 if (max_linkhdr < 16) /* XXX */
100 max_linkhdr = 16;
101 max_hdr = max_linkhdr + max_protohdr;
102 max_datalen = MHLEN - max_hdr;
103 timeout(pffasttimo, (void *)0, 1);
104 timeout(pfslowtimo, (void *)0, 1);
105
106 //printf("Domaininit done\n");
107 }
108
109 struct protosw *
110 pffindtype(family, type)
111 int family, type;
112 {
113 register struct domain *dp;
114 register struct protosw *pr;
115
116 for (dp = domains; dp; dp = dp->dom_next)
117 if (dp->dom_family == family)
118 goto found;
119 return (0);
120 found:
121 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
122 if (pr->pr_type && pr->pr_type == type)
123 return (pr);
124 return (0);
125 }
126
127 struct protosw *
128 pffindproto(family, protocol, type)
129 int family, protocol, type;
130 {
131 register struct domain *dp;
132 register struct protosw *pr;
133 struct protosw *maybe = 0;
134
135 if (family == 0)
136 return (0);
137 for (dp = domains; dp; dp = dp->dom_next)
138 if (dp->dom_family == family)
139 goto found;
140 return (0);
141 found:
142 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) {
143 if ((pr->pr_protocol == protocol) && (pr->pr_type == type))
144 return (pr);
145
146 if (type == SOCK_RAW && pr->pr_type == SOCK_RAW &&
147 pr->pr_protocol == 0 && maybe == (struct protosw *)0)
148 maybe = pr;
149 }
150 return (maybe);
151 }
152
153 int
154 net_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
155 int *name;
156 u_int namelen;
157 void *oldp;
158 size_t *oldlenp;
159 void *newp;
160 size_t newlen;
161 struct proc *p;
162 {
163 register struct domain *dp;
164 register struct protosw *pr;
165 int family, protocol;
166
167 /*
168 * All sysctl names at this level are nonterminal;
169 * next two components are protocol family and protocol number,
170 * then at least one addition component.
171 */
172 if (namelen < 3)
173 return (EISDIR); /* overloaded */
174 family = name[0];
175 protocol = name[1];
176
177 if (family == 0)
178 return (0);
179 for (dp = domains; dp; dp = dp->dom_next)
180 if (dp->dom_family == family)
181 goto found;
182 return (ENOPROTOOPT);
183 found:
184 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
185 if (pr->pr_protocol == protocol && pr->pr_sysctl)
186 return ((*pr->pr_sysctl)(name + 2, namelen - 2,
187 oldp, oldlenp, newp, newlen));
188 return (ENOPROTOOPT);
189 }
190
191 void
192 pfctlinput(cmd, sa)
193 int cmd;
194 struct sockaddr *sa;
195 {
196 register struct domain *dp;
197 register struct protosw *pr;
198
199 for (dp = domains; dp; dp = dp->dom_next)
200 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
201 if (pr->pr_ctlinput)
202 (*pr->pr_ctlinput)(cmd, sa, (caddr_t)0);
203 }
204
205 void
206 pfslowtimo(arg)
207 void *arg;
208 {
209 register struct domain *dp;
210 register struct protosw *pr;
211
212 for (dp = domains; dp; dp = dp->dom_next)
213 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
214 if (pr->pr_slowtimo)
215 (*pr->pr_slowtimo)();
216 timeout(pfslowtimo, (void *)0, hz/2);
217 }
218
219 void
220 pffasttimo(arg)
221 void *arg;
222 {
223 register struct domain *dp;
224 register struct protosw *pr;
225
226 for (dp = domains; dp; dp = dp->dom_next)
227 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
228 if (pr->pr_fasttimo)
229 (*pr->pr_fasttimo)();
230 timeout(pffasttimo, (void *)0, hz/5);
231 }