# DO NOT EDIT BELOW #
#####################
+__is_num() {
+case "${1}" in
+ '')
+ return 1
+ ;;
+ *.*.*)
+ return 1
+ ;;
+ *[!0123456789.]*)
+ return 1
+ ;;
+ [0123456789]*)
+ return 0
+ ;;
+ *)
+ return 1
+ ;;
+esac
+}
+
+
+__is_int() {
+if __is_num "${1}"
+then
+ case "${1}" in
+ *.*)
+ return 1
+ ;;
+ *)
+ return 0
+ ;;
+ esac
+fi
+return 1
+}
+
+
for p in traceroute fping awk
do
type "${p}" >/dev/null || { printf 'FATAL: Required program "%s" not installed.\n' "${p}" >&2; exit 1; }
done
-if [ x"${PING_GW_IPV6}" = xyes ]
+
+if [ x"${PING_GW_IPV6:-no}" = xyes ]
then
PING_PEERS="$(traceroute -6 -n -m 2001:4860:4860::8888 | awk '{if("1" == $1){print $2}}') ${PING_PEERS}"
fi
-if [ x"${PING_GW_IPV4}" = xyes ]
+
+if [ x"${PING_GW_IPV4:-no}" = xyes ]
+then
+ PING_PEERS="$(traceroute -4 -n -m 1 8.8.8.8 | awk '{if("1" == $1){print $2}}') ${PING_PEERS}"
+fi
+
+if ! __is_num "${THRESHOLD}"
then
- PING_PEERS="$(traceroute -4 -n -m 1 1.1.1.1 | awk '{if("1" == $1){print $2}}') ${PING_PEERS}"
+ printf 'FATAL: Invalid value for THRESHOLD\n'
+ exit 1
fi
+if ! __is_num "${FUDGE_MS}"
+then
+ printf 'FATAL: Invalid value for FUDGE_MS\n'
+ exit 1
+fi
+
+if ! __is_int "${PING_SLOTS_PER_PEER}"
+then
+ printf 'FATAL: Invalid value for PING_SLOTS_PER_PEER\n'
+ exit 1
+fi
+
+if ! __is_int "${PING_INTERVAL}"
+then
+ printf 'FATAL: Invalid value for PING_INTERVAL\n'
+ exit 1
+fi
+
+
set -u
fping --loop --retry=1 --size=1280 --period="${PING_INTERVAL}" --random ${PING_PEERS} 2>/dev/null \