2014-11-12 21:22:55 +01:00
|
|
|
#!/bin/sh
|
2014-11-10 20:31:28 +01:00
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
|
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"
|
|
|
|
|
|
|
|
uci set network.mesh.ifname="$SWITCHDEV.1 bat0"
|
|
|
|
|
|
|
|
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
|
|
|
|
uci set network.mesh.ifname="bat0"
|
|
|
|
uci set network.wan.ifname="$WANDEV"
|
2020-08-05 22:39:57 +02:00
|
|
|
uci del network.ethmesh.ifname
|
2016-09-15 21:45:20 +02:00
|
|
|
uci del network.eth0.macaddr
|
|
|
|
elif [ "$ETHMODE" = "CLIENT" ] ; then
|
|
|
|
uci set network.mesh.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
|
|
|
|
uci del network.eth0.macaddr
|
|
|
|
elif [ "$ETHMODE" = "BATMAN" ] ; then
|
|
|
|
uci set network.mesh.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
|
2014-04-12 19:15:31 +02:00
|
|
|
if uci get network.mesh.macaddr
|
|
|
|
then
|
|
|
|
echo "MAC for mesh is set already"
|
|
|
|
else
|
|
|
|
echo "Fixing MAC on br-mesh (mesh)"
|
2014-08-17 14:56:31 +02:00
|
|
|
sleep 10
|
2017-11-03 15:59:18 +01:00
|
|
|
|
|
|
|
uci set network.mesh.macaddr=$ROUTERMAC
|
2017-11-23 21:26:32 +01:00
|
|
|
uci commit network
|
2017-11-03 15:59:18 +01:00
|
|
|
|
2014-04-12 19:15:31 +02:00
|
|
|
ifconfig br-mesh down
|
2017-11-14 11:44:49 +01:00
|
|
|
ifconfig br-mesh hw ether $ROUTERMAC
|
2014-04-12 19:15:31 +02:00
|
|
|
ifconfig br-mesh 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
|
2015-12-31 15:49:55 +01:00
|
|
|
echo "Fixing MAC on eth0"
|
|
|
|
sleep 10
|
2016-01-23 16:59:00 +01:00
|
|
|
NEW_MACADDR=$(cat "/sys/class/net/${ETH0MAC}/address")
|
2015-12-31 15:49:55 +01:00
|
|
|
uci set network.eth0.macaddr=$NEW_MACADDR
|
2017-11-23 21:26:32 +01:00
|
|
|
uci commit network
|
2015-12-31 15:49:55 +01:00
|
|
|
ifconfig eth0 down
|
|
|
|
ifconfig eth0 hw ether $NEW_MACADDR
|
|
|
|
ifconfig eth0 up
|
|
|
|
/etc/init.d/network restart
|
|
|
|
fi
|
2016-01-30 11:59:46 +01:00
|
|
|
|
2018-06-17 14:54:15 +02:00
|
|
|
if uci -q get "network.mesh.ip6addr" > /dev/null
|
2016-01-30 11:59:46 +01:00
|
|
|
then
|
|
|
|
echo "IPv6 for mesh is set already"
|
|
|
|
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
|
|
|
|
|
|
|
|
for ip in $(ip -6 addr show br-mesh | awk '/fdff/{ print $2 }'); do
|
|
|
|
ip -6 addr del $ip dev br-mesh
|
|
|
|
done
|
|
|
|
|
|
|
|
prefix="fdff:0::/64"
|
|
|
|
# Set $prefix::MAC as IP
|
2018-01-03 00:37:08 +01:00
|
|
|
addr="$(ipMacAssemble "$prefix" "$ROUTERMAC")"
|
2016-01-30 11:59:46 +01:00
|
|
|
ip -6 addr add $addr dev br-mesh
|
|
|
|
|
|
|
|
uci -q del network.globals
|
|
|
|
uci -q set network.globals=globals
|
|
|
|
uci -q set network.globals.ula_prefix=$prefix
|
|
|
|
uci -q add_list network.mesh.ip6addr=$addr
|
|
|
|
uci -q set network.mesh.proto=static
|
|
|
|
|
|
|
|
# Set $prefix::1 as IP
|
2017-11-03 09:18:01 +01:00
|
|
|
addr="$(ipAssemble "$prefix" "1")"
|
2016-01-30 11:59:46 +01:00
|
|
|
ip -6 addr add $addr dev br-mesh
|
|
|
|
uci -q add_list network.mesh.ip6addr=$addr
|
|
|
|
|
|
|
|
# Set $prefix::link-local as IP
|
2018-01-03 00:37:08 +01:00
|
|
|
addr="$(ipEUIAssemble "$prefix" "$ROUTERMAC")"
|
2016-01-30 11:59:46 +01:00
|
|
|
ip -6 addr add $addr dev br-mesh
|
|
|
|
uci -q add_list network.mesh.ip6addr=$addr
|
|
|
|
|
|
|
|
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
|