From: Yuyang Huang Date: Fri, 23 May 2025 03:25:18 +0000 (+0900) Subject: iproute2: bugfix - restore ip monitor backward compatibility. X-Git-Tag: v6.15.0~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=969817ce1ddb1aab375d74d0eee6454c13656f84;p=thirdparty%2Fiproute2.git iproute2: bugfix - restore ip monitor backward compatibility. 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 Cc: Luca Boccassi Cc: Maciej Żenczykowski Cc: Lorenzo Colitti Reported-by: Adel Belhouane 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 Tested-by: Luca Boccassi Signed-off-by: Stephen Hemminger --- diff --git a/ip/ipmonitor.c b/ip/ipmonitor.c index b890b4d0..1f4e860f 100644 --- a/ip/ipmonitor.c +++ b/ip/ipmonitor.c @@ -5,6 +5,7 @@ * Authors: Alexey Kuznetsov, */ +#include #include #include #include @@ -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); + } } }