MTV-5323 | Preserve advanced Windows network settings during migration#6414
MTV-5323 | Preserve advanced Windows network settings during migration#6414Hazanel wants to merge 1 commit into
Conversation
📝 WalkthroughWalkthroughThis PR adds comprehensive support for extracting and applying Windows advanced network settings during VM migration. It includes a complete Windows Registry REGF parser to read the SYSTEM hive, utilities to extract network configuration (interfaces, metrics, DNS, NetBIOS, File & Printer Sharing state), entrypoint integration to read settings before customization, refactored template injection to render and upload a firstboot PowerShell script, and extensive test coverage with synthetic hive builders. ChangesWindows Advanced Network Settings Feature
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@pkg/virt-v2v/customize/advancednet/reader.go`:
- Around line 113-126: The buildGUIDToMAC function currently swallows hive
errors when calling hive.EnumerateSubkeys(ns2Key), hive.OpenKey(ns2Path + "\\" +
guid + "\\Kernel"), and hive.ReadBinary(kernelKey,
"CurrentAddress"/"PermanentAddress"); change these to check and wrap each error
with contextual information (include guid and key path/value name) and propagate
the error out of buildGUIDToMAC instead of continuing silently. Specifically,
replace the ignored error returns from guidKeys, err :=
hive.EnumerateSubkeys(ns2Key), kernelKey, err := hive.OpenKey(...), and the
ReadBinary calls with proper if err != nil { return nil,
fmt.Errorf("buildGUIDToMAC: failed to <operation> for guid %s at %s: %w", guid,
<path-or-value>, err) } (or accumulate structured warnings to return alongside
the mapping), ensuring callers receive the error so data-loss conditions are
visible and handled.
- Around line 253-259: The check building hasCustom incorrectly treats only
RegistrationEnabled == 0 as custom; update the condition to mirror
HasNonDefaultSettings() semantics by checking iface.RegistrationEnabled !=
DNSRegistrationEnabled instead of == 0, so that any explicit non-default values
(e.g., 2) mark hasCustom true; adjust the block where hasCustom is computed (the
code referencing iface.InterfaceMetricAuto, iface.InterfaceMetric and
iface.RegistrationEnabled) to use the != comparison.
In `@pkg/virt-v2v/customize/advancednet/regf.go`:
- Around line 243-283: The looped element reads in findInSubkeyListDepth
(handling sigLF/sigLH, sigLI, sigRI) use count without checking that the full
array fits the buffer; before each switch case iterate, compute the required
bytes (sigLF/LH: 4 + int(count)*8, sigLI/sigRI: 4 + int(count)*4) and guard by
validating that abs + required <= len(h.data) (or h.size) and return a safe
error if not; apply the same pattern in FindValue before iterating over
nk.valuesCount (compute required = 4 + int(nk.valuesCount)*sizePerElement and
validate buffer bounds) so all element reads (readInt32, parseNK, child sublist
offsets) are protected from malformed counts.
- Around line 131-137: The code calls cellOffset(off) and only checks upper
bounds, but cellOffset can return negative values; update both locations where
abs := cellOffset(off) is used (the NK offset/record checks in regf.go around
the NK parsing) to validate abs >= 0 before any slicing or adding
cellSizeLen/nkMinSize, returning a descriptive error (e.g., "regf: NK offset
0x%x out of range") when abs < 0; ensure the same check is applied in the second
occurrence (the block handling NK record size further down) to prevent
negative-index panics when reading h.data.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: d1c6328f-1197-44b3-b612-b8d6f3f74846
📒 Files selected for processing (12)
cmd/virt-v2v/entrypoint.gopkg/controller/plan/adapter/base/network_test.gopkg/controller/plan/adapter/hyperv/builder.gopkg/controller/plan/adapter/ovfbase/builder.gopkg/controller/plan/adapter/vsphere/builder.gopkg/virt-v2v/customize/advancednet/reader.gopkg/virt-v2v/customize/advancednet/regf.gopkg/virt-v2v/customize/advancednet/regf_test.gopkg/virt-v2v/customize/advancednet/types.gopkg/virt-v2v/customize/customize.gopkg/virt-v2v/customize/customize_test.gopkg/virt-v2v/customize/scripts/windows/9998-advanced-network-settings.ps1.tmpl
92d7de1 to
bb45e03
Compare
|
@coderabbitai please take a look and also share your thought whether it's a good approach or you think we can come up with a better way |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: Length of output: 61106 🏁 Script executed: Length of output: 7968
Overall Approach Assessment ✅The approach is well-chosen for the environment. The two main design decisions are sound: 1. Custom REGF Parser vs. Using Existing ToolsThe natural alternative to writing your own parser would be to shell out to
The implementation handles all the important edge cases: 2. MAC Resolution from Registry (vs. Provider-Supplied List)This is a clear improvement over the previous approach. Reading from Specific Concerns🔴
|
| Custom REGF parser | ✅ Right choice for this environment |
| MAC from registry | ✅ Better than provider-supplied list |
--format=raw hardcoded |
🔴 Can break on qcow2 |
| First disk only | 🟡 Works in practice, worth a comment |
injectComplementryStaticIPTemplate not refactored |
🟡 Minor tech debt |
| PS1 JSON injection | 🟡 Consider here-string for safety |
The main actionable item before merge is the --format=raw hardcoding. The rest are lower priority.
bb45e03 to
253242d
Compare
|
Hey @coderabbitai Thanks for the thorough review: 🔴 virt-cat --format=raw hardcoded By the time this code runs, virt-v2v has already completed conversion — all disks are raw at this point regardless of the source format (vSphere, OVA, etc.). The --format=raw flag is correct and intentional. 🔴 Only first disk is read — no fallback Windows always places C:\Windows\System32\config\SYSTEM on the boot disk, which is Disks[0]. Added a comment documenting this assumption explicitly. Iterating through all disks would add complexity with no practical benefit — if the boot disk isn't Disks[0], we have bigger problems than advanced network settings. 🟡 injectComplementryStaticIPTemplate not refactored to use renderTemplate Good catch. Refactored — extended renderTemplate with a variadic funcMaps ...template.FuncMap parameter so the custom funcs (lower, add, len, formatIPs, formatDNS) pass through cleanly. 🟡 PowerShell JSON injection — single-quote assumption The JSON is produced by json.MarshalIndent from our own Go structs (AdvancedNetSettings), which contain only MAC addresses (AA:BB:CC:DD:EE:FF), GUIDs ({...}), and uint32 values. None of these can contain single quotes. |
|
Tip For best results, initiate chat on the files or code changes.
The implementation looks solid. 🐇 ✏️ Learnings added
|
253242d to
43537d2
Compare
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6414 +/- ##
==========================================
- Coverage 15.45% 10.52% -4.94%
==========================================
Files 112 522 +410
Lines 23377 62366 +38989
==========================================
+ Hits 3613 6564 +2951
- Misses 19479 55172 +35693
- Partials 285 630 +345
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
0a27f02 to
83f28ad
Compare
Add a REGF registry parser to extract per-adapter network settings from the Windows SYSTEM hive after virt-v2v conversion. MAC addresses are resolved directly from the registry, eliminating any dependency on provider-supplied NIC MAC lists. Settings preserved: - InterfaceMetric - DNS registration, - NetBIOS over TCP/IP, - LanmanServer start type, and File & Printer Sharing bindings. Ref: https://redhat.atlassian.net/browse/MTV-5323 Resolves: MTV-5323 Signed-off-by: Elad Hazan <ehazan@redhat.com>
83f28ad to
d07c164
Compare
|



Add a REGF registry parser to extract per-adapter network settings
from the Windows SYSTEM hive after virt-v2v conversion.
MAC addresses are resolved directly from the registry, eliminating any dependency on
provider-supplied NIC MAC lists.
Settings preserved:
Ref: https://redhat.atlassian.net/browse/MTV-5323
Resolves: MTV-5323