uipc_domain.c revision 10080
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 * $Id: uipc_domain.c,v 1.6 1995/05/11 00:16:44 wollman Exp $ 35 */ 36 37#include <sys/param.h> 38#include <sys/socket.h> 39#include <sys/protosw.h> 40#include <sys/domain.h> 41#include <sys/mbuf.h> 42#include <sys/time.h> 43#include <sys/kernel.h> 44#include <sys/systm.h> 45#include <sys/proc.h> 46#include <vm/vm.h> 47#include <sys/sysctl.h> 48 49void pffasttimo __P((void *)); 50void pfslowtimo __P((void *)); 51 52struct domain *domains; 53 54#define ADDDOMAIN(x) { \ 55 __CONCAT(x,domain.dom_next) = domains; \ 56 domains = &__CONCAT(x,domain); \ 57} 58 59extern struct linker_set domain_set; 60 61void 62domaininit() 63{ 64 register struct domain *dp, **dpp; 65 register struct protosw *pr; 66 67 /* 68 * NB - local domain is always present. 69 */ 70 ADDDOMAIN(local); 71 72 for (dpp = (struct domain **)domain_set.ls_items; *dpp; dpp++) { 73 (**dpp).dom_next = domains; 74 domains = *dpp; 75 } 76 77/* - not in our sources 78#ifdef ISDN 79 ADDDOMAIN(isdn); 80#endif 81*/ 82 83 for (dp = domains; dp; dp = dp->dom_next) { 84 if (dp->dom_init) 85 (*dp->dom_init)(); 86 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) 87 if (pr->pr_init) 88 (*pr->pr_init)(); 89 } 90 91 if (max_linkhdr < 16) /* XXX */ 92 max_linkhdr = 16; 93 max_hdr = max_linkhdr + max_protohdr; 94 max_datalen = MHLEN - max_hdr; 95 timeout(pffasttimo, (void *)0, 1); 96 timeout(pfslowtimo, (void *)0, 1); 97} 98 99struct protosw * 100pffindtype(family, type) 101 int family, type; 102{ 103 register struct domain *dp; 104 register struct protosw *pr; 105 106 for (dp = domains; dp; dp = dp->dom_next) 107 if (dp->dom_family == family) 108 goto found; 109 return (0); 110found: 111 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) 112 if (pr->pr_type && pr->pr_type == type) 113 return (pr); 114 return (0); 115} 116 117struct protosw * 118pffindproto(family, protocol, type) 119 int family, protocol, type; 120{ 121 register struct domain *dp; 122 register struct protosw *pr; 123 struct protosw *maybe = 0; 124 125 if (family == 0) 126 return (0); 127 for (dp = domains; dp; dp = dp->dom_next) 128 if (dp->dom_family == family) 129 goto found; 130 return (0); 131found: 132 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) { 133 if ((pr->pr_protocol == protocol) && (pr->pr_type == type)) 134 return (pr); 135 136 if (type == SOCK_RAW && pr->pr_type == SOCK_RAW && 137 pr->pr_protocol == 0 && maybe == (struct protosw *)0) 138 maybe = pr; 139 } 140 return (maybe); 141} 142 143int 144net_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); 173found: 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 181void 182pfctlinput(cmd, sa) 183 int cmd; 184 struct sockaddr *sa; 185{ 186 register struct domain *dp; 187 register struct protosw *pr; 188 189 for (dp = domains; dp; dp = dp->dom_next) 190 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) 191 if (pr->pr_ctlinput) 192 (*pr->pr_ctlinput)(cmd, sa, (caddr_t)0); 193} 194 195void 196pfslowtimo(arg) 197 void *arg; 198{ 199 register struct domain *dp; 200 register struct protosw *pr; 201 202 for (dp = domains; dp; dp = dp->dom_next) 203 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) 204 if (pr->pr_slowtimo) 205 (*pr->pr_slowtimo)(); 206 timeout(pfslowtimo, (void *)0, hz/2); 207} 208 209void 210pffasttimo(arg) 211 void *arg; 212{ 213 register struct domain *dp; 214 register struct protosw *pr; 215 216 for (dp = domains; dp; dp = dp->dom_next) 217 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) 218 if (pr->pr_fasttimo) 219 (*pr->pr_fasttimo)(); 220 timeout(pffasttimo, (void *)0, hz/5); 221} 222