xref: /csrg-svn/sys/kern/uipc_domain.c (revision 63180)
123416Smckusick /*
2*63180Sbostic  * Copyright (c) 1982, 1986, 1993
3*63180Sbostic  *	The Regents of the University of California.  All rights reserved.
423416Smckusick  *
544447Sbostic  * %sccs.include.redist.c%
633187Sbostic  *
7*63180Sbostic  *	@(#)uipc_domain.c	8.1 (Berkeley) 06/10/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>
1759357Smckusick #include <sys/proc.h>
1859357Smckusick #include <vm/vm.h>
1957842Smckusick #include <sys/sysctl.h>
207425Sroot 
219008Sroot #define	ADDDOMAIN(x)	{ \
2246970Sbostic 	extern struct domain __CONCAT(x,domain); \
2346970Sbostic 	__CONCAT(x,domain.dom_next) = domains; \
2446970Sbostic 	domains = &__CONCAT(x,domain); \
259008Sroot }
269008Sroot 
279008Sroot domaininit()
287500Sroot {
299161Ssam 	register struct domain *dp;
309161Ssam 	register struct protosw *pr;
317500Sroot 
3246970Sbostic #undef unix
339161Ssam #ifndef lint
349008Sroot 	ADDDOMAIN(unix);
3537330Skarels 	ADDDOMAIN(route);
3625765Skarels #ifdef INET
379008Sroot 	ADDDOMAIN(inet);
389008Sroot #endif
3918816Ssklower #ifdef NS
4018816Ssklower 	ADDDOMAIN(ns);
4118816Ssklower #endif
4237330Skarels #ifdef ISO
4337330Skarels 	ADDDOMAIN(iso);
4437330Skarels #endif
4545665Ssklower #ifdef CCITT
4645665Ssklower 	ADDDOMAIN(ccitt);
4745665Ssklower #endif
4810025Ssam #include "imp.h"
4910025Ssam #if NIMP > 0
509008Sroot 	ADDDOMAIN(imp);
519008Sroot #endif
529161Ssam #endif
539008Sroot 
5416993Skarels 	for (dp = domains; dp; dp = dp->dom_next) {
5516993Skarels 		if (dp->dom_init)
5616993Skarels 			(*dp->dom_init)();
579008Sroot 		for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
589008Sroot 			if (pr->pr_init)
599008Sroot 				(*pr->pr_init)();
6016993Skarels 	}
6137330Skarels 
6237330Skarels if (max_linkhdr < 16)		/* XXX */
6337330Skarels max_linkhdr = 16;
6437330Skarels 	max_hdr = max_linkhdr + max_protohdr;
6537330Skarels 	max_datalen = MHLEN - max_hdr;
669161Ssam 	pffasttimo();
679161Ssam 	pfslowtimo();
689008Sroot }
699008Sroot 
709008Sroot struct protosw *
719008Sroot pffindtype(family, type)
729008Sroot 	int family, type;
739008Sroot {
749008Sroot 	register struct domain *dp;
759008Sroot 	register struct protosw *pr;
769008Sroot 
779008Sroot 	for (dp = domains; dp; dp = dp->dom_next)
789008Sroot 		if (dp->dom_family == family)
799008Sroot 			goto found;
809008Sroot 	return (0);
819008Sroot found:
829008Sroot 	for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
8311569Ssam 		if (pr->pr_type && pr->pr_type == type)
849008Sroot 			return (pr);
859008Sroot 	return (0);
869008Sroot }
879008Sroot 
889008Sroot struct protosw *
8921766Skarels pffindproto(family, protocol, type)
9021766Skarels 	int family, protocol, type;
919008Sroot {
929008Sroot 	register struct domain *dp;
939008Sroot 	register struct protosw *pr;
9421766Skarels 	struct protosw *maybe = 0;
959008Sroot 
969008Sroot 	if (family == 0)
979008Sroot 		return (0);
989008Sroot 	for (dp = domains; dp; dp = dp->dom_next)
999008Sroot 		if (dp->dom_family == family)
1009008Sroot 			goto found;
1019008Sroot 	return (0);
1029008Sroot found:
10321766Skarels 	for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) {
10424519Skarels 		if ((pr->pr_protocol == protocol) && (pr->pr_type == type))
1059008Sroot 			return (pr);
10624519Skarels 
10721766Skarels 		if (type == SOCK_RAW && pr->pr_type == SOCK_RAW &&
10821766Skarels 		    pr->pr_protocol == 0 && maybe == (struct protosw *)0)
10921766Skarels 			maybe = pr;
11021766Skarels 	}
11121766Skarels 	return (maybe);
1129008Sroot }
1139008Sroot 
11458399Smckusick net_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
11557842Smckusick 	int *name;
11657842Smckusick 	u_int namelen;
11757842Smckusick 	void *oldp;
11858467Sbostic 	size_t *oldlenp;
11957842Smckusick 	void *newp;
12058467Sbostic 	size_t newlen;
12158399Smckusick 	struct proc *p;
12257842Smckusick {
12357842Smckusick 	register struct domain *dp;
12457842Smckusick 	register struct protosw *pr;
12557842Smckusick 	int family, protocol;
12657842Smckusick 
12757842Smckusick 	/*
12857842Smckusick 	 * All sysctl names at this level are nonterminal;
12957842Smckusick 	 * next two components are protocol family and protocol number,
13057842Smckusick 	 * then at least one addition component.
13157842Smckusick 	 */
13259125Smckusick 	if (namelen < 3)
13357842Smckusick 		return (EISDIR);		/* overloaded */
13457842Smckusick 	family = name[0];
13557842Smckusick 	protocol = name[1];
13657842Smckusick 
13757842Smckusick 	if (family == 0)
13857842Smckusick 		return (0);
13957842Smckusick 	for (dp = domains; dp; dp = dp->dom_next)
14057842Smckusick 		if (dp->dom_family == family)
14157842Smckusick 			goto found;
14257842Smckusick 	return (ENOPROTOOPT);
14357842Smckusick found:
14457842Smckusick 	for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
14557842Smckusick 		if (pr->pr_protocol == protocol && pr->pr_sysctl)
14657842Smckusick 			return ((*pr->pr_sysctl)(name + 2, namelen - 2,
14757842Smckusick 			    oldp, oldlenp, newp, newlen));
14857842Smckusick 	return (ENOPROTOOPT);
14957842Smckusick }
15057842Smckusick 
15124767Skarels pfctlinput(cmd, sa)
1529008Sroot 	int cmd;
15324767Skarels 	struct sockaddr *sa;
1549008Sroot {
1559008Sroot 	register struct domain *dp;
1569008Sroot 	register struct protosw *pr;
1579008Sroot 
1589008Sroot 	for (dp = domains; dp; dp = dp->dom_next)
1599008Sroot 		for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
1609008Sroot 			if (pr->pr_ctlinput)
16140668Skarels 				(*pr->pr_ctlinput)(cmd, sa, (caddr_t) 0);
1629008Sroot }
1639008Sroot 
1649008Sroot pfslowtimo()
1659008Sroot {
1669008Sroot 	register struct domain *dp;
1679008Sroot 	register struct protosw *pr;
1689008Sroot 
1699008Sroot 	for (dp = domains; dp; dp = dp->dom_next)
1709008Sroot 		for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
1719008Sroot 			if (pr->pr_slowtimo)
1729008Sroot 				(*pr->pr_slowtimo)();
1739161Ssam 	timeout(pfslowtimo, (caddr_t)0, hz/2);
1749008Sroot }
1759008Sroot 
1769008Sroot pffasttimo()
1779008Sroot {
1789008Sroot 	register struct domain *dp;
1799008Sroot 	register struct protosw *pr;
1809008Sroot 
1819008Sroot 	for (dp = domains; dp; dp = dp->dom_next)
1829008Sroot 		for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
1839008Sroot 			if (pr->pr_fasttimo)
1849008Sroot 				(*pr->pr_fasttimo)();
1859161Ssam 	timeout(pffasttimo, (caddr_t)0, hz/5);
1869008Sroot }
187