iopsys-feed/map-agent/files/etc/hotplug.d/ethernet/map-dynamic-backhaul
Jakob Olsson f8375dd9e0 map-agent: map-dynamic-backhaul: use brctl delif to remove bsta from bridge
Map-agent now uses libeasy rather than netifd
2024-02-27 17:59:40 +01:00

107 lines
3 KiB
Bash
Executable file

#!/bin/sh
. /lib/network/utils.sh
conn_ports_file="/var/run/multiap/map.connected.ports"
map_bh_file="/var/run/multiap/multiap.backhaul"
al_bridge="$(uci -q get mapagent.agent.al_bridge)"
[ "${al_bridge:0:3}" = "br-" ] || exit 0
al_brnet="${al_bridge:3}"
# Exit if the PORT is not member of the AL Bridge
[ "$(get_network_of $PORT)" = "$al_brnet" ] || exit 0
# Exit if the device is not operating in extender/repeater mode
[ "$(uci -q get network.${al_brnet}.proto)" == "dhcp" ] || exit 0
############## Dynamic Backhaul Daemon ##############
if [ -n "$(which dynbhd)" ]; then
pidof dynbhd >/dev/null && exit 0 # dynbhd is managing the links
if [ ! -f $conn_ports_file ]; then
mkdir -p /var/run/multiap
touch $conn_ports_file
if [ "$LINK" = "up" ]; then
touch $conn_ports_file
echo "$PORT" > $conn_ports_file
brctl delif $al_bridge $PORT
#ubus call network.interface.lan remove_device "{\"name\":\"$PORT\"}"
fi
else
if [ "$LINK" = "up" ]; then
brctl delif $al_bridge $PORT
echo "$PORT" >> $conn_ports_file
#ubus call network.interface.lan remove_device "{\"name\":\"$PORT\"}"
else
sed -i -E "/(^|:)${PORT}(:|$)/d" $conn_ports_file
#ubus call network.interface.lan add_device "{\"name\":\"$PORT\"}"
brctl addif $al_bridge $PORT
[ "$(cat $conn_ports_file | wc -c)" = "0" ] && rm -f $conn_ports_file
fi
fi
exit 0
fi
########################################################
################ Dedicated ETH WAN Port ################
wanport="$(db -q get hw.board.ethernetWanPort)"
if [ -n "$wanport" ]; then
[ "$wanport" = "$PORT" ] || exit 0
########################################################
else
#################### DHCP Discovery ####################
if [ "$LINK" = "up" ]; then
brctl delif $al_bridge $PORT
udhcpc -qnRoC -i $PORT >/dev/null 2>&1 && dhcp=1
brctl addif $al_bridge $PORT
[ $dhcp -eq 1 ] || exit 0
else
[ -f $map_bh_file ] || exit 0
cur_bh="$(cat $map_bh_file | jsonfilter -e @.ifname)"
[ "$cur_bh" = "$PORT" ] || exit 0
fi
########################################################
fi
remove_from_bridge() {
config_get ifname "$section" ifname
[ -n "$ifname" ] && brctl delif ${al_bridge} ${ifname}
}
update_bstas() {
section="$1"
action="$2"
config_get ifname "$section" ifname
config_get_bool enabled "$section" enabled 0
if [ "$action" = "down" ]; then
wpa_cli -i "$ifname" disconnect > /dev/null 2>&1
wpa_cli -i "$ifname" disable_network 0 > /dev/null 2>&1
# wpa_cli -i "$ifname" save_config > /dev/null 2>&1
elif [ "$action" = "up" ]; then
[ "$enabled" -eq 0 ] && return
wpa_cli -i "$ifname" reconnect > /dev/null 2>&1
wpa_cli -i "$ifname" enable_network 0 > /dev/null 2>&1
# wpa_cli -i "$ifname" save_config > /dev/null 2>&1
fi
}
if [ "$LINK" = "up" ]; then
#touch "$map_bh_file"
config_load "mapagent"
config_foreach remove_from_bridge bsta
config_foreach update_bstas bsta down
/lib/wifi/multiap set_uplink "eth" "$PORT"
else
/lib/wifi/multiap unset_uplink "eth"
#rm -f "$map_bh_file"
config_load "mapagent"
config_foreach update_bstas bsta up
fi