Changeset 11069 in vbox for trunk/src/VBox/Devices
- Timestamp:
- Aug 1, 2008 5:05:17 PM (17 years ago)
- svn:sync-xref-src-repo-rev:
- 33969
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Network/SrvIntNetR0.cpp
r11062 r11069 745 745 * @param pCache The cache. 746 746 * @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 */ 749 static 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)); 752 754 Assert(iEntry < pCache->cEntries); 753 755 pCache->cEntries--; … … 771 773 int i = intnetR0IfAddrCacheLookup(pCache, pAddr, cbAddr); 772 774 if (RT_UNLIKELY(i >= 0)) 773 intnetR0IfAddrCacheDeleteIt(pIf, pCache, i );775 intnetR0IfAddrCacheDeleteIt(pIf, pCache, i, "if"); 774 776 } 775 777 … … 785 787 * @param enmType The address type. 786 788 * @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 */ 791 DECLINLINE(void) intnetR0NetworkAddrCacheDelete(PINTNETNETWORK pNetwork, PCRTNETADDRU pAddr, INTNETADDRTYPE const enmType, 792 uint8_t const cbAddr, const char *pszMsg) 790 793 { 791 794 for (PINTNETIF pIf = pNetwork->pIFs; pIf; pIf = pIf->pNext) … … 793 796 int i = intnetR0IfAddrCacheLookup(&pIf->aAddrCache[enmType], pAddr, cbAddr); 794 797 if (RT_UNLIKELY(i >= 0)) 795 intnetR0IfAddrCacheDeleteIt(pIf, &pIf->aAddrCache[enmType], i );798 intnetR0IfAddrCacheDeleteIt(pIf, &pIf->aAddrCache[enmType], i, pszMsg); 796 799 } 797 800 } … … 808 811 * @param enmType The address type. 809 812 * @param cbAddr The address size (optimization). 813 * @param pszMsg Log message. 810 814 */ 811 815 DECLINLINE(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) 813 817 { 814 818 for (PINTNETIF pIf = pNetwork->pIFs; pIf; pIf = pIf->pNext) … … 817 821 int i = intnetR0IfAddrCacheLookup(&pIf->aAddrCache[enmType], pAddr, cbAddr); 818 822 if (RT_UNLIKELY(i >= 0)) 819 intnetR0IfAddrCacheDeleteIt(pIf, &pIf->aAddrCache[enmType], i );823 intnetR0IfAddrCacheDeleteIt(pIf, &pIf->aAddrCache[enmType], i, pszMsg); 820 824 } 821 825 } … … 829 833 * @param pCache The address cache. 830 834 * @param pAddr The address. 831 */ 832 static void intnetR0IfAddrCacheAddIt(PINTNETIF pIf, PINTNETADDRCACHE pCache, PCRTNETADDRU pAddr) 835 * @param pszMsg log message. 836 */ 837 static void intnetR0IfAddrCacheAddIt(PINTNETIF pIf, PINTNETADDRCACHE pCache, PCRTNETADDRU pAddr, const char *pszMsg) 833 838 { 834 839 if (!pCache->cEntriesAlloc) … … 838 843 if (!pCache->pbEntries) 839 844 return; 840 } 841 else 845 pCache->cEntriesAlloc = 16; 846 } 847 else if (pCache->cEntries >= pCache->cEntriesAlloc) 842 848 { 843 849 bool fReplace = true; … … 869 875 memcpy(pbEntry, pAddr, pCache->cbAddress); 870 876 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)); 873 880 pCache->cEntries++; 874 881 Assert(pCache->cEntries <= pCache->cEntriesAlloc); … … 883 890 * @param pAddr The address. 884 891 * @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 */ 894 static void intnetR0IfAddrCacheAddSlow(PINTNETIF pIf, PINTNETADDRCACHE pCache, PCRTNETADDRU pAddr, uint8_t const cbAddr, const char *pszMsg) 887 895 { 888 896 /* … … 906 914 * Not found, add it. 907 915 */ 908 intnetR0IfAddrCacheAddIt(pIf, pCache, pAddr );916 intnetR0IfAddrCacheAddIt(pIf, pCache, pAddr, pszMsg); 909 917 } 910 918 … … 917 925 * @param pAddr The address. 918 926 * @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 */ 929 DECLINLINE(void) intnetR0IfAddrCacheAdd(PINTNETIF pIf, PINTNETADDRCACHE pCache, PCRTNETADDRU pAddr, uint8_t const cbAddr, const char *pszMsg) 921 930 { 922 931 Assert(pCache->cbAddress == cbAddr); … … 947 956 return; 948 957 949 intnetR0IfAddrCacheAddSlow(pIf, pCache, pAddr, cbAddr );958 intnetR0IfAddrCacheAddSlow(pIf, pCache, pAddr, cbAddr, pszMsg); 950 959 } 951 960 … … 1038 1047 1039 1048 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"); 1041 1050 } 1042 1051 #if 0 /** @todo IPv6 support */ … … 1053 1062 1054 1063 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"); 1056 1065 } 1057 1066 #endif … … 1156 1165 return; 1157 1166 } 1158 intnetR0IfAddrCacheAddIt(pIf, &pIf->aAddrCache[kIntNetAddrType_IPv4], &Addr );1167 intnetR0IfAddrCacheAddIt(pIf, &pIf->aAddrCache[kIntNetAddrType_IPv4], &Addr, "if/ipv4"); 1159 1168 fValidatedIpHdr = true; 1160 1169 } … … 1231 1240 } 1232 1241 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"); 1234 1243 } 1235 1244 #if 0 /** @todo IPv6 support */ … … 1252 1261 } 1253 1262 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"); 1255 1264 } 1256 1265 #endif … … 1341 1350 * 1342 1351 * @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 */ 1357 static int intnetR0RingWriteFrame(PINTNETBUF pBuf, PINTNETRINGBUF pRingBuf, PCINTNETSG pSG, PCRTMAC pNewDstMac) 1348 1358 { 1349 1359 /* … … 1373 1383 1374 1384 intnetR0SgRead(pSG, pHdr + 1); 1385 if (pNewDstMac) 1386 ((PRTNETETHERHDR)(pHdr + 1))->DstMac = *pNewDstMac; 1375 1387 1376 1388 offWrite += cb + sizeof(INTNETHDR); … … 1397 1409 1398 1410 intnetR0SgRead(pSG, pvFrameOut); 1411 if (pNewDstMac) 1412 ((PRTNETETHERHDR)pvFrameOut)->DstMac = *pNewDstMac; 1399 1413 1400 1414 offWrite = pRingBuf->offStart + cb; … … 1415 1429 1416 1430 intnetR0SgRead(pSG, pHdr + 1); 1431 if (pNewDstMac) 1432 ((PRTNETETHERHDR)(pHdr + 1))->DstMac = *pNewDstMac; 1417 1433 1418 1434 offWrite += cb + sizeof(INTNETHDR); … … 1434 1450 * @param pIfSender The interface sending the frame. This is NULL if it's the trunk. 1435 1451 * @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 */ 1454 static void intnetR0IfSend(PINTNETIF pIf, PINTNETIF pIfSender, PINTNETSG pSG, PCRTMAC pNewDstMac) 1438 1455 { 1439 1456 // 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); 1441 1458 if (RT_SUCCESS(rc)) 1442 1459 { … … 1476 1493 RTSemEventSignal(pIf->Event); 1477 1494 RTThreadYield(); 1478 rc = intnetR0RingWriteFrame(pIf->pIntBuf, &pIf->pIntBuf->Recv, pSG );1495 rc = intnetR0RingWriteFrame(pIf->pIntBuf, &pIf->pIntBuf->Recv, pSG, pNewDstMac); 1479 1496 if (RT_SUCCESS(rc)) 1480 1497 { … … 1605 1622 for (PINTNETIF pIf = pNetwork->pIFs; pIf; pIf = pIf->pNext) 1606 1623 if (pIf != pIfSender) 1607 intnetR0IfSend(pIf, pIfSender, pSG );1624 intnetR0IfSend(pIf, pIfSender, pSG, NULL); 1608 1625 1609 1626 /* … … 1676 1693 { 1677 1694 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)); 1679 1698 return false; 1699 } 1680 1700 enmAddrType = kIntNetAddrType_IPv4; 1681 1701 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])); 1682 1703 break; 1683 1704 1684 1705 #if 0 /** @todo IntNet: implement IPv6 for wireless MAC sharing. */ 1685 1706 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)); 1687 1710 return false; 1711 } 1688 1712 enmAddrType = kIntNetAddrType_IPv6; 1689 1713 cbAddr = sizeof(Addr.IPv6); … … 1694 1718 case RTNET_ETHERTYPE_IPX_2: 1695 1719 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)); 1697 1723 return false; 1724 } 1698 1725 enmAddrType = kIntNetAddrType_IPX; 1699 1726 cbAddr = sizeof(Addr.IPX); … … 1706 1733 */ 1707 1734 case RTNET_ETHERTYPE_ARP: 1735 Log6(("intnetshareduni: ARP\n")); 1708 1736 return intnetR0NetworkSendBroadcast(pNetwork, NULL, pSG, fTrunkLocked, pEthHdr); 1709 1737 … … 1713 1741 default: 1714 1742 { 1743 Log6(("intnetshareduni: unknown ethertype=%#x\n", RT_BE2H_U16(pEthHdr->EtherType))); 1715 1744 if (!(pNetwork->fFlags & (INTNET_OPEN_FLAGS_IGNORE_PROMISC | INTNET_OPEN_FLAGS_QUIETLY_IGNORE_PROMISC))) 1716 1745 { … … 1719 1748 { 1720 1749 Log2(("Dst=%.6Rhxs => %.6Rhxs\n", &pEthHdr->DstMac, &pIf->Mac)); 1721 intnetR0IfSend(pIf, NULL, pSG );1750 intnetR0IfSend(pIf, NULL, pSG, NULL); 1722 1751 } 1723 1752 } … … 1739 1768 Log2(("Dst=%.6Rhxs => %.6Rhxs\n", &pEthHdr->DstMac, &pIf->Mac)); 1740 1769 fExactIntNetRecipient |= fIt; 1741 intnetR0IfSend(pIf, NULL, pSG );1770 intnetR0IfSend(pIf, NULL, pSG, fIt ? &pIf->Mac : NULL); 1742 1771 } 1743 1772 } … … 1784 1813 Log2(("Dst=%.6Rhxs => %.6Rhxs\n", &pEthHdr->DstMac, &pIf->Mac)); 1785 1814 fExactIntNetRecipient |= fIt; 1786 intnetR0IfSend(pIf, pIfSender, pSG );1815 intnetR0IfSend(pIf, pIfSender, pSG, NULL); 1787 1816 } 1788 1817 }
Note:
See TracChangeset
for help on using the changeset viewer.