Home | History | Annotate | Line # | Download | only in kern
uipc_domain.c revision 1.3
      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.3 1993/05/20 02:55:21 cgd Exp $
     35  */
     36 
     37 #include <sys/cdefs.h>
     38 #include "param.h"
     39 #include "socket.h"
     40 #include "protosw.h"
     41 #include "domain.h"
     42 #include "mbuf.h"
     43 #include "time.h"
     44 #include "kernel.h"
     45 
     46 #define	ADDDOMAIN(x)	{ \
     47 	extern struct domain __CONCAT(x,domain); \
     48 	__CONCAT(x,domain.dom_next) = domains; \
     49 	domains = &__CONCAT(x,domain); \
     50 }
     51 
     52 domaininit()
     53 {
     54 	register struct domain *dp;
     55 	register struct protosw *pr;
     56 
     57 #undef unix
     58 #ifndef lint
     59 	ADDDOMAIN(unix);
     60 	ADDDOMAIN(route);
     61 #ifdef INET
     62 	ADDDOMAIN(inet);
     63 #endif
     64 #ifdef NS
     65 	ADDDOMAIN(ns);
     66 #endif
     67 #ifdef ISO
     68 	ADDDOMAIN(iso);
     69 #endif
     70 #ifdef RMP
     71 	ADDDOMAIN(rmp);
     72 #endif
     73 #ifdef CCITT
     74 	ADDDOMAIN(ccitt);
     75 #endif
     76 #ifdef IMP
     77 	ADDDOMAIN(imp);
     78 #endif
     79 #endif
     80 
     81 	for (dp = domains; dp; dp = dp->dom_next) {
     82 		if (dp->dom_init)
     83 			(*dp->dom_init)();
     84 		for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
     85 			if (pr->pr_init)
     86 				(*pr->pr_init)();
     87 	}
     88 
     89 if (max_linkhdr < 16)		/* XXX */
     90 max_linkhdr = 16;
     91 	max_hdr = max_linkhdr + max_protohdr;
     92 	max_datalen = MHLEN - max_hdr;
     93 	pffasttimo();
     94 	pfslowtimo();
     95 }
     96 
     97 struct protosw *
     98 pffindtype(family, type)
     99 	int family, type;
    100 {
    101 	register struct domain *dp;
    102 	register struct protosw *pr;
    103 
    104 	for (dp = domains; dp; dp = dp->dom_next)
    105 		if (dp->dom_family == family)
    106 			goto found;
    107 	return (0);
    108 found:
    109 	for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
    110 		if (pr->pr_type && pr->pr_type == type)
    111 			return (pr);
    112 	return (0);
    113 }
    114 
    115 struct protosw *
    116 pffindproto(family, protocol, type)
    117 	int family, protocol, type;
    118 {
    119 	register struct domain *dp;
    120 	register struct protosw *pr;
    121 	struct protosw *maybe = 0;
    122 
    123 	if (family == 0)
    124 		return (0);
    125 	for (dp = domains; dp; dp = dp->dom_next)
    126 		if (dp->dom_family == family)
    127 			goto found;
    128 	return (0);
    129 found:
    130 	for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) {
    131 		if ((pr->pr_protocol == protocol) && (pr->pr_type == type))
    132 			return (pr);
    133 
    134 		if (type == SOCK_RAW && pr->pr_type == SOCK_RAW &&
    135 		    pr->pr_protocol == 0 && maybe == (struct protosw *)0)
    136 			maybe = pr;
    137 	}
    138 	return (maybe);
    139 }
    140 
    141 pfctlinput(cmd, sa)
    142 	int cmd;
    143 	struct sockaddr *sa;
    144 {
    145 	register struct domain *dp;
    146 	register struct protosw *pr;
    147 
    148 	for (dp = domains; dp; dp = dp->dom_next)
    149 		for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
    150 			if (pr->pr_ctlinput)
    151 				(*pr->pr_ctlinput)(cmd, sa, (caddr_t) 0);
    152 }
    153 
    154 pfslowtimo()
    155 {
    156 	register struct domain *dp;
    157 	register struct protosw *pr;
    158 
    159 	for (dp = domains; dp; dp = dp->dom_next)
    160 		for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
    161 			if (pr->pr_slowtimo)
    162 				(*pr->pr_slowtimo)();
    163 	timeout(pfslowtimo, (caddr_t)0, hz/2);
    164 }
    165 
    166 pffasttimo()
    167 {
    168 	register struct domain *dp;
    169 	register struct protosw *pr;
    170 
    171 	for (dp = domains; dp; dp = dp->dom_next)
    172 		for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
    173 			if (pr->pr_fasttimo)
    174 				(*pr->pr_fasttimo)();
    175 	timeout(pffasttimo, (caddr_t)0, hz/5);
    176 }
    177