Move network.* files into common library functions

This commit is contained in:
Fabian Bläse 2021-08-08 23:46:43 +02:00
parent 4f3b35fbf9
commit 1fdba9da60
48 changed files with 226 additions and 289 deletions

View File

@ -2,8 +2,7 @@
. /lib/functions/fff/babel
#load board specific properties
BOARD="$(uci get board.model.name)"
. /etc/network.$BOARD
. /lib/functions/fff/interfaces
configure() {
## babelpeer

View File

@ -2,9 +2,8 @@
. /lib/functions.sh
# load board specific properties
BOARD="$(uci get board.model.name)"
. /etc/network.$BOARD
. /lib/functions/fff/cpuport
. /lib/functions/fff/interfaces
configure() {

View File

@ -1,7 +1,5 @@
# load board specific properties
BOARD="$(uci get board.model.name)"
. /etc/network.$BOARD
. /lib/functions/fff/interfaces
configure() {
# ipaddr

View File

@ -1,6 +1,5 @@
# load board specific properties
BOARD="$(uci get board.model.name)"
. /etc/network.$BOARD
. /lib/functions/fff/interfaces
configure() {
if vlan=$(uci -q get gateway.@wan[0].vlan); then

View File

@ -1,9 +1,7 @@
#!/bin/sh
. /lib/functions.sh
BOARD="$(uci get board.model.name)"
. /etc/network.$BOARD
. /lib/functions/fff/switchports
# skip if gateway configuration already exists
if [ -s /etc/config/gateway ]; then

View File

@ -25,7 +25,6 @@ endef
define Package/$(PKG_NAME)/install
$(CP) ./files/* $(1)/
test -d ./$(ARCH) && $(CP) ./$(ARCH)/* $(1)/etc/
endef
$(eval $(call BuildPackage,$(PKG_NAME)))

View File

@ -1,5 +0,0 @@
WANDEV=eth0
SWITCHDEV=eth0
CLIENT_PORTS="0t 3 4"
WAN_PORTS="0t 5"
BATMAN_PORTS="0t 1 2"

View File

@ -1,5 +0,0 @@
WANDEV=eth0
SWITCHDEV=eth0
CLIENT_PORTS="1 2"
WAN_PORTS="5"
BATMAN_PORTS="3 4"

View File

@ -2,10 +2,11 @@
# SPDX-License-Identifier: GPL-3.0-or-later
. /lib/functions/system.sh
. /lib/functions/fff/interfaces
. /lib/functions/fff/network
BOARD="$(uci get board.model.name)"
. /etc/network.$BOARD
. /lib/functions/fff/meshmac
. /lib/functions/fff/routermac
. /lib/functions/fff/switchports
[ -n "$ROUTERMAC" ] || ROUTERMAC=$(get_mac_label)
@ -76,4 +77,4 @@ __EOF__
uci commit network
[ -s /etc/init.d/fff-uradvd ] && /etc/init.d/fff-uradvd restart
exit 0
exit 0

View File

@ -0,0 +1,61 @@
# SPDX-License-Identifier: GPL-3.0-only
BOARD="$(uci get board.model.name)"
case "$BOARD" in
avm,fritzbox-4040|\
tplink,archer-c50-v3|\
tplink,archer-c50-v4|\
tplink,archer-c7-v5|\
tplink,c2600|\
tplink,tl-wdr3600-v1|\
tplink,tl-wdr4300-v1|\
tplink,tl-wdr4310-v1|\
tplink,tl-wdr4900-v1|\
tplink,tl-wr1043nd-v2|\
tplink,tl-wr1043nd-v3|\
tplink,tl-wr1043nd-v4|\
tplink,tl-wr1043n-v5|\
tplink,tl-wr841n-v13|\
xiaomi,mi-router-4a-100m)
WANDEV=eth0
SWITCHDEV=eth0
;;
glinet,gl-ar150|\
tplink,archer-c25-v1|\
tplink,archer-c60-v1|\
tplink,archer-c60-v2|\
tplink,cpe210-v1|\
tplink,tl-wdr3500-v1)
WANDEV=eth1
SWITCHDEV=eth0
;;
tplink,archer-c7-v2)
WANDEV=eth1
SWITCHDEV=eth1
;;
tplink,cpe210-v1|\
tplink,cpe510-v1)
WANDEV=eth1
SWITCHDEV=eth0
TWO_PORT=YES
;;
network.ubnt,unifi|\
network.ubnt,unifiac-mesh|\
tplink,cpe210-v2|\
tplink,cpe210-v3|\
ubnt,nanostation-loco-m-xw)
WANDEV=eth0
SWITCHDEV=eth0
ONE_PORT=YES
;;
netgear,r6220|\
ubnt,edgerouter-4|\
ubnt,edgerouter-x-sfp|\
ubnt,edgerouter-x|\
xiaomi,mi-router-4a-gigabit)
WANDEV=switch0
SWITCHDEV=switch0
DSA=1
;;
esac

View File

@ -0,0 +1,44 @@
# SPDX-License-Identifier: GPL-3.0-only
. /lib/functions.sh
. /lib/functions/system.sh
. /lib/functions/fff/network
BOARD="$(uci get board.model.name)"
case "$BOARD" in
tplink,archer-c7-v2|\
tplink,archer-c25-v1)
ETHMESHMAC=$(cat /sys/class/net/eth0/address)
;;
tplink,archer-c60-v1|\
tplink,archer-c60-v2)
ETHMESHMAC=$(cat /sys/class/net/eth1/address)
;;
glinet,gl-ar150|\
netgear,r6220|\
tplink,archer-c50-v3|\
tplink,archer-c50-v4)
ETHMESHMAC="$(macFlipLocalBit $(cat /sys/class/net/eth0/address))"
;;
tplink,archer-c7-v5|\
tplink,tl-wdr4900-v1)
# use mac address from phy1 with 'locally administered' bit set to '1'
# only possible, because wXmesh is created first and therefore gets the 'universally administered address'
ETHMESHMAC=$(macFlipLocalBit "$(cat /sys/class/ieee80211/phy1/macaddress)")
;;
tplink,tl-wdr3600-v1|\
tplink,tl-wdr4300-v1|\
tplink,tl-wdr4310-v1)
ETHMESHMAC=$(macaddr_add $(cat /sys/class/ieee80211/phy1/macaddress) 1)
;;
tplink,tl-wr1043nd-v4|\
tplink,tl-wr1043n-v5)
# Load second MAC address from flash because we haven't any interface with this
# address where we can copy it from
ETHMESHMAC=$(macaddr_add $(mtd_get_mac_binary info 8) 1)
;;
tplink,tl-wr841n-v13)
ETHMESHMAC=$(macaddr_setbit_la $(cat /sys/class/net/eth0/address))
;;
esac

View File

@ -0,0 +1,9 @@
# SPDX-License-Identifier: GPL-3.0-only
BOARD="$(uci get board.model.name)"
case "$BOARD" in
ubnt,edgerouter-4)
ROUTERMAC=$(cat /sys/class/net/lan3/address)
;;
esac

View File

@ -0,0 +1,88 @@
# SPDX-License-Identifier: GPL-3.0-only
BOARD="$(uci get board.model.name)"
case "$BOARD" in
tplink,c2600|\
tplink,tl-wr1043nd-v2|\
tplink,tl-wr1043nd-v3|\
tplink,tl-wr1043nd-v4|\
tplink,tl-wr1043n-v5)
CLIENT_PORTS="1 2"
BATMAN_PORTS="3 4"
WAN_PORTS="5"
;;
avm,fritzbox-4040)
CLIENT_PORTS="3 4"
BATMAN_PORTS="1 2"
WAN_PORTS="5"
;;
tplink,archer-c7-v2|\
tplink,archer-c7-v5|\
tplink,tl-wdr3600-v1|\
tplink,tl-wdr4300-v1|\
tplink,tl-wdr4310-v1|\
tplink,tl-wdr4900-v1)
CLIENT_PORTS="4 5"
BATMAN_PORTS="2 3"
WAN_PORTS="1"
;;
tplink,archer-c50-v3|\
tplink,archer-c50-v4|\
tplink,tl-wr1043nd-v1|\
tplink,tl-wr841n-v13)
CLIENT_PORTS="3 4"
BATMAN_PORTS="1 2"
WAN_PORTS="0"
;;
xiaomi,mi-router-4a-100m)
CLIENT_PORTS="4"
BATMAN_PORTS="2"
WAN_PORTS="0"
;;
ubnt,edgerouter-4)
CLIENT_PORTS="lan2"
BATMAN_PORTS="lan1"
WAN_PORTS="lan0"
;;
ubnt,edgerouter-x|\
ubnt,edgerouter-x-sfp)
CLIENT_PORTS="eth3 eth4"
BATMAN_PORTS="eth1 eth2"
WAN_PORTS="eth0"
;;
netgear,r6220)
CLIENT_PORTS="lan1 lan2"
BATMAN_PORTS="lan3 lan4"
WAN_PORTS="wan"
;;
xiaomi,mi-router-4a-gigabit)
CLIENT_PORTS="lan2"
BATMAN_PORTS="lan1"
WAN_PORTS="wan"
;;
tplink,archer-c25-v1|\
tplink,archer-c60-v1|\
tplink,archer-c60-v2|\
tplink,tl-wdr3500-v1|\
tplink,tl-wr740n-v4|\
tplink,tl-wr741-v1|\
tplink,tl-wr841-v10|\
tplink,tl-wr841-v11|\
tplink,tl-wr841-v12|\
tplink,tl-wr841-v7|\
tplink,tl-wr841-v9)
CLIENT_PORTS="1 2"
BATMAN_PORTS="3 4"
;;
tplink,tl-wr741nd-v4|\
tplink,tl-wr841-v8|\
tplink,tl-wr842n-v2)
CLIENT_PORTS="1 4"
BATMAN_PORTS="2 3"
;;
tplink,tl-wr710n-v1)
CLIENT_PORTS="3"
BATMAN_PORTS=""
;;
esac

View File

@ -1,13 +0,0 @@
. /lib/functions/fff/network
WANDEV=eth1
SWITCHDEV=eth0
WAN_PORTS=
BATMAN_PORTS=""
CLIENT_PORTS=""
ETHMESHMAC="$(macFlipLocalBit $(cat /sys/class/net/eth0/address))"
. /etc/network.mode
ETHPORT=1

View File

@ -1,7 +0,0 @@
WANDEV=eth1
SWITCHDEV=eth0
CLIENT_PORTS="1 2"
WAN_PORTS=""
BATMAN_PORTS="3 4"
ETHMESHMAC=$(cat /sys/class/net/eth0/address)

View File

@ -1,6 +0,0 @@
WANDEV=eth1
SWITCHDEV=eth0
CLIENT_PORTS="1 2"
BATMAN_PORTS="3 4"
ETHMESHMAC=$(cat /sys/class/net/eth1/address)

View File

@ -1,6 +0,0 @@
WANDEV=eth1
SWITCHDEV=eth0
CLIENT_PORTS="1 2"
BATMAN_PORTS="3 4"
ETHMESHMAC=$(cat /sys/class/net/eth1/address)

View File

@ -1,7 +0,0 @@
WANDEV=eth1
SWITCHDEV=eth1
CLIENT_PORTS="4 5"
WAN_PORTS="1"
BATMAN_PORTS="2 3"
ETHMESHMAC=$(cat /sys/class/net/eth0/address)

View File

@ -1,12 +0,0 @@
. /lib/functions/fff/network
WANDEV=eth0
SWITCHDEV=eth0
CLIENT_PORTS="4 5"
WAN_PORTS="1"
BATMAN_PORTS="2 3"
# use mac address from phy1 with 'locally administered' bit set to '1'
# only possible, because wXmesh is created first and therefore gets the 'universally administered address'
ETHMESHMAC=$(macFlipLocalBit "$(cat /sys/class/ieee80211/phy1/macaddress)")

View File

@ -1,5 +0,0 @@
WANDEV=eth1
SWITCHDEV=eth0
TWO_PORT=YES
. /etc/network.mode

View File

@ -1,5 +0,0 @@
WANDEV=eth0
SWITCHDEV=eth0
ONE_PORT="YES"
. /etc/network.mode

View File

@ -1,5 +0,0 @@
WANDEV=eth0
SWITCHDEV=eth0
ONE_PORT="YES"
. /etc/network.mode

View File

@ -1,5 +0,0 @@
WANDEV=eth1
SWITCHDEV=eth0
TWO_PORT=YES
. /etc/network.mode

View File

@ -1,5 +0,0 @@
WANDEV=eth1
SWITCHDEV=eth0
CLIENT_PORTS="1 2"
WAN_PORTS=
BATMAN_PORTS="3 4"

View File

@ -1,9 +0,0 @@
WANDEV=eth0
SWITCHDEV=eth0
CLIENT_PORTS="4 5"
WAN_PORTS="1"
BATMAN_PORTS="2 3"
. /lib/functions/system.sh
ETHMESHMAC=$(macaddr_add $(cat /sys/class/ieee80211/phy1/macaddress) 1)

View File

@ -1,9 +0,0 @@
WANDEV=eth0
SWITCHDEV=eth0
CLIENT_PORTS="4 5"
WAN_PORTS="1"
BATMAN_PORTS="2 3"
. /lib/functions/system.sh
ETHMESHMAC=$(macaddr_add $(cat /sys/class/ieee80211/phy1/macaddress) 1)

View File

@ -1,9 +0,0 @@
WANDEV=eth0
SWITCHDEV=eth0
CLIENT_PORTS="4 5"
WAN_PORTS="1"
BATMAN_PORTS="2 3"
. /lib/functions/system.sh
ETHMESHMAC=$(macaddr_add $(cat /sys/class/ieee80211/phy1/macaddress) 1)

View File

@ -1,13 +0,0 @@
WANDEV=eth0
SWITCHDEV=eth0
CLIENT_PORTS="1 2"
WAN_PORTS="5"
BATMAN_PORTS="3 4"
. /lib/functions/system.sh
. /lib/functions.sh
# Load second MAC address from flash because we haven't any interface with this
# address where we can copy it from
ETHMESHMAC=$(macaddr_add $(mtd_get_mac_binary info 8) 1)

View File

@ -1,5 +0,0 @@
WANDEV=eth0
SWITCHDEV=eth0
CLIENT_PORTS="1 2"
WAN_PORTS="5"
BATMAN_PORTS="3 4"

View File

@ -1,5 +0,0 @@
WANDEV=eth0
SWITCHDEV=eth0
CLIENT_PORTS="1 2"
WAN_PORTS="5"
BATMAN_PORTS="3 4"

View File

@ -1,13 +0,0 @@
WANDEV=eth0
SWITCHDEV=eth0
CLIENT_PORTS="1 2"
WAN_PORTS="5"
BATMAN_PORTS="3 4"
. /lib/functions/system.sh
. /lib/functions.sh
# Load second MAC address from flash because we haven't any interface with this
# address where we can copy it from
ETHMESHMAC=$(macaddr_add $(mtd_get_mac_binary info 8) 1)

View File

@ -1,8 +0,0 @@
WANDEV=eth0
SWITCHDEV=eth0
CLIENT_PORTS=""
WAN_PORTS=""
BATMAN_PORTS=""
ONE_PORT="YES"
. /etc/network.mode

View File

@ -1,8 +0,0 @@
WANDEV=eth0
SWITCHDEV=eth0
CLIENT_PORTS=""
WAN_PORTS=""
BATMAN_PORTS=""
ONE_PORT="YES"
. /etc/network.mode

View File

@ -1,8 +0,0 @@
WANDEV=eth0
SWITCHDEV=eth0
CLIENT_PORTS=""
WAN_PORTS=""
BATMAN_PORTS=""
ONE_PORT="YES"
. /etc/network.mode

View File

@ -1,10 +0,0 @@
. /lib/functions/fff/network
WANDEV=switch0
SWITCHDEV=switch0
CLIENT_PORTS="lan2"
WAN_PORTS="lan0"
BATMAN_PORTS="lan1"
DSA=1
ROUTERMAC=$(cat /sys/class/net/lan3/address)

View File

@ -1,10 +0,0 @@
. /lib/functions/fff/network
WANDEV=switch0
SWITCHDEV=switch0
CLIENT_PORTS="lan1 lan2"
WAN_PORTS="wan"
BATMAN_PORTS="lan3 lan4"
DSA=1
ETHMESHMAC=$(macFlipLocalBit "$(cat /sys/class/net/eth0/address)")

View File

@ -1,9 +0,0 @@
. /lib/functions/fff/network
WANDEV=eth0
SWITCHDEV=eth0
CLIENT_PORTS="3 4"
WAN_PORTS="0"
BATMAN_PORTS="1 2"
ETHMESHMAC=$(macFlipLocalBit "$(cat /sys/class/net/eth0/address)")

View File

@ -1,9 +0,0 @@
. /lib/functions/fff/network
WANDEV=eth0
SWITCHDEV=eth0
CLIENT_PORTS="3 4"
WAN_PORTS="0"
BATMAN_PORTS="1 2"
ETHMESHMAC=$(macFlipLocalBit "$(cat /sys/class/net/eth0/address)")

View File

@ -1,9 +0,0 @@
. /lib/functions/system.sh
WANDEV=eth0
SWITCHDEV=eth0
CLIENT_PORTS="3 4"
WAN_PORTS="0"
BATMAN_PORTS="1 2"
ETHMESHMAC=$(macaddr_setbit_la $(cat /sys/class/net/eth0/address))

View File

@ -1,6 +0,0 @@
WANDEV=switch0
SWITCHDEV=switch0
CLIENT_PORTS="eth3 eth4"
WAN_PORTS="eth0"
BATMAN_PORTS="eth1 eth2"
DSA=1

View File

@ -1,6 +0,0 @@
WANDEV=switch0
SWITCHDEV=switch0
CLIENT_PORTS="eth3 eth4 eth5"
WAN_PORTS="eth0"
BATMAN_PORTS="eth1 eth2"
DSA=1

View File

@ -1,7 +0,0 @@
. /lib/functions/fff/network
WANDEV=eth0
SWITCHDEV=eth0
CLIENT_PORTS="6t 4"
WAN_PORTS="6t 0"
BATMAN_PORTS="6t 2"

View File

@ -1,6 +0,0 @@
WANDEV=switch0
SWITCHDEV=switch0
CLIENT_PORTS="lan2"
WAN_PORTS="wan"
BATMAN_PORTS="lan1"
DSA=1

View File

@ -1,12 +0,0 @@
. /lib/functions/fff/network
WANDEV=eth0
SWITCHDEV=eth0
CLIENT_PORTS="4 5"
WAN_PORTS="1"
BATMAN_PORTS="2 3"
# use mac address from phy1 with 'locally administered' bit set to '1'
# only possible, because wXmesh is created first and therefore gets the 'universally administered address'
ETHMESHMAC=$(macFlipLocalBit "$(cat /sys/class/ieee80211/phy1/macaddress)")

View File

@ -4,9 +4,8 @@
. /lib/functions/system.sh
. /lib/functions/fff/network
. /lib/functions/fff/cpuport
BOARD="$(uci get board.model.name)"
. /etc/network.$BOARD
. /lib/functions/fff/interfaces
. /lib/functions/fff/switchports
# Add cpuport to switch configuration
CLIENT_PORTS="$(get_cpu_port) $CLIENT_PORTS"

View File

@ -4,10 +4,9 @@
. /lib/functions/fff/evalhoodinfo
. /lib/functions/fff/evalbytes
. /lib/functions/fff/portorder
. /lib/functions/fff/interfaces
. /lib/functions.sh # required for config_load and config_foreach
board_name=$(uci -q get board.model.name)
HOSTNAME=$(uci -q get 'fff.system.hostname')
hood="$(uci -q get "system.@system[0].hood")"
hoodid="$(uci -q get "system.@system[0].hoodid")"
@ -190,7 +189,7 @@ if swconfig list | grep -q switch0 ; then
echo ""
echo ""
if [ ! "$(awk -F= '/WANDEV=/ { print $2 }' /etc/network.$board_name)" = "$(awk -F= '/SWITCHDEV=/ { print $2 }' /etc/network.$board_name)" ] ; then
if [ ! "$WANDEV" = "$SWITCHDEV" ] ; then
wanif=$(uci -q get network.wan.ifname)
link=$(cat /sys/class/net/${wanif}/operstate)
if [ "$link" = "up" ] ; then
@ -221,7 +220,7 @@ if swconfig list | grep -q switch0 ; then
done
else
echo "-> PORT ASSIGNMENT"
if grep -q "ONE_PORT" "/etc/network.$board_name" || grep -q "ETHPORT" "/etc/network.$board_name" ; then
if [ -n "$ONE_PORT" ] || [ -n "$ETHPORT" ] ; then
# Device has a port set by $ETHMODE
. /etc/network.mode
. /etc/network.config

View File

@ -1,7 +1,9 @@
#!/usr/bin/haserl
<%
board_name=$(uci -q get board.model.name)
. /lib/functions/fff/interfaces
# write
if [ "$REQUEST_METHOD" = "POST" ] ; then
if [ "$POST_change_mode" != "" ] ; then
@ -88,7 +90,7 @@ format_port() {
echo "</td>"
echo "<td class=\"swport\" style=\"width:2em\"></td>"
if [ ! "$(awk -F= '/WANDEV=/ { print $2 }' /etc/network.$board_name)" = "$(awk -F= '/SWITCHDEV=/ { print $2 }' /etc/network.$board_name)" ] ; then
if [ ! "$WANDEV" = "$SWITCHDEV" ] ; then
wanif=$(uci -q get network.wan.ifname)
link=$(cat /sys/class/net/${wanif}/operstate)
if [ "$link" = "up" ] ; then
@ -147,7 +149,7 @@ format_port() {
</fieldset>
</td></tr>
<% fi %>
<% if grep -q "ONE_PORT" "/etc/network.$board_name" || grep -q "ETHPORT" "/etc/network.$board_name" ; then %>
<% if [ -n "$ONE_PORT" ] || [ -n "$ETHPORT" ] ; then %>
<%
# Device has a port set by $ETHMODE
. /etc/network.mode
@ -163,7 +165,7 @@ format_port() {
<select name="mode">
<option value="BATMAN" <% [ "$ETHMODE" = "BATMAN" ] && echo -n 'selected="selected" ' %>>BATMAN</option>
<option value="CLIENT" <% [ "$ETHMODE" = "CLIENT" ] && echo -n 'selected="selected" ' %>>CLIENT</option>
<% if grep -q "ONE_PORT" "/etc/network.$board_name" ; then %>
<% if [ -n "$ONE_PORT" ] ; then %>
<option value="WAN" <% [ "$ETHMODE" = "WAN" ] && echo -n 'selected="selected" ' %>>WAN</option>
<% fi %>
</select>
@ -184,7 +186,7 @@ format_port() {
</fieldset>
</td></tr>
<% fi %>
<% if grep -q "LAN0PORT" "/etc/network.$board_name" || grep -q "LAN1PORT" "/etc/network.$board_name" ; then %>
<% if [ -n "$TWO_PORT" ] ; then %>
<%
# Device has two ports
. /etc/network.mode

View File

@ -4,8 +4,7 @@
. /lib/functions/fff/babel
#load board specific properties
BOARD="$(uci get board.model.name)"
. /etc/network.$BOARD
. /lib/functions/fff/routermac
[ -n "$ROUTERMAC" ] || ROUTERMAC=$(get_mac_label)
configure() {