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
|
|
|
|
2021-02-10 01:18:28 +01:00
|
|
|
. /lib/functions/system.sh
|
2017-11-03 09:18:01 +01:00
|
|
|
. /lib/functions/fff/network
|
|
|
|
|
2016-05-16 14:26:49 +02:00
|
|
|
BOARD="$(uci get board.model.name)"
|
|
|
|
. /etc/network.$BOARD
|
2021-02-10 01:18:28 +01:00
|
|
|
[ -n "$ROUTERMAC" ] || ROUTERMAC=$(get_mac_label)
|
2016-05-16 14:26:49 +02:00
|
|
|
|
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
|
2021-06-08 21:58:03 +02:00
|
|
|
if [ -n "$TWO_PORT" ] ; then
|
2017-08-21 18:46:28 +02:00
|
|
|
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
|
|
|
|
|
2021-06-08 21:58:03 +02:00
|
|
|
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
|
2017-08-21 18:46:28 +02:00
|
|
|
|
2021-06-08 21:58:03 +02:00
|
|
|
uci commit network
|
|
|
|
fi
|
|
|
|
else
|
2020-08-05 22:31:19 +02:00
|
|
|
if ! uci -q get network.$SWITCHDEV > /dev/null || [ "$FORCEPARSE" = '1' ] ; then
|
2020-07-31 22:59:15 +02:00
|
|
|
|
2020-08-05 22:31:19 +02:00
|
|
|
SWITCHHW=$(swconfig list | awk '{ print $4 }')
|
2014-04-11 22:39:34 +02:00
|
|
|
|
2020-08-05 22:31:19 +02:00
|
|
|
uci set network.$SWITCHDEV=switch
|
|
|
|
uci set network.$SWITCHDEV.name=$SWITCHHW
|
|
|
|
uci set network.$SWITCHDEV.enable=1
|
|
|
|
uci set network.$SWITCHDEV.reset=1
|
|
|
|
uci set network.$SWITCHDEV.enable_vlan=1
|
2014-04-11 22:39:34 +02:00
|
|
|
|
2020-08-05 22:31:19 +02:00
|
|
|
uci set network.${SWITCHDEV}_1=switch_vlan
|
|
|
|
uci set network.${SWITCHDEV}_1.device=$SWITCHHW
|
|
|
|
uci set network.${SWITCHDEV}_1.vlan=1
|
|
|
|
uci set network.${SWITCHDEV}_1.ports="$CLIENT_PORTS"
|
2014-04-11 22:39:34 +02:00
|
|
|
|
2021-06-09 12:31:29 +02:00
|
|
|
if [ "$WANDEV" = "$SWITCHDEV" ] || [ -n "$WAN_PORTS" ]; then
|
2020-08-05 22:31:19 +02:00
|
|
|
uci set network.${SWITCHDEV}_2=switch_vlan
|
|
|
|
uci set network.${SWITCHDEV}_2.device=$SWITCHHW
|
|
|
|
uci set network.${SWITCHDEV}_2.vlan=2
|
|
|
|
uci set network.${SWITCHDEV}_2.ports="$WAN_PORTS"
|
|
|
|
fi
|
2014-04-11 22:39:34 +02:00
|
|
|
|
2020-08-05 22:31:19 +02:00
|
|
|
uci set network.${SWITCHDEV}_3=switch_vlan
|
|
|
|
uci set network.${SWITCHDEV}_3.device=$SWITCHHW
|
|
|
|
uci set network.${SWITCHDEV}_3.vlan=3
|
|
|
|
uci set network.${SWITCHDEV}_3.ports="$BATMAN_PORTS"
|
|
|
|
|
|
|
|
uci set network.client.ifname="$SWITCHDEV.1 bat0"
|
|
|
|
|
|
|
|
uci set network.ethmesh.ifname="$SWITCHDEV.3"
|
2014-04-12 19:15:31 +02:00
|
|
|
|
2020-08-05 22:31:19 +02:00
|
|
|
if [ "$WANDEV" = "$SWITCHDEV" ]; then
|
|
|
|
uci set network.wan.ifname=$WANDEV.2
|
|
|
|
else
|
|
|
|
uci set network.wan.ifname=$WANDEV
|
|
|
|
fi
|
|
|
|
|
|
|
|
uci commit network
|
2016-09-15 21:45:20 +02:00
|
|
|
fi
|
|
|
|
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-06-08 21:58:03 +02:00
|
|
|
echo "Fixing MAC on $ETH0DEV"
|
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-06-08 21:58:03 +02:00
|
|
|
uci set network.$ETH0DEV.macaddr=$NEW_MACADDR
|
2017-11-23 21:26:32 +01:00
|
|
|
uci commit network
|
2021-06-08 21:58:03 +02:00
|
|
|
ifconfig $ETH0DEV down
|
|
|
|
ifconfig $ETH0DEV hw ether $NEW_MACADDR
|
|
|
|
ifconfig $ETH0DEV 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
|