Added David Mills' kernel NTP PLL code. The current version of NTP does
[unix-history] / sys / kern / uipc_domain.c
CommitLineData
15637ed4
RG
1/*
2 * Copyright (c) 1982, 1986 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
600f7f07 33 * from: @(#)uipc_domain.c 7.9 (Berkeley) 3/4/91
fde1aeb2 34 * $Id: uipc_domain.c,v 1.4 1993/11/25 01:33:31 wollman Exp $
15637ed4
RG
35 */
36
15637ed4 37#include "param.h"
fde1aeb2 38#include "systm.h"
15637ed4
RG
39#include "socket.h"
40#include "protosw.h"
41#include "domain.h"
42#include "mbuf.h"
43#include "time.h"
44#include "kernel.h"
45
bbc3f849
GW
46struct domain *domains;
47
15637ed4
RG
48#define ADDDOMAIN(x) { \
49 extern struct domain __CONCAT(x,domain); \
50 __CONCAT(x,domain.dom_next) = domains; \
51 domains = &__CONCAT(x,domain); \
52}
53
4c45483e
GW
54static void pfslowtimo(caddr_t, int);
55static void pffasttimo(caddr_t, int);
56
57void
15637ed4
RG
58domaininit()
59{
60 register struct domain *dp;
61 register struct protosw *pr;
62
63#undef unix
64#ifndef lint
65 ADDDOMAIN(unix);
66 ADDDOMAIN(route);
67#ifdef INET
68 ADDDOMAIN(inet);
69#endif
70#ifdef NS
71 ADDDOMAIN(ns);
72#endif
73#ifdef ISO
74 ADDDOMAIN(iso);
75#endif
76#ifdef RMP
77 ADDDOMAIN(rmp);
78#endif
79#ifdef CCITT
80 ADDDOMAIN(ccitt);
81#endif
82#include "imp.h"
83#if NIMP > 0
84 ADDDOMAIN(imp);
85#endif
86#endif
87
88 for (dp = domains; dp; dp = dp->dom_next) {
89 if (dp->dom_init)
90 (*dp->dom_init)();
91 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
92 if (pr->pr_init)
93 (*pr->pr_init)();
94 }
95
96if (max_linkhdr < 16) /* XXX */
97max_linkhdr = 16;
98 max_hdr = max_linkhdr + max_protohdr;
99 max_datalen = MHLEN - max_hdr;
4c45483e
GW
100 pffasttimo(0, 0);
101 pfslowtimo(0, 0);
15637ed4
RG
102}
103
104struct protosw *
105pffindtype(family, type)
106 int family, type;
107{
108 register struct domain *dp;
109 register struct protosw *pr;
110
111 for (dp = domains; dp; dp = dp->dom_next)
112 if (dp->dom_family == family)
113 goto found;
114 return (0);
115found:
116 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
117 if (pr->pr_type && pr->pr_type == type)
118 return (pr);
119 return (0);
120}
121
122struct protosw *
123pffindproto(family, protocol, type)
124 int family, protocol, type;
125{
126 register struct domain *dp;
127 register struct protosw *pr;
128 struct protosw *maybe = 0;
129
130 if (family == 0)
131 return (0);
132 for (dp = domains; dp; dp = dp->dom_next)
133 if (dp->dom_family == family)
134 goto found;
135 return (0);
136found:
137 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) {
138 if ((pr->pr_protocol == protocol) && (pr->pr_type == type))
139 return (pr);
140
141 if (type == SOCK_RAW && pr->pr_type == SOCK_RAW &&
142 pr->pr_protocol == 0 && maybe == (struct protosw *)0)
143 maybe = pr;
144 }
145 return (maybe);
146}
147
4c45483e 148void
15637ed4
RG
149pfctlinput(cmd, sa)
150 int cmd;
151 struct sockaddr *sa;
152{
153 register struct domain *dp;
154 register struct protosw *pr;
155
156 for (dp = domains; dp; dp = dp->dom_next)
157 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
158 if (pr->pr_ctlinput)
159 (*pr->pr_ctlinput)(cmd, sa, (caddr_t) 0);
160}
161
4c45483e
GW
162static void
163pfslowtimo(caddr_t dummy1, int dummy2)
15637ed4
RG
164{
165 register struct domain *dp;
166 register struct protosw *pr;
167
168 for (dp = domains; dp; dp = dp->dom_next)
169 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
170 if (pr->pr_slowtimo)
171 (*pr->pr_slowtimo)();
172 timeout(pfslowtimo, (caddr_t)0, hz/2);
173}
174
4c45483e
GW
175static void
176pffasttimo(caddr_t dummy1, int dummy2)
15637ed4
RG
177{
178 register struct domain *dp;
179 register struct protosw *pr;
180
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)();
185 timeout(pffasttimo, (caddr_t)0, hz/5);
186}