modules/wg-clerie: select VPN endpoint based on IP protocol availability
This commit is contained in:
parent
c02a5af8d5
commit
ddbc04dfd2
@ -36,14 +36,30 @@ in
|
||||
|
||||
petabyte.policyrouting = {
|
||||
enable = true;
|
||||
rules6 = concatMap (ip: [
|
||||
{ rule = "from ${ip} lookup wg-clerie"; prio = 20000; }
|
||||
{ rule = "from ${ip} unreachable"; prio = 20001; }
|
||||
]) cfg.ipv6s;
|
||||
rules4 = concatMap (ip: [
|
||||
{ rule = "from ${ip} lookup wg-clerie"; prio = 20000; }
|
||||
{ rule = "from ${ip} unreachable"; prio = 20001; }
|
||||
]) cfg.ipv4s;
|
||||
rules6 = (concatMap (ip: [
|
||||
{ rule = "from ${ip} lookup wg-clerie"; prio = 19000; }
|
||||
{ rule = "from ${ip} unreachable"; prio = 19001; }
|
||||
]) cfg.ipv6s) ++ [
|
||||
# Do not reach VPN server via VPN
|
||||
{ rule = "to 2a01:4f8:c0c:15f1::1/128 ipproto udp dport 51820 lookup main"; prio = 20000; }
|
||||
{ rule = "to 2a01:4f8:c0c:15f1::1/128 ipproto udp dport 51820 unreachable"; prio = 20001; }
|
||||
# Try direct routing first, fallback to VPN
|
||||
{ rule = "lookup main"; prio = 21000; }
|
||||
{ rule = "lookup wg-clerie"; prio = 21001; }
|
||||
{ rule = "unreachable"; prio = 22000; }
|
||||
];
|
||||
rules4 = (concatMap (ip: [
|
||||
{ rule = "from ${ip} lookup wg-clerie"; prio = 19000; }
|
||||
{ rule = "from ${ip} unreachable"; prio = 19001; }
|
||||
]) cfg.ipv4s) ++ [
|
||||
# Do not reach VPN server via VPN
|
||||
{ rule = "to 78.47.183.82/32 ipproto udp dport 51820 lookup main"; prio = 20000; }
|
||||
{ rule = "to 78.47.183.82/32 ipproto udp dport 51820 unreachable"; prio = 20001; }
|
||||
# Try direct routing first, fallback to VPN
|
||||
{ rule = "lookup main"; prio = 21000; }
|
||||
{ rule = "lookup wg-clerie"; prio = 21001; }
|
||||
{ rule = "unreachable"; prio = 22000; }
|
||||
];
|
||||
};
|
||||
|
||||
networking.wireguard.enable = true;
|
||||
@ -54,7 +70,8 @@ in
|
||||
table = "wg-clerie";
|
||||
peers = [
|
||||
{
|
||||
endpoint = "vpn.clerie.de:51820";
|
||||
# Fallback to legacy IP if there is no route to VPN server
|
||||
endpoint = "$(ip route get 2a01:4f8:c0c:15f1::1 ipproto udp dport 51820 &>/dev/null && echo '[2a01:4f8:c0c:15f1::1]:51820' || echo '78.47.183.82:51820')";
|
||||
persistentKeepalive = 25;
|
||||
dynamicEndpointRefreshSeconds = 5;
|
||||
allowedIPs = [ "0.0.0.0/0" "::/0" "10.20.30.0/24" "2a01:4f8:c0c:15f1::/113" ];
|
||||
|
Loading…
Reference in New Issue
Block a user