openwrtv3/package/network/config/qos-scripts/files/usr/bin/qos-stat
Tony Ambardar b701d78105 qos-scripts: fix uci callback handling
The previous callback code was fragile, dependent on some UCI callback
bugs and side-effects now fixed in master commit 73d8a6ab.

Update scripts to use callbacks where appropriate and necessary, while
using normal UCI config parsing for all else. This results in smaller,
simpler, more robust code. Use callbacks in generate.sh to only process
'interface' defaults and the varying entries for 'reclassify', 'default'
and 'classify' sections. Also switch qos-stat to use non-callback UCI
handling.

The current changes work independently of 73d8a6ab (i.e. both before and
after), and are consistent with UCI config parsing documentation.

Signed-off-by: Tony Ambardar <itugrok@yahoo.com>
2018-06-28 16:41:45 +02:00

68 lines
1.5 KiB
Bash
Executable file

#!/bin/sh
# Copyright (C) 2011 OpenWrt.org
. /lib/functions.sh
include /lib/network
get_ifname() {
local interface="$1"
local cfgt
scan_interfaces
config_get cfgt "$interface" TYPE
[ "$cfgt" = "interface" ] && config_get "$interface" ifname
}
qos_set_device() {
config_get TYPE "$1" TYPE
[ "interface" = "$TYPE" ] && {
config_get device "$1" ifname
[ -z "$device" ] && device="$(get_ifname $1)"
config_set "$1" device "$device"
}
}
config_load qos
config_foreach qos_set_device
print_comments() {
echo ''
echo '# Interface: '"$1"
echo '# Direction: '"$2"
echo '# Stats: '"$3"
echo ''
}
get_device() {
( config_load network; scan_interfaces; config_get "$1" ifname )
}
interface_stats() {
local interface="$1"
local device
device="$(get_device "$interface")"
[ -z "$device" ] && config_get device "$interface" device
config_get_bool enabled "$interface" enabled 1
[ -z "$device" -o 1 -ne "$enabled" ] && {
return 1
}
config_get_bool halfduplex "$interface" halfduplex 0
if [ 1 -ne "$halfduplex" ]; then
unset halfduplex
print_comments "$interface" "Egress" "Start"
tc -s class show dev "$device"
print_comments "$interface" "Egress" "End"
id="root"
else
id=""
fi
print_comments "$interface" "Ingress${halfduplex:+/Egress}" "Start"
tc -s class show dev "$(tc filter show dev $device $id | grep mirred | sed -e 's,.*\(ifb.*\)).*,\1,')"
print_comments "$interface" "Ingress${halfduplex:+/Egress}" "End"
}
[ -z "$1" ] && config_foreach interface_stats interface || interface_stats "$1"