xref: /csrg-svn/sys/kern/uipc_domain.c (revision 40668)
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
634860Sbostic  * provided that the above copyright notice and this paragraph are
734860Sbostic  * duplicated in all such forms and that any documentation,
834860Sbostic  * advertising materials, and other materials related to such
934860Sbostic  * distribution and use acknowledge that the software was developed
1034860Sbostic  * by the University of California, Berkeley.  The name of the
1134860Sbostic  * University may not be used to endorse or promote products derived
1234860Sbostic  * from this software without specific prior written permission.
1334860Sbostic  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
1434860Sbostic  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
1534860Sbostic  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1633187Sbostic  *
17*40668Skarels  *	@(#)uipc_domain.c	7.5 (Berkeley) 03/31/90
1823416Smckusick  */
197425Sroot 
2017102Sbloom #include "param.h"
2117102Sbloom #include "socket.h"
2217102Sbloom #include "protosw.h"
2317102Sbloom #include "domain.h"
2437330Skarels #include "mbuf.h"
2517102Sbloom #include "time.h"
2617102Sbloom #include "kernel.h"
277425Sroot 
289008Sroot #define	ADDDOMAIN(x)	{ \
299008Sroot 	extern struct domain x/**/domain; \
309008Sroot 	x/**/domain.dom_next = domains; \
319008Sroot 	domains = &x/**/domain; \
329008Sroot }
339008Sroot 
349008Sroot domaininit()
357500Sroot {
369161Ssam 	register struct domain *dp;
379161Ssam 	register struct protosw *pr;
387500Sroot 
399161Ssam #ifndef lint
409008Sroot 	ADDDOMAIN(unix);
4137330Skarels 	ADDDOMAIN(route);
4225765Skarels #ifdef INET
439008Sroot 	ADDDOMAIN(inet);
449008Sroot #endif
4518816Ssklower #ifdef NS
4618816Ssklower 	ADDDOMAIN(ns);
4718816Ssklower #endif
4837330Skarels #ifdef ISO
4937330Skarels 	ADDDOMAIN(iso);
5037330Skarels #endif
5110025Ssam #include "imp.h"
5210025Ssam #if NIMP > 0
539008Sroot 	ADDDOMAIN(imp);
549008Sroot #endif
559161Ssam #endif
569008Sroot 
5716993Skarels 	for (dp = domains; dp; dp = dp->dom_next) {
5816993Skarels 		if (dp->dom_init)
5916993Skarels 			(*dp->dom_init)();
609008Sroot 		for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
619008Sroot 			if (pr->pr_init)
629008Sroot 				(*pr->pr_init)();
6316993Skarels 	}
6437330Skarels 
6537330Skarels if (max_linkhdr < 16)		/* XXX */
6637330Skarels max_linkhdr = 16;
6737330Skarels 	max_hdr = max_linkhdr + max_protohdr;
6837330Skarels 	max_datalen = MHLEN - max_hdr;
699161Ssam 	pffasttimo();
709161Ssam 	pfslowtimo();
719008Sroot }
729008Sroot 
739008Sroot struct protosw *
749008Sroot pffindtype(family, type)
759008Sroot 	int family, type;
769008Sroot {
779008Sroot 	register struct domain *dp;
789008Sroot 	register struct protosw *pr;
799008Sroot 
809008Sroot 	for (dp = domains; dp; dp = dp->dom_next)
819008Sroot 		if (dp->dom_family == family)
829008Sroot 			goto found;
839008Sroot 	return (0);
849008Sroot found:
859008Sroot 	for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
8611569Ssam 		if (pr->pr_type && pr->pr_type == type)
879008Sroot 			return (pr);
889008Sroot 	return (0);
899008Sroot }
909008Sroot 
919008Sroot struct protosw *
9221766Skarels pffindproto(family, protocol, type)
9321766Skarels 	int family, protocol, type;
949008Sroot {
959008Sroot 	register struct domain *dp;
969008Sroot 	register struct protosw *pr;
9721766Skarels 	struct protosw *maybe = 0;
989008Sroot 
999008Sroot 	if (family == 0)
1009008Sroot 		return (0);
1019008Sroot 	for (dp = domains; dp; dp = dp->dom_next)
1029008Sroot 		if (dp->dom_family == family)
1039008Sroot 			goto found;
1049008Sroot 	return (0);
1059008Sroot found:
10621766Skarels 	for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) {
10724519Skarels 		if ((pr->pr_protocol == protocol) && (pr->pr_type == type))
1089008Sroot 			return (pr);
10924519Skarels 
11021766Skarels 		if (type == SOCK_RAW && pr->pr_type == SOCK_RAW &&
11121766Skarels 		    pr->pr_protocol == 0 && maybe == (struct protosw *)0)
11221766Skarels 			maybe = pr;
11321766Skarels 	}
11421766Skarels 	return (maybe);
1159008Sroot }
1169008Sroot 
11724767Skarels pfctlinput(cmd, sa)
1189008Sroot 	int cmd;
11924767Skarels 	struct sockaddr *sa;
1209008Sroot {
1219008Sroot 	register struct domain *dp;
1229008Sroot 	register struct protosw *pr;
1239008Sroot 
1249008Sroot 	for (dp = domains; dp; dp = dp->dom_next)
1259008Sroot 		for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
1269008Sroot 			if (pr->pr_ctlinput)
127*40668Skarels 				(*pr->pr_ctlinput)(cmd, sa, (caddr_t) 0);
1289008Sroot }
1299008Sroot 
1309008Sroot pfslowtimo()
1319008Sroot {
1329008Sroot 	register struct domain *dp;
1339008Sroot 	register struct protosw *pr;
1349008Sroot 
1359008Sroot 	for (dp = domains; dp; dp = dp->dom_next)
1369008Sroot 		for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
1379008Sroot 			if (pr->pr_slowtimo)
1389008Sroot 				(*pr->pr_slowtimo)();
1399161Ssam 	timeout(pfslowtimo, (caddr_t)0, hz/2);
1409008Sroot }
1419008Sroot 
1429008Sroot pffasttimo()
1439008Sroot {
1449008Sroot 	register struct domain *dp;
1459008Sroot 	register struct protosw *pr;
1469008Sroot 
1479008Sroot 	for (dp = domains; dp; dp = dp->dom_next)
1489008Sroot 		for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
1499008Sroot 			if (pr->pr_fasttimo)
1509008Sroot 				(*pr->pr_fasttimo)();
1519161Ssam 	timeout(pffasttimo, (caddr_t)0, hz/5);
1529008Sroot }
153