[OpenWrt-Devel] Migration in ath79 for swapped ethernet
diff mbox series

Message ID 020101d563fa$a14539a0$e3cface0$@adrianschmutzler.de
State New
Headers show
Series
  • [OpenWrt-Devel] Migration in ath79 for swapped ethernet
Related show

Commit Message

Adrian Schmutzler Sept. 5, 2019, 3 p.m. UTC
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):


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

Comments

David Bauer Sept. 7, 2019, 9:39 a.m. UTC | #1
Hello Adrian,

On 9/5/19 5:00 PM, Adrian Schmutzler wrote:
> 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?

I was thinking about the same. As we have no information about the previously installed platform,
i was thinking about abusing the wmac path we already use to migrate the WiFi configuration.
However, i think this is not the most elegant way to solve this issue.

> 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).

A rewrite with sed is not sufficient, as we will possible rewrite uci section names, possibly
referenced elsewhere. We have to loop thru all interface values and lists, rewriting each occurrence. 

Best wishes
David
Adrian Schmutzler Sept. 7, 2019, 10:15 a.m. UTC | #2
Hi,

> > 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?
> 
> I was thinking about the same. As we have no information about the
> previously installed platform, i was thinking about abusing the wmac path we
> already use to migrate the WiFi configuration.
> However, i think this is not the most elegant way to solve this issue.

I have to think about that. I recently thought one could just check whether the lan/wan assignment matches the one expected for ar71xx, but that would obviously also catch cases were the user modified it to be like this.

> 
> > 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).
> 
> A rewrite with sed is not sufficient, as we will possible rewrite uci section
> names, possibly referenced elsewhere. We have to loop thru all interface
> values and lists, rewriting each occurrence.

Actually, I could well live with that. What kind of references are you referring to?
If just someone really named a section with ethX, it will be renamed consistently throught all uci files (unless they are stored in another location).
Only in case someone uses a section name with ethX and refers to it e.g. in a custom script, this will be a problem.
And this is where I think we do not have to account for every tiny possibility. If someone upgrades to another architecture, I think it's fair to expect him to check whether his custom scripts still work. We do not have to overdo it.
But that's just my point of view at the moment.

Best

Adrian

Patch
diff mbox series

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