]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
iproute2: bugfix - restore ip monitor backward compatibility.
authorYuyang Huang <yuyanghuang@google.com>
Fri, 23 May 2025 03:25:18 +0000 (12:25 +0900)
committerStephen Hemminger <stephen@networkplumber.org>
Mon, 26 May 2025 15:17:46 +0000 (08:17 -0700)
The current ip monitor implementation fails on older kernels that lack
newer RTNLGRP_* definitions. As ip monitor is expected to maintain
backward compatibility, this commit updates the code to check if errno
is not EINVAL when rtnl_add_nl_group() fails. This change restores ip
monitor's backward compatibility with older kernel versions.

Cc: David Ahern <dsahern@kernel.org>
Cc: Luca Boccassi <bluca@debian.org>
Cc: Maciej Żenczykowski <maze@google.com>
Cc: Lorenzo Colitti <lorenzo@google.com>
Reported-by: Adel Belhouane <bugs.a.b@free.fr>
Fixes: 19514606dce3 ("iproute2: add 'ip monitor maddress' support")
Closes: https://lore.kernel.org/netdev/CADXeF1GgJ_1tee3hc7gca2Z21Lyi3mzxq52sSfMg3mFQd2rGWQ@mail.gmail.com/T/#t
Signed-off-by: Yuyang Huang <yuyanghuang@google.com>
Tested-by: Luca Boccassi <bluca@debian.org>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
ip/ipmonitor.c

index b890b4d06ed15a3535648a25a969c54c4e6c51dc..1f4e860f8d6726edffcf9bf81636c6555757dd09 100644 (file)
@@ -5,6 +5,7 @@
  * Authors:    Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
  */
 
+#include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -328,38 +329,46 @@ int do_ipmonitor(int argc, char **argv)
 
        if (lmask & IPMON_LNEXTHOP &&
            rtnl_add_nl_group(&rth, RTNLGRP_NEXTHOP) < 0) {
-               fprintf(stderr, "Failed to add nexthop group to list\n");
-               exit(1);
+               if (errno != EINVAL) {
+                       fprintf(stderr, "Failed to add nexthop group to list\n");
+                       exit(1);
+               }
        }
 
        if (lmask & IPMON_LSTATS &&
            rtnl_add_nl_group(&rth, RTNLGRP_STATS) < 0 &&
            nmask & IPMON_LSTATS) {
-               fprintf(stderr, "Failed to add stats group to list\n");
-               exit(1);
+               if (errno != EINVAL) {
+                       fprintf(stderr, "Failed to add stats group to list\n");
+                       exit(1);
+               }
        }
 
        if (lmask & IPMON_LMADDR) {
                if ((!preferred_family || preferred_family == AF_INET) &&
                    rtnl_add_nl_group(&rth, RTNLGRP_IPV4_MCADDR) < 0) {
-                       fprintf(stderr,
-                               "Failed to add ipv4 mcaddr group to list\n");
-                       exit(1);
+                       if (errno != EINVAL) {
+                               fprintf(stderr, "Failed to add ipv4 mcaddr group to list\n");
+                               exit(1);
+                       }
                }
                if ((!preferred_family || preferred_family == AF_INET6) &&
                    rtnl_add_nl_group(&rth, RTNLGRP_IPV6_MCADDR) < 0) {
-                       fprintf(stderr,
-                               "Failed to add ipv6 mcaddr group to list\n");
-                       exit(1);
+                       if (errno != EINVAL) {
+                               fprintf(stderr,
+                                       "Failed to add ipv6 mcaddr group to list\n");
+                               exit(1);
+                       }
                }
        }
 
        if (lmask & IPMON_LACADDR) {
                if ((!preferred_family || preferred_family == AF_INET6) &&
                    rtnl_add_nl_group(&rth, RTNLGRP_IPV6_ACADDR) < 0) {
-                       fprintf(stderr,
-                               "Failed to add ipv6 acaddr group to list\n");
-                       exit(1);
+                       if (errno != EINVAL) {
+                               fprintf(stderr, "Failed to add ipv6 acaddr group to list\n");
+                               exit(1);
+                       }
                }
        }