Commit | Line | Data |
---|---|---|
da7c5cc6 | 1 | /* |
0880b18e | 2 | * Copyright (c) 1982, 1986 Regents of the University of California. |
5b519e94 | 3 | * All rights reserved. |
da7c5cc6 | 4 | * |
dbf0c423 | 5 | * %sccs.include.redist.c% |
5b519e94 | 6 | * |
e7d26b7c | 7 | * @(#)uipc_domain.c 7.16 (Berkeley) %G% |
da7c5cc6 | 8 | */ |
2f6bcc97 | 9 | |
38a01dbe KB |
10 | #include <sys/param.h> |
11 | #include <sys/socket.h> | |
12 | #include <sys/protosw.h> | |
13 | #include <sys/domain.h> | |
14 | #include <sys/mbuf.h> | |
15 | #include <sys/time.h> | |
16 | #include <sys/kernel.h> | |
e7d26b7c KM |
17 | #include <sys/proc.h> |
18 | #include <vm/vm.h> | |
5a5992a0 | 19 | #include <sys/sysctl.h> |
d0d50a86 BJ |
20 | |
21 | #define ADDDOMAIN(x) { \ | |
8b32fb71 KB |
22 | extern struct domain __CONCAT(x,domain); \ |
23 | __CONCAT(x,domain.dom_next) = domains; \ | |
24 | domains = &__CONCAT(x,domain); \ | |
d0d50a86 BJ |
25 | } |
26 | ||
27 | domaininit() | |
28 | { | |
4f083fd7 SL |
29 | register struct domain *dp; |
30 | register struct protosw *pr; | |
d0d50a86 | 31 | |
8b32fb71 | 32 | #undef unix |
4f083fd7 | 33 | #ifndef lint |
d0d50a86 | 34 | ADDDOMAIN(unix); |
fe8b0eef | 35 | ADDDOMAIN(route); |
2a04df10 | 36 | #ifdef INET |
d0d50a86 BJ |
37 | ADDDOMAIN(inet); |
38 | #endif | |
6e8408aa KS |
39 | #ifdef NS |
40 | ADDDOMAIN(ns); | |
41 | #endif | |
fe8b0eef MK |
42 | #ifdef ISO |
43 | ADDDOMAIN(iso); | |
44 | #endif | |
6b66c26b KS |
45 | #ifdef CCITT |
46 | ADDDOMAIN(ccitt); | |
47 | #endif | |
bd65e3c4 SL |
48 | #include "imp.h" |
49 | #if NIMP > 0 | |
d0d50a86 BJ |
50 | ADDDOMAIN(imp); |
51 | #endif | |
4f083fd7 | 52 | #endif |
d0d50a86 | 53 | |
261a8548 MK |
54 | for (dp = domains; dp; dp = dp->dom_next) { |
55 | if (dp->dom_init) | |
56 | (*dp->dom_init)(); | |
d0d50a86 BJ |
57 | for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) |
58 | if (pr->pr_init) | |
59 | (*pr->pr_init)(); | |
261a8548 | 60 | } |
fe8b0eef MK |
61 | |
62 | if (max_linkhdr < 16) /* XXX */ | |
63 | max_linkhdr = 16; | |
64 | max_hdr = max_linkhdr + max_protohdr; | |
65 | max_datalen = MHLEN - max_hdr; | |
4f083fd7 SL |
66 | pffasttimo(); |
67 | pfslowtimo(); | |
d0d50a86 BJ |
68 | } |
69 | ||
70 | struct protosw * | |
71 | pffindtype(family, type) | |
72 | int family, type; | |
73 | { | |
74 | register struct domain *dp; | |
75 | register struct protosw *pr; | |
76 | ||
77 | for (dp = domains; dp; dp = dp->dom_next) | |
78 | if (dp->dom_family == family) | |
79 | goto found; | |
80 | return (0); | |
81 | found: | |
82 | for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) | |
6cd6d0de | 83 | if (pr->pr_type && pr->pr_type == type) |
d0d50a86 BJ |
84 | return (pr); |
85 | return (0); | |
86 | } | |
87 | ||
88 | struct protosw * | |
9f773c40 MK |
89 | pffindproto(family, protocol, type) |
90 | int family, protocol, type; | |
d0d50a86 BJ |
91 | { |
92 | register struct domain *dp; | |
93 | register struct protosw *pr; | |
9f773c40 | 94 | struct protosw *maybe = 0; |
d0d50a86 BJ |
95 | |
96 | if (family == 0) | |
97 | return (0); | |
98 | for (dp = domains; dp; dp = dp->dom_next) | |
99 | if (dp->dom_family == family) | |
100 | goto found; | |
101 | return (0); | |
102 | found: | |
9f773c40 | 103 | for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) { |
c76325fe | 104 | if ((pr->pr_protocol == protocol) && (pr->pr_type == type)) |
d0d50a86 | 105 | return (pr); |
c76325fe | 106 | |
9f773c40 MK |
107 | if (type == SOCK_RAW && pr->pr_type == SOCK_RAW && |
108 | pr->pr_protocol == 0 && maybe == (struct protosw *)0) | |
109 | maybe = pr; | |
110 | } | |
111 | return (maybe); | |
d0d50a86 BJ |
112 | } |
113 | ||
25d98c48 | 114 | net_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p) |
5a5992a0 KM |
115 | int *name; |
116 | u_int namelen; | |
117 | void *oldp; | |
51cf4abc | 118 | size_t *oldlenp; |
5a5992a0 | 119 | void *newp; |
51cf4abc | 120 | size_t newlen; |
25d98c48 | 121 | struct proc *p; |
5a5992a0 KM |
122 | { |
123 | register struct domain *dp; | |
124 | register struct protosw *pr; | |
125 | int family, protocol; | |
126 | ||
127 | /* | |
128 | * All sysctl names at this level are nonterminal; | |
129 | * next two components are protocol family and protocol number, | |
130 | * then at least one addition component. | |
131 | */ | |
d6bc2b3b | 132 | if (namelen < 3) |
5a5992a0 KM |
133 | return (EISDIR); /* overloaded */ |
134 | family = name[0]; | |
135 | protocol = name[1]; | |
136 | ||
137 | if (family == 0) | |
138 | return (0); | |
139 | for (dp = domains; dp; dp = dp->dom_next) | |
140 | if (dp->dom_family == family) | |
141 | goto found; | |
142 | return (ENOPROTOOPT); | |
143 | found: | |
144 | for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) | |
145 | if (pr->pr_protocol == protocol && pr->pr_sysctl) | |
146 | return ((*pr->pr_sysctl)(name + 2, namelen - 2, | |
147 | oldp, oldlenp, newp, newlen)); | |
148 | return (ENOPROTOOPT); | |
149 | } | |
150 | ||
122d5d84 | 151 | pfctlinput(cmd, sa) |
d0d50a86 | 152 | int cmd; |
122d5d84 | 153 | struct sockaddr *sa; |
d0d50a86 BJ |
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_ctlinput) | |
f3ba532d | 161 | (*pr->pr_ctlinput)(cmd, sa, (caddr_t) 0); |
d0d50a86 BJ |
162 | } |
163 | ||
164 | pfslowtimo() | |
165 | { | |
166 | register struct domain *dp; | |
167 | register struct protosw *pr; | |
168 | ||
169 | for (dp = domains; dp; dp = dp->dom_next) | |
170 | for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) | |
171 | if (pr->pr_slowtimo) | |
172 | (*pr->pr_slowtimo)(); | |
4f083fd7 | 173 | timeout(pfslowtimo, (caddr_t)0, hz/2); |
d0d50a86 BJ |
174 | } |
175 | ||
176 | pffasttimo() | |
4147b3f6 | 177 | { |
d0d50a86 BJ |
178 | register struct domain *dp; |
179 | register struct protosw *pr; | |
4147b3f6 | 180 | |
d0d50a86 BJ |
181 | for (dp = domains; dp; dp = dp->dom_next) |
182 | for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) | |
183 | if (pr->pr_fasttimo) | |
184 | (*pr->pr_fasttimo)(); | |
4f083fd7 | 185 | timeout(pffasttimo, (caddr_t)0, hz/5); |
4147b3f6 | 186 | } |