From: Benjamin Poirier <bpoirier@nvidia.com>
To: Stephen Hemminger <stephen@networkplumber.org>
Cc: netdev@vger.kernel.org, David Ahern <dsahern@kernel.org>,
Ido Schimmel <idosch@nvidia.com>
Subject: [PATCH iproute2 v2] ip-monitor: Do not error out when RTNLGRP_STATS is not available
Date: Wed, 26 Oct 2022 15:49:07 +0900 [thread overview]
Message-ID: <20221026064907.1209952-1-bpoirier@nvidia.com> (raw)
In-Reply-To: <20221025202026.68d92100@hermes.local>
Following commit 4e8a9914c4d4 ("ip-monitor: Include stats events in default
and "all" cases"), `ip monitor` fails to start on kernels which do not
contain linux.git commit 5fd0b838efac ("net: rtnetlink: Add UAPI toggle for
IFLA_OFFLOAD_XSTATS_L3_STATS") because the netlink group RTNLGRP_STATS
doesn't exist:
$ ip monitor
Failed to add stats group to list
When "stats" is not explicitly requested, ignore the error so that `ip
monitor` and `ip monitor all` continue to work on older kernels.
Note that the same change is not done for RTNLGRP_NEXTHOP because its value
is 32 and group numbers <= 32 are always supported; see the comment above
netlink_change_ngroups() in the kernel source. Therefore
NETLINK_ADD_MEMBERSHIP 32 does not error out even on kernels which do not
support RTNLGRP_NEXTHOP.
v2:
* Silently ignore a failure to implicitly add the stats group, instead of
printing a warning.
Reported-by: Stephen Hemminger <stephen@networkplumber.org>
Fixes: 4e8a9914c4d4 ("ip-monitor: Include stats events in default and "all" cases")
Signed-off-by: Benjamin Poirier <bpoirier@nvidia.com>
---
> There are two acceptable solutions:
> 1. Ignore the error, and never print any warning.
> 2. Don't ask for the stats feature with the default "ip monitor" and "ip monitor all"
>
> Either way, it needs to be totally silent when built and run on older kernels.
Strictly speaking, the patch below is solution 1*:
Ignore the error, and never print any warning ... when implicitly
adding the stats group.
Before 4e8a9914c4d4, `ip mon stats` used to error out if the stats group
could not be added. That behavior is preserved.
ip/ipmonitor.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/ip/ipmonitor.c b/ip/ipmonitor.c
index 8a72ea42..d808369c 100644
--- a/ip/ipmonitor.c
+++ b/ip/ipmonitor.c
@@ -195,6 +195,8 @@ static int accept_msg(struct rtnl_ctrl_data *ctrl,
int do_ipmonitor(int argc, char **argv)
{
unsigned int groups = 0, lmask = 0;
+ /* "needed" mask, failure to enable is an error */
+ unsigned int nmask;
char *file = NULL;
int ifindex = 0;
@@ -253,6 +255,7 @@ int do_ipmonitor(int argc, char **argv)
ipneigh_reset_filter(ifindex);
ipnetconf_reset_filter(ifindex);
+ nmask = lmask;
if (!lmask)
lmask = IPMON_L_ALL;
@@ -327,7 +330,8 @@ int do_ipmonitor(int argc, char **argv)
}
if (lmask & IPMON_LSTATS &&
- rtnl_add_nl_group(&rth, RTNLGRP_STATS) < 0) {
+ rtnl_add_nl_group(&rth, RTNLGRP_STATS) < 0 &&
+ nmask & IPMON_LSTATS) {
fprintf(stderr, "Failed to add stats group to list\n");
exit(1);
}
--
2.37.2
next prev parent reply other threads:[~2022-10-26 6:50 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-22 6:19 [PATCH iproute2 0/4] monitor command fixes Benjamin Poirier
2022-09-22 6:19 ` [PATCH iproute2 1/4] bridge: Do not print stray prefixes in monitor mode Benjamin Poirier
2022-09-22 15:28 ` Stephen Hemminger
2022-10-25 22:29 ` [PATCH iproute2] ip-monitor: Do not error out when RTNLGRP_STATS is not available Benjamin Poirier
2022-10-26 2:17 ` Stephen Hemminger
2022-10-26 3:20 ` Stephen Hemminger
2022-10-26 6:49 ` Benjamin Poirier [this message]
2022-09-22 6:19 ` [PATCH iproute2 2/4] ip-monitor: Do not listen for nexthops by default when specifying stats Benjamin Poirier
2022-09-22 6:19 ` [PATCH iproute2 3/4] ip-monitor: Include stats events in default and "all" cases Benjamin Poirier
2022-10-25 15:51 ` Stephen Hemminger
2022-09-22 6:19 ` [PATCH iproute2 4/4] ip-monitor: Fix the selection of rtnl groups when listening for all object types Benjamin Poirier
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=20221026064907.1209952-1-bpoirier@nvidia.com \
--to=bpoirier@nvidia.com \
--cc=dsahern@kernel.org \
--cc=idosch@nvidia.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.