diff mbox series

[2/3] realtek: sort the port list numerically

Message ID 20210412122725.29430-3-bjorn@mork.no
State Superseded, archived
Headers show
Series realtek: fix default network configuration | expand

Commit Message

Bjørn Mork April 12, 2021, 12:27 p.m. UTC
Mac adresses are assigned in the order given by the port list.  The
interfaces are also brought up in this order.  This target supports
devices with up to 52 ports.  Sorting these alphabetically is very
confusing, and assigning mac addresses in alphabetic order does not
match stock firmware behaviour.

There are probably better ways to do the numrical sorting, but this
was what I came up with...

Signed-off-by: Bjørn Mork <bjorn@mork.no>
---
 target/linux/realtek/base-files/etc/board.d/02_network | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

Comments

Sander Vanheule April 12, 2021, 2:52 p.m. UTC | #1
Hi Bjørn,

On Mon, 2021-04-12 at 14:27 +0200, Bjørn Mork wrote:
> Mac adresses are assigned in the order given by the port list.  The
> interfaces are also brought up in this order.  This target supports
> devices with up to 52 ports.  Sorting these alphabetically is very
> confusing, and assigning mac addresses in alphabetic order does not
> match stock firmware behaviour.
> 
> There are probably better ways to do the numrical sorting, but this
> was what I came up with...
> 

ls has the -v flag for numerical ("version") sorting:
	# ls 
	lan0   lan1   lan10  lan2
	# ls -v
	lan0   lan1   lan2   lan10


> Signed-off-by: Bjørn Mork <bjorn@mork.no>
> ---
>  target/linux/realtek/base-files/etc/board.d/02_network | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/target/linux/realtek/base-files/etc/board.d/02_network
> b/target/linux/realtek/base-files/etc/board.d/02_network
> index 44f1f0a7a5c1..06293174b0df 100644
> --- a/target/linux/realtek/base-files/etc/board.d/02_network
> +++ b/target/linux/realtek/base-files/etc/board.d/02_network
> @@ -17,10 +17,7 @@ ucidef_set_poe() {
>  board=$(board_name)
>  board_config_update
>  
> -lan_list=""
> -for lan in /sys/class/net/lan*; do
> -       lan_list="$lan_list $(basename $lan)"
> -done
> +lan_list=$(for lan in /sys/class/net/lan*; do echo
> "${lan#/sys/class/net/lan}"; done|sort -n|sed -e 's/^/lan/'|xargs)

So (unless my little test was bad) this can be shortened to:
	lan_list="$(ls -1 -v /sys/class/net/lan* | xargs -n1
basename)"

Best,
Sander
Bjørn Mork April 12, 2021, 3:03 p.m. UTC | #2
Sander Vanheule <sander@svanheule.net> writes:

> ls has the -v flag for numerical ("version") sorting:
> 	# ls 
> 	lan0   lan1   lan10  lan2
> 	# ls -v
> 	lan0   lan1   lan2   lan10

Thanks. Was staring at the limited functionality of the busybox sort
app, but didn't think to look at the ls app...

Your variant looks much better.


Bjørn
diff mbox series

Patch

diff --git a/target/linux/realtek/base-files/etc/board.d/02_network b/target/linux/realtek/base-files/etc/board.d/02_network
index 44f1f0a7a5c1..06293174b0df 100644
--- a/target/linux/realtek/base-files/etc/board.d/02_network
+++ b/target/linux/realtek/base-files/etc/board.d/02_network
@@ -17,10 +17,7 @@  ucidef_set_poe() {
 board=$(board_name)
 board_config_update
 
-lan_list=""
-for lan in /sys/class/net/lan*; do
-	lan_list="$lan_list $(basename $lan)"
-done
+lan_list=$(for lan in /sys/class/net/lan*; do echo "${lan#/sys/class/net/lan}"; done|sort -n|sed -e 's/^/lan/'|xargs)
 ucidef_set_bridge_device switch
 ucidef_set_interface_lan "$lan_list"