Commit Graph

4 Commits

Author SHA1 Message Date
Jonathan Hui 26a882dabc [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.
2026-04-01 20:24:42 -05:00
Abtin Keshavarzian d2d2f0092f [ipv4] smaller improvements in Address, Cidr, and Header (#11863)
This commit introduces several cleanups and smaller improvements to
the IPv4 types.

- Optimizes `Cidr::ToString(StringWriter&)` by writing the address
  directly to the provided writer, avoiding the allocation of a
  temporary `String` object.
- Moves the IPv4 header field offset constants from the public
  `ip4_types.hpp` header into the unit test file, as this was their
  only place of use. This cleans up the `Ip4::Header` public API.
- Replaces hardcoded values for address and string sizes with the
  corresponding `OT_IP4_*` definitions for consistency.
- Corrects the format specifier in `Address::ToString()` from `%d` to
  `%u` to properly print unsigned octet values.
2025-08-26 19:52:33 -07:00
Abtin Keshavarzian 6e7ed5cb55 [encoding] avoid the use of using for Big/LittleEndian functions (#9621)
This commit refactors the code to eliminate the use of `using` for
`BigEndian` or `LittleEndian` functions like `HostSwap` and `ReadUint`.
As these functions are frequently used in header files, using the
direct namespace enhances code safety by mitigating potential conflicts
arising from the order of included headers in the absence of explicit
`using` declarations. Generally, avoiding the `using` keyword in headers
is considered a recommended practice.

Additionally, this commit removes the `Encoding` namespace to shorten
the full function names.
2023-11-19 21:19:13 -08:00
Song GUO 03c9b9389d [nat64] add functions for processing IPv4 packets (#7824)
With NAT64, we need to handle the IPv4 packets inside the border
router functions in OpenThread core.

This commit introduces a few new classes for NAT64:
- Add `Ip4::Cidr` (for specifying CIDR block of translated packets)
- Updated Ip4 address format -- use a union of (m8[4], m16[2], m32)
  instead of 4 bytes.
- Extend `Checksum` for supporting ICMP in Ip4 (and TCP4 / UDP4) and
  IPv4 header.
2022-07-15 10:54:20 -07:00