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

[PATCH 1/2] Store the current network IDs before upgrade


  • To: <win-pv-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Owen Smith <owen.smith@xxxxxxxxxx>
  • Date: Mon, 26 Sep 2022 10:55:25 +0100
  • Authentication-results: esa4.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none
  • Cc: Owen Smith <owen.smith@xxxxxxxxxx>
  • Delivery-date: Mon, 26 Sep 2022 09:55:48 +0000
  • Ironport-data: A9a23:I5G8sKx7HO5P6tUH0SN6t+doxirEfRIJ4+MujC+fZmUNrF6WrkVWz WcaWGjQafvYMGH8KN11bo+zoBwBvMLTytJiSAY+/yAxQypGp/SeCIXCJC8cHc8zwu4v7q5Dx 59DAjUVBJlsFhcwnj/0bv676yEUOZigHtLUEPTDNj16WThqQSIgjQMLs+Mii8tjjMPR7zml4 LsemOWCfg7+s9JIGjhMsfjb+Uky5K6aVA4w5TTSW9ga5DcyqFFNZH4vDfnZB2f1RIBSAtm7S 47rpF1u1jqEl/uFIorNfofTKiXmcJaLVeS9oiM+t5yZqgpDvkQPPpMTb5LwX6v1ZwKhxLidw P0V3XC5pJxA0qfkwIzxWDEAe81y0DEvFBYq7hFTvOTKp3AqfUcAzN1DXEcdI6cR691RQlxi1 +YiGDEvQQyq0rfeLLKTEoGAh+wmJcjveogepmth3XfSCvNOrZLrGvuQo4UChXFp254ITa22i 8kxMFKDaDzHfBBJfEwSCY4+tOypmmP+Y3tTr1f9Sa8fszODkVUogOWF3Nz9S8K0Q5VzhHSh+ Fntx3++BxRDGISlxm/Qmp6rrrCWxn6qMG4IL5Wn9/gvmEPWymENBRk+UVqgveL/mkO4Q8hYK UEf5mwpt6dayaCwZoCjBVvi+ifC50NCHYoLewEn1O2T4oeE5S2HLGEVdRgCVfAErvUGRB4Fy nbcyrsFGgdTmLGSTHuc8JKdojWzJTUZIAc+WMMUcecWy4K9+d9u13ojWv4mSffo1YOtRVkc1 hjQ9EADa6MvYdnnPklR1XTOmHqSq5fAVWbZDS2HDzv+vmuViGNIDrFECGQ3D94adu51rXHb5 hDofvRyC8hQZaxhbATXHI0w8EiBvp5pygH0j191BIUG/D+w4XOldo04yGggehswaZ5VIW6yO RO7VeZtCHh7bROXgVJfOdrtW6zGM4C5fTgaahwkRoUXOcUgHON21CpveVSRzwjQraTYqolmY M/zTCpZJSxFYUiR5GbpGrx1PH5C7nxW+F4/sriglkr6gefBPiTNIVrHWXPXBt0EAGq/iF292 75i2wGikX2zjMWWjvHrzLMu
  • Ironport-hdrordr: A9a23:UZbFnKNE9thCVsBcTs2jsMiBIKoaSvp037Eqv3oedfUzSL39qy nOpoV86faaslYssR0b9exoW5PwJE80l6QFgrX5VI3KNGKN1VdARLsSircKqAeAJ8SRzIFgPN 9bAspDNOE=
  • List-id: Developer list for the Windows PV Drivers subproject <win-pv-devel.lists.xenproject.org>

Write the current NetCfgInstanceId and NetLuid to a store location during
the install preprocess step, so that XenVif can restore settings if the
network IDs are changed.
Write NetLuid and NetCfgInstanceId to XenVif's Settings key for this VIF index

Signed-off-by: Owen Smith <owen.smith@xxxxxxxxxx>
---
 src/coinst/coinst.c | 343 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 343 insertions(+)

diff --git a/src/coinst/coinst.c b/src/coinst/coinst.c
index e749506..489e600 100644
--- a/src/coinst/coinst.c
+++ b/src/coinst/coinst.c
@@ -36,6 +36,7 @@
 #include <strsafe.h>
 #include <malloc.h>
 #include <assert.h>
+#include <iphlpapi.h>
 
 #include <version.h>
 #include <revision.h>
@@ -56,6 +57,9 @@ __user_code;
 #define UNPLUG_KEY \
         SERVICE_KEY(XEN) ## "\\Unplug"
 
+#define SETTINGS_KEY \
+        SERVICE_KEY(XENVIF) ## "\\Settings"
+
 #define CONTROL_KEY "SYSTEM\\CurrentControlSet\\Control"
 
 #define CLASS_KEY   \
@@ -63,6 +67,9 @@ __user_code;
 
 #define ENUM_KEY    "SYSTEM\\CurrentControlSet\\Enum"
 
