大网数据广告活动
网络与域名解析

Update a Route In Place Using RtmUpdateAndUnlockRoute

· 52CE 我爱测

The following procedure outlines the steps used to update a route in place. The sample code that follows shows how to implement the procedure.

The following procedure outlines the steps used to update a route in place. The sample code that follows shows how to implement the procedure.

To update a route in place, the client should take the following steps

  1. Lock the route by calling RtmLockRoute. Currently, this function actually locks the route's destination. The routing table manager returns a pointer to the route.

  2. Use the pointer to the routing table manager's RTM_ROUTE_INFO structure, obtained in step 1, to make the necessary changes to the route. Only certain members of the RTM_ROUTE_INFO structure can be modified when updating in place. These members are: Neighbour, PrefInfo, EntitySpecificInfo, BelongsToViews, and NextHopsList.

    [!Note]
    If the client adds information to either the Neighbour or NextHopsList members, the client must call RtmReferenceHandles to explicitly increment the reference count that the routing table manager keeps on the next-hop object. Similarly, if the client removes information from the NextHopsList member, the client must call RtmReleaseNextHops to decrement the reference count.

  3. Call RtmUpdateAndUnlockRoute to notify the routing table manager that a change has taken place. The routing table manager commits the changes, updates the destination to reflect the new information, and then unlocks the route.

The following sample code shows how to update a route directly, using a pointer to the actual route information in the routing table.

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);
}

Source: Microsoft Learn / Windows Win32 documentation by Microsoft and contributors. Documentation licensed CC BY 4.0. Code samples are covered by the MIT License. Converted from Markdown, with links normalized and embedded media omitted.

资料来源与适用范围

资料来源
Microsoft Learn / Windows Win32 documentation
适用范围
Windows Win32 API · Source date 05/31/2018
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 4.0 (documentation), MIT (code samples)

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。