2000-06-13 20:29:53 +04:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
2016-10-20 00:27:10 +03:00
|
|
|
# $NetBSD: ipsec,v 1.14 2016/10/19 21:27:10 christos Exp $
|
2000-06-13 20:29:53 +04:00
|
|
|
#
|
|
|
|
|
|
|
|
# PROVIDE: ipsec
|
2008-11-22 23:23:33 +03:00
|
|
|
# REQUIRE: root bootconf mountcritlocal tty
|
2002-03-22 07:33:57 +03:00
|
|
|
# BEFORE: DAEMON
|
2000-06-13 20:29:53 +04:00
|
|
|
|
2004-08-13 22:08:03 +04:00
|
|
|
$_rc_subr_loaded . /etc/rc.subr
|
2000-06-13 20:29:53 +04:00
|
|
|
|
|
|
|
name="ipsec"
|
2000-09-19 17:04:38 +04:00
|
|
|
rcvar=$name
|
2000-07-17 17:10:54 +04:00
|
|
|
start_precmd="ipsec_prestart"
|
2000-06-13 20:29:53 +04:00
|
|
|
start_cmd="ipsec_start"
|
2000-09-19 17:04:38 +04:00
|
|
|
stop_precmd="test -f /etc/ipsec.conf"
|
2000-06-13 20:29:53 +04:00
|
|
|
stop_cmd="ipsec_stop"
|
|
|
|
reload_cmd="ipsec_reload"
|
|
|
|
extra_commands="reload"
|
|
|
|
|
2000-07-21 05:16:07 +04:00
|
|
|
ipsec_prestart()
|
2000-06-13 20:29:53 +04:00
|
|
|
{
|
|
|
|
if [ ! -f /etc/ipsec.conf ]; then
|
2000-07-17 17:10:54 +04:00
|
|
|
warn "/etc/ipsec.conf not readable; ipsec start aborted."
|
2007-04-06 18:20:08 +04:00
|
|
|
|
|
|
|
stop_boot
|
2000-07-17 17:10:54 +04:00
|
|
|
return 1
|
2000-06-13 20:29:53 +04:00
|
|
|
fi
|
2000-07-17 17:10:54 +04:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2013-06-14 20:37:55 +04:00
|
|
|
ipsec_getip() {
|
2016-10-20 00:27:10 +03:00
|
|
|
ifconfig $1 | while IFS="${IFS}/" read what address rest; do
|
2013-06-14 20:37:55 +04:00
|
|
|
case "$what" in
|
|
|
|
inet) echo "$address";;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2013-09-12 23:52:50 +04:00
|
|
|
ipsec_load() {
|
|
|
|
if [ -z "$1" ]; then
|
|
|
|
/sbin/setkey -f /etc/ipsec.conf
|
|
|
|
else
|
|
|
|
sed -e "s/@LOCAL_ADDR@/$1/" < /etc/ipsec.conf | \
|
|
|
|
/sbin/setkey -f -
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
ipsec_configure() {
|
|
|
|
while true; do
|
|
|
|
local addr="$(ipsec_getip "$ipsec_flags")"
|
|
|
|
case "$addr" in
|
|
|
|
'') sleep 1;;
|
|
|
|
"0.0.0.0") sleep 1;;
|
|
|
|
*) ipsec_load "$addr"; return;;
|
|
|
|
esac
|
|
|
|
done &
|
|
|
|
}
|
|
|
|
|
2000-07-17 17:10:54 +04:00
|
|
|
ipsec_start()
|
|
|
|
{
|
2000-06-13 20:29:53 +04:00
|
|
|
echo "Installing ipsec manual keys/policies."
|
2013-06-14 20:37:55 +04:00
|
|
|
if [ -n "$ipsec_flags" ]; then
|
2013-09-12 23:52:50 +04:00
|
|
|
ipsec_configure
|
2013-06-14 20:37:55 +04:00
|
|
|
else
|
2013-09-12 23:52:50 +04:00
|
|
|
ipsec_load
|
2013-06-14 20:37:55 +04:00
|
|
|
fi
|
2000-06-13 20:29:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
ipsec_stop()
|
|
|
|
{
|
2000-06-14 07:24:16 +04:00
|
|
|
echo "Clearing ipsec manual keys/policies."
|
2000-06-13 20:29:53 +04:00
|
|
|
|
|
|
|
# still not 100% sure if we would like to do this.
|
|
|
|
# it is very questionable to do this during shutdown session, since
|
|
|
|
# it can hang any of remaining IPv4/v6 session.
|
|
|
|
#
|
|
|
|
/sbin/setkey -F
|
|
|
|
/sbin/setkey -FP
|
|
|
|
}
|
|
|
|
|
|
|
|
ipsec_reload()
|
|
|
|
{
|
|
|
|
echo "Reloading ipsec manual keys/policies."
|
2013-06-14 20:37:55 +04:00
|
|
|
ipsec_stop
|
|
|
|
ipsec_start
|
2000-06-13 20:29:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
load_rc_config $name
|
|
|
|
run_rc_command "$1"
|