Commit | Line | Data |
---|---|---|
da7c5cc6 | 1 | /* |
0880b18e | 2 | * Copyright (c) 1982, 1986 Regents of the University of California. |
5b519e94 | 3 | * All rights reserved. |
da7c5cc6 | 4 | * |
5b519e94 | 5 | * Redistribution and use in source and binary forms are permitted |
616d42db KB |
6 | * provided that the above copyright notice and this paragraph are |
7 | * duplicated in all such forms and that any documentation, | |
8 | * advertising materials, and other materials related to such | |
9 | * distribution and use acknowledge that the software was developed | |
10 | * by the University of California, Berkeley. The name of the | |
11 | * University may not be used to endorse or promote products derived | |
12 | * from this software without specific prior written permission. | |
13 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR | |
14 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED | |
15 | * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. | |
5b519e94 | 16 | * |
fe8b0eef | 17 | * @(#)uipc_domain.c 7.4 (Berkeley) %G% |
da7c5cc6 | 18 | */ |
2f6bcc97 | 19 | |
94368568 JB |
20 | #include "param.h" |
21 | #include "socket.h" | |
22 | #include "protosw.h" | |
23 | #include "domain.h" | |
fe8b0eef | 24 | #include "mbuf.h" |
94368568 JB |
25 | #include "time.h" |
26 | #include "kernel.h" | |
d0d50a86 BJ |
27 | |
28 | #define ADDDOMAIN(x) { \ | |
29 | extern struct domain x/**/domain; \ | |
30 | x/**/domain.dom_next = domains; \ | |
31 | domains = &x/**/domain; \ | |
32 | } | |
33 | ||
34 | domaininit() | |
35 | { | |
4f083fd7 SL |
36 | register struct domain *dp; |
37 | register struct protosw *pr; | |
d0d50a86 | 38 | |
4f083fd7 | 39 | #ifndef lint |
d0d50a86 | 40 | ADDDOMAIN(unix); |
fe8b0eef | 41 | ADDDOMAIN(route); |
2a04df10 | 42 | #ifdef INET |
d0d50a86 BJ |
43 | ADDDOMAIN(inet); |
44 | #endif | |
6e8408aa KS |
45 | #ifdef NS |
46 | ADDDOMAIN(ns); | |
47 | #endif | |
fe8b0eef MK |
48 | #ifdef ISO |
49 | ADDDOMAIN(iso); | |
50 | #endif | |
bd65e3c4 SL |
51 | #include "imp.h" |
52 | #if NIMP > 0 | |
d0d50a86 BJ |
53 | ADDDOMAIN(imp); |
54 | #endif | |
4f083fd7 | 55 | #endif |
d0d50a86 | 56 | |
261a8548 MK |
57 | for (dp = domains; dp; dp = dp->dom_next) { |
58 | if (dp->dom_init) | |
59 | (*dp->dom_init)(); | |
d0d50a86 BJ |
60 | for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) |
61 | if (pr->pr_init) | |
62 | (*pr->pr_init)(); | |
261a8548 | 63 | } |
fe8b0eef MK |
64 | |
65 | if (max_linkhdr < 16) /* XXX */ | |
66 | max_linkhdr = 16; | |
67 | max_hdr = max_linkhdr + max_protohdr; | |
68 | max_datalen = MHLEN - max_hdr; | |
4f083fd7 SL |
69 | pffasttimo(); |
70 | pfslowtimo(); | |
d0d50a86 BJ |
71 | } |
72 | ||
73 | struct protosw * | |
74 | pffindtype(family, type) | |
75 | int family, type; | |
76 | { | |
77 | register struct domain *dp; | |
78 | register struct protosw *pr; | |
79 | ||
80 | for (dp = domains; dp; dp = dp->dom_next) | |
81 | if (dp->dom_family == family) | |
82 | goto found; | |
83 | return (0); | |
84 | found: | |
85 | for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) | |
6cd6d0de | 86 | if (pr->pr_type && pr->pr_type == type) |
d0d50a86 BJ |
87 | return (pr); |
88 | return (0); | |
89 | } | |
90 | ||
91 | struct protosw * | |
9f773c40 MK |
92 | pffindproto(family, protocol, type) |
93 | int family, protocol, type; | |
d0d50a86 BJ |
94 | { |
95 | register struct domain *dp; | |
96 | register struct protosw *pr; | |
9f773c40 | 97 | struct protosw *maybe = 0; |
d0d50a86 BJ |
98 | |
99 | if (family == 0) | |
100 | return (0); | |
101 | for (dp = domains; dp; dp = dp->dom_next) | |
102 | if (dp->dom_family == family) | |
103 | goto found; | |
104 | return (0); | |
105 | found: | |
9f773c40 | 106 | for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) { |
c76325fe | 107 | if ((pr->pr_protocol == protocol) && (pr->pr_type == type)) |
d0d50a86 | 108 | return (pr); |
c76325fe | 109 | |
9f773c40 MK |
110 | if (type == SOCK_RAW && pr->pr_type == SOCK_RAW && |
111 | pr->pr_protocol == 0 && maybe == (struct protosw *)0) | |
112 | maybe = pr; | |
113 | } | |
114 | return (maybe); | |
d0d50a86 BJ |
115 | } |
116 | ||
122d5d84 | 117 | pfctlinput(cmd, sa) |
d0d50a86 | 118 | int cmd; |
122d5d84 | 119 | struct sockaddr *sa; |
d0d50a86 BJ |
120 | { |
121 | register struct domain *dp; | |
122 | register struct protosw *pr; | |
123 | ||
124 | for (dp = domains; dp; dp = dp->dom_next) | |
125 | for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) | |
126 | if (pr->pr_ctlinput) | |
122d5d84 | 127 | (*pr->pr_ctlinput)(cmd, sa); |
d0d50a86 BJ |
128 | } |
129 | ||
130 | pfslowtimo() | |
131 | { | |
132 | register struct domain *dp; | |
133 | register struct protosw *pr; | |
134 | ||
135 | for (dp = domains; dp; dp = dp->dom_next) | |
136 | for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) | |
137 | if (pr->pr_slowtimo) | |
138 | (*pr->pr_slowtimo)(); | |
4f083fd7 | 139 | timeout(pfslowtimo, (caddr_t)0, hz/2); |
d0d50a86 BJ |
140 | } |
141 | ||
142 | pffasttimo() | |
4147b3f6 | 143 | { |
d0d50a86 BJ |
144 | register struct domain *dp; |
145 | register struct protosw *pr; | |
4147b3f6 | 146 | |
d0d50a86 BJ |
147 | for (dp = domains; dp; dp = dp->dom_next) |
148 | for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) | |
149 | if (pr->pr_fasttimo) | |
150 | (*pr->pr_fasttimo)(); | |
4f083fd7 | 151 | timeout(pffasttimo, (caddr_t)0, hz/5); |
4147b3f6 | 152 | } |