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