Hello list,

The current behavior is that all interfaces (LAN, WAN and Wifi0) get the
first MAC address in the mac mtd assigned (Wifi1 gets the MAC address of
the second MAC address plus 1).

Unfortunately the MAC address printed on the sticker on the bottom of
the router (the second MAC address in the mac mtd) is not used at all.
But for some use cases it appears to be vital that the printed MAC gets
assigned.

For testing I installed D-Link's firmware 304b01 (latest). It handles
MAC assignments the same way as OpenWrt does, except it assigns the
printed MAC to the WAN interface.

So I tried to come up with a way to do the same in OpenWrt. As the WAN
interface is a virtual interface there's no way to do this while loading
the driver. For the same reason I couldn't use the existing code in
lib/preinit, i.e. 05_set_iface_mac_ar71xx.

So I ended up with the following patch. Please consider it/tell me what
you think. Thanks!

Signed-off-by: Sebastian Kemper <sebastian...@gmx.net>

diff -Nur 
openwrt.orig/target/linux/ar71xx/base-files/etc/uci-defaults/02_network 
openwrt.new/target/linux/ar71xx/base-files/etc/uci-defaults/02_network
--- openwrt.orig/target/linux/ar71xx/base-files/etc/uci-defaults/02_network     
2013-09-12 23:54:58.491543186 +0200
+++ openwrt.new/target/linux/ar71xx/base-files/etc/uci-defaults/02_network      
2013-09-13 00:04:46.284856230 +0200
@@ -5,6 +5,18 @@
 
 [ -e /etc/config/network ] && exit 0
 
+fetch_wan_mac_from_mtd() {
+       local mtd_part=$1
+       local wan_env=$2
+       local mtd mac
+
+       mtd=$(grep $mtd_part /proc/mtd | cut -d: -f1)
+       [ -z $mtd ] && return
+
+       mac=$(grep -m 1 $wan_env /dev/$mtd | cut -d= -f2)
+       [ ! -z $mac ] && ucidef_set_interface_macaddr "wan" "$mac"
+}
+
 touch /etc/config/network
 
 . /lib/functions/uci-defaults.sh
@@ -193,7 +205,14 @@
        ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 5t"
        ;;
 
-dir-825-c1 |\
+dir-825-c1)
+       ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
+       fetch_wan_mac_from_mtd "nvram" "wan_mac"
+       ucidef_add_switch "switch0" "1" "1"
+       ucidef_add_switch_vlan "switch0" "1" "0t 1 2 3 4"
+       ucidef_add_switch_vlan "switch0" "2" "0t 5"
+       ;;
+
 dir-835-a1 |\
 wndr4300)
        ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel

Reply via email to