From 8c9688f82f1493112c5c91cba085268f53950b03 Mon Sep 17 00:00:00 2001 From: "Ycarus (Yannick Chabanois)" Date: Wed, 13 Mar 2024 09:44:10 +0100 Subject: [PATCH] Update OpenVPN to 2.6.9 --- openvpn/Makefile | 6 +- openvpn/files/etc/hotplug.d/openvpn/01-user | 7 +- openvpn/files/openvpn.init | 110 +++++++++++++------- 3 files changed, 79 insertions(+), 44 deletions(-) diff --git a/openvpn/Makefile b/openvpn/Makefile index 752d38535..349c7e1cb 100644 --- a/openvpn/Makefile +++ b/openvpn/Makefile @@ -9,14 +9,14 @@ include $(TOPDIR)/rules.mk PKG_NAME:=openvpn -PKG_VERSION:=2.6.5 -PKG_RELEASE:=1 +PKG_VERSION:=2.6.9 +PKG_RELEASE:=10 PKG_SOURCE_URL:=\ https://build.openvpn.net/downloads/releases/ \ https://swupdate.openvpn.net/community/releases/ PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz -PKG_HASH:=e34efdb9a3789a760cfc91d57349dfb1e31da169c98c06cb490c6a8a015638e2 +PKG_HASH:=e08d147e15b4508dfcd1d6618a1f21f1495f9817a8dadc1eddf0532fa116d7e3 PKG_MAINTAINER:=Magnus Kroken diff --git a/openvpn/files/etc/hotplug.d/openvpn/01-user b/openvpn/files/etc/hotplug.d/openvpn/01-user index 4c72f1c4b..f6ad8935e 100644 --- a/openvpn/files/etc/hotplug.d/openvpn/01-user +++ b/openvpn/files/etc/hotplug.d/openvpn/01-user @@ -7,10 +7,14 @@ $* } -# Wrap user defined scripts on up/down events +# Wrap user defined scripts on up/down/route-up/route-pre-down/ipchange events +# Scriptp set with up/down/route-up/route-pre-down/ipchange in the openvpn config are also executed with the command=user_xxxx case "$ACTION" in up) command=$user_up ;; down) command=$user_down ;; + route-up) command=$user_route_up ;; + route-pre-down) command=$user_route_pre_down ;; + ipchange) command=$user_ipchange ;; *) command= ;; esac @@ -20,3 +24,4 @@ if [ -n "$command" ]; then fi exit 0 + diff --git a/openvpn/files/openvpn.init b/openvpn/files/openvpn.init index 34c6f3511..5c1beb0e3 100644 --- a/openvpn/files/openvpn.init +++ b/openvpn/files/openvpn.init @@ -10,22 +10,13 @@ STOP=10 USE_PROCD=1 PROG=/usr/sbin/openvpn +PATH_INSTANCE_DIR="/etc/openvpn" LIST_SEP=" " UCI_STARTED= UCI_DISABLED= -version_over_5_4() { - MAJOR_VERSION=$(uname -r | awk -F '.' '{print $1}') - MINOR_VERSION=$(uname -r | awk -F '.' '{print $2}') - if [ $MAJOR_VERSION -ge 5 ] && [ $MINOR_VERSION -gt 13 ] || [ $MAJOR_VERSION -gt 5 ] ; then - return 0 - else - return 1 - fi -} - append_param() { local s="$1" local v="$2" @@ -154,6 +145,9 @@ openvpn_add_instance() { local security="$4" local up="$5" local down="$6" + local route_up="$7" + local route_pre_down="$8" + local ipchange="$9" local client=$(grep -qEx "client|tls-client" "$dir/$conf" && echo 1) procd_open_instance "$name" @@ -169,12 +163,12 @@ openvpn_add_instance() { ${client:+--ipchange "/usr/libexec/openvpn-hotplug ipchange $name"} \ ${up:+--setenv user_up "$up"} \ ${down:+--setenv user_down "$down"} \ + ${route_up:+--setenv user_route_up "$route_up"} \ + ${route_pre_down:+--setenv user_route_pre_down "$route_pre_down"} \ + ${client:+${ipchange:+--setenv user_ipchange "$ipchange"}} \ --script-security "${security:-2}" \ $(openvpn_get_dev "$name" "$conf") \ $(openvpn_get_credentials "$name" "$conf") - if version_over_5_4; then - procd_append_param command "--mptcp" - fi procd_set_param file "$dir/$conf" procd_set_param term_timeout 15 procd_set_param respawn @@ -184,7 +178,7 @@ openvpn_add_instance() { procd_close_instance } -start_instance() { +start_uci_instance() { local s="$1" config_get config "$s" config @@ -195,18 +189,25 @@ start_instance() { return 1 } - local up down script_security + local up down route_up route_pre_down ipchange script_security config_get up "$s" up config_get down "$s" down + config_get route_up "$s" route_up + config_get route_pre_down "$s" route_pre_down + config_get ipchange "$s" ipchange config_get script_security "$s" script_security [ ! -d "/var/run" ] && mkdir -p "/var/run" if [ ! -z "$config" ]; then append UCI_STARTED "$config" "$LIST_SEP" + [ -n "$script_security" ] || get_openvpn_option "$config" script_security script-security [ -n "$up" ] || get_openvpn_option "$config" up up [ -n "$down" ] || get_openvpn_option "$config" down down - openvpn_add_instance "$s" "${config%/*}" "$config" "$script_security" "$up" "$down" + [ -n "$route_up" ] || get_openvpn_option "$config" route_up route-up + [ -n "$route_pre_down" ] || get_openvpn_option "$config" route_pre_down route-pre-down + [ -n "$ipchange" ] || get_openvpn_option "$config" ipchange ipchange + openvpn_add_instance "$s" "${config%/*}" "$config" "$script_security" "$up" "$down" "$route_up" "$route_pre_down" "$ipchange" return fi @@ -216,7 +217,47 @@ start_instance() { append_params "$s" $OPENVPN_PARAMS append_list "$s" $OPENVPN_LIST - openvpn_add_instance "$s" "/var/etc" "openvpn-$s.conf" "$script_security" "$up" "$down" + openvpn_add_instance "$s" "/var/etc" "openvpn-$s.conf" "$script_security" "$up" "$down" "$route_up" "$route_pre_down" "$ipchange" +} + +start_path_instances() { + local path name + + for path in ${PATH_INSTANCE_DIR}/*.conf; do + [ -f "$path" ] && { + name="${path##*/}" + name="${name%.conf}" + start_path_instance "$name" + } + done +} + +start_path_instance() { + local name="$1" + + local path name up down route_up route_pre_down ipchange + + path="${PATH_INSTANCE_DIR}/${name}.conf" + + # don't start configs again that are already started by uci + if echo "$UCI_STARTED" | grep -qxF "$path"; then + logger -t openvpn "$name.conf already started" + return + fi + + # don't start configs which are set to disabled in uci + if echo "$UCI_DISABLED" | grep -qxF "$path"; then + logger -t openvpn "$name.conf is disabled in /etc/config/openvpn" + return + fi + + get_openvpn_option "$path" up up || up="" + get_openvpn_option "$path" down down || down="" + get_openvpn_option "$path" route_up route-up || route_up="" + get_openvpn_option "$path" route_pre_down route-pre-down || route_pre_down="" + get_openvpn_option "$path" ipchange ipchange || ipchange="" + + openvpn_add_instance "$name" "${path%/*}" "$path" "" "$up" "$down" "$route_up" "$route_pre_down" "$ipchange" } start_service() { @@ -238,31 +279,20 @@ start_service() { config_load 'openvpn' if [ -n "$instance" ]; then - [ "$instance_found" -gt 0 ] || return - start_instance "$instance" + if [ "$instance_found" -gt 0 ]; then + start_uci_instance "$instance" + elif [ -f "${PATH_INSTANCE_DIR}/${instance}.conf" ]; then + start_path_instance "$instance" + fi else - config_foreach start_instance 'openvpn' + config_foreach start_uci_instance 'openvpn' - local path name up down - for path in /etc/openvpn/*.conf; do - if [ -f "$path" ]; then - name="${path##*/}"; name="${name%.conf}" - - # don't start configs again that are already started by uci - if echo "$UCI_STARTED" | grep -qxF "$path"; then - continue - - # don't start configs which are set to disabled in uci - elif echo "$UCI_DISABLED" | grep -qxF "$path"; then - logger -t openvpn "$name.conf is disabled in /etc/config/openvpn" - continue - fi - - get_openvpn_option "$path" up up || up="" - get_openvpn_option "$path" down down || down="" - openvpn_add_instance "$name" "${path%/*}" "$path" "" "$up" "$down" - fi - done + auto="$(uci_get openvpn globals autostart 1)" + if [ "$auto" = "1" ]; then + start_path_instances + else + logger -t openvpn "Autostart for configs in '$PATH_INSTANCE_DIR/*.conf' disabled" + fi fi }