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 | * | |
2a04df10 | 6 | * @(#)uipc_domain.c 6.9 (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 | 28 | ADDDOMAIN(unix); |
2a04df10 | 29 | #ifdef INET |
d0d50a86 BJ |
30 | ADDDOMAIN(inet); |
31 | #endif | |
6e8408aa KS |
32 | #ifdef NS |
33 | ADDDOMAIN(ns); | |
34 | #endif | |
bd65e3c4 SL |
35 | #include "imp.h" |
36 | #if NIMP > 0 | |
d0d50a86 BJ |
37 | ADDDOMAIN(imp); |
38 | #endif | |
4f083fd7 | 39 | #endif |
d0d50a86 | 40 | |
261a8548 MK |
41 | for (dp = domains; dp; dp = dp->dom_next) { |
42 | if (dp->dom_init) | |
43 | (*dp->dom_init)(); | |
d0d50a86 BJ |
44 | for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) |
45 | if (pr->pr_init) | |
46 | (*pr->pr_init)(); | |
261a8548 | 47 | } |
4f083fd7 SL |
48 | pffasttimo(); |
49 | pfslowtimo(); | |
d0d50a86 BJ |
50 | } |
51 | ||
52 | struct protosw * | |
53 | pffindtype(family, type) | |
54 | int family, type; | |
55 | { | |
56 | register struct domain *dp; | |
57 | register struct protosw *pr; | |
58 | ||
59 | for (dp = domains; dp; dp = dp->dom_next) | |
60 | if (dp->dom_family == family) | |
61 | goto found; | |
62 | return (0); | |
63 | found: | |
64 | for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) | |
6cd6d0de | 65 | if (pr->pr_type && pr->pr_type == type) |
d0d50a86 BJ |
66 | return (pr); |
67 | return (0); | |
68 | } | |
69 | ||
70 | struct protosw * | |
9f773c40 MK |
71 | pffindproto(family, protocol, type) |
72 | int family, protocol, type; | |
d0d50a86 BJ |
73 | { |
74 | register struct domain *dp; | |
75 | register struct protosw *pr; | |
9f773c40 | 76 | struct protosw *maybe = 0; |
d0d50a86 BJ |
77 | |
78 | if (family == 0) | |
79 | return (0); | |
80 | for (dp = domains; dp; dp = dp->dom_next) | |
81 | if (dp->dom_family == family) | |
82 | goto found; | |
83 | return (0); | |
84 | found: | |
9f773c40 | 85 | for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) { |
c76325fe | 86 | if ((pr->pr_protocol == protocol) && (pr->pr_type == type)) |
d0d50a86 | 87 | return (pr); |
c76325fe | 88 | |
9f773c40 MK |
89 | if (type == SOCK_RAW && pr->pr_type == SOCK_RAW && |
90 | pr->pr_protocol == 0 && maybe == (struct protosw *)0) | |
91 | maybe = pr; | |
92 | } | |
93 | return (maybe); | |
d0d50a86 BJ |
94 | } |
95 | ||
122d5d84 | 96 | pfctlinput(cmd, sa) |
d0d50a86 | 97 | int cmd; |
122d5d84 | 98 | struct sockaddr *sa; |
d0d50a86 BJ |
99 | { |
100 | register struct domain *dp; | |
101 | register struct protosw *pr; | |
102 | ||
103 | for (dp = domains; dp; dp = dp->dom_next) | |
104 | for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) | |
105 | if (pr->pr_ctlinput) | |
122d5d84 | 106 | (*pr->pr_ctlinput)(cmd, sa); |
d0d50a86 BJ |
107 | } |
108 | ||
109 | pfslowtimo() | |
110 | { | |
111 | register struct domain *dp; | |
112 | register struct protosw *pr; | |
113 | ||
114 | for (dp = domains; dp; dp = dp->dom_next) | |
115 | for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) | |
116 | if (pr->pr_slowtimo) | |
117 | (*pr->pr_slowtimo)(); | |
4f083fd7 | 118 | timeout(pfslowtimo, (caddr_t)0, hz/2); |
d0d50a86 BJ |
119 | } |
120 | ||
121 | pffasttimo() | |
4147b3f6 | 122 | { |
d0d50a86 BJ |
123 | register struct domain *dp; |
124 | register struct protosw *pr; | |
4147b3f6 | 125 | |
d0d50a86 BJ |
126 | for (dp = domains; dp; dp = dp->dom_next) |
127 | for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) | |
128 | if (pr->pr_fasttimo) | |
129 | (*pr->pr_fasttimo)(); | |
4f083fd7 | 130 | timeout(pffasttimo, (caddr_t)0, hz/5); |
4147b3f6 | 131 | } |