From: Hangbin Liu Date: Tue, 8 Nov 2022 12:43:44 +0000 (+0800) Subject: ip: fix return value for rtnl_talk failures X-Git-Tag: v6.1.0~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f38059746dcd9184ed131a01dc30858b64a9306a;p=thirdparty%2Fiproute2.git ip: fix return value for rtnl_talk failures Since my last commit "rtnetlink: add new function rtnl_echo_talk()" we return the kernel rtnl exit code directly, which breaks some kernel selftest checking. As there are still a lot of tests checking -2 as the error return value, to keep backward compatibility, let's keep using -2 for all the rtnl return values. Reported-by: Ido Schimmel Fixes: 6c09257f1bf6 ("rtnetlink: add new function rtnl_echo_talk()") Signed-off-by: Hangbin Liu Tested-by: Ido Schimmel Signed-off-by: Stephen Hemminger --- diff --git a/ip/ipaddress.c b/ip/ipaddress.c index 456545bb6..5e8334823 100644 --- a/ip/ipaddress.c +++ b/ip/ipaddress.c @@ -2422,6 +2422,7 @@ static int ipaddr_modify(int cmd, int flags, int argc, char **argv) __u32 preferred_lft = INFINITY_LIFE_TIME; __u32 valid_lft = INFINITY_LIFE_TIME; unsigned int ifa_flags = 0; + int ret; while (argc > 0) { if (strcmp(*argv, "peer") == 0 || @@ -2604,9 +2605,14 @@ static int ipaddr_modify(int cmd, int flags, int argc, char **argv) } if (echo_request) - return rtnl_echo_talk(&rth, &req.n, json, print_addrinfo); + ret = rtnl_echo_talk(&rth, &req.n, json, print_addrinfo); + else + ret = rtnl_talk(&rth, &req.n, NULL); - return rtnl_talk(&rth, &req.n, NULL); + if (ret) + return -2; + + return 0; } int do_ipaddr(int argc, char **argv) diff --git a/ip/iplink.c b/ip/iplink.c index 92ce6c47b..301a535e6 100644 --- a/ip/iplink.c +++ b/ip/iplink.c @@ -1129,7 +1129,7 @@ static int iplink_modify(int cmd, unsigned int flags, int argc, char **argv) ret = rtnl_talk(&rth, &req.n, NULL); if (ret) - return ret; + return -2; /* remove device from cache; next use can refresh with new data */ ll_drop_by_index(req.i.ifi_index); diff --git a/ip/ipnexthop.c b/ip/ipnexthop.c index c87e847f3..9f16b8097 100644 --- a/ip/ipnexthop.c +++ b/ip/ipnexthop.c @@ -920,6 +920,7 @@ static int ipnh_modify(int cmd, unsigned int flags, int argc, char **argv) .nhm.nh_family = preferred_family, }; __u32 nh_flags = 0; + int ret; while (argc > 0) { if (!strcmp(*argv, "id")) { @@ -1000,9 +1001,14 @@ static int ipnh_modify(int cmd, unsigned int flags, int argc, char **argv) req.nhm.nh_flags = nh_flags; if (echo_request) - return rtnl_echo_talk(&rth, &req.n, json, print_nexthop_nocache); + ret = rtnl_echo_talk(&rth, &req.n, json, print_nexthop_nocache); + else + ret = rtnl_talk(&rth, &req.n, NULL); + + if (ret) + return -2; - return rtnl_talk(&rth, &req.n, NULL); + return 0; } static int ipnh_get_id(__u32 id) diff --git a/ip/iproute.c b/ip/iproute.c index b4b9d1b20..f34289e83 100644 --- a/ip/iproute.c +++ b/ip/iproute.c @@ -1134,6 +1134,7 @@ static int iproute_modify(int cmd, unsigned int flags, int argc, char **argv) int raw = 0; int type_ok = 0; __u32 nhid = 0; + int ret; if (cmd != RTM_DELROUTE) { req.r.rtm_protocol = RTPROT_BOOT; @@ -1588,9 +1589,14 @@ static int iproute_modify(int cmd, unsigned int flags, int argc, char **argv) req.r.rtm_type = RTN_UNICAST; if (echo_request) - return rtnl_echo_talk(&rth, &req.n, json, print_route); + ret = rtnl_echo_talk(&rth, &req.n, json, print_route); + else + ret = rtnl_talk(&rth, &req.n, NULL); + + if (ret) + return -2; - return rtnl_talk(&rth, &req.n, NULL); + return 0; } static int iproute_flush_cache(void) diff --git a/ip/iprule.c b/ip/iprule.c index 8f7504253..8e5a2287c 100644 --- a/ip/iprule.c +++ b/ip/iprule.c @@ -787,6 +787,7 @@ static int iprule_modify(int cmd, int argc, char **argv) .frh.family = preferred_family, .frh.action = FR_ACT_UNSPEC, }; + int ret; if (cmd == RTM_NEWRULE) { if (argc == 0) { @@ -1017,9 +1018,14 @@ static int iprule_modify(int cmd, int argc, char **argv) req.frh.table = RT_TABLE_MAIN; if (echo_request) - return rtnl_echo_talk(&rth, &req.n, json, print_rule); + ret = rtnl_echo_talk(&rth, &req.n, json, print_rule); + else + ret = rtnl_talk(&rth, &req.n, NULL); + + if (ret) + return -2; - return rtnl_talk(&rth, &req.n, NULL); + return 0; } int do_iprule(int argc, char **argv)