2014-11-12 21:22:55 +01:00
|
|
|
#!/bin/sh
|
2021-02-10 01:53:21 +01:00
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
2014-11-10 20:31:28 +01:00
|
|
|
|
2017-11-03 09:18:01 +01:00
|
|
|
. /lib/functions/fff/network
|
|
|
|
|
2018-01-02 15:52:07 +01:00
|
|
|
setupPorts() {
|
|
|
|
# Add a single port to the *_PORTS config
|
|
|
|
# Usage: setupPorts <port id> <port mode>
|
|
|
|
|
|
|
|
local port=$1
|
|
|
|
local mode=$2
|
|
|
|
|
|
|
|
#default: BATMAN
|
|
|
|
if [ "$mode" = "WAN" ] ; then
|
|
|
|
WAN_PORTS="${WAN_PORTS} $port"
|
|
|
|
elif [ "$mode" = "CLIENT" ] ; then
|
|
|
|
CLIENT_PORTS="${CLIENT_PORTS} $port"
|
|
|
|
else
|
|
|
|
BATMAN_PORTS="${BATMAN_PORTS} $port"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2016-05-16 14:26:49 +02:00
|
|
|
BOARD="$(uci get board.model.name)"
|
|
|
|
. /etc/network.$BOARD
|
|
|
|
|
2017-08-21 18:46:28 +02:00
|
|
|
if [ -s /etc/network.config ] ; then
|
|
|
|
. /etc/network.config
|
|
|
|
else
|
2018-01-02 15:52:07 +01:00
|
|
|
# Write network.config
|
2017-08-21 18:46:28 +02:00
|
|
|
echo "CLIENT_PORTS='$CLIENT_PORTS'" > /etc/network.config
|
|
|
|
echo "BATMAN_PORTS='$BATMAN_PORTS'" >> /etc/network.config
|
|
|
|
if [ -n "$WAN_PORTS" ] ; then
|
|
|
|
echo "WAN_PORTS='$WAN_PORTS'" >> /etc/network.config
|
|
|
|
fi
|
|
|
|
if [ "$ONE_PORT" = "YES" ] || [ -n "$ETHPORT" ] ; then
|
|
|
|
echo "ETHMODE='$ETHMODE' # use BATMAN, CLIENT or WAN" >> /etc/network.config
|
|
|
|
fi
|
|
|
|
if [ -n "$LAN0PORT" ] ; then
|
|
|
|
echo "LAN0MODE='$LAN0MODE' # use BATMAN, CLIENT or WAN" >> /etc/network.config
|
|
|
|
fi
|
|
|
|
if [ -n "$LAN1PORT" ] ; then
|
|
|
|
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 [ -n "$ETHPORT" ] ; then
|
|
|
|
#LAN@AR150: default: BATMAN
|
2018-01-02 15:52:07 +01:00
|
|
|
setupPorts "$ETHPORT" "${ETHMODE}"
|
2017-08-21 18:46:28 +02:00
|
|
|
fi
|
|
|
|
if [ -n "$LAN0PORT" ] ; then
|
|
|
|
#LAN0@two-port: default: BATMAN
|
2018-01-02 15:52:07 +01:00
|
|
|
setupPorts "$LAN0PORT" "${LAN0MODE}"
|
2017-08-21 18:46:28 +02:00
|
|
|
fi
|
|
|
|
if [ -n "$LAN1PORT" ] ; then
|
|
|
|
#LAN1@two-port: default: BATMAN
|
2018-01-02 15:52:07 +01:00
|
|
|
setupPorts "$LAN1PORT" "${LAN1MODE}"
|
2017-08-21 18:46:28 +02:00
|
|
|
fi
|
|
|
|
|
2017-08-21 18:46:27 +02:00
|
|
|
if ! uci -q get network.$SWITCHDEV > /dev/null || [ "$FORCEPARSE" = '1' ] ; then
|
2014-08-16 01:11:18 +02:00
|
|
|
|
|
|
|
SWITCHHW=$(swconfig list | awk '{ print $4 }')
|
|
|
|
|
2014-04-11 22:39:34 +02:00
|
|
|
uci set network.$SWITCHDEV=switch
|
2014-08-16 01:11:18 +02:00
|
|
|
uci set network.$SWITCHDEV.name=$SWITCHHW
|
2014-04-11 22:39:34 +02:00
|
|
|
uci set network.$SWITCHDEV.enable=1
|
|
|
|
uci set network.$SWITCHDEV.reset=1
|
|
|
|
uci set network.$SWITCHDEV.enable_vlan=1
|
|
|
|
|
|
|
|
uci set network.${SWITCHDEV}_1=switch_vlan
|
2014-08-16 01:11:18 +02:00
|
|
|
uci set network.${SWITCHDEV}_1.device=$SWITCHHW
|
2014-04-11 22:39:34 +02:00
|
|
|
uci set network.${SWITCHDEV}_1.vlan=1
|
|
|
|
uci set network.${SWITCHDEV}_1.ports="$CLIENT_PORTS"
|
|
|
|
|
2018-07-25 16:45:54 +02:00
|
|
|
if [ "$WANDEV" = "$SWITCHDEV" ] || ! [ -z "$WAN_PORTS" ]; then
|
2014-04-11 22:39:34 +02:00
|
|
|
uci set network.${SWITCHDEV}_2=switch_vlan
|
2014-08-16 01:11:18 +02:00
|
|
|
uci set network.${SWITCHDEV}_2.device=$SWITCHHW
|
2014-04-11 22:39:34 +02:00
|
|
|
uci set network.${SWITCHDEV}_2.vlan=2
|
|
|
|
uci set network.${SWITCHDEV}_2.ports="$WAN_PORTS"
|
|
|
|
fi
|
2020-07-31 22:59:15 +02:00
|
|
|
|
2014-04-11 22:39:34 +02:00
|
|
|
uci set network.${SWITCHDEV}_3=switch_vlan
|
2014-08-16 01:11:18 +02:00
|
|
|
uci set network.${SWITCHDEV}_3.device=$SWITCHHW
|
2014-04-11 22:39:34 +02:00
|
|
|
uci set network.${SWITCHDEV}_3.vlan=3
|
|
|
|
uci set network.${SWITCHDEV}_3.ports="$BATMAN_PORTS"
|
|
|
|
|
2020-12-18 20:49:01 +01:00
|
|
|
uci set network.client.ifname="$SWITCHDEV.1 bat0"
|
2014-04-11 22:39:34 +02:00
|
|
|
|
|
|
|
uci set network.ethmesh.ifname="$SWITCHDEV.3"
|
|
|
|
|
2018-07-25 16:45:54 +02:00
|
|
|
if [ "$WANDEV" = "$SWITCHDEV" ]; then
|
2014-04-11 22:39:34 +02:00
|
|
|
uci set network.wan.ifname=$WANDEV.2
|
|
|
|
else
|
|
|
|
uci set network.wan.ifname=$WANDEV
|
|
|
|
fi
|
|
|
|
|
2017-11-23 21:26:32 +01:00
|
|
|
uci commit network
|
2014-04-11 22:39:34 +02:00
|
|
|
fi
|
2014-04-12 19:15:31 +02:00
|
|
|
|
2017-08-21 18:46:27 +02:00
|
|
|
if [ "$ONE_PORT" = "YES" ] && ( ! uci -q get network.$SWITCHDEV.ifname || [ "$FORCEPARSE" = '1' ] ) ; then
|
2016-09-15 21:45:20 +02:00
|
|
|
uci set network.$SWITCHDEV=interface
|
|
|
|
uci set network.$SWITCHDEV.ifname=$SWITCHDEV
|
|
|
|
if [ "$ETHMODE" = "WAN" ]; then
|
2020-12-18 20:49:01 +01:00
|
|
|
uci set network.client.ifname="bat0"
|
2016-09-15 21:45:20 +02:00
|
|
|
uci set network.wan.ifname="$WANDEV"
|
2020-08-05 22:39:57 +02:00
|
|
|
uci del network.ethmesh.ifname
|
2021-02-15 21:22:10 +01:00
|
|
|
uci del network.${SWITCHDEV}.macaddr
|
2016-09-15 21:45:20 +02:00
|
|
|
elif [ "$ETHMODE" = "CLIENT" ] ; then
|
2020-12-18 20:49:01 +01:00
|
|
|
uci set network.client.ifname="bat0 $SWITCHDEV"
|
fff-network: fix unintended wan=eth1 for two-port devices
For historic reasons, the wan interface is set to eth1 as default
value. When updating the config for one-port devices in
configurenetwork, the same value is put there again if the mode
is switched to something != WAN, instead of just removing the
value.
While ifname actually is a mandatory value, this has been handled
inconsistently in the past, where ethmesh ifname was deleted, and
wan ifname was just changed back to eth1, when assigning the
actually relevant eth0 to a different task.
This concept was set up with a one-port device in mind, i.e. a
device where there is no eth1. However, this very setup routine
got applied to the Nanostation M as well (which is treated as
as one-port), where we suddenly have two interfaces and the eth1
exists.
So, while the user assumes it's unconfigured, the second port
actually becomes set up as WAN if the first one is != WAN.
If connected to a second device with CLIENT (=default) to provide
PoE there, this will create a loop.
So, finally, in order to somehow fix this mess, this patch just
changes the hardcoded "eth1" to "eth2". While this is no proper
fix, it perpetuates the original idea of keeping wan set to
something, but nothing which actually exists. However, there are
no sideeffects and we keep this minimal-invasive.
Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
Reviewed-by: Fabian Bläse <fabian@blaese.de>
2020-08-05 22:39:58 +02:00
|
|
|
uci set network.wan.ifname="eth2" #eth2 because it is default in config file
|
2016-09-15 21:45:20 +02:00
|
|
|
uci del network.ethmesh.ifname
|
2021-02-15 21:22:10 +01:00
|
|
|
uci del network.${SWITCHDEV}.macaddr
|
2016-09-15 21:45:20 +02:00
|
|
|
elif [ "$ETHMODE" = "BATMAN" ] ; then
|
2020-12-18 20:49:01 +01:00
|
|
|
uci set network.client.ifname="bat0"
|
fff-network: fix unintended wan=eth1 for two-port devices
For historic reasons, the wan interface is set to eth1 as default
value. When updating the config for one-port devices in
configurenetwork, the same value is put there again if the mode
is switched to something != WAN, instead of just removing the
value.
While ifname actually is a mandatory value, this has been handled
inconsistently in the past, where ethmesh ifname was deleted, and
wan ifname was just changed back to eth1, when assigning the
actually relevant eth0 to a different task.
This concept was set up with a one-port device in mind, i.e. a
device where there is no eth1. However, this very setup routine
got applied to the Nanostation M as well (which is treated as
as one-port), where we suddenly have two interfaces and the eth1
exists.
So, while the user assumes it's unconfigured, the second port
actually becomes set up as WAN if the first one is != WAN.
If connected to a second device with CLIENT (=default) to provide
PoE there, this will create a loop.
So, finally, in order to somehow fix this mess, this patch just
changes the hardcoded "eth1" to "eth2". While this is no proper
fix, it perpetuates the original idea of keeping wan set to
something, but nothing which actually exists. However, there are
no sideeffects and we keep this minimal-invasive.
Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
Reviewed-by: Fabian Bläse <fabian@blaese.de>
2020-08-05 22:39:58 +02:00
|
|
|
uci set network.wan.ifname="eth2" #eth2 because it is default in config file
|
2016-09-15 21:45:20 +02:00
|
|
|
uci set network.ethmesh.ifname="$SWITCHDEV"
|
|
|
|
ETH0MAC="w2ap"
|
|
|
|
fi
|
2017-11-23 21:26:32 +01:00
|
|
|
uci commit network
|
2016-09-15 21:45:20 +02:00
|
|
|
fi
|
|
|
|
|
2017-08-21 18:46:27 +02:00
|
|
|
/etc/init.d/network restart
|
|
|
|
|
2018-07-25 16:45:54 +02:00
|
|
|
if [ -n "$ETHMESHMAC" ]; then
|
2014-04-12 19:15:31 +02:00
|
|
|
if uci get network.ethmesh.macaddr
|
|
|
|
then
|
|
|
|
echo "MAC for ethmesh is set already"
|
|
|
|
else
|
2017-11-04 23:28:31 +01:00
|
|
|
echo "Fixing MAC on $SWITCHDEV.3 (ethmesh)"
|
2014-08-17 14:56:31 +02:00
|
|
|
sleep 10
|
2017-11-03 15:59:18 +01:00
|
|
|
|
|
|
|
uci set network.ethmesh.macaddr=$ETHMESHMAC
|
2017-11-23 21:26:32 +01:00
|
|
|
uci commit network
|
2017-11-03 15:59:18 +01:00
|
|
|
|
2017-11-04 23:28:31 +01:00
|
|
|
ifconfig $SWITCHDEV.3 down
|
2017-11-14 11:44:49 +01:00
|
|
|
ifconfig $SWITCHDEV.3 hw ether $ETHMESHMAC
|
2017-11-04 23:28:31 +01:00
|
|
|
ifconfig $SWITCHDEV.3 up
|
2014-08-17 14:56:31 +02:00
|
|
|
/etc/init.d/network restart
|
2014-04-12 19:15:31 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2018-07-25 16:45:54 +02:00
|
|
|
if [ -n "$ROUTERMAC" ]; then
|
2020-12-18 20:49:01 +01:00
|
|
|
if uci get network.client.macaddr
|
2014-04-12 19:15:31 +02:00
|
|
|
then
|
2020-12-18 20:49:01 +01:00
|
|
|
echo "MAC for client is set already"
|
2014-04-12 19:15:31 +02:00
|
|
|
else
|
2020-12-18 20:49:01 +01:00
|
|
|
echo "Fixing MAC on br-client"
|
2014-08-17 14:56:31 +02:00
|
|
|
sleep 10
|
2017-11-03 15:59:18 +01:00
|
|
|
|
2020-12-18 20:49:01 +01:00
|
|
|
uci set network.client.macaddr=$ROUTERMAC
|
2017-11-23 21:26:32 +01:00
|
|
|
uci commit network
|
2017-11-03 15:59:18 +01:00
|
|
|
|
2020-12-18 20:49:01 +01:00
|
|
|
ifconfig br-client down
|
|
|
|
ifconfig br-client hw ether $ROUTERMAC
|
|
|
|
ifconfig br-client up
|
2014-08-17 14:56:31 +02:00
|
|
|
/etc/init.d/network restart
|
2014-04-12 19:15:31 +02:00
|
|
|
fi
|
2015-12-31 15:49:55 +01:00
|
|
|
fi
|
|
|
|
|
2018-07-25 16:45:54 +02:00
|
|
|
if [ -n "$ETH0MAC" ]; then
|
2021-02-15 21:22:10 +01:00
|
|
|
echo "Fixing MAC on $SWITCHDEV"
|
2015-12-31 15:49:55 +01:00
|
|
|
sleep 10
|
2016-01-23 16:59:00 +01:00
|
|
|
NEW_MACADDR=$(cat "/sys/class/net/${ETH0MAC}/address")
|
2021-02-15 21:22:10 +01:00
|
|
|
uci set network.${SWITCHDEV}.macaddr=$NEW_MACADDR
|
2017-11-23 21:26:32 +01:00
|
|
|
uci commit network
|
2021-02-15 21:22:10 +01:00
|
|
|
ifconfig $SWITCHDEV down
|
|
|
|
ifconfig $SWITCHDEV hw ether $NEW_MACADDR
|
|
|
|
ifconfig $SWITCHDEV up
|
2015-12-31 15:49:55 +01:00
|
|
|
/etc/init.d/network restart
|
|
|
|
fi
|
2016-01-30 11:59:46 +01:00
|
|
|
|
2020-12-18 20:49:01 +01:00
|
|
|
if uci -q get "network.client.ip6addr" > /dev/null
|
2016-01-30 11:59:46 +01:00
|
|
|
then
|
2020-12-18 20:49:01 +01:00
|
|
|
echo "IPv6 for client is set already"
|
2016-01-30 11:59:46 +01:00
|
|
|
else
|
2018-06-17 14:54:15 +02:00
|
|
|
echo "Setting IPv6 addresses"
|
2016-01-30 11:59:46 +01:00
|
|
|
# Some time needed :(
|
|
|
|
sleep 5
|
|
|
|
|
2020-12-18 20:49:01 +01:00
|
|
|
for ip in $(ip -6 addr show br-client | awk '/fdff/{ print $2 }'); do
|
|
|
|
ip -6 addr del $ip dev br-client
|
2016-01-30 11:59:46 +01:00
|
|
|
done
|
|
|
|
|
2021-01-13 21:12:54 +01:00
|
|
|
prefix="fdff::/64"
|
2016-01-30 11:59:46 +01:00
|
|
|
# Set $prefix::MAC as IP
|
2021-01-13 21:12:54 +01:00
|
|
|
addr=$(owipcalc "$prefix" add "::$(ipMacSuffix "$ROUTERMAC")")
|
2020-12-18 20:49:01 +01:00
|
|
|
ip -6 addr add $addr dev br-client
|
2016-01-30 11:59:46 +01:00
|
|
|
|
|
|
|
uci -q del network.globals
|
|
|
|
uci -q set network.globals=globals
|
|
|
|
uci -q set network.globals.ula_prefix=$prefix
|
2020-12-18 20:49:01 +01:00
|
|
|
uci -q add_list network.client.ip6addr=$addr
|
|
|
|
uci -q set network.client.proto=static
|
2016-01-30 11:59:46 +01:00
|
|
|
|
|
|
|
# Set $prefix::1 as IP
|
2021-01-13 21:12:54 +01:00
|
|
|
addr=$(owipcalc "$prefix" add ::1)
|
2020-12-18 20:49:01 +01:00
|
|
|
ip -6 addr add $addr dev br-client
|
|
|
|
uci -q add_list network.client.ip6addr=$addr
|
2016-01-30 11:59:46 +01:00
|
|
|
|
|
|
|
# Set $prefix::link-local as IP
|
2021-01-13 21:12:54 +01:00
|
|
|
addr=$(owipcalc "$prefix" add "::$(ipEUISuffix "$ROUTERMAC")")
|
2020-12-18 20:49:01 +01:00
|
|
|
ip -6 addr add $addr dev br-client
|
|
|
|
uci -q add_list network.client.ip6addr=$addr
|
2016-01-30 11:59:46 +01:00
|
|
|
|
|
|
|
uci -q commit network
|
|
|
|
|
2019-09-08 15:09:06 +02:00
|
|
|
[ -s /etc/init.d/fff-uradvd ] && /etc/init.d/fff-uradvd restart
|
2016-01-30 11:59:46 +01:00
|
|
|
fi
|