From e272d81c21b34540668d7421dcf18fd9013b94ce Mon Sep 17 00:00:00 2001
From: Felix Fietkau <nbd@openwrt.org>
Date: Mon, 16 Jan 2006 03:14:59 +0000
Subject: [PATCH] port wan_device changes from whiterussian to kamikaze

SVN-Revision: 2993
---
 .../default/etc/hotplug.d/net/10-net          |  2 +-
 .../package/base-files/default/sbin/ifdown    |  2 +-
 openwrt/package/base-files/default/sbin/ifup  |  2 +-
 openwrt/package/ppp/files/ifup.pppoe          |  2 +-
 openwrt/package/pptp/files/ifup.pptp          |  2 +-
 .../files/brcm-2.4/etc/init.d/S05netconfig    |  4 +--
 .../files/brcm-2.4/etc/init.d/S05nvram        | 26 ++++++++++++-------
 .../files/brcm-2.6/etc/init.d/S05netconfig    |  8 ++----
 8 files changed, 24 insertions(+), 24 deletions(-)

diff --git a/openwrt/package/base-files/default/etc/hotplug.d/net/10-net b/openwrt/package/base-files/default/etc/hotplug.d/net/10-net
index 8d2c6a8034..dd4ee8863a 100644
--- a/openwrt/package/base-files/default/etc/hotplug.d/net/10-net
+++ b/openwrt/package/base-files/default/etc/hotplug.d/net/10-net
@@ -26,7 +26,7 @@ find_name()
 				}
 			;;
 			*)
-				[ "$(nvram get ${IFPROTO}_ifname)" = "$INTERFACE" \
+				[ "$(nvram get ${IFTYPE}_device)" = "$INTERFACE" \
 				  -a -x /sbin/ifup.${IFPROTO} ] && return 0
 			;;
 		esac
diff --git a/openwrt/package/base-files/default/sbin/ifdown b/openwrt/package/base-files/default/sbin/ifdown
index 85bb2fbc5d..d0120dcbe8 100755
--- a/openwrt/package/base-files/default/sbin/ifdown
+++ b/openwrt/package/base-files/default/sbin/ifdown
@@ -15,7 +15,7 @@ case "$if_proto" in
 	""|none) exit 0;;
 esac
 
-[ "${if%%[0-9]*}" = "ppp" ] && if="$(nvram get ${if_proto}_ifname)"
+[ "${if%%[0-9]*}" = "ppp" ] && if="$(nvram get ${type}_device)"
 
 if [ "${if%%[0-9]}" = "br" ]; then
 	for sif in $(nvram get ${type}_ifnames); do
diff --git a/openwrt/package/base-files/default/sbin/ifup b/openwrt/package/base-files/default/sbin/ifup
index 67e01a3e90..8ae6416685 100755
--- a/openwrt/package/base-files/default/sbin/ifup
+++ b/openwrt/package/base-files/default/sbin/ifup
@@ -23,7 +23,7 @@ case "$if_proto" in
 	none|"") exit 0;;
 esac
 
-[ "${if%%[0-9]*}" = "ppp" ] && if="$(nvram get ${if_proto}_ifname)"
+[ "${if%%[0-9]*}" = "ppp" ] && if="$(nvram get ${type}_device)"
 
 if [ "${if%%[0-9]}" = "br" ]; then
 	for sif in $(nvram get ${type}_ifnames); do
diff --git a/openwrt/package/ppp/files/ifup.pppoe b/openwrt/package/ppp/files/ifup.pppoe
index a038b34279..b43d2689bd 100644
--- a/openwrt/package/ppp/files/ifup.pppoe
+++ b/openwrt/package/ppp/files/ifup.pppoe
@@ -14,7 +14,7 @@ for module in slhc ppp_generic pppox pppoe; do
 	/sbin/insmod $module 2>&- >&-
 done
 
