change gdium conf to print message out both on uart and lcd
[pmon-gdium.git] / sys / kern / uipc_domain.c
blob77ba85aba7ab9b7c23527606ea50b244d93e66e8
1 /* $Id: uipc_domain.c,v 1.1.1.1 2006/09/14 01:59:08 root Exp $ */
2 /* $OpenBSD: uipc_domain.c,v 1.8 1999/03/30 00:19:05 niklas Exp $ */
3 /* $NetBSD: uipc_domain.c,v 1.14 1996/02/09 19:00:44 christos Exp $ */
5 /*
6 * Copyright (c) 1982, 1986, 1993
7 * The Regents of the University of California. All rights reserved.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by the University of
20 * California, Berkeley and its contributors.
21 * 4. Neither the name of the University nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * SUCH DAMAGE.
37 * @(#)uipc_domain.c 8.2 (Berkeley) 10/18/93
40 #include <sys/param.h>
41 #include <sys/socket.h>
42 #include <sys/protosw.h>
43 #include <sys/domain.h>
44 #include <sys/mbuf.h>
45 #include <sys/time.h>
46 #include <sys/kernel.h>
47 #include <sys/systm.h>
48 #include <sys/proc.h>
49 #include <vm/vm.h>
50 #include <sys/sysctl.h>
52 void pffasttimo __P((void *));
53 void pfslowtimo __P((void *));
54 #if defined (KEY) || defined (IPSEC)
55 int pfkey_init __P((void));
56 #endif /* KEY || IPSEC */
58 #define ADDDOMAIN(x) { \
59 extern struct domain __CONCAT(x,domain); \
60 __CONCAT(x,domain.dom_next) = domains; \
61 domains = &__CONCAT(x,domain); \
64 void
65 domaininit()
67 register struct domain *dp;
68 register struct protosw *pr;
70 #undef unix
71 #ifndef lint
72 #ifndef PMON
73 ADDDOMAIN(unix);
74 #endif
75 ADDDOMAIN(route);
76 #ifdef INET
77 ADDDOMAIN(inet);
78 #endif
79 #ifdef INET6
80 ADDDOMAIN(inet6);
81 #endif /* INET6 */
82 #if defined (KEY) || defined (IPSEC)
83 pfkey_init();
84 #endif /* KEY || IPSEC */
85 #ifdef IPX
86 ADDDOMAIN(ipx);
87 #endif
88 #ifdef NETATALK
89 ADDDOMAIN(atalk);
90 #endif
91 #ifdef NS
92 ADDDOMAIN(ns);
93 #endif
94 #ifdef ISO
95 ADDDOMAIN(iso);
96 #endif
97 #ifdef CCITT
98 ADDDOMAIN(ccitt);
99 #endif
100 #ifdef notdef /* XXXX */
101 #include "imp.h"
102 #if NIMP > 0
103 ADDDOMAIN(imp);
104 #endif
105 #endif
106 #endif
108 for (dp = domains; dp; dp = dp->dom_next) {
109 if (dp->dom_init)
110 (*dp->dom_init)();
111 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
112 if (pr->pr_init)
113 (*pr->pr_init)();
116 if (max_linkhdr < 16) /* XXX */
117 max_linkhdr = 16;
118 max_hdr = max_linkhdr + max_protohdr;
119 max_datalen = MHLEN - max_hdr;
120 timeout(pffasttimo, NULL, 1);
121 timeout(pfslowtimo, NULL, 1);
124 struct protosw *
125 pffindtype(family, type)
126 int family, type;
128 register struct domain *dp;
129 register struct protosw *pr;
131 for (dp = domains; dp; dp = dp->dom_next)
132 if (dp->dom_family == family)
133 goto found;
134 return (0);
135 found:
136 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
137 if (pr->pr_type && pr->pr_type == type)
138 return (pr);
139 return (0);
142 struct protosw *
143 pffindproto(family, protocol, type)
144 int family, protocol, type;
146 register struct domain *dp;
147 register struct protosw *pr;
148 struct protosw *maybe = 0;
150 if (family == 0)
151 return (0);
152 for (dp = domains; dp; dp = dp->dom_next)
153 if (dp->dom_family == family)
154 goto found;
155 return (0);
156 found:
157 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) {
158 if ((pr->pr_protocol == protocol) && (pr->pr_type == type))
159 return (pr);
161 if (type == SOCK_RAW && pr->pr_type == SOCK_RAW &&
162 pr->pr_protocol == 0 && maybe == (struct protosw *)0)
163 maybe = pr;
165 return (maybe);
169 net_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
170 int *name;
171 u_int namelen;
172 void *oldp;
173 size_t *oldlenp;
174 void *newp;
175 size_t newlen;
176 struct proc *p;
178 register struct domain *dp;
179 register struct protosw *pr;
180 int family, protocol;
183 * All sysctl names at this level are nonterminal;
184 * next two components are protocol family and protocol number,
185 * then at least one addition component.
187 if (namelen < 3)
188 return (EISDIR); /* overloaded */
189 family = name[0];
190 protocol = name[1];
192 if (family == 0)
193 return (0);
194 for (dp = domains; dp; dp = dp->dom_next)
195 if (dp->dom_family == family)
196 goto found;
197 return (ENOPROTOOPT);
198 found:
199 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
200 if (pr->pr_protocol == protocol && pr->pr_sysctl)
201 return ((*pr->pr_sysctl)(name + 2, namelen - 2,
202 oldp, oldlenp, newp, newlen));
203 return (ENOPROTOOPT);
206 void
207 pfctlinput(cmd, sa)
208 int cmd;
209 struct sockaddr *sa;
211 register struct domain *dp;
212 register struct protosw *pr;
214 for (dp = domains; dp; dp = dp->dom_next)
215 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
216 if (pr->pr_ctlinput)
217 (*pr->pr_ctlinput)(cmd, sa, NULL);
220 void
221 pfslowtimo(arg)
222 void *arg;
224 register struct domain *dp;
225 register struct protosw *pr;
227 for (dp = domains; dp; dp = dp->dom_next)
228 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
229 if (pr->pr_slowtimo)
230 (*pr->pr_slowtimo)();
231 timeout(pfslowtimo, NULL, hz/2);
234 void
235 pffasttimo(arg)
236 void *arg;
238 register struct domain *dp;
239 register struct protosw *pr;
241 for (dp = domains; dp; dp = dp->dom_next)
242 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
243 if (pr->pr_fasttimo)
244 (*pr->pr_fasttimo)();
245 timeout(pffasttimo, NULL, hz/5);