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