-IFNAME=$(nvram get pppoe_ifname)
+IFNAME=$(nvram get ${type}_device)
 USERNAME=$(nvram get ppp_username)
 PASSWORD=$(nvram get ppp_passwd)
 KEEPALIVE=$(nvram get ppp_redialperiod)
diff --git a/openwrt/package/pptp/files/ifup.pptp b/openwrt/package/pptp/files/ifup.pptp
index c8a1a5eee8..fe04d97848 100644
--- a/openwrt/package/pptp/files/ifup.pptp
+++ b/openwrt/package/pptp/files/ifup.pptp
@@ -33,7 +33,7 @@ do_ifup $PPTP_PROTO $type
 
 # hack for some buggy ISPs
 NETMASK=$(nvram get ${type}_netmask)
-IFNAME=$(nvram get pptp_ifname)
+IFNAME=$(nvram get ${type}_device)
 [ -z "$NETMASK" -o -z "$IFNAME" ] || ifconfig $IFNAME netmask $NETMASK
 
 /usr/sbin/pppd \
diff --git a/openwrt/target/linux/package/base-files/files/brcm-2.4/etc/init.d/S05netconfig b/openwrt/target/linux/package/base-files/files/brcm-2.4/etc/init.d/S05netconfig
index 27336e112e..72d5b63ac7 100755
--- a/openwrt/target/linux/package/base-files/files/brcm-2.4/etc/init.d/S05netconfig
+++ b/openwrt/target/linux/package/base-files/files/brcm-2.4/etc/init.d/S05netconfig
@@ -88,10 +88,10 @@ END {
 	print "#   pppoe: PPP over Ethernet"
 	print "#   pptp: Point-to-Point tunneling Protocol"
 	print "#     for pppoe and pptp you need to use wan_ifname=\"ppp0\""
-	print "#     and {pppoe,pptp}ifname=\"" c["wan_ifname"] "\")"
 	print ""
 	print "wan_proto=dhcp"
 	p("wan_ifname")
+	print "wan_device=\"" c["wan_ifname"] "\""
 	print "# wan_ipaddr=\"192.168.0.2\""
 	print "# wan_netmask=\"255.255.255.0\""
 	print "# wan_gateway=\"192.168.0.1\""
@@ -99,8 +99,6 @@ END {
 	print ""
 	print "## PPP over Ethernet and PPTP"
 	print "# wan_ifname=\"ppp0\""
-	print "# pppoe_ifname=\"" c["wan_ifname"] "\""
-	print "# pptp_ifname=\"" c["wan_ifname"] "\""
 	print "# pptp_server_ip=\"192.168.0.1\""
 }
 ' > /etc/config/network
diff --git a/openwrt/target/linux/package/base-files/files/brcm-2.4/etc/init.d/S05nvram b/openwrt/target/linux/package/base-files/files/brcm-2.4/etc/init.d/S05nvram
index 70fbd46624..a561b3965b 100755
--- a/openwrt/target/linux/package/base-files/files/brcm-2.4/etc/init.d/S05nvram
+++ b/openwrt/target/linux/package/base-files/files/brcm-2.4/etc/init.d/S05nvram
@@ -107,6 +107,14 @@ case "$(nvram get productid)" in
 		nvram set lan_ifnames="eth1 eth2"
 		nvram set wan_ifname="none"
 	;;
+	*)
+		# wl-500g defaults. these are placed here, because WL-HDD and WL-300g
+		# might have the same nvram settings.
+		[ "$(nvram get boardnum)" = "asusX" \
+		-a "$(nvram get boardtype)" = "bcm94710dev" ] && {
+			nvram_default wan_device "eth1"
+		}
+	;;
 esac
 
 # hacks for wap54g hardware
@@ -130,21 +138,12 @@ esac
 	nvram_default wl0id 0x4320
 }
 
