Skip to content

Add types and macros for ICMPv6 filtering#5225

Open
Skyb0rg007 wants to merge 1 commit into
rust-lang:mainfrom
Skyb0rg007:icmpv6-filters-minimal
Open

Add types and macros for ICMPv6 filtering#5225
Skyb0rg007 wants to merge 1 commit into
rust-lang:mainfrom
Skyb0rg007:icmpv6-filters-minimal

Conversation

@Skyb0rg007

@Skyb0rg007 Skyb0rg007 commented Jun 27, 2026

Copy link
Copy Markdown

Description

This commit adds the icmp6_filter type and the corresponding ICMP6_FILTER macros.
The API is defined in RFC 2292; I split-off this code from #4954 because the testing code here is more substantial.

These functions are tested in a similar manner to the CMSG macros, as the implementation differs between Linux and BSDs.

Sources

https://github.com/bminor/glibc/blob/04e750e75b73957cf1c791535a3f4319534a52fc/inet/netinet/icmp6.h
https://github.com/kraj/musl/blob/kraj/master/include/netinet/icmp6.h
https://github.com/freebsd/freebsd-src/blob/9ae367d11de8abbdf53884836c9ba30908c5c8db/sys/netinet/icmp6.h
https://github.com/apple-oss-distributions/xnu/blob/main/bsd/netinet/icmp6.h

Also in the RFC: https://datatracker.ietf.org/doc/html/rfc2292#section-3.2

Checklist

  • Relevant tests in libc-test/semver have been updated
  • No placeholder or unstable values like *LAST or *MAX are
    included (see #3131)
  • Tested locally (cd libc-test && cargo test --target mytarget);
    especially relevant for platforms that may not be checked in CI

@rustbot label +stable-nominated

@rustbot rustbot added S-waiting-on-review stable-nominated This PR should be considered for cherry-pick to libc's stable release branch labels Jun 27, 2026
@Skyb0rg007 Skyb0rg007 force-pushed the icmpv6-filters-minimal branch 11 times, most recently from efdab70 to 5d1ba9f Compare June 27, 2026 21:16
@rustbot

rustbot commented Jun 27, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred in a solarish module

cc @jclulow, @pfmooney

@Skyb0rg007 Skyb0rg007 force-pushed the icmpv6-filters-minimal branch from 5d1ba9f to 8bbb220 Compare June 27, 2026 21:18
@Skyb0rg007

Copy link
Copy Markdown
Author

Sorry for spamming the CI; I couldn't get it to work on my fork.

Anyways, I'm mostly confident with this PR. The missing parts are:

  1. A way to initialize icmp6_filter. Right now the only field is private, so you need to use an unsafe method like std::mem::zeroed. I don't think this is a big deal.
  2. The FreeBSD's netinet/icmp6.h header uses u_int32_t types, which I couldn't figure out how to properly include. The test code therefore includes the typedefs, which is somewhat inelegant.

Some notes on the implementation:

  • The ICMP_FILTER functions are marked as safe. I think this is correct, since the functions are all total (due to marking the typ argument as u8).
  • The icmp6_filter struct does not export its field. The meaning of a set bit differs on Linux and BSD, so there shouldn't be a good reason to not use the accessor functions.
  • The test cases are somewhat slow. It takes ~1s to run them, but its because I am testing all 255 types for pass/fail. This could possibly be improved by using memcmp or similar.

@Skyb0rg007 Skyb0rg007 force-pushed the icmpv6-filters-minimal branch from 8bbb220 to 0936f92 Compare June 27, 2026 22:00
This commit adds the icmp6_filter type and the corresponding
ICMP6_FILTER macros. These functions are tested in a similar manner to
the CMSG macros.
@Skyb0rg007 Skyb0rg007 force-pushed the icmpv6-filters-minimal branch from 0936f92 to c7dad56 Compare June 27, 2026 22:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review stable-nominated This PR should be considered for cherry-pick to libc's stable release branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants