Skip to content

Commit

Permalink
fix ipv4 via ipv6 route
Browse files Browse the repository at this point in the history
fix #230
  • Loading branch information
name-snrl authored and mergify[bot] committed Jul 19, 2024
1 parent 109c070 commit 5b9bbfc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 6 additions & 0 deletions nix/kexec-installer/restore_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
7 changes: 6 additions & 1 deletion nix/kexec-installer/test.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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"; }; }
];
Expand All @@ -68,7 +69,7 @@ makeTest' {
};
};

testScript = ''
testScript = /*python*/ ''
import time
import subprocess
import socket
Expand Down Expand Up @@ -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}"
Expand Down

0 comments on commit 5b9bbfc

Please sign in to comment.