dd63cacd19377ccdd7cf660eb12f3aa182e1ed92
[packages.git] / net / wing / files / usr / bin / wing_status
1 #!/bin/sh
2
3 # Copyright (c) 2006, 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
41 show_status() {
42
43         [ $ROUTES = 1 ] && {
44                 printf "Routes:\n"
45                 write_handler lt.dijkstra true
46                 read_handler lt.routes
47         }
48
49         [ $STATIC = 1 ] && {
50                 printf "\nStatic Routes:\n"
51                 read_handler wr/querier.static_routes
52         }
53
54         [ $HOSTS = 1 ] && {
55                 printf "\nIP:\n"
56                 read_handler lt.ip
57                 printf "\nHosts:\n"
58                 read_handler lt.hosts
59         }
60
61         [ $LINKS = 1 ] && {
62                 printf "\nLinks:\n"
63                 read_handler lt.links
64         }
65
66         [ $ARP = 1 ] && {
67                 printf "\nARP Table:\n"
68                 read_handler arp.table
69         }
70
71         [ $GATEWAY = 1 ] && {
72                 printf "\nBest gateway:\n"
73                 read_handler wr/set_gateway.gateway
74                 printf "\nGateways:\n"
75                 read_handler wr/gw.gateway_stats
76                 printf "\nHNAs:\n"
77                 read_handler wr/gw.hnas
78         }
79
80         [ $PROBES = 1 ] && {
81                 interfaces=$(read_handler lt.interfaces)
82                 for interface in $interfaces; do
83                         printf "\nBroadcast statistics ($interface):\n"
84                         read_handler wr/es/es_$interface.bcast_stats
85                 done
86         }
87
88         exit 0
89
90 }
91
92 if [ $# -eq 0 ]; then
93         ROUTES=1
94         STATIC=1
95         HOSTS=1
96         LINKS=1
97         ARP=1
98         GATEWAY=1
99         PROBES=1
100 fi
101
102 while getopts "rshlagp" OPTVAL
103 do
104         case $OPTVAL in
105         r) ROUTES=1
106           ;;
107         r) STATIC=1
108           ;;
109         h) HOSTS=1
110           ;;
111         l) LINKS=1
112           ;;
113         a) ARP=1
114           ;;
115         g) GATEWAY=1
116           ;;
117         p) PROBES=1
118           ;;
119         *) ROUTES=1; STATIC=1; HOSTS=1; LINKS=1; ARP=1; GATEWAY=1; PROBES=1
120           ;;
121         esac
122 done
123
124 show_status