From b0c814690543d11608016f19589e0122b7753bd9 Mon Sep 17 00:00:00 2001
From: Sukru Senli <sukru.senli@iopsys.eu>
Date: Thu, 10 Feb 2022 11:26:05 +0100
Subject: [PATCH] iopsys-econet: handlet eth_portmap based on network config

---
 .../netifd/pre-reload/tc3162-eth-portmap.sh   | 47 +++++++++++++++++++
 1 file changed, 47 insertions(+)
 create mode 100644 iopsys-econet/base-files/lib/netifd/pre-reload/tc3162-eth-portmap.sh

diff --git a/iopsys-econet/base-files/lib/netifd/pre-reload/tc3162-eth-portmap.sh b/iopsys-econet/base-files/lib/netifd/pre-reload/tc3162-eth-portmap.sh
new file mode 100644
index 000000000..ac86f282c
--- /dev/null
+++ b/iopsys-econet/base-files/lib/netifd/pre-reload/tc3162-eth-portmap.sh
@@ -0,0 +1,47 @@
+#!/bin/sh
+
+tc3162_eth_portmap() {
+	[ -d /proc/tc3162 ] || return 0
+
+	wan_port="-1"
+	lan1_port="-1"
+	lan2_port="-1"
+	lan3_port="-1"
+	lan4_port="-1"
+	lan5_port="-1"
+	lan6_port="-1"
+
+	wandevice="$(uci -q get network.wan.device)"
+	case "$wandevice" in
+		eth0.[0-9])
+			wan_port=${wandevice:5}
+		;;
+	esac
+
+	landevice=$(uci -q get network.lan.device)
+	case "$landevice" in
+		eth0.[0-9])
+			lan1_port="${landevice:5}"
+		;;
+		br-lan)
+			section="$(uci show network | grep 'name=.*br-lan' | cut -d'.' -f2)"
+			lan_ports="$(uci -q get network.$section.ports)"
+			lan1_port=$(echo $lan_ports | cut -d' ' -f1 | cut -d'.' -f2)
+			lan1_port="${lan1_port:--1}"
+			lan2_port=$(echo $lan_ports | cut -d' ' -f2 | cut -d'.' -f2)
+			lan2_port="${lan2_port:--1}"
+			lan3_port=$(echo $lan_ports | cut -d' ' -f3 | cut -d'.' -f2)
+			lan3_port="${lan3_port:--1}"
+			lan4_port=$(echo $lan_ports | cut -d' ' -f4 | cut -d'.' -f2)
+			lan4_port="${lan4_port:--1}"
+			lan5_port=$(echo $lan_ports | cut -d' ' -f5 | cut -d'.' -f2)
+			lan5_port="${lan5_port:--1}"
+			lan6_port=$(echo $lan_ports | cut -d' ' -f6 | cut -d'.' -f2)
+			lan6_port="${lan6_port:--1}"				
+		;;
+	esac
+
+	echo $wan_port $lan1_port $lan2_port $lan3_port $lan4_port $lan5_port $lan6_port > /proc/tc3162/eth_portmap
+}
+
+tc3162_eth_portmap
-- 
GitLab