]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
testing: Add DSCP scenario that uses simple labels
authorTobias Brunner <tobias@strongswan.org>
Thu, 14 Apr 2022 12:13:07 +0000 (14:13 +0200)
committerTobias Brunner <tobias@strongswan.org>
Thu, 14 Apr 2022 16:42:01 +0000 (18:42 +0200)
Instead of creating two IKE_SAs with different identities, this scenario
uses simple labels to select the correct child config.

testing/tests/ikev2/net2net-dscp/description.txt [new file with mode: 0644]
testing/tests/ikev2/net2net-dscp/evaltest.dat [new file with mode: 0644]
testing/tests/ikev2/net2net-dscp/hosts/moon/etc/strongswan.conf [new file with mode: 0644]
testing/tests/ikev2/net2net-dscp/hosts/moon/etc/swanctl/swanctl.conf [new file with mode: 0755]
testing/tests/ikev2/net2net-dscp/hosts/sun/etc/strongswan.conf [new file with mode: 0644]
testing/tests/ikev2/net2net-dscp/hosts/sun/etc/swanctl/swanctl.conf [new file with mode: 0755]
testing/tests/ikev2/net2net-dscp/posttest.dat [new file with mode: 0644]
testing/tests/ikev2/net2net-dscp/pretest.dat [new file with mode: 0644]
testing/tests/ikev2/net2net-dscp/test.conf [new file with mode: 0644]

