draft: remove netdev and netlink deps and replace with minimal inline versions - #210
Draft
Frando wants to merge 10 commits into
Draft
draft: remove netdev and netlink deps and replace with minimal inline versions#210Frando wants to merge 10 commits into
Frando wants to merge 10 commits into
Conversation
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>
|
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
force-pushed
the
Frando/inline-netlink
branch
from
August 18, 2026 14:05
de3e64d to
f047ec9
Compare
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. |
Member
Author
I'll look into it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Removes
netdevandnetlink-*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-routeis 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