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