diff mbox series

[OpenWrt-Devel,RFC,1/2] base-files: always store label MAC address in uci system config

Message ID 20191103204606.7929-1-freifunk@adrianschmutzler.de
State Superseded
Headers show
Series [OpenWrt-Devel,RFC,1/2] base-files: always store label MAC address in uci system config | expand

Commit Message

Adrian Schmutzler Nov. 3, 2019, 8:46 p.m. UTC
If set, label MAC address is available from one of two sources,
device tree or board.json. So far, the function get_mac_label
was meant for retrieving the address, while an option in uci
system config was specified only for case 2 (board.json).

Since this has been perceived as counter-intuitive, this patch
changes front-end access to the label MAC address:
During first-boot, the label MAC address will be written to uci
system config file for both cases, no matter whether is was
specified in DT or in board.json (via 02_network). A user of
the label MAC address will then read the value from
system.@system[0].label_macaddr, which is easier and more intuitive
than using a function and still have an uci value set.

Since this is only changing the access to the label MAC address, it
won't interfere with the addresses stored in the code base so far.

Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>

---

This is not tested and just meant to serve as RFC. I will test
during next week.
---
 package/base-files/files/bin/config_generate     | 6 ++++--
 package/base-files/files/lib/functions/system.sh | 6 +++---
 2 files changed, 7 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/package/base-files/files/bin/config_generate b/package/base-files/files/bin/config_generate
index 0b26afe57f..fe35788a26 100755
--- a/package/base-files/files/bin/config_generate
+++ b/package/base-files/files/bin/config_generate
@@ -3,6 +3,7 @@ 
 CFG=/etc/board.json
 
 . /usr/share/libubox/jshn.sh
+. /lib/functions/system.sh
 
 [ -s $CFG ] || /bin/board_detect || exit 1
 [ -s /etc/config/network -a -s /etc/config/system ] && exit 0
@@ -260,8 +261,9 @@  generate_static_system() {
 				uci -q set "system.@system[-1].hostname=$hostname"
 			fi
 
-			local label_macaddr
-			if json_get_var label_macaddr label_macaddr; then
+			local label_macaddr=$(get_mac_label_dt)
+			[ -n "$label_macaddr" ] || json_get_var label_macaddr label_macaddr
+			if [ -n "$label_macaddr" ]; then
 				uci -q set "system.@system[-1].label_macaddr=$label_macaddr"
 			fi
 
diff --git a/package/base-files/files/lib/functions/system.sh b/package/base-files/files/lib/functions/system.sh
index cb0508fe9c..5b4ced836c 100644
--- a/package/base-files/files/lib/functions/system.sh
+++ b/package/base-files/files/lib/functions/system.sh
@@ -12,14 +12,14 @@  get_mac_binary() {
 	hexdump -v -n 6 -s $offset -e '5/1 "%02x:" 1/1 "%02x"' $path 2>/dev/null
 }
 
-get_mac_label() {
+get_mac_label_dt() {
 	local basepath="/proc/device-tree"
 	local macdevice="$(cat "$basepath/aliases/label-mac-device" 2>/dev/null)"
 	local macaddr
 
-	[ -n "$macdevice" ] && macaddr=$(get_mac_binary "$basepath/$macdevice/mac-address" 0 2>/dev/null)
+	[ -n "$macdevice" ] || return
+	macaddr=$(get_mac_binary "$basepath/$macdevice/mac-address" 0 2>/dev/null)
 	[ -n "$macaddr" ] || macaddr=$(get_mac_binary "$basepath/$macdevice/local-mac-address" 0 2>/dev/null)
-	[ -n "$macaddr" ] || macaddr=$(uci -q get system.@system[0].label_macaddr)
 	echo $macaddr
 }