patch 'examples/l3fwd: fix RFC 1812 checks' has been queued to stable release 24.11.9
luca.boccassi at gmail.com
luca.boccassi at gmail.com
Fri Nov 20 21:29:31 CET 2026
Hi,
FYI, your patch has been queued to stable release 24.11.9
Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet.
It will be pushed if I get no objections before 11/22/26. So please
shout if anyone has objections.
Also note that after the patch there's a diff of the upstream commit vs the
patch applied to the branch. This will indicate if there was any rebasing
needed to apply to the stable branch. If there were code changes for rebasing
(ie: not only metadata diffs), please double check that the rebase was
correctly done.
Queued patches are on a temporary branch at:
https://github.com/bluca/dpdk-stable
This queued commit can be viewed at:
https://github.com/bluca/dpdk-stable/commit/19f3cff26280d7164b418562c75e58d9cf9554e1
Thanks.
Luca Boccassi
---
>From 19f3cff26280d7164b418562c75e58d9cf9554e1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Morten=20Br=C3=B8rup?= <mb at smartsharesystems.com>
Date: Fri, 13 Nov 2026 20:32:36 +0000
Subject: [PATCH] examples/l3fwd: fix RFC 1812 checks
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
[ upstream commit e97135a1ed81dca1dcd18ca37ee304d27a487fa6 ]
Five bug fixes and two enhancements.
1.
If the PMD didn't check the IP header checksum, the
offload value is RTE_MBUF_F_RX_IP_CKSUM_UNKNOWN,
not RTE_MBUF_F_RX_IP_CKSUM_NONE.
CKSUM_NONE means that the packet integrity is good, but the checksum
field has not been set.
CKSUM_UNKNOWN means that the checksum has not been investigated.
(BTW, no PMD currently sets RTE_MBUF_F_RX_IP_CKSUM_NONE, so this part
of the check was effectively dead code.)
Fixed this by processing all four RTE_MBUF_F_RX_IP_CKSUM enum values.
All four values may not actually occur in this application,
but it serves an educational purpose.
2.
When checking the checksum, the checksum field in the packet was zeroed
for calculating the checksum.
If the checksum was correct, the zero value remained in the packet.
Fixed this by simply calculating the checksum of the packet without
modifying the checksum field.
If the calculated checksum is zero, the checksum is correct.
3.
When checking the Link Layer length of an IP packet, the length did
not omit the length of the preceding Layer 2 headers.
Fixed this by subtracting the Ethernet header length when calling the
IPv4 validation function.
4.
In the 5th bullet check,
"5. The IP total length field must be large enough to hold the IP
datagram header, whose length is specified in the IP header length
field."
the comparison did not use the IP header length field, but the size
of the IP header structure, which did not account for IP header
options.
Fixed this by using the IP header length field instead of the
size of the structure.
5.
Calculating the checksum in the 2nd bullet check uses rte_ipv4_cksum(),
which gets its length from the IP header length field.
If the IP header length exceeded the Link Layer length, it would read
out of bounds.
Fixed this by moving the 2nd bullet check down after the length checks,
and adding a comment describing the reason for its position.
6.
Added the additional check recommended in RFC 1812 section 5.2.2,
verifying that the packet length reported by the Link Layer is at least
as large as the IP total length recorded in the packet's IP header.
7.
Different negative values are returned on failure, but they are not used
by any callers of this function.
This is unnecessary, and may be confusing.
Changed all negative return values to -1.
Fixes: 4b01cabfb09b ("examples/l3fwd: add option to relax Rx offload")
Fixes: af75078fece3 ("first public release")
Signed-off-by: Morten Brørup <mb at smartsharesystems.com>
---
examples/l3fwd/l3fwd.h | 50 ++++++++++++++++++++++++++------------
examples/l3fwd/l3fwd_em.h | 3 ++-
examples/l3fwd/l3fwd_lpm.h | 3 ++-
3 files changed, 39 insertions(+), 17 deletions(-)
diff --git a/examples/l3fwd/l3fwd.h b/examples/l3fwd/l3fwd.h
index 471e3b488f..74b3546382 100644
--- a/examples/l3fwd/l3fwd.h
+++ b/examples/l3fwd/l3fwd.h
@@ -169,38 +169,58 @@ is_valid_ipv4_pkt(struct rte_ipv4_hdr *pkt, uint32_t link_len, uint64_t ol_flags
if (link_len < sizeof(struct rte_ipv4_hdr))
return -1;
- /* 2. The IP checksum must be correct. */
- /* if this is not checked in H/W, check it. */
- if ((ol_flags & RTE_MBUF_F_RX_IP_CKSUM_MASK) == RTE_MBUF_F_RX_IP_CKSUM_NONE) {
- uint16_t actual_cksum, expected_cksum;
- actual_cksum = pkt->hdr_checksum;
- pkt->hdr_checksum = 0;
- expected_cksum = rte_ipv4_cksum(pkt);
- if (actual_cksum != expected_cksum)
- return -2;
- }
-
/*
* 3. The IP version number must be 4. If the version number is not 4
* then the packet may be another version of IP, such as IPng or
* ST-II.
*/
if (((pkt->version_ihl) >> 4) != 4)
- return -3;
+ return -1;
/*
* 4. The IP header length field must be large enough to hold the
* minimum length legal IP datagram (20 bytes = 5 words).
*/
if ((pkt->version_ihl & 0xf) < 5)
- return -4;
+ return -1;
/*
* 5. The IP total length field must be large enough to hold the IP
* datagram header, whose length is specified in the IP header length
* field.
*/
- if (rte_cpu_to_be_16(pkt->total_length) < sizeof(struct rte_ipv4_hdr))
- return -5;
+ if (rte_be_to_cpu_16(pkt->total_length) < rte_ipv4_hdr_len(pkt))
+ return -1;
+
+ /*
+ * Additionally, the router SHOULD verify that the packet length
+ * reported by the Link Layer is at least as large as the IP total
+ * length recorded in the packet's IP header.
+ */
+ if (link_len < rte_be_to_cpu_16(pkt->total_length))
+ return -1;
+
+ /*
+ * 2. The IP checksum must be correct.
+ * Note: This check is performed after the length checks,
+ * to prevent rte_ipv4_cksum() from reading out of bounds
+ * if the IP header length exceeds the packet length.
+ */
+ switch (ol_flags & RTE_MBUF_F_RX_IP_CKSUM_MASK) {
+ case RTE_MBUF_F_RX_IP_CKSUM_UNKNOWN:
+ /* Not checked in H/W; check it. */
+ if (rte_ipv4_cksum(pkt) != 0)
+ return -1;
+ break;
+ case RTE_MBUF_F_RX_IP_CKSUM_GOOD:
+ break;
+ case RTE_MBUF_F_RX_IP_CKSUM_BAD:
+ return -1;
+ case RTE_MBUF_F_RX_IP_CKSUM_NONE:
+ /* Packet integrity known good, checksum field unset; set it. */
+ pkt->hdr_checksum = 0;
+ pkt->hdr_checksum = rte_ipv4_cksum(pkt);
+ break;
+ }
return 0;
}
diff --git a/examples/l3fwd/l3fwd_em.h b/examples/l3fwd/l3fwd_em.h
index 1fee2e2e6c..34801fba2b 100644
--- a/examples/l3fwd/l3fwd_em.h
+++ b/examples/l3fwd/l3fwd_em.h
@@ -20,7 +20,8 @@ l3fwd_em_handle_ipv4(struct rte_mbuf *m, uint16_t portid,
#ifdef DO_RFC_1812_CHECKS
/* Check to make sure the packet is valid (RFC1812) */
- if (is_valid_ipv4_pkt(ipv4_hdr, m->pkt_len, m->ol_flags) < 0) {
+ if (is_valid_ipv4_pkt(ipv4_hdr, m->pkt_len - sizeof(struct rte_ether_hdr),
+ m->ol_flags) < 0) {
rte_pktmbuf_free(m);
return BAD_PORT;
}
diff --git a/examples/l3fwd/l3fwd_lpm.h b/examples/l3fwd/l3fwd_lpm.h
index 4ee61e8d88..1731ebb2a8 100644
--- a/examples/l3fwd/l3fwd_lpm.h
+++ b/examples/l3fwd/l3fwd_lpm.h
@@ -22,7 +22,8 @@ l3fwd_lpm_simple_forward(struct rte_mbuf *m, uint16_t portid,
#ifdef DO_RFC_1812_CHECKS
/* Check to make sure the packet is valid (RFC1812) */
- if (is_valid_ipv4_pkt(ipv4_hdr, m->pkt_len, m->ol_flags) < 0) {
+ if (is_valid_ipv4_pkt(ipv4_hdr, m->pkt_len - sizeof(struct rte_ether_hdr),
+ m->ol_flags) < 0) {
rte_pktmbuf_free(m);
return;
}
--
2.47.3
---
Diff of the applied patch vs upstream commit (please double-check if non-empty:
---
--- - 2026-11-20 20:29:05.301149945 +0000
+++ 0002-examples-l3fwd-fix-RFC-1812-checks.patch 2026-11-20 20:29:05.168111711 +0000
@@ -1 +1 @@
-From e97135a1ed81dca1dcd18ca37ee304d27a487fa6 Mon Sep 17 00:00:00 2001
+From 19f3cff26280d7164b418562c75e58d9cf9554e1 Mon Sep 17 00:00:00 2001
@@ -8,0 +9,2 @@
+[ upstream commit e97135a1ed81dca1dcd18ca37ee304d27a487fa6 ]
+
@@ -75 +76,0 @@
-Cc: stable at dpdk.org
@@ -85 +86 @@
-index 20c457ee7f0..300b400a72a 100644
+index 471e3b488f..74b3546382 100644
@@ -163 +164 @@
-index 1fee2e2e6c9..34801fba2b7 100644
+index 1fee2e2e6c..34801fba2b 100644
@@ -177 +178 @@
-index 4ee61e8d889..1731ebb2a83 100644
+index 4ee61e8d88..1731ebb2a8 100644
More information about the stable
mailing list