VirtualBox

Ignore:
Timestamp:
Feb 12, 2016 12:29:58 PM (9 years ago)
Author:
vboxsync
Message:

NetLwf/Win(bugref:8246): Support jumbo frames over 2 KB

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostDrivers/VBoxNetFlt/win/drv/VBoxNetLwf-win.cpp

    r59065 r59653  
    1717
    1818//#define VBOXNETLWF_SYNC_SEND
     19/* Payload + Ethernet header + VLAN tag = Max Ethernet frame size */
     20#define VBOXNETLWF_MAX_FRAME_SIZE(mtu) (mtu +  sizeof(RTNETETHERHDR) + 4)
    1921
    2022#include <VBox/version.h>
     
    193195    /** MAC address of underlying adapter */
    194196    RTMAC MacAddr;
     197    /** Saved MTU size */
     198    ULONG uMtuSize;
    195199    /** Saved offload configuration */
    196200    NDIS_OFFLOAD SavedOffloadConfig;
     
    834838    pModuleCtx->cPendingBuffers = 0;
    835839#endif /* !VBOXNETLWF_SYNC_SEND */
    836     /* Allocate buffer pools */
    837     NET_BUFFER_LIST_POOL_PARAMETERS PoolParams;
    838     NdisZeroMemory(&PoolParams, sizeof(PoolParams));
    839     PoolParams.Header.Type = NDIS_OBJECT_TYPE_DEFAULT;
    840     PoolParams.Header.Revision = NET_BUFFER_LIST_POOL_PARAMETERS_REVISION_1;
    841     PoolParams.Header.Size = sizeof(PoolParams);
    842     PoolParams.ProtocolId = NDIS_PROTOCOL_ID_DEFAULT;
    843     PoolParams.fAllocateNetBuffer = TRUE;
    844     PoolParams.ContextSize = 0; /** @todo Do we need to consider underlying drivers? I think not. */
    845     PoolParams.PoolTag = VBOXNETLWF_MEM_TAG;
    846 #ifndef VBOXNETLWF_SYNC_SEND
    847     PoolParams.DataSize = 2048; /** @todo figure out the optimal size, use several pools if necessary, make configurable, etc */
    848 #endif /* !VBOXNETLWF_SYNC_SEND */
    849 
    850     pModuleCtx->hPool = NdisAllocateNetBufferListPool(hFilter, &PoolParams);
    851     if (!pModuleCtx->hPool)
    852     {
    853         LogError(("vboxNetLwfWinAttach: NdisAllocateNetBufferListPool failed\n"));
    854         NdisFreeIoWorkItem(pModuleCtx->hWorkItem);
    855         NdisFreeMemory(pModuleCtx, 0, 0);
    856         return NDIS_STATUS_RESOURCES;
    857     }
    858     Log4(("vboxNetLwfWinAttach: allocated NBL+NB pool 0x%p\n", pModuleCtx->hPool));
    859840
    860841    NDIS_FILTER_ATTRIBUTES Attributes;
     
    970951    vboxNetLwfWinChangeState(pModuleCtx, LwfState_Restarting, LwfState_Paused);
    971952
    972     vboxNetLwfWinChangeState(pModuleCtx, LwfState_Running, LwfState_Restarting);
    973953    NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
     954    ULONG uNewMtuSize = 1500; /* If we fail to find out MTU, we can always assume 1500. */
     955    PNDIS_RESTART_ATTRIBUTES pAttributes = pParameters->RestartAttributes;
     956    while (pAttributes && pAttributes->Oid != OID_GEN_MINIPORT_RESTART_ATTRIBUTES)
     957        pAttributes = pAttributes->Next;
     958    if (pAttributes)
     959    {
     960        PNDIS_RESTART_GENERAL_ATTRIBUTES pGenAttrs = (PNDIS_RESTART_GENERAL_ATTRIBUTES)pAttributes->Data;
     961        uNewMtuSize = pGenAttrs->MtuSize;
     962    }
     963
     964    /* Let's see if MTU has changed. Re-allocate the pool if it has. */
     965    if (pModuleCtx->uMtuSize != uNewMtuSize)
     966    {
     967        pModuleCtx->uMtuSize = uNewMtuSize;
     968        if (pModuleCtx->hPool)
     969        {
     970            /*
     971             * Don't need to wait for pending sends to complete since we are already
     972             * in paused state. Just free the old pool.
     973             */
     974            NdisFreeNetBufferListPool(pModuleCtx->hPool);
     975            pModuleCtx->hPool = NULL;
     976        }
     977    }
     978    if (!pModuleCtx->hPool)
     979    {
     980        /* Allocate a new pool. */
     981        NET_BUFFER_LIST_POOL_PARAMETERS PoolParams;
     982        NdisZeroMemory(&PoolParams, sizeof(PoolParams));
     983        PoolParams.Header.Type = NDIS_OBJECT_TYPE_DEFAULT;
     984        PoolParams.Header.Revision = NET_BUFFER_LIST_POOL_PARAMETERS_REVISION_1;
     985        PoolParams.Header.Size = sizeof(PoolParams);
     986        PoolParams.ProtocolId = NDIS_PROTOCOL_ID_DEFAULT;
     987        PoolParams.fAllocateNetBuffer = TRUE;
     988        PoolParams.ContextSize = 0; /** @todo Do we need to consider underlying drivers? I think not. */
     989        PoolParams.PoolTag = VBOXNETLWF_MEM_TAG;
     990#ifndef VBOXNETLWF_SYNC_SEND
     991        PoolParams.DataSize = VBOXNETLWF_MAX_FRAME_SIZE(pModuleCtx->uMtuSize);
     992#endif /* !VBOXNETLWF_SYNC_SEND */
     993
     994        pModuleCtx->hPool = NdisAllocateNetBufferListPool(pModuleCtx->hFilter, &PoolParams);
     995        if (!pModuleCtx->hPool)
     996        {
     997            LogError(("vboxNetLwfWinRestart: NdisAllocateNetBufferListPool failed\n"));
     998            Status = NDIS_STATUS_RESOURCES;
     999        }
     1000        else
     1001        {
     1002            Log4(("vboxNetLwfWinRestart: allocated NBL+NB pool 0x%p with MTU=%u\n",
     1003                  pModuleCtx->hPool, pModuleCtx->uMtuSize));
     1004        }
     1005    }
     1006
     1007    vboxNetLwfWinChangeState(pModuleCtx, Status == NDIS_STATUS_SUCCESS ? LwfState_Running : LwfState_Paused, LwfState_Restarting);
    9741008    LogFlow(("<==vboxNetLwfWinRestart: Status = 0x%x\n", Status));
    9751009    return Status;
     
    10221056    uint16_t uEthType = RT_N2H_U16(*(uint16_t*)(pHdr+12));
    10231057    Log2(("NetLWF: %s (%d bytes), %RTmac => %RTmac, EthType=%s(0x%x)\n",
    1024           cszText, cb, pHdr+6, pHdr, vboxNetLwfWinEthTypeStr(uEthType), uEthType));
     1058          cszText, pSG->cbTotal, pHdr+6, pHdr, vboxNetLwfWinEthTypeStr(uEthType), uEthType));
    10251059    pHdr += sizeof(RTNETETHERHDR);
    10261060    if (uEthType == RTNET_ETHERTYPE_VLAN)
     
    11691203{
    11701204    AssertReturn(pSG->cSegsUsed >= 1, NULL);
    1171     LogFlow(("==>vboxNetLwfWinSGtoNB: segments=%d\n", pSG->cSegsUsed));
     1205    LogFlow(("==>vboxNetLwfWinSGtoNB: segments=%d hPool=%p cb=%u max=%u\n", pSG->cSegsUsed,
     1206             pModule->hPool, pSG->cbTotal, VBOXNETLWF_MAX_FRAME_SIZE(pModule->uMtuSize)));
     1207    AssertReturn(pModule->hPool, NULL);
    11721208
    11731209#ifdef VBOXNETLWF_SYNC_SEND
     
    12141250    }
    12151251#else /* !VBOXNETLWF_SYNC_SEND */
    1216     AssertReturn(pSG->cbTotal < 2048, NULL);
     1252    AssertReturn(pSG->cbTotal <= VBOXNETLWF_MAX_FRAME_SIZE(pModule->uMtuSize), NULL);
    12171253    PNET_BUFFER_LIST pBufList = NdisAllocateNetBufferList(pModule->hPool,
    12181254                                                          0 /** @todo ContextSize */,
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