zhhyu7 opened a new pull request, #22474:
URL: https://github.com/apache/nuttx/pull/22474
## Summary
1. net/netlink: always report RTM_NEWLINK in an RTM_GETLINK dump.
netlink_get_device() chose the message type from IFF_IS_UP(), but its
two callers need different types. A dump must always report
RTM_NEWLINK, because the link state is carried by ifi_flags; only the
RTNLGRP_LINK broadcast reports the actual up/down event. Reporting
RTM_DELLINK inside a dump made every interface that is down vanish from
the enumeration, since a client collects only RTM_NEWLINK entries. Pass
the type in explicitly.
2. net/netlink: move the NLA type enum to the public header.
The NLA_UNSPEC..NLA_TYPE_MAX enum describes the attribute types of the
netlink protocol itself but lived in the private net/netlink/netlink.h,
so an application had to redefine the values to build an attribute
policy. Move it to include/netpacket/netlink.h, next to the other
protocol definitions, and add NLMSG_ALIGNTO, which the attribute macros
of libnl expect.
## Impact
The first commit changes what a client sees in an RTM_GETLINK dump: an
interface that is down now appears, as RTM_NEWLINK with IFF_UP clear in
ifi_flags. A client that relied on the old behaviour to learn about a
down interface has to read ifi_flags instead, which is how Linux has
always reported it.
The second is a header move with no functional change; the only in-tree
users are in net/netlink, which includes both headers.
## Testing
sim:dynconns (CI config, tools/ci/testlist/sim-02.dat) with
SIM_NET_BRIDGE, built with gcc 13.4 and gcc 11, checkpatch clean.
A small program sends RTM_GETLINK with NLM_F_DUMP and prints the type
of every response.
Before this series, eth0 disappears from the dump while it is down:
---A-all-up---
GETLINK: msg=RTM_NEWLINK ifindex=1 flags=0x3006 up=1
GETLINK: msg=RTM_NEWLINK ifindex=2 flags=0x26 up=1
GETLINK RESULT: responses=2 RTM_NEWLINK=2 RTM_DELLINK=0
ifdown eth0...OK
---B-eth0-down---
GETLINK: msg=RTM_DELLINK ifindex=1 flags=0x3000 up=0 <-- a dump client
drops this
GETLINK: msg=RTM_NEWLINK ifindex=2 flags=0x26 up=1
GETLINK RESULT: responses=2 RTM_NEWLINK=1 RTM_DELLINK=1
With this series, it stays in the dump and the state is in the flags
(0x3006 -> 0x3000, IFF_UP clear):
---B-eth0-down---
GETLINK: msg=RTM_NEWLINK ifindex=1 flags=0x3000 up=0
GETLINK: msg=RTM_NEWLINK ifindex=2 flags=0x26 up=1
GETLINK RESULT: responses=2 RTM_NEWLINK=2 RTM_DELLINK=0
ifup restores 0x3006 and the dump is unchanged.
Not tested: real hardware, other architectures, the protected and
kernel builds, and the RTNLGRP_LINK broadcast path, which keeps reporting
RTM_DELLINK on an ifdown.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]