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$ 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 #include "imp.h" 81 #if NIMP > 0 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, (void *)0, 1); 99 timeout(pfslowtimo, (void *)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 int 147 net_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p) 148 int *name; 149 u_int namelen; 150 void *oldp; 151 size_t *oldlenp; 152 void *newp; 153 size_t newlen; 154 struct proc *p; 155 { 156 register struct domain *dp; 157 register struct protosw *pr; 158 int family, protocol; 159 160 /* 161 * All sysctl names at this level are nonterminal; 162 * next two components are protocol family and protocol number, 163 * then at least one addition component. 164 */ 165 if (namelen < 3) 166 return (EISDIR); /* overloaded */ 167 family = name[0]; 168 protocol = name[1]; 169 170 if (family == 0) 171 return (0); 172 for (dp = domains; dp; dp = dp->dom_next) 173 if (dp->dom_family == family) 174 goto found; 175 return (ENOPROTOOPT); 176 found: 177 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) 178 if (pr->pr_protocol == protocol && pr->pr_sysctl) 179 return ((*pr->pr_sysctl)(name + 2, namelen - 2, 180 oldp, oldlenp, newp, newlen)); 181 return (ENOPROTOOPT); 182 } 183 184 void 185 pfctlinput(cmd, sa) 186 int cmd; 187 struct sockaddr *sa; 188 { 189 register struct domain *dp; 190 register struct protosw *pr; 191 192 for (dp = domains; dp; dp = dp->dom_next) 193 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) 194 if (pr->pr_ctlinput) 195 (*pr->pr_ctlinput)(cmd, sa, (caddr_t)0); 196 } 197 198 void 199 pfslowtimo(arg) 200 void *arg; 201 { 202 register struct domain *dp; 203 register struct protosw *pr; 204 205 for (dp = domains; dp; dp = dp->dom_next) 206 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) 207 if (pr->pr_slowtimo) 208 (*pr->pr_slowtimo)(); 209 timeout(pfslowtimo, (void *)0, hz/2); 210 } 211 212 void 213 pffasttimo(arg) 214 void *arg; 215 { 216 register struct domain *dp; 217 register struct protosw *pr; 218 219 for (dp = domains; dp; dp = dp->dom_next) 220 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) 221 if (pr->pr_fasttimo) 222 (*pr->pr_fasttimo)(); 223 timeout(pffasttimo, (void *)0, hz/5); 224 } 225