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 | * |
2a45cac7 | 17 | * @(#)uipc_domain.c 7.6 (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 | |
2a45cac7 KM |
51 | #ifdef RMP |
52 | ADDDOMAIN(rmp); | |
53 | #endif | |
bd65e3c4 SL |
54 | #include "imp.h" |
55 | #if NIMP > 0 | |
d0d50a86 BJ |
56 | ADDDOMAIN(imp); |
57 | #endif | |
4f083fd7 | 58 | #endif |
d0d50a86 | 59 | |
261a8548 MK |
60 | for (dp = domains; dp; dp = dp->dom_next) { |
61 | if (dp->dom_init) | |
62 | (*dp->dom_init)(); | |
d0d50a86 BJ |
63 | for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) |
64 | if (pr->pr_init) | |
65 | (*pr->pr_init)(); | |
261a8548 | 66 | } |
fe8b0eef MK |
67 | |
68 | if (max_linkhdr < 16) /* XXX */ | |
69 | max_linkhdr = 16; | |
70 | max_hdr = max_linkhdr + max_protohdr; | |
71 | max_datalen = MHLEN - max_hdr; | |
4f083fd7 SL |
72 | pffasttimo(); |
73 | pfslowtimo(); | |
d0d50a86 BJ |
74 | } |
75 | ||
76 | struct protosw * | |
77 | pffindtype(family, type) | |
78 | int family, type; | |
79 | { | |
80 | register struct domain *dp; | |
81 | register struct protosw *pr; | |
82 | ||
83 | for (dp = domains; dp; dp = dp->dom_next) | |
84 | if (dp->dom_family == family) | |
85 | goto found; | |
86 | return (0); | |
87 | found: | |
88 | for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) | |
6cd6d0de | 89 | if (pr->pr_type && pr->pr_type == type) |
d0d50a86 BJ |
90 | return (pr); |
91 | return (0); | |
92 | } | |
93 | ||
94 | struct protosw * | |
9f773c40 MK |
95 | pffindproto(family, protocol, type) |
96 | int family, protocol, type; | |
d0d50a86 BJ |
97 | { |
98 | register struct domain *dp; | |
99 | register struct protosw *pr; | |
9f773c40 | 100 | struct protosw *maybe = 0; |
d0d50a86 BJ |
101 | |
102 | if (family == 0) | |
103 | return (0); | |
104 | for (dp = domains; dp; dp = dp->dom_next) | |
105 | if (dp->dom_family == family) | |
106 | goto found; | |
107 | return (0); | |
108 | found: | |
9f773c40 | 109 | for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) { |
c76325fe | 110 | if ((pr->pr_protocol == protocol) && (pr->pr_type == type)) |
d0d50a86 | 111 | return (pr); |
c76325fe | 112 | |
9f773c40 MK |
113 | if (type == SOCK_RAW && pr->pr_type == SOCK_RAW && |
114 | pr->pr_protocol == 0 && maybe == (struct protosw *)0) | |
115 | maybe = pr; | |
116 | } | |
117 | return (maybe); | |
d0d50a86 BJ |
118 | } |
119 | ||
122d5d84 | 120 | pfctlinput(cmd, sa) |
d0d50a86 | 121 | int cmd; |
122d5d84 | 122 | struct sockaddr *sa; |
d0d50a86 BJ |
123 | { |
124 | register struct domain *dp; | |
125 | register struct protosw *pr; | |
126 | ||
127 | for (dp = domains; dp; dp = dp->dom_next) | |
128 | for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) | |
129 | if (pr->pr_ctlinput) | |
f3ba532d | 130 | (*pr->pr_ctlinput)(cmd, sa, (caddr_t) 0); |
d0d50a86 BJ |
131 | } |
132 | ||
133 | pfslowtimo() | |
134 | { | |
135 | register struct domain *dp; | |
136 | register struct protosw *pr; | |
137 | ||
138 | for (dp = domains; dp; dp = dp->dom_next) | |
139 | for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) | |
140 | if (pr->pr_slowtimo) | |
141 | (*pr->pr_slowtimo)(); | |
4f083fd7 | 142 | timeout(pfslowtimo, (caddr_t)0, hz/2); |
d0d50a86 BJ |
143 | } |
144 | ||
145 | pffasttimo() | |
4147b3f6 | 146 | { |
d0d50a86 BJ |
147 | register struct domain *dp; |
148 | register struct protosw *pr; | |
4147b3f6 | 149 | |
d0d50a86 BJ |
150 | for (dp = domains; dp; dp = dp->dom_next) |
151 | for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) | |
152 | if (pr->pr_fasttimo) | |
153 | (*pr->pr_fasttimo)(); | |
4f083fd7 | 154 | timeout(pffasttimo, (caddr_t)0, hz/5); |
4147b3f6 | 155 | } |