xref: /csrg-svn/sys/kern/uipc_domain.c (revision 58399)
123416Smckusick /*
229123Smckusick  * Copyright (c) 1982, 1986 Regents of the University of California.
333187Sbostic  * All rights reserved.
423416Smckusick  *
544447Sbostic  * %sccs.include.redist.c%
633187Sbostic  *
7*58399Smckusick  *	@(#)uipc_domain.c	7.13 (Berkeley) 03/02/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>
1757842Smckusick #include <sys/sysctl.h>
187425Sroot 
199008Sroot #define	ADDDOMAIN(x)	{ \
2046970Sbostic 	extern struct domain __CONCAT(x,domain); \
2146970Sbostic 	__CONCAT(x,domain.dom_next) = domains; \
2246970Sbostic 	domains = &__CONCAT(x,domain); \
239008Sroot }
249008Sroot 
259008Sroot domaininit()
267500Sroot {
279161Ssam 	register struct domain *dp;
289161Ssam 	register struct protosw *pr;
297500Sroot 
3046970Sbostic #undef unix
319161Ssam #ifndef lint
329008Sroot 	ADDDOMAIN(unix);
3337330Skarels 	ADDDOMAIN(route);
3425765Skarels #ifdef INET
359008Sroot 	ADDDOMAIN(inet);
369008Sroot #endif
3718816Ssklower #ifdef NS
3818816Ssklower 	ADDDOMAIN(ns);
3918816Ssklower #endif
4037330Skarels #ifdef ISO
4137330Skarels 	ADDDOMAIN(iso);
4237330Skarels #endif
4345665Ssklower #ifdef CCITT
4445665Ssklower 	ADDDOMAIN(ccitt);
4545665Ssklower #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 	}
5937330Skarels 
6037330Skarels if (max_linkhdr < 16)		/* XXX */
6137330Skarels max_linkhdr = 16;
6237330Skarels 	max_hdr = max_linkhdr + max_protohdr;
6337330Skarels 	max_datalen = MHLEN - max_hdr;
649161Ssam 	pffasttimo();
659161Ssam 	pfslowtimo();
669008Sroot }
679008Sroot 
689008Sroot struct protosw *
699008Sroot pffindtype(family, type)
709008Sroot 	int family, type;
719008Sroot {
729008Sroot 	register struct domain *dp;
739008Sroot 	register struct protosw *pr;
749008Sroot 
759008Sroot 	for (dp = domains; dp; dp = dp->dom_next)
769008Sroot 		if (dp->dom_family == family)
779008Sroot 			goto found;
789008Sroot 	return (0);
799008Sroot found:
809008Sroot 	for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
8111569Ssam 		if (pr->pr_type && pr->pr_type == type)
829008Sroot 			return (pr);
839008Sroot 	return (0);
849008Sroot }
859008Sroot 
869008Sroot struct protosw *
8721766Skarels pffindproto(family, protocol, type)
8821766Skarels 	int family, protocol, type;
899008Sroot {
909008Sroot 	register struct domain *dp;
919008Sroot 	register struct protosw *pr;
9221766Skarels 	struct protosw *maybe = 0;
939008Sroot 
949008Sroot 	if (family == 0)
959008Sroot 		return (0);
969008Sroot 	for (dp = domains; dp; dp = dp->dom_next)
979008Sroot 		if (dp->dom_family == family)
989008Sroot 			goto found;
999008Sroot 	return (0);
1009008Sroot found:
10121766Skarels 	for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) {
10224519Skarels 		if ((pr->pr_protocol == protocol) && (pr->pr_type == type))
1039008Sroot 			return (pr);
10424519Skarels 
10521766Skarels 		if (type == SOCK_RAW && pr->pr_type == SOCK_RAW &&
10621766Skarels 		    pr->pr_protocol == 0 && maybe == (struct protosw *)0)
10721766Skarels 			maybe = pr;
10821766Skarels 	}
10921766Skarels 	return (maybe);
1109008Sroot }
1119008Sroot 
112*58399Smckusick net_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
11357842Smckusick 	int *name;
11457842Smckusick 	u_int namelen;
11557842Smckusick 	void *oldp;
11657842Smckusick 	u_int *oldlenp;
11757842Smckusick 	void *newp;
11857842Smckusick 	u_int newlen;
119*58399Smckusick 	struct proc *p;
12057842Smckusick {
12157842Smckusick 	register struct domain *dp;
12257842Smckusick 	register struct protosw *pr;
12357842Smckusick 	int family, protocol;
12457842Smckusick 
12557842Smckusick 	/*
12657842Smckusick 	 * All sysctl names at this level are nonterminal;
12757842Smckusick 	 * next two components are protocol family and protocol number,
12857842Smckusick 	 * then at least one addition component.
12957842Smckusick 	 */
13057842Smckusick 	if (namelen <= 3)
13157842Smckusick 		return (EISDIR);		/* overloaded */
13257842Smckusick 	family = name[0];
13357842Smckusick 	protocol = name[1];
13457842Smckusick 
13557842Smckusick 	if (family == 0)
13657842Smckusick 		return (0);
13757842Smckusick 	for (dp = domains; dp; dp = dp->dom_next)
13857842Smckusick 		if (dp->dom_family == family)
13957842Smckusick 			goto found;
14057842Smckusick 	return (ENOPROTOOPT);
14157842Smckusick found:
14257842Smckusick 	for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
14357842Smckusick 		if (pr->pr_protocol == protocol && pr->pr_sysctl)
14457842Smckusick 			return ((*pr->pr_sysctl)(name + 2, namelen - 2,
14557842Smckusick 			    oldp, oldlenp, newp, newlen));
14657842Smckusick 	return (ENOPROTOOPT);
14757842Smckusick }
14857842Smckusick 
14924767Skarels pfctlinput(cmd, sa)
1509008Sroot 	int cmd;
15124767Skarels 	struct sockaddr *sa;
1529008Sroot {
1539008Sroot 	register struct domain *dp;
1549008Sroot 	register struct protosw *pr;
1559008Sroot 
1569008Sroot 	for (dp = domains; dp; dp = dp->dom_next)
1579008Sroot 		for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
1589008Sroot 			if (pr->pr_ctlinput)
15940668Skarels 				(*pr->pr_ctlinput)(cmd, sa, (caddr_t) 0);
1609008Sroot }
1619008Sroot 
1629008Sroot pfslowtimo()
1639008Sroot {
1649008Sroot 	register struct domain *dp;
1659008Sroot 	register struct protosw *pr;
1669008Sroot 
1679008Sroot 	for (dp = domains; dp; dp = dp->dom_next)
1689008Sroot 		for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
1699008Sroot 			if (pr->pr_slowtimo)
1709008Sroot 				(*pr->pr_slowtimo)();
1719161Ssam 	timeout(pfslowtimo, (caddr_t)0, hz/2);
1729008Sroot }
1739008Sroot 
1749008Sroot pffasttimo()
1759008Sroot {
1769008Sroot 	register struct domain *dp;
1779008Sroot 	register struct protosw *pr;
1789008Sroot 
1799008Sroot 	for (dp = domains; dp; dp = dp->dom_next)
1809008Sroot 		for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
1819008Sroot 			if (pr->pr_fasttimo)
1829008Sroot 				(*pr->pr_fasttimo)();
1839161Ssam 	timeout(pffasttimo, (caddr_t)0, hz/5);
1849008Sroot }
185