From: Sven Eckelmann <sven@narfation.org>
To: b.a.t.m.a.n@lists.open-mesh.org
Cc: Sven Eckelmann <sven@narfation.org>
Subject: [PATCH 10/12] batctl: netlink: detect receive errors in query_rtnl_link_single
Date: Wed, 08 Jul 2026 22:00:16 +0200 [thread overview]
Message-ID: <20260708-bugfixes-netlink-v1-10-8ce03e37f17b@narfation.org> (raw)
In-Reply-To: <20260708-bugfixes-netlink-v1-0-8ce03e37f17b@narfation.org>
With the exception of nl_socket_alloc(), query_rtnl_link_single() always
returns 0, no matter what happens. All callers rely solely on the *_found
flags in link_data to decide what an interface is.
Return proper negative errno codes from the setup error paths, mirroring
the sibling helper query_rtnl_link(). These need to be handled also by the
callers.
Fixes: 07967cd19702 ("batctl: Support checking of meshif without sysfs")
Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
functions.c | 51 ++++++++++++++++++++++++++++++++++++++++-----------
1 file changed, 40 insertions(+), 11 deletions(-)
diff --git a/functions.c b/functions.c
index 36cae49..56bacdf 100644
--- a/functions.c
+++ b/functions.c
@@ -667,6 +667,7 @@ static int query_rtnl_link_single(int mesh_ifindex,
};
struct nl_cb *cb = NULL;
struct nl_sock *sock;
+ int err = 0;
int ret;
link_data->kind_found = false;
@@ -676,42 +677,55 @@ static int query_rtnl_link_single(int mesh_ifindex,
sock = nl_socket_alloc();
if (!sock)
- return -1;
+ return -ENOMEM;
ret = nl_connect(sock, NETLINK_ROUTE);
- if (ret < 0)
+ if (ret < 0) {
+ err = -ENOMEM;
goto free_sock;
+ }
ret = nl_send_simple(sock, RTM_GETLINK, NLM_F_REQUEST,
&ifinfo, sizeof(ifinfo));
- if (ret < 0)
+ if (ret < 0) {
+ err = -EIO;
goto free_sock;
+ }
cb = nl_cb_alloc(NL_CB_DEFAULT);
- if (!cb)
+ if (!cb) {
+ err = -ENOMEM;
goto free_sock;
+ }
nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, query_rtnl_link_single_parse,
link_data);
- nl_recvmsgs(sock, cb);
+
+ ret = nl_recvmsgs(sock, cb);
+ if (ret < 0)
+ err = -EIO;
nl_cb_put(cb);
free_sock:
nl_socket_free(sock);
- return 0;
+ return err;
}
int translate_vlan_iface(struct state *state, const char *vlandev)
{
struct rtnl_link_iface_data link_data;
unsigned int arg_ifindex;
+ int ret;
arg_ifindex = if_nametoindex(vlandev);
if (arg_ifindex == 0)
return -ENODEV;
- query_rtnl_link_single(arg_ifindex, &link_data);
+ ret = query_rtnl_link_single(arg_ifindex, &link_data);
+ if (ret < 0)
+ return ret;
+
if (!link_data.vid_found)
return -ENODEV;
@@ -785,12 +799,16 @@ int translate_hard_iface(struct state *state, const char *hardif)
{
struct rtnl_link_iface_data link_data;
unsigned int arg_ifindex;
+ int ret;
arg_ifindex = if_nametoindex(hardif);
if (arg_ifindex == 0)
return -ENODEV;
- query_rtnl_link_single(arg_ifindex, &link_data);
+ ret = query_rtnl_link_single(arg_ifindex, &link_data);
+ if (ret < 0)
+ return ret;
+
if (!link_data.master_found)
return -ENOLINK;
@@ -806,8 +824,12 @@ int translate_hard_iface(struct state *state, const char *hardif)
static int check_mesh_iface_netlink(unsigned int ifindex)
{
struct rtnl_link_iface_data link_data;
+ int ret;
+
+ ret = query_rtnl_link_single(ifindex, &link_data);
+ if (ret < 0)
+ return ret;
- query_rtnl_link_single(ifindex, &link_data);
if (!link_data.kind_found)
return -1;
@@ -821,12 +843,15 @@ int guess_netdev_type(const char *netdev, enum selector_prefix *type)
{
struct rtnl_link_iface_data link_data;
unsigned int netdev_ifindex;
+ int ret;
netdev_ifindex = if_nametoindex(netdev);
if (netdev_ifindex == 0)
return -ENODEV;
- query_rtnl_link_single(netdev_ifindex, &link_data);
+ ret = query_rtnl_link_single(netdev_ifindex, &link_data);
+ if (ret < 0)
+ return ret;
if (link_data.kind_found && strcmp(link_data.kind, "batadv") == 0) {
*type = SP_MESHIF;
@@ -860,12 +885,16 @@ int check_mesh_iface_ownership(struct state *state, char *hard_iface)
{
struct rtnl_link_iface_data link_data;
unsigned int hardif_index;
+ int ret;
hardif_index = if_nametoindex(hard_iface);
if (hardif_index == 0)
return EXIT_FAILURE;
- query_rtnl_link_single(hardif_index, &link_data);
+ ret = query_rtnl_link_single(hardif_index, &link_data);
+ if (ret < 0)
+ return EXIT_FAILURE;
+
if (!link_data.master_found)
return EXIT_FAILURE;
--
2.47.3
next prev parent reply other threads:[~2026-07-08 20:08 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-08 20:00 [PATCH 00/12] batctl: netlink bugfixes Sven Eckelmann
2026-07-08 20:00 ` [PATCH 01/12] batctl: handle netlink callback object on error Sven Eckelmann
2026-07-08 20:00 ` [PATCH 02/12] batctl: netlink: abort netlink_print_common when message allocation fails Sven Eckelmann
2026-07-08 20:00 ` [PATCH 03/12] batctl: netlink: don't format NULL extra_info in info_callback Sven Eckelmann
2026-07-08 20:00 ` [PATCH 04/12] batctl: netlink: report dump errors signalled in the NLMSG_DONE message Sven Eckelmann
2026-07-08 20:00 ` [PATCH 05/12] batctl: netlink: detect receive errors in netlink_print_common Sven Eckelmann
2026-07-08 20:00 ` [PATCH 06/12] batctl: netlink: report kernel errors when writing settings Sven Eckelmann
2026-07-08 20:00 ` [PATCH 07/12] batctl: netlink: report send errors in netlink_simple_request Sven Eckelmann
2026-07-08 20:00 ` [PATCH 08/12] batctl: netlink: detect receive errors in query_rtnl_link Sven Eckelmann
2026-07-08 20:00 ` [PATCH 09/12] batctl: netlink: detect receive errors in netlink_simple_request Sven Eckelmann
2026-07-08 20:00 ` Sven Eckelmann [this message]
2026-07-08 20:00 ` [PATCH 11/12] batctl: netlink: report error on query_rtnl_link send failure Sven Eckelmann
2026-07-08 20:00 ` [PATCH 12/12] batctl: netlink: use kernel-style error codes for nl_recvmsgs Sven Eckelmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260708-bugfixes-netlink-v1-10-8ce03e37f17b@narfation.org \
--to=sven@narfation.org \
--cc=b.a.t.m.a.n@lists.open-mesh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox