xref: /csrg-svn/sys/kern/uipc_domain.c (revision 24519)
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.7 (Berkeley) 09/04/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) && (pr->pr_type == type))
90 			return (pr);
91 
92 		if (type == SOCK_RAW && pr->pr_type == SOCK_RAW &&
93 		    pr->pr_protocol == 0 && maybe == (struct protosw *)0)
94 			maybe = pr;
95 	}
96 	return (maybe);
97 }
98 
99 pfctlinput(cmd, arg)
100 	int cmd;
101 	caddr_t arg;
102 {
103 	register struct domain *dp;
104 	register struct protosw *pr;
105 
106 	for (dp = domains; dp; dp = dp->dom_next)
107 		for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
108 			if (pr->pr_ctlinput)
109 				(*pr->pr_ctlinput)(cmd, arg);
110 }
111 
112 pfslowtimo()
113 {
114 	register struct domain *dp;
115 	register struct protosw *pr;
116 
117 	for (dp = domains; dp; dp = dp->dom_next)
118 		for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
119 			if (pr->pr_slowtimo)
120 				(*pr->pr_slowtimo)();
121 	timeout(pfslowtimo, (caddr_t)0, hz/2);
122 }
123 
124 pffasttimo()
125 {
126 	register struct domain *dp;
127 	register struct protosw *pr;
128 
129 	for (dp = domains; dp; dp = dp->dom_next)
130 		for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
131 			if (pr->pr_fasttimo)
132 				(*pr->pr_fasttimo)();
133 	timeout(pffasttimo, (caddr_t)0, hz/5);
134 }
135