Skip to content

fix(net): convert in6_pktinfo's interface index with a range check - #2

Merged
asmie merged 1 commit into
asmie:masterfrom
athola:fix/android-in6-pktinfo-ifindex
Oct 27, 2026
Merged

asmie merged 1 commit into
asmie:masterfrom
athola:fix/android-in6-pktinfo-ifindex

Conversation

@athola

@athola athola commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

dlep-net does not build for Android. in6_pktinfo.ipi6_ifindex is a u32 in glibc and musl but a c_int in bionic, so the three places in discovery.rs that copy it to or from a u32 interface index fail there:

$ cargo check --target aarch64-linux-android -p dlep-net
error[E0308]: mismatched types   (x3)

A plain as cast would build, but it wraps a bad value silently. On glibc, as u32 is also a same-type cast, which clippy -D warnings refuses.

This change converts both directions through i64, which holds either type, with a checked conversion (two small helpers next to the tests):

  • Sending: an index that does not fit the field is not sent. That in6_pktinfo is skipped, the same as when no interface is selected.
  • Receiving: a negative index leaves interface_index unset and the scope id untouched.

On glibc and musl the behaviour is unchanged.

Tests, in crates/dlep-net/src/discovery.rs:

  • an_interface_index_that_does_not_fit_the_field_is_not_sent
  • a_received_interface_index_is_checked_not_wrapped

Both are written so they run on Linux with i32 and u32 inputs.

Checked:

  • cargo check --target aarch64-linux-android -p dlep-net -p dlep-daemon: 3 errors on master, clean with the change. Clippy (-D warnings) is also clean for that target.
  • Linux: cargo fmt --all -- --check and cargo clippy --workspace --all-targets --locked -- -D warnings are clean.
  • .github/scripts/test-network.sh cargo test --workspace --locked --offline, in a privileged container: no failures before or after. That is 451 tests before and 453 after, the two new ones, and it includes the IPv6 discovery tests that go through the changed receive path.

An Android cargo check job may be helpful for checking Android builds for errors before merge, but it requires an NDK in the runner.

dlep-net does not build for Android: in6_pktinfo.ipi6_ifindex is a u32
in glibc and musl but a c_int in bionic, so the three places that copy
it to or from a u32 interface index are type errors there (E0308,
mismatched types). A plain cast would build but wrap silently, and on
glibc `as u32` is a same-type cast that clippy -D warnings refuses.

Both directions now go through i64, which holds either type, with a
checked conversion. An index that does not fit the field is not sent
(that pktinfo is skipped), and a received index that is negative leaves
the interface unset and the scope id untouched. On glibc and musl the
behaviour is unchanged.
@athola
athola force-pushed the fix/android-in6-pktinfo-ifindex branch from f5afe0d to 0c14670 Compare October 6, 2026 01:08
@asmie
asmie merged commit a4f114a into asmie:master Oct 27, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants