Commit | Line | Data |
---|---|---|
da7c5cc6 KM |
1 | /* |
2 | * Copyright (c) 1982 Regents of the University of California. | |
3 | * All rights reserved. The Berkeley software License Agreement | |
4 | * specifies the terms and conditions for redistribution. | |
5 | * | |
c76325fe | 6 | * @(#)uipc_domain.c 6.7 (Berkeley) %G% |
da7c5cc6 | 7 | */ |
2f6bcc97 | 8 | |
94368568 JB |
9 | #include "param.h" |
10 | #include "socket.h" | |
11 | #include "protosw.h" | |
12 | #include "domain.h" | |
13 | #include "time.h" | |
14 | #include "kernel.h" | |
d0d50a86 BJ |
15 | |
16 | #define ADDDOMAIN(x) { \ | |
17 | extern struct domain x/**/domain; \ | |
18 | x/**/domain.dom_next = domains; \ | |
19 | domains = &x/**/domain; \ | |
20 | } | |
21 | ||
22 | domaininit() | |
23 | { | |
4f083fd7 SL |
24 | register struct domain *dp; |
25 | register struct protosw *pr; | |
d0d50a86 | 26 | |
4f083fd7 | 27 | #ifndef lint |
d0d50a86 BJ |
28 | ADDDOMAIN(unix); |
29 | #ifdef INET | |
30 | ADDDOMAIN(inet); | |
31 | #endif | |
6e8408aa KS |
32 | #ifdef NS |
33 | ADDDOMAIN(ns); | |
34 | #endif | |
d0d50a86 BJ |
35 | #ifdef PUP |
36 | ADDDOMAIN(pup); | |
37 | #endif | |
bd65e3c4 SL |
38 | #include "imp.h" |
39 | #if NIMP > 0 | |
d0d50a86 BJ |
40 | ADDDOMAIN(imp); |
41 | #endif | |
4f083fd7 | 42 | #endif |
d0d50a86 | 43 | |
261a8548 MK |
44 | for (dp = domains; dp; dp = dp->dom_next) { |
45 | if (dp->dom_init) | |
46 | (*dp->dom_init)(); | |
d0d50a86 BJ |
47 | for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) |
48 | if (pr->pr_init) | |
49 | (*pr->pr_init)(); | |
261a8548 | 50 | } |
4f083fd7 SL |
51 | pffasttimo(); |
52 | pfslowtimo(); | |
d0d50a86 BJ |
53 | } |
54 | ||
55 | struct protosw * | |
56 | pffindtype(family, type) | |
57 | int family, type; | |
58 | { | |
59 | register struct domain *dp; | |
60 | register struct protosw *pr; | |
61 | ||
62 | for (dp = domains; dp; dp = dp->dom_next) | |
63 | if (dp->dom_family == family) | |
64 | goto found; | |
65 | return (0); | |
66 | found: | |
67 | for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) | |
6cd6d0de | 68 | if (pr->pr_type && pr->pr_type == type) |
d0d50a86 BJ |
69 | return (pr); |
70 | return (0); | |
71 | } | |
72 | ||
73 | struct protosw * | |
9f773c40 MK |
74 | pffindproto(family, protocol, type) |
75 | int family, protocol, type; | |
d0d50a86 BJ |
76 | { |
77 | register struct domain *dp; | |
78 | register struct protosw *pr; | |
9f773c40 | 79 | struct protosw *maybe = 0; |
d0d50a86 BJ |
80 | |
81 | if (family == 0) | |
82 | return (0); | |
83 | for (dp = domains; dp; dp = dp->dom_next) | |
84 | if (dp->dom_family == family) | |
85 | goto found; | |
86 | return (0); | |
87 | found: | |
9f773c40 | 88 | for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) { |
c76325fe | 89 | if ((pr->pr_protocol == protocol) && (pr->pr_type == type)) |
d0d50a86 | 90 | return (pr); |
c76325fe | 91 | |
9f773c40 MK |
92 | if (type == SOCK_RAW && pr->pr_type == SOCK_RAW && |
93 | pr->pr_protocol == 0 && maybe == (struct protosw *)0) | |
94 | maybe = pr; | |
95 | } | |
96 | return (maybe); | |
d0d50a86 BJ |
97 | } |
98 | ||
99 | pfctlinput(cmd, arg) | |
100 | int cmd; | |
101 | caddr_t arg; | |
102 | { | |
103 | register struct domain *dp; | |
104 | register struct protosw *pr; | |
105 | ||
106 | for (dp = domains; dp; dp = dp->dom_next) | |
107 | for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) | |
108 | if (pr->pr_ctlinput) | |
109 | (*pr->pr_ctlinput)(cmd, arg); | |
110 | } | |
111 | ||
112 | pfslowtimo() | |
113 | { | |
114 | register struct domain *dp; | |
115 | register struct protosw *pr; | |
116 | ||
117 | for (dp = domains; dp; dp = dp->dom_next) | |
118 | for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) | |
119 | if (pr->pr_slowtimo) | |
120 | (*pr->pr_slowtimo)(); | |
4f083fd7 | 121 | timeout(pfslowtimo, (caddr_t)0, hz/2); |
d0d50a86 BJ |
122 | } |
123 | ||
124 | pffasttimo() | |
4147b3f6 | 125 | { |
d0d50a86 BJ |
126 | register struct domain *dp; |
127 | register struct protosw *pr; | |
4147b3f6 | 128 | |
d0d50a86 BJ |
129 | for (dp = domains; dp; dp = dp->dom_next) |
130 | for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) | |
131 | if (pr->pr_fasttimo) | |
132 | (*pr->pr_fasttimo)(); | |
4f083fd7 | 133 | timeout(pffasttimo, (caddr_t)0, hz/5); |
4147b3f6 | 134 | } |