Description
Mirage.Init() in pkg/unikontainers/unikernels/mirage.go reads the subnet mask from the container's network parameters but then ignores it, hardcoding /24 into the IP address string. For any container network using a prefix other than /24 — such as /28, /16, or /30 — the MirageOS kernel command line will have the wrong prefix, causing incorrect routing inside the unikernel.
Steps to reproduce
Add a test that initializes a Mirage struct with a /28 mask and checks the resulting address string:
go test ./pkg/unikontainers/unikernels/ -v -run TestMirageInitSubnetMask
The test will fail before the fix because Net.Address contains /24 instead of /28.
Expected behavior: The CIDR prefix in the Mirage kernel command line matches the actual subnet mask of the container's network interface.
Current behavior: The CIDR prefix is always /24 regardless of the actual subnet mask.
Proposed solution: Call subnetMaskToCIDR() on the value from data.Net.Mask and use the result when building the IP address string, instead of hardcoding /24.
Description
Mirage.Init()inpkg/unikontainers/unikernels/mirage.goreads the subnet mask from the container's network parameters but then ignores it, hardcoding/24into the IP address string. For any container network using a prefix other than/24— such as/28,/16, or/30— the MirageOS kernel command line will have the wrong prefix, causing incorrect routing inside the unikernel.Steps to reproduce
Add a test that initializes a
Miragestruct with a/28mask and checks the resulting address string:go test ./pkg/unikontainers/unikernels/ -v -run TestMirageInitSubnetMaskThe test will fail before the fix because
Net.Addresscontains/24instead of/28.Expected behavior: The CIDR prefix in the Mirage kernel command line matches the actual subnet mask of the container's network interface.
Current behavior: The CIDR prefix is always
/24regardless of the actual subnet mask.Proposed solution: Call
subnetMaskToCIDR()on the value fromdata.Net.Maskand use the result when building the IP address string, instead of hardcoding/24.