[BACK]Return to uipc_domain.c CVS log [TXT][DIR] Up to [local] / sys / kern

Annotation of sys/kern/uipc_domain.c, Revision 1.1

1.1     ! nbrk        1: /*     $OpenBSD: uipc_domain.c,v 1.26 2007/06/06 10:04:36 henning Exp $        */
        !             2: /*     $NetBSD: uipc_domain.c,v 1.14 1996/02/09 19:00:44 christos Exp $        */
        !             3:
        !             4: /*
        !             5:  * Copyright (c) 1982, 1986, 1993
        !             6:  *     The Regents of the University of California.  All rights reserved.
        !             7:  *
        !             8:  * Redistribution and use in source and binary forms, with or without
        !             9:  * modification, are permitted provided that the following conditions
        !            10:  * are met:
        !            11:  * 1. Redistributions of source code must retain the above copyright
        !            12:  *    notice, this list of conditions and the following disclaimer.
        !            13:  * 2. Redistributions in binary form must reproduce the above copyright
        !            14:  *    notice, this list of conditions and the following disclaimer in the
        !            15:  *    documentation and/or other materials provided with the distribution.
        !            16:  * 3. Neither the name of the University nor the names of its contributors
        !            17:  *    may be used to endorse or promote products derived from this software
        !            18:  *    without specific prior written permission.
        !            19:  *
        !            20:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
        !            21:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        !            22:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
        !            23:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
        !            24:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
        !            25:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
        !            26:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
        !            27:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
        !            28:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
        !            29:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
        !            30:  * SUCH DAMAGE.
        !            31:  *
        !            32:  *     @(#)uipc_domain.c       8.2 (Berkeley) 10/18/93
        !            33:  */
        !            34:
        !            35: #include <sys/param.h>
        !            36: #include <sys/socket.h>
        !            37: #include <sys/protosw.h>
        !            38: #include <sys/domain.h>
        !            39: #include <sys/mbuf.h>
        !            40: #include <sys/time.h>
        !            41: #include <sys/kernel.h>
        !            42: #include <sys/systm.h>
        !            43: #include <sys/proc.h>
        !            44: #include <uvm/uvm_extern.h>
        !            45: #include <sys/sysctl.h>
        !            46: #include <sys/timeout.h>
        !            47:
        !            48: #include "bluetooth.h"
        !            49: #include "bpfilter.h"
        !            50:
        !            51: struct domain *domains;
        !            52:
        !            53: void           pffasttimo(void *);
        !            54: void           pfslowtimo(void *);
        !            55: struct domain *        pffinddomain(int);
        !            56:
        !            57: #if defined (KEY) || defined (IPSEC) || defined (TCP_SIGNATURE)
        !            58: int pfkey_init(void);
        !            59: #endif /* KEY || IPSEC || TCP_SIGNATURE */
        !            60:
        !            61: #define        ADDDOMAIN(x)    { \
        !            62:        extern struct domain __CONCAT(x,domain); \
        !            63:        __CONCAT(x,domain.dom_next) = domains; \
        !            64:        domains = &__CONCAT(x,domain); \
        !            65: }
        !            66:
        !            67: void
        !            68: domaininit(void)
        !            69: {
        !            70:        struct domain *dp;
        !            71:        struct protosw *pr;
        !            72:        static struct timeout pffast_timeout;
        !            73:        static struct timeout pfslow_timeout;
        !            74:
        !            75: #undef unix
        !            76:        /*
        !            77:         * KAME NOTE: ADDDOMAIN(route) is moved to the last part so that
        !            78:         * it will be initialized as the *first* element.  confusing!
        !            79:         */
        !            80: #ifndef lint
        !            81:        ADDDOMAIN(unix);
        !            82: #ifdef INET
        !            83:        ADDDOMAIN(inet);
        !            84: #endif
        !            85: #ifdef INET6
        !            86:        ADDDOMAIN(inet6);
        !            87: #endif /* INET6 */
        !            88: #if defined (KEY) || defined (IPSEC) || defined (TCP_SIGNATURE)
        !            89:        pfkey_init();
        !            90: #endif /* KEY || IPSEC */
        !            91: #ifdef NETATALK
        !            92:        ADDDOMAIN(atalk);
        !            93: #endif
        !            94: #ifdef NATM
        !            95:        ADDDOMAIN(natm);
        !            96: #endif
        !            97: #ifdef IPSEC
        !            98: #ifdef __KAME__
        !            99:        ADDDOMAIN(key);
        !           100: #endif
        !           101: #endif
        !           102: #if NBLUETOOTH > 0
        !           103:        ADDDOMAIN(bt);
        !           104: #endif
        !           105:        ADDDOMAIN(route);
        !           106: #endif
        !           107:
        !           108:        for (dp = domains; dp; dp = dp->dom_next) {
        !           109:                if (dp->dom_init)
        !           110:                        (*dp->dom_init)();
        !           111:                for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
        !           112:                        if (pr->pr_init)
        !           113:                                (*pr->pr_init)();
        !           114:        }
        !           115:
        !           116:        if (max_linkhdr < 16)           /* XXX */
        !           117:                max_linkhdr = 16;
        !           118:        max_hdr = max_linkhdr + max_protohdr;
        !           119:        max_datalen = MHLEN - max_hdr;
        !           120:        timeout_set(&pffast_timeout, pffasttimo, &pffast_timeout);
        !           121:        timeout_set(&pfslow_timeout, pfslowtimo, &pfslow_timeout);
        !           122:        timeout_add(&pffast_timeout, 1);
        !           123:        timeout_add(&pfslow_timeout, 1);
        !           124: }
        !           125:
        !           126: struct domain *
        !           127: pffinddomain(int family)
        !           128: {
        !           129:        struct domain *dp;
        !           130:
        !           131:        for (dp = domains; dp != NULL; dp = dp->dom_next)
        !           132:                if (dp->dom_family == family)
        !           133:                        return (dp);
        !           134:        return (NULL);
        !           135: }
        !           136:
        !           137: struct protosw *
        !           138: pffindtype(int family, int type)
        !           139: {
        !           140:        struct domain *dp;
        !           141:        struct protosw *pr;
        !           142:
        !           143:        dp = pffinddomain(family);
        !           144:        if (dp == NULL)
        !           145:                return (NULL);
        !           146:
        !           147:        for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
        !           148:                if (pr->pr_type && pr->pr_type == type)
        !           149:                        return (pr);
        !           150:        return (NULL);
        !           151: }
        !           152:
        !           153: struct protosw *
        !           154: pffindproto(int family, int protocol, int type)
        !           155: {
        !           156:        struct domain *dp;
        !           157:        struct protosw *pr;
        !           158:        struct protosw *maybe = NULL;
        !           159:
        !           160:        if (family == 0)
        !           161:                return (NULL);
        !           162:
        !           163:        dp = pffinddomain(family);
        !           164:        if (dp == NULL)
        !           165:                return (NULL);
        !           166:
        !           167:        for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) {
        !           168:                if ((pr->pr_protocol == protocol) && (pr->pr_type == type))
        !           169:                        return (pr);
        !           170:
        !           171:                if (type == SOCK_RAW && pr->pr_type == SOCK_RAW &&
        !           172:                    pr->pr_protocol == 0 && maybe == NULL)
        !           173:                        maybe = pr;
        !           174:        }
        !           175:        return (maybe);
        !           176: }
        !           177:
        !           178: int
        !           179: net_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp,
        !           180:     size_t newlen, struct proc *p)
        !           181: {
        !           182:        struct domain *dp;
        !           183:        struct protosw *pr;
        !           184:        int family, protocol;
        !           185:
        !           186:        /*
        !           187:         * All sysctl names at this level are nonterminal.
        !           188:         * Usually: next two components are protocol family and protocol
        !           189:         *      number, then at least one addition component.
        !           190:         */
        !           191:        if (namelen < 2)
        !           192:                return (EISDIR);                /* overloaded */
        !           193:        family = name[0];
        !           194:
        !           195:        if (family == 0)
        !           196:                return (0);
        !           197: #if NBPFILTER > 0
        !           198:        if (family == PF_BPF)
        !           199:                return (bpf_sysctl(name + 1, namelen - 1, oldp, oldlenp,
        !           200:                    newp, newlen));
        !           201: #endif
        !           202:        dp = pffinddomain(family);
        !           203:        if (dp == NULL)
        !           204:                return (ENOPROTOOPT);
        !           205:
        !           206:        if (namelen < 3)
        !           207:                return (EISDIR);                /* overloaded */
        !           208:        protocol = name[1];
        !           209:        for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
        !           210:                if (pr->pr_protocol == protocol && pr->pr_sysctl)
        !           211:                        return ((*pr->pr_sysctl)(name + 2, namelen - 2,
        !           212:                            oldp, oldlenp, newp, newlen));
        !           213:        return (ENOPROTOOPT);
        !           214: }
        !           215:
        !           216: void
        !           217: pfctlinput(int cmd, struct sockaddr *sa)
        !           218: {
        !           219:        struct domain *dp;
        !           220:        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_ctlinput)
        !           225:                                (*pr->pr_ctlinput)(cmd, sa, NULL);
        !           226: }
        !           227:
        !           228: void
        !           229: pfslowtimo(void *arg)
        !           230: {
        !           231:        struct timeout *to = (struct timeout *)arg;
        !           232:        struct domain *dp;
        !           233:        struct protosw *pr;
        !           234:
        !           235:        for (dp = domains; dp; dp = dp->dom_next)
        !           236:                for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
        !           237:                        if (pr->pr_slowtimo)
        !           238:                                (*pr->pr_slowtimo)();
        !           239:        timeout_add(to, hz/2);
        !           240: }
        !           241:
        !           242: void
        !           243: pffasttimo(void *arg)
        !           244: {
        !           245:        struct timeout *to = (struct timeout *)arg;
        !           246:        struct domain *dp;
        !           247:        struct protosw *pr;
        !           248:
        !           249:        for (dp = domains; dp; dp = dp->dom_next)
        !           250:                for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
        !           251:                        if (pr->pr_fasttimo)
        !           252:                                (*pr->pr_fasttimo)();
        !           253:        timeout_add(to, hz/5);
        !           254: }

CVSweb