Home | History | Annotate | Line # | Download | only in kern
uipc_domain.c revision 1.8
      1 /*
      2  * Copyright (c) 1982, 1986 Regents of the University of California.
      3  * 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  *	from: @(#)uipc_domain.c	7.9 (Berkeley) 3/4/91
     34  *	$Id: uipc_domain.c,v 1.8 1994/05/05 05:38:45 cgd Exp $
     35  */
     36 
     37 #include <sys/cdefs.h>
     38 #include <sys/param.h>
     39 #include <sys/systm.h>
     40 #include <sys/socket.h>
     41 #include <sys/protosw.h>
     42 #include <sys/domain.h>
     43 #include <sys/mbuf.h>
     44 #include <sys/time.h>
     45 #include <sys/kernel.h>
     46 
     47 #define	ADDDOMAIN(x)	{ \
     48 	extern struct domain __CONCAT(x,domain); \
     49 	__CONCAT(x,domain.dom_next) = domains; \
     50 	domains = &__CONCAT(x,domain); \
     51 }
     52 
     53 void pffasttimo __P((void *));
     54 void pfslowtimo __P((void *));
     55 
     56 void
     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 RMP
     76 	ADDDOMAIN(rmp);
     77 #endif
     78 #ifdef CCITT
     79 	ADDDOMAIN(ccitt);
     80 #endif
     81 #ifdef IMP
     82 	ADDDOMAIN(imp);
     83 #endif
     84 #endif
     85 
     86 	for (dp = domains; dp; dp = dp->dom_next) {
     87 		if (dp->dom_init)
     88 			(*dp->dom_init)();
     89 		for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
     90 			if (pr->pr_init)
     91 				(*pr->pr_init)();
     92 	}
     93 
     94 if (max_linkhdr < 16)		/* XXX */
     95 max_linkhdr = 16;
     96 	max_hdr = max_linkhdr + max_protohdr;
     97 	max_datalen = MHLEN - max_hdr;
     98 	timeout(pffasttimo, (caddr_t)0, 1);
     99 	timeout(pfslowtimo, (caddr_t)0, 1);
    100 }
    101 
    102 struct protosw *
    103 pffindtype(family, type)
    104 	int family, type;
    105 {
    106 	register struct domain *dp;
    107 	register struct protosw *pr;
    108 
    109 	for (dp = domains; dp; dp = dp->dom_next)
    110 		if (dp->dom_family == family)
    111 			goto found;
    112 	return (0);
    113 found:
    114 	for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
    115 		if (pr->pr_type && pr->pr_type == type)
    116 			return (pr);
    117 	return (0);
    118 }
    119 
    120 struct protosw *
    121 pffindproto(family, protocol, type)
    122 	int family, protocol, type;
    123 {
    124 	register struct domain *dp;
    125 	register struct protosw *pr;
    126 	struct protosw *maybe = 0;
    127 
    128 	if (family == 0)
    129 		return (0);
    130 	for (dp = domains; dp; dp = dp->dom_next)
    131 		if (dp->dom_family == family)
    132 			goto found;
    133 	return (0);
    134 found:
    135 	for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) {
    136 		if ((pr->pr_protocol == protocol) && (pr->pr_type == type))
    137 			return (pr);
    138 
    139 		if (type == SOCK_RAW && pr->pr_type == SOCK_RAW &&
    140 		    pr->pr_protocol == 0 && maybe == (struct protosw *)0)
    141 			maybe = pr;
    142 	}
    143 	return (maybe);
    144 }
    145 
    146 void
    147 pfctlinput(cmd, sa)
    148 	int cmd;
    149 	struct sockaddr *sa;
    150 {
    151 	register struct domain *dp;
    152 	register struct protosw *pr;
    153 
    154 	for (dp = domains; dp; dp = dp->dom_next)
    155 		for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
    156 			if (pr->pr_ctlinput)
    157 				(*pr->pr_ctlinput)(cmd, sa, (caddr_t) 0);
    158 }
    159 
    160 /* ARGSUSED */
    161 void
    162 pfslowtimo(arg)
    163 	void *arg;
    164 {
    165 	register struct domain *dp;
    166 	register struct protosw *pr;
    167 
    168 	for (dp = domains; dp; dp = dp->dom_next)
    169 		for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
    170 			if (pr->pr_slowtimo)
    171 				(*pr->pr_slowtimo)();
    172 	timeout(pfslowtimo, (caddr_t)0, hz/2);
    173 }
    174 
    175 /* ARGSUSED */
    176 void
    177 pffasttimo(arg)
    178 	void *arg;
    179 {
    180 	register struct domain *dp;
    181 	register struct protosw *pr;
    182 
    183 	for (dp = domains; dp; dp = dp->dom_next)
    184 		for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
    185 			if (pr->pr_fasttimo)
    186 				(*pr->pr_fasttimo)();
    187 	timeout(pffasttimo, (caddr_t)0, hz/5);
    188 }
    189