Revert "Revert "and added files""
[bcm963xx.git] / userapps / opensource / ipsec-tools / src / racoon / samples / roadwarrior / client / phase1-up.sh
1 #!/bin/sh
2
3 #
4 # sa-up.sh local configuration for a new SA
5 #
6 PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
7
8 case `uname -s` in
9 NetBSD)
10         DEFAULT_GW=`netstat -rn | awk '($1 == "default"){print $2}'`
11         ;;
12 Linux)
13         DEFAULT_GW=`netstat -rn | awk '($1 == "0.0.0.0"){print $2}'`
14         ;;
15 esac
16
17 echo $@
18 echo "LOCAL_ADDR = ${LOCAL_ADDR}"
19 echo "REMOTE_ADDR = ${REMOTE_ADDR}"
20 echo "DEFAULT_GW = ${DEFAULT_GW}"
21 echo "INTERNAL_ADDR4 = ${INTERNAL_ADDR4}"
22 echo "INTERNAL_DNS4 = ${INTERNAL_DNS4}"
23
24 echo ${INTERNAL_ADDR4} | grep '[0-9]' > /dev/null || exit 0
25 echo ${DEFAULT_GW} | grep '[0-9]' > /dev/null || exit 0
26
27 test -f /etc/resolv.conf.bak || cp /etc/resolv.conf /etc/resolv.conf.bak
28 echo "# Generated by racoon on `date`" > /etc/resolv.conf
29 echo "nameserver ${INTERNAL_DNS4}" >> /etc/resolv.conf
30
31 case `uname -s` in
32 NetBSD)
33         if=`netstat -rn|awk '($1 == "default"){print $7}'`
34         ifconfig ${if} alias ${INTERNAL_ADDR4}
35         route delete default
36         route add default ${DEFAULT_GW} -ifa ${INTERNAL_ADDR4}
37         ;;
38 Linux)
39         if=`netstat -rn|awk '($1 == "0.0.0.0"){print $8}'`
40         ifconfig ${if}:1 ${INTERNAL_ADDR4}      
41         route delete default
42         route add ${REMOTE_ADDR} gw ${DEFAULT_GW} dev ${if}
43         route add default gw ${DEFAULT_GW} dev ${if}:1
44         ;;
45 esac
46
47 echo "
48 spdadd ${INTERNAL_ADDR4}/32[any] 0.0.0.0/0[any] any
49        -P out ipsec esp/tunnel/${LOCAL_ADDR}-${REMOTE_ADDR}/require;
50 spdadd 0.0.0.0/0[any] ${INTERNAL_ADDR4}[any] any
51        -P in ipsec esp/tunnel/${REMOTE_ADDR}-${LOCAL_ADDR}/require;
52 " | setkey -c
53
54 #
55 # XXX This is a workaround for Linux forward policies problem. 
56 # Someone familiar with forward policies please fix this properly.
57 #
58 case `uname -s` in
59 Linux)
60         echo "
61         spddelete 0.0.0.0/0[any] ${INTERNAL_ADDR4}[any] any
62                 -P fwd ipsec esp/tunnel/${REMOTE_ADDR}-${LOCAL_ADDR}/require;
63         " | setkey -c
64         ;;
65 esac