wireguard-tools: add uci option to disable wireguard peers
authorStepan Henek <stepan.henek@nic.cz>
Sun, 25 Apr 2021 21:32:29 +0000 (23:32 +0200)
committerPaul Spooren <mail@aparcar.org>
Mon, 18 Oct 2021 22:14:36 +0000 (12:14 -1000)
Right now when I want to temporarily disable wg peer I need to delete
the entire peer section. This is not such a good solution because I
loose the previous configuration of the peer.

This patch adds `disabled` option to peer config which causes that
the config section is ignored.

Signed-off-by: Stepan Henek <stepan.henek@nic.cz>
[use $(AUTORELEASE)]
Signed-off-by: Paul Spooren <mail@aparcar.org>
package/network/utils/wireguard-tools/Makefile
package/network/utils/wireguard-tools/files/wireguard.sh
package/network/utils/wireguard-tools/files/wireguard_watchdog

index 11372f23310c7e79362db2d897cfffc1d14cc4aa..717ec2bbb1431b6f7a559d3177158fe10832986a 100644 (file)
@@ -12,7 +12,7 @@ include $(INCLUDE_DIR)/kernel.mk
 PKG_NAME:=wireguard-tools
 
 PKG_VERSION:=1.0.20210424
-PKG_RELEASE:=1
+PKG_RELEASE:=$(AUTORELEASE)
 
 PKG_SOURCE:=wireguard-tools-$(PKG_VERSION).tar.xz
 PKG_SOURCE_URL:=https://git.zx2c4.com/wireguard-tools/snapshot/
index 63261aea71daa058bf37014ba7d670a5e74a2e04..2e6d74bc913def99a7381c94b9fa07c4141e8c0b 100644 (file)
@@ -26,6 +26,7 @@ proto_wireguard_init_config() {
 proto_wireguard_setup_peer() {
        local peer_config="$1"
 
+       local disabled
        local public_key
        local preshared_key
        local allowed_ips
@@ -34,6 +35,7 @@ proto_wireguard_setup_peer() {
        local endpoint_port
        local persistent_keepalive
 
+       config_get_bool disabled "${peer_config}" "disabled" 0
        config_get public_key "${peer_config}" "public_key"
        config_get preshared_key "${peer_config}" "preshared_key"
        config_get allowed_ips "${peer_config}" "allowed_ips"
@@ -42,6 +44,11 @@ proto_wireguard_setup_peer() {
        config_get endpoint_port "${peer_config}" "endpoint_port"
        config_get persistent_keepalive "${peer_config}" "persistent_keepalive"
 
+       if [ "${disabled}" -eq 1 ]; then
+               # skip disabled peers
+               return 0
+       fi
+
        if [ -z "$public_key" ]; then
                echo "Skipping peer config $peer_config because public key is not defined."
                return 0
index c0a5a0aa33c3224b757a33cbd98c8ae7edc02771..0126f699bb433e75bdc2ebb62b8a27a56769ba01 100644 (file)
@@ -17,6 +17,7 @@
 check_peer_activity() {
   local cfg=$1
   local iface=$2
+  local disabled
   local public_key
   local endpoint_host
   local endpoint_port
@@ -24,9 +25,16 @@ check_peer_activity() {
   local last_handshake
   local idle_seconds
 
+  config_get_bool disabled "${cfg}" "disabled" 0
   config_get public_key "${cfg}" "public_key"
   config_get endpoint_host "${cfg}" "endpoint_host"
   config_get endpoint_port "${cfg}" "endpoint_port"
+
+  if [ "${disabled}" -eq 1 ]; then
+    # skip disabled peers
+    return 0
+  fi
+
   persistent_keepalive=$(wg show ${iface} persistent-keepalive | grep ${public_key} | awk '{print $2}')
 
   # only process peers with endpoints and keepalive set