From 9f871a6f8073e304c74bb635e27654f8988c84e9 Mon Sep 17 00:00:00 2001 From: ehazan Date: Tue, 6 May 2025 21:20:50 +0300 Subject: [PATCH] Clean up duplicate persistent routes from registry during boot sequence. During the conversion of Windows virtual machines, some persistent static routes were being duplicated in the Windows registry. This change adds a cleanup step during the boot sequence to remove redundant entries from the PersistentRoutes registry key, ensuring that only unique static routes are retained and applied at boot time. Fixes: https://issues.redhat.com/browse/RHEL-89939. Signed-off-by: ehazan --- convert/convert_windows.ml | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/convert/convert_windows.ml b/convert/convert_windows.ml index 024229aa5..629795132 100644 --- a/convert/convert_windows.ml +++ b/convert/convert_windows.ml @@ -755,6 +755,35 @@ let convert (g : G.guestfs) source inspect i_firmware add "# In the timeout case $ifindex will not be set below."; add "" ); + + (* Clean up old persistent routes to avoid duplicates *) + add "# Clean up duplicate persistent routes from registry"; + add "$regPath = 'HKLM:\\SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\PersistentRoutes'"; + add "if (Test-Path $regPath) {"; + add " $routes = Get-ItemProperty -Path $regPath"; + add " $existing = $routes.PSObject.Properties | Where-Object { $_.Value -match '^\\d' }"; + add " $grouped = @{}"; + add " foreach ($r in $existing) {"; + add " $tokens = $r.Value -split '\\s+'"; + add " if ($tokens.Length -ge 2) {"; + add " $key = \"$($tokens[0]) $($tokens[1])\""; + add " if (-not $grouped.ContainsKey($key)) { $grouped[$key] = @() }"; + add " $grouped[$key] += $r"; + add " }"; + add " }"; + add " foreach ($entry in $grouped.GetEnumerator()) {"; + add " $list = $entry.Value"; + add " if ($list.Count -gt 1) {"; + add " $toDelete = $list[0..($list.Count - 2)]"; + add " foreach ($r in $toDelete) {"; + add " Write-Host \"Removing duplicate persistent route: $($r.Value)\""; + add " Remove-ItemProperty -Path $regPath -Name $r.Name -ErrorAction SilentlyContinue"; + add " }"; + add " }"; + add " }"; + add "}"; + add ""; + List.iter ( fun { if_mac_addr; if_ip_address; if_default_gateway;