[nat64] handle IPv4 options and discard source route options (#12818)

OpenThread's NAT64 translator assumed a fixed IPv4 header length of 20
bytes, which caused incorrect parsing and translation of IPv4 packets
containing options (IHL > 5).

Specifically, if an IPv4 packet with options was received:
1. The transport header was read from a fixed 20-byte offset, leading
   to corruption of transport layer fields (e.g., UDP ports).
2. Only 20 bytes were removed from the message, leaving the IPv4
   options at the beginning of the translated IPv6 payload.
3. Mandatory security checks for source route options were bypassed.

This commit fixes these issues by:
- Updating Ip4::Header to validate IHL and provide the actual header
  length.
- Using the actual header length for transport header parsing and
  IPv4 header removal in the NAT64 translator.
- Implementing a check to discard packets with LSRR or SSRR options
  as required by RFC 7915.

A new Nexus regression test is added to verify the fix.
This commit is contained in:
Jonathan Hui
2026-04-01 20:24:42 -05:00
committed by GitHub
parent 42b653a18c
commit 26a882dabc
5 changed files with 297 additions and 8 deletions
+2 -1
View File
@@ -78,8 +78,9 @@ void TestIp4Header(void)
header.Clear();
header.InitVersionIhl();
header.SetTotalLength(header.GetHeaderLength());
VerifyOrQuit(header.IsValid());
VerifyOrQuit(header.GetTotalLength() == 0);
VerifyOrQuit(header.GetTotalLength() == sizeof(Header));
VerifyOrQuit(header.GetProtocol() == 0);
VerifyOrQuit(header.GetTtl() == 0);
VerifyOrQuit(header.GetSource().mFields.m32 == 0);