Skip to content

Conversation

austinderek
Copy link

Fixes golang#53660.

This Linux-specific optimization adds filtering by network interface index to the RTM_GETADDR netlink dump request, by setting the NETLINK_GET_STRICT_CHK socket option to enable strict checking and setting the IfAddrmsg.Index field to the requested interface index. This eliminates the O(n^2) behavior described in the issue, resulting in a significant performance improvement on systems with a large number (thousands) of network interfaces:

BenchmarkNetInterfaces-64    	       9	 124993080 ns/op
BenchmarkOriginal-64         	       1	7822389469 ns/op

This PR does not require any changes to the public API. In order to avoid changes to the (frozen) syscall.NetlinkRIB API (which hard-codes its netlink requests to the older RtGenmsg type), this PR copies this logic into an unexported netlinkRIB function with the necessary changes to send the new message type.


🔄 This is a mirror of upstream PR golang#75076

@austinderek austinderek force-pushed the master branch 29 times, most recently from 5a56d88 to d50240b Compare August 19, 2025 13:10
@austinderek austinderek force-pushed the master branch 30 times, most recently from 34e6762 to 37c78b5 Compare September 28, 2025 02:30
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