Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F178120299
D62061.1796028607.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
9 KB
Referenced Files
None
Subscribers
None
D62061.1796028607.diff
View Options
diff --git a/sys/netipsec/ipsec_output.c b/sys/netipsec/ipsec_output.c
--- a/sys/netipsec/ipsec_output.c
+++ b/sys/netipsec/ipsec_output.c
@@ -125,6 +125,24 @@
}
}
+/*
+ * The request whose SA gives the outer destination for the PMTU check: the
+ * last one with addresses of its own, as every tunnel request has, or the
+ * last one if none has. The SA of a request without addresses depends on
+ * the header that the requests before it leave, which is not known here.
+ */
+static u_int
+ipsec_pmtu_reqidx(const struct secpolicy *sp)
+{
+ u_int i;
+
+ for (i = sp->tcount; i > 0; i--) {
+ if (sp->req[i - 1]->saidx.dst.sa.sa_len != 0)
+ return (i - 1);
+ }
+ return (sp->tcount - 1);
+}
+
#ifdef INET
static struct secasvar *
ipsec4_allocsa(struct ifnet *ifp, struct mbuf *m, const struct ip *ip,
@@ -371,16 +389,14 @@
return (0);
setdf:
- idx = sp->tcount - 1;
+ idx = ipsec_pmtu_reqidx(sp);
sav = ipsec4_allocsa(ifp, m, ip1, sp, &idx, &error);
if (sav == NULL) {
/*
- * No SA was found for the last request and it does not
- * require one. The requests before it may still apply, and
- * a transport request after a tunnel request was looked up
- * with the addresses of this packet rather than those of the
- * tunnel, so it may have an SA after all. Leave them to
- * ipsec4_process_packet() and skip the PMTU check.
+ * None of the requests from that index on has an SA or
+ * requires one. The requests before it may still apply:
+ * leave them to ipsec4_process_packet() and skip the PMTU
+ * check.
*/
if (error == EJUSTRETURN)
return (0);
@@ -795,16 +811,14 @@
if (!forwarding)
return (0);
- idx = sp->tcount - 1;
+ idx = ipsec_pmtu_reqidx(sp);
sav = ipsec6_allocsa(ifp, m, sp, &idx, &error);
if (sav == NULL) {
/*
- * No SA was found for the last request and it does not
- * require one. The requests before it may still apply, and
- * a transport request after a tunnel request was looked up
- * with the addresses of this packet rather than those of the
- * tunnel, so it may have an SA after all. Leave them to
- * ipsec6_process_packet() and skip the PMTU check.
+ * None of the requests from that index on has an SA or
+ * requires one. The requests before it may still apply:
+ * leave them to ipsec6_process_packet() and skip the PMTU
+ * check.
*/
if (error == EJUSTRETURN)
return (0);
diff --git a/tests/sys/netipsec/tunnel/bundle.sh b/tests/sys/netipsec/tunnel/bundle.sh
--- a/tests/sys/netipsec/tunnel/bundle.sh
+++ b/tests/sys/netipsec/tunnel/bundle.sh
@@ -2,17 +2,26 @@
. $(atf_get_srcdir)/utils.subr
KEY="12345678901234567890"
+AKEY="12345678901234567890123456789012"
-# bundle_use 4|6 [DFBIT]: ipsecA's outbound policy bundles a required ESP
-# tunnel with an AH transport request at level "use", and only the ESP SAs
-# exist. The AH request is skipped, so the packets must leave with ESP
-# alone: ipsecB has a plain ESP tunnel and drops anything else, and the
-# router has no route to lan_b for a packet sent without the tunnel.
+# bundle_setup KIND AF [DFBIT]: ipsecA's outbound policy is a bundle with a
+# transport request after a tunnel request, and the router has no route to
+# lan_b for a packet sent without the tunnel.
+# "use" and "require": a required ESP tunnel with an AH transport request at
+# that level, and ipsecB's inbound policy is the ESP tunnel alone. For "use"
+# only the ESP SAs exist, so the AH request is skipped, and ipsecB would drop
+# an AH packet. For "require" both ends also have the AH SA, which has the
+# outer addresses gw_a and gw_b, and ipsecB must have received the pings
+# with AH.
+# "ipcomp": the policy strongSwan installs for IPComp in tunnel mode, an
+# IPComp tunnel with an ESP transport request after it, both at level unique
+# with one reqid, and the IPComp and ESP SAs on both ends. ipsecB must have
+# received the pings through the IPComp SA, compressed or not.
# DFBIT sets net.inet.ipsec.dfbit on ipsecA, which makes IPv4 run the PMTU
# check, as forwarded IPv6 always does.
-bundle_use()
+bundle_setup()
{
- af=$1; dfbit=${2:-}
+ kind=$1; af=$2; dfbit=${3:-}
if [ ${af} = 4 ]; then
lan_a=192.0.2.0/30; lan_b=203.0.113.0/30; target=203.0.113.1
gw_a=198.51.100.2; gw_b=198.51.100.6
@@ -20,7 +29,21 @@
lan_a=2001:db8:1::/64; lan_b=2001:db8:45::/64; target=2001:db8:45::1
gw_a=2001:db8:23::2; gw_b=2001:db8:34::2
fi
- sas="add ${gw_a} ${gw_b} esp 0x1000 -m tunnel -E aes-gcm-16 \"${KEY}\";
+ if [ ${kind} = ipcomp ]; then
+ pol_out="ipcomp/tunnel/${gw_a}-${gw_b}/unique:100 esp/transport//unique:100"
+ pol_in="ipcomp/tunnel/${gw_a}-${gw_b}/use esp/transport//unique:100"
+ sas="add ${gw_a} ${gw_b} ipcomp 0x2000 -m tunnel -u 100 -C deflate;
+add ${gw_a} ${gw_b} esp 0x1002 -m transport -u 100 -E aes-gcm-16 \"${KEY}\";"
+ else
+ pol_out="esp/tunnel/${gw_a}-${gw_b}/require ah/transport//${kind}"
+ pol_in="esp/tunnel/${gw_a}-${gw_b}/require"
+ sas="add ${gw_a} ${gw_b} esp 0x1000 -m tunnel -E aes-gcm-16 \"${KEY}\";"
+ if [ ${kind} = require ]; then
+ sas="${sas}
+add ${gw_a} ${gw_b} ah 0x1002 -m transport -A hmac-sha2-256 \"${AKEY}\";"
+ fi
+ fi
+ sas="${sas}
add ${gw_b} ${gw_a} esp 0x1001 -m tunnel -E aes-gcm-16 \"${KEY}\";"
ist_init
@@ -33,20 +56,35 @@
cat > ${TMPDIR}/ipsec.ipsecA.conf <<-EOF
flush;
spdflush;
- spdadd ${lan_a} ${lan_b} any -P out ipsec esp/tunnel/${gw_a}-${gw_b}/require ah/transport//use;
+ spdadd ${lan_a} ${lan_b} any -P out ipsec ${pol_out};
spdadd ${lan_b} ${lan_a} any -P in ipsec esp/tunnel/${gw_b}-${gw_a}/require;
${sas}
EOF
cat > ${TMPDIR}/ipsec.ipsecB.conf <<-EOF
flush;
spdflush;
- spdadd ${lan_a} ${lan_b} any -P in ipsec esp/tunnel/${gw_a}-${gw_b}/require;
+ spdadd ${lan_a} ${lan_b} any -P in ipsec ${pol_in};
spdadd ${lan_b} ${lan_a} any -P out ipsec esp/tunnel/${gw_b}-${gw_a}/require;
${sas}
EOF
atf_check -s exit:0 -o ignore jexec ipsecA setkey -f ${TMPDIR}/ipsec.ipsecA.conf
atf_check -s exit:0 -o ignore jexec ipsecB setkey -f ${TMPDIR}/ipsec.ipsecB.conf
+}
+
+bundle_ping()
+{
+ bundle_setup "$@"
atf_check -s exit:0 -o ignore jexec hostA ping -c 3 -i 0.2 ${target}
+ case ${kind} in
+ require)
+ atf_check -s exit:0 -o match:"[[:space:]]3 packets in" \
+ jexec ipsecB netstat -s -p ah
+ ;;
+ ipcomp)
+ atf_check -s exit:0 -o match:"[[:space:]]3 packets in" \
+ jexec ipsecB netstat -s -p ipcomp
+ ;;
+ esac
}
atf_test_case "use_v4" "cleanup"
@@ -57,7 +95,7 @@
}
use_v4_body()
{
- bundle_use 4
+ bundle_ping use 4
}
use_v4_cleanup()
{
@@ -72,7 +110,7 @@
}
use_v4_dfbit_body()
{
- bundle_use 4 1
+ bundle_ping use 4 1
}
use_v4_dfbit_cleanup()
{
@@ -87,16 +125,152 @@
}
use_v6_body()
{
- bundle_use 6
+ bundle_ping use 6
}
use_v6_cleanup()
{
ist_cleanup
}
+atf_test_case "require_v4" "cleanup"
+require_v4_head()
+{
+ atf_set descr 'A required transport request after a tunnel request is applied (IPv4)'
+ atf_set require.user root
+}
+require_v4_body()
+{
+ bundle_ping require 4
+}
+require_v4_cleanup()
+{
+ ist_cleanup
+}
+
+atf_test_case "require_v4_dfbit" "cleanup"
+require_v4_dfbit_head()
+{
+ atf_set descr 'A required transport request after a tunnel request is applied (IPv4, PMTU check)'
+ atf_set require.user root
+}
+require_v4_dfbit_body()
+{
+ bundle_ping require 4 1
+}
+require_v4_dfbit_cleanup()
+{
+ ist_cleanup
+}
+
+atf_test_case "require_v6" "cleanup"
+require_v6_head()
+{
+ atf_set descr 'A required transport request after a tunnel request is applied (IPv6)'
+ atf_set require.user root
+}
+require_v6_body()
+{
+ bundle_ping require 6
+}
+require_v6_cleanup()
+{
+ ist_cleanup
+}
+
+atf_test_case "ipcomp_v4" "cleanup"
+ipcomp_v4_head()
+{
+ atf_set descr 'An ESP transport request after an IPComp tunnel request is applied (IPv4)'
+ atf_set require.user root
+}
+ipcomp_v4_body()
+{
+ bundle_ping ipcomp 4
+}
+ipcomp_v4_cleanup()
+{
+ ist_cleanup
+}
+
+atf_test_case "ipcomp_v4_dfbit" "cleanup"
+ipcomp_v4_dfbit_head()
+{
+ atf_set descr 'An ESP transport request after an IPComp tunnel request is applied (IPv4, PMTU check)'
+ atf_set require.user root
+}
+ipcomp_v4_dfbit_body()
+{
+ bundle_ping ipcomp 4 1
+}
+ipcomp_v4_dfbit_cleanup()
+{
+ ist_cleanup
+}
+
+atf_test_case "ipcomp_v6" "cleanup"
+ipcomp_v6_head()
+{
+ atf_set descr 'An ESP transport request after an IPComp tunnel request is applied (IPv6)'
+ atf_set require.user root
+}
+ipcomp_v6_body()
+{
+ bundle_ping ipcomp 6
+}
+ipcomp_v6_cleanup()
+{
+ ist_cleanup
+}
+
+# The PMTU check takes the path MTU to the tunnel endpoint, whether the AH
+# request after the tunnel applies or not. A full-size packet from hostA
+# does not fit once tunnelled, and ipsecA must report it to hostA. Without
+# -u, ping -6 fragments to the minimum IPv6 MTU.
+atf_test_case "needfrag_v4" "cleanup"
+needfrag_v4_head()
+{
+ atf_set descr 'The PMTU check of a bundle uses its tunnel request (IPv4)'
+ atf_set require.user root
+}
+needfrag_v4_body()
+{
+ bundle_setup use 4 1
+ atf_check -s exit:2 -o match:"frag needed and DF set" \
+ jexec hostA ping -c 1 -t 2 -D -s 1472 ${target}
+}
+needfrag_v4_cleanup()
+{
+ ist_cleanup
+}
+
+atf_test_case "needfrag_v6" "cleanup"
+needfrag_v6_head()
+{
+ atf_set descr 'The PMTU check of a bundle uses its tunnel request (IPv6)'
+ atf_set require.user root
+}
+needfrag_v6_body()
+{
+ bundle_setup use 6
+ atf_check -s exit:2 -o match:"Packet too big" \
+ jexec hostA ping -6 -c 1 -t 2 -u -v -s 1452 ${target}
+}
+needfrag_v6_cleanup()
+{
+ ist_cleanup
+}
+
atf_init_test_cases()
{
atf_add_test_case "use_v4"
atf_add_test_case "use_v4_dfbit"
atf_add_test_case "use_v6"
+ atf_add_test_case "require_v4"
+ atf_add_test_case "require_v4_dfbit"
+ atf_add_test_case "require_v6"
+ atf_add_test_case "ipcomp_v4"
+ atf_add_test_case "ipcomp_v4_dfbit"
+ atf_add_test_case "ipcomp_v6"
+ atf_add_test_case "needfrag_v4"
+ atf_add_test_case "needfrag_v6"
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Nov 30, 8:50 AM (23 h, 25 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
42103190
Default Alt Text
D62061.1796028607.diff (9 KB)
Attached To
Mode
D62061: netipsec: Find the outer destination of a bundle for the PMTU check
Attached
Detach File
Event Timeline