fix ipv4 via ipv6 route

fix #230
This commit is contained in:
name_snrl 2024-07-14 03:21:24 +05:00 committed by mergify[bot]
parent 109c0704a1
commit 5b9bbfc570
2 changed files with 12 additions and 1 deletions

View file

@ -63,6 +63,12 @@ def generate_networkd_units(
# can be skipped for default routes # can be skipped for default routes
route_section += f"Destination = {route['dst']}\n" route_section += f"Destination = {route['dst']}\n"
gateway = route.get("gateway") 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: if gateway:
route_section += f"Gateway = {gateway}\n" route_section += f"Gateway = {gateway}\n"

View file

@ -58,6 +58,7 @@ makeTest' {
# Some static routes that we want to see in the kexeced image # Some static routes that we want to see in the kexeced image
{ routeConfig = { Destination = "192.168.43.0/24"; }; } { routeConfig = { Destination = "192.168.43.0/24"; }; }
{ routeConfig = { Destination = "192.168.44.0/24"; Gateway = "192.168.43.1"; }; } { 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 = "43::0/64"; }; }
{ routeConfig = { Destination = "44::1/64"; Gateway = "43::1"; }; } { routeConfig = { Destination = "44::1/64"; Gateway = "43::1"; }; }
]; ];
@ -68,7 +69,7 @@ makeTest' {
}; };
}; };
testScript = '' testScript = /*python*/ ''
import time import time
import subprocess import subprocess
import socket import socket
@ -185,6 +186,10 @@ makeTest' {
print(out) 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}" 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 out = ssh(["ip", "route", "get", "43::2"], stdout=subprocess.PIPE).stdout
print(out) print(out)
assert "43::2 from :: dev" in out, f"route `43::2 from dev` not found: {out}" assert "43::2 from :: dev" in out, f"route `43::2 from dev` not found: {out}"