added ikev2/nat-two-rw-mark scenario

This commit is contained in:
Andreas Steffen
2010-07-03 13:25:09 +02:00
parent ee26c537d7
commit 342fc85e9e
11 changed files with 185 additions and 0 deletions
@@ -0,0 +1,13 @@
The roadwarriors <b>alice</b> and <b>venus</b> sitting behind the NAT router <b>moon</b> set up
tunnels to gateway <b>sun</b>. UDP encapsulation is used to traverse the NAT router.
Since both roadwarriors possess the same 10.1.0.0/25 subnet, gateway <b>sun</b> uses Source NAT
after ESP decryption to map these subnets to 10.3.0.10 and 10.3.0.20, respectively.
<p/>
In order to differentiate between the tunnels to <b>alice</b> and <b>venus</b>, respectively,
<b>XFRM marks</b> are defined for both the inbound and outbound IPsec SAs and policies using
the <b>mark=</b> ipsec.conf parameter. <b>iptables -t mangle</b> rules are then used in the PREROUTING
chain to mark the traffic to and from <b>alice</b> and <b>venus</b>, respectively.
<p/>
<b>leftfirewall=yes</b> automatically inserts iptables-based firewall rules that let pass
the tunneled traffic. In order to test the tunnel, the NAT-ed hosts <b>alice</b> and <b>venus</b>
ping the client <b>bob</b> behind the gateway <b>sun</b>.
@@ -0,0 +1,16 @@
alice::ipsec statusall::nat-t.*INSTALLED::YES
venus::ipsec statusall::nat-t.*INSTALLED::YES
sun::ipsec statusall::alice.*ESTABLISHED.*[email protected]::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
@@ -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
[email protected]
leftfirewall=yes
lefthostaccess=yes
right=PH_IP_SUN
[email protected]
rightsubnet=10.2.0.0/16
auto=add
@@ -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
}
@@ -0,0 +1,35 @@
# /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
[email protected]
mark=10/0xffffffff
also=sun
auto=add
conn venus
[email protected]
mark=20 #0xffffffff is used by default
also=sun
auto=add
conn sun
left=PH_IP_SUN
leftcert=sunCert.pem
[email protected]
leftsubnet=10.2.0.0/16
leftfirewall=yes
right=%any
rightsubnet=0.0.0.0/0
@@ -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
}
@@ -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
[email protected]
leftfirewall=yes
lefthostaccess=yes
right=PH_IP_SUN
[email protected]
rightsubnet=10.2.0.0/16
auto=add
@@ -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
}
@@ -0,0 +1,11 @@
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::iptables -t mangle -F
sun::iptables -t nat -F
sun::conntrack -F
@@ -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 10
sun::iptables -t mangle -A PREROUTING -d 10.3.0.20 -j MARK --set-mark 20
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
@@ -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"