uipc_domain.c revision 1.2 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 #ifdef IMP
76 ADDDOMAIN(imp);
77 #endif
78 #endif
79
80 for (dp = domains; dp; dp = dp->dom_next) {
81 if (dp->dom_init)
82 (*dp->dom_init)();
83 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
84 if (pr->pr_init)
85 (*pr->pr_init)();
86 }
87
88 if (max_linkhdr < 16) /* XXX */
89 max_linkhdr = 16;
90 max_hdr = max_linkhdr + max_protohdr;
91 max_datalen = MHLEN - max_hdr;
92 pffasttimo();
93 pfslowtimo();
94 }
95
96 struct protosw *
97 pffindtype(family, type)
98 int family, type;
99 {
100 register struct domain *dp;
101 register struct protosw *pr;
102
103 for (dp = domains; dp; dp = dp->dom_next)
104 if (dp->dom_family == family)
105 goto found;
106 return (0);
107 found:
108 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
109 if (pr->pr_type && pr->pr_type == type)
110 return (pr);
111 return (0);
112 }
113
114 struct protosw *
115 pffindproto(family, protocol, type)
116 int family, protocol, type;
117 {
118 register struct domain *dp;
119 register struct protosw *pr;
120 struct protosw *maybe = 0;
121
122 if (family == 0)
123 return (0);
124 for (dp = domains; dp; dp = dp->dom_next)
125 if (dp->dom_family == family)
126 goto found;
127 return (0);
128 found:
129 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) {
130 if ((pr->pr_protocol == protocol) && (pr->pr_type == type))
131 return (pr);
132
133 if (type == SOCK_RAW && pr->pr_type == SOCK_RAW &&
134 pr->pr_protocol == 0 && maybe == (struct protosw *)0)
135 maybe = pr;
136 }
137 return (maybe);
138 }
139
140 pfctlinput(cmd, sa)
141 int cmd;
142 struct sockaddr *sa;
143 {
144 register struct domain *dp;
145 register struct protosw *pr;
146
147 for (dp = domains; dp; dp = dp->dom_next)
148 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
149 if (pr->pr_ctlinput)
150 (*pr->pr_ctlinput)(cmd, sa, (caddr_t) 0);
151 }
152
153 pfslowtimo()
154 {
155 register struct domain *dp;
156 register struct protosw *pr;
157
158 for (dp = domains; dp; dp = dp->dom_next)
159 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
160 if (pr->pr_slowtimo)
161 (*pr->pr_slowtimo)();
162 timeout(pfslowtimo, (caddr_t)0, hz/2);
163 }
164
165 pffasttimo()
166 {
167 register struct domain *dp;
168 register struct protosw *pr;
169
170 for (dp = domains; dp; dp = dp->dom_next)
171 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
172 if (pr->pr_fasttimo)
173 (*pr->pr_fasttimo)();
174 timeout(pffasttimo, (caddr_t)0, hz/5);
175 }
176