diff --git a/testing/tests/ikev2/net2net-dscp/description.txt b/testing/tests/ikev2/net2net-dscp/description.txt
new file mode 100644 (file)
index 0000000..0108bcb
--- /dev/null
@@ -0,0 +1,11 @@
+In order to support <b>Differentiated Services</b> (DiffServ), two parallel IPsec
+connections between the subnets behind the gateways <b>moon</b> and <b>sun</b> are
+set up. Using <b>XFRM marks</b> one IPsec SA is designated for <b>Best Effort</b> (BE)
+traffic and the second SA for <b>Expedited Forwarding</b> (EF) traffic.  To guarantee
+that the CHILD_SA with the correct mark is selected on the responder side, labels
+are used and negotiated via IKEv2. The authentication is based on <b>X.509 certificates</b>.
+<p/>
+Upon the successful establishment of the IPsec tunnel, the updown script automatically
+inserts iptables-based firewall rules that let pass the tunneled traffic
+In order to test both tunnel and firewall, client <b>alice</b> behind gateway <b>moon</b>
+pings client <b>bob</b> located behind gateway <b>sun</b>.
diff --git a/testing/tests/ikev2/net2net-dscp/evaltest.dat b/testing/tests/ikev2/net2net-dscp/evaltest.dat
new file mode 100644 (file)
index 0000000..313891e
--- /dev/null
@@ -0,0 +1,10 @@
+moon::swanctl --list-sas --raw 2> /dev/null::dscp.*version=2 state=ESTABLISHED local-host=PH_IP_MOON local-port=500 local-id=moon.strongswan.org remote-host=PH_IP_SUN 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-be.*state=INSTALLED mode=TUNNEL label=647363702d626500.*ESP.*mark-in=0000000a mark-out=0000000a encr-alg=AES_GCM_16 encr-keysize=128.*local-ts=\[10.1.0.0/16] remote-ts=\[10.2.0.0/16]::YES
+moon::swanctl --list-sas --raw 2> /dev/null::dscp.*version=2 state=ESTABLISHED local-host=PH_IP_MOON local-port=500 local-id=moon.strongswan.org remote-host=PH_IP_SUN 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-ef.*state=INSTALLED mode=TUNNEL label=647363702d656600.*ESP.*mark-in=00000014 mark-out=00000014 encr-alg=AES_GCM_16 encr-keysize=128.*local-ts=\[10.1.0.0/16] remote-ts=\[10.2.0.0/16]::YES
+sun:: swanctl --list-sas --raw 2> /dev/null::dscp.*version=2 state=ESTABLISHED local-host=PH_IP_SUN local-port=500 local-id=sun.strongswan.org remote-host=PH_IP_MOON 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-be.*state=INSTALLED mode=TUNNEL label=647363702d626500.*ESP.*mark-in=0000000a mark-out=0000000a encr-alg=AES_GCM_16 encr-keysize=128.*local-ts=\[10.2.0.0/16] remote-ts=\[10.1.0.0/16]::YES
+sun:: swanctl --list-sas --raw 2> /dev/null::dscp.*version=2 state=ESTABLISHED local-host=PH_IP_SUN local-port=500 local-id=sun.strongswan.org remote-host=PH_IP_MOON 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-ef.*state=INSTALLED mode=TUNNEL label=647363702d656600.*ESP.*mark-in=00000014 mark-out=00000014 encr-alg=AES_GCM_16 encr-keysize=128.*local-ts=\[10.2.0.0/16] remote-ts=\[10.1.0.0/16]::YES
+alice::ping -c 1 PH_IP_BOB::64 bytes from PH_IP_BOB: icmp_.eq=1::YES
+venus::ping -c 1 PH_IP_BOB::64 bytes from PH_IP_BOB: icmp_.eq=1::YES
+moon::swanctl --list-sas --child net-be --raw 2> /dev/null::child-sas.*net-be.*packets-in=1.*packets-out=1::YES
+moon::swanctl --list-sas --child net-ef --raw 2> /dev/null::child-sas.*net-ef.*packets-in=1.*packets-out=1::YES
+sun::tcpdump::IP moon.strongswan.org > sun.strongswan.org: ESP::YES
+sun::tcpdump::IP sun.strongswan.org > moon.strongswan.org: ESP::YES
diff --git a/testing/tests/ikev2/net2net-dscp/hosts/moon/etc/strongswan.conf b/testing/tests/ikev2/net2net-dscp/hosts/moon/etc/strongswan.conf
new file mode 100644 (file)
index 0000000..4fe92b6
--- /dev/null
@@ -0,0 +1,14 @@
+# /etc/strongswan.conf - strongSwan configuration file
+
+swanctl {
+  load = pem pkcs1 x509 revocation constraints pubkey openssl random
+}
+
+charon-systemd {
+  load = random nonce aes sha1 sha2 hmac pem pkcs1 x509 revocation curve25519 gmp curl kernel-netlink socket-default updown vici
+  syslog {
+    daemon {
+      knl = 2
+    }
+  }
+}
diff --git a/testing/tests/ikev2/net2net-dscp/hosts/moon/etc/swanctl/swanctl.conf b/testing/tests/ikev2/net2net-dscp/hosts/moon/etc/swanctl/swanctl.conf
new file mode 100755 (executable)
index 0000000..d6c2b30
--- /dev/null
@@ -0,0 +1,38 @@
+connections {
+
+   dscp {
+      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-be {
+            local_ts  = 10.1.0.0/16
+            remote_ts = 10.2.0.0/16
+
+            mark_in  = 10
+            mark_out = 10
+            label = dscp-be
+
+            updown = /usr/local/libexec/ipsec/_updown iptables
+            esp_proposals = aes128gcm128-x25519
+         }
+         net-ef : connections.dscp.children.net-be {
+            mark_in  = 20
+            mark_out = 20
+            label = dscp-ef
+         }
+      }
+      version = 2
+      mobike = no
+      proposals = aes128-sha256-x25519
+   }
+}
diff --git a/testing/tests/ikev2/net2net-dscp/hosts/sun/etc/strongswan.conf b/testing/tests/ikev2/net2net-dscp/hosts/sun/etc/strongswan.conf
new file mode 100644 (file)
index 0000000..f7a83f3
--- /dev/null
@@ -0,0 +1,15 @@
+# /etc/strongswan.conf - strongSwan configuration file
+
+swanctl {
+  load = pem pkcs1 x509 revocation constraints pubkey openssl random
+}
+
+charon-systemd {
+  load = random nonce aes sha1 sha2 hmac pem pkcs1 x509 revocation curve25519 gmp curl kernel-netlink socket-default updown vici
+  multiple_authentication = no
+  syslog {
+    daemon {
+      knl = 2
+    }
+  }
+}
diff --git a/testing/tests/ikev2/net2net-dscp/hosts/sun/etc/swanctl/swanctl.conf b/testing/tests/ikev2/net2net-dscp/hosts/sun/etc/swanctl/swanctl.conf
new file mode 100755 (executable)
index 0000000..6e69f2a
--- /dev/null
@@ -0,0 +1,38 @@
+connections {
+
+   dscp {
+      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-be {
+            local_ts  = 10.2.0.0/16
+            remote_ts = 10.1.0.0/16
+
+            mark_in  = 10
+            mark_out = 10
+            label = dscp-be
+
+            updown = /usr/local/libexec/ipsec/_updown iptables
+            esp_proposals = aes128gcm128-x25519
+         }
+         net-ef : connections.dscp.children.net-be {
+            mark_in  = 20
+            mark_out = 20
+            label = dscp-ef
+         }
+      }
+      version = 2
+      mobike = no
+      proposals = aes128-sha256-x25519
+   }
+}
diff --git a/testing/tests/ikev2/net2net-dscp/posttest.dat b/testing/tests/ikev2/net2net-dscp/posttest.dat
new file mode 100644 (file)
index 0000000..8c9a5f9
--- /dev/null
@@ -0,0 +1,8 @@
+moon::systemctl stop strongswan
+sun::systemctl stop strongswan
+moon::iptables-restore < /etc/iptables.flush
+sun::iptables-restore < /etc/iptables.flush
+alice::iptables -t mangle -F OUTPUT
+venus::iptables -t mangle -F OUTPUT
+bob::iptables -t mangle -F OUTPUT
+
diff --git a/testing/tests/ikev2/net2net-dscp/pretest.dat b/testing/tests/ikev2/net2net-dscp/pretest.dat
new file mode 100644 (file)
index 0000000..2d5d7ba
--- /dev/null
@@ -0,0 +1,16 @@
+moon::iptables-restore < /etc/iptables.rules
+sun::iptables-restore < /etc/iptables.rules
+alice::iptables -t mangle -A OUTPUT -p icmp -j DSCP --set-dscp-class BE
+venus::iptables -t mangle -A OUTPUT -p icmp -j DSCP --set-dscp-class EF
+moon::iptables -t mangle -A PREROUTING -m dscp --dscp-class BE -j MARK --set-mark 10
+moon::iptables -t mangle -A PREROUTING -m dscp --dscp-class EF -j MARK --set-mark 20
+bob::iptables -t mangle -A OUTPUT -d PH_IP_ALICE -p icmp -j DSCP --set-dscp-class BE
+bob::iptables -t mangle -A OUTPUT -d PH_IP_VENUS -p icmp -j DSCP --set-dscp-class EF
+sun::iptables -t mangle -A PREROUTING -m dscp --dscp-class BE -j MARK --set-mark 10
+sun::iptables -t mangle -A PREROUTING -m dscp --dscp-class EF -j MARK --set-mark 20
+sun::systemctl start strongswan
+moon::systemctl start strongswan
+sun::expect-connection dscp
+moon::expect-connection dscp
+moon::swanctl --initiate --child net-be
+moon::swanctl --initiate --child net-ef
diff --git a/testing/tests/ikev2/net2net-dscp/test.conf b/testing/tests/ikev2/net2net-dscp/test.conf
new file mode 100644 (file)
index 0000000..7f82c02
--- /dev/null
@@ -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="sun"
+
+# Guest instances on which IPsec is started
+# Used for IPsec logging purposes
+#
+IPSECHOSTS="moon sun"
+
+# charon controlled by swanctl
+#
+SWANCTL=1