From 9e053b621af0134ec52f4b5b30601b756f22af7b Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sun, 16 Feb 2014 11:32:16 +0800 Subject: [PATCH] vpnc-script: split disconnect and destroy The tun/tap device can be created outside vpnc (or openconnect) and aimed to be persisten. In this case vpnc-script should not destroy it when the VPN is disconnected. - Split existing reason "disconnect" in "disconnect_only" and "destroy". - Add new hooks for pre/post destroy. - Keep backward compatibility with aggregate reason "disconnect". - Add reason "disconnect_destroy" equivalent to existing reason "disconnect". Notice: it's _not_ fully equivalent calling reason "disconnect" or in sequence "disconnect_only" followed by "destroy", due to different order of calling hooks. This is done on purpose for backward compatibility. Based on patch from Alon Bar-Lev http://lists.unix-ag.uni-kl.de/pipermail/vpnc-devel/2013-December/004037.html Signed-off-by: Antonio Borneo --- trunk/vpnc-script | 21 ++++++++++++++++++++- 1 files changed, 20 insertions(+), 1 deletions(-) diff --git a/trunk/vpnc-script b/trunk/vpnc-script index 5e9b00f..a164331 100755 --- a/trunk/vpnc-script +++ b/trunk/vpnc-script @@ -21,7 +21,9 @@ ################ # # List of parameters passed through environment -#* reason -- why this script was called, one of: pre-init connect disconnect reconnect +#* reason -- why this script was called, one of: pre-init connect disconnect +# disconnect_destroy disconnect_only destroy reconnect +# (disconnect and disconnect_destroy are equivalent) #* VPNGATEWAY -- vpn gateway address (always present) #* TUNDEV -- tunnel device (always present) #* INTERNAL_IP4_ADDRESS -- address (always present) @@ -723,6 +725,9 @@ do_disconnect() { if [ -n "$INTERNAL_IP4_DNS" ]; then $RESTORERESOLVCONF fi +} + +do_destroy() { destroy_tun_device } @@ -744,10 +749,24 @@ case "$reason" in run_hooks post-connect ;; disconnect) + disconnect_destroy) run_hooks disconnect do_disconnect + run_hooks destroy + do_destroy + run_hooks post-destroy run_hooks post-disconnect ;; + disconnect_only) + run_hooks disconnect + do_disconnect + run_hooks post-disconnect + ;; + destroy) + run_hooks destroy + do_destroy + run_hooks post-destroy + ;; reconnect) run_hooks reconnect ;; -- 1.7.3.4