Branch oldpackages for 14.07
[14.07/packages.git] / net / wing / files / usr / bin / wing_status
1 #!/bin/sh
2
3 # Copyright (c) 2012, Roberto Riggio
4 #
5 # All rights reserved.
6 #
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
9 # are met:
10 #
11 #   - Redistributions of source code must retain the above copyright
12 #     notice, this list of conditions and the following disclaimer.
13 #   - Redistributions in binary form must reproduce the above copyright
14 #     notice, this list of conditions and the following disclaimer in
15 #     the documentation and/or other materials provided with the
16 #     distribution.
17 #   - Neither the name of the CREATE-NET nor the names of its
18 #     contributors may be used to endorse or promote products derived
19 #     from this software without specific prior written permission.
20 #
21 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28 # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29 # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
33 ROUTES=0
34 STATIC=0
35 HOSTS=0
36 LINKS=0
37 ARP=0
38 GATEWAY=0
39 PROBES=0
40 INTERFACES=0
41
42 show_status() {
43
44         [ $ROUTES = 1 ] && {
45                 printf "Routes:\n"
46                 write_handler lt.dijkstra true
47                 read_handler lt.routes
48         }
49
50         [ $STATIC = 1 ] && {
51                 printf "\nStatic Routes:\n"
52                 read_handler wr/querier.static_routes
53         }
54
55         [ $HOSTS = 1 ] && {
56                 printf "\nIP:\n"
57                 read_handler lt.ip
58                 printf "\nHosts:\n"
59                 read_handler lt.hosts
60         }
61
62         [ $INTERFACES = 1 ] && {
63                 printf "\nInterfaces:\n"
64                 read_handler lt.interfaces
65         }
66
67         [ $LINKS = 1 ] && {
68                 printf "\nLinks:\n"
69                 read_handler lt.links
70         }
71
72         [ $ARP = 1 ] && {
73                 printf "\nARP Table:\n"
74                 read_handler arp.table
75         }
76
77         [ $GATEWAY = 1 ] && {
78                 printf "\nBest gateway:\n"
79                 read_handler wr/set_gateway.gateway
80                 printf "\nGateways:\n"
81                 read_handler wr/gw.gateway_stats
82                 printf "\nHNAs:\n"
83                 read_handler wr/gw.hnas
84         }
85
86         [ $PROBES = 1 ] && {
87                 interfaces=$(read_handler lt.interfaces)
88                 for interface in $interfaces; do
89                         printf "\nBroadcast statistics ($interface):\n"
90                         read_handler wr/es/es_$interface.bcast_stats
91                         printf "\nBroadcast statistics HT ($interface):\n"
92                         read_handler wr/es/es_$interface.bcast_stats_ht
93                 done
94         }
95
96         exit 0
97
98 }
99
100 if [ $# -eq 0 ]; then
101         ROUTES=1
102         STATIC=1
103         HOSTS=1
104         LINKS=1
105         ARP=1
106         GATEWAY=1
107         PROBES=1
108         INTERFACES=1
109 fi
110
111 while getopts "rshlagpi" OPTVAL
112 do
113         case $OPTVAL in
114         r) ROUTES=1
115           ;;
116         r) STATIC=1
117           ;;
118         h) HOSTS=1
119           ;;
120         l) LINKS=1
121           ;;
122         i) INTERFACES=1
123           ;;
124         a) ARP=1
125           ;;
126         g) GATEWAY=1
127           ;;
128         p) PROBES=1
129           ;;
130         *) ROUTES=1; STATIC=1; HOSTS=1; LINKS=1; ARP=1; GATEWAY=1; PROBES=1
131           ;;
132         esac
133 done
134
135 show_status