From: Tobias Brunner Date: Thu, 14 Apr 2022 12:13:07 +0000 (+0200) Subject: testing: Add DSCP scenario that uses simple labels X-Git-Tag: 5.9.6rc1~3^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6910347d1aba509ac7085938124b2b7c9f240064;p=thirdparty%2Fstrongswan.git testing: Add DSCP scenario that uses simple labels Instead of creating two IKE_SAs with different identities, this scenario uses simple labels to select the correct child config. --- diff --git a/testing/tests/ikev2/net2net-dscp/description.txt b/testing/tests/ikev2/net2net-dscp/description.txt new file mode 100644 index 0000000000..0108bcb14a --- /dev/null +++ b/testing/tests/ikev2/net2net-dscp/description.txt @@ -0,0 +1,11 @@ +In order to support Differentiated Services (DiffServ), two parallel IPsec +connections between the subnets behind the gateways moon and sun are +set up. Using XFRM marks one IPsec SA is designated for Best Effort (BE) +traffic and the second SA for Expedited Forwarding (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 X.509 certificates. +

+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 alice behind gateway moon +pings client bob located behind gateway sun. diff --git a/testing/tests/ikev2/net2net-dscp/evaltest.dat b/testing/tests/ikev2/net2net-dscp/evaltest.dat new file mode 100644 index 0000000000..313891ef9a --- /dev/null +++ b/testing/tests/ikev2/net2net-dscp/evaltest.dat @@ -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 index 0000000000..4fe92b6ece --- /dev/null +++ b/testing/tests/ikev2/net2net-dscp/hosts/moon/etc/strongswan.conf @@ -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 index 0000000000..d6c2b30039 --- /dev/null +++ b/testing/tests/ikev2/net2net-dscp/hosts/moon/etc/swanctl/swanctl.conf @@ -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 index 0000000000..f7a83f3a42 --- /dev/null +++ b/testing/tests/ikev2/net2net-dscp/hosts/sun/etc/strongswan.conf @@ -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 index 0000000000..6e69f2a3c0 --- /dev/null +++ b/testing/tests/ikev2/net2net-dscp/hosts/sun/etc/swanctl/swanctl.conf @@ -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 index 0000000000..8c9a5f9ba4 --- /dev/null +++ b/testing/tests/ikev2/net2net-dscp/posttest.dat @@ -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 index 0000000000..2d5d7ba37a --- /dev/null +++ b/testing/tests/ikev2/net2net-dscp/pretest.dat @@ -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 index 0000000000..7f82c02f11 --- /dev/null +++ b/testing/tests/ikev2/net2net-dscp/test.conf @@ -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