Commit | Line | Data |
---|---|---|
15637ed4 RG |
1 | /* |
2 | * Copyright (c) 1982, 1986 Regents of the University of California. | |
3 | * 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 | * | |
600f7f07 RG |
33 | * from: @(#)uipc_domain.c 7.9 (Berkeley) 3/4/91 |
34 | * $Id$ | |
15637ed4 RG |
35 | */ |
36 | ||
37 | #include <sys/cdefs.h> | |
38 | #include "param.h" | |
39 | #include "socket.h" | |
40 | #include "protosw.h" | |
41 | #include "domain.h" | |
42 | #include "mbuf.h" | |
43 | #include "time.h" | |
44 | #include "kernel.h" | |
45 | ||
46 | #define ADDDOMAIN(x) { \ | |
47 | extern struct domain __CONCAT(x,domain); \ | |
48 | __CONCAT(x,domain.dom_next) = domains; \ | |
49 | domains = &__CONCAT(x,domain); \ | |
50 | } | |
51 | ||
52 | domaininit() | |
53 | { | |
54 | register struct domain *dp; | |
55 | register struct protosw *pr; | |
56 | ||
57 | #undef unix | |
58 | #ifndef lint | |
59 | ADDDOMAIN(unix); | |
60 | ADDDOMAIN(route); | |
61 | #ifdef INET | |
62 | ADDDOMAIN(inet); | |
63 | #endif | |
64 | #ifdef NS | |
65 | ADDDOMAIN(ns); | |
66 | #endif | |
67 | #ifdef ISO | |
68 | ADDDOMAIN(iso); | |
69 | #endif | |
70 | #ifdef RMP | |
71 | ADDDOMAIN(rmp); | |
72 | #endif | |
73 | #ifdef CCITT | |
74 | ADDDOMAIN(ccitt); | |
75 | #endif | |
76 | #include "imp.h" | |
77 | #if NIMP > 0 | |
78 | ADDDOMAIN(imp); | |
79 | #endif | |
80 | #endif | |
81 | ||
82 | for (dp = domains; dp; dp = dp->dom_next) { | |
83 | if (dp->dom_init) | |
84 | (*dp->dom_init)(); | |
85 | for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) | |
86 | if (pr->pr_init) | |
87 | (*pr->pr_init)(); | |
88 | } | |
89 | ||
90 | if (max_linkhdr < 16) /* XXX */ | |
91 | max_linkhdr = 16; | |
92 | max_hdr = max_linkhdr + max_protohdr; | |
93 | max_datalen = MHLEN - max_hdr; | |
94 | pffasttimo(); | |
95 | pfslowtimo(); | |
96 | } | |
97 | ||
98 | struct protosw * | |
99 | pffindtype(family, type) | |
100 | int family, type; | |
101 | { | |
102 | register struct domain *dp; | |
103 | register struct protosw *pr; | |
104 | ||
105 | for (dp = domains; dp; dp = dp->dom_next) | |
106 | if (dp->dom_family == family) | |
107 | goto found; | |
108 | return (0); | |
109 | found: | |
110 | for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) | |
111 | if (pr->pr_type && pr->pr_type == type) | |
112 | return (pr); | |
113 | return (0); | |
114 | } | |
115 | ||
116 | struct protosw * | |
117 | pffindproto(family, protocol, type) | |
118 | int family, protocol, type; | |
119 | { | |
120 | register struct domain *dp; | |
121 | register struct protosw *pr; | |
122 | struct protosw *maybe = 0; | |
123 | ||
124 | if (family == 0) | |
125 | return (0); | |
126 | for (dp = domains; dp; dp = dp->dom_next) | |
127 | if (dp->dom_family == family) | |
128 | goto found; | |
129 | return (0); | |
130 | found: | |
131 | for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) { | |
132 | if ((pr->pr_protocol == protocol) && (pr->pr_type == type)) | |
133 | return (pr); | |
134 | ||
135 | if (type == SOCK_RAW && pr->pr_type == SOCK_RAW && | |
136 | pr->pr_protocol == 0 && maybe == (struct protosw *)0) | |
137 | maybe = pr; | |
138 | } | |
139 | return (maybe); | |
140 | } | |
141 | ||
142 | pfctlinput(cmd, sa) | |
143 | int cmd; | |
144 | struct sockaddr *sa; | |
145 | { | |
146 | register struct domain *dp; | |
147 | register struct protosw *pr; | |
148 | ||
149 | for (dp = domains; dp; dp = dp->dom_next) | |
150 | for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) | |
151 | if (pr->pr_ctlinput) | |
152 | (*pr->pr_ctlinput)(cmd, sa, (caddr_t) 0); | |
153 | } | |
154 | ||
155 | pfslowtimo() | |
156 | { | |
157 | register struct domain *dp; | |
158 | register struct protosw *pr; | |
159 | ||
160 | for (dp = domains; dp; dp = dp->dom_next) | |
161 | for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) | |
162 | if (pr->pr_slowtimo) | |
163 | (*pr->pr_slowtimo)(); | |
164 | timeout(pfslowtimo, (caddr_t)0, hz/2); | |
165 | } | |
166 | ||
167 | pffasttimo() | |
168 | { | |
169 | register struct domain *dp; | |
170 | register struct protosw *pr; | |
171 | ||
172 | for (dp = domains; dp; dp = dp->dom_next) | |
173 | for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) | |
174 | if (pr->pr_fasttimo) | |
175 | (*pr->pr_fasttimo)(); | |
176 | timeout(pffasttimo, (caddr_t)0, hz/5); | |
177 | } |