|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. ! 3: * ! 4: * @APPLE_LICENSE_HEADER_START@ ! 5: * ! 6: * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights ! 7: * Reserved. This file contains Original Code and/or Modifications of ! 8: * Original Code as defined in and that are subject to the Apple Public ! 9: * Source License Version 1.1 (the "License"). You may not use this file ! 10: * except in compliance with the License. Please obtain a copy of the ! 11: * License at http://www.apple.com/publicsource and read it before using ! 12: * this file. ! 13: * ! 14: * The Original Code and all software distributed under the License are ! 15: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER ! 16: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, ! 17: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, ! 18: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the ! 19: * License for the specific language governing rights and limitations ! 20: * under the License. ! 21: * ! 22: * @APPLE_LICENSE_HEADER_END@ ! 23: */ ! 24: ! 25: /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ ! 26: /* ! 27: * Copyright (c) 1982, 1986, 1993 ! 28: * The Regents of the University of California. All rights reserved. ! 29: * ! 30: * Redistribution and use in source and binary forms, with or without ! 31: * modification, are permitted provided that the following conditions ! 32: * are met: ! 33: * 1. Redistributions of source code must retain the above copyright ! 34: * notice, this list of conditions and the following disclaimer. ! 35: * 2. Redistributions in binary form must reproduce the above copyright ! 36: * notice, this list of conditions and the following disclaimer in the ! 37: * documentation and/or other materials provided with the distribution. ! 38: * 3. All advertising materials mentioning features or use of this software ! 39: * must display the following acknowledgement: ! 40: * This product includes software developed by the University of ! 41: * California, Berkeley and its contributors. ! 42: * 4. Neither the name of the University nor the names of its contributors ! 43: * may be used to endorse or promote products derived from this software ! 44: * without specific prior written permission. ! 45: * ! 46: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ! 47: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ! 48: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ! 49: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE ! 50: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ! 51: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS ! 52: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ! 53: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT ! 54: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY ! 55: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ! 56: * SUCH DAMAGE. ! 57: * ! 58: * @(#)uipc_domain.c 8.3 (Berkeley) 2/14/95 ! 59: */ ! 60: ! 61: #include <sys/param.h> ! 62: #include <sys/socket.h> ! 63: #include <sys/protosw.h> ! 64: #include <sys/domain.h> ! 65: #include <sys/mbuf.h> ! 66: #include <sys/time.h> ! 67: #include <sys/kernel.h> ! 68: #include <sys/systm.h> ! 69: #include <sys/proc.h> ! 70: #include <sys/sysctl.h> ! 71: ! 72: void pffasttimo __P((void *)); ! 73: void pfslowtimo __P((void *)); ! 74: ! 75: #define ADDDOMAIN(x) { \ ! 76: extern struct domain __CONCAT(x,domain); \ ! 77: __CONCAT(x,domain.dom_next) = domains; \ ! 78: domains = &__CONCAT(x,domain); \ ! 79: } ! 80: ! 81: void ! 82: domaininit() ! 83: { ! 84: register struct domain *dp; ! 85: register struct protosw *pr; ! 86: ! 87: #undef unix ! 88: #ifndef lint ! 89: ADDDOMAIN(unix); ! 90: ADDDOMAIN(route); ! 91: #if INET ! 92: ADDDOMAIN(inet); ! 93: #endif ! 94: #if NS ! 95: ADDDOMAIN(ns); ! 96: #endif ! 97: #if ISO ! 98: ADDDOMAIN(iso); ! 99: #endif ! 100: #if CCITT ! 101: ADDDOMAIN(ccitt); ! 102: #endif ! 103: ! 104: #if defined(ppc) ! 105: ADDDOMAIN(ndrv); ! 106: #endif /* ppc */ ! 107: ! 108: ! 109: #ifdef notdef /* XXXX */ ! 110: #include "imp.h" ! 111: #if NIMP > 0 ! 112: ADDDOMAIN(imp); ! 113: #endif ! 114: #endif ! 115: #endif ! 116: ! 117: for (dp = domains; dp; dp = dp->dom_next) { ! 118: if (dp->dom_init) ! 119: (*dp->dom_init)(); ! 120: for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) ! 121: if (pr->pr_init) ! 122: (*pr->pr_init)(); ! 123: } ! 124: ! 125: if (max_linkhdr < 16) /* XXX */ ! 126: max_linkhdr = 16; ! 127: max_hdr = max_linkhdr + max_protohdr; ! 128: max_datalen = MHLEN - max_hdr; ! 129: timeout(pffasttimo, NULL, 1); ! 130: timeout(pfslowtimo, NULL, 1); ! 131: } ! 132: ! 133: struct protosw * ! 134: pffindtype(family, type) ! 135: int family, type; ! 136: { ! 137: register struct domain *dp; ! 138: register struct protosw *pr; ! 139: ! 140: for (dp = domains; dp; dp = dp->dom_next) ! 141: if (dp->dom_family == family) ! 142: goto found; ! 143: return (0); ! 144: found: ! 145: for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) ! 146: if (pr->pr_type && pr->pr_type == type) ! 147: return (pr); ! 148: return (0); ! 149: } ! 150: ! 151: struct protosw * ! 152: pffindproto(family, protocol, type) ! 153: int family, protocol, type; ! 154: { ! 155: register struct domain *dp; ! 156: register struct protosw *pr; ! 157: struct protosw *maybe = 0; ! 158: ! 159: if (family == 0) ! 160: return (0); ! 161: for (dp = domains; dp; dp = dp->dom_next) ! 162: if (dp->dom_family == family) ! 163: goto found; ! 164: return (0); ! 165: found: ! 166: for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) { ! 167: if ((pr->pr_protocol == protocol) && (pr->pr_type == type)) ! 168: return (pr); ! 169: ! 170: if (type == SOCK_RAW && pr->pr_type == SOCK_RAW && ! 171: pr->pr_protocol == 0 && maybe == (struct protosw *)0) ! 172: maybe = pr; ! 173: } ! 174: return (maybe); ! 175: } ! 176: ! 177: int ! 178: net_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p) ! 179: int *name; ! 180: u_int namelen; ! 181: void *oldp; ! 182: size_t *oldlenp; ! 183: void *newp; ! 184: size_t newlen; ! 185: struct proc *p; ! 186: { ! 187: register struct domain *dp; ! 188: register struct protosw *pr; ! 189: int family, protocol; ! 190: ! 191: /* ! 192: * All sysctl names at this level are nonterminal; ! 193: * next two components are protocol family and protocol number, ! 194: * then at least one addition component. ! 195: */ ! 196: if (namelen < 3) ! 197: return (EISDIR); /* overloaded */ ! 198: family = name[0]; ! 199: protocol = name[1]; ! 200: ! 201: if (family == 0) ! 202: return (0); ! 203: for (dp = domains; dp; dp = dp->dom_next) ! 204: if (dp->dom_family == family) ! 205: goto found; ! 206: return (ENOPROTOOPT); ! 207: found: ! 208: for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) ! 209: if (pr->pr_protocol == protocol && pr->pr_sysctl) ! 210: return ((*pr->pr_sysctl)(name + 2, namelen - 2, ! 211: oldp, oldlenp, newp, newlen)); ! 212: return (ENOPROTOOPT); ! 213: } ! 214: ! 215: void ! 216: pfctlinput(cmd, sa) ! 217: int cmd; ! 218: struct sockaddr *sa; ! 219: { ! 220: register struct domain *dp; ! 221: register struct protosw *pr; ! 222: ! 223: for (dp = domains; dp; dp = dp->dom_next) ! 224: for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) ! 225: if (pr->pr_ctlinput) ! 226: (*pr->pr_ctlinput)(cmd, sa, (caddr_t)0); ! 227: } ! 228: ! 229: void ! 230: pfslowtimo(arg) ! 231: void *arg; ! 232: { ! 233: register struct domain *dp; ! 234: register struct protosw *pr; ! 235: ! 236: for (dp = domains; dp; dp = dp->dom_next) ! 237: for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) ! 238: if (pr->pr_slowtimo) ! 239: (*pr->pr_slowtimo)(); ! 240: timeout(pfslowtimo, NULL, hz/2); ! 241: } ! 242: ! 243: void ! 244: pffasttimo(arg) ! 245: void *arg; ! 246: { ! 247: register struct domain *dp; ! 248: register struct protosw *pr; ! 249: ! 250: for (dp = domains; dp; dp = dp->dom_next) ! 251: for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) ! 252: if (pr->pr_fasttimo) ! 253: (*pr->pr_fasttimo)(); ! 254: timeout(pffasttimo, NULL, hz/5); ! 255: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.