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.3 1994/08/02 07:43:00 davidg 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 49 void pffasttimo __P((void *)); 50 void pfslowtimo __P((void *)); 51 52 #define ADDDOMAIN(x) { \ 53 extern struct domain __CONCAT(x,domain); \ 54 __CONCAT(x,domain.dom_next) = domains; \ 55 domains = &__CONCAT(x,domain); \ 56 } 57 58 void 59 domaininit() 60 { 61 register struct domain *dp; 62 register struct protosw *pr; 63 64 #undef unix 65 #ifndef lint 66 ADDDOMAIN(unix); 67 ADDDOMAIN(route); 68 #ifdef INET 69 ADDDOMAIN(inet); 70 #endif 71 #ifdef NS 72 ADDDOMAIN(ns); 73 #endif 74 #ifdef ISO 75 ADDDOMAIN(iso); 76 #endif 77 #ifdef CCITT 78 ADDDOMAIN(ccitt); 79 #endif 80 #ifdef ISDN 81 ADDDOMAIN(isdn); 82 #endif 83 #include "imp.h" 84 #if NIMP > 0 85 ADDDOMAIN(imp); 86 #endif 87 #endif 88 89 for (dp = domains; dp; dp = dp->dom_next) { 90 if (dp->dom_init) 91 (*dp->dom_init)(); 92 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) 93 if (pr->pr_init) 94 (*pr->pr_init)(); 95 } 96 97 if (max_linkhdr < 16) /* XXX */ 98 max_linkhdr = 16; 99 max_hdr = max_linkhdr + max_protohdr; 100 max_datalen = MHLEN - max_hdr; 101 timeout(pffasttimo, (void *)0, 1); 102 timeout(pfslowtimo, (void *)0, 1); 103 } 104 105 struct protosw * 106 pffindtype(family, type) 107 int family, type; 108 { 109 register struct domain *dp; 110 register struct protosw *pr; 111 112 for (dp = domains; dp; dp = dp->dom_next) 113 if (dp->dom_family == family) 114 goto found; 115 return (0); 116 found: 117 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) 118 if (pr->pr_type && pr->pr_type == type) 119 return (pr); 120 return (0); 121 } 122 123 struct protosw * 124 pffindproto(family, protocol, type) 125 int family, protocol, type; 126 { 127 register struct domain *dp; 128 register struct protosw *pr; 129 struct protosw *maybe = 0; 130 131 if (family == 0) 132 return (0); 133 for (dp = domains; dp; dp = dp->dom_next) 134 if (dp->dom_family == family) 135 goto found; 136 return (0); 137 found: 138 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) { 139 if ((pr->pr_protocol == protocol) && (pr->pr_type == type)) 140 return (pr); 141 142 if (type == SOCK_RAW && pr->pr_type == SOCK_RAW && 143 pr->pr_protocol == 0 && maybe == (struct protosw *)0) 144 maybe = pr; 145 } 146 return (maybe); 147 } 148 149 int 150 net_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p) 151 int *name; 152 u_int namelen; 153 void *oldp; 154 size_t *oldlenp; 155 void *newp; 156 size_t newlen; 157 struct proc *p; 158 { 159 register struct domain *dp; 160 register struct protosw *pr; 161 int family, protocol; 162 163 /* 164 * All sysctl names at this level are nonterminal; 165 * next two components are protocol family and protocol number, 166 * then at least one addition component. 167 */ 168 if (namelen < 3) 169 return (EISDIR); /* overloaded */ 170 family = name[0]; 171 protocol = name[1]; 172 173 if (family == 0) 174 return (0); 175 for (dp = domains; dp; dp = dp->dom_next) 176 if (dp->dom_family == family) 177 goto found; 178 return (ENOPROTOOPT); 179 found: 180 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) 181 if (pr->pr_protocol == protocol && pr->pr_sysctl) 182 return ((*pr->pr_sysctl)(name + 2, namelen - 2, 183 oldp, oldlenp, newp, newlen)); 184 return (ENOPROTOOPT); 185 } 186 187 void 188 pfctlinput(cmd, sa) 189 int cmd; 190 struct sockaddr *sa; 191 { 192 register struct domain *dp; 193 register struct protosw *pr; 194 195 for (dp = domains; dp; dp = dp->dom_next) 196 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) 197 if (pr->pr_ctlinput) 198 (*pr->pr_ctlinput)(cmd, sa, (caddr_t)0); 199 } 200 201 void 202 pfslowtimo(arg) 203 void *arg; 204 { 205 register struct domain *dp; 206 register struct protosw *pr; 207 208 for (dp = domains; dp; dp = dp->dom_next) 209 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) 210 if (pr->pr_slowtimo) 211 (*pr->pr_slowtimo)(); 212 timeout(pfslowtimo, (void *)0, hz/2); 213 } 214 215 void 216 pffasttimo(arg) 217 void *arg; 218 { 219 register struct domain *dp; 220 register struct protosw *pr; 221 222 for (dp = domains; dp; dp = dp->dom_next) 223 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) 224 if (pr->pr_fasttimo) 225 (*pr->pr_fasttimo)(); 226 timeout(pffasttimo, (void *)0, hz/5); 227 } 228