Skip to content

Commit 024cd42

Browse files
committed
add classless static route support to the forknet dhcp client so that the ipv4.dhcp.static-routes setting works with OCI containers
Signed-off-by: Gwendolyn <[email protected]>
1 parent 4c303d4 commit 024cd42

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

cmd/incusd/main_forknet.go

+15
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,21 @@ func (c *cmdForknet) RunDHCP(cmd *cobra.Command, args []string) error {
391391
return nil
392392
}
393393

394+
for _, staticRoute := range lease.Offer.ClasslessStaticRoute() {
395+
route := &ip.Route{
396+
DevName: iface,
397+
Route: staticRoute.Dest.String(),
398+
Via: staticRoute.Router.String(),
399+
Family: ip.FamilyV4,
400+
}
401+
402+
err = route.Add()
403+
if err != nil {
404+
fmt.Fprintf(os.Stderr, "Giving up on DHCP, couldn't add classless static route to %q: %v\n", iface, err)
405+
return nil
406+
}
407+
}
408+
394409
// Create PID file.
395410
err = os.WriteFile(filepath.Join(args[0], "dhcp.pid"), []byte(fmt.Sprintf("%d", os.Getpid())), 0644)
396411
if err != nil {

test/suites/network_dhcp_routes.sh

+16
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,22 @@ test_network_dhcp_routes() {
1313
incus exec nettest -- ip route list | grep -q "2.3.0.0/16 via 10.13.37.7"
1414

1515
incus delete nettest -f
16+
17+
if [ -n "${INCUS_OFFLINE:-}" ]; then
18+
echo "==> SKIP: Skipping OCI tests as running offline"
19+
else
20+
ensure_has_localhost_remote "${INCUS_ADDR}"
21+
22+
incus remote add docker https://docker.io --protocol=oci
23+
incus launch docker:alpine nettest --network=inct$$
24+
25+
incus exec nettest -- ip route list | grep -q "1.2.0.0/16 via 10.13.37.5"
26+
incus exec nettest -- ip route list | grep -q "2.3.0.0/16 via 10.13.37.7"
27+
28+
incus delete -f nettest
29+
incus remote remove docker
30+
fi
31+
1632
incus network delete inct$$
1733

1834

0 commit comments

Comments
 (0)