-WAN_PROTO="$(nvram get wan_proto)"
-[  "$WAN_PROTO" = "pptp" \
--o "$WAN_PROTO" = "pppoe" ] && {
-	WAN_IFNAME="$(nvram get wan_ifname)"
-	[ "${WAN_IFNAME%%[0-9]*}" = "ppp" ] || {
-		nvram set wan_ifname=ppp0
-		nvram set ${WAN_PROTO}_ifname="$WAN_IFNAME"
-	}
-}
-
 # defaults
 nvram_default lan_ifname "br0"
 nvram_default lan_ifnames "$FAILSAFE_ifnames"
 
 nvram_default wan_ifname "vlan1"
+nvram_default wan_device "vlan1"
 nvram_default wan_proto "dhcp"
 
 nvram_default wl0_ssid OpenWrt
@@ -152,6 +151,13 @@ nvram_default wl0_mode ap
 nvram_default wl0_infra 1
 nvram_default wl0_radio 1
 
+WAN_PROTO="$(nvram get wan_proto)"
+WAN_IFNAME="$(nvram get wan_ifname)"
+case "$WAN_PROTO" in
+	pp*) [ "${WAN_IFNAME%%[0-9]*}" = "ppp" ] || nvram set wan_ifname=ppp0;;
+	*) [ "${WAN_IFNAME%%[0-9]*}" = "ppp" ] && nvram set wan_ifname="$(nvram get wan_device)";;
+esac
+
 [ "$(nvram get il0macaddr)" = "00:90:4c:5f:00:2a" ] && {
 	# if default wifi mac, set two higher than the lan mac
 	nvram set il0macaddr=$(nvram get et0macaddr|
diff --git a/openwrt/target/linux/package/base-files/files/brcm-2.6/etc/init.d/S05netconfig b/openwrt/target/linux/package/base-files/files/brcm-2.6/etc/init.d/S05netconfig
index 0cafa17402..72d5b63ac7 100755
--- a/openwrt/target/linux/package/base-files/files/brcm-2.6/etc/init.d/S05netconfig
+++ b/openwrt/target/linux/package/base-files/files/brcm-2.6/etc/init.d/S05netconfig
@@ -57,9 +57,8 @@ END {
 	# WAP54G
 	if ((nvram["boardnum"] == "2") || \
 		(nvram["boardnum"] == "1024")) {
-		c["lan_ifnames"]="eth1 eth2"
+		c["lan_ifnames"]="eth0 eth1"
 		c["wan_ifname"]=""
-		c["unused_ifnames"]="eth0"
 	}
 
 	print "#### VLAN configuration "
@@ -79,7 +78,6 @@ END {
 	print "# lan_gateway=\"192.168.1.1\""
 
 	print ""
-	p("unused_ifnames")
 	print ""
 
 	print "#### WAN configuration"
@@ -90,10 +88,10 @@ END {
 	print "#   pppoe: PPP over Ethernet"
 	print "#   pptp: Point-to-Point tunneling Protocol"
 	print "#     for pppoe and pptp you need to use wan_ifname=\"ppp0\""
-	print "#     and {pppoe,pptp}ifname=\"" c["wan_ifname"] "\")"
 	print ""
 	print "wan_proto=dhcp"
 	p("wan_ifname")
+	print "wan_device=\"" c["wan_ifname"] "\""
 	print "# wan_ipaddr=\"192.168.0.2\""
 	print "# wan_netmask=\"255.255.255.0\""
 	print "# wan_gateway=\"192.168.0.1\""
@@ -101,8 +99,6 @@ END {
 	print ""
 	print "## PPP over Ethernet and PPTP"
 	print "# wan_ifname=\"ppp0\""
-	print "# pppoe_ifname=\"" c["wan_ifname"] "\""
-	print "# pptp_ifname=\"" c["wan_ifname"] "\""
 	print "# pptp_server_ip=\"192.168.0.1\""
 }
 ' > /etc/config/network
-- 
2.30.2