Browse Source

watchcat: add IP version selection support; fix bug with unlockbands

Signed-off-by: John Kohl <jtk.git@bostonpog.org>
(cherry picked from commit baed5531ef)
lilik-openwrt-22.03
John Kohl 2 years ago
committed by Rosen Penev
parent
commit
afd77fd6c4
3 changed files with 48 additions and 19 deletions
  1. +1
    -1
      utils/watchcat/Makefile
  2. +7
    -6
      utils/watchcat/files/watchcat.init
  3. +40
    -12
      utils/watchcat/files/watchcat.sh

+ 1
- 1
utils/watchcat/Makefile View File

@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
PKG_NAME:=watchcat
PKG_VERSION:=1
PKG_RELEASE:=14
PKG_RELEASE:=15
PKG_MAINTAINER:=Roger D <rogerdammit@gmail.com>
PKG_LICENSE:=GPL-2.0


+ 7
- 6
utils/watchcat/files/watchcat.init View File

@ -9,7 +9,7 @@ append_string() {
varname="$1"
add="$2"
separator="${3:- }"
actual
local actual
eval "actual=\$$varname"
new="${actual:+$actual$separator}$add"
@ -41,6 +41,7 @@ config_watchcat() {
config_get interface "$1" interface
config_get mmifacename "$1" mmifacename
config_get_bool unlockbands "$1" unlockbands "0"
config_get addressfamily "$1" addressfamily "any"
# Fix potential typo in mode and provide backward compatibility.
[ "$mode" = "allways" ] && mode="periodic_reboot"
@ -93,19 +94,19 @@ config_watchcat() {
periodic_reboot)
procd_open_instance "watchcat_${1}"
procd_set_param command /usr/bin/watchcat.sh "periodic_reboot" "$period" "$forcedelay"
procd_set_param respawn ${respawn_threshold:-3600} ${respawn_timeout:-5} ${respawn_retry:-5}
procd_set_param respawn "${respawn_threshold:-3600}" "${respawn_timeout:-5}" "${respawn_retry:-5}"
procd_close_instance
;;
ping_reboot)
procd_open_instance "watchcat_${1}"
procd_set_param command /usr/bin/watchcat.sh "ping_reboot" "$period" "$forcedelay" "$pinghosts" "$pingperiod" "$pingsize"
procd_set_param respawn ${respawn_threshold:-3600} ${respawn_timeout:-5} ${respawn_retry:-5}
procd_set_param command /usr/bin/watchcat.sh "ping_reboot" "$period" "$forcedelay" "$pinghosts" "$pingperiod" "$pingsize" "$addressfamily"
procd_set_param respawn "${respawn_threshold:-3600}" "${respawn_timeout:-5}" "${respawn_retry:-5}"
procd_close_instance
;;
restart_iface)
procd_open_instance "watchcat_${1}"
procd_set_param command /usr/bin/watchcat.sh "restart_iface" "$period" "$pinghosts" "$pingperiod" "$pingsize" "$interface" "$mmifacename"
procd_set_param respawn ${respawn_threshold:-3600} ${respawn_timeout:-5} ${respawn_retry:-5}
procd_set_param command /usr/bin/watchcat.sh "restart_iface" "$period" "$pinghosts" "$pingperiod" "$pingsize" "$interface" "$mmifacename" "$unlockbands" "$addressfamily"
procd_set_param respawn "${respawn_threshold:-3600}" "${respawn_timeout:-5}" "${respawn_retry:-5}"
procd_close_instance
;;
*)


+ 40
- 12
utils/watchcat/files/watchcat.sh View File

