odhcp6c: switch to userspace RA-handling and offload address assignment to netifd

SVN-Revision: 35419
This commit is contained in:
Steven Barth 2013-02-01 12:28:39 +00:00
parent a3368da479
commit 9a62439c28
3 changed files with 54 additions and 30 deletions

View File

@ -8,14 +8,14 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=odhcp6c
PKG_VERSION:=2013-01-29
PKG_VERSION:=2013-02-01
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:=770741e98f2569ec0b00251ba9bf17a92e89221e
PKG_SOURCE_VERSION:=7b3e29a4ff20f1b1e91fa65b5a0631462dbee06d
PKG_MAINTAINER:=Steven Barth <steven@midlink.org>
include $(INCLUDE_DIR)/package.mk

View File

@ -3,33 +3,19 @@
. /lib/functions.sh
. /lib/netifd/netifd-proto.sh
ipv6_conf() {
echo "$3" > "/proc/sys/net/ipv6/conf/$1/$2"
}
prepare_interface() {
local device="$1"
ipv6_conf "$device" accept_ra 2
# Send RS
if [ -x /usr/sbin/6relayd ]; then
sleep 1
/usr/sbin/6relayd -s "$device"
sleep 4
/usr/sbin/6relayd -s "$device"
fi
}
cleanup_interface() {
local device="$1"
ipv6_conf "$device" accept_ra 0
}
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
@ -42,6 +28,43 @@ setup_interface () {
proto_add_ipv6_prefix "$prefix"
done
# 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"
# TODO: $SNTP_IP $SIP_IP $SNTP_FQDN $SIP_DOMAIN
@ -53,12 +76,10 @@ teardown_interface() {
}
case "$2" in
informed|bound|updated|rebound)
informed|bound|updated|rebound|ra-updated)
setup_interface "$1"
prepare_interface "$1"
;;
started|stopped|unbound)
cleanup_interface "$1"
teardown_interface "$1"
;;
esac

View File

@ -9,14 +9,15 @@ proto_dhcpv6_init_config() {
proto_config_add_string "reqprefix"
proto_config_add_string "clientid"
proto_config_add_string "reqopts"
proto_config_add_string "allow_slaaconly"
}
proto_dhcpv6_setup() {
local config="$1"
local iface="$2"
local reqaddress reqprefix clientid reqopts
json_get_vars reqaddress reqprefix clientid reqopts
local reqaddress reqprefix clientid reqopts allow_slaaconly
json_get_vars reqaddress reqprefix clientid reqopts allow_slaaconly
# Configure
@ -28,6 +29,8 @@ proto_dhcpv6_setup() {
[ -n "$clientid" ] && append opts "-c$clientid"
[ "$allow_slaaconly" = "1" ] && append opts "-S"
for opt in $reqopts; do
append opts "-r$opt"
done