Hotplug script and config file to establish a 6-to-4 tunnel using a IPv6 public 
relay or tunnel broker.

Signed-off-by: Conrad Hirano <[EMAIL PROTECTED]>


Index: packages/ipv6/6to4/files/etc/hotplug.d/iface/10-ipv6
===================================================================
--- packages/ipv6/6to4/files/etc/hotplug.d/iface/10-ipv6        (revision 0)
+++ packages/ipv6/6to4/files/etc/hotplug.d/iface/10-ipv6        (revision 0)
@@ -0,0 +1,80 @@
+#!/bin/sh
+# Copyright (C) 2008 OpenWrt.org
+
+TUNNEL=tun6to4
+
+. /etc/functions.sh
+
+config_cb() {
+       local cfg="$CONFIG_SECTION"
+       local cfgtype
+       local ip6add
+
+       config_get cfgtype "$cfg" TYPE
+
+       if [ "$cfgtype" = ipv6 ]
+       then
+               config_get REMOTE $cfg remote
+
+               if [ "$REMOTE" = relay ]
+               then
+                       ip6add=`echo $IP4LOC | awk -F. '{ printf 
"2002:%02x%02x:%02x%02x::1", $1, $2, $3, $4 }'`
+                       IP4REM="any"
+                       IP6TUN="${ip6add}/16"
+                       IP6REM="::192.88.99.1"
+                       IP6LOC="${ip6add}/64"
+               else
+                       config_get ip6add $cfg local6
+                       IP4REM="${REMOTE}"
+                       IP6TUN="${ip6add}/64"
+                       config_get IP6REM $cfg remote6
+                       config_get IP6LOC lan  ip6addr
+               fi
+       fi
+}
+
+del_ip6addr() {
+       local file=/var/state/network.$$
+       grep -v "^config_set 'wan' 'ip6addr' " /var/state/network > "$file"
+       mv "$file" /var/state/network
+}
+
+if [ "$INTERFACE" = wan ]
+then
+       . /var/state/network
+       config_get  IP4LOC wan ipaddr
+       config_get  IP6WAN wan ip6addr
+       config_get  IFNAME lan ifname
+       config_load ipv6
+
+       case $ACTION in
+               ifup)
+                       if [ ! "$IP6WAN" ]
+                       then
+                               ip tunnel add $TUNNEL mode sit ttl 255 remote 
$IP4REM local $IP4LOC
+                               ip link set $TUNNEL up
+                               ip -6 addr add $IP6TUN dev $TUNNEL
+                               ip -6 route add 2000::/3 via $IP6REM dev 
$TUNNEL metric 1
+                               [ "$REMOTE" = relay ] && ip -6 addr add $IP6LOC 
dev $IFNAME
+                               uci set "/var/state/network.wan.ip6addr=$IP6TUN"
+                       else
+                               ip tunnel change $TUNNEL local $IP4LOC
+                               if [ "$IP6WAN" != "$IP6TUN" ]
+                               then
+                                       ip -6 addr flush to 2002::/16
+                                       ip -6 addr add $IP6TUN dev $TUNNEL
+                                       ip -6 addr add $IP6LOC dev $IFNAME
+                                       del_ip6addr                             
        
+                                       uci set 
"/var/state/network.wan.ip6addr=$IP6TUN"
+                               fi
+                       fi
+               ;;
+               ifdown)
+                       ip -6 route flush dev $TUNNEL
+                       ip link set dev $TUNNEL down
+                       ip tunnel del $TUNNEL
+                       [ "$REMOTE" = relay ] && ip -6 addr del $IP6LOC dev 
$IFNAME
+                       del_ip6addr
+               ;;
+       esac
+fi
Index: packages/ipv6/6to4/files/etc/config/ipv6
===================================================================
--- packages/ipv6/6to4/files/etc/config/ipv6    (revision 0)
+++ packages/ipv6/6to4/files/etc/config/ipv6    (revision 0)
@@ -0,0 +1,8 @@
+config ipv6
+       option remote   relay
+
+# Use a public relay, i.e. 192.88.99.1, or specify parameters supplied by a 
tunnel broker.
+
+#      option remote   xxx.xxx.xxx.xxx
+#      option local6   2001:db8::2
+#      option remote6  2001:db8::1
Index: packages/ipv6/6to4/Makefile
===================================================================
--- packages/ipv6/6to4/Makefile (revision 0)
+++ packages/ipv6/6to4/Makefile (revision 0)
@@ -0,0 +1,36 @@
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=6to4
+PKG_VERSION:=1.0.0
+PKG_RELEASE:=1
+
+PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
+
+include $(INCLUDE_DIR)/package.mk
+
+define Package/6to4
+       SECTION:=ipv6
+       CATEGORY:=IPv6
+       TITLE:=IPv6 tunnel hotplug script
+       DEPENDS:=+kmod-ipv6 +ip
+endef
+
+define Package/6to4/description
+       Hotplug script to establish a 6-to-4 tunnel
+endef
+
+define Build/Prepare
+endef
+
+define Build/Configure
+endef
+
+define Build/Compile
+endef
+
+define Package/6to4/install
+       $(INSTALL_DIR) $(1)
+       $(CP) ./files/* $(1)/
+endef
+
+$(eval $(call BuildPackage,6to4))
_______________________________________________
openwrt-devel mailing list
[email protected]
http://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel

Reply via email to