OSDN Git Service

2013.10.24
[uclinux-h8/uClinux-dist.git] / freeswan / utils / look
1 #! /bin/sh
2 # quick look at current connections and related information
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: look,v 1.26 2001/06/01 16:44:11 henry Exp $
16
17 info=/var/run/ipsec.info
18 me="ipsec look"
19
20 case "$1" in
21 --help)         echo "Usage: ipsec look" ; exit 0       ;;
22 --version)      echo "$me $IPSEC_VERSION" ; exit 0      ;;
23 esac
24
25 # clear out variables that have strange effects on sort etc.
26 unset LANG LANGUAGE LC_ALL LC_MESSAGES
27
28 # Pick up IPsec configuration etc.
29 eval `ipsec _confread --varprefix IPSEC --type config setup`
30 if test " $IPSEC_confreadstatus" != " "
31 then
32         echo "$IPSEC_confreadstatus -- aborting" |
33                 logger -s -p daemon.error -t ipsec_look
34         exit 1
35 fi
36 if test -s $info
37 then
38         . $info
39 fi
40
41 # label it just to be sure
42 echo "`hostname` `date`"
43
44 # combine spigrp and eroute
45 cat /proc/net/ipsec_spigrp /proc/net/ipsec_eroute |
46         awk '
47                 function pad(subnet) {
48                         sub("/", ".", subnet)
49                         split(subnet, d, ".")
50                         return sprintf("%03s%03s%03s%03s%03s", d[1], d[2],
51                                                         d[3], d[4], d[5])
52                 }
53                 $2 == "->" {
54                         printf "%s:%-18s -> %-18s => %s\n",
55                                 (pad($1) pad($3)),
56                                 $1, $3, (($5 in tun) ? tun[$5] : $5)
57                         next
58                 }
59                 $3 == "->" {
60                         printf "%s:%-18s -> %-18s => %s (%s)\n",
61                                 (pad($2) pad($4)),
62                                 $2, $4, (($6 in tun) ? tun[$6] : $6), $1
63                         next
64                 }
65                 { tun[$1] = $0 }
66         ' | sort | sed 's/^[^:]*://'
67
68 # tncfg (mostly as a divider line)
69 egrep -v 'NULL[ \t]+mtu=0\(0\)[ \t]+->[ \t]+0' /proc/net/ipsec_tncfg |
70         paste -d % | sed 's/%/   /g' | sed 's/ -> /->/g'
71
72 # SAs
73 sort /proc/net/ipsec_spi
74
75 # relevant routing information, including header line (which is good
76 # enough as a separator, no need for another bar)
77 pat="^Dest"
78 if test " $defaultroutephys" != " "
79 then
80         pat="$pat|$defaultroutephys\$|$defaultroutevirt\$"
81 else
82         for i in `echo "$IPSECinterfaces" | tr '=' ' '`
83         do
84                 pat="$pat|$i\$"
85         done
86 fi
87 netstat -nr | egrep "$pat" | sed '/^Dest/s/^/ /' | sort | sed '/^ Dest/s/ //'