Skip to content

draft: remove netdev and netlink deps and replace with minimal inline versions - #210

Draft
Frando wants to merge 10 commits into
mainfrom
Frando/inline-netlink
Draft

draft: remove netdev and netlink deps and replace with minimal inline versions#210
Frando wants to merge 10 commits into
mainfrom
Frando/inline-netlink

Conversation

@Frando

@Frando Frando commented Aug 18, 2026

Copy link
Copy Markdown
Member

Description

Removes netdev and netlink-* crates from the dependency graph, replacing them with a small inline netlink client that only supports the messages we actually need.

This reduces the binary size of a size-optimized iroh build on linux by about 400KB, without loss of features. netlink-packet-route is large and has no feature flags, it includes stuff for parsing all kinds of messages we don't need.

netdev also has quite a few features we don't need.

Breaking Changes

Notes & open questions

Change checklist

  • Self-review.
  • Documentation updates following the style guide, if relevant.
  • Tests if relevant.
  • All breaking changes documented.

Frando and others added 9 commits August 17, 2026 17:08
netlink-packet-route has no feature flags and adds ~300kb to every
linux binary while netwatch parses a handful of attributes from three
message families. This crate covers exactly that subset: link, address
and route dumps, a link-by-index lookup, and a multicast event socket,
over a plain non-blocking netlink socket. netwatch will switch to it
and drop netlink-proto, netlink-sys, netlink-packet-core and
netlink-packet-route.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
netmon's route monitor and the linux default-route lookup now use the
netwatch-netlink event socket and dumps instead of netlink-proto with
netlink-packet-route. Same multicast groups, same event filtering, and
the same reconnect-with-backoff loop; the netlink-proto dependency and
its futures stack leave the tree entirely (netdev still pulls the
netlink-packet crates until enumeration moves too).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Pure restructuring ahead of inlining netdev: get_state, home_router and
LocalAddresses now live in interfaces::enumerate, built on two platform
primitives (interfaces() and default_gateway()) with the netdev-backed
implementations isolated in a temporary netdev_shim backend. The local
IP probe (UDP connect trick) is inlined since it is plain std. Platform
backends replace the shim one by one in the following commits.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Linux and android now enumerate interfaces through netwatch-netlink
link and address dumps, falling back to a getifaddrs walk when netlink
is unavailable (Android 11+ SELinux denies link dumps to apps; there
getifaddrs stays loadable on old releases by resolving the symbol at
runtime, like netdev did). The home router gateway comes from a netlink
route dump with a procfs fallback on linux. This drops netdev, and with
it netlink-packet-route, from all linux and android builds.

Verified field-for-field against netdev's output on a live system:
identical interfaces (name, index, flags, mac, addresses, prefixes,
scope ids, IPv6 address flags) and identical gateway.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
BSD and Apple platforms now enumerate through the inlined getifaddrs
walk: MAC from AF_LINK sockaddr_dl entries, prefixes from (possibly
truncated) netmask sockaddrs, scope IDs from sin6_scope_id with the
link-local ifindex fallback, and per-address IPv6 flags from the
SIOCGIFAFLAG_IN6 ioctl. netdev leaves all Apple and BSD builds, taking
the plist, objc2 and SystemConfiguration dependency stack (and our msrv
pins for it) with it. On OpenBSD and NetBSD the flag ioctl keeps
netdev's behavior of failing softly to all-false flags.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Windows now enumerates adapters through GetAdaptersAddresses via the
already-present windows crate, keeping netdev's behavior: every adapter
is reported, flags are synthesized winsock IFF_* values, IPv6 address
flags come from the DAD state and suffix origin, and the home router
gateway requires an ARP-resolvable IPv4 gateway on the adapter owning
the local IP. With the last backend inlined, netdev leaves the tree
entirely and the netdev cfg alias becomes enumerate, named for the
module it gates.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Match netdev's gateway selection exactly: the first interface owning
the local IP that also has a gateway wins, instead of only consulting
the first owner. Annotate the BSD default_route as intentionally async
(cross-platform contract), and add netwatch-netlink to the CI feature
check list.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The netlink socket now goes through socket2 instead of raw libc calls,
leaving two one-line unsafe blocks (the sockaddr_nl construction and
the MaybeUninit buffer cast for recv); the manual poll loop is replaced
by a receive timeout. The getifaddrs walk moves behind an RAII IfAddrs
list with Entry accessors, making the enumeration logic itself safe and
fixing a leak of the list when the walk panicked; the flag ioctl now
encodes its request bytes directly instead of unaligned struct writes,
leaving the ioctl call as its only unsafe. The windows backend gets the
same treatment with an Adapters buffer type whose iterators tie adapter
references to the buffer lifetime.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
… blocks

Record in the module docs why nix is not used for the getifaddrs FFI
(netmask truncation only handled on Apple targets, direct getifaddrs
linkage breaking pre-API-24 Android, no flag ioctl). Merge the split
unsafe blocks in sockaddr_slice, the windows sockaddr parser and the
android dlsym lookup, each of which guards one invariant.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Aug 18, 2026

Copy link
Copy Markdown

Documentation for this PR has been generated and is available at: https://n0-computer.github.io/net-tools/pr/210/docs/net_tools/

Last updated: 2026-08-18T14:06:23Z

@Frando Frando changed the title draft: remove netdev and netlink and replace with minimal inline versions draft: remove netdev and netlink deps and replace with minimal inline versions Aug 18, 2026
@Frando
Frando force-pushed the Frando/inline-netlink branch from de3e64d to f047ec9 Compare August 18, 2026 14:05
@n0bot n0bot Bot added this to iroh Aug 18, 2026
@github-project-automation github-project-automation Bot moved this to 🚑 Needs Triage in iroh Aug 18, 2026
@flub

flub commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Is it possible to modify the upstream projects to have cargo features that would make sense for them and still achieve the same code side reduction for us? I'm not particularly keen on vendoring these. The maintenance of upstream has been very good.

@Frando

Frando commented Aug 19, 2026

Copy link
Copy Markdown
Member Author

Is it possible to modify the upstream projects to have cargo features that would make sense for them and still achieve the same code side reduction for us? I'm not particularly keen on vendoring these. The maintenance of upstream has been very good.

I'll look into it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 🚑 Needs Triage

Development

Successfully merging this pull request may close these issues.

2 participants