Drop main() prototype. Syncs with NetBSD-8
[minix.git] / etc / rc.d / ipsec
blobd5fc0caf78929e33a013b1afd4dc4b6d8fdfc290
1 #!/bin/sh
3 # $NetBSD: ipsec,v 1.13 2013/09/12 19:52:50 christos Exp $
6 # PROVIDE: ipsec
7 # REQUIRE: root bootconf mountcritlocal tty
8 # BEFORE: DAEMON
10 $_rc_subr_loaded . /etc/rc.subr
12 name="ipsec"
13 rcvar=$name
14 start_precmd="ipsec_prestart"
15 start_cmd="ipsec_start"
16 stop_precmd="test -f /etc/ipsec.conf"
17 stop_cmd="ipsec_stop"
18 reload_cmd="ipsec_reload"
19 extra_commands="reload"
21 ipsec_prestart()
23 if [ ! -f /etc/ipsec.conf ]; then
24 warn "/etc/ipsec.conf not readable; ipsec start aborted."
26 stop_boot
27 return 1
29 return 0
32 ipsec_getip() {
33 ifconfig $1 | while read what address rest; do
34 case "$what" in
35 inet) echo "$address";;
36 esac
37 done
40 ipsec_load() {
41 if [ -z "$1" ]; then
42 /sbin/setkey -f /etc/ipsec.conf
43 else
44 sed -e "s/@LOCAL_ADDR@/$1/" < /etc/ipsec.conf | \
45 /sbin/setkey -f -
49 ipsec_configure() {
50 while true; do
51 local addr="$(ipsec_getip "$ipsec_flags")"
52 case "$addr" in
53 '') sleep 1;;
54 "0.0.0.0") sleep 1;;
55 *) ipsec_load "$addr"; return;;
56 esac
57 done &
60 ipsec_start()
62 echo "Installing ipsec manual keys/policies."
63 if [ -n "$ipsec_flags" ]; then
64 ipsec_configure
65 else
66 ipsec_load
70 ipsec_stop()
72 echo "Clearing ipsec manual keys/policies."
74 # still not 100% sure if we would like to do this.
75 # it is very questionable to do this during shutdown session, since
76 # it can hang any of remaining IPv4/v6 session.
78 /sbin/setkey -F
79 /sbin/setkey -FP
82 ipsec_reload()
84 echo "Reloading ipsec manual keys/policies."
85 ipsec_stop
86 ipsec_start
89 load_rc_config $name
90 run_rc_command "$1"