Skip to content

Conversation

wjordan
Copy link

@wjordan wjordan commented Aug 18, 2025

Fixes #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.

Copy link

google-cla bot commented Aug 18, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

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.

proposal: net: fetch all interfaces with associated addresses in a single call
1 participant