OSDN Git Service

2013.10.24
[uclinux-h8/uClinux-dist.git] / freeswan / utils / barf
1 #! /bin/sh
2 # dump assorted information of use in debugging
3 # Copyright (C) 1998, 1999  Henry Spencer.
4
5 # This program is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by the
7 # Free Software Foundation; either version 2 of the License, or (at your
8 # option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
9
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 # or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
13 # for more details.
14 #
15 # RCSID $Id: barf,v 1.65 2002/03/26 17:49:42 henry Exp $
16
17 KERNSRC=${KERNSRC-/usr/src/linux}
18 LOGS=${LOGS-/var/log}
19 CONFS=${IPSEC_CONFS-/etc}
20 me="ipsec barf"
21
22 # message patterns that start relevant parts of logs
23 fstart='Starting FreeS.WAN'
24 pstart='Starting Pluto subsystem'
25
26 case "$1" in
27 --help)         echo "Usage: ipsec barf" ; exit 0       ;;
28 --version)      echo "$me $IPSEC_VERSION" ; exit 0      ;;
29 esac
30
31 # make sure output is in English
32 unset LANG LANGUAGE LC_ALL LC_MESSAGES
33
34 # log-location guesser, results in $findlog_file and $findlog_startline
35 # Fine point:  startline is the *last* line containing "string", or
36 # failing that, the *first* line containing "fallbackstring".
37 findlog() {             # findlog string fallbackstring possiblefile ...
38         s="$1"
39         shift
40         t="$1"
41         shift
42         # try the suggested files first
43         for f in $*
44         do
45                 if test -r $LOGS/$f -a ! -d $LOGS/$f && egrep -q "$s" $LOGS/$f
46                 then
47                         # aha, this one has it
48                         findlog_file=$LOGS/$f
49                         findlog_startline=`egrep -n "$s" $LOGS/$f |
50                                 sed -n '$s/:.*//p'`
51                         return 0
52                 fi
53         done
54         for f in $*
55         do
56                 if test -r $LOGS/$f -a ! -d $LOGS/$f && egrep -q "$t" $LOGS/$f
57                 then
58                         # aha, this one has it
59                         findlog_file=$LOGS/$f
60                         findlog_startline=`egrep -n "$t" $LOGS/$f |
61                                 sed -n '1s/:.*//p'`
62                         return 0
63                 fi
64         done
65         # nope, resort to a search, newest first, of uncompressed logs
66         for f in `ls -t $LOGS | | egrep -v '^mail' | egrep -v '\.(gz|Z)$'`
67         do
68                 if test -r $LOGS/$f -a ! -d $LOGS/$f && egrep -q "$s" $LOGS/$f
69                 then
70                         # found it
71                         findlog_file=$LOGS/$f
72                         findlog_startline=`egrep -n "$s" $LOGS/$f |
73                                 sed -n '$s/:.*//p'`
74                         return 0
75                 fi
76         done
77         for f in `ls -t $LOGS | egrep -v '^mail' | egrep -v '\.(gz|Z)$'`
78         do
79                 if test -r $LOGS/$f -a ! -d $LOGS/$f && egrep -q "$t" $LOGS/$f
80                 then
81                         # found it
82                         findlog_file=$LOGS/$f
83                         findlog_startline=`egrep -n "$t" $LOGS/$f |
84                                 sed -n '1s/:.*//p'`
85                         return 0
86                 fi
87         done
88         echo "$0: unable to find $LOGS/$1 or local equivalent" >&2
89         findlog_file=/dev/null
90         findlog_startline=1             # arbitrary
91 }
92
93 # try to guess where logs are
94 findlog "$fstart" "klips" messages syslog
95 klog=$findlog_file
96 kline=$findlog_startline
97 findlog "$pstart" "Pluto" secure auth.log debug
98 plog=$findlog_file
99 pline=$findlog_startline
100
101 # /lib/modules examiner
102 modulegoo() {
103         set +x
104         for d in `ls /lib/modules`
105         do
106                 if test -d /lib/modules/$d
107                 then
108                         f=/lib/modules/$d/$1
109                         if test -f $f
110                         then
111                                 nm -g $f | egrep "$2"
112                         else
113                                 echo
114                         fi | sed "s;^;$d: ;"
115                 fi
116         done
117         set -x
118 }
119
120 # advanced shell deviousness to get dividers into output
121 _________________________() {
122         $2      # something to do nothing and not echo anything
123 }
124
125 exec 2>&1               # stderr on stdout, so errors go into main output
126
127 hostname ; date
128 set -x
129 _________________________ version
130 ipsec --version
131 _________________________ proc/version
132 cat /proc/version
133 _________________________ proc/net/ipsec_eroute
134 sort +3 /proc/net/ipsec_eroute || cat /proc/net/ipsec_eroute
135 _________________________ proc/net/ipsec_spi
136 cat /proc/net/ipsec_spi
137 _________________________ proc/net/ipsec_spigrp
138 cat /proc/net/ipsec_spigrp
139 _________________________ netstart-rn
140 netstat -nr
141 _________________________ proc/net/ipsec_tncfg
142 cat /proc/net/ipsec_tncfg
143 _________________________ proc/net/pf_key
144 cat /proc/net/pf_key
145 _________________________ proc/net/pf_key-star
146 ( cd /proc/net ; egrep '^' pf_key_* )
147 _________________________ proc/sys/net/ipsec-star
148 ( cd /proc/sys/net/ipsec ; egrep '^' * )
149 _________________________ ipsec/status
150 ipsec auto --status
151 _________________________ ifconfig-a
152 ifconfig -a
153 _________________________ ipsec/directory
154 ipsec --directory
155 _________________________ hostname/fqdn
156 hostname --fqdn
157 _________________________ hostname/ipaddress
158 hostname --ip-address
159 _________________________ uptime
160 uptime
161 _________________________ ps
162 # -i ppid picks up the header
163 ps alxwf | egrep -i 'ppid|pluto|ipsec|klips'
164 _________________________ ipsec/showdefaults
165 ipsec showdefaults
166 _________________________ ipsec/conf
167 ipsec _include $CONFS/ipsec.conf | ipsec _keycensor
168 _________________________ ipsec/secrets
169 ipsec _include $CONFS/ipsec.secrets | ipsec _secretcensor
170 _________________________ ipsec/ls-dir
171 ls -l ${IPSEC_DIR-/usr/local/lib/ipsec}
172 _________________________ ipsec/updowns
173 for f in `ls ${IPSEC_DIR-/usr/local/lib/ipsec} | egrep updown`
174 do
175         cat ${IPSEC_DIR-/usr/local/lib/ipsec}/$f
176 done
177 _________________________ proc/net/dev
178 cat /proc/net/dev
179 _________________________ proc/net/route
180 cat /proc/net/route
181 _________________________ proc/sys/net/ipv4/ip_forward
182 cat /proc/sys/net/ipv4/ip_forward
183 _________________________ proc/sys/net/ipv4/conf/star-rp_filter
184 ( cd /proc/sys/net/ipv4/conf ; egrep '^' */rp_filter )
185 _________________________ uname-a
186 uname -a
187 _________________________ redhat-release
188 if test -r /etc/redhat-release
189 then
190         cat /etc/redhat-release
191 fi
192 _________________________ proc/net/ipsec_version
193 cat /proc/net/ipsec_version
194 _________________________ iptables/list
195 iptables -L -v -n
196 _________________________ ipchains/list
197 ipchains -L -v -n
198 _________________________ ipfwadm/forward
199 ipfwadm -F -l -n -e
200 _________________________ ipfwadm/input
201 ipfwadm -I -l -n -e
202 _________________________ ipfwadm/output
203 ipfwadm -O -l -n -e
204 _________________________ iptables/nat
205 iptables -t nat -L -v -n
206 _________________________ ipchains/masq
207 ipchains -M -L -v -n
208 _________________________ ipfwadm/masq
209 ipfwadm -M -l -n -e
210 _________________________ iptables/mangle
211 iptables -t mangle -L -v -n
212 _________________________ proc/modules
213 cat /proc/modules
214 _________________________ proc/meminfo
215 cat /proc/meminfo
216 _________________________ dev/ipsec-ls
217 ls -l /dev/ipsec*
218 _________________________ proc/net/ipsec-ls
219 ls -l /proc/net/ipsec_*
220 _________________________ usr/src/linux/.config
221 if test -f $KERNSRC/.config
222 then
223         egrep 'IP|NETLINK' $KERNSRC/.config
224 fi
225 _________________________ etc/syslog.conf
226 cat /etc/syslog.conf
227 _________________________ lib/modules-ls
228 ls -ltr /lib/modules
229 _________________________ proc/ksyms-netif_rx
230 egrep netif_rx /proc/ksyms
231 _________________________ lib/modules-netif_rx
232 modulegoo kernel/net/ipv4/ipip.o netif_rx
233 _________________________ kern.debug
234 if test -f $LOGS/kern.debug
235 then
236         tail -100 $LOGS/kern.debug
237 fi
238 _________________________ klog
239 sed -n $kline,'$'p $klog |
240         egrep -i 'ipsec|klips|pluto' |
241         case "$1" in
242         --short)        tail -500       ;;
243         *)              cat             ;;
244         esac
245 _________________________ plog
246 sed -n $pline,'$'p $plog |
247         egrep -i 'pluto' |
248         case "$1" in
249         --short)        tail -500       ;;
250         *)              cat             ;;
251         esac
252 _________________________ date
253 date