Share via


Actualizar una ruta local mediante RtmUpdateAndUnlockRoute

En el procedimiento siguiente se describen los pasos que se usan para actualizar una ruta en contexto. El código de ejemplo siguiente muestra cómo implementar el procedimiento.

Para actualizar una ruta en contexto, el cliente debe realizar los pasos siguientes.

  1. Bloquee la ruta mediante una llamada a RtmLockRoute. Actualmente, esta función bloquea realmente el destino de la ruta. El administrador de tablas de enrutamiento devuelve un puntero a la ruta.

  2. Use el puntero a la estructura RTM_ROUTE_INFO del administrador de tablas de enrutamiento, obtenida en el paso 1, para realizar los cambios necesarios en la ruta. Solo se pueden modificar determinados miembros de la estructura RTM_ROUTE_INFO al actualizarse en su lugar. Estos miembros son: Neighbor, PrefInfo, EntitySpecificInfo, BelongsToViews y NextHopsList.

    Nota

    Si el cliente agrega información a los miembros Vecino o NextHopsList , el cliente debe llamar a RtmReferenceHandles para incrementar explícitamente el recuento de referencias que el administrador de tablas de enrutamiento mantiene en el objeto de próximo salto. Del mismo modo, si el cliente quita información del miembro NextHopsList , el cliente debe llamar a RtmReleaseNextHops para disminuir el recuento de referencias.

     

  3. Llame a RtmUpdateAndUnlockRoute para notificar al administrador de tablas de enrutamiento que ha tenido lugar un cambio. El administrador de tablas de enrutamiento confirma los cambios, actualiza el destino para reflejar la nueva información y, a continuación, desbloquea la ruta.

En el código de ejemplo siguiente se muestra cómo actualizar una ruta directamente mediante un puntero a la información de ruta real de la tabla de enrutamiento.

Status = RtmLockRoute(RtmRegHandle,
                      RouteHandle,
                      TRUE,
                      TRUE,
                      &RoutePointer);

if (Status == NO_ERROR)
{
        // Update route parameters in place (i.e., directly on 
// the routing table manager's copy)
    
    // Update the metric and views of the route
    RoutePointer->PrefInfo.Metric = 16;

    // Change the views so that the route belongs to only the multicast view
    RoutePointer->BelongsToViews = RTM_VIEW_MASK_MCAST;

    // Set the entity-specific information to X
    RoutePointer->EntitySpecificInfo = X;

    // Note that the following manipulation of
    // next-hop references is not needed when
    // using RtmAddRouteToDest, as it is done
    // by the routing table manager automatically
    
    // Change next hop from NextHop1 to NextHop2
    NextHop1 = RoutePointer->NextHopsList.NextHop[0];

    // Explicitly dereference the old next hop
    RtmReleaseNextHops(RtmRegHandle, 1, &NextHop1);

    RoutePointer->NextHopsList.NextHop[0] = NextHop2;

    // Explicitly reference next hop being added
    RtmReferenceHandles(RtmRegHandle, 1, &NextHop2);

    // Call the routing table manager to indicate that route information
    // has changed, and that its position might
    // have to be rearranged and the corresponding destination
    // needs to be updated to reflect this change.
    
    Status = RtmUpdateAndUnlockRoute(RtmRegHandle,
                                     RouteHandle,
                                     INFINITE, // Keep forever
                                     NULL,
                                     0,
                                     NULL,
                                     &ChangeFlags);
    ASSERT(Status == NO_ERROR);
}