You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
2.9 KiB
Bash
83 lines
2.9 KiB
Bash
#!/bin/sh
|
|
# Copyright (C) 2016 PIVA Software <www.pivasoftware.com>
|
|
# Author: MOHAMED Kallel <mohamed.kallel@pivasoftware.com>
|
|
|
|
[ "$1" != "run" -a "$1" != "stop" ] && return
|
|
|
|
UCI_GET_VARSTATE="/sbin/uci -q ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -P /var/state get"
|
|
UCI_SET_VARSTATE="/sbin/uci -q ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -P /var/state set"
|
|
UCI_ADD_VARSTATE="/sbin/uci -q ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -P /var/state add"
|
|
UCI_DELETE_VARSTATE="/sbin/uci -q ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -P /var/state delete"
|
|
UCI_SHOW_VARSTATE="/sbin/uci -q ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -P /var/state show"
|
|
|
|
traceroute_get() {
|
|
local val=`$UCI_GET_VARSTATE $1`
|
|
echo ${val:-$2}
|
|
}
|
|
|
|
traceroute_launch() {
|
|
local i res host ip time=0
|
|
[ "`$UCI_GET_VARSTATE easycwmp.@local[0].TraceDiagnosticsState`" != "Requested" ] && return
|
|
local host=`traceroute_get easycwmp.@local[0].TraceHost`
|
|
local cnt=`traceroute_get easycwmp.@local[0].TraceNumberOfTries 3`
|
|
local dsize=`traceroute_get easycwmp.@local[0].TraceDataBlockSize 64`
|
|
local timeout=`traceroute_get easycwmp.@local[0].TraceTimeout 3000`
|
|
local maxhop=`traceroute_get easycwmp.@local[0].TraceMaxHops 30`
|
|
[ "$host" = "" ] && return
|
|
timeout=$((timeout/1000))
|
|
[ "$timeout" = "0" ] && timeout = "1"
|
|
i=-2
|
|
delete_all_route_hops
|
|
rm -f /tmp/traceres
|
|
traceroute -m $maxhop -w $timeout -q $cnt $host $dsize 2>&1 >/tmp/traceres
|
|
while read _ host ip time _; do
|
|
[ "$host" = "*" -a "$ip" = "*" ] && continue
|
|
let i++
|
|
[ "$i" = "-1" ] && continue;
|
|
ip=${ip#(}; ip=${ip%)}
|
|
time=${time%.*}
|
|
$UCI_ADD_VARSTATE easycwmp RouteHops
|
|
$UCI_SET_VARSTATE easycwmp.@RouteHops[$i].host=$host
|
|
$UCI_SET_VARSTATE easycwmp.@RouteHops[$i].ip=$ip
|
|
$UCI_SET_VARSTATE easycwmp.@RouteHops[$i].time=$time
|
|
done < /tmp/traceres
|
|
rm -f /tmp/traceres
|
|
let i++
|
|
|
|
$UCI_SET_VARSTATE easycwmp.@local[0].TraceDiagnosticsState=Complete
|
|
$UCI_SET_VARSTATE easycwmp.@local[0].TraceNumberOfHops=$i
|
|
$UCI_SET_VARSTATE easycwmp.@local[0].TraceResponseTime=$($UCI_GET_VARSTATE easycwmp.@RouteHops[-1].time)
|
|
event_diagnostic
|
|
}
|
|
|
|
delete_all_route_hops() {
|
|
local j
|
|
for j in $($UCI_SHOW_VARSTATE easycwmp | grep "easycwmp.@RouteHops.*=RouteHops"); do
|
|
$UCI_DELETE_VARSTATE easycwmp.@RouteHops[-1]
|
|
done
|
|
}
|
|
|
|
event_diagnostic() {
|
|
local e=1
|
|
local i=0
|
|
while [ "$e" != 0 -a $i -lt 200 ]; do
|
|
ubus -t 1 call tr069 inform '{"event":"8 DIAGNOSTICS COMPLETE"}'
|
|
e=$?
|
|
[ "$e" != "0" ] && sleep 1;
|
|
let i++
|
|
done
|
|
}
|
|
|
|
traceroute_stop() {
|
|
delete_all_route_hops
|
|
local pids=`ps aux | grep traceroute_launch | grep -v grep | grep -v stop | awk '{print $2}'`
|
|
[ -z "$pids" ] && pids=`ps | grep traceroute_launch | grep -v grep | grep -v stop | awk '{print $2}'`
|
|
if [ -n "$pids" ]; then
|
|
kill -9 $pids 2>/dev/null
|
|
$UCI_SET_VARSTATE easycwmp.@local[0].TraceDiagnosticsState=None
|
|
fi
|
|
}
|
|
|
|
[ "$1" == "run" ] && { traceroute_launch 2>/dev/null; exit 0; }
|
|
[ "$1" == "stop" ] && traceroute_stop 2>/dev/null
|