VirtualBox

Changeset 56205 in vbox


Ignore:
Timestamp:
Jun 2, 2015 2:34:47 PM (10 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
100744
Message:

NetLwf: Notify all address changes via all filters, add all addresses at filter instance creation, moved hNotifier from module to filter instance to avoid crashes when NDIS initiates unload (#7661).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostDrivers/VBoxNetFlt/win/ndis6/VBoxNetLwf-win.cpp

    r56201 r56205  
    1818//#define VBOXNETLWF_SYNC_SEND
    1919#define VBOXNETLWF_NO_BYPASS
    20 #define VBOXNETLWF_SUPRESS_REDUNDANT_NOTIFICATIONS
    2120
    2221#include <VBox/version.h>
     
    8180    /** filter module context handle */
    8281    NDIS_HANDLE hModuleCtx;
     82    /** IP address change notifier handle */
     83    HANDLE hNotifier; /* Must be here as hModuleCtx may already be NULL when vboxNetFltOsDeleteInstance is called */
    8384} VBOXNETFLTWIN, *PVBOXNETFLTWIN;
    8485#define VBOXNETFLT_NO_PACKET_QUEUE
     
    191192    /** MAC address of underlying adapter */
    192193    RTMAC MacAddr;
    193     /** Index of underlying adapter */
    194     NET_IFINDEX uIfIndex;
    195     /** IP address change notifier handle */
    196     HANDLE hNotifier;
    197194    /** Saved offload configuration */
    198195    NDIS_OFFLOAD SavedOffloadConfig;
     
    803800    pModuleCtx->pGlobals  = pGlobals;
    804801    pModuleCtx->hFilter   = hFilter;
    805     pModuleCtx->uIfIndex  = pParameters->BaseMiniportIfIndex;
    806     pModuleCtx->hNotifier = NULL;
    807802    vboxNetLwfWinChangeState(pModuleCtx, LwfState_Attaching);
    808803    /* Insert into module chain */
     
    21942189    PVBOXNETLWF_MODULE pModule = (PVBOXNETLWF_MODULE)pThis->u.s.WinIf.hModuleCtx;
    21952190
    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 
    22072191    /* We are only interested in add or remove notifications. */
    22082192    bool fAdded;
     
    22192203        {
    22202204            case AF_INET:
    2221                 Log(("vboxNetLwfWinIpAddrChangeCallback: %s IPv4 addr=%RTnaipv4 on luid=(%u,%u)\n",
     2205                Log((__FUNCTION__": %s IPv4 addr=%RTnaipv4 on luid=(%u,%u)\n",
    22222206                     fAdded ? "add" : "remove", pRow->Address.Ipv4.sin_addr,
    22232207                     pRow->InterfaceLuid.Info.IfType, pRow->InterfaceLuid.Info.NetLuidIndex));
     
    22262210                break;
    22272211            case AF_INET6:
    2228                 Log(("vboxNetLwfWinIpAddrChangeCallback: %s IPv6 addr=%RTnaipv6 luid=(%u,%u)\n",
     2212                Log((__FUNCTION__": %s IPv6 addr=%RTnaipv6 luid=(%u,%u)\n",
    22292213                     fAdded ? "add" : "remove", &pRow->Address.Ipv6.sin6_addr,
    22302214                     pRow->InterfaceLuid.Info.IfType, pRow->InterfaceLuid.Info.NetLuidIndex));
     
    22352219    }
    22362220    else
    2237         Log(("vboxNetLwfWinIpAddrChangeCallback: pRow=%p pfnNotifyHostAddress=%p\n",
     2221        Log((__FUNCTION__": pRow=%p pfnNotifyHostAddress=%p\n",
    22382222             pRow, pThis->pSwitchPort->pfnNotifyHostAddress));
    22392223}
    22402224
    2241 void vboxNetLwfWinRegisterIpAddrNotifier(PVBOXNETFLTINS pThis, PVBOXNETLWF_MODULE pModuleCtx)
     2225void vboxNetLwfWinRegisterIpAddrNotifier(PVBOXNETFLTINS pThis)
    22422226{
    22432227    if (pThis->pSwitchPort && pThis->pSwitchPort->pfnNotifyHostAddress)
    22442228    {
    22452229        NETIO_STATUS Status;
     2230        /* First we need to go over all host IP addresses and add them via pfnNotifyHostAddress. */
     2231        PMIB_UNICASTIPADDRESS_TABLE HostIpAddresses = NULL;
     2232        Status = GetUnicastIpAddressTable(AF_UNSPEC, &HostIpAddresses);
     2233        if (NETIO_SUCCESS(Status))
     2234        {
     2235            for (int i = 0; i < HostIpAddresses->NumEntries; i++)
     2236                vboxNetLwfWinIpAddrChangeCallback(pThis, &HostIpAddresses->Table[i], MibAddInstance);
     2237        }
     2238        else
     2239            Log((__FUNCTION__": GetUnicastIpAddressTable failed with %x\n", Status));
     2240        /* Now we can register a callback function to keep track of address changes. */
    22462241        Status = NotifyUnicastIpAddressChange(AF_UNSPEC, vboxNetLwfWinIpAddrChangeCallback,
    2247                                               pThis, false, &pModuleCtx->hNotifier);
    2248         if (!NETIO_SUCCESS(Status))
    2249             Log(("vboxNetLwfWinRegisterIpAddrNotifier: NotifyUnicastIpAddressChange failed with %x\n", Status));
     2242                                              pThis, false, &pThis->u.s.WinIf.hNotifier);
     2243        if (NETIO_SUCCESS(Status))
     2244            Log((__FUNCTION__": notifier=%p\n", pThis->u.s.WinIf.hNotifier));
    22502245        else
    2251             Log(("vboxNetLwfWinRegisterIpAddrNotifier: notifier=%p\n", pModuleCtx->hNotifier));
     2246            Log((__FUNCTION__": NotifyUnicastIpAddressChange failed with %x\n", Status));
    22522247    }
    22532248    else
    2254         pModuleCtx->hNotifier = NULL;
    2255 }
    2256 
    2257 void vboxNetLwfWinUnregisterIpAddrNotifier(PVBOXNETLWF_MODULE pModuleCtx)
    2258 {
    2259     Log(("vboxNetLwfWinUnregisterIpAddrNotifier: notifier=%p\n", pModuleCtx->hNotifier));
    2260     if (pModuleCtx->hNotifier)
    2261         CancelMibChangeNotify2(pModuleCtx->hNotifier);
     2249        pThis->u.s.WinIf.hNotifier = NULL;
     2250}
     2251
     2252void vboxNetLwfWinUnregisterIpAddrNotifier(PVBOXNETFLTINS pThis)
     2253{
     2254    Log((__FUNCTION__": notifier=%p\n", pThis->u.s.WinIf.hNotifier));
     2255    if (pThis->u.s.WinIf.hNotifier)
     2256        CancelMibChangeNotify2(pThis->u.s.WinIf.hNotifier);
    22622257}
    22632258
     
    22672262    LogFlow(("==>"__FUNCTION__": instance=%p module=%p\n", pThis, pModuleCtx));
    22682263    /* Cancel IP address change notifications */
    2269     vboxNetLwfWinUnregisterIpAddrNotifier(pModuleCtx);
     2264    vboxNetLwfWinUnregisterIpAddrNotifier(pThis);
    22702265    /* Technically it is possible that the module has already been gone by now. */
    22712266    if (pModuleCtx)
     
    23102305            pModuleCtx->pNetFlt = pThis;
    23112306            vboxNetLwfWinReportCapabilities(pThis, pModuleCtx);
    2312             vboxNetLwfWinRegisterIpAddrNotifier(pThis, pModuleCtx);
     2307            vboxNetLwfWinRegisterIpAddrNotifier(pThis);
    23132308            LogFlow(("<=="__FUNCTION__": return 0\n"));
    23142309            return VINF_SUCCESS;
     
    23232318    LogFlow(("==>"__FUNCTION__": instance=%p\n", pThis));
    23242319    pThis->u.s.WinIf.hModuleCtx = 0;
     2320    pThis->u.s.WinIf.hNotifier  = NULL;
    23252321    LogFlow(("<=="__FUNCTION__": return 0\n"));
    23262322    return VINF_SUCCESS;
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette