testing: Add scenarios to test ICMP forwarding

This commit is contained in:
Tobias Brunner
2026-02-12 16:21:37 +01:00
parent 22e502b286
commit a7c03a415e
26 changed files with 692 additions and 0 deletions
+18
View File
@@ -0,0 +1,18 @@
A connection between the gateways <b>moon</b> and <b>sun</b> is set up, which
connects <b>alice</b> and <b>moon</b> with a small subnet behind gateway <b>sun</b>.
A second tunnel is created between client <b>venus</b> and gateway <b>moon</b>,
which connects <b>venus</b> with another small subnet behind, in this case,
non-IPsec gateway <b>sun</b>.
The authentication is based on <b>X.509 certificates</b>.
<p/>
In order to test ICMP error forwarding, which <b>venus</b>, <b>moon</b> and
<b>sun</b> all enabled, <b>alice</b> and <b>moon</b> ping unreachable IPs behind
IPsec gateway <b>sun</b> and behind host <b>bob</b>, respectively. The
corresponding ICMP Destination Unreachable messages, with source IP addresses
outside the IPsec tunnel traffic selectors are expected to be forwarded
by <b>sun</b> and <b>moon</b>.
<p/>
Similar tests are run from <b>venus</b>, in which case the non-IPsec router
<b>sun</b> generates ICMP Time Exceeded (TTL expired) and Fragmentation Needed
(MTU exceeded) messages with a source IP outside of the traffic selectors.
These messages should again get forwarded by <b>moon</b>.
+18
View File
@@ -0,0 +1,18 @@
moon::swanctl --list-sas --raw 2> /dev/null::gw-gw.*version=2 state=ESTABLISHED local-host=192.168.0.1 local-port=500 local-id=moon.strongswan.org remote-host=192.168.0.2 remote-port=500 remote-id=sun.strongswan.org initiator=yes.*encr-alg=AES_CBC encr-keysize=128 integ-alg=HMAC_SHA2_256_128 prf-alg=PRF_HMAC_SHA2_256 dh-group=CURVE_25519.*child-sas.*net-net.*state=INSTALLED mode=TUNNEL.*ESP.*encr-alg=AES_GCM_16 encr-keysize=128.*local-ts=\[10.1.0.0/16] remote-ts=\[10.2.0.16/28]::YES
sun:: swanctl --list-sas --raw 2> /dev/null::gw-gw.*version=2 state=ESTABLISHED local-host=192.168.0.2 local-port=500 local-id=sun.strongswan.org remote-host=192.168.0.1 remote-port=500 remote-id=moon.strongswan.org.*encr-alg=AES_CBC encr-keysize=128 integ-alg=HMAC_SHA2_256_128 prf-alg=PRF_HMAC_SHA2_256 dh-group=CURVE_25519.*child-sas.*net-net.*state=INSTALLED mode=TUNNEL.*ESP.*encr-alg=AES_GCM_16 encr-keysize=128.*local-ts=\[10.2.0.16/28] remote-ts=\[10.1.0.0/16]::YES
moon::swanctl --list-sas --raw 2> /dev/null::venus.*version=2 state=ESTABLISHED local-host=10.1.0.1 local-port=500 local-id=moon.strongswan.org remote-host=10.1.0.20 remote-port=500 remote-id=venus.strongswan.org.*encr-alg=AES_CBC encr-keysize=128 integ-alg=HMAC_SHA2_256_128 prf-alg=PRF_HMAC_SHA2_256 dh-group=CURVE_25519.*child-sas.*net-net.*state=INSTALLED mode=TUNNEL.*ESP.*encr-alg=AES_GCM_16 encr-keysize=128.*local-ts=\[10.2.0.8/30] remote-ts=\[10.1.0.20/32]::YES
venus::swanctl --list-sas --raw 2> /dev/null::rw.*version=2 state=ESTABLISHED local-host=10.1.0.20 local-port=500 local-id=venus.strongswan.org remote-host=10.1.0.1 remote-port=500 remote-id=moon.strongswan.org initiator=yes.*encr-alg=AES_CBC encr-keysize=128 integ-alg=HMAC_SHA2_256_128 prf-alg=PRF_HMAC_SHA2_256 dh-group=CURVE_25519.*child-sas.*rw.*state=INSTALLED mode=TUNNEL.*ESP.*encr-alg=AES_GCM_16 encr-keysize=128.*local-ts=\[10.1.0.20/32] remote-ts=\[10.2.0.8/30]::YES
# the kernel currently sets the source incorrectly to the non-existent IP
# allow both in case it gets fixed
alice::ping -c 1 -W 4 10.2.0.25::From \(PH_IP_SUN\|10.2.0.25\) icmp_seq=1 Destination Host Unreachable::YES
moon::ping -c 1 -W 4 10.2.0.17::From PH_IP_BOB icmp_seq=1 Destination Host Unreachable::YES
# test other types of ICMPs with venus
venus::ping -c 1 PH_IP_BOB::64 bytes from PH_IP_BOB: icmp_.eq=1::YES
venus::ping -t 2 -c 1 PH_IP_BOB::From PH_IP_SUN.*Time to live exceeded::YES
venus::ping -M do -s 1320 -c 1 PH_IP_BOB::From PH_IP_SUN.*Frag needed and DF set (mtu = 1280)::YES
sun::tcpdump::IP moon.strongswan.org > sun.strongswan.org: ESP::2
sun::tcpdump::IP sun.strongswan.org > moon.strongswan.org: ESP::2
sun::tcpdump::IP sun.strongswan.org > alice.strongswan.org: ICMP host 10.2.0.25 unreachable::NO
sun::tcpdump::IP bob.strongswan.org > moon1.strongswan.org: ICMP host 10.2.0.17 unreachable::NO
venus::tcpdump::IP venus.strongswan.org > moon1.strongswan.org: ESP::3
venus::tcpdump::IP moon1.strongswan.org > venus.strongswan.org: ESP::3
@@ -0,0 +1,48 @@
*filter
# default policy is DROP
-P INPUT DROP
-P OUTPUT DROP
-P FORWARD DROP
# allow esp
-A INPUT -i eth0 -p 50 -j ACCEPT
-A OUTPUT -o eth0 -p 50 -j ACCEPT
# allow IKE
-A INPUT -i eth0 -p udp --sport 500 --dport 500 -j ACCEPT
-A OUTPUT -o eth0 -p udp --dport 500 --sport 500 -j ACCEPT
# allow MobIKE
-A INPUT -i eth0 -p udp --sport 4500 --dport 4500 -j ACCEPT
-A OUTPUT -o eth0 -p udp --dport 4500 --sport 4500 -j ACCEPT
# allow ssh
-A INPUT -p tcp --dport 22 -j ACCEPT
-A OUTPUT -p tcp --sport 22 -j ACCEPT
# allow crl fetch from winnetou
-A INPUT -i eth0 -p tcp --sport 80 -s 192.168.0.150 -j ACCEPT
-A OUTPUT -o eth0 -p tcp --dport 80 -d 192.168.0.150 -j ACCEPT
# allow decrypted ICMPs from any source IP (updown script is too specific)
-A INPUT -p icmp --icmp-type destination-unreachable -m policy --dir in -j ACCEPT
-A FORWARD -p icmp --icmp-type destination-unreachable -m policy --dir in -j ACCEPT
# allow venus to connect and fetch crls
-A INPUT -i eth1 -p udp --sport 500 --dport 500 -j ACCEPT
-A OUTPUT -o eth1 -p udp --dport 500 --sport 500 -j ACCEPT
-A INPUT -i eth1 -p 50 -j ACCEPT
-A OUTPUT -o eth1 -p 50 -j ACCEPT
-A FORWARD -i eth0 -o eth1 -p tcp --sport 80 -s 192.168.0.150 -j ACCEPT
-A FORWARD -o eth0 -i eth1 -p tcp --dport 80 -d 192.168.0.150 -j ACCEPT
# forward specific errors to venus
-A FORWARD -d 10.1.0.20/32 -p icmp --icmp-type time-exceeded -j ACCEPT
-A FORWARD -d 10.1.0.20/32 -p icmp --icmp-type fragmentation-needed -j ACCEPT
# log dropped packets
-A INPUT -j LOG --log-prefix " IN: "
-A OUTPUT -j LOG --log-prefix " OUT: "
COMMIT
@@ -0,0 +1,9 @@
# /etc/strongswan.conf - strongSwan configuration file
swanctl {
load = pem pkcs1 pubkey openssl random
}
charon-systemd {
load = random nonce openssl pem pkcs1 revocation curl kernel-netlink socket-default updown vici
}
@@ -0,0 +1,48 @@
connections {
gw-gw {
local_addrs = PH_IP_MOON
remote_addrs = PH_IP_SUN
local {
auth = pubkey
certs = moonCert.pem
id = moon.strongswan.org
}
remote {
auth = pubkey
id = sun.strongswan.org
}
children {
net-net {
local_ts = 10.1.0.0/16
remote_ts = 10.2.0.0/16
icmp = yes
updown = /usr/local/libexec/ipsec/_updown iptables
hostaccess = yes
esp_proposals = aes128gcm128-x25519
}
}
version = 2
mobike = no
proposals = aes128-sha256-x25519
}
venus : connections.gw-gw {
local_addrs = PH_IP_MOON1
remote_addrs = PH_IP_VENUS
remote {
id = venus.strongswan.org
}
children {
net-net {
# only include bob
local_ts = 10.2.0.8/30
remote_ts = dynamic
hostaccess = no
}
}
}
}
@@ -0,0 +1,42 @@
*filter
# default policy is DROP
-P INPUT DROP
-P OUTPUT DROP
-P FORWARD DROP
# allow esp
-A INPUT -i eth0 -p 50 -j ACCEPT
-A OUTPUT -o eth0 -p 50 -j ACCEPT
# allow IKE
-A INPUT -i eth0 -p udp --sport 500 --dport 500 -j ACCEPT
-A OUTPUT -o eth0 -p udp --dport 500 --sport 500 -j ACCEPT
# allow MobIKE
-A INPUT -i eth0 -p udp --sport 4500 --dport 4500 -j ACCEPT
-A OUTPUT -o eth0 -p udp --dport 4500 --sport 4500 -j ACCEPT
# allow ssh
-A INPUT -p tcp --dport 22 -j ACCEPT
-A OUTPUT -p tcp --sport 22 -j ACCEPT
# allow crl fetch from winnetou
-A INPUT -i eth0 -p tcp --sport 80 -s 192.168.0.150 -j ACCEPT
-A OUTPUT -o eth0 -p tcp --dport 80 -d 192.168.0.150 -j ACCEPT
# explicitly allow ICMP responses we don't actually want to see as they should get encrypted
-A OUTPUT -p icmp --icmp-type destination-unreachable -j ACCEPT
-A FORWARD -p icmp --icmp-type destination-unreachable -j ACCEPT
# allow only specific ICMPs from/to venus for this scenario
-A FORWARD -s 10.1.0.20/32 -p icmp --icmp-type echo-request -j ACCEPT
-A FORWARD -d 10.1.0.20/32 -p icmp --icmp-type echo-reply -j ACCEPT
-A OUTPUT -d 10.1.0.20/32 -p icmp --icmp-type time-exceeded -j ACCEPT
-A OUTPUT -d 10.1.0.20/32 -p icmp --icmp-type fragmentation-needed -j ACCEPT
# log dropped packets
-A INPUT -j LOG --log-prefix " IN: "
-A OUTPUT -j LOG --log-prefix " OUT: "
COMMIT
@@ -0,0 +1,9 @@
# /etc/strongswan.conf - strongSwan configuration file
swanctl {
load = pem pkcs1 pubkey openssl random
}
charon-systemd {
load = random nonce openssl pem pkcs1 revocation curl kernel-netlink socket-default updown vici
}
@@ -0,0 +1,31 @@
connections {
gw-gw {
local_addrs = PH_IP_SUN
remote_addrs = PH_IP_MOON
local {
auth = pubkey
certs = sunCert.pem
id = sun.strongswan.org
}
remote {
auth = pubkey
id = moon.strongswan.org
}
children {
net-net {
# exclude sun's and bob's IPs
local_ts = 10.2.0.16/28
remote_ts = 10.1.0.0/16
icmp = yes
updown = /usr/local/libexec/ipsec/_updown iptables
esp_proposals = aes128gcm128-x25519
}
}
version = 2
mobike = no
proposals = aes128-sha256-x25519
}
}
@@ -0,0 +1,9 @@
# /etc/strongswan.conf - strongSwan configuration file
swanctl {
load = pem pkcs1 pubkey openssl random
}
charon-systemd {
load = random nonce openssl pem pkcs1 revocation curl kernel-netlink socket-default updown vici
}
@@ -0,0 +1,29 @@
connections {
rw {
remote_addrs = PH_IP_MOON1
local {
auth = pubkey
certs = venusCert.pem
id = venus.strongswan.org
}
remote {
auth = pubkey
id = moon.strongswan.org
}
children {
rw {
remote_ts = 10.2.0.0/16
icmp = yes
updown = /usr/local/libexec/ipsec/_updown iptables
hostaccess = yes
esp_proposals = aes128gcm128-x25519
}
}
version = 2
mobike = no
proposals = aes128-sha256-x25519
}
}
+13
View File
@@ -0,0 +1,13 @@
moon::swanctl --terminate --ike gw-gw 2> /dev/null
moon::swanctl --terminate --ike venus 2> /dev/null
venus::systemctl stop strongswan
moon::systemctl stop strongswan
sun::systemctl stop strongswan
venus::iptables-restore < /etc/iptables.flush
moon::iptables-restore < /etc/iptables.flush
sun::iptables-restore < /etc/iptables.flush
sun::ip route del 10.2.0.16/30 via PH_IP_BOB
moon::ip route del 10.2.0.8/30 via PH_IP_SUN
sun::ip route del PH_IP_VENUS/32 via PH_IP_MOON
sun::ip route del 10.2.0.8/30 dev eth1 src PH_IP_SUN1
winnetou::ip route del 10.1.0.0/16 via PH_IP_MOON
+21
View File
@@ -0,0 +1,21 @@
venus::iptables-restore < /etc/iptables.rules
moon::iptables-restore < /etc/iptables.rules
sun::iptables-restore < /etc/iptables.rules
venus::systemctl start --no-block strongswan
moon::systemctl start --no-block strongswan
sun::systemctl start --no-block strongswan
# add a route for part of the private subnet via bob
sun::ip route add 10.2.0.16/30 via PH_IP_BOB
# setup routes to test with venus
winnetou::ip route add 10.1.0.0/16 via PH_IP_MOON
moon::ip route add 10.2.0.8/30 via PH_IP_SUN
sun::ip route add PH_IP_VENUS/32 via PH_IP_MOON
# force a lower MTU for traffic to bob
sun::ip route add 10.2.0.8/30 dev eth1 src PH_IP_SUN1 mtu 1280
# allow decrypted ICMPs from any source IP (rules for sun and moon are in iptables.rules)
venus::iptables -A INPUT -p icmp -m policy --dir in -j ACCEPT
venus::expect-connection rw
moon::expect-connection gw-gw
sun::expect-connection gw-gw
moon::swanctl --initiate --child net-net 2> /dev/null
venus::swanctl --initiate --child rw 2> /dev/null
+25
View File
@@ -0,0 +1,25 @@
#!/bin/bash
#
# This configuration file provides information on the
# guest instances used for this test
# All guest instances that are required for this test
#
VIRTHOSTS="alice venus moon winnetou sun bob"
# Corresponding block diagram
#
DIAGRAM="a-v-m-w-s-b.png"
# Guest instances on which tcpdump is to be started
#
TCPDUMPHOSTS="venus sun"
# Guest instances on which IPsec is started
# Used for IPsec logging purposes
#
IPSECHOSTS="venus moon sun"
# charon controlled by swanctl
#
SWANCTL=1