fix: resolve Traefik route interface correctly
Homelab Main / validate (push) Waiting to run Details
Homelab Main / running-update (push) Blocked by required conditions Details
Homelab Main / debian-ops (push) Blocked by required conditions Details

This commit is contained in:
juvenal.diaz 2026-10-01 17:36:18 -06:00
parent 2ec6e53002
commit f6c2b76095
1 changed files with 9 additions and 1 deletions

View File

@ -6353,7 +6353,9 @@ if [ -n "\$sysctl_bin" ]; then
"\$sysctl_bin" -w net.ipv4.ip_forward=1 >/dev/null
fi
lan_if="\$(ip route get "\$traefik_ip" | awk '{print \$5; exit}')"
route_line="\$(ip route get "\$traefik_ip")"
lan_if="\$(printf '%s\n' "\$route_line" | awk '{for (i = 1; i < NF; i++) if (\$i == "dev") {print \$(i + 1); exit}}')"
route_src="\$(printf '%s\n' "\$route_line" | awk '{for (i = 1; i < NF; i++) if (\$i == "src") {print \$(i + 1); exit}}')"
if [ -z "\$lan_if" ]; then
echo "Could not resolve LAN interface for \$traefik_ip." >&2
exit 1
@ -6372,6 +6374,12 @@ iptables_cmd() {
"\$iptables_bin" "\$@"
}
if [ -n "\$route_src" ] && [ "\$route_src" != "\$lan_if" ]; then
while iptables_cmd -D FORWARD -i tailscale0 -o "\$route_src" -s "\$tailscale_cidr" -d "\$traefik_ip" -m comment --comment homelab-edge-traefik-route -j ACCEPT 2>/dev/null; do :; done
while iptables_cmd -D FORWARD -i "\$route_src" -o tailscale0 -s "\$traefik_ip" -d "\$tailscale_cidr" -m comment --comment homelab-edge-traefik-route -j ACCEPT 2>/dev/null; do :; done
while iptables_cmd -t nat -D POSTROUTING -s "\$tailscale_cidr" -d "\$traefik_ip" -o "\$route_src" -m comment --comment homelab-edge-traefik-route -j MASQUERADE 2>/dev/null; do :; done
fi
iptables_cmd -C FORWARD -i tailscale0 -o "\$lan_if" -s "\$tailscale_cidr" -d "\$traefik_ip" -m comment --comment homelab-edge-traefik-route -j ACCEPT 2>/dev/null ||
iptables_cmd -I FORWARD 1 -i tailscale0 -o "\$lan_if" -s "\$tailscale_cidr" -d "\$traefik_ip" -m comment --comment homelab-edge-traefik-route -j ACCEPT