VirtualBox

Changeset 11069 in vbox for trunk/src/VBox/Devices


Ignore:
Timestamp:
Aug 1, 2008 5:05:17 PM (17 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
33969
Message:

intnet: Fixed a couple of address caching bugs, enh. logging of address cache updates, fixed bad offsets when getting the network destination address from a packet, and added missing SrcMac update when sending frames to a VM.

File:
1 edited

Legend:

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

    r11062 r11069  
    745745 * @param   pCache          The cache.
    746746 * @param   iEntry          The entry to delete.
    747  */
    748 static void intnetR0IfAddrCacheDeleteIt(PINTNETIF pIf, PINTNETADDRCACHE pCache, int iEntry)
    749 {
    750     Log(("intnetR0IfAddrCacheDeleteIt: hIf=%RX32 type=%d #%d %.*Rhxs\n", pIf->hIf,
    751          (int)(intptr_t)(pCache - &pIf->aAddrCache[0]), iEntry, pCache->cbAddress, pCache->pbEntries + iEntry * pCache->cbEntry));
     747 * @param   pszMsg          Log message.
     748 */
     749static void intnetR0IfAddrCacheDeleteIt(PINTNETIF pIf, PINTNETADDRCACHE pCache, int iEntry, const char *pszMsg)
     750{
     751    Log(("intnetR0IfAddrCacheDeleteIt: hIf=%RX32 type=%d #%d %.*Rhxs %s\n", pIf->hIf,
     752         (int)(intptr_t)(pCache - &pIf->aAddrCache[0]), iEntry, pCache->cbAddress,
     753         pCache->pbEntries + iEntry * pCache->cbEntry, pszMsg));
    752754    Assert(iEntry < pCache->cEntries);
    753755    pCache->cEntries--;
     
    771773    int i = intnetR0IfAddrCacheLookup(pCache, pAddr, cbAddr);
    772774    if (RT_UNLIKELY(i >= 0))
    773         intnetR0IfAddrCacheDeleteIt(pIf, pCache, i);
     775        intnetR0IfAddrCacheDeleteIt(pIf, pCache, i, "if");
    774776}
    775777
     
    785787 * @param   enmType         The address type.
    786788 * @param   cbAddr          The address size (optimization).
    787  */
    788 DECLINLINE(void) intnetR0NetworkAddrCacheDelete(PINTNETNETWORK pNetwork, PCRTNETADDRU pAddr,
    789                                                 INTNETADDRTYPE const enmType, uint8_t const cbAddr)
     789 * @param   pszMsg          Log message.
     790 */
     791DECLINLINE(void) intnetR0NetworkAddrCacheDelete(PINTNETNETWORK pNetwork, PCRTNETADDRU pAddr, INTNETADDRTYPE const enmType,
     792                                                uint8_t const cbAddr, const char *pszMsg)
    790793{
    791794    for (PINTNETIF pIf = pNetwork->pIFs; pIf; pIf = pIf->pNext)
     
    793796        int i = intnetR0IfAddrCacheLookup(&pIf->aAddrCache[enmType], pAddr, cbAddr);
    794797        if (RT_UNLIKELY(i >= 0))
    795             intnetR0IfAddrCacheDeleteIt(pIf, &pIf->aAddrCache[enmType], i);
     798            intnetR0IfAddrCacheDeleteIt(pIf, &pIf->aAddrCache[enmType], i, pszMsg);
    796799    }
    797800}
     
    808811 * @param   enmType         The address type.
    809812 * @param   cbAddr          The address size (optimization).
     813 * @param   pszMsg          Log message.
    810814 */
    811815DECLINLINE(void) intnetR0NetworkAddrCacheDeleteMinusIf(PINTNETNETWORK pNetwork, PINTNETIF pIfSender, PCRTNETADDRU pAddr,
    812                                                        INTNETADDRTYPE const enmType, uint8_t const cbAddr)
     816                                                       INTNETADDRTYPE const enmType, uint8_t const cbAddr, const char *pszMsg)
    813817{
    814818    for (PINTNETIF pIf = pNetwork->pIFs; pIf; pIf = pIf->pNext)
     
    817821            int i = intnetR0IfAddrCacheLookup(&pIf->aAddrCache[enmType], pAddr, cbAddr);
    818822            if (RT_UNLIKELY(i >= 0))
    819                 intnetR0IfAddrCacheDeleteIt(pIf, &pIf->aAddrCache[enmType], i);
     823                intnetR0IfAddrCacheDeleteIt(pIf, &pIf->aAddrCache[enmType], i, pszMsg);
    820824        }
    821825}
     
    829833 * @param   pCache      The address cache.
    830834 * @param   pAddr       The address.
    831  */
    832 static void intnetR0IfAddrCacheAddIt(PINTNETIF pIf, PINTNETADDRCACHE pCache, PCRTNETADDRU pAddr)
     835 * @param   pszMsg      log message.
     836 */
     837static void intnetR0IfAddrCacheAddIt(PINTNETIF pIf, PINTNETADDRCACHE pCache, PCRTNETADDRU pAddr, const char *pszMsg)
    833838{
    834839    if (!pCache->cEntriesAlloc)
     
    838843        if (!pCache->pbEntries)
    839844            return;
    840     }
    841     else
     845        pCache->cEntriesAlloc = 16;
     846    }
     847    else if (pCache->cEntries >= pCache->cEntriesAlloc)
    842848    {
    843849        bool fReplace = true;
     
    869875    memcpy(pbEntry, pAddr, pCache->cbAddress);
    870876    memset(pbEntry + pCache->cbAddress, '\0', pCache->cbEntry - pCache->cbAddress);
    871     Log(("intnetR0IfAddrCacheAddIt: type=%d added #%d %.*Rhxs\n",
    872          (int)(uintptr_t)(pCache - &pIf->aAddrCache[0]), pCache->cEntries, pCache->cbAddress, pAddr));
     877    Log(("intnetR0IfAddrCacheAddIt: type=%d added #%d %.*Rhxs %s\n",
     878         (int)(uintptr_t)(pCache - &pIf->aAddrCache[0]), pCache->cEntries,
     879         pCache->cbAddress, pAddr, pszMsg));
    873880    pCache->cEntries++;
    874881    Assert(pCache->cEntries <= pCache->cEntriesAlloc);
     
    883890 * @param   pAddr       The address.
    884891 * @param   cbAddr      The size of the address (optimization).
    885  */
    886 static void intnetR0IfAddrCacheAddSlow(PINTNETIF pIf, PINTNETADDRCACHE pCache, PCRTNETADDRU pAddr, uint8_t const cbAddr)
     892 * @param   pszMsg      Log message.
     893 */
     894static void intnetR0IfAddrCacheAddSlow(PINTNETIF pIf, PINTNETADDRCACHE pCache, PCRTNETADDRU pAddr, uint8_t const cbAddr, const char *pszMsg)
    887895{
    888896    /*
     
    906914     * Not found, add it.
    907915     */
    908     intnetR0IfAddrCacheAddIt(pIf, pCache, pAddr);
     916    intnetR0IfAddrCacheAddIt(pIf, pCache, pAddr, pszMsg);
    909917}
    910918
     
    917925 * @param   pAddr       The address.
    918926 * @param   cbAddr      The size of the address (optimization).
    919  */
    920 DECLINLINE(void) intnetR0IfAddrCacheAdd(PINTNETIF pIf, PINTNETADDRCACHE pCache, PCRTNETADDRU pAddr, uint8_t const cbAddr)
     927 * @param   pszMsg      Log message.
     928 */
     929DECLINLINE(void) intnetR0IfAddrCacheAdd(PINTNETIF pIf, PINTNETADDRCACHE pCache, PCRTNETADDRU pAddr, uint8_t const cbAddr, const char *pszMsg)
    921930{
    922931    Assert(pCache->cbAddress == cbAddr);
     
    947956        return;
    948957
    949     intnetR0IfAddrCacheAddSlow(pIf, pCache, pAddr, cbAddr);
     958    intnetR0IfAddrCacheAddSlow(pIf, pCache, pAddr, cbAddr, pszMsg);
    950959}
    951960
     
    10381047
    10391048        Addr.IPv4 = pReq->ar_spa;
    1040         intnetR0NetworkAddrCacheDelete(pNetwork, &Addr, kIntNetAddrType_IPv4, sizeof(pReq->ar_spa));
     1049        intnetR0NetworkAddrCacheDelete(pNetwork, &Addr, kIntNetAddrType_IPv4, sizeof(pReq->ar_spa), "tif/arp");
    10411050    }
    10421051#if 0 /** @todo IPv6 support */
     
    10531062
    10541063        Addr.IPv6 = pReq->ar_spa;
    1055         intnetR0NetworkAddrCacheDelete(pNetwork, &Addr, kIntNetAddrType_IPv6, sizeof(pReq->ar_spa));
     1064        intnetR0NetworkAddrCacheDelete(pNetwork, &Addr, kIntNetAddrType_IPv6, sizeof(pReq->ar_spa), "tif/arp");
    10561065    }
    10571066#endif
     
    11561165            return;
    11571166        }
    1158         intnetR0IfAddrCacheAddIt(pIf, &pIf->aAddrCache[kIntNetAddrType_IPv4], &Addr);
     1167        intnetR0IfAddrCacheAddIt(pIf, &pIf->aAddrCache[kIntNetAddrType_IPv4], &Addr, "if/ipv4");
    11591168        fValidatedIpHdr = true;
    11601169    }
     
    12311240        }
    12321241        Addr.IPv4 = pReq->ar_spa;
    1233         intnetR0IfAddrCacheAdd(pIf, &pIf->aAddrCache[kIntNetAddrType_IPv4], &Addr, sizeof(pReq->ar_spa));
     1242        intnetR0IfAddrCacheAdd(pIf, &pIf->aAddrCache[kIntNetAddrType_IPv4], &Addr, sizeof(pReq->ar_spa), "if/arp");
    12341243    }
    12351244#if 0 /** @todo IPv6 support */
     
    12521261        }
    12531262        Addr.IPv6 = pReq->ar_spa;
    1254         intnetR0IfAddrCacheAdd(pIf, &pIf->aAddrCache[kIntNetAddrType_IPv6], &Addr, sizeof(pReq->ar_spa));
     1263        intnetR0IfAddrCacheAdd(pIf, &pIf->aAddrCache[kIntNetAddrType_IPv6], &Addr, sizeof(pReq->ar_spa), "if/arp");
    12551264    }
    12561265#endif
     
    13411350 *
    13421351 * @returns VBox status code.
    1343  * @param   pBuf        The buffer.
    1344  * @param   pRingBuf    The ring buffer to read from.
    1345  * @param   pSG         The gatter list.
    1346  */
    1347 static int intnetR0RingWriteFrame(PINTNETBUF pBuf, PINTNETRINGBUF pRingBuf, PCINTNETSG pSG)
     1352 * @param   pBuf            The buffer.
     1353 * @param   pRingBuf        The ring buffer to read from.
     1354 * @param   pSG             The gather list.
     1355 * @param   pNewDstMac      Set the destination MAC address to the address if specified.
     1356 */
     1357static int intnetR0RingWriteFrame(PINTNETBUF pBuf, PINTNETRINGBUF pRingBuf, PCINTNETSG pSG, PCRTMAC pNewDstMac)
    13481358{
    13491359    /*
     
    13731383
    13741384            intnetR0SgRead(pSG, pHdr + 1);
     1385            if (pNewDstMac)
     1386                ((PRTNETETHERHDR)(pHdr + 1))->DstMac = *pNewDstMac;
    13751387
    13761388            offWrite += cb + sizeof(INTNETHDR);
     
    13971409
    13981410            intnetR0SgRead(pSG, pvFrameOut);
     1411            if (pNewDstMac)
     1412                ((PRTNETETHERHDR)pvFrameOut)->DstMac = *pNewDstMac;
    13991413
    14001414            offWrite = pRingBuf->offStart + cb;
     
    14151429
    14161430        intnetR0SgRead(pSG, pHdr + 1);
     1431        if (pNewDstMac)
     1432            ((PRTNETETHERHDR)(pHdr + 1))->DstMac = *pNewDstMac;
    14171433
    14181434        offWrite += cb + sizeof(INTNETHDR);
     
    14341450 * @param   pIfSender       The interface sending the frame. This is NULL if it's the trunk.
    14351451 * @param   pSG             The gather buffer which data is being sent to the interface.
    1436  */
    1437 static void intnetR0IfSend(PINTNETIF pIf, PINTNETIF pIfSender, PINTNETSG pSG)
     1452 * @param   pNewDstMac      Set the destination MAC address to the address if specified.
     1453 */
     1454static void intnetR0IfSend(PINTNETIF pIf, PINTNETIF pIfSender, PINTNETSG pSG, PCRTMAC pNewDstMac)
    14381455{
    14391456//    LogFlow(("intnetR0IfSend: pIf=%p:{.hIf=%RX32}\n", pIf, pIf->hIf));
    1440     int rc = intnetR0RingWriteFrame(pIf->pIntBuf, &pIf->pIntBuf->Recv, pSG);
     1457    int rc = intnetR0RingWriteFrame(pIf->pIntBuf, &pIf->pIntBuf->Recv, pSG, pNewDstMac);
    14411458    if (RT_SUCCESS(rc))
    14421459    {
     
    14761493            RTSemEventSignal(pIf->Event);
    14771494            RTThreadYield();
    1478             rc = intnetR0RingWriteFrame(pIf->pIntBuf, &pIf->pIntBuf->Recv, pSG);
     1495            rc = intnetR0RingWriteFrame(pIf->pIntBuf, &pIf->pIntBuf->Recv, pSG, pNewDstMac);
    14791496            if (RT_SUCCESS(rc))
    14801497            {
     
    16051622    for (PINTNETIF pIf = pNetwork->pIFs; pIf; pIf = pIf->pNext)
    16061623        if (pIf != pIfSender)
    1607             intnetR0IfSend(pIf, pIfSender, pSG);
     1624            intnetR0IfSend(pIf, pIfSender, pSG, NULL);
    16081625
    16091626    /*
     
    16761693    {
    16771694        case RTNET_ETHERTYPE_IPV4:
    1678             if (!intnetR0SgReadPart(pSG, RT_OFFSETOF(RTNETIPV4, ip_dst), sizeof(Addr.IPv4), &Addr))
     1695            if (RT_UNLIKELY(!intnetR0SgReadPart(pSG, sizeof(RTNETETHERHDR) + RT_OFFSETOF(RTNETIPV4, ip_dst), sizeof(Addr.IPv4), &Addr)))
     1696            {
     1697                Log(("intnetshareduni: failed to read ip_dst! cbTotal=%#x\n", pSG->cbTotal));
    16791698                return false;
     1699            }
    16801700            enmAddrType = kIntNetAddrType_IPv4;
    16811701            cbAddr = sizeof(Addr.IPv4);
     1702            Log6(("intnetshareduni: IPv4 %d.%d.%d.%d\n", Addr.au8[0], Addr.au8[1], Addr.au8[2], Addr.au8[3]));
    16821703            break;
    16831704
    16841705#if 0 /** @todo IntNet: implement IPv6 for wireless MAC sharing. */
    16851706        case RTNET_ETHERTYPE_IPV6
    1686             if (!intnetR0SgReadPart(pSG, RT_OFFSETOF(RTNETIPV6, ip6_dst), sizeof(Addr.IPv6), &Addr))
     1707            if (RT_UNLIKELY(!intnetR0SgReadPart(pSG, sizeof(RTNETETHERHDR) + RT_OFFSETOF(RTNETIPV6, ip6_dst), sizeof(Addr.IPv6), &Addr)))
     1708            {
     1709                Log(("intnetshareduni: failed to read ip6_dst! cbTotal=%#x\n", pSG->cbTotal));
    16871710                return false;
     1711            }
    16881712            enmAddrType = kIntNetAddrType_IPv6;
    16891713            cbAddr = sizeof(Addr.IPv6);
     
    16941718        case RTNET_ETHERTYPE_IPX_2:
    16951719        case RTNET_ETHERTYPE_IPX_3:
    1696             if (!intnetR0SgReadPart(pSG, RT_OFFSETOF(RTNETIPX, ipx_dstnet), sizeof(Addr.IPX), &Addr))
     1720            if (RT_UNLIKELY(!intnetR0SgReadPart(pSG, sizeof(RTNETETHERHDR) + RT_OFFSETOF(RTNETIPX, ipx_dstnet), sizeof(Addr.IPX), &Addr)))
     1721            {
     1722                Log(("intnetshareduni: failed to read ipx_dstnet! cbTotal=%#x\n", pSG->cbTotal));
    16971723                return false;
     1724            }
    16981725            enmAddrType = kIntNetAddrType_IPX;
    16991726            cbAddr = sizeof(Addr.IPX);
     
    17061733         */
    17071734        case RTNET_ETHERTYPE_ARP:
     1735            Log6(("intnetshareduni: ARP\n"));
    17081736            return intnetR0NetworkSendBroadcast(pNetwork, NULL, pSG, fTrunkLocked, pEthHdr);
    17091737
     
    17131741        default:
    17141742        {
     1743            Log6(("intnetshareduni: unknown ethertype=%#x\n", RT_BE2H_U16(pEthHdr->EtherType)));
    17151744            if (!(pNetwork->fFlags & (INTNET_OPEN_FLAGS_IGNORE_PROMISC | INTNET_OPEN_FLAGS_QUIETLY_IGNORE_PROMISC)))
    17161745            {
     
    17191748                    {
    17201749                        Log2(("Dst=%.6Rhxs => %.6Rhxs\n", &pEthHdr->DstMac, &pIf->Mac));
    1721                         intnetR0IfSend(pIf, NULL, pSG);
     1750                        intnetR0IfSend(pIf, NULL, pSG, NULL);
    17221751                    }
    17231752            }
     
    17391768            Log2(("Dst=%.6Rhxs => %.6Rhxs\n", &pEthHdr->DstMac, &pIf->Mac));
    17401769            fExactIntNetRecipient |= fIt;
    1741             intnetR0IfSend(pIf, NULL, pSG);
     1770            intnetR0IfSend(pIf, NULL, pSG, fIt ? &pIf->Mac : NULL);
    17421771        }
    17431772    }
     
    17841813            Log2(("Dst=%.6Rhxs => %.6Rhxs\n", &pEthHdr->DstMac, &pIf->Mac));
    17851814            fExactIntNetRecipient |= fIt;
    1786             intnetR0IfSend(pIf, pIfSender, pSG);
     1815            intnetR0IfSend(pIf, pIfSender, pSG, NULL);
    17871816        }
    17881817    }
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