@ -28,13 +28,32 @@ get_ping_size() {
ps="9000"
;;
*)
echo "Error: invalid ping_size. ping_size should be either: small, windows, standard, big, huge or jumbo"
echo "Cooresponding ping packet sizes (bytes): small=1, windows=32, standard=56, big=248, huge=1492, jumbo=9000"
echo "Error: invalid ping_size. ping_size should be either: small, windows, standard, big, huge or jumbo" 1>&2
echo "Corresponding ping packet sizes (bytes): small=1, windows=32, standard=56, big=248, huge=1492, jumbo=9000" 1>&2
;;
esac
echo $ps
}
get_ping_family_flag() {
family=$1
case "$family" in
any)
family=""
;;
ipv4)
family="-4"
;;
ipv6)
family="-6"
;;
*)
echo "Error: invalid address_family \"$family\". address_family should be one of: any, ipv4, ipv6" 1>&2
;;
esac
echo $family
}
reboot_now() {
reboot &
@ -54,22 +73,22 @@ watchcat_periodic() {
watchcat_restart_modemmanager_iface() {
[ "$2" -gt 0 ] && {
logger -t INFO "Resetting current-bands to 'any' on modem: \"$1\" now."
logger -p daemon.info -t "watchcat[$$]" "Resetting current-bands to 'any' on modem: \"$1\" now."
/usr/bin/mmcli -m any --set-current-bands=any
}
logger -t INFO "Reconnecting modem: \"$1\" now."
logger -p daemon.info -t "watchcat[$$]" "Reconnecting modem: \"$1\" now."
/etc/init.d/modemmanager restart
ifup "$1"
}
watchcat_restart_network_iface() {
logger -t INFO "Restarting network interface: \"$1\"."
logger -p daemon.info -t "watchcat[$$]" "Restarting network interface: \"$1\"."
ip link set "$1" down
ip link set "$1" up
}
watchcat_restart_all_network() {
logger -t INFO "Restarting networking now by running: /etc/init.d/network restart"
logger -p daemon.info -t "watchcat[$$]" "Restarting networking now by running: /etc/init.d/network restart"
/etc/init.d/network restart
}
@ -81,6 +100,7 @@ watchcat_monitor_network() {
iface="$5"
mm_iface_name="$6"
mm_iface_unlock_bands="$7"
address_family="$8"
time_now="$(cat /proc/uptime)"
time_now="${time_now%%.*}"
@ -94,6 +114,8 @@ watchcat_monitor_network() {
ping_size="$(get_ping_size "$ping_size")"
ping_family="$(get_ping_family_flag "$address_family")"
while true; do
# account for the time ping took to return. With a ping time of 5s, ping might take more than that, so it is important to avoid even more delay.
time_now="$(cat /proc/uptime)"
@ -109,12 +131,12 @@ watchcat_monitor_network() {
for host in $ping_hosts; do
if [ "$iface" != "" ]; then
ping_result="$(
ping -I "$iface" -s "$ping_size" -c 1 "$host" &> /dev/null
ping "$ping_family" -I "$iface" -s "$ping_size" -c 1 "$host" &> /dev/null
echo $?
)"
else
ping_result="$(
ping -s "$ping_size" -c 1 "$host" &> /dev/null
ping "$ping_family" -s "$ping_size" -c 1 "$host" &> /dev/null
echo $?
)"
fi
@ -153,6 +175,7 @@ watchcat_ping() {
ping_hosts="$3"
ping_frequency_interval="$4"
ping_size="$5"
address_family="$6"
time_now="$(cat /proc/uptime)"
time_now="${time_now%%.*}"
@ -166,6 +189,8 @@ watchcat_ping() {
ping_size="$(get_ping_size "$ping_size")"
ping_family="$(get_ping_family_flag "$address_family")"
while true; do
# account for the time ping took to return. With a ping time of 5s, ping might take more than that, so it is important to avoid even more delay.
time_now="$(cat /proc/uptime)"
@ -181,12 +206,12 @@ watchcat_ping() {
for host in $ping_hosts; do
if [ "$iface" != "" ]; then
ping_result="$(
ping -I "$iface" -s "$ping_size" -c 1 "$host" &> /dev/null
ping "$ping_family" -I "$iface" -s "$ping_size" -c 1 "$host" &> /dev/null
echo $?
)"
else
ping_result="$(
ping -s "$ping_size" -c 1 "$host" &> /dev/null
ping "$ping_family" -s "$ping_size" -c 1 "$host" &> /dev/null
echo $?
)"
fi
@ -211,13 +236,16 @@ mode="$1"
case "$mode" in
periodic_reboot)
# args from init script: period forcedelay
watchcat_periodic "$2" "$3"
;;
ping_reboot)
watchcat_ping "$2" "$3" "$4" "$5" "$6"
# args from init script: period forcedelay pinghosts pingperiod pingsize addressfamily
watchcat_ping "$2" "$3" "$4" "$5" "$6" "$7"
;;
restart_iface)
watchcat_monitor_network "$2" "$3" "$4" "$5" "$6" "$7"
# args from init script: period pinghosts pingperiod pingsize interface mmifacename unlockbands addressfamily
watchcat_monitor_network "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9"
;;
*)
echo "Error: invalid mode selected: $mode"


Loading…
Cancel
Save