revert between 56095 -> 55830 in arch
[AROS.git] / workbench / network / stacks / AROSTCP / bsdsocket / kern / uipc_domain.c
blobbd7de097800e8e55741a5a0c0e4d9289cbe6f2fb
1 /*
2 * Copyright (C) 1993 AmiTCP/IP Group, <amitcp-group@hut.fi>
3 * Helsinki University of Technology, Finland.
4 * All rights reserved.
5 * Copyright (C) 2005 Neil Cafferkey
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
19 * MA 02111-1307, USA.
24 * Copyright (c) 1982, 1986 Regents of the University of California.
25 * All rights reserved.
27 * Redistribution and use in source and binary forms, with or without
28 * modification, are permitted provided that the following conditions
29 * are met:
30 * 1. Redistributions of source code must retain the above copyright
31 * notice, this list of conditions and the following disclaimer.
32 * 2. Redistributions in binary form must reproduce the above copyright
33 * notice, this list of conditions and the following disclaimer in the
34 * documentation and/or other materials provided with the distribution.
35 * 3. All advertising materials mentioning features or use of this software
36 * must display the following acknowledgement:
37 * This product includes software developed by the University of
38 * California, Berkeley and its contributors.
39 * 4. Neither the name of the University nor the names of its contributors
40 * may be used to endorse or promote products derived from this software
41 * without specific prior written permission.
43 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
44 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
46 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
47 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
48 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
49 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
51 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
52 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
53 * SUCH DAMAGE.
55 * @(#)uipc_domain.c 7.9 (Berkeley) 3/4/91
58 #include <conf.h>
60 #include <sys/param.h>
61 #include <sys/socket.h>
62 #include <sys/protosw.h>
63 #include <sys/domain.h>
64 #include <sys/mbuf.h>
65 #include <sys/kernel.h>
67 #include <kern/amiga_includes.h>
68 #include <kern/uipc_domain_protos.h>
70 /* --- start moved from sys/domain.h --- */
71 struct domain *domains = NULL;
72 /* --- end moved from sys/domain.h --- */
74 static BOOL domain_initialized = FALSE;
76 #define ADDDOMAIN(x) { \
77 extern struct domain __CONCAT(x,domain); \
78 __CONCAT(x,domain.dom_next) = domains; \
79 domains = &__CONCAT(x,domain); \
82 BOOL
83 domaininit()
85 register struct domain *dp;
86 register struct protosw *pr;
88 if (domain_initialized)
89 return TRUE;
91 #undef unix
92 #ifndef AMITCP
93 ADDDOMAIN(unix);
94 #endif /* AMITCP */
95 ADDDOMAIN(route);
96 #if INET
97 ADDDOMAIN(inet);
98 #endif
99 #if NS
100 ADDDOMAIN(ns);
101 #endif
102 #if ISO
103 ADDDOMAIN(iso);
104 #endif
105 #if RMP
106 ADDDOMAIN(rmp);
107 #endif
108 #if CCITT
109 ADDDOMAIN(ccitt);
110 #endif
111 #if NIMP > 0
112 ADDDOMAIN(imp);
113 #endif
115 for (dp = domains; dp; dp = dp->dom_next) {
116 if (dp->dom_init)
117 (*dp->dom_init)();
118 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
119 if (pr->pr_init)
120 (*pr->pr_init)();
122 #ifdef AMITCP
124 * No space needed for the link header with SanaII drivers
126 max_linkhdr = 0;
127 #else
128 if (max_linkhdr < 16) /* XXX */
129 max_linkhdr = 16;
130 #endif
131 max_hdr = max_linkhdr + max_protohdr;
132 max_datalen = MHLEN - max_hdr;
134 #ifndef AMITCP
136 * Timeouts are scheduled from amiga_main.c in AmiTCP/IP
138 pffasttimo();
139 pfslowtimo();
140 #endif
141 domain_initialized = TRUE;
142 return TRUE;
145 struct protosw *
146 pffindtype(family, type)
147 int family, type;
149 register struct domain *dp;
150 register struct protosw *pr;
152 for (dp = domains; dp; dp = dp->dom_next)
153 if (dp->dom_family == family)
154 goto found;
155 return (0);
156 found:
157 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
158 if (pr->pr_type && pr->pr_type == type)
159 return (pr);
160 return (0);
163 struct protosw *
164 pffindproto(family, protocol, type)
165 int family, protocol, type;
167 register struct domain *dp;
168 register struct protosw *pr;
169 struct protosw *maybe = 0;
171 if (family == 0)
172 return (0);
173 for (dp = domains; dp; dp = dp->dom_next)
174 if (dp->dom_family == family)
175 goto found;
176 return (0);
177 found:
178 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) {
179 if ((pr->pr_protocol == protocol) && (pr->pr_type == type))
180 return (pr);
182 if (type == SOCK_RAW && pr->pr_type == SOCK_RAW &&
183 pr->pr_protocol == 0 && maybe == (struct protosw *)0)
184 maybe = pr;
186 return (maybe);
189 void
190 pfctlinput(cmd, sa)
191 int cmd;
192 struct sockaddr *sa;
194 register struct domain *dp;
195 register struct protosw *pr;
197 for (dp = domains; dp; dp = dp->dom_next)
198 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
199 if (pr->pr_ctlinput)
200 (*pr->pr_ctlinput)(cmd, sa, (caddr_t) 0);
203 void
204 pfslowtimo()
206 register struct domain *dp;
207 register struct protosw *pr;
209 for (dp = domains; dp; dp = dp->dom_next)
210 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
211 if (pr->pr_slowtimo)
212 (*pr->pr_slowtimo)();
213 #ifndef AMITCP
215 * Timeouts are scheduled from amiga_main.c in AmiTCP/IP
217 timeout(pfslowtimo, (caddr_t)0, hz/2);
218 #endif /* AMITCP */
221 void
222 pffasttimo()
224 register struct domain *dp;
225 register struct protosw *pr;
227 for (dp = domains; dp; dp = dp->dom_next)
228 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
229 if (pr->pr_fasttimo)
230 (*pr->pr_fasttimo)();
231 #ifndef AMITCP
233 * Timeouts are scheduled from amiga_main.c in AmiTCP/IP
235 timeout(pffasttimo, (caddr_t)0, hz/5);
236 #endif /* AMITCP */