[OpenWrt-Devel] Migration in ath79 for swapped ethernet

David Bauer mail at david-bauer.net
Sat Sep 7 05:39:30 EDT 2019


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

_______________________________________________
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