Page MenuHomeFreeBSD

D62061.1795972464.diff
No OneTemporary

Authored By
Unknown
Size
15 KB
Referenced Files
None
Subscribers
None

D62061.1795972464.diff

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
@@ -128,7 +128,7 @@
#ifdef INET
static struct secasvar *
ipsec4_allocsa(struct ifnet *ifp, struct mbuf *m, const struct ip *ip,
- struct secpolicy *sp, u_int *pidx, int *error)
+ struct secpolicy *sp, u_int *pidx, int *error, bool skip)
{
struct secasindex *saidx, tmpsaidx;
struct ipsecrequest *isr;
@@ -186,9 +186,10 @@
* We have no SA and policy that doesn't require
* this IPsec transform, thus we can continue w/o
* IPsec processing, i.e. return EJUSTRETURN.
- * But first check if there is some bundled transform.
+ * But first check if there is some bundled transform,
+ * unless the caller looks at this request alone.
*/
- if (sp->tcount > ++(*pidx))
+ if (skip && sp->tcount > ++(*pidx))
goto next;
*error = EJUSTRETURN;
}
@@ -224,7 +225,7 @@
* determine next transform. At the end of transform we can
* release reference to SP.
*/
- sav = ipsec4_allocsa(ifp, m, ip1, sp, &idx, &error);
+ sav = ipsec4_allocsa(ifp, m, ip1, sp, &idx, &error, true);
if (sav == NULL) {
if (error == EJUSTRETURN) { /* No IPsec required */
(void)ipsec_accel_output(ifp, m, inp, sp, NULL,
@@ -357,7 +358,7 @@
{
struct secasvar *sav;
size_t hlen, pmtu;
- uint32_t idx;
+ uint32_t i, idx;
int error;
/* Don't check PMTU if the frame won't have DF bit set. */
@@ -371,16 +372,34 @@
return (0);
setdf:
- idx = sp->tcount - 1;
- sav = ipsec4_allocsa(ifp, m, ip1, sp, &idx, &error);
+ /*
+ * The outer destination is that of the last request that has both
+ * addresses of its own, as every tunnel request does, and an SA.
+ * One at level use without an SA is skipped, so the requests before
+ * it may apply. The SA of a request without addresses depends on
+ * the header that the requests before it leave, so look those up,
+ * with the addresses of the packet, only when no request with
+ * addresses applies.
+ */
+ sav = NULL;
+ error = EJUSTRETURN;
+ for (i = sp->tcount; i > 0 && sav == NULL && error == EJUSTRETURN;
+ i--) {
+ idx = i - 1;
+ if (sp->req[idx]->saidx.dst.sa.sa_len != 0)
+ sav = ipsec4_allocsa(ifp, m, ip1, sp, &idx, &error,
+ false);
+ }
+ for (idx = 0; idx < sp->tcount && sav == NULL && error == EJUSTRETURN;
+ idx++) {
+ if (sp->req[idx]->saidx.dst.sa.sa_len == 0)
+ sav = ipsec4_allocsa(ifp, m, ip1, sp, &idx, &error,
+ false);
+ }
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.
+ * No request applies. ipsec4_process_packet() finds the
+ * same and sends the packet without IPsec processing.
*/
if (error == EJUSTRETURN)
return (0);
@@ -561,7 +580,7 @@
static struct secasvar *
ipsec6_allocsa(struct ifnet *ifp, struct mbuf *m, struct secpolicy *sp,
- u_int *pidx, int *error)
+ u_int *pidx, int *error, bool skip)
{
struct secasindex *saidx, tmpsaidx;
struct ipsecrequest *isr;
@@ -633,9 +652,10 @@
* We have no SA and policy that doesn't require
* this IPsec transform, thus we can continue w/o
* IPsec processing, i.e. return EJUSTRETURN.
- * But first check if there is some bundled transform.
+ * But first check if there is some bundled transform,
+ * unless the caller looks at this request alone.
*/
- if (sp->tcount > ++(*pidx))
+ if (skip && sp->tcount > ++(*pidx))
goto next;
*error = EJUSTRETURN;
}
@@ -661,7 +681,7 @@
IPSEC_ASSERT(idx < sp->tcount, ("Wrong IPsec request index %d", idx));
- sav = ipsec6_allocsa(ifp, m, sp, &idx, &error);
+ sav = ipsec6_allocsa(ifp, m, sp, &idx, &error, true);
if (sav == NULL) {
if (error == EJUSTRETURN) { /* No IPsec required */
(void)ipsec_accel_output(ifp, m, inp, sp, NULL,
@@ -783,7 +803,7 @@
{
struct secasvar *sav;
size_t hlen, pmtu;
- uint32_t idx;
+ uint32_t i, idx;
int error;
/*
@@ -795,16 +815,32 @@
if (!forwarding)
return (0);
- idx = sp->tcount - 1;
- sav = ipsec6_allocsa(ifp, m, sp, &idx, &error);
+ /*
+ * The outer destination is that of the last request that has both
+ * addresses of its own, as every tunnel request does, and an SA.
+ * One at level use without an SA is skipped, so the requests before
+ * it may apply. The SA of a request without addresses depends on
+ * the header that the requests before it leave, so look those up,
+ * with the addresses of the packet, only when no request with
+ * addresses applies.
+ */
+ sav = NULL;
+ error = EJUSTRETURN;
+ for (i = sp->tcount; i > 0 && sav == NULL && error == EJUSTRETURN;
+ i--) {
+ idx = i - 1;
+ if (sp->req[idx]->saidx.dst.sa.sa_len != 0)
+ sav = ipsec6_allocsa(ifp, m, sp, &idx, &error, false);
+ }
+ for (idx = 0; idx < sp->tcount && sav == NULL && error == EJUSTRETURN;
+ idx++) {
+ if (sp->req[idx]->saidx.dst.sa.sa_len == 0)
+ sav = ipsec6_allocsa(ifp, m, sp, &idx, &error, false);
+ }
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.
+ * No request applies. ipsec6_process_packet() finds the
+ * same and sends the packet without IPsec processing.
*/
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,25 +2,56 @@
. $(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.
+# "nested": as "require", with a second tunnel request, to gw_c, at level use
+# between the two, and no SA for it: the AH request is applied after the
+# tunnel to gw_b, and ipsecB must have received the pings with AH.
# 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
+ gw_a=198.51.100.2; gw_b=198.51.100.6; gw_c=198.51.100.1
else
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
+ gw_a=2001:db8:23::2; gw_b=2001:db8:34::2; gw_c=2001:db8:23::3
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}\";"
+ elif [ ${kind} = nested ]; then
+ pol_out="esp/tunnel/${gw_a}-${gw_b}/require esp/tunnel/${gw_a}-${gw_c}/use ah/transport//require"
+ pol_in="esp/tunnel/${gw_a}-${gw_b}/require"
+ sas="add ${gw_a} ${gw_b} esp 0x1000 -m tunnel -E aes-gcm-16 \"${KEY}\";
+add ${gw_a} ${gw_b} ah 0x1002 -m transport -A hmac-sha2-256 \"${AKEY}\";"
+ 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 +64,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|nested)
+ 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 +103,7 @@
}
use_v4_body()
{
- bundle_use 4
+ bundle_ping use 4
}
use_v4_cleanup()
{
@@ -72,7 +118,7 @@
}
use_v4_dfbit_body()
{
- bundle_use 4 1
+ bundle_ping use 4 1
}
use_v4_dfbit_cleanup()
{
@@ -87,16 +133,248 @@
}
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
+}
+
+atf_test_case "nested_v4" "cleanup"
+nested_v4_head()
+{
+ atf_set descr 'A transport request after a skipped tunnel request is applied (IPv4)'
+ atf_set require.user root
+}
+nested_v4_body()
+{
+ bundle_ping nested 4
+}
+nested_v4_cleanup()
+{
+ ist_cleanup
+}
+
+atf_test_case "nested_v4_dfbit" "cleanup"
+nested_v4_dfbit_head()
+{
+ atf_set descr 'A transport request after a skipped tunnel request is applied (IPv4, PMTU check)'
+ atf_set require.user root
+}
+nested_v4_dfbit_body()
+{
+ bundle_ping nested 4 1
+}
+nested_v4_dfbit_cleanup()
+{
+ ist_cleanup
+}
+
+atf_test_case "nested_v6" "cleanup"
+nested_v6_head()
+{
+ atf_set descr 'A transport request after a skipped tunnel request is applied (IPv6)'
+ atf_set require.user root
+}
+nested_v6_body()
+{
+ bundle_ping nested 6
+}
+nested_v6_cleanup()
+{
+ ist_cleanup
+}
+
+# The PMTU check takes the path MTU to the tunnel endpoint, whether the
+# requests after the tunnel to it apply or not. On ipsecA the route to gw_b
+# has an MTU of 1300, while the other routes keep 1500, so a 1300-byte ping
+# with DF cannot go through the tunnel, and ipsecA must report it to hostA.
+# For the "use" bundle the ping would fit under 1500, as far as the check
+# estimates, so the check must take the path MTU to gw_b; for the "nested"
+# one it must find the tunnel to gw_b behind the skipped one. Without -u,
+# ping -6 fragments to the minimum IPv6 MTU.
+needfrag_check()
+{
+ bundle_setup "$@"
+ if [ ${af} = 4 ]; then
+ atf_check -s exit:0 -o ignore jexec ipsecA \
+ route add -host ${gw_b} 198.51.100.1 -mtu 1300
+ atf_check -s exit:2 -o match:"frag needed and DF set" \
+ jexec hostA ping -c 1 -t 2 -D -s 1272 ${target}
+ else
+ atf_check -s exit:0 -o ignore jexec ipsecA \
+ route -6 add -host ${gw_b} 2001:db8:23::3 -mtu 1300
+ atf_check -s exit:2 -o match:"Packet too big" \
+ jexec hostA ping -6 -c 1 -t 2 -u -v -s 1252 ${target}
+ fi
+}
+
+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()
+{
+ needfrag_check use 4 1
+}
+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()
+{
+ needfrag_check use 6
+}
+needfrag_v6_cleanup()
+{
+ ist_cleanup
+}
+
+atf_test_case "needfrag_nested_v4" "cleanup"
+needfrag_nested_v4_head()
+{
+ atf_set descr 'The PMTU check finds the tunnel request behind a skipped one (IPv4)'
+ atf_set require.user root
+}
+needfrag_nested_v4_body()
+{
+ needfrag_check nested 4 1
+}
+needfrag_nested_v4_cleanup()
+{
+ ist_cleanup
+}
+
+atf_test_case "needfrag_nested_v6" "cleanup"
+needfrag_nested_v6_head()
+{
+ atf_set descr 'The PMTU check finds the tunnel request behind a skipped one (IPv6)'
+ atf_set require.user root
+}
+needfrag_nested_v6_body()
+{
+ needfrag_check nested 6
+}
+needfrag_nested_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 "nested_v4"
+ atf_add_test_case "nested_v4_dfbit"
+ atf_add_test_case "nested_v6"
+ atf_add_test_case "needfrag_v4"
+ atf_add_test_case "needfrag_v6"
+ atf_add_test_case "needfrag_nested_v4"
+ atf_add_test_case "needfrag_nested_v6"
}

File Metadata

Mime Type
text/plain
Expires
Sun, Nov 29, 5:14 PM (7 h, 49 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
42088254
Default Alt Text
D62061.1795972464.diff (15 KB)

Event Timeline