+#define NETWORK_CLASS_GUID \
+        "{4d36e972-e325-11ce-bfc1-08002be10318}"
+
 static VOID
 #pragma prefast(suppress:6262) // Function uses '1036' bytes of stack: exceeds 
/analyze:stacksize'1024'
 __Log(
@@ -1025,6 +1032,335 @@ fail1:
     return FALSE;
 }
 
+static BOOLEAN
+CreateSettingsKey(
+    IN  PTCHAR  KeyName,
+    OUT PHKEY   Key
+    )
+{
+    HKEY        SettingsKey;
+    HRESULT     Error;
+
+    Error = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
+                         SETTINGS_KEY,
+                         0,
+                         KEY_ALL_ACCESS,
+                         &SettingsKey);
+    if (Error != ERROR_SUCCESS) {
+        SetLastError(Error);
+        goto fail1;
+    }
+
+    Error = RegCreateKeyEx(SettingsKey,
+                           KeyName,
+                           0,
+                           NULL,
+                           REG_OPTION_NON_VOLATILE,
+                           KEY_ALL_ACCESS,
+                           NULL,
+                           Key,
+                           NULL);
+    if (Error != ERROR_SUCCESS) {
+        SetLastError(Error);
+        goto fail2;
+    }
+
+    RegCloseKey(SettingsKey);
+
+    return TRUE;
+
+fail2:
+    Log("fail2");
+
+    RegCloseKey(SettingsKey);
+
+fail1:
+    Error = GetLastError();
+
+    {
+        PTCHAR  Message;
+
+        Message = GetErrorMessage(Error);
+        Log("fail1 (%s)", Message);
+        LocalFree(Message);
+    }
+
+    return FALSE;
+}
+
+static BOOLEAN
+CopyNetworkID(
+    IN  PTCHAR  VifIndex,
+    IN  HKEY    DriverKey
+    )
+{
+    BOOLEAN     Success;
+    HRESULT     Error;
+    TCHAR       NetCfgInstanceId[MAX_PATH];
+    DWORD       NetCfgInstanceIdLength;
+    DWORD       Value;
+    DWORD       ValueLength;
+    NET_LUID    NetLuid;
+    HKEY        SettingsKey;
+
+    NetCfgInstanceIdLength = sizeof(NetCfgInstanceId);
+    Error = RegQueryValueEx(DriverKey,
+                            "NetCfgInstanceId",
+                            NULL,
+                            NULL,
+                            (LPBYTE)NetCfgInstanceId,
+                            &NetCfgInstanceIdLength);
+    if (Error != ERROR_SUCCESS) {
+        SetLastError(Error);
+        goto fail1;
+    }
+
+    NetLuid.Value = 0ull;
+
+    ValueLength = sizeof(DWORD);
+    Error = RegQueryValueEx(DriverKey,
+                            "NetLuidIndex",
+                            NULL,
+                            NULL,
+                            (LPBYTE)&Value,
+                            &ValueLength);
+    if (Error != ERROR_SUCCESS) {
+        SetLastError(Error);
+        goto fail2;
+    }
+
+    NetLuid.Info.NetLuidIndex = Value;
+
+    ValueLength = sizeof(DWORD);
+    Error = RegQueryValueEx(DriverKey,
+                            "*IfType",
+                            NULL,
+                            NULL,
+                            (LPBYTE)&Value,
+                            &ValueLength);
+    if (Error != ERROR_SUCCESS) {
+        SetLastError(Error);
+        goto fail3;
+    }
+
+    NetLuid.Info.IfType = Value;
+
+    Log("VIF/%s was %s", VifIndex, NetCfgInstanceId);
+
+    Success = CreateSettingsKey(VifIndex, &SettingsKey);
+    if (!Success)
+        goto fail4;
+
+    Error = RegSetValueEx(SettingsKey,
+                          "NetCfgInstanceId",
+                          0,
+                          REG_SZ,
+                          (const BYTE*)NetCfgInstanceId,
+                          NetCfgInstanceIdLength);
+    if (Error != ERROR_SUCCESS) {
+        SetLastError(Error);
+        goto fail5;
+    }
+
+    Error = RegSetValueEx(SettingsKey,
+                          "NetLuid",
+                          0,
+                          REG_BINARY,
+                          (const BYTE*)&NetLuid,
+                          sizeof(NET_LUID));
+    if (Error != ERROR_SUCCESS) {
+        SetLastError(Error);
+        goto fail6;
+    }
+
+    Value = 1;
+    Error = RegSetValueEx(SettingsKey,
+                          "HasSettings",
+                          0,
+                          REG_DWORD,
+                          (const BYTE*)&Value,
+                          sizeof(DWORD));
+    if (Error != ERROR_SUCCESS) {
+        SetLastError(Error);
+        goto fail7;
+    }
+
+    RegCloseKey(SettingsKey);
+
+    return TRUE;
+
+fail7:
+    Log("fail7");
+
+fail6:
+    Log("fail6");
+
+fail5:
+    Log("fail5");
+
+    RegCloseKey(SettingsKey);
+
+fail4:
+    Log("fail4");
+
+fail3:
+    Log("fail3");
+
+fail2:
+    Log("fail2");
+
+fail1:
+    Error = GetLastError();
+
+    {
+        PTCHAR  Message;
+
+        Message = GetErrorMessage(Error);
+        Log("fail1 (%s)", Message);
+        LocalFree(Message);
+    }
+
+    return FALSE;
+}
+
+static BOOLEAN
+CopyNetworkIDs(
+    VOID
+    )
+{
+    BOOLEAN     Success;
+    HRESULT     Error;
+    HKEY        ClassKey;
+    DWORD       SubKeys;
+    DWORD       MaxSubKeyLength;
+    DWORD       Index;
+    DWORD       SubKeyLength;
+    PTCHAR      SubKeyName;
+
+    Log("====>");
+
+    Success = OpenDriverKey(NETWORK_CLASS_GUID, &ClassKey);
+    if (!Success)
+        goto fail1;
+
+    Error = RegQueryInfoKey(ClassKey,
+                            NULL,
+                            NULL,
+                            NULL,
+                            &SubKeys,
+                            &MaxSubKeyLength,
+                            NULL,
+                            NULL,
+                            NULL,
+                            NULL,
+                            NULL,
+                            NULL);
+    if (Error != ERROR_SUCCESS) {
+        SetLastError(Error);
+        goto fail2;
+    }
+
+    SubKeyLength = MaxSubKeyLength + sizeof (TCHAR);
+
+    SubKeyName = malloc(SubKeyLength);
+    if (SubKeyName == NULL)
+        goto fail3;
+
+    for (Index = 0; Index < SubKeys; ++Index) {
+        HKEY        DriverKey;
+        TCHAR       DeviceInstanceID[MAX_PATH];
+        PTCHAR      VifIndex;
+        DWORD       Length;
+
+        SubKeyLength = MaxSubKeyLength + sizeof (TCHAR);
+        memset(SubKeyName, 0, SubKeyLength);
+
+        Error = RegEnumKeyEx(ClassKey,
+                             Index,
+                             (LPTSTR)SubKeyName,
+                             &SubKeyLength,
+                             NULL,
+                             NULL,
+                             NULL,
+                             NULL);
+        if (Error != ERROR_SUCCESS) {
+            SetLastError(Error);
+            goto fail4;
+        }
+
+        Error = RegOpenKeyEx(ClassKey,
+                             SubKeyName,
+                             0,
+                             KEY_READ,
+                             &DriverKey);
+        if (Error != ERROR_SUCCESS) {
+            SetLastError(Error);
+            continue;
+        }
+
+        Length = sizeof(DeviceInstanceID);
+        Error = RegQueryValueEx(DriverKey,
+                                "DeviceInstanceID",
+                                NULL,
+                                NULL,
+                                (LPBYTE)DeviceInstanceID,
+                                &Length);
+        if (Error != ERROR_SUCCESS) {
+            SetLastError(Error);
+            goto loop1;
+        }
+
+        if (_strnicmp("XENVIF", DeviceInstanceID, strlen("XENVIF")) != 0)
+            goto loop2;
+
+        VifIndex = strrchr(DeviceInstanceID, '\\');
+        if (VifIndex == NULL)
+            goto loop3;
+
+        ++VifIndex;
+
+        CopyNetworkID(VifIndex, DriverKey);
+
+    loop3:
+    loop2:
+    loop1:
+        RegCloseKey(DriverKey);
+    }
+
+    free(SubKeyName);
+    RegCloseKey(ClassKey);
+
+    Log("<====");
+
+    return TRUE;
+
+fail4:
+    Log("fail4");
+
+    free(SubKeyName);
+
+fail3:
+    Log("fail3");
+
+fail2:
+    Log("fail2");
+
+    RegCloseKey(ClassKey);
+
+fail1:
+    Error = GetLastError();
+
+    {
+        PTCHAR  Message;
+
+        Message = GetErrorMessage(Error);
+        Log("fail1 (%s)", Message);
+        LocalFree(Message);
+    }
+
+    return FALSE;
+}
+
 static HRESULT
 DifInstallPreProcess(
     IN  HDEVINFO                    DeviceInfoSet,
@@ -1055,10 +1391,17 @@ DifInstallPreProcess(
     if (!Success)
         goto fail3;
 
+    Success = CopyNetworkIDs();
+    if (!Success)
+        goto fail4;
+
     Log("<====");
 
     return NO_ERROR;
 
+fail4:
+    Log("fail4");
+
 fail3:
     Log("fail3");
 
-- 
2.32.0.windows.1




 


Rackspace

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