VirtualBox

Changeset 28208 in vbox


Ignore:
Timestamp:
Apr 12, 2010 2:07:33 PM (15 years ago)
Author:
vboxsync
Message:

intnet,VBoxNetFlt-linux: Added INTNETTRUNKSWPORT::pfnPreRecv for doing filtering and switching in difficult contexts. It currently returns broadcast all the time, but that will be addressed before long.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/intnet.h

    r28120 r28208  
    353353/** @} */
    354354
     355/**
     356 * Switch decisions returned by INTNETTRUNKSWPORT::pfnPreRecv.
     357 */
     358typedef enum INTNETSWDECISION
     359{
     360    /** The usual invalid zero value. */
     361    INTNETSWDECISION_INVALID = 0,
     362    /** Everywhere. */
     363    INTNETSWDECISION_BROADCAST,
     364    /** Only to the internal network. */
     365    INTNETSWDECISION_INTNET,
     366    /** Only for the trunk (host/wire). */
     367    INTNETSWDECISION_TRUNK,
     368    /** The usual 32-bit type expansion. */
     369    INTNETSWDECISION_32BIT_HACK = 0x7fffffff
     370} INTNETSWDECISION;
     371
    355372
    356373/** Pointer to the switch side of a trunk port. */
     
    366383    /** Structure version number. (INTNETTRUNKSWPORT_VERSION) */
    367384    uint32_t u32Version;
     385
     386    /**
     387     * Examine the packet and figure out where it is going.
     388     *
     389     * This method is for making packet switching decisions in contexts where
     390     * pfnRecv cannot be called or is no longer applicable.  This method can be
     391     * called from any context.
     392     *
     393     * @returns INTNETSWDECISION_BROADCAST, INTNETSWDECISION_INTNET or
     394     *          INTNETSWDECISION_TRUNK.  The source is excluded from broadcast &
     395     *          trunk, of course.
     396     *
     397     * @param   pSwitchPort Pointer to this structure.
     398     * @param   pvHdrs      Pointer to the packet headers.
     399     * @param   cbHdrs      Size of the packet headers.  This must be at least 6
     400     *                      bytes (the destination MAC address), but should if
     401     *                      possibly also include any VLAN tag and network layer
     402     *                      header (wireless mac address sharing).
     403     * @param   fSrc        Where this frame comes from.  Only one bit should be
     404     *                      set!
     405     *
     406     * @remarks Will only grab the switch table spinlock (interrupt safe).
     407     */
     408    DECLR0CALLBACKMEMBER(INTNETSWDECISION, pfnPreRecv,(PINTNETTRUNKSWPORT pSwitchPort,
     409                                                       void const *pvHdrs, size_t cbHdrs, uint32_t fSrc));
    368410
    369411    /**
     
    376418     *
    377419     * @returns true if we've handled it and it should be dropped.
    378      *          false if it should hit the wire.
     420     *          false if it should hit the wire/host.
    379421     *
    380422     * @param   pSwitchPort Pointer to this structure.
     
    679721
    680722/** The UUID for the (current) trunk factory. (case sensitive) */
    681 #define INTNETTRUNKFACTORY_UUID_STR     "1d3810bc-0899-42b0-8ae1-346a08bffff7"
     723#define INTNETTRUNKFACTORY_UUID_STR     "b010afb2-cb4c-44b7-9da9-1e113cfcd47c"
    682724
    683725/** @name INTNETTRUNKFACTORY::pfnCreateAndConnect flags.
  • trunk/src/VBox/Devices/Network/DrvIntNet.cpp

    r28134 r28208  
    135135#ifdef IN_RING3
    136136
    137 /* -=-=-=-=- PDMINETWORKUP -=-=-=-=- */
    138 
    139137
    140138/**
     
    192190}
    193191
     192/* -=-=-=-=- PDMINETWORKUP -=-=-=-=- */
    194193
    195194/**
  • trunk/src/VBox/Devices/Network/SrvIntNetR0.cpp

    r28156 r28208  
    33293329
    33303330
     3331/** @copydoc INTNETTRUNKSWPORT::pfnPreRecv */
     3332static DECLCALLBACK(INTNETSWDECISION) intnetR0TrunkIfPortPreRecv(PINTNETTRUNKSWPORT pSwitchPort,
     3333                                                                 void const *pvSrc, size_t cbSrc, uint32_t fSrc)
     3334{
     3335    PINTNETTRUNKIF pThis = INTNET_SWITCHPORT_2_TRUNKIF(pSwitchPort);
     3336    PINTNETNETWORK pNetwork = pThis->pNetwork;
     3337
     3338    /* assert some sanity */
     3339    AssertPtrReturn(pNetwork, INTNETSWDECISION_TRUNK);
     3340    AssertReturn(pNetwork->FastMutex != NIL_RTSEMFASTMUTEX, INTNETSWDECISION_TRUNK);
     3341    AssertPtr(pvSrc);
     3342    AssertPtr(cbSrc >= 6);
     3343    Assert(fSrc);
     3344
     3345    /** @todo implement the switch table. */
     3346
     3347    return INTNETSWDECISION_BROADCAST;
     3348}
     3349
     3350
    33313351/** @copydoc INTNETTRUNKSWPORT::pfnRecv */
    33323352static DECLCALLBACK(bool) intnetR0TrunkIfPortRecv(PINTNETTRUNKSWPORT pSwitchPort, PINTNETSG pSG, uint32_t fSrc)
     
    36123632        return VERR_NO_MEMORY;
    36133633    pTrunkIF->SwitchPort.u32Version                 = INTNETTRUNKSWPORT_VERSION;
     3634    pTrunkIF->SwitchPort.pfnPreRecv                 = intnetR0TrunkIfPortPreRecv;
    36143635    pTrunkIF->SwitchPort.pfnRecv                    = intnetR0TrunkIfPortRecv;
    36153636    pTrunkIF->SwitchPort.pfnSGRetain                = intnetR0TrunkIfPortSGRetain;
  • trunk/src/VBox/HostDrivers/VBoxNetFlt/linux/VBoxNetFlt-linux.c

    r28202 r28208  
    250250    /** Our overridden ops. */
    251251    struct net_device_ops           Ops;
     252    /** Magic word. */
     253    uint32_t                        u32Magic;
    252254    /** Pointer to the original ops. */
    253255    struct net_device_ops const    *pOrgOps;
    254     /** Magic word. */
    255     uint32_t                        u32Magic;
     256    /** Pointer to the net filter instance. */
     257    PVBOXNETFLTINS                  pVBoxNetFlt;
    256258    /** The number of filtered packages. */
    257259    uint64_t                        cFiltered;
     
    273275{
    274276    PVBOXNETDEVICEOPSOVERRIDE   pOverride = (PVBOXNETDEVICEOPSOVERRIDE)pDev->netdev_ops;
    275     RTNETETHERHDR               EtherHdrBuf;
     277    uint8_t                     abHdrBuf[sizeof(RTNETETHERHDR) + sizeof(uint32_t) + RTNETIPV4_MIN_LEN];
    276278    PCRTNETETHERHDR             pEtherHdr;
     279    PINTNETTRUNKSWPORT          pSwitchPort;
     280
    277281
    278282    /*
     
    300304     *       drop it.
    301305     */
    302     pEtherHdr = (PCRTNETETHERHDR)skb_header_pointer(pSkb, 0, sizeof(EtherHdrBuf), &EtherHdrBuf);
    303     if (    pEtherHdr
    304         &&  pEtherHdr->DstMac.au8[0] == 0x08
    305         &&  pEtherHdr->DstMac.au8[1] == 0x00
    306         &&  pEtherHdr->DstMac.au8[2] == 0x27
     306    pEtherHdr = (PCRTNETETHERHDR)skb_header_pointer(pSkb, 0, sizeof(abHdrBuf), &abHdrBuf[0]);
     307    if (   pEtherHdr
     308        && VALID_PTR(pOverride->pVBoxNetFlt)
     309        && (pSwitchPort = pOverride->pVBoxNetFlt->pSwitchPort) != NULL
     310        && VALID_PTR(pSwitchPort)
    307311       )
    308312    {
    309         dev_kfree_skb(pSkb);
    310         pOverride->cFiltered++;
    311         return NETDEV_TX_OK;
     313        INTNETSWDECISION    enmDecision;
     314        uint32_t            cbHdrs = skb_headlen(pSkb);
     315        cbHdrs = RT_MAX(cbHdrs, sizeof(abHdrBuf));
     316
     317        /** @todo consider reference counting, etc. */
     318        enmDecision = pSwitchPort->pfnPreRecv(pSwitchPort, pEtherHdr, cbHdrs, INTNETTRUNKDIR_HOST);
     319        if (enmDecision == INTNETSWDECISION_INTNET)
     320        {
     321            dev_kfree_skb(pSkb);
     322            pOverride->cFiltered++;
     323            return NETDEV_TX_OK;
     324        }
    312325    }
    313326
     
    333346    pOverride->Ops.ndo_start_xmit   = vboxNetFltLinuxStartXmitFilter;
    334347    pOverride->u32Magic             = VBOXNETDEVICEOPSOVERRIDE_MAGIC;
     348    pOverride->cTotal               = 0;
     349    pOverride->cFiltered            = 0;
     350    pOverride->pVBoxNetFlt          = pThis;
    335351
    336352    RTSpinlockAcquire(pThis->hSpinlock, &Tmp); /* (this isn't necessary, but so what) */
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette