#
# Copyright (C) 2014-2015 OpenWrt.org
# Copyright (C) 2016 LEDE-Project.org
#

preinit_set_mac_address() {
	local mac

	. /lib/functions.sh

	case $(board_name) in
	armada-xp-linksys-mamba)
		mac=$(mtd_get_mac_ascii devinfo hw_mac_addr)
		ip link set dev eth0 address $mac 2>/dev/null
		ip link set dev eth1 address $mac 2>/dev/null
		;;
	armada-385-linksys-caiman|armada-385-linksys-cobra|armada-385-linksys-rango|armada-385-linksys-shelby|armada-385-linksys-venom)
		# rename interfaces back to the way they were with 4.4
		case "$(readlink /sys/class/net/eth0)" in
			*f1070000*)
				ip link set eth0 name tmp0
				ip link set eth1 name eth0
				ip link set tmp0 name eth1
			;;
		esac

		mac=$(mtd_get_mac_ascii devinfo hw_mac_addr)
		mac_wan=$(macaddr_setbit_la "$mac")
		ip link set dev eth1 address $mac 2>/dev/null
		ip link set dev eth0 address $mac_wan 2>/dev/null
		;;
	armada-385-db-ap|armada-388-clearfog)
		# rename interfaces back to the way they were with 4.4
		case "$(readlink /sys/class/net/eth0)" in
			*f1070000*)
				ip link set eth0 name tmp0
				ip link set eth1 name eth0
				ip link set eth2 name eth1
				ip link set tmp0 name eth2
			;;
		esac
		;;
	esac
}

boot_hook_add preinit_main preinit_set_mac_address
