Re: [PATCH net-next v2] selftests: net: Add kernel selftest for RFC 4884

Willem de Bruijn
2026-01-21T14:41:08Z

Danielle Ratson wrote:
> RFC 4884 extended certain ICMP messages with a length attribute that
> encodes the length of the "original datagram" field. This is needed so
> that new information could be appended to these messages without
> applications thinking that it is part of the "original datagram" field.
>
> In version 5.9, the kernel was extended with two new socket options
> (SOL_IP/IP_RECVERR_4884 and SOL_IPV6/IPV6_RECVERR_RFC4884) that allow
> user space to retrieve this length which is basically the offset to the
> ICMP Extension Structure at the end of the ICMP message. This is
> required by user space applications that need to parse the information
> contained in the ICMP Extension Structure. For example, the RFC 5837
> extension for tracepath.
>
> Add a selftest that verifies correct handling of the RFC 4884 length
> field for both IPv4 and IPv6, with and without extension structures,
> and validates that malformed extensions are correctly reported as invalid.
>
> For each address family, the test creates:
> - a raw socket used to send locally crafted ICMP error packets to the
> loopback address, and
> - a datagram socket used to receive the encapsulated original datagram
> and associated error metadata from the kernel error queue.
>
> ICMP packets are constructed entirely in user space rather than relying
> on kernel-generated errors. This allows the test to exercise invalid
> scenarios (such as corrupted checksums and incorrect length fields) and
> verify that the SO_EE_RFC4884_FLAG_INVALID flag is set as expected.
>
> Output Example:
>
> $ ./icmp_rfc4884
> Starting 18 tests from 18 test cases.
> RUN rfc4884.ipv4_ext_small_payload.rfc4884 ...
> OK rfc4884.ipv4_ext_small_payload.rfc4884
> ok 1 rfc4884.ipv4_ext_small_payload.rfc4884
> RUN rfc4884.ipv4_ext.rfc4884 ...
> OK rfc4884.ipv4_ext.rfc4884
> ok 2 rfc4884.ipv4_ext.rfc4884
> RUN rfc4884.ipv4_ext_large_payload.rfc4884 ...
> OK rfc4884.ipv4_ext_large_payload.rfc4884
> ok 3 rfc4884.ipv4_ext_large_payload.rfc4884
> RUN rfc4884.ipv4_no_ext_small_payload.rfc4884 ...
> OK rfc4884.ipv4_no_ext_small_payload.rfc4884
> ok 4 rfc4884.ipv4_no_ext_small_payload.rfc4884
> RUN rfc4884.ipv4_no_ext_min_payload.rfc4884 ...
> OK rfc4884.ipv4_no_ext_min_payload.rfc4884
> ok 5 rfc4884.ipv4_no_ext_min_payload.rfc4884
> RUN rfc4884.ipv4_no_ext_large_payload.rfc4884 ...
> OK rfc4884.ipv4_no_ext_large_payload.rfc4884
> ok 6 rfc4884.ipv4_no_ext_large_payload.rfc4884
> RUN rfc4884.ipv4_invalid_ext_checksum.rfc4884 ...
> OK rfc4884.ipv4_invalid_ext_checksum.rfc4884
> ok 7 rfc4884.ipv4_invalid_ext_checksum.rfc4884
> RUN rfc4884.ipv4_invalid_ext_length_small.rfc4884 ...
> OK rfc4884.ipv4_invalid_ext_length_small.rfc4884
> ok 8 rfc4884.ipv4_invalid_ext_length_small.rfc4884
> RUN rfc4884.ipv4_invalid_ext_length_large.rfc4884 ...
> OK rfc4884.ipv4_invalid_ext_length_large.rfc4884
> ok 9 rfc4884.ipv4_invalid_ext_length_large.rfc4884
> RUN rfc4884.ipv6_ext_small_payload.rfc4884 ...
> OK rfc4884.ipv6_ext_small_payload.rfc4884
> ok 10 rfc4884.ipv6_ext_small_payload.rfc4884
> RUN rfc4884.ipv6_ext.rfc4884 ...
> OK rfc4884.ipv6_ext.rfc4884
> ok 11 rfc4884.ipv6_ext.rfc4884
> RUN rfc4884.ipv6_ext_large_payload.rfc4884 ...
> OK rfc4884.ipv6_ext_large_payload.rfc4884
> ok 12 rfc4884.ipv6_ext_large_payload.rfc4884
> RUN rfc4884.ipv6_no_ext_small_payload.rfc4884 ...
> OK rfc4884.ipv6_no_ext_small_payload.rfc4884
> ok 13 rfc4884.ipv6_no_ext_small_payload.rfc4884
> RUN rfc4884.ipv6_no_ext_min_payload.rfc4884 ...
> OK rfc4884.ipv6_no_ext_min_payload.rfc4884
> ok 14 rfc4884.ipv6_no_ext_min_payload.rfc4884
> RUN rfc4884.ipv6_no_ext_large_payload.rfc4884 ...
> OK rfc4884.ipv6_no_ext_large_payload.rfc4884
> ok 15 rfc4884.ipv6_no_ext_large_payload.rfc4884
> RUN rfc4884.ipv6_invalid_ext_checksum.rfc4884 ...
> OK rfc4884.ipv6_invalid_ext_checksum.rfc4884
> ok 16 rfc4884.ipv6_invalid_ext_checksum.rfc4884
> RUN rfc4884.ipv6_invalid_ext_length_small.rfc4884 ...
> OK rfc4884.ipv6_invalid_ext_length_small.rfc4884
> ok 17 rfc4884.ipv6_invalid_ext_length_small.rfc4884
> RUN rfc4884.ipv6_invalid_ext_length_large.rfc4884 ...
> OK rfc4884.ipv6_invalid_ext_length_large.rfc4884
> ok 18 rfc4884.ipv6_invalid_ext_length_large.rfc4884
> PASSED: 18 / 18 tests passed.
> Totals: pass:18 fail:0 xfail:0 xpass:0 skip:0 error:0
>
> Signed-off-by: Danielle Ratson <danieller@nvidia.com>
> Reviewed-by: Ido Schimmel <idosch@nvidia.com>

Reviewed-by: Willem de Bruijn <willemb@google.com>

Thanks!