aboutsummaryrefslogtreecommitdiffstats
path: root/package/odhcp6c
diff options
context:
space:
mode:
authorSteven Barth <steven@midlink.org>2013-05-24 13:03:50 +0000
committerSteven Barth <steven@midlink.org>2013-05-24 13:03:50 +0000
commitd698f749801a0e0655829d0ea7e383bdfd0fad37 (patch)
treee71e7e4d3440d35e7a221838572f3f6a8382fa13 /package/odhcp6c
parent545b4169d1a645c0263ce792f823345ac9c498d4 (diff)
downloadupstream-d698f749801a0e0655829d0ea7e383bdfd0fad37.tar.gz
upstream-d698f749801a0e0655829d0ea7e383bdfd0fad37.tar.bz2
upstream-d698f749801a0e0655829d0ea7e383bdfd0fad37.zip
AA: backport odhcp6c from trunk
git-svn-id: svn://svn.openwrt.org/openwrt/branches/attitude_adjustment@36710 3c298f89-4303-0410-b956-a3cf2f4a3e73
Diffstat (limited to 'package/odhcp6c')
-rw-r--r--package/odhcp6c/Makefile39
-rwxr-xr-xpackage/odhcp6c/files/dhcpv6.script110
-rwxr-xr-xpackage/odhcp6c/files/dhcpv6.sh57
3 files changed, 206 insertions, 0 deletions
diff --git a/package/odhcp6c/Makefile b/package/odhcp6c/Makefile
new file mode 100644
index 0000000000..6c8934e7cc
--- /dev/null
+++ b/package/odhcp6c/Makefile
@@ -0,0 +1,39 @@
+#
+# Copyright (C) 2012 OpenWrt.org
+#
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=odhcp6c
+PKG_VERSION:=2013-05-21
+PKG_RELEASE=$(PKG_SOURCE_VERSION)
+
+PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
+PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION)
+PKG_SOURCE_URL:=git://github.com/sbyx/odhcp6c.git
+PKG_SOURCE_PROTO:=git
+PKG_SOURCE_VERSION:=6677edeab2d7472b97a34461872c2c8985d6a57c
+PKG_MAINTAINER:=Steven Barth <steven@midlink.org>
+
+include $(INCLUDE_DIR)/package.mk
+include $(INCLUDE_DIR)/cmake.mk
+
+define Package/odhcp6c
+ SECTION:=ipv6
+ CATEGORY:=IPv6
+ TITLE:=Embedded DHCPv6-client for OpenWrt
+ DEPENDS:=+kmod-ipv6
+endef
+
+define Package/odhcp6c/install
+ $(INSTALL_DIR) $(1)/usr/sbin/
+ $(INSTALL_BIN) $(PKG_BUILD_DIR)/odhcp6c $(1)/usr/sbin/
+ $(INSTALL_DIR) $(1)/lib/netifd/proto
+ $(INSTALL_BIN) ./files/dhcpv6.sh $(1)/lib/netifd/proto/dhcpv6.sh
+ $(INSTALL_BIN) ./files/dhcpv6.script $(1)/lib/netifd/
+endef
+
+$(eval $(call BuildPackage,odhcp6c))
diff --git a/package/odhcp6c/files/dhcpv6.script b/package/odhcp6c/files/dhcpv6.script
new file mode 100755
index 0000000000..324a823ce9
--- /dev/null
+++ b/package/odhcp6c/files/dhcpv6.script
@@ -0,0 +1,110 @@
+#!/bin/sh
+[ -z "$2" ] && echo "Error: should be run by odhcpc6c" && exit 1
+. /lib/functions.sh
+. /lib/netifd/netifd-proto.sh
+
+setup_interface () {
+ local device="$1"
+ proto_init_update "*" 1
+
+ # Merge RA-DNS
+ for radns in $RA_DNS; do
+ local duplicate=0
+ for dns in $RDNSS; do
+ [ "$radns" = "$dns" ] && duplicate=1
+ done
+ [ "$duplicate" = 0 ] && RDNSS="$RDNSS $radns"
+ done
+
+ for dns in $RDNSS; do
+ proto_add_dns_server "$dns"
+ done
+
+ for domain in $DOMAINS; do
+ proto_add_dns_search "$domain"
+ done
+
+ for prefix in $PREFIXES; do
+ proto_add_ipv6_prefix "$prefix"
+ done
+
+ [ -n "$USERPREFIX" ] && proto_add_ipv6_prefix "$USERPREFIX"
+
+ # Merge addresses
+ for entry in $RA_ADDRESSES; do
+ local duplicate=0
+ local addr="${entry%%/*}"
+ for dentry in $ADDRESSES; do
+ local daddr="${dentry%%/*}"
+ [ "$addr" = "$daddr" ] && duplicate=1
+ done
+ [ "$duplicate" = "0" ] && ADDRESSES="$ADDRESSES $entry"
+ done
+
+ for entry in $ADDRESSES; do
+ local addr="${entry%%/*}"
+ entry="${entry#*/}"
+ local mask="${entry%%,*}"
+ entry="${entry#*,}"
+ local preferred="${entry%%,*}"
+ entry="${entry#*,}"
+ local valid="${entry%%,*}"
+
+ proto_add_ipv6_address "$addr" "$mask" "$preferred" "$valid" 1
+ done
+
+ for entry in $RA_ROUTES; do
+ local addr="${entry%%/*}"
+ entry="${entry#*/}"
+ local mask="${entry%%,*}"
+ entry="${entry#*,}"
+ local gw="${entry%%,*}"
+ entry="${entry#*,}"
+ local valid="${entry%%,*}"
+ entry="${entry#*,}"
+ local metric="${entry%%,*}"
+
+ proto_add_ipv6_route "$addr" "$mask" "$gw" "$metric" "$valid"
+ done
+
+ proto_send_update "$INTERFACE"
+
+ if [ -n "$AFTR_IP " -a -n "$IFACE_DSLITE" ]; then
+uci -q batch <<-EOF >/dev/null
+set network.$IFACE_DSLITE.proto=dslite
+set network.$IFACE_DSLITE.auto=0
+set network.$IFACE_DSLITE.peeraddr=$AFTR_IP
+set network.$IFACE_DSLITE.tunlink=$INTERFACE
+commit network
+EOF
+
+ ifdown "$IFACE_DSLITE"
+ /etc/init.d/network reload
+ ifup "$IFACE_DSLITE"
+ fi
+
+ # TODO: $SNTP_IP $SIP_IP $SNTP_FQDN $SIP_DOMAIN
+}
+
+teardown_interface() {
+ proto_init_update "*" 0
+ proto_send_update "$INTERFACE"
+}
+
+case "$2" in
+ bound)
+ teardown_interface "$1"
+ setup_interface "$1"
+ ;;
+ informed|updated|rebound|ra-updated)
+ setup_interface "$1"
+ ;;
+ started|stopped|unbound)
+ teardown_interface "$1"
+ ;;
+esac
+
+# user rules
+[ -f /etc/odhcp6c.user ] && . /etc/odhcp6c.user
+
+exit 0
diff --git a/package/odhcp6c/files/dhcpv6.sh b/package/odhcp6c/files/dhcpv6.sh
new file mode 100755
index 0000000000..b2264ed907
--- /dev/null
+++ b/package/odhcp6c/files/dhcpv6.sh
@@ -0,0 +1,57 @@
+#!/bin/sh
+
+. /lib/functions.sh
+. ../netifd-proto.sh
+init_proto "$@"
+
+proto_dhcpv6_init_config() {
+ proto_config_add_string "reqaddress"
+ proto_config_add_string "reqprefix"
+ proto_config_add_string "clientid"
+ proto_config_add_string "reqopts"
+ proto_config_add_string "noslaaconly"
+ proto_config_add_string "norelease"
+ proto_config_add_string "ip6prefix"
+}
+
+proto_dhcpv6_setup() {
+ local config="$1"
+ local iface="$2"
+
+ local reqaddress reqprefix clientid reqopts noslaaconly norelease ip6prefix iface_dslite
+ json_get_vars reqaddress reqprefix clientid reqopts noslaaconly norelease ip6prefix iface_dslite
+
+
+ # Configure
+ local opts=""
+ [ -n "$reqaddress" ] && append opts "-N$reqaddress"
+
+ [ -z "$reqprefix" -o "$reqprefix" = "auto" ] && reqprefix=0
+ [ "$reqprefix" != "no" ] && append opts "-P$reqprefix"
+
+ [ -n "$clientid" ] && append opts "-c$clientid"
+
+ [ "$noslaaconly" = "1" ] && append opts "-S"
+
+ [ "$norelease" = "1" ] && append opts "-k"
+
+ for opt in $reqopts; do
+ append opts "-r$opt"
+ done
+
+ [ -n "$ip6prefix" ] && proto_export "USERPREFIX=$ip6prefix"
+ [ -n "$iface_dslite" ] && proto_export "IFACE_DSLITE=$iface_dslite"
+
+ proto_export "INTERFACE=$config"
+ proto_run_command "$config" odhcp6c \
+ -s /lib/netifd/dhcpv6.script \
+ $opts $iface
+}
+
+proto_dhcpv6_teardown() {
+ local interface="$1"
+ proto_kill_command "$interface"
+}
+
+add_protocol dhcpv6
+