Skip to content

fix(unikraft): Use the container's subnet mask in netdev.ip - #1210

Open
arshil42 wants to merge 2 commits into
urunc-dev:mainfrom
arshil42:fix/unikraft-netdev-mask
Open

arshil42 wants to merge 2 commits into
urunc-dev:mainfrom
arshil42:fix/unikraft-netdev-mask

Conversation

@arshil42

Copy link
Copy Markdown

Description

For Unikraft 0.16.1 and later, and when the Unikraft version is undefined or cannot be parsed, configureUnikraftArgs sets the guest network with

netdev.ip=<ip>/24:<gateway>:<dns>

so the prefix length is always /24 and the ethDeviceMask of the container network is ignored. On any network with a different mask, such as Docker's default 172.17.0.0/16 bridge, the guest gets the wrong subnet. The older netdev.ipv4_subnet_mask path already passes the real mask.

This converts the mask to a prefix length with the existing subnetMaskToCIDR helper, as the Hermit, Mewz and MirageOS guests already do. When there is no mask, the prefix stays /24, as before. An invalid mask now returns an error from Init, like it does for those guests.

The PR also adds me to .github/contributors.yaml in a separate commit.

This picks up #827 after #823, which addressed it, was closed as stale.

Related issues

How was this tested?

On Ubuntu (WSL2, x86_64), in a fresh clone of the branch:

  • New TestUnikraftNetdevIPPrefixLength and TestUnikraftNetdevIPInvalidMask in pkg/unikontainers/unikernels/unikraft_test.go cover /16, /24 and /20 masks, an undefined version, a missing mask (stays /24), the pre-0.16.1 path (mask passed as is) and an invalid mask. Without the change, the /16, /20, undefined-version and invalid-mask cases fail.
  • go test ./pkg/... ./cmd/... ./internal/...: everything passes except TestCopyFile and TestMoveFile in pkg/unikontainers, which fail the same way on main in this environment because the tests run as root, so the permission errors they expect do not happen.
  • golangci-lint run with v2.15.0 (the version used by make lint) over the whole repository: 0 issues.
  • commitlint and cspell with the configs in .github/linters: no issues.

I could not run the e2e tests: this machine has no KVM or containerd setup.

LLM usage

Claude Opus 5.5 (claude-opus-5-5, through Claude Code) was used to find the code path, write the change and the tests, and draft this description. I reviewed the changes and ran the tests above before opening the PR.

Checklist

  • I have read the contribution guide.
  • The linter passes locally (make lint).
  • The e2e tests of at least one tool pass locally (make test_ctr, make test_nerdctl, make test_docker, make test_crictl).
  • If LLMs were used: I have read the llm policy.

Signed-off-by: Arshil Ahmed <194646586+arshil42@users.noreply.github.com>
For Unikraft 0.16.1 and later, and when the version is unknown, the
guest network is set with netdev.ip=<ip>/24:<gw>:<dns>, so the prefix
is always /24 and the subnet mask of the container network is ignored.
On a network with any other mask, such as Docker's default 172.17.0.0/16
bridge, the guest gets the wrong subnet. The older netdev.ipv4_subnet_mask
path already passes the real mask.

Convert the mask to a prefix length with subnetMaskToCIDR, as the Hermit,
Mewz and MirageOS guests do, and keep /24 when there is no mask.

Fixes: urunc-dev#827
Signed-off-by: Arshil Ahmed <194646586+arshil42@users.noreply.github.com>
@netlify

netlify Bot commented Nov 17, 2026

Copy link
Copy Markdown

👷 Deploy request for urunc pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 632bebc

This branch has not been deployed

No deployments
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.

Unikraft guest network ignores container subnet mask (hardcoded /24) in current-version args path

1 participant