add some missing returns, correct args to ipcaccess, general cleanup
[unix-history] / usr / src / sys / kern / uipc_domain.c
... / ...
CommitLineData
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 are permitted
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.
16 *
17 * @(#)uipc_domain.c 7.6 (Berkeley) %G%
18 */
19
20#include "param.h"
21#include "socket.h"
22#include "protosw.h"
23#include "domain.h"
24#include "mbuf.h"
25#include "time.h"
26#include "kernel.h"
27
28#define ADDDOMAIN(x) { \
29 extern struct domain x/**/domain; \
30 x/**/domain.dom_next = domains; \
31 domains = &x/**/domain; \
32}
33
34domaininit()
35{
36 register struct domain *dp;
37 register struct protosw *pr;
38
39#ifndef lint
40 ADDDOMAIN(unix);
41 ADDDOMAIN(route);
42#ifdef INET
43 ADDDOMAIN(inet);
44#endif
45#ifdef NS
46 ADDDOMAIN(ns);
47#endif
48#ifdef ISO
49 ADDDOMAIN(iso);
50#endif
51#ifdef RMP
52 ADDDOMAIN(rmp);
53#endif
54#include "imp.h"
55#if NIMP > 0
56 ADDDOMAIN(imp);
57#endif
58#endif
59
60 for (dp = domains; dp; dp = dp->dom_next) {
61 if (dp->dom_init)
62 (*dp->dom_init)();
63 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
64 if (pr->pr_init)
65 (*pr->pr_init)();
66 }
67
68if (max_linkhdr < 16) /* XXX */
69max_linkhdr = 16;
70 max_hdr = max_linkhdr + max_protohdr;
71 max_datalen = MHLEN - max_hdr;
72 pffasttimo();
73 pfslowtimo();
74}
75
76struct protosw *
77pffindtype(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);
87found:
88 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
89 if (pr->pr_type && pr->pr_type == type)
90 return (pr);
91 return (0);
92}
93
94struct protosw *
95pffindproto(family, protocol, type)
96 int family, protocol, type;
97{
98 register struct domain *dp;
99 register struct protosw *pr;
100 struct protosw *maybe = 0;
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);
108found:
109 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) {
110 if ((pr->pr_protocol == protocol) && (pr->pr_type == type))
111 return (pr);
112
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);
118}
119
120pfctlinput(cmd, sa)
121 int cmd;
122 struct sockaddr *sa;
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)
130 (*pr->pr_ctlinput)(cmd, sa, (caddr_t) 0);
131}
132
133pfslowtimo()
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)();
142 timeout(pfslowtimo, (caddr_t)0, hz/2);
143}
144
145pffasttimo()
146{
147 register struct domain *dp;
148 register struct protosw *pr;
149
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)();
154 timeout(pffasttimo, (caddr_t)0, hz/5);
155}