From: Michael Tremer Date: Tue, 16 Apr 2024 14:20:55 +0000 (+0200) Subject: firewall: Automatically open ports for WireGuard X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=fc32e7b9147d2eeeb6e2bc1497859fb050001eb5;p=people%2Fmfischer%2Fipfire-2.x.git firewall: Automatically open ports for WireGuard Signed-off-by: Michael Tremer --- diff --git a/src/initscripts/system/firewall b/src/initscripts/system/firewall index 6befa9fc3..b7e8a9cda 100644 --- a/src/initscripts/system/firewall +++ b/src/initscripts/system/firewall @@ -319,6 +319,10 @@ iptables_init() { iptables -N WIRELESSFORWARD iptables -A FORWARD -m conntrack --ctstate NEW -j WIRELESSFORWARD + # WireGuard + iptables -N WGINPUT + iptables -A INPUT -j WGINPUT + # OpenVPN iptables -N OVPNINPUT iptables -A INPUT -j OVPNINPUT diff --git a/src/initscripts/system/wireguard b/src/initscripts/system/wireguard index 42428aee0..2ad6b9fe2 100644 --- a/src/initscripts/system/wireguard +++ b/src/initscripts/system/wireguard @@ -78,7 +78,19 @@ generate_config() { done < /var/ipfire/wireguard/peers } +reload_firewall() { + # Flush all previous rules + iptables -F WGINPUT + + if [ "${ENABLED}" = "on" ]; then + iptables -A WGINPUT -p udp --dport "${PORT}" -j ACCEPT + fi +} + wg_start() { + # Reload the firewall + reload_firewall + # Create the interface if it does not exist if [ ! -d "/sys/class/net/${INTF}" ]; then ip link add "${INTF}" type wireguard || return $? @@ -99,6 +111,9 @@ wg_start() { } wg_stop() { + # Reload the firewall + ENABLED=off reload_firewall + if [ -d "/sys/class/net/${INTF}" ]; then ip link del "${INTF}" || return $? fi