git: 3cd5f1b307ad - main - netipsec: Process a nested IPsec header on IPv6 input
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 23 Nov 2026 14:38:02 UTC
The branch main has been updated by rcm:
URL: https://cgit.FreeBSD.org/src/commit/?id=3cd5f1b307ad497d409e1a98bddf28702b579a47
commit 3cd5f1b307ad497d409e1a98bddf28702b579a47
Author: R. Christian McDonald <rcm@FreeBSD.org>
AuthorDate: 2026-11-23 14:36:01 +0000
Commit: R. Christian McDonald <rcm@FreeBSD.org>
CommitDate: 2026-11-23 14:37:57 +0000
netipsec: Process a nested IPsec header on IPv6 input
After a transport mode SA has processed an inbound IPv6 packet,
ipsec6_common_input_cb() walks the remaining header chain itself and
calls ip6_protox[] for each next header. AH, ESP and IPComp have had no
entry in ip6_protox[] since the projects/ipsec merge; ip6_input() reaches
them through IPSEC_INPUT() instead. The callback did not, so when the
next header was another IPsec header the packet went to rip6_input() and
was never decapsulated. The receiving side of a bundle such as ESP
beneath a transport mode AH, or ESP with IPComp, did not work over IPv6.
Hand such a header back to ipsec_common_input() from the loop. Look up
the offset of the preceding next header field with ip6_get_prevhdr(),
since extension headers may sit between the two IPsec headers.
The bundle cases of the flowlabel test had to ignore the result of ping
because of this. Have them check it, and give the second target, which
no host owned, an address on hostB.
Reported by: llm-postcr
Reviewed by: ae, kib
Fixes: fcf596178b5f ("Merge projects/ipsec into head/.")
MFC after: 2 weeks
Sponsored by: Rubicon Communications, LLC ("Netgate")
Differential Revision: https://reviews.freebsd.org/D61805
---
sys/netipsec/ipsec_input.c | 13 ++++++++++++-
tests/sys/netipsec/tunnel/flowlabel.sh | 18 +++++++++---------
2 files changed, 21 insertions(+), 10 deletions(-)
diff --git a/sys/netipsec/ipsec_input.c b/sys/netipsec/ipsec_input.c
index e54f65a50f83..43e01a3e9895 100644
--- a/sys/netipsec/ipsec_input.c
+++ b/sys/netipsec/ipsec_input.c
@@ -787,11 +787,22 @@ ipsec6_common_input_cb(struct mbuf *m, struct secasvar *sav, int skip,
error = EINVAL;
goto bad;
}
+ /*
+ * AH, ESP and IPComp are not in ip6_protox[]; as in
+ * ip6_input(), a further IPsec header of a bundle has to be
+ * handed back to IPsec here.
+ */
+ if (nxt == IPPROTO_AH || nxt == IPPROTO_ESP ||
+ nxt == IPPROTO_IPCOMP) {
+ error = ipsec_common_input(m, skip,
+ ip6_get_prevhdr(m, skip), AF_INET6, nxt);
+ break;
+ }
nxt = ip6_protox[nxt](&m, &skip, nxt);
}
NET_EPOCH_EXIT(et);
key_freesav(&sav);
- return (0);
+ return (error);
bad:
NET_EPOCH_EXIT(et);
ipsec_sahtree_runlock(sahtree_tracker);
diff --git a/tests/sys/netipsec/tunnel/flowlabel.sh b/tests/sys/netipsec/tunnel/flowlabel.sh
index 7afd1c8cc21e..349da885ae90 100755
--- a/tests/sys/netipsec/tunnel/flowlabel.sh
+++ b/tests/sys/netipsec/tunnel/flowlabel.sh
@@ -34,9 +34,7 @@ fl_setkey()
# fl_run COUNT TARGET...: ping each target from hostA while capturing COUNT
# packets that match fl_filter on ipsecA's public interface, by default ESP
-# or AH in both directions. A test that expects no replies sets
-# fl_ping_status=ignore.
-fl_ping_status=exit:0
+# or AH in both directions.
fl_filter="ip6 and (esp or ah)"
fl_run()
{
@@ -57,7 +55,7 @@ fl_run()
i=$((i + 1))
done
for target in "$@"; do
- atf_check -s ${fl_ping_status} -o ignore \
+ atf_check -s exit:0 -o ignore \
jexec hostA ping -c 5 -i 0.2 ${target}
done
timeout 5 sh -c "while kill -0 ${tdpid} 2>/dev/null; do sleep 0.2; done"
@@ -202,14 +200,17 @@ sa_flowid_off_cleanup()
# mode "any"). The outer header must carry the label of the AH SA on every
# packet, not that of the tunnel SA which built it. AH leaves the ESP
# header readable, so the capture shows which tunnel SA each packet took.
-# Only the outbound packets carry AH, so only they are captured: when this
-# was written, ipsec6_common_input_cb() handed the ESP header beneath a
-# transport mode AH to the raw IPv6 input, so ipsecB did not decapsulate
-# the packets and did not reply.
+# Only the outbound packets carry AH, so only they are captured. The
+# replies show that ipsecB removed both headers of the bundle.
fl_bundle()
{
ahmode=${1:+-m $1}
fl_lab 4
+ # A second address on hostB, reached by the second policy.
+ atf_check -s exit:0 jexec hostB \
+ ifconfig ${epair_LAN_B}a alias 203.0.113.129/32
+ atf_check -s exit:0 -o ignore jexec ipsecB \
+ route add 203.0.113.129/32 203.0.113.1
(
printf "flush;\nspdflush;\n"
printf "spdadd 192.0.2.0/24 203.0.113.0/25 any -P out ipsec esp/tunnel/${GW_A}-${GW_B}/unique:1 ah/transport//require;\n"
@@ -231,7 +232,6 @@ fl_bundle()
printf "add ${GW_B} ${GW_A} esp 0x1003 -m tunnel -E aes-gcm-16 \"${KEY}\";\n"
) > ${TMPDIR}/ipsec.ipsecB.conf
atf_check -s exit:0 -o ignore jexec ipsecB setkey -f ${TMPDIR}/ipsec.ipsecB.conf
- fl_ping_status=ignore
fl_filter="ip6 and ah"
fl_run 10 203.0.113.1 203.0.113.129
fl_check 0x1002 828ed