VirtualBox

Changeset 30557 in vbox for trunk/src


Ignore:
Timestamp:
Jul 1, 2010 2:15:01 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
63270
Message:

SrvIntNetR0.cpp: Implemented pfnPreRecv.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Network/SrvIntNetR0.cpp

    r30320 r30557  
    14631463
    14641464/**
     1465 * Pre-switch a unicast MAC address.
     1466 *
     1467 * @returns INTNETSWDECISION_DROP, INTNETSWDECISION_TRUNK,
     1468 *          INTNETSWDECISION_INTNET or INTNETSWDECISION_BROADCAST (misnomer).
     1469 * @param   pNetwork            The network to switch on.
     1470 * @param   fSrc                The frame source.
     1471 * @param   pSrcAddr            The source address of the frame.
     1472 * @param   pDstAddr            The destination address of the frame.
     1473 */
     1474static INTNETSWDECISION intnetR0NetworkPreSwitchUnicast(PINTNETNETWORK pNetwork, uint32_t fSrc, PCRTMAC pSrcAddr,
     1475                                                        PCRTMAC pDstAddr)
     1476{
     1477    Assert(!intnetR0IsMacAddrMulticast(pDstAddr));
     1478
     1479    /*
     1480     * Grab the spinlock first and do the switching.
     1481     */
     1482    INTNETSWDECISION    enmSwDecision   = INTNETSWDECISION_BROADCAST;
     1483    PINTNETMACTAB       pTab            = &pNetwork->MacTab;
     1484    RTSPINLOCKTMP       Tmp             = RTSPINLOCKTMP_INITIALIZER;
     1485    RTSpinlockAcquireNoInts(pNetwork->hAddrSpinlock, &Tmp);
     1486
     1487    /* Iterate the internal network interfaces and look for matching source and
     1488       destination addresses. */
     1489    uint32_t cExactHits = 0;
     1490    uint32_t iIfMac     = pTab->cEntries;
     1491    while (iIfMac-- > 0)
     1492    {
     1493        if (pTab->paEntries[iIfMac].fActive)
     1494        {
     1495            /* Unknown interface address? */
     1496            if (intnetR0IsMacAddrDummy(&pTab->paEntries[iIfMac].MacAddr))
     1497                break;
     1498
     1499            /* Paranoia - this shouldn't happen, right? */
     1500            if (    pSrcAddr
     1501                &&  intnetR0AreMacAddrsEqual(&pTab->paEntries[iIfMac].MacAddr, pSrcAddr))
     1502                break;
     1503
     1504            /* Exact match? */
     1505            if (intnetR0AreMacAddrsEqual(&pTab->paEntries[iIfMac].MacAddr, pDstAddr))
     1506            {
     1507                enmSwDecision = pTab->fHostPromiscuous && fSrc == INTNETTRUNKDIR_WIRE
     1508                              ? INTNETSWDECISION_BROADCAST
     1509                              : INTNETSWDECISION_INTNET;
     1510                break;
     1511            }
     1512        }
     1513    }
     1514
     1515    RTSpinlockReleaseNoInts(pNetwork->hAddrSpinlock, &Tmp);
     1516    return enmSwDecision;
     1517}
     1518
     1519
     1520/**
    14651521 * Switch a unicast MAC address and return a destination table.
    14661522 *
     
    14831539     * Grab the spinlock first and do the switching.
    14841540     */
    1485     PINTNETMACTAB   pTab    = &pNetwork->MacTab;
    1486     RTSPINLOCKTMP   Tmp     = RTSPINLOCKTMP_INITIALIZER;
     1541    PINTNETMACTAB   pTab = &pNetwork->MacTab;
     1542    RTSPINLOCKTMP   Tmp = RTSPINLOCKTMP_INITIALIZER;
    14871543    RTSpinlockAcquireNoInts(pNetwork->hAddrSpinlock, &Tmp);
    14881544
     
    44604516{
    44614517    PINTNETTRUNKIF pThis = INTNET_SWITCHPORT_2_TRUNKIF(pSwitchPort);
     4518
     4519    /* assert some sanity */
     4520    AssertPtr(pvSrc);
     4521    AssertReturn(cbSrc >= 6, INTNETSWDECISION_BROADCAST);
     4522    Assert(fSrc);
     4523
     4524    /*
     4525     * Mark the trunk as busy, make sure we've got a network and that there are
     4526     * some active interfaces around.
     4527     */
     4528    INTNETSWDECISION enmSwDecision = INTNETSWDECISION_TRUNK;
     4529    intnetR0BusyIncTrunk(pThis);
    44624530    PINTNETNETWORK pNetwork = pThis->pNetwork;
    4463 
    4464     /* assert some sanity */
    4465     AssertPtrReturn(pNetwork, INTNETSWDECISION_TRUNK);
    4466     AssertReturn(pNetwork->hEvtBusyIf != NIL_RTSEMEVENT, INTNETSWDECISION_TRUNK);
    4467     AssertPtr(pvSrc);
    4468     Assert(cbSrc >= 6);
    4469     Assert(fSrc);
    4470 
    4471     /** @todo implement the switch table. */
    4472 
    4473     return INTNETSWDECISION_BROADCAST;
     4531    if (RT_LIKELY(   pNetwork
     4532                  && pNetwork->cActiveIFs > 0 ))
     4533    {
     4534        /*
     4535         * Lazy bird! No pre-switching of multicast and shared-MAC-on-wire.
     4536         */
     4537        PCRTNETETHERHDR pEthHdr = (PCRTNETETHERHDR)pvSrc;
     4538        if (intnetR0IsMacAddrMulticast(&pEthHdr->DstMac))
     4539            enmSwDecision = INTNETSWDECISION_BROADCAST;
     4540        else if (pNetwork->fFlags & INTNET_OPEN_FLAGS_SHARED_MAC_ON_WIRE)
     4541            enmSwDecision = INTNETSWDECISION_BROADCAST;
     4542        else
     4543            enmSwDecision = intnetR0NetworkPreSwitchUnicast(pNetwork,
     4544                                                            fSrc,
     4545                                                            cbSrc >= 12 ? &pEthHdr->SrcMac : NULL,
     4546                                                            &pEthHdr->DstMac);
     4547    }
     4548
     4549    intnetR0BusyDecTrunk(pThis);
     4550    return enmSwDecision;
    44744551}
    44754552
Note: See TracChangeset for help on using the changeset viewer.

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