From: Andreas Steffen Date: Fri, 9 Jul 2010 07:36:03 +0000 (+0200) Subject: added ikev2/nat-two-rw-mark-in-out scenario X-Git-Tag: 4.4.1~99 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9f949068156c16a3f2608b38a4f89d9c030ced08;p=thirdparty%2Fstrongswan.git added ikev2/nat-two-rw-mark-in-out scenario --- diff --git a/testing/tests/ikev2/nat-two-rw-mark-in-out/description.txt b/testing/tests/ikev2/nat-two-rw-mark-in-out/description.txt new file mode 100644 index 0000000000..5b5aa99f87 --- /dev/null +++ b/testing/tests/ikev2/nat-two-rw-mark-in-out/description.txt @@ -0,0 +1,15 @@ +The roadwarriors alice and venus sitting behind the NAT router moon set up +tunnels to gateway sun. UDP encapsulation is used to traverse the NAT router. +Since both roadwarriors possess the same 10.1.0.0/25 subnet, gateway sun uses Source NAT +after ESP decryption to map these subnets to 10.3.0.10 and 10.3.0.20, respectively. +

+In order to differentiate between the tunnels to alice and venus, respectively, +XFRM marks are defined for both the inbound and outbound IPsec SAs and policies using +the mark_in and mark_out/b> parameters in ipsec.conf. +

+iptables -t mangle rules are then used in the PREROUTING chain to mark the traffic to +and from alice and venus, respectively. +

