VirtualBox

Changeset 56201 in vbox


Ignore:
Timestamp:
Jun 2, 2015 10:54:24 AM (10 years ago)
Author:
vboxsync
Message:

NetLwf: Notifications for host address changes on Windows (NDIS6 only, #7661).

Location:
trunk/src/VBox/HostDrivers/VBoxNetFlt
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostDrivers/VBoxNetFlt/Makefile.kmk

    r55656 r56201  
    178178        $(PATH_SDK_$(VBOX_WINDDK_WLH)_LIB)/hal.lib \
    179179        $(PATH_SDK_$(VBOX_WINDDK_WLH)_LIB)/ndis.lib \
     180        $(PATH_SDK_$(VBOX_WINDDK_WLH)_LIB)/netio.lib \
    180181        $(PATH_STAGE_LIB)/RuntimeR0Drv$(VBOX_SUFF_LIB)
    181182 VBoxNetLwf_LIBS = \
  • trunk/src/VBox/HostDrivers/VBoxNetFlt/win/ndis6/VBoxNetLwf-win.cpp

    r55207 r56201  
    1818//#define VBOXNETLWF_SYNC_SEND
    1919#define VBOXNETLWF_NO_BYPASS
     20#define VBOXNETLWF_SUPRESS_REDUNDANT_NOTIFICATIONS
    2021
    2122#include <VBox/version.h>
     
    5960#  undef  _interlockedbittestandreset64
    6061#  include <ndis.h>
     62#  include <netioapi.h>
    6163#else
    62 //#  include <ntddk.h>
     64#  include <ntddk.h>
     65#  include <netioapi.h>
    6366/* can include ndis.h right away */
    6467#  include <ndis.h>
     
    188191    /** MAC address of underlying adapter */
    189192    RTMAC MacAddr;
     193    /** Index of underlying adapter */
     194    NET_IFINDEX uIfIndex;
     195    /** IP address change notifier handle */
     196    HANDLE hNotifier;
    190197    /** Saved offload configuration */
    191198    NDIS_OFFLOAD SavedOffloadConfig;
     
    794801    }
    795802
    796     pModuleCtx->pGlobals = pGlobals;
    797     pModuleCtx->hFilter  = hFilter;
     803    pModuleCtx->pGlobals  = pGlobals;
     804    pModuleCtx->hFilter   = hFilter;
     805    pModuleCtx->uIfIndex  = pParameters->BaseMiniportIfIndex;
     806    pModuleCtx->hNotifier = NULL;
    798807    vboxNetLwfWinChangeState(pModuleCtx, LwfState_Attaching);
    799808    /* Insert into module chain */
     
    21782187}
    21792188
     2189static void vboxNetLwfWinIpAddrChangeCallback(IN PVOID pvCtx,
     2190                                              IN PMIB_UNICASTIPADDRESS_ROW pRow,
     2191                                              IN MIB_NOTIFICATION_TYPE enmNotifType)
     2192{
     2193    PVBOXNETFLTINS pThis = (PVBOXNETFLTINS)pvCtx;
     2194    PVBOXNETLWF_MODULE pModule = (PVBOXNETLWF_MODULE)pThis->u.s.WinIf.hModuleCtx;
     2195
     2196#ifdef VBOXNETLWF_SUPRESS_REDUNDANT_NOTIFICATIONS
     2197    /* Ignore notifications on the interfaces we are not attached to. */
     2198    if (pRow && pModule->uIfIndex != pRow->InterfaceIndex)
     2199    {
     2200        Log((__FUNCTION__ ": ignoring notification for luid %d-%d, index %d\n",
     2201             pRow->InterfaceLuid.Info.IfType, pRow->InterfaceLuid.Info.NetLuidIndex,
     2202             pRow->InterfaceIndex));
     2203        return;
     2204    }
     2205#endif /* VBOXNETLWF_SUPRESS_REDUNDANT_NOTIFICATIONS */
     2206
     2207    /* We are only interested in add or remove notifications. */
     2208    bool fAdded;
     2209    if (enmNotifType == MibAddInstance)
     2210        fAdded = true;
     2211    else if (enmNotifType == MibDeleteInstance)
     2212        fAdded = false;
     2213    else
     2214        return;
     2215
     2216    if (pRow && pThis->pSwitchPort->pfnNotifyHostAddress)
     2217    {
     2218        switch (pRow->Address.si_family)
     2219        {
     2220            case AF_INET:
     2221                Log(("vboxNetLwfWinIpAddrChangeCallback: %s IPv4 addr=%RTnaipv4 on luid=(%u,%u)\n",
     2222                     fAdded ? "add" : "remove", pRow->Address.Ipv4.sin_addr,
     2223                     pRow->InterfaceLuid.Info.IfType, pRow->InterfaceLuid.Info.NetLuidIndex));
     2224                pThis->pSwitchPort->pfnNotifyHostAddress(pThis->pSwitchPort, fAdded, kIntNetAddrType_IPv4,
     2225                                                         &pRow->Address.Ipv4.sin_addr);
     2226                break;
     2227            case AF_INET6:
     2228                Log(("vboxNetLwfWinIpAddrChangeCallback: %s IPv6 addr=%RTnaipv6 luid=(%u,%u)\n",
     2229                     fAdded ? "add" : "remove", &pRow->Address.Ipv6.sin6_addr,
     2230                     pRow->InterfaceLuid.Info.IfType, pRow->InterfaceLuid.Info.NetLuidIndex));
     2231                pThis->pSwitchPort->pfnNotifyHostAddress(pThis->pSwitchPort, fAdded, kIntNetAddrType_IPv6,
     2232                                                         &pRow->Address.Ipv6.sin6_addr);
     2233                break;
     2234        }
     2235    }
     2236    else
     2237        Log(("vboxNetLwfWinIpAddrChangeCallback: pRow=%p pfnNotifyHostAddress=%p\n",
     2238             pRow, pThis->pSwitchPort->pfnNotifyHostAddress));
     2239}
     2240
     2241void vboxNetLwfWinRegisterIpAddrNotifier(PVBOXNETFLTINS pThis, PVBOXNETLWF_MODULE pModuleCtx)
     2242{
     2243    if (pThis->pSwitchPort && pThis->pSwitchPort->pfnNotifyHostAddress)
     2244    {
     2245        NETIO_STATUS Status;
     2246        Status = NotifyUnicastIpAddressChange(AF_UNSPEC, vboxNetLwfWinIpAddrChangeCallback,
     2247                                              pThis, false, &pModuleCtx->hNotifier);
     2248        if (!NETIO_SUCCESS(Status))
     2249            Log(("vboxNetLwfWinRegisterIpAddrNotifier: NotifyUnicastIpAddressChange failed with %x\n", Status));
     2250        else
     2251            Log(("vboxNetLwfWinRegisterIpAddrNotifier: notifier=%p\n", pModuleCtx->hNotifier));
     2252    }
     2253    else
     2254        pModuleCtx->hNotifier = NULL;
     2255}
     2256
     2257void vboxNetLwfWinUnregisterIpAddrNotifier(PVBOXNETLWF_MODULE pModuleCtx)
     2258{
     2259    Log(("vboxNetLwfWinUnregisterIpAddrNotifier: notifier=%p\n", pModuleCtx->hNotifier));
     2260    if (pModuleCtx->hNotifier)
     2261        CancelMibChangeNotify2(pModuleCtx->hNotifier);
     2262}
     2263
    21802264void vboxNetFltOsDeleteInstance(PVBOXNETFLTINS pThis)
    21812265{
    21822266    PVBOXNETLWF_MODULE pModuleCtx = (PVBOXNETLWF_MODULE)pThis->u.s.WinIf.hModuleCtx;
    21832267    LogFlow(("==>"__FUNCTION__": instance=%p module=%p\n", pThis, pModuleCtx));
     2268    /* Cancel IP address change notifications */
     2269    vboxNetLwfWinUnregisterIpAddrNotifier(pModuleCtx);
    21842270    /* Technically it is possible that the module has already been gone by now. */
    21852271    if (pModuleCtx)
     
    22242310            pModuleCtx->pNetFlt = pThis;
    22252311            vboxNetLwfWinReportCapabilities(pThis, pModuleCtx);
     2312            vboxNetLwfWinRegisterIpAddrNotifier(pThis, pModuleCtx);
    22262313            LogFlow(("<=="__FUNCTION__": return 0\n"));
    22272314            return VINF_SUCCESS;
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