Commit 78a8f2d733 for strongswan.org

commit 78a8f2d73398f7a7c1100e14b763dc048df9a6aa
Author: Tobias Brunner <tobias@strongswan.org>
Date:   Thu Apr 16 09:14:25 2026 +0200

    testing: Add ikev2/mobike-transport scenario

diff --git a/testing/tests/ikev2/mobike-transport/description.txt b/testing/tests/ikev2/mobike-transport/description.txt
new file mode 100644
index 0000000000..ad3f985b1f
--- /dev/null
+++ b/testing/tests/ikev2/mobike-transport/description.txt
@@ -0,0 +1,9 @@
+The roadwarrior <b>alice</b> is sitting behind the router <b>moon</b> but
+at the outset of the scenario is also directly connected to the 192.168.0.0/24 network
+via an additional <b>eth1</b> interface. <b>alice</b> builds up a transport mode SA to
+host <b>sun</b>. When the <b>eth1</b> interface goes away, <b>alice</b> switches
+to <b>eth0</b> and signals the IP address change via a MOBIKE ADDRESS_UPDATE
+notification to peer <b>sun</b>. Then <b>eth1</b> is enabled again and the IPv4
+traffic to <b>sun</b> is blackholed to force a switch to IPv6 with another
+update. Since transport mode is used, the selectors installed on the SAs have
+to be updated in addition to the IPsec policies.
diff --git a/testing/tests/ikev2/mobike-transport/evaltest.dat b/testing/tests/ikev2/mobike-transport/evaltest.dat
new file mode 100644
index 0000000000..7fd087edff
--- /dev/null
+++ b/testing/tests/ikev2/mobike-transport/evaltest.dat
@@ -0,0 +1,34 @@
+alice::swanctl --list-sas --raw 2> /dev/null::mobike.*state=ESTABLISHED local-host=192.168.0.50 local-port=4500 local-id=alice@strongswan.org remote-host=PH_IP_SUN remote-port=4500 remote-id=sun.strongswan.org.*mode=TRANSPORT.*local-ts=\[PH_IP_ALICE1/32] remote-ts=\[PH_IP_SUN/32]::YES
+sun::  swanctl --list-sas --raw 2> /dev/null::mobike.*state=ESTABLISHED local-host=PH_IP_SUN local-port=4500 local-id=sun.strongswan.org remote-host=192.168.0.50 remote-port=4500 remote-id=alice@strongswan.org.*mode=TRANSPORT.*local-ts=\[PH_IP_SUN/32] remote-ts=\[PH_IP_ALICE1/32]::YES
+alice::ping -c 1 PH_IP_SUN::64 bytes from PH_IP_SUN: icmp_.eq=1::YES
+alice::ip xfrm state::sel src PH_IP_ALICE1/32 dst PH_IP_SUN/32::YES
+alice::ip xfrm state::sel src PH_IP_SUN/32 dst PH_IP_ALICE1/32::YES
+sun::ip xfrm state::sel src PH_IP_ALICE1/32 dst PH_IP_SUN/32::YES
+sun::ip xfrm state::sel src PH_IP_SUN/32 dst PH_IP_ALICE1/32::YES
+alice::ifdown eth1
+alice::sleep 1
+alice::swanctl --list-sas --raw 2> /dev/null::mobike.*state=ESTABLISHED local-host=PH_IP_ALICE local-port=4500 local-id=alice@strongswan.org remote-host=PH_IP_SUN remote-port=4500 remote-id=sun.strongswan.org.*mode=TRANSPORT.*local-ts=\[PH_IP_ALICE/32] remote-ts=\[PH_IP_SUN/32]::YES
+sun::  swanctl --list-sas --raw 2> /dev/null::mobike.*state=ESTABLISHED local-host=PH_IP_SUN local-port=4500 local-id=sun.strongswan.org remote-host=PH_IP_ALICE remote-port=4500 remote-id=alice@strongswan.org.*mode=TRANSPORT.*local-ts=\[PH_IP_SUN/32] remote-ts=\[PH_IP_ALICE/32]::YES
+alice::ping -c 1 PH_IP_SUN::64 bytes from PH_IP_SUN: icmp_.eq=1::YES
+alice::ip xfrm state::sel src PH_IP_ALICE/32 dst PH_IP_SUN/32::YES
+alice::ip xfrm state::sel src PH_IP_SUN/32 dst PH_IP_ALICE/32::YES
+sun::ip xfrm state::sel src PH_IP_ALICE/32 dst PH_IP_SUN/32::YES
+sun::ip xfrm state::sel src PH_IP_SUN/32 dst PH_IP_ALICE/32::YES
+# blackhole IPv4 traffic to sun to force a switch IPv6 via eth1 (easier routing than via eth0)
+alice::ip route add blackhole PH_IP_SUN/32
+# make sure the IPv6 address is available immediately
+alice::ifup eth1 -o dad-attempts=0
+alice::sleep 1
+alice::swanctl --list-sas --raw 2> /dev/null::mobike.*state=ESTABLISHED local-host=fec0:\:5 local-port=4500 local-id=alice@strongswan.org remote-host=fec0:\:2 remote-port=4500 remote-id=sun.strongswan.org.*mode=TRANSPORT.*local-ts=\[fec0:\:5/128] remote-ts=\[fec0:\:2/128]::YES
+sun::  swanctl --list-sas --raw 2> /dev/null::mobike.*state=ESTABLISHED local-host=fec0:\:2 local-port=4500 local-id=sun.strongswan.org remote-host=fec0:\:5 remote-port=4500 remote-id=alice@strongswan.org.*mode=TRANSPORT.*local-ts=\[fec0:\:2/128] remote-ts=\[fec0:\:5/128]::YES
+alice::ping6 -c 1 ip6-sun.strongswan.org::64 bytes from ip6-sun.strongswan.org.* icmp_.eq=1::YES
+alice::ip xfrm state::sel src fec0:\:5/128 dst fec0:\:2/128::YES
+alice::ip xfrm state::sel src fec0:\:2/128 dst fec0:\:5/128::YES
+sun::ip xfrm state::sel src fec0:\:5/128 dst fec0:\:2/128::YES
+sun::ip xfrm state::sel src fec0:\:2/128 dst fec0:\:5/128::YES
+sun::tcpdump::alice1.strongswan.org.*sun.strongswan.org: ESP.*seq=0x1::YES
+sun::tcpdump::sun.strongswan.org.*alice1.strongswan.org: ESP.*seq=0x1::YES
+moon::tcpdump::alice.strongswan.org.*sun.strongswan.org: ESP.*seq=0x2::YES
+moon::tcpdump::sun.strongswan.org.*alice.strongswan.org: ESP.*seq=0x2::YES
+sun::tcpdump::ip6-alice1.strongswan.org.*ip6-sun.strongswan.org: ESP.*seq=0x3::YES
+sun::tcpdump::ip6-sun.strongswan.org.*ip6-alice1.strongswan.org: ESP.*seq=0x3::YES
diff --git a/testing/tests/ikev2/mobike-transport/hosts/alice/etc/iptables.rules b/testing/tests/ikev2/mobike-transport/hosts/alice/etc/iptables.rules
new file mode 100644
index 0000000000..450e7cef6d
--- /dev/null
+++ b/testing/tests/ikev2/mobike-transport/hosts/alice/etc/iptables.rules
@@ -0,0 +1,42 @@
+*filter
+
+# default policy is DROP
+-P INPUT DROP
+-P OUTPUT DROP
+-P FORWARD DROP
+
+# allow traffic on lo as ifup/ifdown call bind's rndc which accesses TCP 953
+-A OUTPUT -o lo -j ACCEPT
+-A INPUT -i lo -j ACCEPT
+
+# allow IPsec tunnel traffic
+-A INPUT  -m policy --dir in  --pol ipsec --proto esp -j ACCEPT
+-A OUTPUT -m policy --dir out --pol ipsec --proto esp -j ACCEPT
+
+# allow ESP
+-A INPUT  -i eth0 -p 50 -j ACCEPT
+-A INPUT  -i eth1 -p 50 -j ACCEPT
+-A OUTPUT -o eth0 -p 50 -j ACCEPT
+-A OUTPUT -o eth1 -p 50 -j ACCEPT
+
+# allow IKE
+-A INPUT  -i eth0 -p udp --sport 500 --dport 500 -j ACCEPT
+-A INPUT  -i eth1 -p udp --sport 500 --dport 500 -j ACCEPT
+-A OUTPUT -o eth0 -p udp --dport 500 --sport 500 -j ACCEPT
+-A OUTPUT -o eth1 -p udp --dport 500 --sport 500 -j ACCEPT
+
+# allow MobIKE
+-A INPUT  -i eth0 -p udp --sport 4500 --dport 4500 -j ACCEPT
+-A INPUT  -i eth1 -p udp --sport 4500 --dport 4500 -j ACCEPT
+-A OUTPUT -o eth0 -p udp --dport 4500 --sport 4500 -j ACCEPT
+-A OUTPUT -o eth1 -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  -p tcp --sport 80 -s PH_IP_WINNETOU -j ACCEPT
+-A OUTPUT -p tcp --dport 80 -d PH_IP_WINNETOU -j ACCEPT
+
+COMMIT
diff --git a/testing/tests/ikev2/mobike-transport/hosts/alice/etc/strongswan.conf b/testing/tests/ikev2/mobike-transport/hosts/alice/etc/strongswan.conf
new file mode 100644
index 0000000000..bf035bb634
--- /dev/null
+++ b/testing/tests/ikev2/mobike-transport/hosts/alice/etc/strongswan.conf
@@ -0,0 +1,15 @@
+# /etc/strongswan.conf - strongSwan configuration file
+
+ swanctl {
+  load = pem pkcs1 pubkey openssl random
+}
+
+charon-systemd {
+  load = random nonce openssl pem pkcs1 revocation constraints pubkey curl kernel-netlink socket-default resolve updown vici
+  plugins {
+    kernel-netlink {
+      # set this to use route lookup via kernel, which allows using blackholing
+      fwmark = !0x42
+    }
+  }
+}
diff --git a/testing/tests/ikev2/mobike-transport/hosts/alice/etc/swanctl/swanctl.conf b/testing/tests/ikev2/mobike-transport/hosts/alice/etc/swanctl/swanctl.conf
new file mode 100644
index 0000000000..8254eb2286
--- /dev/null
+++ b/testing/tests/ikev2/mobike-transport/hosts/alice/etc/swanctl/swanctl.conf
@@ -0,0 +1,22 @@
+connections {
+
+   mobike {
+      local_addrs  = 192.168.0.50
+      remote_addrs = PH_IP_SUN
+
+      local {
+         auth = pubkey
+         certs = aliceCert.pem
+         id = alice@strongswan.org
+      }
+      remote {
+         auth = pubkey
+         id = sun.strongswan.org
+      }
+      children {
+         mobike {
+            mode = transport
+         }
+      }
+   }
+}
diff --git a/testing/tests/ikev2/mobike-transport/hosts/sun/etc/iptables.rules b/testing/tests/ikev2/mobike-transport/hosts/sun/etc/iptables.rules
new file mode 100644
index 0000000000..8866d30eb5
--- /dev/null
+++ b/testing/tests/ikev2/mobike-transport/hosts/sun/etc/iptables.rules
@@ -0,0 +1,32 @@
+*filter
+
+# default policy is DROP
+-P INPUT DROP
+-P OUTPUT DROP
+-P FORWARD DROP
+
+# allow IPsec tunnel traffic
+-A INPUT -m policy --dir in  --pol ipsec --proto esp -j ACCEPT
+-A OUTPUT -m policy --dir out --pol ipsec --proto esp -j ACCEPT
+
+# 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 PH_IP_WINNETOU -j ACCEPT
+-A OUTPUT -o eth0 -p tcp --dport 80 -d PH_IP_WINNETOU -j ACCEPT
+
+COMMIT
diff --git a/testing/tests/ikev2/mobike-transport/hosts/sun/etc/strongswan.conf b/testing/tests/ikev2/mobike-transport/hosts/sun/etc/strongswan.conf
new file mode 100644
index 0000000000..7b4ffcf7dc
--- /dev/null
+++ b/testing/tests/ikev2/mobike-transport/hosts/sun/etc/strongswan.conf
@@ -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 constraints pubkey curl kernel-netlink socket-default resolve updown vici
+}
diff --git a/testing/tests/ikev2/mobike-transport/hosts/sun/etc/swanctl/swanctl.conf b/testing/tests/ikev2/mobike-transport/hosts/sun/etc/swanctl/swanctl.conf
new file mode 100644
index 0000000000..7a62fab55e
--- /dev/null
+++ b/testing/tests/ikev2/mobike-transport/hosts/sun/etc/swanctl/swanctl.conf
@@ -0,0 +1,22 @@
+connections {
+
+   mobike {
+      local_addrs  = PH_IP_SUN
+      remote_addrs = 192.168.0.50
+
+      local {
+         auth = pubkey
+         certs = sunCert.pem
+         id = sun.strongswan.org
+      }
+      remote {
+         auth = pubkey
+         id = alice@strongswan.org
+      }
+      children {
+         mobike {
+            mode = transport
+         }
+      }
+   }
+}
diff --git a/testing/tests/ikev2/mobike-transport/posttest.dat b/testing/tests/ikev2/mobike-transport/posttest.dat
new file mode 100644
index 0000000000..52f33e5641
--- /dev/null
+++ b/testing/tests/ikev2/mobike-transport/posttest.dat
@@ -0,0 +1,7 @@
+alice::systemctl stop strongswan
+sun::systemctl stop strongswan
+alice::iptables-restore < /etc/iptables.flush
+alice::ifdown eth1
+alice::ip route del blackhole PH_IP_SUN/32
+sun::iptables-restore < /etc/iptables.flush
+sun::ip route del 10.1.0.0/16 via PH_IP_MOON
diff --git a/testing/tests/ikev2/mobike-transport/pretest.dat b/testing/tests/ikev2/mobike-transport/pretest.dat
new file mode 100644
index 0000000000..e80dcd33ed
--- /dev/null
+++ b/testing/tests/ikev2/mobike-transport/pretest.dat
@@ -0,0 +1,9 @@
+alice::ifup eth1
+alice::iptables-restore < /etc/iptables.rules
+sun::iptables-restore < /etc/iptables.rules
+sun::ip route add 10.1.0.0/16 via PH_IP_MOON
+alice::systemctl start strongswan
+sun::systemctl start strongswan
+alice::expect-connection mobike
+sun::expect-connection mobike
+alice::swanctl --initiate --child mobike 2> /dev/null
diff --git a/testing/tests/ikev2/mobike-transport/test.conf b/testing/tests/ikev2/mobike-transport/test.conf
new file mode 100644
index 0000000000..074889f0b6
--- /dev/null
+++ b/testing/tests/ikev2/mobike-transport/test.conf
@@ -0,0 +1,24 @@
+#!/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 moon winnetou sun bob"
+
+# Corresponding block diagram
+#
+DIAGRAM="a-m-w-s-b.png"
+
+# Guest instances on which tcpdump is to be started
+#
+TCPDUMPHOSTS="moon sun"
+
+# Guest instances on which IPsec is started
+# Used for IPsec logging purposes
+#
+IPSECHOSTS="alice sun"
+
+# charon controlled by swanctl
+SWANCTL=1