forked from freifunk-franken/firmware
ETHPORT was used to configure devices with two physical ethernet ports, one of them being connected directly to the CPU, while the other one is connected to the internal switch of the platform. As the GL-AR150 has been converted to the TWO_PORT codepath and no other devices utilizes ETHPORT, remove all leftovers. Signed-off-by: Fabian Bläse <fabian@blaese.de> Tested-by: Sebastian Beck <freifunk@beibecks.de>
118 lines
4.8 KiB
Bash
Executable File
118 lines
4.8 KiB
Bash
Executable File
#!/bin/sh
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
. /lib/functions/system.sh
|
|
. /lib/functions/fff/network
|
|
|
|
BOARD="$(uci get board.model.name)"
|
|
. /etc/network.$BOARD
|
|
|
|
if [ -s /etc/network.config ] ; then
|
|
. /etc/network.config
|
|
else
|
|
# Write network.config
|
|
if [ "$ONE_PORT" = "YES" ] ; then
|
|
echo "ETHMODE='$ETHMODE' # use BATMAN, CLIENT or WAN" >> /etc/network.config
|
|
fi
|
|
if [ -n "$TWO_PORT" ] ; then
|
|
echo "LAN0MODE='$LAN0MODE' # use BATMAN, CLIENT or WAN" >> /etc/network.config
|
|
echo "LAN1MODE='$LAN1MODE' # use BATMAN, CLIENT or WAN" >> /etc/network.config
|
|
fi
|
|
echo "FORCEPARSE='0' # Parse at: 0=first boot only, 1=every reboot, 2=next reboot (once)" >> /etc/network.config
|
|
fi
|
|
|
|
if [ "$FORCEPARSE" = '2' ] ; then
|
|
sed -i '/^FORCEPARSE/d' /etc/network.config
|
|
echo "FORCEPARSE='0' # Parse at: 0=first boot only, 1=every reboot, 2=next reboot (once)" >> /etc/network.config
|
|
FORCEPARSE='1'
|
|
fi
|
|
|
|
if [ "$ONE_PORT" = "YES" ]; then
|
|
if ! uci -q get network.$SWITCHDEV.ifname || [ "$FORCEPARSE" = '1' ] ; then
|
|
uci set network.$SWITCHDEV=interface
|
|
uci set network.$SWITCHDEV.ifname=$SWITCHDEV
|
|
if [ "$ETHMODE" = "WAN" ]; then
|
|
uci set network.client.ifname="bat0"
|
|
uci set network.wan.ifname="$WANDEV"
|
|
uci del network.ethmesh.ifname
|
|
uci del network.${SWITCHDEV}.macaddr
|
|
elif [ "$ETHMODE" = "CLIENT" ] ; then
|
|
uci set network.client.ifname="bat0 $SWITCHDEV"
|
|
uci set network.wan.ifname="eth2" #eth2 because it is default in config file
|
|
uci del network.ethmesh.ifname
|
|
uci del network.${SWITCHDEV}.macaddr
|
|
elif [ "$ETHMODE" = "BATMAN" ] ; then
|
|
uci set network.client.ifname="bat0"
|
|
uci set network.wan.ifname="eth2" #eth2 because it is default in config file
|
|
uci set network.ethmesh.ifname="$SWITCHDEV"
|
|
ETH0DEV="$SWITCHDEV"
|
|
ETH0MAC="w2ap"
|
|
fi
|
|
uci commit network
|
|
fi
|
|
elif [ "$TWO_PORT" = "YES" ]; then
|
|
if ! uci -q get network.$WANDEV.ifname || [ "$FORCEPARSE" = '1' ] ; then
|
|
uci set network.$WANDEV=interface
|
|
uci set network.$WANDEV.ifname="$WANDEV"
|
|
uci set network.$SWITCHDEV=interface
|
|
uci set network.$SWITCHDEV.ifname="$SWITCHDEV"
|
|
# Only one WAN possible, second port will be unset if both are WAN
|
|
if [ "$LAN0MODE" = "WAN" ]; then
|
|
if [ "$LAN1MODE" = "CLIENT" ]; then
|
|
uci set network.client.ifname="bat0 $SWITCHDEV"; else
|
|
uci set network.client.ifname=bat0; fi
|
|
# WAN
|
|
uci set network.wan.ifname="$WANDEV"
|
|
if [ "$LAN1MODE" = "BATMAN" ]; then
|
|
uci set network.ethmesh.ifname="$SWITCHDEV"; else
|
|
uci del network.ethmesh.ifname; fi
|
|
# Two client ports are possible
|
|
elif [ "$LAN0MODE" = "CLIENT" ]; then
|
|
if [ "$LAN1MODE" = "CLIENT" ]; then
|
|
uci set network.client.ifname="bat0 $WANDEV $SWITCHDEV"; else
|
|
uci set network.client.ifname="bat0 $WANDEV"; fi
|
|
if [ "$LAN1MODE" = "WAN" ]; then
|
|
uci set network.wan.ifname="$SWITCHDEV"; else
|
|
uci set network.wan.ifname=eth2; fi #eth2 because it is default in config file
|
|
if [ "$LAN1MODE" = "BATMAN" ]; then
|
|
uci set network.ethmesh.ifname="$SWITCHDEV"; else
|
|
uci del network.ethmesh.ifname; fi
|
|
# Only one BATMAN port possible, second port will be unset if both are BATMAN
|
|
elif [ "$LAN0MODE" = "BATMAN" ] ; then
|
|
if [ "$LAN1MODE" = "CLIENT" ]; then
|
|
uci set network.client.ifname="bat0 $SWITCHDEV"; else
|
|
uci set network.client.ifname=bat0; fi
|
|
if [ "$LAN1MODE" = "WAN" ]; then
|
|
uci set network.wan.ifname="$SWITCHDEV"; else
|
|
uci set network.wan.ifname=eth2; fi #eth2 because it is default in config file
|
|
# BATMAN
|
|
uci set network.ethmesh.ifname="$WANDEV"
|
|
fi
|
|
if [ "$LAN0MODE" = "BATMAN" ]; then
|
|
ETH0DEV="$WANDEV" # only needed for setting macaddr
|
|
ETH0MAC=w2ap
|
|
uci del network.$SWITCHDEV.macaddr
|
|
elif [ "$LAN1MODE" = "BATMAN" ]; then
|
|
# $WANDEV will win if both are set to BATMAN, as above
|
|
ETH0DEV="$SWITCHDEV" # only needed for setting macaddr
|
|
ETH0MAC=w2ap
|
|
uci del network.$WANDEV.macaddr
|
|
else
|
|
uci del network.$WANDEV.macaddr
|
|
uci del network.$SWITCHDEV.macaddr
|
|
fi
|
|
|
|
uci commit network
|
|
fi
|
|
fi
|
|
|
|
if [ -n "$ETH0MAC" ]; then
|
|
echo "Fixing MAC on $ETH0DEV"
|
|
sleep 10
|
|
NEW_MACADDR=$(cat "/sys/class/net/${ETH0MAC}/address")
|
|
uci set network.$ETH0DEV.macaddr=$NEW_MACADDR
|
|
uci commit network
|
|
fi
|
|
|
|
reload_config
|