Skip to content

Instantly share code, notes, and snippets.

@Blaok
Created November 1, 2015 07:09
Show Gist options
  • Save Blaok/d686175bb5a734c4c9ee to your computer and use it in GitHub Desktop.
Save Blaok/d686175bb5a734c4c9ee to your computer and use it in GitHub Desktop.
ISATAP Daemon. Tested and used under OpenWRT and Arch Linux.
#!/bin/sh
IFACE6=sit1
V4_REMOTE="166.111.21.1"
V6_REMOTE="2402:f000:1:1501:200:5efe"
V6_LOCAL="fe80::200:5efe"
while true
do
IFACE4=`ip route|grep default|awk -F ' ' '{print $5}'`
ip=`ip addr show dev $IFACE4 | sed -e's/^.*inet \([^ ]*\)\/.*$/\1/;t;d'`
ip4=`echo $ip|sed -e 's/\./ /g'`
IP4=`printf '%02x%02x:%02x%02x' $ip4`
IP6=`ip addr show dev $IFACE6 | sed -e's/^.*inet6 \([^ ]*\)\/.*$/\1/;t;d' | egrep -o '[0-9a-f]{4}:[0-9a-f]{4}$' -m 1`
if [ "$IP4" != "$IP6" ] && [ ! -e "$IP4" ]
then
echo "$IP4" != "$IP6"
ip -6 route del default via $V6_REMOTE:$V4_REMOTE metric 256
ip tunnel del $IFACE6
sleep 1s
ip tunnel add $IFACE6 mode sit remote $V4_REMOTE local $ip
ifconfig $IFACE6 up
ifconfig $IFACE6 add $V6_LOCAL:$ip/64
ifconfig $IFACE6 add $V6_REMOTE:$ip/64
ifconfig $IFACE6 del fe80::$ip/64
ip -6 route add default via $V6_REMOTE:$V4_REMOTE metric 256 dev $IFACE6
else
sleep 1s
fi
done &
if [ ! -e "$1" ]
then
echo $! | tee $1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment