add Berkeley header
[unix-history] / usr / src / sys / kern / uipc_domain.c
CommitLineData
da7c5cc6 1/*
0880b18e 2 * Copyright (c) 1982, 1986 Regents of the University of California.
5b519e94 3 * All rights reserved.
da7c5cc6 4 *
5b519e94
KB
5 * Redistribution and use in source and binary forms are permitted
6 * provided that this notice is preserved and that due credit is given
7 * to the University of California at Berkeley. The name of the University
8 * may not be used to endorse or promote products derived from this
9 * software without specific prior written permission. This software
10 * is provided ``as is'' without express or implied warranty.
11 *
12 * @(#)uipc_domain.c 7.2 (Berkeley) %G%
da7c5cc6 13 */
2f6bcc97 14
94368568
JB
15#include "param.h"
16#include "socket.h"
17#include "protosw.h"
18#include "domain.h"
19#include "time.h"
20#include "kernel.h"
d0d50a86
BJ
21
22#define ADDDOMAIN(x) { \
23 extern struct domain x/**/domain; \
24 x/**/domain.dom_next = domains; \
25 domains = &x/**/domain; \
26}
27
28domaininit()
29{
4f083fd7
SL
30 register struct domain *dp;
31 register struct protosw *pr;
d0d50a86 32
4f083fd7 33#ifndef lint
d0d50a86 34 ADDDOMAIN(unix);
2a04df10 35#ifdef INET
d0d50a86
BJ
36 ADDDOMAIN(inet);
37#endif
6e8408aa
KS
38#ifdef NS
39 ADDDOMAIN(ns);
40#endif
bd65e3c4
SL
41#include "imp.h"
42#if NIMP > 0
d0d50a86
BJ
43 ADDDOMAIN(imp);
44#endif
4f083fd7 45#endif
d0d50a86 46
261a8548
MK
47 for (dp = domains; dp; dp = dp->dom_next) {
48 if (dp->dom_init)
49 (*dp->dom_init)();
d0d50a86
BJ
50 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
51 if (pr->pr_init)
52 (*pr->pr_init)();
261a8548 53 }
79058dbc 54 null_init();
4f083fd7
SL
55 pffasttimo();
56 pfslowtimo();
d0d50a86
BJ
57}
58
59struct protosw *
60pffindtype(family, type)
61 int family, type;
62{
63 register struct domain *dp;
64 register struct protosw *pr;
65
66 for (dp = domains; dp; dp = dp->dom_next)
67 if (dp->dom_family == family)
68 goto found;
69 return (0);
70found:
71 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
6cd6d0de 72 if (pr->pr_type && pr->pr_type == type)
d0d50a86
BJ
73 return (pr);
74 return (0);
75}
76
77struct protosw *
9f773c40
MK
78pffindproto(family, protocol, type)
79 int family, protocol, type;
d0d50a86
BJ
80{
81 register struct domain *dp;
82 register struct protosw *pr;
9f773c40 83 struct protosw *maybe = 0;
d0d50a86
BJ
84
85 if (family == 0)
86 return (0);
87 for (dp = domains; dp; dp = dp->dom_next)
88 if (dp->dom_family == family)
89 goto found;
90 return (0);
91found:
9f773c40 92 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) {
c76325fe 93 if ((pr->pr_protocol == protocol) && (pr->pr_type == type))
d0d50a86 94 return (pr);
c76325fe 95
9f773c40
MK
96 if (type == SOCK_RAW && pr->pr_type == SOCK_RAW &&
97 pr->pr_protocol == 0 && maybe == (struct protosw *)0)
98 maybe = pr;
99 }
100 return (maybe);
d0d50a86
BJ
101}
102
122d5d84 103pfctlinput(cmd, sa)
d0d50a86 104 int cmd;
122d5d84 105 struct sockaddr *sa;
d0d50a86
BJ
106{
107 register struct domain *dp;
108 register struct protosw *pr;
109
110 for (dp = domains; dp; dp = dp->dom_next)
111 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
112 if (pr->pr_ctlinput)
122d5d84 113 (*pr->pr_ctlinput)(cmd, sa);
d0d50a86
BJ
114}
115
116pfslowtimo()
117{
118 register struct domain *dp;
119 register struct protosw *pr;
120
121 for (dp = domains; dp; dp = dp->dom_next)
122 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
123 if (pr->pr_slowtimo)
124 (*pr->pr_slowtimo)();
4f083fd7 125 timeout(pfslowtimo, (caddr_t)0, hz/2);
d0d50a86
BJ
126}
127
128pffasttimo()
4147b3f6 129{
d0d50a86
BJ
130 register struct domain *dp;
131 register struct protosw *pr;
4147b3f6 132
d0d50a86
BJ
133 for (dp = domains; dp; dp = dp->dom_next)
134 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
135 if (pr->pr_fasttimo)
136 (*pr->pr_fasttimo)();
4f083fd7 137 timeout(pffasttimo, (caddr_t)0, hz/5);
4147b3f6 138}