xref: /csrg-svn/sys/kern/uipc_domain.c (revision 23416)
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  *
6  *	@(#)uipc_domain.c	6.6 (Berkeley) 06/08/85
7  */
8 
9 #include "param.h"
10 #include "socket.h"
11 #include "protosw.h"
12 #include "domain.h"
13 #include "time.h"
14 #include "kernel.h"
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 {
24 	register struct domain *dp;
25 	register struct protosw *pr;
26 
27 #ifndef lint
28 	ADDDOMAIN(unix);
29 #ifdef INET
30 	ADDDOMAIN(inet);
31 #endif
32 #ifdef NS
33 	ADDDOMAIN(ns);
34 #endif
35 #ifdef PUP
36 	ADDDOMAIN(pup);
37 #endif
38 #include "imp.h"
39 #if NIMP > 0
40 	ADDDOMAIN(imp);
41 #endif
42 #endif
43 
44 	for (dp = domains; dp; dp = dp->dom_next) {
45 		if (dp->dom_init)
46 			(*dp->dom_init)();
47 		for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
48 			if (pr->pr_init)
49 				(*pr->pr_init)();
50 	}
51 	pffasttimo();
52 	pfslowtimo();
53 }
54 
55 struct protosw *
56 pffindtype(family, type)
57 	int family, type;
58 {
59 	register struct domain *dp;
60 	register struct protosw *pr;
61 
62 	for (dp = domains; dp; dp = dp->dom_next)
63 		if (dp->dom_family == family)
64 			goto found;
65 	return (0);
66 found:
67 	for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
68 		if (pr->pr_type && pr->pr_type == type)
69 			return (pr);
70 	return (0);
71 }
72 
73 struct protosw *
74 pffindproto(family, protocol, type)
75 	int family, protocol, type;
76 {
77 	register struct domain *dp;
78 	register struct protosw *pr;
79 	struct protosw *maybe = 0;
80 
81 	if (family == 0)
82 		return (0);
83 	for (dp = domains; dp; dp = dp->dom_next)
84 		if (dp->dom_family == family)
85 			goto found;
86 	return (0);
87 found:
88 	for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) {
89 		if (pr->pr_protocol == protocol)
90 			return (pr);
91 		if (type == SOCK_RAW && pr->pr_type == SOCK_RAW &&
92 		    pr->pr_protocol == 0 && maybe == (struct protosw *)0)
93 			maybe = pr;
94 	}
95 	return (maybe);
96 }
97 
98 pfctlinput(cmd, arg)
99 	int cmd;
100 	caddr_t arg;
101 {
102 	register struct domain *dp;
103 	register struct protosw *pr;
104 
105 	for (dp = domains; dp; dp = dp->dom_next)
106 		for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
107 			if (pr->pr_ctlinput)
108 				(*pr->pr_ctlinput)(cmd, arg);
109 }
110 
111 pfslowtimo()
112 {
113 	register struct domain *dp;
114 	register struct protosw *pr;
115 
116 	for (dp = domains; dp; dp = dp->dom_next)
117 		for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
118 			if (pr->pr_slowtimo)
119 				(*pr->pr_slowtimo)();
120 	timeout(pfslowtimo, (caddr_t)0, hz/2);
121 }
122 
123 pffasttimo()
124 {
125 	register struct domain *dp;
126 	register struct protosw *pr;
127 
128 	for (dp = domains; dp; dp = dp->dom_next)
129 		for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
130 			if (pr->pr_fasttimo)
131 				(*pr->pr_fasttimo)();
132 	timeout(pffasttimo, (caddr_t)0, hz/5);
133 }
134