Home | History | Annotate | Line # | Download | only in kern
uipc_domain.c revision 1.1.1.2
      1 /*
      2  * Copyright (c) 1982, 1986, 1993
      3  *	The Regents of the University of California.  All rights reserved.
      4  *
      5  * Redistribution and use in source and binary forms, with or without
      6  * modification, are permitted provided that the following conditions
      7  * are met:
      8  * 1. Redistributions of source code must retain the above copyright
      9  *    notice, this list of conditions and the following disclaimer.
     10  * 2. Redistributions in binary form must reproduce the above copyright
     11  *    notice, this list of conditions and the following disclaimer in the
     12  *    documentation and/or other materials provided with the distribution.
     13  * 3. All advertising materials mentioning features or use of this software
     14  *    must display the following acknowledgement:
     15  *	This product includes software developed by the University of
     16  *	California, Berkeley and its contributors.
     17  * 4. Neither the name of the University nor the names of its contributors
     18  *    may be used to endorse or promote products derived from this software
     19  *    without specific prior written permission.
     20  *
     21  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     31  * SUCH DAMAGE.
     32  *
     33  *	@(#)uipc_domain.c	8.2 (Berkeley) 10/18/93
     34  */
     35 
     36 #include <sys/param.h>
     37 #include <sys/socket.h>
     38 #include <sys/protosw.h>
     39 #include <sys/domain.h>
     40 #include <sys/mbuf.h>
     41 #include <sys/time.h>
     42 #include <sys/kernel.h>
     43 #include <sys/systm.h>
     44 #include <sys/proc.h>
     45 #include <vm/vm.h>
     46 #include <sys/sysctl.h>
     47 
     48 void	pffasttimo __P((void *));
     49 void	pfslowtimo __P((void *));
     50 
     51 #define	ADDDOMAIN(x)	{ \
     52 	extern struct domain __CONCAT(x,domain); \
     53 	__CONCAT(x,domain.dom_next) = domains; \
     54 	domains = &__CONCAT(x,domain); \
     55 }
     56 
     57 domaininit()
     58 {
     59 	register struct domain *dp;
     60 	register struct protosw *pr;
     61 
     62 #undef unix
     63 #ifndef lint
     64 	ADDDOMAIN(unix);
     65 	ADDDOMAIN(route);
     66 #ifdef INET
     67 	ADDDOMAIN(inet);
     68 #endif
     69 #ifdef NS
     70 	ADDDOMAIN(ns);
     71 #endif
     72 #ifdef ISO
     73 	ADDDOMAIN(iso);
     74 #endif
     75 #ifdef CCITT
     76 	ADDDOMAIN(ccitt);
     77 #endif
     78 #include "imp.h"
     79 #if NIMP > 0
     80 	ADDDOMAIN(imp);
     81 #endif
     82 #endif
     83 
     84 	for (dp = domains; dp; dp = dp->dom_next) {
     85 		if (dp->dom_init)
     86 			(*dp->dom_init)();
     87 		for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
     88 			if (pr->pr_init)
     89 				(*pr->pr_init)();
     90 	}
     91 
     92 if (max_linkhdr < 16)		/* XXX */
     93 max_linkhdr = 16;
     94 	max_hdr = max_linkhdr + max_protohdr;
     95 	max_datalen = MHLEN - max_hdr;
     96 	timeout(pffasttimo, (void *)0, 1);
     97 	timeout(pfslowtimo, (void *)0, 1);
     98 }
     99 
    100 struct protosw *
    101 pffindtype(family, type)
    102 	int family, type;
    103 {
    104 	register struct domain *dp;
    105 	register struct protosw *pr;
    106 
    107 	for (dp = domains; dp; dp = dp->dom_next)
    108 		if (dp->dom_family == family)
    109 			goto found;
    110 	return (0);
    111 found:
    112 	for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
    113 		if (pr->pr_type && pr->pr_type == type)
    114 			return (pr);
    115 	return (0);
    116 }
    117 
    118 struct protosw *
    119 pffindproto(family, protocol, type)
    120 	int family, protocol, type;
    121 {
    122 	register struct domain *dp;
    123 	register struct protosw *pr;
    124 	struct protosw *maybe = 0;
    125 
    126 	if (family == 0)
    127 		return (0);
    128 	for (dp = domains; dp; dp = dp->dom_next)
    129 		if (dp->dom_family == family)
    130 			goto found;
    131 	return (0);
    132 found:
    133 	for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) {
    134 		if ((pr->pr_protocol == protocol) && (pr->pr_type == type))
    135 			return (pr);
    136 
    137 		if (type == SOCK_RAW && pr->pr_type == SOCK_RAW &&
    138 		    pr->pr_protocol == 0 && maybe == (struct protosw *)0)
    139 			maybe = pr;
    140 	}
    141 	return (maybe);
    142 }
    143 
    144 net_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
    145 	int *name;
    146 	u_int namelen;
    147 	void *oldp;
    148 	size_t *oldlenp;
    149 	void *newp;
    150 	size_t newlen;
    151 	struct proc *p;
    152 {
    153 	register struct domain *dp;
    154 	register struct protosw *pr;
    155 	int family, protocol;
    156 
    157 	/*
    158 	 * All sysctl names at this level are nonterminal;
    159 	 * next two components are protocol family and protocol number,
    160 	 * then at least one addition component.
    161 	 */
    162 	if (namelen < 3)
    163 		return (EISDIR);		/* overloaded */
    164 	family = name[0];
    165 	protocol = name[1];
    166 
    167 	if (family == 0)
    168 		return (0);
    169 	for (dp = domains; dp; dp = dp->dom_next)
    170 		if (dp->dom_family == family)
    171 			goto found;
    172 	return (ENOPROTOOPT);
    173 found:
    174 	for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
    175 		if (pr->pr_protocol == protocol && pr->pr_sysctl)
    176 			return ((*pr->pr_sysctl)(name + 2, namelen - 2,
    177 			    oldp, oldlenp, newp, newlen));
    178 	return (ENOPROTOOPT);
    179 }
    180 
    181 pfctlinput(cmd, sa)
    182 	int cmd;
    183 	struct sockaddr *sa;
    184 {
    185 	register struct domain *dp;
    186 	register struct protosw *pr;
    187 
    188 	for (dp = domains; dp; dp = dp->dom_next)
    189 		for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
    190 			if (pr->pr_ctlinput)
    191 				(*pr->pr_ctlinput)(cmd, sa, (caddr_t)0);
    192 }
    193 
    194 void
    195 pfslowtimo(arg)
    196 	void *arg;
    197 {
    198 	register struct domain *dp;
    199 	register struct protosw *pr;
    200 
    201 	for (dp = domains; dp; dp = dp->dom_next)
    202 		for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
    203 			if (pr->pr_slowtimo)
    204 				(*pr->pr_slowtimo)();
    205 	timeout(pfslowtimo, (void *)0, hz/2);
    206 }
    207 
    208 void
    209 pffasttimo(arg)
    210 	void *arg;
    211 {
    212 	register struct domain *dp;
    213 	register struct protosw *pr;
    214 
    215 	for (dp = domains; dp; dp = dp->dom_next)
    216 		for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
    217 			if (pr->pr_fasttimo)
    218 				(*pr->pr_fasttimo)();
    219 	timeout(pffasttimo, (void *)0, hz/5);
    220 }
    221