This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 3ce8e0cd29d1bec54380da7589dcae36d9760d20 Author: zhanghongyu <[email protected]> AuthorDate: Tue Sep 22 19:50:49 2026 +0800 net/netlink: always report RTM_NEWLINK in an RTM_GETLINK dump. Standard netlink clients only collect RTM_NEWLINK entries while walking a dump, so reporting RTM_DELLINK for a device that is down made it vanish from the enumeration: "ip link" and getifaddrs() missed every down interface. netlink_get_device() chose the message type from IFF_IS_UP() for both of its callers, but the two need different types. Pass the type in explicitly: a dump always reports RTM_NEWLINK, because the link state is carried by ifi_flags, while the RTNLGRP_LINK broadcast keeps reporting the actual up/down event. Assisted-by: Kiro:claude-opus-4 Signed-off-by: zhanghongyu <[email protected]> --- net/netlink/netlink_route.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/net/netlink/netlink_route.c b/net/netlink/netlink_route.c index b627e19e41a..46dab7522d0 100644 --- a/net/netlink/netlink_route.c +++ b/net/netlink/netlink_route.c @@ -380,6 +380,15 @@ const struct nla_policy g_cgw_policy[CGW_MAX + 1] = * Description: * Generate one device response. * + * Input Parameters: + * dev - The network device to report on. + * type - The netlink message type to report, either RTM_NEWLINK or + * RTM_DELLINK. The caller decides this because the meaning + * differs per usage: a RTM_GETLINK dump always reports + * RTM_NEWLINK (link state is carried by ifi_flags), while an + * RTNLGRP_LINK broadcast reports the actual link event. + * req - The originating request, or NULL for an unsolicited broadcast. + * ****************************************************************************/ #ifndef CONFIG_NETLINK_DISABLE_GETLINK @@ -422,12 +431,11 @@ static uint16_t netlink_convert_device_type(uint8_t lltype) } static FAR struct netlink_response_s * -netlink_get_device(FAR struct net_driver_s *dev, +netlink_get_device(FAR struct net_driver_s *dev, int type, FAR const struct nlroute_sendto_request_s *req) { FAR struct getlink_recvfrom_rsplist_s *alloc; FAR struct getlink_recvfrom_response_s *resp; - int up = IFF_IS_UP(dev->d_flags); /* Allocate the response buffer */ @@ -444,7 +452,7 @@ netlink_get_device(FAR struct net_driver_s *dev, resp = &alloc->payload; resp->hdr.nlmsg_len = sizeof(struct getlink_recvfrom_response_s); - resp->hdr.nlmsg_type = up ? RTM_NEWLINK : RTM_DELLINK; + resp->hdr.nlmsg_type = type; resp->hdr.nlmsg_flags = req ? req->hdr.nlmsg_flags : 0; resp->hdr.nlmsg_seq = req ? req->hdr.nlmsg_seq : 0; resp->hdr.nlmsg_pid = req ? req->hdr.nlmsg_pid : 0; @@ -584,7 +592,9 @@ static int netlink_device_callback(FAR struct net_driver_s *dev, FAR struct nlroute_info_s *info = arg; FAR struct netlink_response_s * resp; - resp = netlink_get_device(dev, info->req); + /* A RTM_GETLINK dump always reports RTM_NEWLINK */ + + resp = netlink_get_device(dev, RTM_NEWLINK, info->req); if (resp == NULL) { return -ENOMEM; @@ -2203,7 +2213,13 @@ void netlink_device_notify(FAR struct net_driver_s *dev) DEBUGASSERT(dev != NULL); - resp = netlink_get_device(dev, NULL); + /* report the link event itself, RTM_NEWLINK when the device came up and + * RTM_DELLINK when it went down. + */ + + resp = netlink_get_device(dev, IFF_IS_UP(dev->d_flags) ? RTM_NEWLINK : + RTM_DELLINK, + NULL); if (resp != NULL) { netlink_add_broadcast(RTNLGRP_LINK, resp);
