datapath-windows/ovsext/BufferMgmt.c
/*
 * --------------------------------------------------------------------------
 * OvsInitExternalNBLContext --
 *
 *     For NBL not allocated by OVS, it will allocate and initialize
 *     the NBL context.
 * --------------------------------------------------------------------------
 */


For NBL not allocated by OVS, it will allocate and initialize
the NBL context.
For NBL not allocated by OVS it will allocate and initialize the NBL context .
POVS_BUFFER_CONTEXT
OvsInitExternalNBLContext(PVOID ovsContext,
                          PNET_BUFFER_LIST nbl,
                          BOOLEAN isRecv)
{
    NDIS_HANDLE poolHandle;
    POVS_SWITCH_CONTEXT context = (POVS_SWITCH_CONTEXT)ovsContext;
    POVS_BUFFER_CONTEXT ctx;
    PNET_BUFFER nb;
    NDIS_STATUS status;
    UINT16 flags;
    poolHandle = NdisGetPoolFromNetBufferList(nbl);
    if (poolHandle == context->ovsPool.ndisHandle ||
        nbl->SourceHandle == context->ovsPool.ndisHandle) {
        return (POVS_BUFFER_CONTEXT)NET_BUFFER_LIST_CONTEXT_DATA_START(nbl);
    }
    status = NdisAllocateNetBufferListContext(nbl, sizeof (OVS_BUFFER_CONTEXT),
                                              OVS_DEFAULT_NBL_CONTEXT_FILL,
                                              OVS_OTHER_POOL_TAG);
    if (status != NDIS_STATUS_SUCCESS) {
        return NULL;
    }
#ifdef DBG
    OvsDumpNBLContext(nbl);
    InterlockedIncrement((LONG volatile *)&context->ovsPool.sysNBLCount);
#endif
    flags = isRecv ? OVS_BUFFER_RECV_BUFFER : OVS_BUFFER_SEND_BUFFER;
    flags |= OVS_BUFFER_NEED_COMPLETE | OVS_BUFFER_PRIVATE_CONTEXT;
    ctx = (POVS_BUFFER_CONTEXT)NET_BUFFER_LIST_CONTEXT_DATA_START(nbl);
    nb = NET_BUFFER_LIST_FIRST_NB(nbl);
    OvsInitNBLContext(ctx, flags, NET_BUFFER_DATA_LENGTH(nb),
                      OVS_DPPORT_NUMBER_INVALID, 0);
    return ctx;
}
POVS_BUFFER_CONTEXT OvsInitExternalNBLContext ( PVOID ovsContext , PNET_BUFFER_LIST nbl , BOOLEAN isRecv ) { NDIS_HANDLE poolHandle ; POVS_SWITCH_CONTEXT context = ( POVS_SWITCH_CONTEXT ) ovsContext ; POVS_BUFFER_CONTEXT ctx ; PNET_BUFFER nb ; NDIS_STATUS status ; UINT16 flags ; poolHandle = NdisGetPoolFromNetBufferList ( nbl ) ; if ( poolHandle == context -> ovsPool . ndisHandle || nbl -> SourceHandle == context -> ovsPool . ndisHandle ) { return ( POVS_BUFFER_CONTEXT ) NET_BUFFER_LIST_CONTEXT_DATA_START ( nbl ) ; } status = NdisAllocateNetBufferListContext ( nbl , sizeof ( OVS_BUFFER_CONTEXT ) , OVS_DEFAULT_NBL_CONTEXT_FILL , OVS_OTHER_POOL_TAG ) ; if ( status != NDIS_STATUS_SUCCESS ) { return NULL ; } #ifdef DBG OvsDumpNBLContext ( nbl ) ; InterlockedIncrement ( ( LONG volatile * ) & context -> ovsPool . sysNBLCount ) ; #endif flags = isRecv ? OVS_BUFFER_RECV_BUFFER : OVS_BUFFER_SEND_BUFFER ; flags |= OVS_BUFFER_NEED_COMPLETE | OVS_BUFFER_PRIVATE_CONTEXT ; ctx = ( POVS_BUFFER_CONTEXT ) NET_BUFFER_LIST_CONTEXT_DATA_START ( nbl ) ; nb = NET_BUFFER_LIST_FIRST_NB ( nbl ) ; OvsInitNBLContext ( ctx , flags , NET_BUFFER_DATA_LENGTH ( nb ) , OVS_DPPORT_NUMBER_INVALID , 0 ) ; return ctx ; }
OvsInitExternalNBLContext
OvsInitExternalNBLContext
/*
     * we use first nb to decide whether we need advance or retreat during
     * complete.
     */