From 5b9bbfc570f5543d8ba86d33ff9791d71ee522f6 Mon Sep 17 00:00:00 2001 From: name_snrl Date: Sun, 14 Jul 2024 03:21:24 +0500 Subject: [PATCH] fix ipv4 via ipv6 route fix #230 --- nix/kexec-installer/restore_routes.py | 6 ++++++ nix/kexec-installer/test.nix | 7 ++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/nix/kexec-installer/restore_routes.py b/nix/kexec-installer/restore_routes.py index 1635376..1bf1801 100644 --- a/nix/kexec-installer/restore_routes.py +++ b/nix/kexec-installer/restore_routes.py @@ -63,6 +63,12 @@ def generate_networkd_units( # can be skipped for default routes route_section += f"Destination = {route['dst']}\n" gateway = route.get("gateway") + # route v4 via v6 + route_via = route.get("via") + if route_via and route_via.get("family") == "inet6": + gateway = route_via.get("host") + if route.get("dst") == "default": + route_section += "Destination = 0.0.0.0/0\n" if gateway: route_section += f"Gateway = {gateway}\n" diff --git a/nix/kexec-installer/test.nix b/nix/kexec-installer/test.nix index a5198bb..70db2f0 100644 --- a/nix/kexec-installer/test.nix +++ b/nix/kexec-installer/test.nix @@ -58,6 +58,7 @@ makeTest' { # Some static routes that we want to see in the kexeced image { routeConfig = { Destination = "192.168.43.0/24"; }; } { routeConfig = { Destination = "192.168.44.0/24"; Gateway = "192.168.43.1"; }; } + { routeConfig = { Destination = "192.168.45.0/24"; Gateway = "43::1"; }; } { routeConfig = { Destination = "43::0/64"; }; } { routeConfig = { Destination = "44::1/64"; Gateway = "43::1"; }; } ]; @@ -68,7 +69,7 @@ makeTest' { }; }; - testScript = '' + testScript = /*python*/ '' import time import subprocess import socket @@ -185,6 +186,10 @@ makeTest' { print(out) assert "192.168.44.2 via 192.168.43.1" in out, f"route to `192.168.44.2 via 192.168.43.1` not found: {out}" + out = ssh(["ip", "route", "get", "192.168.45.2"], stdout=subprocess.PIPE).stdout + print(out) + assert "192.168.45.2 via inet6 43::1" in out, f"route to `192.168.45.2 via inet6 43::1` not found: {out}" + out = ssh(["ip", "route", "get", "43::2"], stdout=subprocess.PIPE).stdout print(out) assert "43::2 from :: dev" in out, f"route `43::2 from dev` not found: {out}"