[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[win-pv-devel] [PATCH 7/8] Stop synthesizing the NET_LUID



From Windows 10 the lifetime of the registry keys used to synthesize the
PDO's NET_LUID has changed. Instead of using a synthesized NET_LUID, look it
up in the MIB interface table (keyed by the permanent physical address)

Signed-off-by: Paul Durrant <paul.durrant@xxxxxxxxxx>
---
 src/xenvif/frontend.c | 101 ++++++++++++++++++++++++++++++++++++++++----------
 src/xenvif/pdo.c      |  91 ++++++++++-----------------------------------
 src/xenvif/pdo.h      |   5 ---
 3 files changed, 102 insertions(+), 95 deletions(-)

diff --git a/src/xenvif/frontend.c b/src/xenvif/frontend.c
index 9f032c3..aea907d 100644
--- a/src/xenvif/frontend.c
+++ b/src/xenvif/frontend.c
@@ -455,6 +455,37 @@ fail1:
 }
 
 static NTSTATUS
+FrontendGetLuid(
+    IN  PXENVIF_FRONTEND    Frontend,
+    IN  PMIB_IF_TABLE2      Table,
+    OUT PNET_LUID           Luid
+    )
+{
+    ETHERNET_ADDRESS        PermanentPhysicalAddress;
+    ULONG                   Index;
+    PMIB_IF_ROW2            Row;
+
+    MacQueryPermanentAddress(__FrontendGetMac(Frontend),
+                             &PermanentPhysicalAddress);
+
+    for (Index = 0; Index < Table->NumEntries; Index++) {
+        Row = &Table->Table[Index];
+
+        if (memcmp(Row->PermanentPhysicalAddress,
+                   &PermanentPhysicalAddress,
+                   sizeof (ETHERNET_ADDRESS)) == 0)
+            goto found;
+    }
+
+    return STATUS_UNSUCCESSFUL;
+
+found:
+    *Luid = Row->InterfaceLuid;
+
+    return STATUS_SUCCESS;
+}
+
+static NTSTATUS
 FrontendInsertAddress(
     IN OUT  PSOCKADDR_INET      *AddressTable,
     IN      const SOCKADDR_INET *Address,
@@ -511,22 +542,22 @@ fail1:
 static NTSTATUS
 FrontendProcessAddressTable(
     IN  PXENVIF_FRONTEND            Frontend,
-    IN  PMIB_UNICASTIPADDRESS_TABLE MibTable,
+    IN  PMIB_UNICASTIPADDRESS_TABLE Table,
+    IN  PNET_LUID                   Luid,
     OUT PSOCKADDR_INET              *AddressTable,
     OUT PULONG                      AddressCount
     )
 {
-    PNET_LUID                       Luid;
     ULONG                           Index;
     NTSTATUS                        status;
 
+    UNREFERENCED_PARAMETER(Frontend);
+
     *AddressTable = NULL;
     *AddressCount = 0;
 
-    Luid = PdoGetLuid(__FrontendGetPdo(Frontend));
-
-    for (Index = 0; Index < MibTable->NumEntries; Index++) {
-        PMIB_UNICASTIPADDRESS_ROW   Row = &MibTable->Table[Index];
+    for (Index = 0; Index < Table->NumEntries; Index++) {
+        PMIB_UNICASTIPADDRESS_ROW   Row = &Table->Table[Index];
 
         if (Row->InterfaceLuid.Info.IfType != Luid->Info.IfType)
             continue;
@@ -717,6 +748,7 @@ FrontendMib(
 {
     PXENVIF_FRONTEND    Frontend = Context;
     PKEVENT             Event;
+    NTSTATUS            (*__GetIfTable2)(PMIB_IF_TABLE2 *);
     NTSTATUS            (*__NotifyUnicastIpAddressChange)(ADDRESS_FAMILY,
                                                           
PUNICAST_IPADDRESS_CHANGE_CALLBACK,
                                                           PVOID,    
@@ -733,28 +765,34 @@ FrontendMib(
     Trace("====>\n");
 
     status = LinkGetRoutineAddress("netio.sys",
+                                   "GetIfTable2",
+                                   (PVOID *)&__GetIfTable2);
+    if (!NT_SUCCESS(status))
+        goto fail1;
+
+    status = LinkGetRoutineAddress("netio.sys",
                                    "NotifyUnicastIpAddressChange",
                                    (PVOID *)&__NotifyUnicastIpAddressChange);
     if (!NT_SUCCESS(status))
-        goto fail1;
+        goto fail2;
 
     status = LinkGetRoutineAddress("netio.sys",
                                    "GetUnicastIpAddressTable",
                                    (PVOID *)&__GetUnicastIpAddressTable);
     if (!NT_SUCCESS(status))
-        goto fail2;
+        goto fail3;
 
     status = LinkGetRoutineAddress("netio.sys",
                                    "FreeMibTable",
                                    (PVOID *)&__FreeMibTable);
     if (!NT_SUCCESS(status))
-        goto fail3;
+        goto fail4;
 
     status = LinkGetRoutineAddress("netio.sys",
                                    "CancelMibChangeNotify2",
                                    (PVOID *)&__CancelMibChangeNotify2);
     if (!NT_SUCCESS(status))
-        goto fail4;
+        goto fail5;
 
     status = __NotifyUnicastIpAddressChange(AF_UNSPEC,
                                             FrontendIpAddressChange,
@@ -762,12 +800,14 @@ FrontendMib(
                                             TRUE,
                                             &Handle);
     if (!NT_SUCCESS(status))
-        goto fail5;
+        goto fail6;
 
     Event = ThreadGetEvent(Self);
 
     for (;;) { 
-        PMIB_UNICASTIPADDRESS_TABLE MibTable;
+        PMIB_IF_TABLE2              IfTable;
+        NET_LUID                    Luid;
+        PMIB_UNICASTIPADDRESS_TABLE UnicastIpAddressTable;
         KIRQL                       Irql;
         PSOCKADDR_INET              AddressTable;
         ULONG                       AddressCount;
@@ -782,23 +822,38 @@ FrontendMib(
         if (ThreadIsAlerted(Self))
             break;
 
-        status = __GetUnicastIpAddressTable(AF_UNSPEC, &MibTable);
+        IfTable = NULL;
+        UnicastIpAddressTable = NULL;
+
+        status = __GetIfTable2(&IfTable);
         if (!NT_SUCCESS(status))
-            continue;
+            goto loop;
+
+        status = FrontendGetLuid(Frontend,
+                                 IfTable,
+                                 &Luid);
+        if (!NT_SUCCESS(status))
+            goto loop;
+
+        status = __GetUnicastIpAddressTable(AF_UNSPEC,
+                                            &UnicastIpAddressTable);
+        if (!NT_SUCCESS(status))
+            goto loop;
 
         KeAcquireSpinLock(&Frontend->Lock, &Irql);
 
         // It is not safe to use interfaces before this point
         if (Frontend->State != FRONTEND_CONNECTED &&
             Frontend->State != FRONTEND_ENABLED)
-            goto loop;
+            goto unlock;
 
         status = FrontendProcessAddressTable(Frontend,
-                                             MibTable,
+                                             UnicastIpAddressTable,
+                                             &Luid,
                                              &AddressTable,
                                              &AddressCount);
         if (!NT_SUCCESS(status))
-            goto loop;
+            goto unlock;
 
         TransmitterUpdateAddressTable(__FrontendGetTransmitter(Frontend),
                                       AddressTable,
@@ -811,10 +866,15 @@ FrontendMib(
         if (AddressCount != 0)
             __FrontendFree(AddressTable);
 
-loop:
+unlock:
         KeReleaseSpinLock(&Frontend->Lock, Irql);
 
-        __FreeMibTable(MibTable);
+loop:
+        if (UnicastIpAddressTable != NULL)
+            __FreeMibTable(UnicastIpAddressTable);
+
+        if (IfTable != NULL)
+            __FreeMibTable(IfTable);
     }
 
     status = __CancelMibChangeNotify2(Handle);
@@ -824,6 +884,9 @@ loop:
 
     return STATUS_SUCCESS;
 
+fail6:
+    Error("fail6\n");
+
 fail5:
     Error("fail5\n");
 
diff --git a/src/xenvif/pdo.c b/src/xenvif/pdo.c
index 9e3003e..140b618 100644
--- a/src/xenvif/pdo.c
+++ b/src/xenvif/pdo.c
@@ -681,56 +681,6 @@ PdoGetVifContext(
 }
 
 static FORCEINLINE NTSTATUS
-__PdoSetLuid(
-    IN  PXENVIF_PDO Pdo,
-    IN  HANDLE      Key
-    )
-{
-    ULONG           IfType;
-    ULONG           NetLuidIndex;
-    NTSTATUS        status;
-
-    status = RegistryQueryDwordValue(Key, "*IfType", &IfType);
-    if (!NT_SUCCESS(status))
-        goto fail1;
-
-    status = RegistryQueryDwordValue(Key, "NetLuidIndex", &NetLuidIndex);
-    if (!NT_SUCCESS(status))
-        goto fail2;
-
-    Pdo->Luid.Info.IfType = IfType;
-    Pdo->Luid.Info.NetLuidIndex = NetLuidIndex;
-
-    Info("%s: %016llX\n", __PdoGetName(Pdo), Pdo->Luid.Value);
-
-    return STATUS_SUCCESS;
-
-fail2:
-    Error("fail2\n");
-
-fail1:
-    Error("fail1 (%08x)\n", status);
-
-    return status;
-}
-
-static FORCEINLINE PNET_LUID
-__PdoGetLuid(
-    IN  PXENVIF_PDO Pdo
-    )
-{
-    return &Pdo->Luid;
-}
-
-PNET_LUID
-PdoGetLuid(
-    IN  PXENVIF_PDO Pdo
-    )
-{
-    return __PdoGetLuid(Pdo);
-}
-
-static FORCEINLINE NTSTATUS
 __PdoParseAddress(
     IN  PCHAR               Buffer,
     OUT PETHERNET_ADDRESS   Address
@@ -813,12 +763,20 @@ fail1:
     return status;
 }
 
+static FORCEINLINE PETHERNET_ADDRESS
+__PdoGetPermanentAddress(
+    IN  PXENVIF_PDO Pdo
+    )
+{
+    return &Pdo->PermanentAddress;
+}
+
 PETHERNET_ADDRESS
 PdoGetPermanentAddress(
     IN  PXENVIF_PDO Pdo
     )
 {
-    return &Pdo->PermanentAddress;
+    return __PdoGetPermanentAddress(Pdo);
 }
 
 static FORCEINLINE NTSTATUS
@@ -1141,25 +1099,21 @@ PdoStartDevice(
     if (!NT_SUCCESS(status))
         goto fail3;
 
-    status = __PdoSetLuid(Pdo, Key);
-    if (!NT_SUCCESS(status))
-        goto fail4;
-
     status = LinkGetRoutineAddress("netio.sys",
                                    "GetIfTable2",
                                    (PVOID *)&__GetIfTable2);
     if (!NT_SUCCESS(status))
-        goto fail5;
+        goto fail4;
 
     status = LinkGetRoutineAddress("netio.sys",
                                    "FreeMibTable",
                                    (PVOID *)&__FreeMibTable);
     if (!NT_SUCCESS(status))
-        goto fail6;
+        goto fail5;
 
     status = __GetIfTable2(&Table);
     if (!NT_SUCCESS(status))
-        goto fail7;
+        goto fail6;
 
     for (Index = 0; Index < Table->NumEntries; Index++) {
         PMIB_IF_ROW2    Row = &Table->Table[Index];
@@ -1175,17 +1129,17 @@ PdoStartDevice(
             continue;
 
         status = STATUS_UNSUCCESSFUL;
-        if (memcmp(Row->PhysicalAddress,
-                   &Pdo->PermanentAddress,
+        if (memcmp(Row->PermanentPhysicalAddress,
+                   __PdoGetPermanentAddress(Pdo),
                    sizeof (ETHERNET_ADDRESS)) == 0)
-            goto fail8;
+            goto fail7;
     }
 
     StackLocation = IoGetCurrentIrpStackLocation(Irp);
 
     status = PdoD3ToD0(Pdo);
     if (!NT_SUCCESS(status))
-        goto fail9;
+        goto fail8;
 
     __PdoSetDevicePnpState(Pdo, Started);
 
@@ -1198,29 +1152,24 @@ PdoStartDevice(
 
     return STATUS_SUCCESS;
 
-fail9:
-    Error("fail9\n");
-
-    __FreeMibTable(Table);
-    goto fail6;
-
 fail8:
     Error("fail8\n");
 
-    DriverRequestReboot();
     __FreeMibTable(Table);
+    goto fail6;
 
 fail7:
     Error("fail7\n");
 
+    DriverRequestReboot();
+    __FreeMibTable(Table);
+
 fail6:
     Error("fail6\n");
 
 fail5:
     Error("fail5\n");
 
-    RtlZeroMemory(&Pdo->Luid, sizeof (NET_LUID));
-
 fail4:
     Error("fail4\n");
 
diff --git a/src/xenvif/pdo.h b/src/xenvif/pdo.h
index be05125..7066aaf 100644
--- a/src/xenvif/pdo.h
+++ b/src/xenvif/pdo.h
@@ -127,11 +127,6 @@ PdoGetBusData(
     IN  ULONG           Length
     );
 
-extern PNET_LUID
-PdoGetLuid(
-    IN  PXENVIF_PDO Pdo
-    );
-
 extern PETHERNET_ADDRESS
 PdoGetPermanentAddress(
     IN  PXENVIF_PDO Pdo
-- 
2.1.1


_______________________________________________
win-pv-devel mailing list
win-pv-devel@xxxxxxxxxxxxxxxxxxxx
http://lists.xenproject.org/cgi-bin/mailman/listinfo/win-pv-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.