/etc/functions.sh => /lib/functions.sh
[openwrt/openwrt.git] / package / qos-scripts / files / usr / bin / qos-stat
1 #!/bin/sh
2 # Copyright (C) 2011 OpenWrt.org
3
4 . /lib/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 get_device() {
37 ( config_load network; scan_interfaces; config_get "$1" ifname )
38 }
39
40 interface_stats() {
41 local interface="$1"
42 local device
43
44 device="$(get_device "$interface")"
45 [ -z "$device" ] && config_get device "$interface" device
46 config_get_bool enabled "$interface" enabled 1
47 [ -z "$device" -o 1 -ne "$enabled" ] && {
48 return 1
49 }
50 config_get_bool halfduplex "$interface" halfduplex 0
51
52 if [ 1 -ne "$halfduplex" ]; then
53 unset halfduplex
54 print_comments "$interface" "Egress" "Start"
55 tc -s class show dev "$device"
56 print_comments "$interface" "Egress" "End"
57 id="root"
58 else
59 id=""
60 fi
61
62 print_comments "$interface" "Ingress${halfduplex:+/Egress}" "Start"
63 tc -s class show dev "$(tc filter show dev $device $id | grep mirred | sed -e 's,.*\(ifb.*\)).*,\1,')"
64 print_comments "$interface" "Ingress${halfduplex:+/Egress}" "End"
65 }
66
67 [ -z "$1" ] && config_foreach interface_stats interface || interface_stats "$1"