|WARNING| [v4] examples/l3fwd: fix RFC 1812 checks

dpdklab at iol.unh.edu dpdklab at iol.unh.edu
Sat Oct 24 13:53:30 CEST 2026


Test-Label: ai-code-review
Test-Status: WARNING
https://dpdk.org/patch/172033

_AI Code Review_

=== Patch Review: series.patch (via Claude) ===
Review date: 2026-10-24

## Code Review: examples/l3fwd: fix RFC 1812 checks

### ERRORS

**1. Incorrect byte order in Link Layer length check**

Line 215:
```c
if (link_len < rte_cpu_to_be_16(pkt->total_length))
```

The `link_len` parameter is in host byte order (it comes from `m->pkt_len` which is host order).
The comparison converts `pkt->total_length` from little-endian to big-endian,
then compares against host-order `link_len`.
On little-endian systems this produces the wrong result.

**Fix:**
```c
if (link_len < rte_be_to_cpu_16(pkt->total_length))
```

---

### WARNINGS

**1. Inconsistent byte order conversion pattern**

Line 207:
```c
if (rte_cpu_to_be_16(pkt->total_length) < rte_ipv4_hdr_len(pkt))
```

This converts `total_length` from little-endian to big-endian for comparison against `rte_ipv4_hdr_len()` return value (host order).
The operation is backwards: should convert from big-endian (network order in packet) to host order.

The code happens to work on little-endian systems because `rte_cpu_to_be_16` and `rte_be_to_cpu_16` are the same operation (byte swap),
but it is semantically incorrect and will produce wrong results on big-endian systems.

**Fix:**
```c
if (rte_be_to_cpu_16(pkt->total_length) < rte_ipv4_hdr_len(pkt))
```

Note: Line 198 has the same pattern in existing code (not introduced by this patch, so pre-existing),
but should also be fixed for consistency:
```c
if (rte_be_to_cpu_16(pkt->total_length) > link_len)
```

---

### INFO

**1. Pre-existing byte order issue (not introduced by this patch)**

Line 198 (context, not modified by patch):
```c
if (rte_cpu_to_be_16(pkt->total_length) > link_len)
```

Uses the same incorrect `rte_cpu_to_be_16` pattern as the new code.
Should be `rte_be_to_cpu_16(pkt->total_length)`.
This is pre-existing and not introduced by this patch.

---

### SUMMARY

The patch fixes real bugs in RFC 1812 validation and adds useful checks,
but introduces byte-order conversion errors that will cause incorrect behavior on big-endian systems
and may produce wrong results even on little-endian depending on packet contents.

Review-Result: ERROR


More information about the test-report mailing list