[OpenWrt-Devel] Migration in ath79 for swapped ethernet

Adrian Schmutzler mail at adrianschmutzler.de
Thu Sep 5 11:00:17 EDT 2019


Hi,

if I remember correctly, there is still no mechanism to fix eth0/eth1 for devices where those have been swapped from ar71xx to ath79.

In principle, this can be done with a relatively small piece of code (not tested):

diff --git a/target/linux/ath79/base-files/etc/uci-defaults/05_eth_migration b/target/linux/ath79/base-files/etc/uci-defaults/05_eth_migration
new file mode 100644
index 0000000000..d6b519d25a
--- /dev/null
+++ b/target/linux/ath79/base-files/etc/uci-defaults/05_eth_migration
@@ -0,0 +1,28 @@
+#!/bin/sh
+
+rename_all_eth() {
+       local before="$1"
+       local after="$2"
+
+       sed -i "s/$before/$after/" /etc/board.json
+       for e in $(ls /etc/config/* 2>/dev/null); do
+               sed -i "s/$before/$after/" "$e"
+       done
+       for e in $(ls /etc/sysctl.d/* 2>/dev/null); do
+               sed -i "s/$before/$after/" "$e"
+       done
+}
+
+case $(board_name) in
+glinet,gl-ar150|\
+tplink,archer-c58-v1|\
+tplink,archer-c59-v1|\
+tplink,archer-c60-v1|\
+tplink,archer-c60-v2)
+       rename_all_eth "eth0" "ethX"
+       rename_all_eth "eth1" "eth0"
+       rename_all_eth "ethX" "eth0"
+       ;;
+esac
+
+exit 0

However, this will obviously swap eth0/eth1 on EVERY upgrade, not just when coming from ar71xx.
So, does anyone have an idea how to limit this to run only when updated from ar71xx?

Despite, while having the abstraction of "rename_all_eth", I wonder whether it would be possible and desirable to do all renames in one step:
sed -i -e 's/eth0/ethX/' -e 's/eth1/eth0/' -e 's/ethX/eth1/' $file
or even
sed -i -e 's/eth0/eth1/' -e  's/eth0/eth1/' $file
depending on how sed handles this internally. These options would mean less flash writes (although this might not be too important here).

One might also need to add the 'g' modifier to sed to account for multiple ethX found per line, e.g. 'eth0.1 eth0.2'.
I will test the latter cases when I have more time, just wanted to start the discussion with this proposal.

Best

Adrian
-------------- next part --------------
A non-text attachment was scrubbed...
Name: openpgp-digital-signature.asc
Type: application/pgp-signature
Size: 834 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/openwrt-devel/attachments/20190905/b06f6ffa/attachment.sig>
-------------- next part --------------
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


More information about the openwrt-devel mailing list