diff options
author | wbx <wbx@hydrogenium.(none)> | 2009-05-17 14:41:34 +0200 |
---|---|---|
committer | wbx <wbx@hydrogenium.(none)> | 2009-05-17 14:41:34 +0200 |
commit | 219a6dab8995aad9ac4860cc1a84d6f3509a03a4 (patch) | |
tree | b9c0f3c43aebba2fcfef777592d0add39f2072f4 /package/vpnc/files |
Initial import
Diffstat (limited to 'package/vpnc/files')
-rwxr-xr-x | package/vpnc/files/vpnc-route | 30 | ||||
-rwxr-xr-x | package/vpnc/files/vpnc-script | 118 | ||||
-rw-r--r-- | package/vpnc/files/vpnc.conf | 8 |
3 files changed, 156 insertions, 0 deletions
diff --git a/package/vpnc/files/vpnc-route b/package/vpnc/files/vpnc-route new file mode 100755 index 000000000..f39eb1355 --- /dev/null +++ b/package/vpnc/files/vpnc-route @@ -0,0 +1,30 @@ +#!/bin/sh + +#* VPNGATEWAY -- vpn gateway address (always present) +#* TUNDEV -- tunnel device (always present) +#* INTERNAL_IP4_ADDRESS -- address (always present) + +# define which traffic should be routed through the tunnel device +# any traffic that is not bound to a local interface will be +# mangled by the "main" routing table, so we add our rules to +# the main routing table + +# the setup for remote traffic and already bound traffic is done by +# the hotplug scripts. + +if [ "x$TUNDEV" == "x" ]; then + echo "No TUNDEV given. Script must be called from vpnc-script" + exit 1; +fi +case "$1" in + start) + # for each subnet that should be reached from this machine over the vpn tunnel, + # add a line like this: + # ip route add some.sub.net/msk dev $TUNDEV src $INTERNAL_IP4_ADDRESS + ;; + stop) + # remove the routing entries + ;; +esac; +exit 0; + diff --git a/package/vpnc/files/vpnc-script b/package/vpnc/files/vpnc-script new file mode 100755 index 000000000..16f1111fa --- /dev/null +++ b/package/vpnc/files/vpnc-script @@ -0,0 +1,118 @@ +#!/bin/sh +#* reason -- why this script was called, one of: pre-init connect disconnect +#* VPNGATEWAY -- vpn gateway address (always present) +#* TUNDEV -- tunnel device (always present) +#* INTERNAL_IP4_ADDRESS -- address (always present) +#* INTERNAL_IP4_NETMASK -- netmask (often unset) +#* INTERNAL_IP4_DNS -- list of dns serverss +#* INTERNAL_IP4_NBNS -- list of wins servers +#* CISCO_DEF_DOMAIN -- default domain name +#* CISCO_BANNER -- banner from server +#* CISCO_SPLIT_INC -- number of networks in split-network-list +#* CISCO_SPLIT_INC_%d_ADDR -- network address +#* CISCO_SPLIT_INC_%d_MASK -- subnet mask (for example: 255.255.255.0) +#* CISCO_SPLIT_INC_%d_MASKLEN -- subnet masklen (for example: 24) +#* CISCO_SPLIT_INC_%d_PROTOCOL -- protocol (often just 0) +#* CISCO_SPLIT_INC_%d_SPORT -- source port (often just 0) +#* CISCO_SPLIT_INC_%d_DPORT -- destination port (often just 0) + +do_pre_init() { + # bevore doing anything, make shure, the tun module is loaded and the + # tun device nodes exist. + if (exec 6<> /dev/net/tun) > /dev/null 2>&1 ; then + : + else # can't open /dev/net/tun + test -e /proc/sys/kernel/modprobe && `cat /proc/sys/kernel/modprobe` tun 2>/dev/null + # fix for broken devfs in kernel 2.6.x + if [ "`readlink /dev/net/tun`" = misc/net/tun \ + -a ! -e /dev/net/misc/net/tun -a -e /dev/misc/net/tun ] ; then + ln -sf /dev/misc/net/tun /dev/net/tun + fi + # make sure tun device exists + if [ ! -e /dev/net/tun ]; then + mkdir -p /dev/net + mknod -m 0640 /dev/net/tun c 10 200 + fi + fi + echo "pre-init successful." +} + +do_connect() { + # after connection is established, we should update resolv.conf + # and the kernel routing table + + # set up the interface + ifconfig $TUNDEV $INTERNAL_IP4_ADDRESS pointopoint $INTERNAL_IP4_ADDRESS mtu 1412 up + + # set up the route to the remote side and remove any cached routes + ip route add `ip route get "$VPNGATEWAY"` + ip route flush cache + + # set up the default routes via vpnc-route + echo "starting vpnc-route" + /etc/vpnc/vpnc-route start + + if [ "x$INTERNAL_IP4_DNS" != "x" ]; then + # set up the dns servers (add to resolv.conf) + echo "setting up DNS server" + # simply add the given servers to the resolv.conf file + echo "" > /var/run/vpnc/resolv.conf + for dns in $INTERNAL_IP4_DNS; do + echo "nameserver $dns" >> /var/run/vpnc/resolv.conf + done; + cat /etc/resolv.conf >> /var/run/vpnc/resolv.conf + mv /var/run/vpnc/resolv.conf /etc/resolv.conf + # keep the DNS server IPs for shutdown + echo "$INTERNAL_IP4_DNS" > /var/run/vpnc/dnsserver + fi + +} + +do_disconnect() { + # remove the nameserver from resolv.conf + # and restore the old routing table + + # remove route to gateway + ip route del $VPNGATEWAY + + # remove default routes + /etc/vpnc/vpnc-route stop + + # remove the dns servers from resolv.conf + if [ -f /var/run/vpnc/dnsserver ]; then + re_dns=""; + for dns in `cat /var/run/vpnc/dnsserver`; do + echo "removing DNS server $dns"; + if [ "x$re_dns" == "x" ]; then + re_dns=\($dns\); + else + re_dns=$re_dns\|\($dns\); + fi; + done; + echo "re_dns=$re_dns" + cat /etc/resolv.conf | grep -v -E "($re_dns)|(^\ *$)" > /var/run/vpnc/resolv.conf + mv /var/run/vpnc/resolv.conf /etc/resolv.conf + rm /var/run/vpnc/dnsserver + fi; + + # deconfigure network interface + ifconfig $TUNDEV down +} + +case "$reason" in + pre-init) + do_pre_init + ;; + connect) + do_connect + ;; + disconnect) + do_disconnect + ;; + *) + echo "unknown reason '$reason'. Maybe vpnc-script is out of date" 1>&2 + exit 1 + ;; +esac + +exit 0 diff --git a/package/vpnc/files/vpnc.conf b/package/vpnc/files/vpnc.conf new file mode 100644 index 000000000..3f515e08c --- /dev/null +++ b/package/vpnc/files/vpnc.conf @@ -0,0 +1,8 @@ +IPSec gateway vpn-gateway.tld +IPSec ID group_id +IPSec secret group_password +Xauth username your_username +Xauth password your_password +# DNSUpdate no + + |