xref: /original-bsd/sys/kern/uipc_domain.c (revision 792e4f5f)
1 /*
2  * Copyright (c) 1982, 1986 Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted
6  * provided that the above copyright notice and this paragraph are
7  * duplicated in all such forms and that any documentation,
8  * advertising materials, and other materials related to such
9  * distribution and use acknowledge that the software was developed
10  * by the University of California, Berkeley.  The name of the
11  * University may not be used to endorse or promote products derived
12  * from this software without specific prior written permission.
13  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16  *
17  *	@(#)uipc_domain.c	7.4 (Berkeley) 04/08/89
18  */
19 
20 #include "param.h"
21 #include "socket.h"
22 #include "protosw.h"
23 #include "domain.h"
24 #include "mbuf.h"
25 #include "time.h"
26 #include "kernel.h"
27 
28 #define	ADDDOMAIN(x)	{ \
29 	extern struct domain x/**/domain; \
30 	x/**/domain.dom_next = domains; \
31 	domains = &x/**/domain; \
32 }
33 
34 domaininit()
35 {
36 	register struct domain *dp;
37 	register struct protosw *pr;
38 
39 #ifndef lint
40 	ADDDOMAIN(unix);
41 	ADDDOMAIN(route);
42 #ifdef INET
43 	ADDDOMAIN(inet);
44 #endif
45 #ifdef NS
46 	ADDDOMAIN(ns);
47 #endif
48 #ifdef ISO
49 	ADDDOMAIN(iso);
50 #endif
51 #include "imp.h"
52 #if NIMP > 0
53 	ADDDOMAIN(imp);
54 #endif
55 #endif
56 
57 	for (dp = domains; dp; dp = dp->dom_next) {
58 		if (dp->dom_init)
59 			(*dp->dom_init)();
60 		for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
61 			if (pr->pr_init)
62 				(*pr->pr_init)();
63 	}
64 
65 if (max_linkhdr < 16)		/* XXX */
66 max_linkhdr = 16;
67 	max_hdr = max_linkhdr + max_protohdr;
68 	max_datalen = MHLEN - max_hdr;
69 	pffasttimo();
70 	pfslowtimo();
71 }
72 
73 struct protosw *
74 pffindtype(family, type)
75 	int family, type;
76 {
77 	register struct domain *dp;
78 	register struct protosw *pr;
79 
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_type && pr->pr_type == type)
87 			return (pr);
88 	return (0);
89 }
90 
91 struct protosw *
92 pffindproto(family, protocol, type)
93 	int family, protocol, type;
94 {
95 	register struct domain *dp;
96 	register struct protosw *pr;
97 	struct protosw *maybe = 0;
98 
99 	if (family == 0)
100 		return (0);
101 	for (dp = domains; dp; dp = dp->dom_next)
102 		if (dp->dom_family == family)
103 			goto found;
104 	return (0);
105 found:
106 	for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) {
107 		if ((pr->pr_protocol == protocol) && (pr->pr_type == type))
108 			return (pr);
109 
110 		if (type == SOCK_RAW && pr->pr_type == SOCK_RAW &&
111 		    pr->pr_protocol == 0 && maybe == (struct protosw *)0)
112 			maybe = pr;
113 	}
114 	return (maybe);
115 }
116 
117 pfctlinput(cmd, sa)
118 	int cmd;
119 	struct sockaddr *sa;
120 {
121 	register struct domain *dp;
122 	register struct protosw *pr;
123 
124 	for (dp = domains; dp; dp = dp->dom_next)
125 		for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
126 			if (pr->pr_ctlinput)
127 				(*pr->pr_ctlinput)(cmd, sa);
128 }
129 
130 pfslowtimo()
131 {
132 	register struct domain *dp;
133 	register struct protosw *pr;
134 
135 	for (dp = domains; dp; dp = dp->dom_next)
136 		for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
137 			if (pr->pr_slowtimo)
138 				(*pr->pr_slowtimo)();
139 	timeout(pfslowtimo, (caddr_t)0, hz/2);
140 }
141 
142 pffasttimo()
143 {
144 	register struct domain *dp;
145 	register struct protosw *pr;
146 
147 	for (dp = domains; dp; dp = dp->dom_next)
148 		for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
149 			if (pr->pr_fasttimo)
150 				(*pr->pr_fasttimo)();
151 	timeout(pffasttimo, (caddr_t)0, hz/5);
152 }
153