xref: /csrg-svn/sys/kern/uipc_domain.c (revision 68327)
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*68327Scgd  *	@(#)uipc_domain.c	8.3 (Berkeley) 02/14/95
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>
1764730Smckusick #include <sys/systm.h>
1859357Smckusick #include <sys/proc.h>
1959357Smckusick #include <vm/vm.h>
2057842Smckusick #include <sys/sysctl.h>
217425Sroot 
2264730Smckusick void	pffasttimo __P((void *));
2364730Smckusick void	pfslowtimo __P((void *));
2464730Smckusick 
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 
31*68327Scgd void
domaininit()329008Sroot domaininit()
337500Sroot {
349161Ssam 	register struct domain *dp;
359161Ssam 	register struct protosw *pr;
367500Sroot 
3746970Sbostic #undef unix
389161Ssam #ifndef lint
399008Sroot 	ADDDOMAIN(unix);
4037330Skarels 	ADDDOMAIN(route);
4125765Skarels #ifdef INET
429008Sroot 	ADDDOMAIN(inet);
439008Sroot #endif
4418816Ssklower #ifdef NS
4518816Ssklower 	ADDDOMAIN(ns);
4618816Ssklower #endif
4737330Skarels #ifdef ISO
4837330Skarels 	ADDDOMAIN(iso);
4937330Skarels #endif
5045665Ssklower #ifdef CCITT
5145665Ssklower 	ADDDOMAIN(ccitt);
5245665Ssklower #endif
5310025Ssam #include "imp.h"
5410025Ssam #if NIMP > 0
559008Sroot 	ADDDOMAIN(imp);
569008Sroot #endif
579161Ssam #endif
589008Sroot 
5916993Skarels 	for (dp = domains; dp; dp = dp->dom_next) {
6016993Skarels 		if (dp->dom_init)
6116993Skarels 			(*dp->dom_init)();
629008Sroot 		for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
639008Sroot 			if (pr->pr_init)
649008Sroot 				(*pr->pr_init)();
6516993Skarels 	}
6637330Skarels 
6737330Skarels if (max_linkhdr < 16)		/* XXX */
6837330Skarels max_linkhdr = 16;
6937330Skarels 	max_hdr = max_linkhdr + max_protohdr;
7037330Skarels 	max_datalen = MHLEN - max_hdr;
71*68327Scgd 	timeout(pffasttimo, NULL, 1);
72*68327Scgd 	timeout(pfslowtimo, NULL, 1);
739008Sroot }
749008Sroot 
759008Sroot struct protosw *
pffindtype(family,type)769008Sroot pffindtype(family, type)
779008Sroot 	int family, type;
789008Sroot {
799008Sroot 	register struct domain *dp;
809008Sroot 	register struct protosw *pr;
819008Sroot 
829008Sroot 	for (dp = domains; dp; dp = dp->dom_next)
839008Sroot 		if (dp->dom_family == family)
849008Sroot 			goto found;
859008Sroot 	return (0);
869008Sroot found:
879008Sroot 	for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
8811569Ssam 		if (pr->pr_type && pr->pr_type == type)
899008Sroot 			return (pr);
909008Sroot 	return (0);
919008Sroot }
929008Sroot 
939008Sroot struct protosw *
pffindproto(family,protocol,type)9421766Skarels pffindproto(family, protocol, type)
9521766Skarels 	int family, protocol, type;
969008Sroot {
979008Sroot 	register struct domain *dp;
989008Sroot 	register struct protosw *pr;
9921766Skarels 	struct protosw *maybe = 0;
1009008Sroot 
1019008Sroot 	if (family == 0)
1029008Sroot 		return (0);
1039008Sroot 	for (dp = domains; dp; dp = dp->dom_next)
1049008Sroot 		if (dp->dom_family == family)
1059008Sroot 			goto found;
1069008Sroot 	return (0);
1079008Sroot found:
10821766Skarels 	for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) {
10924519Skarels 		if ((pr->pr_protocol == protocol) && (pr->pr_type == type))
1109008Sroot 			return (pr);
11124519Skarels 
11221766Skarels 		if (type == SOCK_RAW && pr->pr_type == SOCK_RAW &&
11321766Skarels 		    pr->pr_protocol == 0 && maybe == (struct protosw *)0)
11421766Skarels 			maybe = pr;
11521766Skarels 	}
11621766Skarels 	return (maybe);
1179008Sroot }
1189008Sroot 
119*68327Scgd int
net_sysctl(name,namelen,oldp,oldlenp,newp,newlen,p)12058399Smckusick net_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
12157842Smckusick 	int *name;
12257842Smckusick 	u_int namelen;
12357842Smckusick 	void *oldp;
12458467Sbostic 	size_t *oldlenp;
12557842Smckusick 	void *newp;
12658467Sbostic 	size_t newlen;
12758399Smckusick 	struct proc *p;
12857842Smckusick {
12957842Smckusick 	register struct domain *dp;
13057842Smckusick 	register struct protosw *pr;
13157842Smckusick 	int family, protocol;
13257842Smckusick 
13357842Smckusick 	/*
13457842Smckusick 	 * All sysctl names at this level are nonterminal;
13557842Smckusick 	 * next two components are protocol family and protocol number,
13657842Smckusick 	 * then at least one addition component.
13757842Smckusick 	 */
13859125Smckusick 	if (namelen < 3)
13957842Smckusick 		return (EISDIR);		/* overloaded */
14057842Smckusick 	family = name[0];
14157842Smckusick 	protocol = name[1];
14257842Smckusick 
14357842Smckusick 	if (family == 0)
14457842Smckusick 		return (0);
14557842Smckusick 	for (dp = domains; dp; dp = dp->dom_next)
14657842Smckusick 		if (dp->dom_family == family)
14757842Smckusick 			goto found;
14857842Smckusick 	return (ENOPROTOOPT);
14957842Smckusick found:
15057842Smckusick 	for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
15157842Smckusick 		if (pr->pr_protocol == protocol && pr->pr_sysctl)
15257842Smckusick 			return ((*pr->pr_sysctl)(name + 2, namelen - 2,
15357842Smckusick 			    oldp, oldlenp, newp, newlen));
15457842Smckusick 	return (ENOPROTOOPT);
15557842Smckusick }
15657842Smckusick 
157*68327Scgd void
pfctlinput(cmd,sa)15824767Skarels pfctlinput(cmd, sa)
1599008Sroot 	int cmd;
16024767Skarels 	struct sockaddr *sa;
1619008Sroot {
1629008Sroot 	register struct domain *dp;
1639008Sroot 	register struct protosw *pr;
1649008Sroot 
1659008Sroot 	for (dp = domains; dp; dp = dp->dom_next)
1669008Sroot 		for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
1679008Sroot 			if (pr->pr_ctlinput)
16864730Smckusick 				(*pr->pr_ctlinput)(cmd, sa, (caddr_t)0);
1699008Sroot }
1709008Sroot 
17164730Smckusick void
pfslowtimo(arg)17264730Smckusick pfslowtimo(arg)
17364730Smckusick 	void *arg;
1749008Sroot {
1759008Sroot 	register struct domain *dp;
1769008Sroot 	register struct protosw *pr;
1779008Sroot 
1789008Sroot 	for (dp = domains; dp; dp = dp->dom_next)
1799008Sroot 		for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
1809008Sroot 			if (pr->pr_slowtimo)
1819008Sroot 				(*pr->pr_slowtimo)();
182*68327Scgd 	timeout(pfslowtimo, NULL, hz/2);
1839008Sroot }
1849008Sroot 
18564730Smckusick void
pffasttimo(arg)18664730Smckusick pffasttimo(arg)
18764730Smckusick 	void *arg;
1889008Sroot {
1899008Sroot 	register struct domain *dp;
1909008Sroot 	register struct protosw *pr;
1919008Sroot 
1929008Sroot 	for (dp = domains; dp; dp = dp->dom_next)
1939008Sroot 		for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
1949008Sroot 			if (pr->pr_fasttimo)
1959008Sroot 				(*pr->pr_fasttimo)();
196*68327Scgd 	timeout(pffasttimo, NULL, hz/5);
1979008Sroot }
198