[packages] wide-dhcpv6: use network.sh to find devices
[packages] wide-dhcpv6: use network.sh to find devices

git-svn-id: svn://svn.openwrt.org/openwrt/packages@31961 3c298f89-4303-0410-b956-a3cf2f4a3e73

--- a/ipv6/wide-dhcpv6/Makefile
+++ b/ipv6/wide-dhcpv6/Makefile
@@ -1,5 +1,5 @@
 #
-# Copyright (C) 2010-2011 OpenWrt.org
+# Copyright (C) 2010-2012 OpenWrt.org
 #
 # This is free software, licensed under the GNU General Public License v2.
 # See /LICENSE for more information.
@@ -9,7 +9,7 @@
 
 PKG_NAME:=wide-dhcpv6
 PKG_VERSION:=20080615
-PKG_RELEASE:=10
+PKG_RELEASE:=11
 
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
 PKG_SOURCE_URL:=@SF/$(PKG_NAME)

--- a/ipv6/wide-dhcpv6/files/dhcp6c.init
+++ b/ipv6/wide-dhcpv6/files/dhcp6c.init
@@ -1,27 +1,6 @@
 #!/bin/sh /etc/rc.common
 
 DHCP6C_REQUEST_OPTIONS='domain_name_servers domain_name ntp_servers sip_server_address sip_domain_name nis_server_address nis_domain_name nisp_server_address nisp_domain_name bcmcs_server_address bcmcs_domain_name'
-
-get_ifname() {
-	local interface=$1
-	local ifname
-	scan_interfaces
-	config_get ifname "$interface" ifname
-	printf '%s\n' "$ifname"
-	return 0
-}
-
-get_device() {
-	local interface=$1
-	local ifname=$2
-	local device
-	scan_interfaces
-	config_get device "$interface" device
-	grep -qE "^ *$device:" /proc/net/dev && \
-		printf '%s\n' "$device" || \
-		printf '%s\n' "$ifname"
-	return 0
-}
 
 dhcp6c_write_duid() {
 	local mac="${1:-$(ifconfig "$client_device" | sed -ne 's/[[:space:]]*$//; s/.*HWaddr //p')}"
@@ -73,6 +52,7 @@
 	local sla_id
 	local sla_len
 	local enabled
+	local device
 
 	config_get_bool enabled "$cfg" enabled 0
 
@@ -80,10 +60,12 @@
 		config_get sla_id "$cfg" sla_id
 		config_get sla_len "$cfg" sla_len
 
-		printf '\tprefix-interface %s {\n' "$(get_ifname $cfg)"
-		printf '\t\tsla-id %s;\n' "$sla_id"
-		printf '\t\tsla-len %s;\n' "$sla_len"
-		printf '\t};\n'
+		network_get_device device "$cfg" && {
+			printf '\tprefix-interface %s {\n' "$device"
+			printf '\t\tsla-id %s;\n' "$sla_id"
+			printf '\t\tsla-len %s;\n' "$sla_len"
+			printf '\t};\n'
+		}
 	fi
 }
 
@@ -143,7 +125,7 @@
 
 	[ -e /var/run/dhcp6c.pid ] && return 0
 
-	include /lib/network
+	. /lib/functions/network.sh
 
 	config_load "dhcp6c"
 
@@ -156,10 +138,10 @@
 
 	logger -t dhcp6c starting dhcp6c
 
-	local client_interface
+	local client_interface client_ifname client_device
 	config_get client_interface basic interface
-	local client_ifname=$(get_ifname "$client_interface")
-	local client_device=$(get_device "$client_interface" "$client_ifname")
+	network_get_device  client_ifname "$client_interface"
+	network_get_physdev client_device "$client_interface" || client_device="$client_ifname"
 
 	local config_file="/var/etc/dhcp6c.conf"
 	local duid_file="/var/dhcp6c_duid"

--- a/ipv6/wide-dhcpv6/files/dhcp6s.init
+++ b/ipv6/wide-dhcpv6/files/dhcp6s.init
@@ -1,23 +1,14 @@
-#!/bin/sh /etc/rc.common 
-# Copyright (C) 2010-2011 OpenWrt.org
+#!/bin/sh /etc/rc.common
+# Copyright (C) 2010-2012 OpenWrt.org
 
 SERVICE_USE_PID=1
-
-get_ifname() {
-	local interface=$1
-	local ifname
-	scan_interfaces
-	config_get ifname "$interface" ifname
-	printf '%s\n' "$ifname"
-	return 0
-}
 
 start() {
 	[ ! -e /etc/dhcp6sctlkey ] && `dd if=/dev/urandom count=1 2> /dev/null | md5sum | cut -d" " -f1 > /etc/dhcp6sctlkey`
 
 	[ -e /var/run/dhcp6s.pid ] && return 0
 
-	include /lib/network
+	. /lib/functions/network.sh
 
 	config_load "dhcp6s"
 
@@ -27,9 +18,9 @@
 
 	logger starting dhcp6s
 
-	local server_interface 
+	local server_interface server_ifname
 	config_get server_interface basic interface
-	local server_ifname=$(get_ifname "$server_interface")
+	network_get_device server_ifname "$server_interface" || return 1
 
 	local config_file
 	config_get config_file basic config_file

comments