+leftfirewall=yes automatically inserts iptables-based firewall rules that let pass +the tunneled traffic. In order to test the tunnel, the NAT-ed hosts alice and venus +ping the client bob behind the gateway sun. diff --git a/testing/tests/ikev2/nat-two-rw-mark-in-out/evaltest.dat b/testing/tests/ikev2/nat-two-rw-mark-in-out/evaltest.dat new file mode 100644 index 0000000000..74ba178d9e --- /dev/null +++ b/testing/tests/ikev2/nat-two-rw-mark-in-out/evaltest.dat @@ -0,0 +1,16 @@ +alice::ipsec statusall::nat-t.*INSTALLED::YES +venus::ipsec statusall::nat-t.*INSTALLED::YES +sun::ipsec statusall::alice.*ESTABLISHED.*alice@strongswan.org::YES +sun::ipsec statusall::venus.*ESTABLISHED.*venus.strongswan.org::YES +sun::ipsec statusall::alice.*10.2.0.0/16 === 10.1.0.0/25::YES +sun::ipsec statusall::venus.*10.2.0.0/16 === 10.1.0.0/25::YES +alice::ping -c 1 PH_IP_BOB::64 bytes from PH_IP_BOB: icmp_seq=1::YES +venus::ping -c 1 PH_IP_BOB::64 bytes from PH_IP_BOB: icmp_seq=1::YES +moon::tcpdump::IP moon.strongswan.org.4510.* > sun.strongswan.org.ipsec-nat-t: UDP::YES +moon::tcpdump::IP moon.strongswan.org.4520.* > sun.strongswan.org.ipsec-nat-t: UDP::YES +moon::tcpdump::IP sun.strongswan.org.ipsec-nat-t > moon.strongswan.org.4510.*: UDP::YES +moon::tcpdump::IP sun.strongswan.org.ipsec-nat-t > moon.strongswan.org.4520.*: UDP::YES +bob::tcpdump::10.3.0.10 > bob.strongswan.org: ICMP echo request::YES +bob::tcpdump::10.3.0.20 > bob.strongswan.org: ICMP echo request::YES +bob::tcpdump::bob.strongswan.org > 10.3.0.10: ICMP echo reply::YES +bob::tcpdump::bob.strongswan.org > 10.3.0.20: ICMP echo reply::YES diff --git a/testing/tests/ikev2/nat-two-rw-mark-in-out/hosts/alice/etc/ipsec.conf b/testing/tests/ikev2/nat-two-rw-mark-in-out/hosts/alice/etc/ipsec.conf new file mode 100755 index 0000000000..0f7c238453 --- /dev/null +++ b/testing/tests/ikev2/nat-two-rw-mark-in-out/hosts/alice/etc/ipsec.conf @@ -0,0 +1,25 @@ +# /etc/ipsec.conf - strongSwan IPsec configuration file + +config setup + crlcheckinterval=180 + strictcrlpolicy=no + plutostart=no + +conn %default + ikelifetime=60m + keylife=20m + rekeymargin=3m + keyingtries=1 + keyexchange=ikev2 + +conn nat-t + left=%defaultroute + leftsubnet=10.1.0.0/25 + leftcert=aliceCert.pem + leftid=alice@strongswan.org + leftfirewall=yes + lefthostaccess=yes + right=PH_IP_SUN + rightid=@sun.strongswan.org + rightsubnet=10.2.0.0/16 + auto=add diff --git a/testing/tests/ikev2/nat-two-rw-mark-in-out/hosts/alice/etc/strongswan.conf b/testing/tests/ikev2/nat-two-rw-mark-in-out/hosts/alice/etc/strongswan.conf new file mode 100644 index 0000000000..de9ae45cce --- /dev/null +++ b/testing/tests/ikev2/nat-two-rw-mark-in-out/hosts/alice/etc/strongswan.conf @@ -0,0 +1,5 @@ +# /etc/strongswan.conf - strongSwan configuration file + +charon { + load = curl aes des sha1 sha2 md5 pem pkcs1 gmp random x509 hmac xcbc stroke kernel-netlink socket-default updown +} diff --git a/testing/tests/ikev2/nat-two-rw-mark-in-out/hosts/sun/etc/ipsec.conf b/testing/tests/ikev2/nat-two-rw-mark-in-out/hosts/sun/etc/ipsec.conf new file mode 100755 index 0000000000..850c55f6d7 --- /dev/null +++ b/testing/tests/ikev2/nat-two-rw-mark-in-out/hosts/sun/etc/ipsec.conf @@ -0,0 +1,37 @@ +# /etc/ipsec.conf - strongSwan IPsec configuration file + +config setup + crlcheckinterval=180 + strictcrlpolicy=no + plutostart=no + charondebug="knl 2" + +conn %default + ikelifetime=60m + keylife=20m + rekeymargin=3m + keyingtries=1 + keyexchange=ikev2 + +conn alice + rightid=alice@strongswan.org + mark_in=10/0xffffffff + mark_out=11/0xffffffff + also=sun + auto=add + +conn venus + rightid=@venus.strongswan.org + mark_in=20 #0xffffffff is used by default + mark_out=21 #0xffffffff is used by default + also=sun + auto=add + +conn sun + left=PH_IP_SUN + leftcert=sunCert.pem + leftid=@sun.strongswan.org + leftsubnet=10.2.0.0/16 + leftfirewall=yes + right=%any + rightsubnet=0.0.0.0/0 diff --git a/testing/tests/ikev2/nat-two-rw-mark-in-out/hosts/sun/etc/strongswan.conf b/testing/tests/ikev2/nat-two-rw-mark-in-out/hosts/sun/etc/strongswan.conf new file mode 100644 index 0000000000..de9ae45cce --- /dev/null +++ b/testing/tests/ikev2/nat-two-rw-mark-in-out/hosts/sun/etc/strongswan.conf @@ -0,0 +1,5 @@ +# /etc/strongswan.conf - strongSwan configuration file + +charon { + load = curl aes des sha1 sha2 md5 pem pkcs1 gmp random x509 hmac xcbc stroke kernel-netlink socket-default updown +} diff --git a/testing/tests/ikev2/nat-two-rw-mark-in-out/hosts/venus/etc/ipsec.conf b/testing/tests/ikev2/nat-two-rw-mark-in-out/hosts/venus/etc/ipsec.conf new file mode 100755 index 0000000000..c82c3e9789 --- /dev/null +++ b/testing/tests/ikev2/nat-two-rw-mark-in-out/hosts/venus/etc/ipsec.conf @@ -0,0 +1,25 @@ +# /etc/ipsec.conf - strongSwan IPsec configuration file + +config setup + crlcheckinterval=180 + strictcrlpolicy=no + plutostart=no + +conn %default + ikelifetime=60m + keylife=20m + rekeymargin=3m + keyingtries=1 + keyexchange=ikev2 + +conn nat-t + left=%defaultroute + leftsubnet=10.1.0.0/25 + leftcert=venusCert.pem + leftid=@venus.strongswan.org + leftfirewall=yes + lefthostaccess=yes + right=PH_IP_SUN + rightid=@sun.strongswan.org + rightsubnet=10.2.0.0/16 + auto=add diff --git a/testing/tests/ikev2/nat-two-rw-mark-in-out/hosts/venus/etc/strongswan.conf b/testing/tests/ikev2/nat-two-rw-mark-in-out/hosts/venus/etc/strongswan.conf new file mode 100644 index 0000000000..de9ae45cce --- /dev/null +++ b/testing/tests/ikev2/nat-two-rw-mark-in-out/hosts/venus/etc/strongswan.conf @@ -0,0 +1,5 @@ +# /etc/strongswan.conf - strongSwan configuration file + +charon { + load = curl aes des sha1 sha2 md5 pem pkcs1 gmp random x509 hmac xcbc stroke kernel-netlink socket-default updown +} diff --git a/testing/tests/ikev2/nat-two-rw-mark-in-out/posttest.dat b/testing/tests/ikev2/nat-two-rw-mark-in-out/posttest.dat new file mode 100644 index 0000000000..df49eb777f --- /dev/null +++ b/testing/tests/ikev2/nat-two-rw-mark-in-out/posttest.dat @@ -0,0 +1,9 @@ +sun::ipsec stop +alice::ipsec stop +venus::ipsec stop +alice::/etc/init.d/iptables stop 2> /dev/null +venus::/etc/init.d/iptables stop 2> /dev/null +sun::/etc/init.d/iptables stop 2> /dev/null +moon::iptables -t nat -F +moon::conntrack -F +sun::conntrack -F diff --git a/testing/tests/ikev2/nat-two-rw-mark-in-out/pretest.dat b/testing/tests/ikev2/nat-two-rw-mark-in-out/pretest.dat new file mode 100644 index 0000000000..52b87fa4e5 --- /dev/null +++ b/testing/tests/ikev2/nat-two-rw-mark-in-out/pretest.dat @@ -0,0 +1,24 @@ +alice::/etc/init.d/iptables start 2> /dev/null +venus::/etc/init.d/iptables start 2> /dev/null +sun::/etc/init.d/iptables start 2> /dev/null +moon::echo 1 > /proc/sys/net/ipv4/ip_forward +moon::iptables -t nat -A POSTROUTING -o eth0 -s 10.1.0.0/16 -p tcp -j SNAT --to PH_IP_MOON +moon::iptables -t nat -A POSTROUTING -o eth0 -s PH_IP_ALICE -p udp --sport 500 -j SNAT --to PH_IP_MOON:510 +moon::iptables -t nat -A POSTROUTING -o eth0 -s PH_IP_VENUS -p udp --sport 500 -j SNAT --to PH_IP_MOON:520 +moon::iptables -t nat -A POSTROUTING -o eth0 -s PH_IP_ALICE -p udp --sport 4500 -j SNAT --to PH_IP_MOON:4510 +moon::iptables -t nat -A POSTROUTING -o eth0 -s PH_IP_VENUS -p udp --sport 4500 -j SNAT --to PH_IP_MOON:4520 +sun::echo 1 > /proc/sys/net/ipv4/ip_forward +sun::iptables -t mangle -A PREROUTING -s PH_IP_MOON -p udp --sport 4510 -j MARK --set-mark 10 +sun::iptables -t mangle -A PREROUTING -s PH_IP_MOON -p udp --sport 4520 -j MARK --set-mark 20 +sun::iptables -t nat -A POSTROUTING -o eth1 -m mark --mark 10 -j SNAT --to 10.3.0.10 +sun::iptables -t nat -A POSTROUTING -o eth1 -m mark --mark 20 -j SNAT --to 10.3.0.20 +sun::iptables -t mangle -A PREROUTING -d 10.3.0.10 -j MARK --set-mark 11 +sun::iptables -t mangle -A PREROUTING -d 10.3.0.20 -j MARK --set-mark 21 +alice::ipsec start +venus::ipsec start +sun::ipsec start +alice::sleep 2 +alice::ipsec up nat-t +venus::sleep 2 +venus::ipsec up nat-t +venus::sleep 2 diff --git a/testing/tests/ikev2/nat-two-rw-mark-in-out/test.conf b/testing/tests/ikev2/nat-two-rw-mark-in-out/test.conf new file mode 100644 index 0000000000..ae3c190b89 --- /dev/null +++ b/testing/tests/ikev2/nat-two-rw-mark-in-out/test.conf @@ -0,0 +1,21 @@ +#!/bin/bash +# +# This configuration file provides information on the +# UML instances used for this test + +# All UML instances that are required for this test +# +UMLHOSTS="alice venus moon winnetou sun bob" + +# Corresponding block diagram +# +DIAGRAM="a-v-m-w-s-b.png" + +# UML instances on which tcpdump is to be started +# +TCPDUMPHOSTS="moon bob" + +# UML instances on which IPsec is started +# Used for IPsec logging purposes +# +IPSECHOSTS="alice venus sun"