[LEDE-DEV] [RFC/RFT 2/7] base-files: add preinit ifname detection based on board.json
Jonas Gorski
jonas.gorski at gmail.com
Fri Jul 29 02:07:50 PDT 2016
Make use of the existing board.d to autodetect lan ifname in a generic way.
Signed-off-by: Jonas Gorski <jonas.gorski at gmail.com>
---
.../files/lib/preinit/10_indicate_preinit | 45 ++++++++++++++++++++--
1 file changed, 41 insertions(+), 4 deletions(-)
diff --git a/package/base-files/files/lib/preinit/10_indicate_preinit b/package/base-files/files/lib/preinit/10_indicate_preinit
index 717d35c..4be4f30 100644
--- a/package/base-files/files/lib/preinit/10_indicate_preinit
+++ b/package/base-files/files/lib/preinit/10_indicate_preinit
@@ -2,6 +2,42 @@
# Copyright (C) 2006 OpenWrt.org
# Copyright (C) 2010 Vertical Communications
+preinit_config_netdev() {
+ grep -q "$1" /proc/net/dev || return
+
+ ip link set dev $1 up
+ ip -4 address add $pi_ip/$pi_netmask broadcast $pi_broadcast dev $1
+}
+
+preinit_config_board() {
+ [ -z "$ifname" ] || return
+
+ /bin/board_detect /tmp/board.json
+
+ [ -f "/tmp/board.json" ] || return
+
+ . /usr/share/libubox/jshn.sh
+
+ json_init
+ json_load "$(cat /tmp/board.json)"
+
+ json_select network
+ json_select "lan"
+ json_get_vars ifname
+ json_select ..
+ json_select ..
+
+ [ -n "$ifname" ] || return
+
+ # only use the first one
+ ifname=${ifname%% *}
+
+ # trim any vlan ids
+ ifname=${ifname%\.*}
+
+ preinit_config_netdev $ifname
+}
+
preinit_ip() {
# if the preinit interface isn't specified and ifname is set in
# preinit.arch use that interface
@@ -9,10 +45,11 @@ preinit_ip() {
pi_ifname=$ifname
fi
- [ -n "$pi_ifname" ] && grep -q "$pi_ifname" /proc/net/dev && {
- ip link set dev $pi_ifname up
- ip -4 address add $pi_ip/$pi_netmask broadcast $pi_broadcast dev $pi_ifname
- }
+ if [ -n "$pi_ifname" ]; then
+ preinit_config_netdev $pi_ifname
+ elif [ -d "/etc/board.d/" ]; then
+ preinit_config_board
+ fi
}
preinit_ip_deconfig() {
--
2.1.4
More information about the Lede-dev
mailing list