From: Dharmik Parmar Date: Thu, 2 Jul 2026 03:31:19 +0000 (+0530) Subject: watchcat: resolve logical interface names X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=dd826b7de646897b2534b19c45966fc95d536a65;p=openwrt-packages.git watchcat: resolve logical interface names Allow logical interface references in watchcat interface options. Resolve those names to real netifd devices for ping -I. Keep logical names for ifup and real-device find_config behavior. Use separate helpers for ping and restart values to avoid eval. Treat ModemManager mm_iface_name=null as empty, not a modem name. Signed-off-by: Dharmik Parmar --- diff --git a/utils/watchcat/Makefile b/utils/watchcat/Makefile index d43f1d21e..ee03a5a37 100644 --- a/utils/watchcat/Makefile +++ b/utils/watchcat/Makefile @@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=watchcat PKG_VERSION:=1 -PKG_RELEASE:=24 +PKG_RELEASE:=25 PKG_MAINTAINER:=Roger D PKG_LICENSE:=GPL-2.0 diff --git a/utils/watchcat/files/watchcat.sh b/utils/watchcat/files/watchcat.sh index e0ecb5cf8..87c9678ca 100644 --- a/utils/watchcat/files/watchcat.sh +++ b/utils/watchcat/files/watchcat.sh @@ -7,6 +7,77 @@ # . /lib/network/config.sh +. /lib/functions/network.sh + +# Accept the historical real-device input while also handling @logical +# interface references used by other OpenWrt configs. +watchcat_resolve_ping_iface() { + local iface="$1" + local logical device network + + [ -n "$iface" ] || return 1 + + case "$iface" in + @*) + logical="${iface#@}" + [ -n "$logical" ] || return 1 + if network_get_device device "$logical"; then + printf '%s\n' "$device" + return 0 + fi + printf '%s\n' "$iface" + return 1 + ;; + esac + + network="$(find_config "$iface")" + if [ -n "$network" ]; then + printf '%s\n' "$iface" + return 0 + fi + + if network_get_device device "$iface"; then + printf '%s\n' "$device" + return 0 + fi + + printf '%s\n' "$iface" + return 1 +} + +watchcat_resolve_restart_iface() { + local iface="$1" + local network device + + [ -n "$iface" ] || return 1 + + case "$iface" in + @*) + network="${iface#@}" + [ -n "$network" ] || return 1 + if ! network_get_device device "$network"; then + printf '%s\n' "$network" + return 1 + fi + printf '%s\n' "$network" + return 0 + ;; + esac + + network="$(find_config "$iface")" + if [ -n "$network" ]; then + printf '%s\n' "$network" + return 0 + fi + + if network_get_device device "$iface"; then + printf '%s\n' "$iface" + return 0 + fi + + printf '%s\n' "$iface" + return 1 +} get_ping_size() { ps=$1 @@ -84,8 +155,11 @@ watchcat_restart_modemmanager_iface() { } watchcat_restart_network_iface() { - local network - network="$(find_config "$1")" + local iface="$1" + local network="$2" + + [ -z "$network" ] && network="$(watchcat_resolve_restart_iface "$iface")" + logger -p daemon.info -t "watchcat[$$]" "Restarting network interface: \"$1\" (network: \"$network\")." ifup "$network" } @@ -110,11 +184,26 @@ watchcat_monitor_network() { mm_iface_unlock_bands="$7" address_family="$8" script="$9" + ping_iface="" + restart_iface="" reset_failure_timer="" if [ "$#" -gt 9 ]; then shift 9 reset_failure_timer="$1" fi + [ "$mm_iface_name" = "null" ] && mm_iface_name="" + if [ "$iface" != "" ]; then + if ! ping_iface="$(watchcat_resolve_ping_iface "$iface")"; then + logger -p daemon.warn -t "watchcat[$$]" "Could not resolve interface \"$iface\" for pinging." + case "$iface" in + @*) ping_iface="" ;; + *) ping_iface="$iface" ;; + esac + fi + if ! restart_iface="$(watchcat_resolve_restart_iface "$iface")"; then + logger -p daemon.warn -t "watchcat[$$]" "Could not resolve interface \"$iface\" for restart." + fi + fi time_now="$(cat /proc/uptime)" time_now="${time_now%%.*}" @@ -143,9 +232,9 @@ watchcat_monitor_network() { time_lastcheck="$time_now" for host in $ping_hosts; do - if [ "$iface" != "" ]; then + if [ "$ping_iface" != "" ]; then ping_result="$( - ping $ping_family -I "$iface" -s "$ping_size" -c 1 "$host" &> /dev/null + ping $ping_family -I "$ping_iface" -s "$ping_size" -c 1 "$host" &> /dev/null echo $? )" else @@ -178,7 +267,7 @@ watchcat_monitor_network() { watchcat_restart_modemmanager_iface "$mm_iface_name" "$mm_iface_unlock_bands" fi if [ "$iface" != "" ]; then - watchcat_restart_network_iface "$iface" + watchcat_restart_network_iface "$iface" "$restart_iface" else watchcat_restart_all_network fi @@ -207,6 +296,16 @@ watchcat_ping() { ping_size="$5" address_family="$6" iface="$7" + ping_iface="" + if [ "$iface" != "" ]; then + if ! ping_iface="$(watchcat_resolve_ping_iface "$iface")"; then + logger -p daemon.warn -t "watchcat[$$]" "Could not resolve interface \"$iface\" for pinging." + case "$iface" in + @*) ping_iface="" ;; + *) ping_iface="$iface" ;; + esac + fi + fi time_now="$(cat /proc/uptime)" time_now="${time_now%%.*}" @@ -235,9 +334,9 @@ watchcat_ping() { time_lastcheck="$time_now" for host in $ping_hosts; do - if [ "$iface" != "" ]; then + if [ "$ping_iface" != "" ]; then ping_result="$( - ping $ping_family -I "$iface" -s "$ping_size" -c 1 "$host" &> /dev/null + ping $ping_family -I "$ping_iface" -s "$ping_size" -c 1 "$host" &> /dev/null echo $? )" else