diff mbox series

[iproute2] ip-monitor: Do not error out when RTNLGRP_STATS is not available

Message ID 20221025222909.1112705-1-bpoirier@nvidia.com (mailing list archive)
State Superseded
Delegated to: David Ahern
Headers show
Series [iproute2] ip-monitor: Do not error out when RTNLGRP_STATS is not available | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Benjamin Poirier Oct. 25, 2022, 10:29 p.m. UTC
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, change the error to a warning 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.

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>
---
 ip/ipmonitor.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Comments

Stephen Hemminger Oct. 26, 2022, 2:17 a.m. UTC | #1
On Wed, 26 Oct 2022 07:29:09 +0900
Benjamin Poirier <bpoirier@nvidia.com> wrote:

> 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, change the error to a warning 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.
> 
> 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>
> ---
>  ip/ipmonitor.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/ip/ipmonitor.c b/ip/ipmonitor.c
> index 8a72ea42..45e4e8f1 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 */
> +	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;
>  
> @@ -328,8 +331,11 @@ int do_ipmonitor(int argc, char **argv)
>  
>  	if (lmask & IPMON_LSTATS &&
>  	    rtnl_add_nl_group(&rth, RTNLGRP_STATS) < 0) {
> +		if (!(nmask & IPMON_LSTATS))
> +			fprintf(stderr, "Warning: ");
>  		fprintf(stderr, "Failed to add stats group to list\n");
> -		exit(1);
> +		if (nmask & IPMON_LSTATS)
> +			exit(1);
>  	}
>  
>  	if (listen_all_nsid && rtnl_listen_all_nsid(&rth) < 0)

You still end up warning on older kernels. My version is simpler.
All needs to not include lstats
Stephen Hemminger Oct. 26, 2022, 3:20 a.m. UTC | #2
On Wed, 26 Oct 2022 07:29:09 +0900
Benjamin Poirier <bpoirier@nvidia.com> wrote:

> 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, change the error to a warning 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.
> 
> 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.
diff mbox series

Patch

diff --git a/ip/ipmonitor.c b/ip/ipmonitor.c
index 8a72ea42..45e4e8f1 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 */
+	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;
 
@@ -328,8 +331,11 @@  int do_ipmonitor(int argc, char **argv)
 
 	if (lmask & IPMON_LSTATS &&
 	    rtnl_add_nl_group(&rth, RTNLGRP_STATS) < 0) {
+		if (!(nmask & IPMON_LSTATS))
+			fprintf(stderr, "Warning: ");
 		fprintf(stderr, "Failed to add stats group to list\n");
-		exit(1);
+		if (nmask & IPMON_LSTATS)
+			exit(1);
 	}
 
 	if (listen_all_nsid && rtnl_listen_all_nsid(&rth) < 0)