This source file includes following definitions.
- domaininit
- pffinddomain
- pffindtype
- pffindproto
- net_sysctl
- pfctlinput
- pfslowtimo
- pffasttimo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 #include <sys/param.h>
36 #include <sys/socket.h>
37 #include <sys/protosw.h>
38 #include <sys/domain.h>
39 #include <sys/mbuf.h>
40 #include <sys/time.h>
41 #include <sys/kernel.h>
42 #include <sys/systm.h>
43 #include <sys/proc.h>
44 #include <uvm/uvm_extern.h>
45 #include <sys/sysctl.h>
46 #include <sys/timeout.h>
47
48 #include "bluetooth.h"
49 #include "bpfilter.h"
50
51 struct domain *domains;
52
53 void pffasttimo(void *);
54 void pfslowtimo(void *);
55 struct domain * pffinddomain(int);
56
57 #if defined (KEY) || defined (IPSEC) || defined (TCP_SIGNATURE)
58 int pfkey_init(void);
59 #endif
60
61 #define ADDDOMAIN(x) { \
62 extern struct domain __CONCAT(x,domain); \
63 __CONCAT(x,domain.dom_next) = domains; \
64 domains = &__CONCAT(x,domain); \
65 }
66
67 void
68 domaininit(void)
69 {
70 struct domain *dp;
71 struct protosw *pr;
72 static struct timeout pffast_timeout;
73 static struct timeout pfslow_timeout;
74
75 #undef unix
76
77
78
79
80 #ifndef lint
81 ADDDOMAIN(unix);
82 #ifdef INET
83 ADDDOMAIN(inet);
84 #endif
85 #ifdef INET6
86 ADDDOMAIN(inet6);
87 #endif
88 #if defined (KEY) || defined (IPSEC) || defined (TCP_SIGNATURE)
89 pfkey_init();
90 #endif
91 #ifdef NETATALK
92 ADDDOMAIN(atalk);
93 #endif
94 #ifdef NATM
95 ADDDOMAIN(natm);
96 #endif
97 #ifdef IPSEC
98 #ifdef __KAME__
99 ADDDOMAIN(key);
100 #endif
101 #endif
102 #if NBLUETOOTH > 0
103 ADDDOMAIN(bt);
104 #endif
105 ADDDOMAIN(route);
106 #endif
107
108 for (dp = domains; dp; dp = dp->dom_next) {
109 if (dp->dom_init)
110 (*dp->dom_init)();
111 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
112 if (pr->pr_init)
113 (*pr->pr_init)();
114 }
115
116 if (max_linkhdr < 16)
117 max_linkhdr = 16;
118 max_hdr = max_linkhdr + max_protohdr;
119 max_datalen = MHLEN - max_hdr;
120 timeout_set(&pffast_timeout, pffasttimo, &pffast_timeout);
121 timeout_set(&pfslow_timeout, pfslowtimo, &pfslow_timeout);
122 timeout_add(&pffast_timeout, 1);
123 timeout_add(&pfslow_timeout, 1);
124 }
125
126 struct domain *
127 pffinddomain(int family)
128 {
129 struct domain *dp;
130
131 for (dp = domains; dp != NULL; dp = dp->dom_next)
132 if (dp->dom_family == family)
133 return (dp);
134 return (NULL);
135 }
136
137 struct protosw *
138 pffindtype(int family, int type)
139 {
140 struct domain *dp;
141 struct protosw *pr;
142
143 dp = pffinddomain(family);
144 if (dp == NULL)
145 return (NULL);
146
147 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
148 if (pr->pr_type && pr->pr_type == type)
149 return (pr);
150 return (NULL);
151 }
152
153 struct protosw *
154 pffindproto(int family, int protocol, int type)
155 {
156 struct domain *dp;
157 struct protosw *pr;
158 struct protosw *maybe = NULL;
159
160 if (family == 0)
161 return (NULL);
162
163 dp = pffinddomain(family);
164 if (dp == NULL)
165 return (NULL);
166
167 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) {
168 if ((pr->pr_protocol == protocol) && (pr->pr_type == type))
169 return (pr);
170
171 if (type == SOCK_RAW && pr->pr_type == SOCK_RAW &&
172 pr->pr_protocol == 0 && maybe == NULL)
173 maybe = pr;
174 }
175 return (maybe);
176 }
177
178 int
179 net_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp,
180 size_t newlen, struct proc *p)
181 {
182 struct domain *dp;
183 struct protosw *pr;
184 int family, protocol;
185
186
187
188
189
190
191 if (namelen < 2)
192 return (EISDIR);
193 family = name[0];
194
195 if (family == 0)
196 return (0);
197 #if NBPFILTER > 0
198 if (family == PF_BPF)
199 return (bpf_sysctl(name + 1, namelen - 1, oldp, oldlenp,
200 newp, newlen));
201 #endif
202 dp = pffinddomain(family);
203 if (dp == NULL)
204 return (ENOPROTOOPT);
205
206 if (namelen < 3)
207 return (EISDIR);
208 protocol = name[1];
209 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
210 if (pr->pr_protocol == protocol && pr->pr_sysctl)
211 return ((*pr->pr_sysctl)(name + 2, namelen - 2,
212 oldp, oldlenp, newp, newlen));
213 return (ENOPROTOOPT);
214 }
215
216 void
217 pfctlinput(int cmd, struct sockaddr *sa)
218 {
219 struct domain *dp;
220 struct protosw *pr;
221
222 for (dp = domains; dp; dp = dp->dom_next)
223 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
224 if (pr->pr_ctlinput)
225 (*pr->pr_ctlinput)(cmd, sa, NULL);
226 }
227
228 void
229 pfslowtimo(void *arg)
230 {
231 struct timeout *to = (struct timeout *)arg;
232 struct domain *dp;
233 struct protosw *pr;
234
235 for (dp = domains; dp; dp = dp->dom_next)
236 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
237 if (pr->pr_slowtimo)
238 (*pr->pr_slowtimo)();
239 timeout_add(to, hz/2);
240 }
241
242 void
243 pffasttimo(void *arg)
244 {
245 struct timeout *to = (struct timeout *)arg;
246 struct domain *dp;
247 struct protosw *pr;
248
249 for (dp = domains; dp; dp = dp->dom_next)
250 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
251 if (pr->pr_fasttimo)
252 (*pr->pr_fasttimo)();
253 timeout_add(to, hz/5);
254 }