netlink: answer non-dump RTM_GETLINK for lo - #245
Open
congwang-mk wants to merge 1 commit into
Open
congwang-mk wants to merge 1 commit into
congwang-mk wants to merge 1 commit into
Conversation
Only the dump forms were synthesized, so a lookup by name or index got EOPNOTSUPP. iproute2 resolves a device name that way before it does anything else, which made "ip link show lo" and "ip addr show dev lo" report that lo does not exist while the dump forms worked. parse_request now keeps the ifinfomsg index and the IFLA_IFNAME or IFLA_ALT_IFNAME attribute, and the lookup follows rtnl_getlink: a positive index wins over the name, neither is EINVAL, anything but lo is ENODEV. The reply is acked when the request asks for it, because libnl sets NLM_F_ACK on every request and waits for the ack. Non-dump RTM_GETADDR stays EOPNOTSUPP, which is what the kernel itself returns for AF_UNSPEC and AF_INET. Fixes #239 Signed-off-by: Cong Wang <cwang@multikernel.io>
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.
Fixes #239
Problem
Only the dump forms of
RTM_GETLINKandRTM_GETADDRwere synthesized, so a lookup by name or index gotEOPNOTSUPP. iproute2 resolves a device name with a non-dumpRTM_GETLINKcarryingIFLA_IFNAMEbefore it does anything else, and reads any error as a missing device:Fix
parse_requestkeeps theifinfomsgindex and theIFLA_IFNAMEorIFLA_ALT_IFNAMEattribute (the kernel accepts both).RTM_GETLINKfollowsrtnl_getlink: a positive index wins over the name, a request with neither isEINVAL, anything butlo(index 1) isENODEV. A match is a singleRTM_NEWLINKwithoutNLM_F_MULTIand withoutNLMSG_DONE.NLM_F_ACK. libnl sets that flag on every request and waits for the ack, so it would hang otherwise. This was not tested against libnl itself.RTM_GETADDRstaysEOPNOTSUPPeven though the issue title mentions it: that is what the kernel returns forAF_UNSPECandAF_INET, andip addr show dev loonly failed because of the name lookup.After the fix, in the sandbox:
Testing
IFLA_ALT_IFNAME, truncated attribute ignored) and for the lookup (by name, by index, index precedence,ENODEV,EINVAL, ack).link_lookup_by_name_finds_only_losends the request over a raw netlink socket from Python, so it does not needipinstalled.test_netlink_virtintegration tests 16 of 16. The full suite was not run locally.🤖 Generated with Claude Code