]> xenbits.xensource.com Git - pvdrivers/win/xenvif.git/commitdiff
Advertise MAC address information in the registry
authorPaul Durrant <paul.durrant@citrix.com>
Thu, 11 Aug 2016 10:03:42 +0000 (11:03 +0100)
committerPaul Durrant <paul.durrant@citrix.com>
Fri, 12 Aug 2016 09:48:34 +0000 (10:48 +0100)
Because XENNET's co-installer is again taking responsibility for messing
with network settings it needs to be able to figure out which VIF instance
corresponds to which emulated device, and the only way it can do that is
by MAC address.

This patch therefore restores the old 'Addresses' subkey under XENVIF's
service key and populates it with REG_SZ values named with PDO names and
containing hex encoded ':' separated MAC address octets.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
src/xenvif/driver.c
src/xenvif/driver.h
src/xenvif/pdo.c

index 66962e0839f0775072087f8c71281b053bdfe877..db17f2e148c2a41c97ef10e504c73debc3b06f27 100644 (file)
@@ -46,6 +46,7 @@
 typedef struct _XENVIF_DRIVER {
     PDRIVER_OBJECT      DriverObject;
     HANDLE              ParametersKey;
+    HANDLE              AddressesKey;
     BOOLEAN             NeedReboot;
 } XENVIF_DRIVER, *PXENVIF_DRIVER;
 
@@ -117,6 +118,30 @@ DriverGetParametersKey(
     return __DriverGetParametersKey();
 }
 
+static FORCEINLINE VOID
+__DriverSetAddressesKey(
+    IN  HANDLE  Key
+    )
+{
+    Driver.AddressesKey = Key;
+}
+
+static FORCEINLINE HANDLE
+__DriverGetAddressesKey(
+    VOID
+    )
+{
+    return Driver.AddressesKey;
+}
+
+HANDLE
+DriverGetAddressesKey(
+    VOID
+    )
+{
+    return __DriverGetAddressesKey();
+}
+
 #define MAXNAMELEN  128
 
 static FORCEINLINE VOID
