Skip to content

Fix cloud-init netconfig parsing - #136

Merged
metalefty merged 2 commits into
masterfrom
fix/netconfig-parsing
Aug 20, 2026
Merged

Fix cloud-init netconfig parsing#136
metalefty merged 2 commits into
masterfrom
fix/netconfig-parsing

Conversation

@mateuszkwiatkowski

Copy link
Copy Markdown
Contributor

The netconfig string passed to vm create -C -n was parsed with a bunch of grep -oE 'key=[^;]*' passes. This had several problems:

  • Unrecognised keys were silently ignored. Passing gateway= instead of gateway4=/gateway6= produced a guest with no default route and no warning of any kind.
  • Keys were matched as substrings, so ip= also matched inside any key ending in ip, and repeated occurrences were concatenated.

Replace this with a loop that splits the string on ; and matches each key=value pair, erroring out on an unknown key or on an entry with no =.

Parsing now happens during argument validation, before the dataset and disks are created, so a bad netconfig string no longer leaves a half-created guest behind.

While on that also fix two typos that made searchdomains= a complete no-op: the guard tested _network_config_serachdomains and the search: line read _searchdomains, neither of which is ever set. And declare _ipv6_found local rather than the unused ipv6_found.

Finally, vm help create listed the template option as -f; the option actually parsed by core::create is -t.

@metalefty

Copy link
Copy Markdown
Member

Overall, LGTM. Thank you. Please allow me about a week, as I'm on vacation.

Comment thread lib/vm-core

# nameservers & searchdomains
if [ -n "${_network_config_serachdomains}" -o -n "${_network_config_nameservers}" ]; then
if [ -n "${_network_config_searchdomains}" -o -n "${_network_config_nameservers}" ]; then

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good find!

@metalefty

Copy link
Copy Markdown
Member

@mateuszkwiatkowski LGTM. Could you separate commits on vm-help? This fix should also be applied to 1.7-stable.

The netconfig string passed to `vm create -C -n` was parsed with a bunch
of `grep -oE 'key=[^;]*'` passes. This had several problems:

- Unrecognised keys were silently ignored. Passing `gateway=` instead of
  `gateway4=`/`gateway6=` produced a guest with no default route and no
  warning of any kind.
- Keys were matched as substrings, so `ip=` also matched inside any key
  ending in `ip`, and repeated occurrences were concatenated.

Replace this with a loop that splits the string on `;` and matches each
`key=value` pair, erroring out on an unknown key or on an entry
with no `=`.

Parsing now happens during argument validation, before the dataset and
disks are created, so a bad netconfig string no longer leaves a
half-created guest behind.

While on that also fix two typos that made `searchdomains=` a complete
no-op: the guard tested `_network_config_serachdomains` and the `search:`
line read `_searchdomains`, neither of which is ever set. And declare
`_ipv6_found` local rather than the unused `ipv6_found`.
`vm help create` listed the template option as `-f`; the option actually
parsed by core::create is `-t`.
@mateuszkwiatkowski
mateuszkwiatkowski force-pushed the fix/netconfig-parsing branch 2 times, most recently from 548cc12 to 2580f47 Compare August 19, 2026 13:40
@mateuszkwiatkowski

Copy link
Copy Markdown
Contributor Author

@mateuszkwiatkowski LGTM. Could you separate commits on vm-help? This fix should also be applied to 1.7-stable.

I checked 1.7-stable and lib/vm-help doesn't exist there. It's still on util::usage and it already documents create correctly as -t template so it seems there's nothing to be backported. I split the PR anyway.

@mateuszkwiatkowski

Copy link
Copy Markdown
Contributor Author

Ah, you probably meant backporting cloud-init fix. :-) Sorry!

@metalefty

Copy link
Copy Markdown
Member

Ah, you probably meant backporting cloud-init fix. :-) Sorry!

Exactly!

@metalefty
metalefty merged commit 89c21d0 into master Aug 20, 2026
3 checks passed
@metalefty
metalefty deleted the fix/netconfig-parsing branch August 20, 2026 00:07
@metalefty metalefty mentioned this pull request Aug 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants