netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel.org>
To: stephen@networkplumber.org
Cc: dsahern@gmail.com, netdev@vger.kernel.org,
	Jakub Kicinski <kuba@kernel.org>
Subject: [PATCH iproute2] ip: netconf: fix overzealous error checking
Date: Wed,  9 Oct 2024 11:21:54 -0700	[thread overview]
Message-ID: <20241009182154.1784675-1-kuba@kernel.org> (raw)

The rtnetlink.sh kernel test started reporting errors after
iproute2 update. The error checking introduced by commit
under fixes is incorrect. rtnl_listen() always returns
an error, because the only way to break the loop is to
return an error from the handler, it seems.

Switch this code to using normal rtnl_talk(), instead of
the rtnl_listen() abuse. As far as I can tell the use of
rtnl_listen() was to make get and dump use common handling
but that's no longer the case, anyway.

Before:
  $ ip -6 netconf show dev lo
  inet6 lo forwarding off mc_forwarding off proxy_neigh off ignore_routes_with_linkdown off
  $ echo $?
  2

After:
  $ ./ip/ip -6 netconf show dev lo
inet6 lo forwarding off mc_forwarding off proxy_neigh off ignore_routes_with_linkdown off
  $ echo $?
  0

Fixes: 00e8a64dac3b ("ip: detect errors in netconf monitor mode")
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
We're also missing opening a JSON object here, but I'll send
that fix separately, to -next?
---
 ip/ipnetconf.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/ip/ipnetconf.c b/ip/ipnetconf.c
index 77147eb69097..cf27e7e30a5a 100644
--- a/ip/ipnetconf.c
+++ b/ip/ipnetconf.c
@@ -187,16 +187,16 @@ static int do_show(int argc, char **argv)
 	ll_init_map(&rth);
 
 	if (filter.ifindex && filter.family != AF_UNSPEC) {
+		struct nlmsghdr *answer;
+
 		req.ncm.ncm_family = filter.family;
 		addattr_l(&req.n, sizeof(req), NETCONFA_IFINDEX,
 			  &filter.ifindex, sizeof(filter.ifindex));
 
-		if (rtnl_send(&rth, &req.n, req.n.nlmsg_len) < 0) {
-			perror("Can not send request");
-			exit(1);
-		}
-		if (rtnl_listen(&rth, print_netconf, stdout) < 0)
+		if (rtnl_talk(&rth, &req.n, &answer) < 0)
 			exit(2);
+
+		print_netconf2(answer, stdout);
 	} else {
 		rth.flags = RTNL_HANDLE_F_SUPPRESS_NLERR;
 dump:
-- 
2.46.2


             reply	other threads:[~2024-10-09 18:22 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-09 18:21 Jakub Kicinski [this message]
2024-10-11 18:32 ` [PATCH iproute2] ip: netconf: fix overzealous error checking patchwork-bot+netdevbpf

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=20241009182154.1784675-1-kuba@kernel.org \
    --to=kuba@kernel.org \
    --cc=dsahern@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=stephen@networkplumber.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;
as well as URLs for NNTP newsgroup(s).