Skip to content

netlink: answer non-dump RTM_GETLINK for lo - #245

Open
congwang-mk wants to merge 1 commit into
mainfrom
netlink-getlink-lookup
Open

congwang-mk wants to merge 1 commit into
mainfrom
netlink-getlink-lookup

Conversation

@congwang-mk

Copy link
Copy Markdown
Contributor

Fixes #239

Problem

Only the dump forms of RTM_GETLINK and RTM_GETADDR were synthesized, so a lookup by name or index got EOPNOTSUPP. iproute2 resolves a device name with a non-dump RTM_GETLINK carrying IFLA_IFNAME before it does anything else, and reads any error as a missing device:

sandlock run -r /usr -r /proc -- ip link show lo      -> Device "lo" does not exist.
sandlock run -r /usr -r /proc -- ip addr show dev lo  -> Device "lo" does not exist.

Fix

  • parse_request keeps the ifinfomsg index and the IFLA_IFNAME or IFLA_ALT_IFNAME attribute (the kernel accepts both).
  • A non-dump RTM_GETLINK follows rtnl_getlink: a positive index wins over the name, a request with neither is EINVAL, anything but lo (index 1) is ENODEV. A match is a single RTM_NEWLINK without NLM_F_MULTI and without NLMSG_DONE.
  • The reply is acked when the request sets 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.
  • Non-dump RTM_GETADDR stays EOPNOTSUPP even though the issue title mentions it: that is what the kernel returns for AF_UNSPEC and AF_INET, and ip addr show dev lo only failed because of the name lookup.

After the fix, in the sandbox:

ip link show lo      -> 1: lo: <LOOPBACK,UP> mtu 65536 ...   rc=0
ip addr show dev lo  -> lo with 127.0.0.1/8 and ::1/128      rc=0
ip link show eth0    -> Device "eth0" does not exist.        rc=1
ip -br link / addr   -> unchanged

Testing

  • Unit tests for the parser (index and name kept, IFLA_ALT_IFNAME, truncated attribute ignored) and for the lookup (by name, by index, index precedence, ENODEV, EINVAL, ack).
  • Integration test link_lookup_by_name_finds_only_lo sends the request over a raw netlink socket from Python, so it does not need ip installed.
  • Locally: netlink unit tests 16 of 16, test_netlink_virt integration tests 16 of 16. The full suite was not run locally.

🤖 Generated with Claude Code

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

netlink: non-dump RTM_GETLINK/RTM_GETADDR is unsupported (ip link show lo fails)

1 participant