@@ -214,6 +239,7 @@ DriverUnload(
     IN  PDRIVER_OBJECT  DriverObject
     )
 {
+    HANDLE              AddressesKey;
     HANDLE              ParametersKey;
 
     ASSERT3P(DriverObject, ==, __DriverGetDriverObject());
@@ -222,6 +248,11 @@ DriverUnload(
 
     Driver.NeedReboot = FALSE;
 
+    AddressesKey = __DriverGetAddressesKey();
+    __DriverSetAddressesKey(NULL);
+
+    RegistryCloseKey(AddressesKey);
+
     ParametersKey = __DriverGetParametersKey();
     __DriverSetParametersKey(NULL);
 
@@ -328,6 +359,7 @@ DriverEntry(
 {
     HANDLE              ServiceKey;
     HANDLE              ParametersKey;
+    HANDLE              AddressesKey;
     ULONG               Index;
     NTSTATUS            status;
 
@@ -368,6 +400,15 @@ DriverEntry(
 
     __DriverSetParametersKey(ParametersKey);
 
+    status = RegistryCreateSubKey(ServiceKey,
+                                  "Addresses",
+                                  REG_OPTION_VOLATILE,
+                                  &AddressesKey);
+    if (!NT_SUCCESS(status))
+        goto fail4;
+
+    __DriverSetAddressesKey(AddressesKey);
+
     RegistryCloseKey(ServiceKey);
 
     DriverObject->DriverExtension->AddDevice = AddDevice;
@@ -382,6 +423,13 @@ DriverEntry(
 
     return STATUS_SUCCESS;
 
+fail4:
+    Error("fail4\n");
+
+    __DriverSetParametersKey(NULL);
+
+    RegistryCloseKey(ParametersKey);
+
 fail3:
     Error("fail3\n");
 
index c04558316f2d3bf879c3198ebbd025c9d9d7ac35..b2f1615481dd374d7880c0e55af1ef5faa4bd60e 100644 (file)
@@ -47,6 +47,11 @@ DriverGetParametersKey(
     VOID
     );
 
+extern HANDLE
+DriverGetAddressesKey(
+    VOID
+    );
+
 extern VOID
 DriverRequestReboot(
     VOID
index 3fbf980af039bc5d6761f8ffe818c9ae75bac254..33a75ae424b41aa85f63818bf542635dd52b3eae 100644 (file)
@@ -730,16 +730,30 @@ __PdoSetPermanentAddress(
     IN  PCHAR       Buffer
     )
 {
+    ANSI_STRING     Ansi[2];
     NTSTATUS        status;
 
     status = __PdoParseAddress(Buffer, &Pdo->PermanentAddress);
     if (!NT_SUCCESS(status))
         goto fail1;
 
-    Info("%s: %s\n", __PdoGetName(Pdo), Buffer);
+    RtlZeroMemory(Ansi, sizeof (ANSI_STRING) * 2);
+    RtlInitAnsiString(&Ansi[0], Buffer);
+
+    status = RegistryUpdateSzValue(DriverGetAddressesKey(),
+                                   __PdoGetName(Pdo),
+                                   REG_SZ,
+                                   Ansi);
+    if (!NT_SUCCESS(status))
+        goto fail2;
+
+    Info("%s: %Z\n", __PdoGetName(Pdo), &Ansi[0]);
 
     return STATUS_SUCCESS;
 
+fail2:
+    Error("fail2\n");
+
 fail1:
     Error("fail1 (%08x)\n", status);
 
@@ -762,6 +776,17 @@ PdoGetPermanentAddress(
     return __PdoGetPermanentAddress(Pdo);
 }
 
+static FORCEINLINE VOID
+__PdoClearPermanentAddress(
+    IN  PXENVIF_PDO Pdo
+    )
+{
+    (VOID) RegistryDeleteValue(DriverGetAddressesKey(),
+                               __PdoGetName(Pdo));
+
+    RtlZeroMemory(&Pdo->PermanentAddress, sizeof (ETHERNET_ADDRESS));
+}
+
 static FORCEINLINE NTSTATUS
 __PdoSetSoftwareKey(
     IN  PXENVIF_PDO Pdo
@@ -827,7 +852,7 @@ PdoSetFriendlyName(
 {
     PANSI_STRING    DriverDesc;
     CHAR            Buffer[MAXNAMELEN];
-    ANSI_STRING     FriendlyName[2];
+    ANSI_STRING     Ansi[2];
     NTSTATUS        status;
 
     status = RegistryQuerySzValue(__PdoGetSoftwareKey(Pdo),
@@ -846,17 +871,17 @@ PdoSetFriendlyName(
     if (!NT_SUCCESS(status))
         goto fail2;
 
-    RtlZeroMemory(FriendlyName, sizeof (ANSI_STRING) * 2);
-    RtlInitAnsiString(&FriendlyName[0], Buffer);
+    RtlZeroMemory(Ansi, sizeof (ANSI_STRING) * 2);
+    RtlInitAnsiString(&Ansi[0], Buffer);
 
     status = RegistryUpdateSzValue(__PdoGetHardwareKey(Pdo),
                                    "FriendlyName",
                                    REG_SZ,
-                                   FriendlyName);
+                                   Ansi);
     if (!NT_SUCCESS(status))
         goto fail3;
 
-    Info("%Z\n", &FriendlyName[0]);
+    Info("%s: %Z\n", __PdoGetName(Pdo), &Ansi[0]);
 
     RegistryFreeSzValue(DriverDesc);
 
@@ -2734,7 +2759,7 @@ fail7:
 fail6:
     Error("fail6\n");
 
-    RtlZeroMemory(&Pdo->PermanentAddress, sizeof (ETHERNET_ADDRESS));
+    __PdoClearPermanentAddress(Pdo);
 
 fail5:
     Error("fail5\n");
@@ -2817,7 +2842,7 @@ PdoDestroy(
     RtlFreeUnicodeString(&Pdo->ContainerID);
     RtlZeroMemory(&Pdo->ContainerID, sizeof (UNICODE_STRING));
 
-    RtlZeroMemory(&Pdo->PermanentAddress, sizeof (ETHERNET_ADDRESS));
+    __PdoClearPermanentAddress(Pdo);
 
     ThreadAlert(Pdo->DevicePowerThread);
     ThreadJoin(Pdo->DevicePowerThread);