This is more controversial part of my patch: watching and reconnecting scripts. I've tried to implement the simplest watch scenario with minimum extra configuration: option keepalive_interval.
Signed-off-by: Dmitri Bogomolov <[email protected]> diff --git a/net/vpnc/Makefile b/net/vpnc/Makefile index 66cad8b..1c66c6c 100644 --- a/net/vpnc/Makefile +++ b/net/vpnc/Makefile @@ -61,6 +61,13 @@ define Package/vpnc/install echo "Noninteractive" >> $(PKG_INSTALL_DIR)/etc/vpnc/default.conf $(INSTALL_CONF) $(PKG_INSTALL_DIR)/etc/vpnc/default.conf $(1)/etc/vpnc/ + $(INSTALL_BIN) ./files/watch.sh $(1)/etc/vpnc/ + $(INSTALL_DIR) $(1)/etc/vpnc/post-connect.d + $(INSTALL_BIN) ./files/start_watch $(1)/etc/vpnc/post-connect.d/ + $(INSTALL_DIR) $(1)/etc/vpnc/post-disconnect.d + $(INSTALL_BIN) ./files/stop_watch $(1)/etc/vpnc/post-disconnect.d/ + $(INSTALL_DIR) $(1)/etc/hotplug.d/iface + $(INSTALL_BIN) ./files/vpnc.hotplug $(1)/etc/hotplug.d/iface/30-vpnc $(INSTALL_DIR) $(1)/etc/config $(INSTALL_CONF) ./files/vpnc.config $(1)/etc/config/vpnc $(INSTALL_DIR) $(1)/etc/init.d diff --git a/net/vpnc/files/start_watch b/net/vpnc/files/start_watch new file mode 100644 index 0000000..4789e84 --- /dev/null +++ b/net/vpnc/files/start_watch @@ -0,0 +1,8 @@ +. /etc/init.d/vpnc +. /lib/config/uci.sh + +local keepalive_interval=$(uci_get vpnc config keepalive_interval 300) +if [ $keepalive_interval -gt 0 ]; then + /etc/vpnc/watch.sh $INTERNAL_IP4_DNS $keepalive_interval $PID_F & + echo $! > /var/run/vpnc_watch.pid +fi diff --git a/net/vpnc/files/stop_watch b/net/vpnc/files/stop_watch new file mode 100644 index 0000000..dcea0b7 --- /dev/null +++ b/net/vpnc/files/stop_watch @@ -0,0 +1,3 @@ +PID_F=/var/run/vpnc_watch.pid +[ -f $PID_F ] && kill -KILL $(cat $PID_F) +rm -f $PID_F diff --git a/net/vpnc/files/vpnc.config b/net/vpnc/files/vpnc.config index ebeb81d..7d4dda7 100644 --- a/net/vpnc/files/vpnc.config +++ b/net/vpnc/files/vpnc.config @@ -4,3 +4,4 @@ config vpnc config # option ipsec_secret 'your secret' # option xauth_username 'username' # option xauth_password 'password' + option keepalive_interval 300 diff --git a/net/vpnc/files/vpnc.hotplug b/net/vpnc/files/vpnc.hotplug new file mode 100644 index 0000000..1cce1e2 --- /dev/null +++ b/net/vpnc/files/vpnc.hotplug @@ -0,0 +1,7 @@ +#!/bin/sh + +[ "$ACTION" = ifup -o "$ACTION" = ifupdate ] || exit 0 +if $(/etc/init.d/vpnc enabled) && [ $(fw3 -q network $INTERFACE) = wan ]; then + logger -t vpnc "Restarting due to ifup of $INTERFACE" + /etc/init.d/vpnc restart +fi diff --git a/net/vpnc/files/watch.sh b/net/vpnc/files/watch.sh new file mode 100644 index 0000000..3e13b53 --- /dev/null +++ b/net/vpnc/files/watch.sh @@ -0,0 +1,25 @@ +#!/bin/sh +# Simple watch script for VPNC + +KEEPALIVE_HOST=$1 +KEEPALIVE_INTERVAL=$2 +PID_F=$3 + +alive_test () { + ping -c2 -q $KEEPALIVE_HOST >> /dev/null + #nslookup $KEEPALIVE_HOST $KEEPALIVE_HOST >> /dev/null + echo $? +} + +while true; do + if [ $(alive_test) -eq 0 ]; then + sleep $KEEPALIVE_INTERVAL + else + # FIXME: what if alive_test continuously fails? + if [ -f $PID_F ]; then + logger -t vpnc "Restarting due to alive test failure" + /etc/init.d/vpnc restart + fi + exit 0 + fi +done _______________________________________________ openwrt-devel mailing list [email protected] https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
