VirtualBox

Changeset 108371 in vbox


Ignore:
Timestamp:
Feb 25, 2025 1:57:42 PM (8 weeks ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
167732
Message:

UsbNet: Minor logging enhancements, including packet dumping/numbering bugref:10779

File:
1 edited

Legend:

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

    r107875 r108371  
    422422    STAMCOUNTER                         StatTransmitBytes;
    423423
     424    uint32_t                            u32PktNo;
    424425    /**
    425426     * LUN\#0 data.
     
    11331134static int usbNetCompleteOk(PUSBNET pThis, PVUSBURB pUrb, size_t cbData)
    11341135{
    1135     LogFunc(("/#%u/ pUrb=%p:%s cbData=%#zx\n", pThis->pUsbIns->iInstance, pUrb, pUrb->pszDesc, cbData));
     1136    LogFlowFunc(("/#%u/ pUrb=%p:%s cbData=%#zx\n", pThis->pUsbIns->iInstance, pUrb, pUrb->pszDesc, cbData));
    11361137
    11371138    pUrb->enmStatus = VUSBSTATUS_OK;
     
    11491150static void usbNetCompleteNotificationOk(PUSBNET pThis, PVUSBURB pUrb, const void *pSrc, size_t cbSrc)
    11501151{
    1151     LogFunc(("/#%u/ pUrb=%p:%s (cbData=%#x) cbSrc=%#zx\n", pThis->pUsbIns->iInstance, pUrb, pUrb->pszDesc, pUrb->cbData, cbSrc));
     1152    LogFlowFunc(("/#%u/ pUrb=%p:%s (cbData=%#x) cbSrc=%#zx\n", pThis->pUsbIns->iInstance, pUrb, pUrb->pszDesc, pUrb->cbData, cbSrc));
    11521153
    11531154    pUrb->enmStatus = VUSBSTATUS_OK;
     
    11641165        memcpy(pDst, pSrc, cbCopy);
    11651166        pUrb->cbData = (uint32_t)cbCopy;
    1166         Log(("Copied %zu bytes to pUrb->abData, source had %zu bytes\n", cbCopy, cbSrc));
     1167        Log2Func(("/#%u/ Copied %zu bytes to pUrb->abData, source had %zu bytes\n", pThis->pUsbIns->iInstance, cbCopy, cbSrc));
    11671168
    11681169        /*
     
    12671268}
    12681269
     1270#ifdef LOG_ENABLED
     1271
     1272DECLINLINE(void) usbNetProtocolDump(const uint8_t *cpPacket, uint32_t cb)
     1273{
     1274    RT_NOREF(cb);
     1275    uint8_t  protocol;
     1276    uint16_t offset = sizeof(RTNETETHERHDR);
     1277    uint16_t uEthType = RT_N2H_U16(*(uint16_t*)(cpPacket+12));
     1278    if (uEthType == RTNET_ETHERTYPE_VLAN)
     1279    {
     1280        uEthType = RT_N2H_U16(*(uint16_t*)(cpPacket+16));
     1281        offset += 4;
     1282    }
     1283    if (uEthType == RTNET_ETHERTYPE_ARP)
     1284    {
     1285        Log4(("\tARP\n"));
     1286        return;
     1287    }
     1288    else if (uEthType == RTNET_ETHERTYPE_IPV4)
     1289    {
     1290        PRTNETIPV4 pHdr = (PRTNETIPV4)(cpPacket + offset);
     1291        offset += pHdr->ip_hl * 4;
     1292        protocol = pHdr->ip_p;
     1293        Log4(("\tIPv4: %RTnaipv4 => %RTnaipv4\n", pHdr->ip_src, pHdr->ip_dst));
     1294    }
     1295    else if (uEthType == RTNET_ETHERTYPE_IPV6)
     1296    {
     1297        PRTNETIPV6 pHdr = (PRTNETIPV6)(cpPacket + offset);
     1298        protocol = pHdr->ip6_nxt;
     1299        offset += sizeof(RTNETIPV6);
     1300        if (protocol == 0 || protocol == 60)
     1301        {
     1302            /* Skip hop-by-hop and destination options */
     1303            while (cpPacket[offset] == 0 || cpPacket[offset] == 60)
     1304                offset += 8 * (1 + cpPacket[offset+1]);
     1305            protocol = cpPacket[offset];
     1306            offset += 8 * (1 + cpPacket[offset+1]);
     1307        }
     1308        Log4(("\tIPv6: %RTnaipv6 => %RTnaipv6\n", pHdr->ip6_src, pHdr->ip6_dst));
     1309    }
     1310    else
     1311    {
     1312        Log4(("\tEthernet: 0x%04x\n", uEthType));
     1313        return;
     1314    }     
     1315    switch (protocol)
     1316    {
     1317        case 1: Log4(("\tICMP\n")); break;
     1318        case 2: Log4(("\tIGMP\n")); break;
     1319        case 58: Log4(("\tICMPv6\n")); break;
     1320
     1321        case 6:
     1322            {
     1323                PRTNETTCP pTcp = (PRTNETTCP)(cpPacket + offset);
     1324                Log4(("\tTCP: %u => %u, seq=%u ack=%u\n", RT_N2H_U16(pTcp->th_sport), RT_N2H_U16(pTcp->th_dport),
     1325                      RT_N2H_U32(pTcp->th_seq), RT_N2H_U32(pTcp->th_ack)));
     1326            }
     1327            break;
     1328        case 17:
     1329            {
     1330                PRTNETUDP pUdp = (PRTNETUDP)(cpPacket + offset);
     1331                Log4(("\tUDP: %u => %u\n", RT_N2H_U16(pUdp->uh_sport), RT_N2H_U16(pUdp->uh_dport)));
     1332            }
     1333            break;
     1334        default:
     1335            Log4(("\tUnknown (%u)", protocol));
     1336            break;
     1337    }
     1338}
     1339
     1340DECLINLINE(void) usbNetPacketDump(PUSBNET pThis, const void *pvBuf, size_t cb, const char *pcszText)
     1341{
     1342    const uint8_t *cpPacket = (const uint8_t *)pvBuf;
     1343    if (cb < 14)
     1344        Log3(("/#%u/ %s packet #%d is too small (%u bytes):\n%.*Rhxd\n",
     1345              pThis->pUsbIns->iInstance, pcszText, ++pThis->u32PktNo, (uint32_t)cb, (uint32_t)cb, cpPacket));
     1346    else
     1347    {
     1348        Log3(("/#%u/ %s packet #%d, %u bytes, %RTmac => %RTmac\n",
     1349              pThis->pUsbIns->iInstance, pcszText, ++pThis->u32PktNo, (uint32_t)cb, cpPacket+6, cpPacket));
     1350        if (LogIs4Enabled())
     1351            usbNetProtocolDump(cpPacket, (uint32_t)cb);
     1352        Log5(("%.*Rhxd\n", (uint32_t)cb, cpPacket));
     1353    }
     1354}
     1355
     1356#else
     1357#define usbNetPacketDump(pUsbIns, pvBuf, cb, pcszText)
     1358#endif
    12691359
    12701360/**
     
    13091399        return VINF_SUCCESS;
    13101400    }
     1401
     1402    usbNetPacketDump(pThis, pvBuf, cb, "<-- Rx");
    13111403
    13121404    PUSBNCMNTH16 pNth16 = (PUSBNCMNTH16)&pUrb->abData[0];
     
    14681560
    14691561    if (pUrb)
    1470         LogFunc(("/#%u/ pUrb=%p:%s\n", pUsbIns->iInstance, pUrb, pUrb->pszDesc));
     1562        Log2Func(("/#%u/ pUrb=%p:%s\n", pUsbIns->iInstance, pUrb, pUrb->pszDesc));
    14711563    return pUrb;
    14721564}
     
    15251617    if (pUrb->cbData < sizeof(*pNth16))
    15261618    {
    1527         Log(("UsbNet: Bad NTH16: cbData=%#x < min=%#x\n", pUrb->cbData, sizeof(*pNth16) ));
     1619        LogFunc(("/#%u/ Bad NTH16: cbData=%#x < min=%#x\n", pThis->pUsbIns->iInstance, pUrb->cbData, sizeof(*pNth16) ));
    15281620        return usbNetCompleteStall(pThis, NULL, pUrb, "BAD NTH16");
    15291621    }
    15301622    if (pNth16->dwSignature != USBNCMNTH16_SIGNATURE)
    15311623    {
    1532         Log(("UsbNet: NTH16: Invalid dwSignature value: %#x\n", pNth16->dwSignature));
     1624        LogFunc(("/#%u/ NTH16: Invalid dwSignature value: %#x\n", pNth16->dwSignature));
    15331625        return usbNetCompleteStall(pThis, NULL, pUrb, "Bad NTH16");
    15341626    }
    1535     Log(("UsbNet: NTH16: wHeaderLength=%#x wSequence=%#x wBlockLength=%#x wNdpIndex=%#x cbData=%#x fShortNotOk=%RTbool\n",
    1536          pNth16->wHeaderLength, pNth16->wSequence, pNth16->wBlockLength, pNth16->wNdpIndex, pUrb->cbData, pUrb->fShortNotOk));
     1627    Log2Func(("/#%u/ NTH16: wHeaderLength=%#x wSequence=%#x wBlockLength=%#x wNdpIndex=%#x cbData=%#x fShortNotOk=%RTbool\n", pThis->pUsbIns->iInstance,
     1628              pNth16->wHeaderLength, pNth16->wSequence, pNth16->wBlockLength, pNth16->wNdpIndex, pUrb->cbData, pUrb->fShortNotOk));
    15371629    if (pNth16->wHeaderLength != sizeof(*pNth16))
    15381630    {
    1539         Log(("UsbNet: NTH16: Bad wHeaderLength value: %#x\n", pNth16->wHeaderLength));
     1631        LogFunc(("/#%u/ NTH16: Bad wHeaderLength value: %#x\n", pThis->pUsbIns->iInstance, pNth16->wHeaderLength));
    15401632        return usbNetCompleteStall(pThis, NULL, pUrb, "Bad NTH16");
    15411633
     
    15431635    if (pNth16->wBlockLength > pUrb->cbData)
    15441636    {
    1545         Log(("UsbNet: NTH16: Bad wBlockLength value: %#x\n", pNth16->wBlockLength));
     1637        LogFunc(("/#%u/ NTH16: Bad wBlockLength value: %#x\n", pThis->pUsbIns->iInstance, pNth16->wBlockLength));
    15461638        return usbNetCompleteStall(pThis, NULL, pUrb, "Bad NTH16");
    15471639    }
     
    15491641    if (pNth16->wNdpIndex < sizeof(*pNth16))
    15501642    {
    1551         Log(("UsbNet: NTH16: wNdpIndex is too small: %#x (%u), at least required %#x\n",
     1643        LogFunc(("/#%u/ NTH16: wNdpIndex is too small: %#x (%u), at least required %#x\n", pThis->pUsbIns->iInstance,
    15521644             pNth16->wNdpIndex, pNth16->wNdpIndex, sizeof(*pNth16) ));
    15531645        return usbNetCompleteStall(pThis, NULL, pUrb, "Bad NTH16");
     
    15601652        if (offNdp16Next >= pUrb->cbData)
    15611653        {
    1562             Log(("UsbNet: Bad NDP16: offNdp16Next=%#x >= cbData=%#x\n", offNdp16Next, pUrb->cbData));
     1654            LogFunc(("/#%u/ Bad NDP16: offNdp16Next=%#x >= cbData=%#x\n", pThis->pUsbIns->iInstance, offNdp16Next, pUrb->cbData));
    15631655            return usbNetCompleteStall(pThis, NULL, pUrb, "BAD NDP16");
    15641656        }
     
    15681660        if (cbNdpMax < sizeof(*pNdp16))
    15691661        {
    1570             Log(("UsbNet: Bad NDP16: cbNdpMax=%#x < min=%#x\n", cbNdpMax, sizeof(*pNdp16) ));
     1662            LogFunc(("/#%u/ Bad NDP16: cbNdpMax=%#x < min=%#x\n", pThis->pUsbIns->iInstance, cbNdpMax, sizeof(*pNdp16) ));
    15711663            return usbNetCompleteStall(pThis, NULL, pUrb, "BAD NDP16");
    15721664        }
     
    15751667            && pNdp16->dwSignature != USBNCMNDP16_SIGNATURE_NCM1)
    15761668        {
    1577             Log(("UsbNet: NDP16: Invalid dwSignature value: %#x\n", pNdp16->dwSignature));
     1669            LogFunc(("/#%u/ NDP16: Invalid dwSignature value: %#x\n", pThis->pUsbIns->iInstance, pNdp16->dwSignature));
    15781670            return usbNetCompleteStall(pThis, NULL, pUrb, "Bad NDP16");
    15791671        }
     
    15831675            || pNdp16->wLength > cbNdpMax)
    15841676        {
    1585             Log(("UsbNet: NDP16: Invalid size value: %#x, req. (min %#x max %#x)\n",
     1677            LogFunc(("/#%u/ NDP16: Invalid size value: %#x, req. (min %#x max %#x)\n", pThis->pUsbIns->iInstance,
    15861678                 pNdp16->wLength, sizeof(*pNdp16), cbNdpMax));
    15871679            return usbNetCompleteStall(pThis, NULL, pUrb, "Bad NDP16");
     
    16071699                    || pDGram->wDatagramIndex >= pUrb->cbData)
    16081700                {
    1609                     Log(("UsbNet: DGRAM16: Invalid wDatagramIndex value: %#x\n", pDGram->wDatagramIndex));
     1701                    LogFunc(("/#%u/ DGRAM16: Invalid wDatagramIndex value: %#x\n", pThis->pUsbIns->iInstance, pDGram->wDatagramIndex));
    16101702                    return usbNetCompleteStall(pThis, NULL, pUrb, "Bad DGRAM16");
    16111703                }
     
    16131705                if (pUrb->cbData - pDGram->wDatagramIndex < pDGram->wDatagramLength)
    16141706                {
    1615                     Log(("UsbNet: DGRAM16: Invalid wDatagramLength value: %#x (max %#x)\n",
     1707                    LogFunc(("/#%u/ DGRAM16: Invalid wDatagramLength value: %#x (max %#x)\n", pThis->pUsbIns->iInstance,
    16161708                         pDGram->wDatagramLength, pUrb->cbData - pDGram->wDatagramIndex));
    16171709                    return usbNetCompleteStall(pThis, NULL, pUrb, "Bad DGRAM16");
     
    16241716                    uint8_t *pbBuf = pSgBuf ? (uint8_t *)pSgBuf->aSegs[0].pvSeg : NULL;
    16251717                    memcpy(pbBuf, &pUrb->abData[pDGram->wDatagramIndex], pDGram->wDatagramLength);
     1718                    usbNetPacketDump(pThis, pbBuf, pDGram->wDatagramLength, "--> Tx");
    16261719                    pSgBuf->cbUsed = pDGram->wDatagramLength;
    16271720                    rc = pThis->Lun0.pINetwork->pfnSendBuf(pThis->Lun0.pINetwork, pSgBuf, true /* fOnWorkerThread */);
     
    16401733        else
    16411734        {
    1642             Log(("UsbNet: NDP16: Not implemented\n"));
     1735            LogFunc(("/#%u/ NDP16: Not implemented\n", pThis->pUsbIns->iInstance));
    16431736            return usbNetCompleteStall(pThis, NULL, pUrb, "Bad NDP16");
    16441737        }
     
    17541847                if (pSetup->bmRequestType != (VUSB_TO_DEVICE | VUSB_REQ_STANDARD | VUSB_DIR_TO_HOST))
    17551848                {
    1756                     Log(("UsbNet: Bad GET_DESCRIPTOR req: bmRequestType=%#x\n", pSetup->bmRequestType));
     1849                    LogFunc(("/#%u/ Bad GET_DESCRIPTOR req: bmRequestType=%#x\n", pThis->pUsbIns->iInstance, pSetup->bmRequestType));
    17571850                    return usbNetCompleteStall(pThis, pEp, pUrb, "Bad GET_DESCRIPTOR");
    17581851                }
     
    17631856
    17641857                    case VUSB_DT_STRING:
    1765                         Log(("UsbNet: GET_DESCRIPTOR DT_STRING wValue=%#x wIndex=%#x\n", pSetup->wValue, pSetup->wIndex));
     1858                        LogFunc(("/#%u/ GET_DESCRIPTOR DT_STRING wValue=%#x wIndex=%#x\n", pThis->pUsbIns->iInstance, pSetup->wValue, pSetup->wIndex));
    17661859                        break;
    17671860                    case VUSB_DT_DEVICE_QUALIFIER:
    1768                         Log(("UsbNet: GET_DESCRIPTOR DT_DEVICE_QUALIFIER wValue=%#x wIndex=%#x\n", pSetup->wValue, pSetup->wIndex));
     1861                        LogFunc(("/#%u/ GET_DESCRIPTOR DT_DEVICE_QUALIFIER wValue=%#x wIndex=%#x\n", pThis->pUsbIns->iInstance, pSetup->wValue, pSetup->wIndex));
    17691862                        /* Returned data is written after the setup message. */
    17701863                        cbCopy = pUrb->cbData - sizeof(*pSetup);
     
    17731866                        return usbNetCompleteOk(pThis, pUrb, cbCopy + sizeof(*pSetup));
    17741867                    case VUSB_DT_BOS:
    1775                         Log(("UsbNet: GET_DESCRIPTOR DT_BOS wValue=%#x wIndex=%#x\n", pSetup->wValue, pSetup->wIndex));
     1868                        LogFunc(("/#%u/ GET_DESCRIPTOR DT_BOS wValue=%#x wIndex=%#x\n", pThis->pUsbIns->iInstance, pSetup->wValue, pSetup->wIndex));
    17761869                        /* Returned data is written after the setup message. */
    17771870                        cbCopy = pUrb->cbData - sizeof(*pSetup);
     
    17801873                        return usbNetCompleteOk(pThis, pUrb, cbCopy + sizeof(*pSetup));
    17811874                    default:
    1782                         Log(("UsbNet: GET_DESCRIPTOR, huh? wValue=%#x wIndex=%#x\n", pSetup->wValue, pSetup->wIndex));
     1875                        LogFunc(("/#%u/ GET_DESCRIPTOR, huh? wValue=%#x wIndex=%#x\n", pThis->pUsbIns->iInstance, pSetup->wValue, pSetup->wIndex));
    17831876                        break;
    17841877                }
     
    18541947
    18551948        /** @todo implement this. */
    1856         Log(("UsbNet: Implement standard request: bmRequestType=%#x bRequest=%#x wValue=%#x wIndex=%#x wLength=%#x\n",
     1949        LogFunc(("/#%u/ Implement standard request: bmRequestType=%#x bRequest=%#x wValue=%#x wIndex=%#x wLength=%#x\n", pThis->pUsbIns->iInstance,
    18571950             pSetup->bmRequestType, pSetup->bRequest, pSetup->wValue, pSetup->wIndex, pSetup->wLength));
    18581951
     
    18671960                if (pSetup->bmRequestType != (VUSB_TO_INTERFACE | VUSB_REQ_CLASS | VUSB_DIR_TO_HOST))
    18681961                {
    1869                     Log(("UsbNet: Bad GET_NTB_PARAMETERS req: bmRequestType=%#x\n", pSetup->bmRequestType));
     1962                    LogFunc(("/#%u/ Bad GET_NTB_PARAMETERS req: bmRequestType=%#x\n", pThis->pUsbIns->iInstance, pSetup->bmRequestType));
    18701963                    return usbNetCompleteStall(pThis, pEp, pUrb, "Bad GET_NTB_PARAMETERS");
    18711964                }
     
    19001993    else
    19011994    {
    1902         Log(("UsbNet: Unknown control msg: bmRequestType=%#x bRequest=%#x wValue=%#x wIndex=%#x wLength=%#x\n",
     1995        LogFunc(("/#%u/ Unknown control msg: bmRequestType=%#x bRequest=%#x wValue=%#x wIndex=%#x wLength=%#x\n", pThis->pUsbIns->iInstance,
    19031996             pSetup->bmRequestType, pSetup->bRequest, pSetup->wValue, pSetup->wIndex, pSetup->wLength));
    19041997        return usbNetCompleteStall(pThis, pEp, pUrb, "Unknown control msg");
     
    22162309    LogFlowFunc(("/#%u/\n", iInstance));
    22172310
     2311    pThis->u32PktNo = 1;
    22182312    /*
    22192313     * Perform the basic structure initialization first so the destructor
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