EnableInterface Sample

[This is preliminary documentation and subject to change.]

DWORD
APIENTRY
EnableInterface(
    IN DWORD dwIndex
    )
/*++
  Routine Description
      An interface comes up in a DISABLED state. This function is
      called by the router manager to enable the interface.  It can also
      be called when the interface is being reenabled after being
      disabled by the admin. The bindings on an interface are kept
      across and Enable-Disable, so we heck to see if we were already
      bound, and if so we activate the protocol over the bindings.

  Arguments
      dwIndex   Interface to be enabled

  Return Value
      NO_ERROR

--*/
{
    PNT_IF      pIf;
    PLIST_ENTRY pleNode;
    PINTRNL_IF  pBind;
    DWORD       dwResult;
    
    
    EnterProtocolApi();

    TraceEnter("EnableInterface");
    
    EnterCriticalSection(&g_csIfListLock);

    pIf = GetIfBlockGivenIndex(dwIndex);

    if(pIf == NULL)
    {
        LeaveCriticalSection(&g_csIfListLock);
        
        Trace1(ERR,
               "EnableInterface: Interface %d does not exist",
               dwIndex);

        TraceLeave("EnableInterface");

        ExitProtocolApi();

        return ERROR_INVALID_PARAMETER;
    }

    if(IsNtEnabled(pIf))
    {
        //
        // Nothing new happening
        //
        
        Trace1(INTF,
               "EnableInterface: Enable received for %S which is already enabled",
               pIf->pwszIfName);

        LeaveCriticalSection(&g_csIfListLock);
        
        TraceLeave("EnableInterface");

        ExitProtocolApi();

        return NO_ERROR;
    }
    
    SetNtEnabled(pIf);

    if(IsNtBound(pIf))
    {
        //
        // Since it is enabled and bound, activate the bindings
        //
        
        for(pleNode  = pIf->leInternalIfHead.Flink;
            pleNode != &pIf->leInternalIfHead;
            pleNode  = pleNode->Flink)
        {
            pBind = CONTAINING_RECORD(pleNode, INTRNL_IF, leInternalIfLink);

            ASSERT(pBind->dwState == BINDING_DOWN);
            
            if(pBind->bEnabled)
            {
                dwResult = ActivateBinding(pBind);
                
                if(dwResult != NO_ERROR)
                {
                    Trace2(ERR,
                           "EnableInterface: Unable to activate %d.%d.%d.%d over %S",
                           PRINT_ADDRESS(pBind->dwAddress),
                           pIf->pwszIfName);
                }
            }
        }
    }

    LeaveCriticalSection(&g_csIfListLock);
        
    TraceLeave("EnableInterface");
    
    ExitProtocolApi();
    
    return NO_ERROR;
}