2

My university has a special wireless network that requires you to use a VPN to get into the internet. So I have little script that connects me to the VPN once I get into the wireless:

/etc/NetworkManager/dispatcher.d/99bonnet:

if [[ "$1" != "wlan0" ]]
then
    return
fi

# Kill vpnc if it is still active
if pgrep vpnc
then
    vpnc-disconnect
fi

# Exit if we are not connected to bonnet
if ! iwconfig wlan0 | grep bonnet
then
    return 0
fi

# Handle the action
if [[ "$2" == up ]]
then
    vpnc "$vpn_config_file"
else
    vpnc-disconnect
fi

This works like a charm and connects and disconnects the VPN with the wifi. The problem is that vpnc has a tendency to die on me. Is there some way to respawn the vpnc if it dies? There is a nice wiki about process management, but it seems that I cannot really use inittab for my purpose here, or at least not straight forward.

What would be a non hack way to respawn vpnc if it dies while I am connected to the certain wireless?

1 Answer 1

1

If you've noticed vpnc dies after around the same amount of time being connected, you may want to try to disable DPD:

   --dpd-idle <0,10-86400>
          Send DPD packet after not receiving anything for <idle> seconds.  Use 0 to disable DPD completely (both ways).
          Default: 300
   conf-variable: DPD idle timeout (our side) <0,10-86400>

(taken from the vpnc man page)

The parameter above (--dpd-idle 0) will disable dead peer detection and avoid the connection stopping if the packets don't reach you in time. You can otherwise set it in your config file as described above.

I think I'd also edit your startup script a little to avoid unconditionally stopping vpnc "if it's still active". You may be running into different state changes than "up" and "down" (for instance, you have "hostname"); for instance when roaming from access point to access point due to signal level changes or otherwise you might get a new "up". In other words:

# Exit if we are not connected to bonnet
if ! iwconfig wlan0 | grep bonnet then
    # Kill vpnc if it is still active
    if pgrep vpnc then
        vpnc-disconnect
    fi
    return 0
fi

Instead of doing two separate checks. (though I didn't test that)

3
  • The last point is valid indeed, I will change that. And the DPD would mean that if it disconnects after 5 mins idle, that would be it, right? Commented Nov 3, 2011 at 7:40
  • it's the most likely cause if it consistently disconnects after a specific amount of time (eg. always after 5 minutes) Commented Nov 25, 2011 at 17:45
  • I tried setting it to zero. I do not get disconnected, but if the network glitches, I cannot reconnect for quite a while. So I guess the timeout has its use … Commented Nov 25, 2011 at 21:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .