[package] wide-dhcpv6: improve user DUID handling

- values containing exactly six octets are treated as type 3 (DUID-LL)
	- values containing seven and more octets get the length tag added in native endianess
	- all other values are treated as invalid


git-svn-id: svn://svn.openwrt.org/openwrt/packages@28079 3c298f89-4303-0410-b956-a3cf2f4a3e73
This commit is contained in:
jow 2011-08-22 22:50:16 +00:00
parent ebf7e69f61
commit 9960c58602
2 changed files with 38 additions and 31 deletions

View File

@ -3,7 +3,7 @@ include $(TOPDIR)/rules.mk
PKG_NAME:=wide-dhcpv6
PKG_VERSION:=20080615
PKG_RELEASE:=6
PKG_RELEASE:=7
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=@SF/$(PKG_NAME)

View File

@ -28,10 +28,7 @@ dhcp6c_write_duid() {
local pat="[0-9A-F][0-9A-F]"
case "$mac" in
$pat:$pat:$pat:$pat:$pat:$pat:$pat:$pat:$pat:$pat)
printf $(echo "$mac" | sed -e 's/^/\\x/; s/:/\\x/g')
logger -t dhcp6c "Using user provided DUID $mac"
;;
# exactly 6 octets -> assume type 3 (DUID-LL - RFC3315, 9.4)
$pat:$pat:$pat:$pat:$pat:$pat)
local oIFS="$IFS"; IFS=":"; set -- $mac; IFS="$oIFS"
@ -47,6 +44,24 @@ dhcp6c_write_duid() {
printf \\x00\\x03\\x00\\x06\\x$1\\x$2\\x$3\\x$4\\x$5\\x$6
logger -t dhcp6c "Using MAC address DUID 00:03:00:06:$1:$2:$3:$4:$5:$6"
;;
# at least 7 octets -> could be type 1 or type 2
$pat:$pat:$pat:$pat:$pat:$pat:*)
local len_id=":$(echo "$mac" | sed -e 's/[^:]//g')"
local len_hi=$(printf "%02x" $((${#len_id} / 0xFF)) )
local len_lo=$(printf "%02x" $((${#len_id} % 0xFF)) )
# low endian
if [ "$(printf \\1 | hexdump -n1 -ve '8/2 "%04x"')" = "0001" ]; then
printf \\x$len_lo\\x$len_hi
# big endian
else
printf \\x$len_hi\\x$len_lo
fi
printf $(echo "$mac" | sed -e 's/^/\\x/; s/:/\\x/g')
logger -t dhcp6c "Using user provided DUID $mac"
;;
*)
logger -t dhcp6c "Unable to derive DUID from interface '$client_device' and no valid user DUID given"
;;
@ -62,7 +77,6 @@ dhcp6c_write_interface() {
config_get_bool enabled "$cfg" enabled 0
if [ $enabled -ne 0 ]; then
config_get sla_id "$cfg" sla_id
config_get sla_len "$cfg" sla_len
@ -70,9 +84,7 @@ dhcp6c_write_interface() {
printf '\t\tsla-id %s;\n' "$sla_id"
printf '\t\tsla-len %s;\n' "$sla_len"
printf '\t};\n'
fi
}
dhcp6c_write_request() {
@ -80,7 +92,6 @@ dhcp6c_write_request() {
}
dhcp6c_write_config() {
local pd
local na
config_get_bool pd basic pd 0
@ -128,7 +139,6 @@ dhcp6c_write_config() {
}
start() {
[ ! -e /etc/dhcp6cctlkey ] && `dd if=/dev/urandom count=1 2> /dev/null | md5sum | cut -d" " -f1 > /etc/dhcp6cctlkey`
[ -e /var/run/dhcp6c.pid ] && return 0
@ -167,17 +177,14 @@ start() {
ACTION=start /sbin/hotplug-call dhcp6c
return 0
}
stop() {
logger -t dhcp6c stopping dhcp6c
service_kill dhcp6c /var/run/dhcp6c.pid
rm -f /var/etc/dhcp6c.conf /var/run/dhcp6c.pid
ACTION=stop /sbin/hotplug-call dhcp6c
return 0
}