Annotation of XNU/iokit/Drivers/network/AppleBPF/AppleBPF.cpp, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
        !             3:  *
        !             4:  * @APPLE_LICENSE_HEADER_START@
        !             5:  * 
        !             6:  * The contents of this file constitute Original Code as defined in and
        !             7:  * are subject to the Apple Public Source License Version 1.1 (the
        !             8:  * "License").  You may not use this file except in compliance with the
        !             9:  * License.  Please obtain a copy of the License at
        !            10:  * http://www.apple.com/publicsource and read it before using this file.
        !            11:  * 
        !            12:  * This Original Code and all software distributed under the License are
        !            13:  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
        !            14:  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
        !            15:  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
        !            16:  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
        !            17:  * License for the specific language governing rights and limitations
        !            18:  * under the License.
        !            19:  * 
        !            20:  * @APPLE_LICENSE_HEADER_END@
        !            21:  */
        !            22: /*
        !            23:  * AppleBPF.cpp - BPF driver class implementation.
        !            24:  *
        !            25:  */
        !            26: 
        !            27: // Need to check with Simon on User/Client interface and how to do
        !            28: // PostLoad, and check on IOBSD (IONeededResource)
        !            29: 
        !            30: #include <assert.h>
        !            31: #include <IOKit/IOLib.h>
        !            32: #include "AppleBPF.h"
        !            33: 
        !            34: extern "C" {
        !            35: #include <sys/time.h>
        !            36: #include <net/bpf.h>
        !            37: #include <net/bpfdesc.h>
        !            38: #include <sys/malloc.h>
        !            39: }
        !            40: 
        !            41: //------------------------------------------------------------------------
        !            42: 
        !            43: #define super IOService
        !            44: OSDefineMetaClassAndStructors(AppleBPF, IOService);
        !            45: 
        !            46: //------------------------------------------------------------------------
        !            47: 
        !            48: 
        !            49: // -----------------------------------------------------------------------
        !            50: //
        !            51: // This is the first method to be called when an object of this class is 
        !            52: // instantiated.
        !            53: // 
        !            54: bool AppleBPF::init(OSDictionary * properties)
        !            55: {
        !            56:        if (!super::init(properties))
        !            57:        {       IOLog("BPF: super init failed\n");
        !            58:                return false;
        !            59:        }
        !            60:        
        !            61:        // Do class specific initialization here. Probably not necessary for
        !            62:        // this driver.
        !            63: 
        !            64: //     IOLog("BPF: super init succeeded\n");
        !            65:        return true;    // return 'true' for success, 'false' for failure.
        !            66: }
        !            67: 
        !            68: // -----------------------------------------------------------------------
        !            69: //
        !            70: // The driver has been matched, start it up. Do most initialization and
        !            71: // resource allocation here.
        !            72: //
        !            73: bool AppleBPF::start(IOService * provider)
        !            74: {      int i;
        !            75:        OSNumber *val;
        !            76:        extern struct bpf_d     *bpf_dtab;
        !            77:        extern int nbpfilter;
        !            78: 
        !            79:        if (!super::start(provider))
        !            80:        {       IOLog("BPF: super start failed\n");
        !            81:                return false;
        !            82:        }
        !            83: 
        !            84:        val = OSDynamicCast(OSNumber, getObject("IODevCount"));
        !            85:        if (val == 0)
        !            86:                nbpfilter = DEFAULT_BPF_DEV_COUNT;
        !            87:        else
        !            88:                nbpfilter = val->unsigned32BitValue();
        !            89: 
        !            90: //     bpfops.bpf_tap = bpf_tap;
        !            91: //     bpfops.bpf_mtap = bpf_mtap;
        !            92: 
        !            93:        bpf_dtab = (struct bpf_d *)IOMalloc(sizeof (struct bpf_d) * nbpfilter);
        !            94:        if (bpf_dtab == NULL)
        !            95:        {       IOLog("%s: couldn't get memory for descriptor table\n",
        !            96:                      getName());
        !            97:                return false;
        !            98:        }
        !            99: 
        !           100:        /*
        !           101:         * Mark all the descriptors free
        !           102:         */
        !           103:        for (i = 0; i < nbpfilter; ++i)
        !           104:            D_MARKFREE(&bpf_dtab[i]);
        !           105: 
        !           106: //     IOLog("AppleBPF::start() called\n");
        !           107: 
        !           108:        return true;    // return 'true' for success, 'false' for failure.
        !           109: }
        !           110: 
        !           111: // -----------------------------------------------------------------------
        !           112: //
        !           113: // Release all resources before the driver goes away.
        !           114: //
        !           115: void AppleBPF::stop(IOService * provider)
        !           116: {      extern struct bpf_d     *bpf_dtab;
        !           117:        extern int nbpfilter;
        !           118:  
        !           119:        IOFree((void *)bpf_dtab, sizeof (struct bpf_d) * nbpfilter);
        !           120: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.