-
-
Save torkildr/8931272 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Place it in /jffs/etc/config/altibox-6rd.wanup, and then ln -s /jffs/etc/config/altibox-6rd.ipup to it. | |
# This script is inredible untested, and is currently used mostly as notes... | |
# The Altibox 6rd gateway. | |
REMOTE=213.167.115.92 | |
# Your local IP address. | |
LOCAL="$(ifconfig eth1 | sed -n '/inet /{s/.*addr://;s/ .*//;p}')" | |
LOCAL_HEX=$(printf '%02X%02X%02X%02X' $(echo $LOCAL | tr '.' ' ') | awk '{print substr($1,1, | |
1) substr($1,2,4) substr($1,6)}') | |
# this will only work with prefix length 30 | |
LOCAL_PREFIX=$(printf %X $(echo -n "$(printf %d 0x$LOCAL_HEX) 4 mul p"|dc)) | |
# hacky way to "do" impresise 64-bit math, also only works with prefix length 30 | |
LOCAL_MSB=$(echo -n "16 o 0x$LOCAL_PREFIX 0x2A01079C00000000 add 0x100000000 div p" | dc) | |
LOCAL_LSB=$(echo -n "16 o 0x$LOCAL_PREFIX 0xffffffff and p" |dc) | |
V6PREFIX=$(echo -n $LOCAL_MSB$LOCAL_LSB | awk '{print substr($1,1,4) ":" substr($1,5,4) ":" substr($1,9,4) ":" substr($1, 13, 4)}') | |
# The local address that will wind up assigned to your bridge | |
V6LOCAL=$V6PREFIX::1/62 | |
# The remote address bound to the sit tunnel to the 6rd gateway | |
V6REMOTE=$V6PREFIX::2/30 | |
# The name of the tunnel | |
TUNNEL=altibox-6rd | |
# The MTU of the tunnel. It is the PPP MTU - 20 bytes. | |
MTU=1472 | |
# Make sure we have needed kernel modules | |
insmod ipv6 | |
insmod sit | |
# Clean up any leftovers. This ensures we start with a fresh tunnel whenever the PPP link bounces. | |
killall radvd | |
ip -6 addr flush dev br0 scope global | |
ip -6 addr flush dev $TUNNEL scope global | |
ip -6 route flush dev br0 | |
ip -6 route flush dev $TUNNEL | |
ip link set $TUNNEL down | |
ip tunnel del $TUNNEL | |
# Create our tunnel. | |
ip tunnel add $TUNNEL mode sit remote $REMOTE local $LOCAL ttl 64 | |
ip link set $TUNNEL up | |
ip link set mtu $MTU dev $TUNNEL | |
ip addr add $V6REMOTE dev $TUNNEL | |
ip addr add $V6LOCAL dev br0 | |
ip route add ::/0 dev $TUNNEL | |
# Make sure we forward IPv6 packets | |
echo 1 > /proc/sys/net/ipv6/conf/all/forwarding | |
# Create an RADVD config file and start radvd to let everyone on our local network get an auto-assigned IP6 address. | |
cat >/tmp/radvd.conf <<EOF | |
interface br0 { | |
AdvLinkMTU $MTU; | |
AdvSendAdvert on; | |
prefix $V6PREFIX::/64 { | |
AdvOnLink on; | |
AdvAutonomous on; | |
AdvRouterAddr on; | |
}; | |
}; | |
EOF | |
radvd -C /tmp/radvd.conf | |
# Profit. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment