From 4af40db1a120bf2b7b855dfd425c62a1216f4f6b Mon Sep 17 00:00:00 2001 From: bergware Date: Mon, 18 Apr 2022 01:00:12 +0200 Subject: [PATCH] WireGuard: add logic to recreate networks after reboot --- plugins/dynamix/include/update.wireguard.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/plugins/dynamix/include/update.wireguard.php b/plugins/dynamix/include/update.wireguard.php index 73bdee118..d2c2fdb91 100644 --- a/plugins/dynamix/include/update.wireguard.php +++ b/plugins/dynamix/include/update.wireguard.php @@ -53,6 +53,9 @@ function ipfilter(&$list) { function host($ip) { return strpos($ip,'/')!==false ? $ip : (ipv4($ip) ? "$ip/32" : "$ip/128"); } +function nonet($network) { + return empty(exec("ip rule|grep -Pom1 'from $network'")); +} function wgState($vtun,$state,$type=0) { global $t1,$etc; $tmp = '/tmp/wg-quick.tmp'; @@ -91,7 +94,7 @@ function addDocker($vtun) { $network = "$dockernet.$index.0/24"; exec("docker network create $vtun --subnet=$network 2>/dev/null"); $error = dockerNet($vtun); - if (!$error && !exec("ip rule|grep -Pom1 'from $network'")) { + if (!$error && nonet($network)) { extract(parse_ini_file('state/network.ini',true)); $thisnet = long2ip(ip2long($eth0['IPADDR:0']) & ip2long($eth0['NETMASK:0'])).'/'.mask2cidr($eth0['NETMASK:0']); $gateway = $eth0['GATEWAY:0']; @@ -376,6 +379,9 @@ case 'toggle': echo status($vtun) ? 1 : 0; break; case 'start': + $index = substr($vtun,2)+200; + $network = "$dockernet.$index.0/24"; + if (nonet($network)) exec("ip -4 rule add from $network table $index"); wgState($vtun,'up',$_POST['#type']); echo status($vtun) ? 0 : 1; break;