uipc_domain.c revision 1.1.1.3 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.3 (Berkeley) 2/14/95
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 #define ADDDOMAIN(x) { \
52 extern struct domain __CONCAT(x,domain); \
53 __CONCAT(x,domain.dom_next) = domains; \
54 domains = &__CONCAT(x,domain); \
55 }
56
57 void
58 domaininit()
59 {
60 register struct domain *dp;
61 register struct protosw *pr;
62
63 #undef unix
64 #ifndef lint
65 ADDDOMAIN(unix);
66 ADDDOMAIN(route);
67 #ifdef INET
68 ADDDOMAIN(inet);
69 #endif
70 #ifdef NS
71 ADDDOMAIN(ns);
72 #endif
73 #ifdef ISO
74 ADDDOMAIN(iso);
75 #endif
76 #ifdef CCITT
77 ADDDOMAIN(ccitt);
78 #endif
79 #include "imp.h"
80 #if NIMP > 0
81 ADDDOMAIN(imp);
82 #endif
83 #endif
84
85 for (dp = domains; dp; dp = dp->dom_next) {
86 if (dp->dom_init)
87 (*dp->dom_init)();
88 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
89 if (pr->pr_init)
90 (*pr->pr_init)();
91 }
92
93 if (max_linkhdr < 16) /* XXX */
94 max_linkhdr = 16;
95 max_hdr = max_linkhdr + max_protohdr;
96 max_datalen = MHLEN - max_hdr;
97 timeout(pffasttimo, NULL, 1);
98 timeout(pfslowtimo, NULL, 1);
99 }
100
101 struct protosw *
102 pffindtype(family, type)
103 int family, type;
104 {
105 register struct domain *dp;
106 register struct protosw *pr;
107
108 for (dp = domains; dp; dp = dp->dom_next)
109 if (dp->dom_family == family)
110 goto found;
111 return (0);
112 found:
113 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
114 if (pr->pr_type && pr->pr_type == type)
115 return (pr);
116 return (0);
117 }
118
119 struct protosw *
120 pffindproto(family, protocol, type)
121 int family, protocol, type;
122 {
123 register struct domain *dp;
124 register struct protosw *pr;
125 struct protosw *maybe = 0;
126
127 if (family == 0)
128 return (0);
129 for (dp = domains; dp; dp = dp->dom_next)
130 if (dp->dom_family == family)
131 goto found;
132 return (0);
133 found:
134 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) {
135 if ((pr->pr_protocol == protocol) && (pr->pr_type == type))
136 return (pr);
137
138 if (type == SOCK_RAW && pr->pr_type == SOCK_RAW &&
139 pr->pr_protocol == 0 && maybe == (struct protosw *)0)
140 maybe = pr;
141 }
142 return (maybe);
143 }
144
145 int
146 net_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
147 int *name;
148 u_int namelen;
149 void *oldp;
150 size_t *oldlenp;
151 void *newp;
152 size_t newlen;
153 struct proc *p;
154 {
155 register struct domain *dp;
156 register struct protosw *pr;
157 int family, protocol;
158
159 /*
160 * All sysctl names at this level are nonterminal;
161 * next two components are protocol family and protocol number,
162 * then at least one addition component.
163 */
164 if (namelen < 3)
165 return (EISDIR); /* overloaded */
166 family = name[0];
167 protocol = name[1];
168
169 if (family == 0)
170 return (0);
171 for (dp = domains; dp; dp = dp->dom_next)
172 if (dp->dom_family == family)
173 goto found;
174 return (ENOPROTOOPT);
175 found:
176 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
177 if (pr->pr_protocol == protocol && pr->pr_sysctl)
178 return ((*pr->pr_sysctl)(name + 2, namelen - 2,
179 oldp, oldlenp, newp, newlen));
180 return (ENOPROTOOPT);
181 }
182
183 void
184 pfctlinput(cmd, sa)
185 int cmd;
186 struct sockaddr *sa;
187 {
188 register struct domain *dp;
189 register struct protosw *pr;
190
191 for (dp = domains; dp; dp = dp->dom_next)
192 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
193 if (pr->pr_ctlinput)
194 (*pr->pr_ctlinput)(cmd, sa, (caddr_t)0);
195 }
196
197 void
198 pfslowtimo(arg)
199 void *arg;
200 {
201 register struct domain *dp;
202 register struct protosw *pr;
203
204 for (dp = domains; dp; dp = dp->dom_next)
205 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
206 if (pr->pr_slowtimo)
207 (*pr->pr_slowtimo)();
208 timeout(pfslowtimo, NULL, hz/2);
209 }
210
211 void
212 pffasttimo(arg)
213 void *arg;
214 {
215 register struct domain *dp;
216 register struct protosw *pr;
217
218 for (dp = domains; dp; dp = dp->dom_next)
219 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
220 if (pr->pr_fasttimo)
221 (*pr->pr_fasttimo)();
222 timeout(pffasttimo, NULL, hz/5);
223 }
224