#! /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,v 1.11 1999/04/10 22:51:28 henry Exp $

PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin
export PATH

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

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

# combine spigrp and eroute
cat /proc/net/ipsec_spigrp /proc/net/ipsec_eroute |
	awk '	$2 != "->" { tun[$1] = $0 }
		$2 == "->" { $5 = tun[$5] ; print }'
echo -------------------------

# SAs
cat /proc/net/ipsec_spi | egrep -v '^SPI|^$'

# relevant routing information, including header line (which is good
# enough as a separator, no need for another bar)
pat="^Dest"
for i in `echo "$IPSECinterfaces" | tr '=' ' '`
do
	pat="$pat|$i"
done
netstat -nr | egrep "$pat"
