File: look.in

package info (click to toggle)
strongswan 2.8.0+dfsg-1+etch2
  • links: PTS
  • area: main
  • in suites: etch
  • size: 15,344 kB
  • ctags: 15,752
  • sloc: ansic: 104,081; sh: 6,913; asm: 4,026; perl: 3,711; makefile: 3,215; pascal: 250; yacc: 221; lex: 190; xml: 147; awk: 124; sed: 98; lisp: 3
file content (87 lines) | stat: -rwxr-xr-x 2,447 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#! /bin/sh
# quick look at current connections and related information
# Copyright (C) 1998, 1999  Henry Spencer.
# 
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
# 
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# for more details.
#
# RCSID $Id: look.in,v 1.1 2004/03/15 20:35:28 as Exp $

info=/var/run/ipsec.info
me="ipsec look"

case "$1" in
--help)		echo "Usage: ipsec look" ; exit 0	;;
--version)	echo "$me $IPSEC_VERSION" ; exit 0	;;
esac

# clear out variables that have strange effects on sort etc.
unset LANG LANGUAGE LC_ALL LC_MESSAGES

# Pick up IPsec configuration etc.
eval `ipsec _confread --varprefix IPSEC --optional --type config setup`
if test " $IPSEC_confreadstatus" != " "
then
	echo "$IPSEC_confreadstatus -- aborting" |
		logger -s -p daemon.error -t ipsec_look
	exit 1
fi
if test -s $info
then
	. $info
fi

# label it just to be sure
echo "`hostname` `date`"

# combine spigrp and eroute
cat /proc/net/ipsec_spigrp /proc/net/ipsec_eroute |
	awk '
		function pad(subnet) {
			sub("/", ".", subnet)
			split(subnet, d, ".")
			return sprintf("%03s%03s%03s%03s%03s", d[1], d[2],
							d[3], d[4], d[5])
		}
		$2 == "->" {
			printf "%s:%-18s -> %-18s => %s\n",
				(pad($1) pad($3)),
				$1, $3, (($5 in tun) ? tun[$5] : $5)
			next
		}
		$3 == "->" {
			printf "%s:%-18s -> %-18s => %s (%s)\n",
				(pad($2) pad($4)),
				$2, $4, (($6 in tun) ? tun[$6] : $6), $1
			next
		}
		{ tun[$1] = $0 }
	' | sort | sed 's/^[^:]*://'

# tncfg (mostly as a divider line)
egrep -v 'NULL[ \t]+mtu=0\(0\)[ \t]+->[ \t]+0' /proc/net/ipsec_tncfg |
	paste -d % | sed 's/%/   /g' | sed 's/ -> /->/g'

# SAs
sort /proc/net/ipsec_spi

# relevant routing information, including header line (which is good
# enough as a separator, no need for another bar)
pat="^Dest"
if test " $defaultroutephys" != " "
then
	pat="$pat|$defaultroutephys\$|$defaultroutevirt\$"
else
	for i in `echo "$IPSECinterfaces" | tr '=' ' '`
	do
		pat="$pat|$i\$"
	done
fi
netstat -nr | egrep "$pat" | sed '/^Dest/s/^/ /' | sort | sed '/^ Dest/s/ //'