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 this notice is preserved and that due credit is given
7: * to the University of California at Berkeley. The name of the University
8: * may not be used to endorse or promote products derived from this
9: * software without specific prior written permission. This software
10: * is provided ``as is'' without express or implied warranty.
11: *
12: * @(#)uipc_domain.c 7.2.1 (2.11BSD) 1995/10/09
13: */
14:
15: #include "param.h"
16: #ifdef INET
17: #include "socket.h"
18: #include "protosw.h"
19: #include "domain.h"
20: #include "time.h"
21: #include "kernel.h"
22: #include "errno.h"
23:
24: #define ADDDOMAIN(x) { \
25: extern struct domain x/**/domain; \
26: x/**/domain.dom_next = domains; \
27: domains = &x/**/domain; \
28: }
29:
30: domaininit()
31: {
32: register struct domain *dp;
33: register struct protosw *pr;
34:
35: #ifndef lint
36: ADDDOMAIN(unix);
37: #ifdef INET
38: ADDDOMAIN(inet);
39: #endif
40: #ifdef NS
41: ADDDOMAIN(ns);
42: #endif
43: #include "imp.h"
44: #if NIMP > 0
45: ADDDOMAIN(imp);
46: #endif
47: #endif
48:
49: for (dp = domains; dp; dp = dp->dom_next) {
50: if (dp->dom_init)
51: (*dp->dom_init)();
52: for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
53: if (pr->pr_init)
54: (*pr->pr_init)();
55: }
56: null_init();
57: pffasttimo();
58: pfslowtimo();
59: }
60:
61: struct protosw *
62: pffindtype(family, type)
63: int family, type;
64: {
65: register struct domain *dp;
66: register struct protosw *pr;
67:
68: for (dp = domains; dp; dp = dp->dom_next)
69: if (dp->dom_family == family)
70: goto found;
71: return (0);
72: found:
73: for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
74: if (pr->pr_type && pr->pr_type == type)
75: return (pr);
76: return (0);
77: }
78:
79: struct protosw *
80: pffindproto(family, protocol, type)
81: int family, protocol, type;
82: {
83: register struct domain *dp;
84: register struct protosw *pr;
85: struct protosw *maybe = 0;
86:
87: if (family == 0)
88: return (0);
89: for (dp = domains; dp; dp = dp->dom_next)
90: if (dp->dom_family == family)
91: goto found;
92: return (0);
93: found:
94: for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) {
95: if ((pr->pr_protocol == protocol) && (pr->pr_type == type))
96: return (pr);
97:
98: if (type == SOCK_RAW && pr->pr_type == SOCK_RAW &&
99: pr->pr_protocol == 0 && maybe == (struct protosw *)0)
100: maybe = pr;
101: }
102: return (maybe);
103: }
104:
105: net_sysctl(name, namelen, oldp, oldlenp, newp, newlen)
106: int *name;
107: u_int namelen;
108: void *oldp;
109: size_t *oldlenp;
110: void *newp;
111: size_t newlen;
112: {
113: register struct domain *dp;
114: register struct protosw *pr;
115: int family, protocol;
116:
117: /*
118: * All sysctl names at this level are nonterminal;
119: * next two components are protocol family and protocol number,
120: * then at least one addition component.
121: */
122: if (namelen < 3)
123: return (EISDIR); /* overloaded */
124: family = name[0];
125: protocol = name[1];
126:
127: if (family == 0)
128: return (0);
129: for (dp = domains; dp; dp = dp->dom_next)
130: if (dp->dom_family == family)
131: goto found;
132: return (ENOPROTOOPT);
133: found:
134: for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
135: if (pr->pr_protocol == protocol && pr->pr_sysctl)
136: return ((*pr->pr_sysctl)(name + 2, namelen - 2,
137: oldp, oldlenp, newp, newlen));
138: return (ENOPROTOOPT);
139: }
140:
141: pfctlinput(cmd, sa)
142: int cmd;
143: struct sockaddr *sa;
144: {
145: register struct domain *dp;
146: register struct protosw *pr;
147:
148: for (dp = domains; dp; dp = dp->dom_next)
149: for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
150: if (pr->pr_ctlinput)
151: (*pr->pr_ctlinput)(cmd, sa);
152: }
153:
154: extern int hz;
155:
156: pfslowtimo()
157: {
158: register struct domain *dp;
159: register struct protosw *pr;
160:
161: for (dp = domains; dp; dp = dp->dom_next)
162: for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
163: if (pr->pr_slowtimo)
164: (*pr->pr_slowtimo)();
165: TIMEOUT(pfslowtimo, (caddr_t)0, hz/PR_SLOWHZ);
166: }
167:
168: pffasttimo()
169: {
170: register struct domain *dp;
171: register struct protosw *pr;
172:
173: for (dp = domains; dp; dp = dp->dom_next)
174: for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
175: if (pr->pr_fasttimo)
176: (*pr->pr_fasttimo)();
177: TIMEOUT(pffasttimo, (caddr_t)0, hz/PR_FASTHZ);
178: }
179: #endif
Defined functions
Defined macros