varname="$1"
add="$2"
separator="${3:- }"
- actual
+ local actual
eval "actual=\$$varname"
new="${actual:+$actual$separator}$add"
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"
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
;;
*)
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 &
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
}
iface="$5"
mm_iface_name="$6"
mm_iface_unlock_bands="$7"
+ address_family="$8"
time_now="$(cat /proc/uptime)"
time_now="${time_now%%.*}"
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)"
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
ping_hosts="$3"
ping_frequency_interval="$4"
ping_size="$5"
+ address_family="$6"
time_now="$(cat /proc/uptime)"
time_now="${time_now%%.*}"
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)"
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
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"