VirtualBox

Changeset 46904 in vbox for trunk/include/VBox


Ignore:
Timestamp:
Jul 2, 2013 12:59:56 PM (11 years ago)
Author:
vboxsync
Message:

IntNet, VirtioNet, NetFilter: Large frame support + drop oversized + UFO fix (#6821)

Location:
trunk/include/VBox
Files:
2 edited

Legend:

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

    r39034 r46904  
    214214typedef struct INTNETHDR
    215215{
     216    /** The size of the frame. */
     217    uint32_t        cbFrame : 24;
    216218    /** Header type. This is currently serving as a magic, it
    217219     * can be extended later to encode special command frames and stuff. */
    218     uint16_t        u16Type;
    219     /** The size of the frame. */
    220     uint16_t        cbFrame;
     220    uint32_t        u8Type  : 8;
    221221    /** The offset from the start of this header to where the actual frame starts.
    222222     * This is used to keep the frame it self contiguous in virtual memory and
     
    236236AssertCompile(INTNETHDR_ALIGNMENT <= INTNETRINGBUF_ALIGNMENT);
    237237
    238 /** @name Frame types (INTNETHDR::u16Type).
     238/** @name Frame types (INTNETHDR::u8Type).
    239239 * @{ */
    240240/** Normal frames. */
    241 #define INTNETHDR_TYPE_FRAME        0x2442
     241#define INTNETHDR_TYPE_FRAME        0x42
    242242/** Padding frames. */
    243 #define INTNETHDR_TYPE_PADDING      0x3553
     243#define INTNETHDR_TYPE_PADDING      0x53
    244244/** Generic segment offload frames.
    245245 * The frame starts with a PDMNETWORKGSO structure which is followed by the
    246246 * header template and data. */
    247 #define INTNETHDR_TYPE_GSO          0x4664
     247#define INTNETHDR_TYPE_GSO          0x64
    248248AssertCompileSize(PDMNETWORKGSO, 8);
    249249/** @}  */
     
    258258        AssertPtr(pHdr); \
    259259        Assert(RT_ALIGN_PT(pHdr, INTNETHDR_ALIGNMENT, INTNETHDR *) == pHdr); \
    260         Assert(   (pHdr)->u16Type == INTNETHDR_TYPE_FRAME \
    261                || (pHdr)->u16Type == INTNETHDR_TYPE_GSO \
    262                || (pHdr)->u16Type == INTNETHDR_TYPE_PADDING); \
     260        Assert(   (pHdr)->u8Type == INTNETHDR_TYPE_FRAME \
     261               || (pHdr)->u8Type == INTNETHDR_TYPE_GSO \
     262               || (pHdr)->u8Type == INTNETHDR_TYPE_PADDING); \
    263263        { \
    264264            uintptr_t const offHdr   = (uintptr_t)pHdr - (uintptr_t)pRingBuf; \
  • trunk/include/VBox/intnetinline.h

    r44528 r46904  
    4444 *
    4545 * @returns  true / false.
    46  * @param   u16Type             The frame type to check.
    47  */
    48 DECLINLINE(bool) IntNetIsValidFrameType(uint16_t u16Type)
    49 {
    50     if (RT_LIKELY(   u16Type == INTNETHDR_TYPE_FRAME
    51                   || u16Type == INTNETHDR_TYPE_GSO
    52                   || u16Type == INTNETHDR_TYPE_PADDING))
     46 * @param    u8Type             The frame type to check.
     47 */
     48DECLINLINE(bool) IntNetIsValidFrameType(uint8_t u8Type)
     49{
     50    if (RT_LIKELY(   u8Type == INTNETHDR_TYPE_FRAME
     51                  || u8Type == INTNETHDR_TYPE_GSO
     52                  || u8Type == INTNETHDR_TYPE_PADDING))
    5353        return true;
    5454    return false;
     
    328328#ifdef VBOX_STRICT
    329329    const uintptr_t off = (uintptr_t)pu8 - (uintptr_t)pBuf;
    330     Assert(IntNetIsValidFrameType(pHdr->u16Type));
     330    Assert(IntNetIsValidFrameType(pHdr->u8Type));
    331331    Assert(off < pBuf->cbBuf);
    332332    Assert(off + pHdr->cbFrame <= pBuf->cbBuf);
     
    354354#ifdef VBOX_STRICT
    355355    const uintptr_t off = (uintptr_t)pGso - (uintptr_t)pBuf;
    356     Assert(pHdr->u16Type == INTNETHDR_TYPE_GSO);
     356    Assert(pHdr->u8Type == INTNETHDR_TYPE_GSO);
    357357    Assert(off < pBuf->cbBuf);
    358358    Assert(off + pHdr->cbFrame <= pBuf->cbBuf);
     
    375375    Assert(offReadOld <  pRingBuf->offEnd);
    376376    Assert(RT_ALIGN_PT(pHdr, INTNETHDR_ALIGNMENT, INTNETHDR *) == pHdr);
    377     Assert(IntNetIsValidFrameType(pHdr->u16Type));
     377    Assert(IntNetIsValidFrameType(pHdr->u8Type));
    378378
    379379    /* skip the frame */
     
    402402 * @param   ppvFrame            Where to return the frame pointer.
    403403 */
    404 DECLINLINE(int) intnetRingAllocateFrameInternal(PINTNETRINGBUF pRingBuf, uint32_t cbFrame, uint16_t u16Type,
     404DECLINLINE(int) intnetRingAllocateFrameInternal(PINTNETRINGBUF pRingBuf, uint32_t cbFrame, uint8_t u8Type,
    405405                                                PINTNETHDR *ppHdr, void **ppvFrame)
    406406{
     
    426426            if (RT_UNLIKELY(!ASMAtomicCmpXchgU32(&pRingBuf->offWriteInt, offNew, offWriteInt)))
    427427                return VERR_WRONG_ORDER; /* race */
    428             Log2(("intnetRingAllocateFrameInternal: offWriteInt: %#x -> %#x (1) (R=%#x T=%#x S=%#x)\n", offWriteInt, offNew, offRead, u16Type, cbFrame));
     428            Log2(("intnetRingAllocateFrameInternal: offWriteInt: %#x -> %#x (1) (R=%#x T=%#x S=%#x)\n", offWriteInt, offNew, offRead, u8Type, cbFrame));
    429429
    430430            PINTNETHDR pHdr = (PINTNETHDR)((uint8_t *)pRingBuf + offWriteInt);
    431             pHdr->u16Type  = u16Type;
    432             pHdr->cbFrame  = (uint16_t)cbFrame; Assert(pHdr->cbFrame == cbFrame);
     431            pHdr->u8Type   = u8Type;
     432            pHdr->cbFrame  = cbFrame; Assert(pHdr->cbFrame == cbFrame);
    433433            pHdr->offFrame = sizeof(INTNETHDR);
    434434
     
    447447            if (RT_UNLIKELY(!ASMAtomicCmpXchgU32(&pRingBuf->offWriteInt, offNew, offWriteInt)))
    448448                return VERR_WRONG_ORDER; /* race */
    449             Log2(("intnetRingAllocateFrameInternal: offWriteInt: %#x -> %#x (2) (R=%#x T=%#x S=%#x)\n", offWriteInt, offNew, offRead, u16Type, cbFrame));
     449            Log2(("intnetRingAllocateFrameInternal: offWriteInt: %#x -> %#x (2) (R=%#x T=%#x S=%#x)\n", offWriteInt, offNew, offRead, u8Type, cbFrame));
    450450
    451451            PINTNETHDR pHdr = (PINTNETHDR)((uint8_t *)pRingBuf + offWriteInt);
    452             pHdr->u16Type  = u16Type;
    453             pHdr->cbFrame  = (uint16_t)cbFrame; Assert(pHdr->cbFrame == cbFrame);
     452            pHdr->u8Type   = u8Type;
     453            pHdr->cbFrame  = cbFrame; Assert(pHdr->cbFrame == cbFrame);
    454454            pHdr->offFrame = pRingBuf->offStart - offWriteInt;
    455455
     
    467467        if (RT_UNLIKELY(!ASMAtomicCmpXchgU32(&pRingBuf->offWriteInt, offNew, offWriteInt)))
    468468            return VERR_WRONG_ORDER; /* race */
    469         Log2(("intnetRingAllocateFrameInternal: offWriteInt: %#x -> %#x (3) (R=%#x T=%#x S=%#x)\n", offWriteInt, offNew, offRead, u16Type, cbFrame));
     469        Log2(("intnetRingAllocateFrameInternal: offWriteInt: %#x -> %#x (3) (R=%#x T=%#x S=%#x)\n", offWriteInt, offNew, offRead, u8Type, cbFrame));
    470470
    471471        PINTNETHDR pHdr = (PINTNETHDR)((uint8_t *)pRingBuf + offWriteInt);
    472         pHdr->u16Type  = u16Type;
    473         pHdr->cbFrame  = (uint16_t)cbFrame; Assert(pHdr->cbFrame == cbFrame);
     472        pHdr->u8Type   = u8Type;
     473        pHdr->cbFrame  = cbFrame; Assert(pHdr->cbFrame == cbFrame);
    474474        pHdr->offFrame = sizeof(INTNETHDR);
    475475
     
    561561        offWriteCom = pRingBuf->offStart;
    562562    }
    563     Log2(("IntNetRingCommitFrame:   offWriteCom: %#x -> %#x (R=%#x T=%#x S=%#x)\n", pRingBuf->offWriteCom, offWriteCom, pRingBuf->offReadX, pHdr->u16Type, cbFrame));
     563    Log2(("IntNetRingCommitFrame:   offWriteCom: %#x -> %#x (R=%#x T=%#x S=%#x)\n", pRingBuf->offWriteCom, offWriteCom, pRingBuf->offReadX, pHdr->u8Type, cbFrame));
    564564    ASMAtomicWriteU32(&pRingBuf->offWriteCom, offWriteCom);
    565565    STAM_REL_COUNTER_ADD(&pRingBuf->cbStatWritten, cbFrame);
     
    589589    Assert(pRingBuf->offWriteCom == ((uintptr_t)pHdr - (uintptr_t)pRingBuf));
    590590
    591     if (pHdr->u16Type == INTNETHDR_TYPE_GSO)
     591    if (pHdr->u8Type == INTNETHDR_TYPE_GSO)
    592592        cbUsed += sizeof(PDMNETWORKGSO);
    593593
     
    613613        /** @todo Later: Try unallocate the extra memory.  */
    614614        PINTNETHDR pHdrPadding = (PINTNETHDR)((uint8_t *)pHdr + pHdr->offFrame + cbAlignedUsed);
    615         pHdrPadding->u16Type  = INTNETHDR_TYPE_PADDING;
    616         pHdrPadding->cbFrame  = (uint16_t)(cbAlignedFrame - cbAlignedUsed - sizeof(INTNETHDR));
     615        pHdrPadding->u8Type   = INTNETHDR_TYPE_PADDING;
     616        pHdrPadding->cbFrame  = cbAlignedFrame - cbAlignedUsed - sizeof(INTNETHDR);
     617        Assert(pHdrPadding->cbFrame == cbAlignedFrame - cbAlignedUsed - sizeof(INTNETHDR));
    617618        pHdrPadding->offFrame = sizeof(INTNETHDR);
    618         pHdr->cbFrame = (uint16_t)cbUsed;
    619     }
    620 
    621     Log2(("IntNetRingCommitFrameEx:   offWriteCom: %#x -> %#x (R=%#x T=%#x S=%#x P=%#x)\n", pRingBuf->offWriteCom, offWriteCom, pRingBuf->offReadX, pHdr->u16Type, pHdr->cbFrame, cbAlignedFrame - cbAlignedUsed));
     619        pHdr->cbFrame = cbUsed; Assert(pHdr->cbFrame == cbUsed);
     620    }
     621
     622    Log2(("IntNetRingCommitFrameEx:   offWriteCom: %#x -> %#x (R=%#x T=%#x S=%#x P=%#x)\n", pRingBuf->offWriteCom, offWriteCom, pRingBuf->offReadX, pHdr->u8Type, pHdr->cbFrame, cbAlignedFrame - cbAlignedUsed));
    622623    ASMAtomicWriteU32(&pRingBuf->offWriteCom, offWriteCom);
    623624    STAM_REL_COUNTER_ADD(&pRingBuf->cbStatWritten, cbUsed);
     
    665666
    666667            PINTNETHDR pHdr = (PINTNETHDR)((uint8_t *)pRingBuf + offWriteInt);
    667             pHdr->u16Type  = INTNETHDR_TYPE_FRAME;
    668             pHdr->cbFrame  = (uint16_t)cbFrame; Assert(pHdr->cbFrame == cbFrame);
     668            pHdr->u8Type   = INTNETHDR_TYPE_FRAME;
     669            pHdr->cbFrame  = cbFrame; Assert(pHdr->cbFrame == cbFrame);
    669670            pHdr->offFrame = sizeof(INTNETHDR);
    670671
     
    690691
    691692            PINTNETHDR pHdr = (PINTNETHDR)((uint8_t *)pRingBuf + offWriteInt);
    692             pHdr->u16Type  = INTNETHDR_TYPE_FRAME;
    693             pHdr->cbFrame  = (uint16_t)cbFrame; Assert(pHdr->cbFrame == cbFrame);
     693            pHdr->u8Type   = INTNETHDR_TYPE_FRAME;
     694            pHdr->cbFrame  = cbFrame; Assert(pHdr->cbFrame == cbFrame);
    694695            pHdr->offFrame = pRingBuf->offStart - offWriteInt;
    695696
     
    714715
    715716        PINTNETHDR pHdr = (PINTNETHDR)((uint8_t *)pRingBuf + offWriteInt);
    716         pHdr->u16Type  = INTNETHDR_TYPE_FRAME;
    717         pHdr->cbFrame  = (uint16_t)cbFrame; Assert(pHdr->cbFrame == cbFrame);
     717        pHdr->u8Type   = INTNETHDR_TYPE_FRAME;
     718        pHdr->cbFrame  = cbFrame; Assert(pHdr->cbFrame == cbFrame);
    718719        pHdr->offFrame = sizeof(INTNETHDR);
    719720
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