#!/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 [ -n "$ROUTERMAC" ] || ROUTERMAC=$(get_mac_label) if [ -s /etc/network.config ] ; then . /etc/network.config else # Write network.config if [ "$ONE_PORT" = "YES" ] || [ -n "$ETHPORT" ] ; 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 else if ! uci -q get network.$SWITCHDEV > /dev/null ; then if [ "$DSA" = "1" ]; then uci set network.$SWITCHDEV=device uci set network.$SWITCHDEV.name=$SWITCHDEV uci set network.$SWITCHDEV.type=bridge # temporary workaround for netifd bug present in OpenWrt 21.02.0 (FS#4104) uci set network.$SWITCHDEV.bridge_empty='1' uci set network.${SWITCHDEV}_1=bridge-vlan uci set network.${SWITCHDEV}_1.device=$SWITCHDEV uci set network.${SWITCHDEV}_1.vlan=1 uci set network.${SWITCHDEV}_1.ports="$CLIENT_PORTS" if [ "$WANDEV" = "$SWITCHDEV" ] || ! [ -z "$WAN_PORTS" ]; then uci set network.${SWITCHDEV}_2=bridge-vlan uci set network.${SWITCHDEV}_2.device=$SWITCHDEV uci set network.${SWITCHDEV}_2.vlan=2 uci set network.${SWITCHDEV}_2.ports="$WAN_PORTS" fi uci set network.${SWITCHDEV}_3=bridge-vlan uci set network.${SWITCHDEV}_3.device=$SWITCHDEV uci set network.${SWITCHDEV}_3.vlan=3 uci set network.${SWITCHDEV}_3.ports="$BATMAN_PORTS" else SWITCHHW=$(swconfig list | awk '{ print $4 }') 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 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" if [ "$WANDEV" = "$SWITCHDEV" ] || [ -n "$WAN_PORTS" ]; then 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 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" fi uci set network.client.ifname="$SWITCHDEV.1 bat0" uci set network.ethmesh.ifname="$SWITCHDEV.3" if [ "$WANDEV" = "$SWITCHDEV" ]; then uci set network.wan.ifname=$WANDEV.2 else uci set network.wan.ifname=$WANDEV fi uci commit network fi fi if [ -n "$ETHMESHMAC" ]; then if uci get network.ethmesh.macaddr then echo "MAC for ethmesh is set already" else echo "Fixing MAC on $SWITCHDEV.3 (ethmesh)" sleep 10 uci set network.ethmesh.macaddr=$ETHMESHMAC uci commit network fi fi if [ -n "$ROUTERMAC" ]; then if uci get network.client.macaddr then echo "MAC for client is set already" else echo "Fixing MAC on br-client" sleep 10 uci set network.client.macaddr=$ROUTERMAC 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 if uci -q get "network.client.ip6addr" > /dev/null then echo "IPv6 for client is set already" else echo "Setting IPv6 addresses" # Some time needed :( sleep 5 prefix="fdff::/64" # Set $prefix::MAC as IP addr=$(owipcalc "$prefix" add "::$(ipMacSuffix "$ROUTERMAC")") uci -q set network.globals.ula_prefix=$prefix uci -q add_list network.client.ip6addr=$addr uci -q set network.client.proto=static # Set $prefix::1 as IP addr=$(owipcalc "$prefix" add ::1) uci -q add_list network.client.ip6addr=$addr # Set $prefix::link-local as IP addr=$(owipcalc "$prefix" add "::$(ipEUISuffix "$ROUTERMAC")") uci -q add_list network.client.ip6addr=$addr uci -q commit network [ -s /etc/init.d/fff-uradvd ] && /etc/init.d/fff-uradvd restart fi reload_config