[package] qos-scripts: Rework qos-stat script
[openwrt.git] / package / qos-scripts / files / usr / bin / qos-stat
1 #!/bin/sh
2 # Copyright (C) 2011 OpenWrt.org
3
4 . /etc/functions.sh
5
6 include /lib/network
7
8 get_ifname() {
9 local interface="$1"
10 local cfgt
11
12 scan_interfaces
13 config_get cfgt "$interface" TYPE
14 [ "$cfgt" == "interface" ] && config_get "$interface" ifname
15 }
16
17 config_cb() {
18 config_get TYPE "$CONFIG_SECTION" TYPE
19 [ "interface" == "$TYPE" ] && {
20 config_get device "$CONFIG_SECTION" ifname
21 [ -z "$device" ] && device="$(get_ifname ${CONFIG_SECTION})"
22 config_set "$CONFIG_SECTION" device "$device"
23 }
24 }
25
26 config_load qos
27
28 print_comments() {
29 echo ''
30 echo '# Interface: '"$1"
31 echo '# Direction: '"$2"
32 echo '# Stats: '"$3"
33 echo ''
34 }
35
36 interface_stats() {
37 local interface="$1"
38 local device
39
40 config_get device "$interface" device
41 config_get_bool enabled "$interface" enabled 1
42 [ -z "$device" -o 1 -ne "$enabled" ] && {
43 return 1
44 }
45 config_get_bool halfduplex "$interface" halfduplex
46
47 [ 1 -ne "$halfduplex" ] && {
48 unset halfduplex
49 print_comments "$interface" "Egress" "Start"
50 tc -s class show dev "$device"
51 print_comments "$interface" "Egress" "End"
52 }
53
54 print_comments "$interface" "Ingress${halfduplex:+/Egress}" "Start"
55 tc -s class show dev "$(iptables -v -L PREROUTING -t mangle | awk '/IMQ: todev .*$/ && $6 ~ /'$device'/ {print "imq"$12}')"
56 print_comments "$interface" "Ingress${halfduplex:+/Egress}" "End"
57 }
58
59 [ -z "$1" ] && config_foreach interface_stats interface || interface_stats "$1"
This page took 0.042581 seconds and 5 git commands to generate.