Release new version 0.19.7
[grml-etc-core.git] / usr_share_grml / zsh / functions / ipv6-tunnel
1 # set up an ipv6 tunnel
2 emulate -L zsh
3
4 case $1 in
5 start)
6     if ifconfig sit1 2>/dev/null | grep -q 'inet6 addr: 2002:.*:1::1' ; then
7         print 'ipv6 tunnel already set up, nothing to be done.'
8         print 'execute: "ifconfig sit1 down ; ifconfig sit0 down" to remove ipv6-tunnel.' ; return 1
9     else
10         [[ -n "$PUBLIC_IP" ]] || \
11             local PUBLIC_IP=$(ifconfig $(route -n | awk '/^0\.0\.0\.0/{print $8; exit}') | \
12             awk '/inet addr:/ {print $2}' | tr -d 'addr:')
13
14         [[ -n "$PUBLIC_IP" ]] || {
15             print 'No $PUBLIC_IP set and could not determine default one.'
16             return 1
17         }
18         local IPV6ADDR=$(printf "2002:%02x%02x:%02x%02x:1::1" $(print ${PUBLIC_IP//./ }))
19         print -n "Setting up ipv6 tunnel $IPV6ADDR via ${PUBLIC_IP}: "
20         ifconfig sit0 tunnel ::192.88.99.1 up
21         ifconfig sit1 add "$IPV6ADDR" && print done || print failed
22     fi
23     ;;
24 status)
25     if ifconfig sit1 2>/dev/null | grep -q 'inet6 addr: 2002:.*:1::1' ; then
26         print 'ipv6 tunnel available' ; return 0
27     else
28         print 'ipv6 tunnel not available' ; return 1
29     fi
30     ;;
31 stop)
32     if ifconfig sit1 2>/dev/null | grep -q 'inet6 addr: 2002:.*:1::1' ; then
33         print -n 'Stopping ipv6 tunnel (sit0 + sit1): '
34         ifconfig sit1 down ; ifconfig sit0 down && print done || print failed
35     else
36         print 'No ipv6 tunnel found, nothing to be done.' ; return 1
37     fi
38     ;;
39 *)
40     print "Usage: ipv6-tunnel [start|stop|status]">&2 ; return 1
41     ;;
42 esac