From 4f7e6ba76544895a63bd7b9074ecf6fad8b16d74 Mon Sep 17 00:00:00 2001
From: Richard Muzik <richard.muzik@nic.cz>
Date: Mon, 11 Dec 2023 12:53:08 +0100
Subject: [PATCH] patches/packages/openvpn: fix ipchange hotplug event

Patch taken from OpenWrt:
- https://github.com/openwrt/packages/commit/808f67d6152fcac09dcda4d66e2bb285878fb3d4
- https://github.com/openwrt/packages/issues/21200
---
 ...2-openvpn-fix-ipchange-hotplug-event.patch | 59 +++++++++++++++++++
 1 file changed, 59 insertions(+)
 create mode 100644 patches/packages/pending/0002-openvpn-fix-ipchange-hotplug-event.patch

diff --git a/patches/packages/pending/0002-openvpn-fix-ipchange-hotplug-event.patch b/patches/packages/pending/0002-openvpn-fix-ipchange-hotplug-event.patch
new file mode 100644
index 000000000..24508cf8a
--- /dev/null
+++ b/patches/packages/pending/0002-openvpn-fix-ipchange-hotplug-event.patch
@@ -0,0 +1,59 @@
+From 808f67d6152fcac09dcda4d66e2bb285878fb3d4 Mon Sep 17 00:00:00 2001
+From: Ivan Pavlov <AuthorReflex@gmail.com>
+Date: Wed, 7 Jun 2023 20:58:42 +0300
+Subject: [PATCH] openvpn: fix ipchange hotplug event
+
+In f8a8b71e26b9bdbf86fbb7d4d1482637af7f3ba4 openvpn introduced new hotplug events.
+For server config, ipchange hotplug event produces an error.
+So, make ipchange hotplug event for client only
+
+Fixes https://github.com/openwrt/packages/issues/21200
+
+Signed-off-by: Ivan Pavlov <AuthorReflex@gmail.com>
+---
+ net/openvpn/Makefile           | 2 +-
+ net/openvpn/files/openvpn.init | 5 +++--
+ 2 files changed, 4 insertions(+), 3 deletions(-)
+
+diff --git a/net/openvpn/Makefile b/net/openvpn/Makefile
+index 213f027fd..ac76841b8 100644
+--- a/net/openvpn/Makefile
++++ b/net/openvpn/Makefile
+@@ -10,7 +10,7 @@ include $(TOPDIR)/rules.mk
+ PKG_NAME:=openvpn
+ 
+ PKG_VERSION:=2.5.3
+-PKG_RELEASE:=4
++PKG_RELEASE:=5
+ 
+ PKG_SOURCE_URL:=\
+ 	https://build.openvpn.net/downloads/releases/ \
+diff --git a/net/openvpn/files/openvpn.init b/net/openvpn/files/openvpn.init
+index b5f612e46..6eb305135 100644
+--- a/net/openvpn/files/openvpn.init
++++ b/net/openvpn/files/openvpn.init
+@@ -140,10 +140,11 @@ openvpn_get_credentials() {
+ openvpn_add_instance() {
+ 	local name="$1"
+ 	local dir="$2"
+-	local conf="$3"
++	local conf=$(basename "$3")
+ 	local security="$4"
+ 	local up="$5"
+ 	local down="$6"
++	local client=$(grep -qEx "client|tls-client" "$dir/$conf" && echo 1)
+ 
+ 	procd_open_instance "$name"
+ 	procd_set_param command "$PROG"	\
+@@ -155,7 +156,7 @@ openvpn_add_instance() {
+ 		--down "/usr/libexec/openvpn-hotplug down $name" \
+ 		--route-up "/usr/libexec/openvpn-hotplug route-up $name" \
+ 		--route-pre-down "/usr/libexec/openvpn-hotplug route-pre-down $name" \
+-		--ipchange "/usr/libexec/openvpn-hotplug ipchange $name" \
++		${client:+--ipchange "/usr/libexec/openvpn-hotplug ipchange $name"} \
+ 		${up:+--setenv user_up "$up"} \
+ 		${down:+--setenv user_down "$down"} \
+ 		--script-security "${security:-2}" \
+-- 
+2.43.0
+
-- 
GitLab