xref: /csrg-svn/sys/kern/uipc_domain.c (revision 64730)
123416Smckusick /*
263180Sbostic  * Copyright (c) 1982, 1986, 1993
363180Sbostic  *	The Regents of the University of California.  All rights reserved.
423416Smckusick  *
544447Sbostic  * %sccs.include.redist.c%
633187Sbostic  *
7*64730Smckusick  *	@(#)uipc_domain.c	8.2 (Berkeley) 10/18/93
823416Smckusick  */
97425Sroot 
1056517Sbostic #include <sys/param.h>
1156517Sbostic #include <sys/socket.h>
1256517Sbostic #include <sys/protosw.h>
1356517Sbostic #include <sys/domain.h>
1456517Sbostic #include <sys/mbuf.h>
1556517Sbostic #include <sys/time.h>
1656517Sbostic #include <sys/kernel.h>
17*64730Smckusick #include <sys/systm.h>
1859357Smckusick #include <sys/proc.h>
1959357Smckusick #include <vm/vm.h>
2057842Smckusick #include <sys/sysctl.h>
217425Sroot 
22*64730Smckusick void	pffasttimo __P((void *));
23*64730Smckusick void	pfslowtimo __P((void *));
24*64730Smckusick 
259008Sroot #define	ADDDOMAIN(x)	{ \
2646970Sbostic 	extern struct domain __CONCAT(x,domain); \
2746970Sbostic 	__CONCAT(x,domain.dom_next) = domains; \
2846970Sbostic 	domains = &__CONCAT(x,domain); \
299008Sroot }
309008Sroot 
319008Sroot domaininit()
327500Sroot {
339161Ssam 	register struct domain *dp;
349161Ssam 	register struct protosw *pr;
357500Sroot 
3646970Sbostic #undef unix
379161Ssam #ifndef lint
389008Sroot 	ADDDOMAIN(unix);
3937330Skarels 	ADDDOMAIN(route);
4025765Skarels #ifdef INET
419008Sroot 	ADDDOMAIN(inet);
429008Sroot #endif
4318816Ssklower #ifdef NS
4418816Ssklower 	ADDDOMAIN(ns);
4518816Ssklower #endif
4637330Skarels #ifdef ISO
4737330Skarels 	ADDDOMAIN(iso);
4837330Skarels #endif
4945665Ssklower #ifdef CCITT
5045665Ssklower 	ADDDOMAIN(ccitt);
5145665Ssklower #endif
5210025Ssam #include "imp.h"
5310025Ssam #if NIMP > 0
549008Sroot 	ADDDOMAIN(imp);
559008Sroot #endif
569161Ssam #endif
579008Sroot 
5816993Skarels 	for (dp = domains; dp; dp = dp->dom_next) {
5916993Skarels 		if (dp->dom_init)
6016993Skarels 			(*dp->dom_init)();
619008Sroot 		for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
629008Sroot 			if (pr->pr_init)
639008Sroot 				(*pr->pr_init)();
6416993Skarels 	}
6537330Skarels 
6637330Skarels if (max_linkhdr < 16)		/* XXX */
6737330Skarels max_linkhdr = 16;
6837330Skarels 	max_hdr = max_linkhdr + max_protohdr;
6937330Skarels 	max_datalen = MHLEN - max_hdr;
70*64730Smckusick 	timeout(pffasttimo, (void *)0, 1);
71*64730Smckusick 	timeout(pfslowtimo, (void *)0, 1);
729008Sroot }
739008Sroot 
749008Sroot struct protosw *
759008Sroot pffindtype(family, type)
769008Sroot 	int family, type;
779008Sroot {
789008Sroot 	register struct domain *dp;
799008Sroot 	register struct protosw *pr;
809008Sroot 
819008Sroot 	for (dp = domains; dp; dp = dp->dom_next)
829008Sroot 		if (dp->dom_family == family)
839008Sroot 			goto found;
849008Sroot 	return (0);
859008Sroot found:
869008Sroot 	for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
8711569Ssam 		if (pr->pr_type && pr->pr_type == type)
889008Sroot 			return (pr);
899008Sroot 	return (0);
909008Sroot }
919008Sroot 
929008Sroot struct protosw *
9321766Skarels pffindproto(family, protocol, type)
9421766Skarels 	int family, protocol, type;
959008Sroot {
969008Sroot 	register struct domain *dp;
979008Sroot 	register struct protosw *pr;
9821766Skarels 	struct protosw *maybe = 0;
999008Sroot 
1009008Sroot 	if (family == 0)
1019008Sroot 		return (0);
1029008Sroot 	for (dp = domains; dp; dp = dp->dom_next)
1039008Sroot 		if (dp->dom_family == family)
1049008Sroot 			goto found;
1059008Sroot 	return (0);
1069008Sroot found:
10721766Skarels 	for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) {
10824519Skarels 		if ((pr->pr_protocol == protocol) && (pr->pr_type == type))
1099008Sroot 			return (pr);
11024519Skarels 
11121766Skarels 		if (type == SOCK_RAW && pr->pr_type == SOCK_RAW &&
11221766Skarels 		    pr->pr_protocol == 0 && maybe == (struct protosw *)0)
11321766Skarels 			maybe = pr;
11421766Skarels 	}
11521766Skarels 	return (maybe);
1169008Sroot }
1179008Sroot 
11858399Smckusick net_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
11957842Smckusick 	int *name;
12057842Smckusick 	u_int namelen;
12157842Smckusick 	void *oldp;
12258467Sbostic 	size_t *oldlenp;
12357842Smckusick 	void *newp;
12458467Sbostic 	size_t newlen;
12558399Smckusick 	struct proc *p;
12657842Smckusick {
12757842Smckusick 	register struct domain *dp;
12857842Smckusick 	register struct protosw *pr;
12957842Smckusick 	int family, protocol;
13057842Smckusick 
13157842Smckusick 	/*
13257842Smckusick 	 * All sysctl names at this level are nonterminal;
13357842Smckusick 	 * next two components are protocol family and protocol number,
13457842Smckusick 	 * then at least one addition component.
13557842Smckusick 	 */
13659125Smckusick 	if (namelen < 3)
13757842Smckusick 		return (EISDIR);		/* overloaded */
13857842Smckusick 	family = name[0];
13957842Smckusick 	protocol = name[1];
14057842Smckusick 
14157842Smckusick 	if (family == 0)
14257842Smckusick 		return (0);
14357842Smckusick 	for (dp = domains; dp; dp = dp->dom_next)
14457842Smckusick 		if (dp->dom_family == family)
14557842Smckusick 			goto found;
14657842Smckusick 	return (ENOPROTOOPT);
14757842Smckusick found:
14857842Smckusick 	for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
14957842Smckusick 		if (pr->pr_protocol == protocol && pr->pr_sysctl)
15057842Smckusick 			return ((*pr->pr_sysctl)(name + 2, namelen - 2,
15157842Smckusick 			    oldp, oldlenp, newp, newlen));
15257842Smckusick 	return (ENOPROTOOPT);
15357842Smckusick }
15457842Smckusick 
15524767Skarels pfctlinput(cmd, sa)
1569008Sroot 	int cmd;
15724767Skarels 	struct sockaddr *sa;
1589008Sroot {
1599008Sroot 	register struct domain *dp;
1609008Sroot 	register struct protosw *pr;
1619008Sroot 
1629008Sroot 	for (dp = domains; dp; dp = dp->dom_next)
1639008Sroot 		for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
1649008Sroot 			if (pr->pr_ctlinput)
165*64730Smckusick 				(*pr->pr_ctlinput)(cmd, sa, (caddr_t)0);
1669008Sroot }
1679008Sroot 
168*64730Smckusick void
169*64730Smckusick pfslowtimo(arg)
170*64730Smckusick 	void *arg;
1719008Sroot {
1729008Sroot 	register struct domain *dp;
1739008Sroot 	register struct protosw *pr;
1749008Sroot 
1759008Sroot 	for (dp = domains; dp; dp = dp->dom_next)
1769008Sroot 		for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
1779008Sroot 			if (pr->pr_slowtimo)
1789008Sroot 				(*pr->pr_slowtimo)();
179*64730Smckusick 	timeout(pfslowtimo, (void *)0, hz/2);
1809008Sroot }
1819008Sroot 
182*64730Smckusick void
183*64730Smckusick pffasttimo(arg)
184*64730Smckusick 	void *arg;
1859008Sroot {
1869008Sroot 	register struct domain *dp;
1879008Sroot 	register struct protosw *pr;
1889008Sroot 
1899008Sroot 	for (dp = domains; dp; dp = dp->dom_next)
1909008Sroot 		for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
1919008Sroot 			if (pr->pr_fasttimo)
1929008Sroot 				(*pr->pr_fasttimo)();
193*64730Smckusick 	timeout(pffasttimo, (void *)0, hz/5);
1949008Sroot }
195