xref: /csrg-svn/sys/kern/uipc_domain.c (revision 44447)
1 /*
2  * Copyright (c) 1982, 1986 Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  *
7  *	@(#)uipc_domain.c	7.7 (Berkeley) 06/28/90
8  */
9 
10 #include "param.h"
11 #include "socket.h"
12 #include "protosw.h"
13 #include "domain.h"
14 #include "mbuf.h"
15 #include "time.h"
16 #include "kernel.h"
17 
18 #define	ADDDOMAIN(x)	{ \
19 	extern struct domain x/**/domain; \
20 	x/**/domain.dom_next = domains; \
21 	domains = &x/**/domain; \
22 }
23 
24 domaininit()
25 {
26 	register struct domain *dp;
27 	register struct protosw *pr;
28 
29 #ifndef lint
30 	ADDDOMAIN(unix);
31 	ADDDOMAIN(route);
32 #ifdef INET
33 	ADDDOMAIN(inet);
34 #endif
35 #ifdef NS
36 	ADDDOMAIN(ns);
37 #endif
38 #ifdef ISO
39 	ADDDOMAIN(iso);
40 #endif
41 #ifdef RMP
42 	ADDDOMAIN(rmp);
43 #endif
44 #include "imp.h"
45 #if NIMP > 0
46 	ADDDOMAIN(imp);
47 #endif
48 #endif
49 
50 	for (dp = domains; dp; dp = dp->dom_next) {
51 		if (dp->dom_init)
52 			(*dp->dom_init)();
53 		for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
54 			if (pr->pr_init)
55 				(*pr->pr_init)();
56 	}
57 
58 if (max_linkhdr < 16)		/* XXX */
59 max_linkhdr = 16;
60 	max_hdr = max_linkhdr + max_protohdr;
61 	max_datalen = MHLEN - max_hdr;
62 	pffasttimo();
63 	pfslowtimo();
64 }
65 
66 struct protosw *
67 pffindtype(family, type)
68 	int family, type;
69 {
70 	register struct domain *dp;
71 	register struct protosw *pr;
72 
73 	for (dp = domains; dp; dp = dp->dom_next)
74 		if (dp->dom_family == family)
75 			goto found;
76 	return (0);
77 found:
78 	for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
79 		if (pr->pr_type && pr->pr_type == type)
80 			return (pr);
81 	return (0);
82 }
83 
84 struct protosw *
85 pffindproto(family, protocol, type)
86 	int family, protocol, type;
87 {
88 	register struct domain *dp;
89 	register struct protosw *pr;
90 	struct protosw *maybe = 0;
91 
92 	if (family == 0)
93 		return (0);
94 	for (dp = domains; dp; dp = dp->dom_next)
95 		if (dp->dom_family == family)
96 			goto found;
97 	return (0);
98 found:
99 	for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) {
100 		if ((pr->pr_protocol == protocol) && (pr->pr_type == type))
101 			return (pr);
102 
103 		if (type == SOCK_RAW && pr->pr_type == SOCK_RAW &&
104 		    pr->pr_protocol == 0 && maybe == (struct protosw *)0)
105 			maybe = pr;
106 	}
107 	return (maybe);
108 }
109 
110 pfctlinput(cmd, sa)
111 	int cmd;
112 	struct sockaddr *sa;
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_ctlinput)
120 				(*pr->pr_ctlinput)(cmd, sa, (caddr_t) 0);
121 }
122 
123 pfslowtimo()
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_slowtimo)
131 				(*pr->pr_slowtimo)();
132 	timeout(pfslowtimo, (caddr_t)0, hz/2);
133 }
134 
135 pffasttimo()
136 {
137 	register struct domain *dp;
138 	register struct protosw *pr;
139 
140 	for (dp = domains; dp; dp = dp->dom_next)
141 		for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
142 			if (pr->pr_fasttimo)
143 				(*pr->pr_fasttimo)();
144 	timeout(pffasttimo, (caddr_t)0, hz/5);
145 }
146