xref: /csrg-svn/sys/kern/uipc_domain.c (revision 34860)
123416Smckusick /*
229123Smckusick  * Copyright (c) 1982, 1986 Regents of the University of California.
333187Sbostic  * All rights reserved.
423416Smckusick  *
533187Sbostic  * Redistribution and use in source and binary forms are permitted
6*34860Sbostic  * provided that the above copyright notice and this paragraph are
7*34860Sbostic  * duplicated in all such forms and that any documentation,
8*34860Sbostic  * advertising materials, and other materials related to such
9*34860Sbostic  * distribution and use acknowledge that the software was developed
10*34860Sbostic  * by the University of California, Berkeley.  The name of the
11*34860Sbostic  * University may not be used to endorse or promote products derived
12*34860Sbostic  * from this software without specific prior written permission.
13*34860Sbostic  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14*34860Sbostic  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15*34860Sbostic  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1633187Sbostic  *
17*34860Sbostic  *	@(#)uipc_domain.c	7.3 (Berkeley) 06/29/88
1823416Smckusick  */
197425Sroot 
2017102Sbloom #include "param.h"
2117102Sbloom #include "socket.h"
2217102Sbloom #include "protosw.h"
2317102Sbloom #include "domain.h"
2417102Sbloom #include "time.h"
2517102Sbloom #include "kernel.h"
267425Sroot 
279008Sroot #define	ADDDOMAIN(x)	{ \
289008Sroot 	extern struct domain x/**/domain; \
299008Sroot 	x/**/domain.dom_next = domains; \
309008Sroot 	domains = &x/**/domain; \
319008Sroot }
329008Sroot 
339008Sroot domaininit()
347500Sroot {
359161Ssam 	register struct domain *dp;
369161Ssam 	register struct protosw *pr;
377500Sroot 
389161Ssam #ifndef lint
399008Sroot 	ADDDOMAIN(unix);
4025765Skarels #ifdef INET
419008Sroot 	ADDDOMAIN(inet);
429008Sroot #endif
4318816Ssklower #ifdef NS
4418816Ssklower 	ADDDOMAIN(ns);
4518816Ssklower #endif
4610025Ssam #include "imp.h"
4710025Ssam #if NIMP > 0
489008Sroot 	ADDDOMAIN(imp);
499008Sroot #endif
509161Ssam #endif
519008Sroot 
5216993Skarels 	for (dp = domains; dp; dp = dp->dom_next) {
5316993Skarels 		if (dp->dom_init)
5416993Skarels 			(*dp->dom_init)();
559008Sroot 		for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
569008Sroot 			if (pr->pr_init)
579008Sroot 				(*pr->pr_init)();
5816993Skarels 	}
5928884Skarels 	null_init();
609161Ssam 	pffasttimo();
619161Ssam 	pfslowtimo();
629008Sroot }
639008Sroot 
649008Sroot struct protosw *
659008Sroot pffindtype(family, type)
669008Sroot 	int family, type;
679008Sroot {
689008Sroot 	register struct domain *dp;
699008Sroot 	register struct protosw *pr;
709008Sroot 
719008Sroot 	for (dp = domains; dp; dp = dp->dom_next)
729008Sroot 		if (dp->dom_family == family)
739008Sroot 			goto found;
749008Sroot 	return (0);
759008Sroot found:
769008Sroot 	for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
7711569Ssam 		if (pr->pr_type && pr->pr_type == type)
789008Sroot 			return (pr);
799008Sroot 	return (0);
809008Sroot }
819008Sroot 
829008Sroot struct protosw *
8321766Skarels pffindproto(family, protocol, type)
8421766Skarels 	int family, protocol, type;
859008Sroot {
869008Sroot 	register struct domain *dp;
879008Sroot 	register struct protosw *pr;
8821766Skarels 	struct protosw *maybe = 0;
899008Sroot 
909008Sroot 	if (family == 0)
919008Sroot 		return (0);
929008Sroot 	for (dp = domains; dp; dp = dp->dom_next)
939008Sroot 		if (dp->dom_family == family)
949008Sroot 			goto found;
959008Sroot 	return (0);
969008Sroot found:
9721766Skarels 	for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) {
9824519Skarels 		if ((pr->pr_protocol == protocol) && (pr->pr_type == type))
999008Sroot 			return (pr);
10024519Skarels 
10121766Skarels 		if (type == SOCK_RAW && pr->pr_type == SOCK_RAW &&
10221766Skarels 		    pr->pr_protocol == 0 && maybe == (struct protosw *)0)
10321766Skarels 			maybe = pr;
10421766Skarels 	}
10521766Skarels 	return (maybe);
1069008Sroot }
1079008Sroot 
10824767Skarels pfctlinput(cmd, sa)
1099008Sroot 	int cmd;
11024767Skarels 	struct sockaddr *sa;
1119008Sroot {
1129008Sroot 	register struct domain *dp;
1139008Sroot 	register struct protosw *pr;
1149008Sroot 
1159008Sroot 	for (dp = domains; dp; dp = dp->dom_next)
1169008Sroot 		for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
1179008Sroot 			if (pr->pr_ctlinput)
11824767Skarels 				(*pr->pr_ctlinput)(cmd, sa);
1199008Sroot }
1209008Sroot 
1219008Sroot pfslowtimo()
1229008Sroot {
1239008Sroot 	register struct domain *dp;
1249008Sroot 	register struct protosw *pr;
1259008Sroot 
1269008Sroot 	for (dp = domains; dp; dp = dp->dom_next)
1279008Sroot 		for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
1289008Sroot 			if (pr->pr_slowtimo)
1299008Sroot 				(*pr->pr_slowtimo)();
1309161Ssam 	timeout(pfslowtimo, (caddr_t)0, hz/2);
1319008Sroot }
1329008Sroot 
1339008Sroot pffasttimo()
1349008Sroot {
1359008Sroot 	register struct domain *dp;
1369008Sroot 	register struct protosw *pr;
1379008Sroot 
1389008Sroot 	for (dp = domains; dp; dp = dp->dom_next)
1399008Sroot 		for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
1409008Sroot 			if (pr->pr_fasttimo)
1419008Sroot 				(*pr->pr_fasttimo)();
1429161Ssam 	timeout(pffasttimo, (caddr_t)0, hz/5);
1439008Sroot }
144