From patchwork Mon Oct 12 13:55:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Engelhardt X-Patchwork-Id: 11832739 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F3C83C43457 for ; Mon, 12 Oct 2020 13:56:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BD8FE2076E for ; Mon, 12 Oct 2020 13:56:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390155AbgJLN4M (ORCPT ); Mon, 12 Oct 2020 09:56:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389652AbgJLN4A (ORCPT ); Mon, 12 Oct 2020 09:56:00 -0400 Received: from a3.inai.de (a3.inai.de [IPv6:2a01:4f8:10b:45d8::f5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 028F1C0613D0 for ; Mon, 12 Oct 2020 06:56:00 -0700 (PDT) Received: by a3.inai.de (Postfix, from userid 65534) id E74AE586342DF; Mon, 12 Oct 2020 15:55:56 +0200 (CEST) Received: from a4.inai.de (a4.inai.de [IPv6:2a01:4f8:10b:45d8::f8]) by a3.inai.de (Postfix) with ESMTP id 12BD9586342DD; Mon, 12 Oct 2020 15:55:56 +0200 (CEST) From: Jan Engelhardt To: stephen@networkplumber.org Cc: jengelh@inai.de, netdev@vger.kernel.org Subject: [iproute PATCH] ip: add error reporting when RTM_GETNSID failed Date: Mon, 12 Oct 2020 15:55:55 +0200 Message-Id: <20201012135555.6071-1-jengelh@inai.de> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org `ip addr` when run under qemu-user-riscv64, fails. This likely is due to qemu-5.1 not doing translation of RTM_GETNSID calls. Aborting ip completely is not helpful for the user however. This patch reworks the error handling. Before: rtest:/ # ip a 2: host0@if4: mtu 1500 qdisc noqueue state UP group default qlen 1000 request send failed: Operation not supported link/ether 46:3f:2d:88:3d:db brd ff:ff:ff:ff:ff:ffrtest:/ # Afterwards: rtest:/ # ip a 2: host0@if4: mtu 1500 qdisc noqueue state UP group default qlen 1000 rtnl_send(RTM_GETNSID): Operation not supported. Continuing anyway. link/ether 46:3f:2d:88:3d:db brd ff:ff:ff:ff:ff:ff link-netnsid 0 inet 192.168.72.147/28 brd 192.168.72.159 scope global host0 valid_lft forever preferred_lft forever inet6 fe80::443f:2dff:fe88:3ddb/64 scope link valid_lft forever preferred_lft forever rtest:/ # Signed-off-by: Jan Engelhardt --- ip/ipnetns.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ip/ipnetns.c b/ip/ipnetns.c index 46cc235b..e7a45653 100644 --- a/ip/ipnetns.c +++ b/ip/ipnetns.c @@ -78,6 +78,8 @@ static int ipnetns_have_nsid(void) if (have_rtnl_getnsid < 0) { fd = open("/proc/self/ns/net", O_RDONLY); if (fd < 0) { + fprintf(stderr, "/proc/self/ns/net: %s. " + "Continuing anyway.\n", strerror(errno)); have_rtnl_getnsid = 0; return 0; } @@ -85,8 +87,11 @@ static int ipnetns_have_nsid(void) addattr32(&req.n, 1024, NETNSA_FD, fd); if (rtnl_send(&rth, &req.n, req.n.nlmsg_len) < 0) { - perror("request send failed"); - exit(1); + fprintf(stderr, "rtnl_send(RTM_GETNSID): %s. " + "Continuing anyway.\n", strerror(errno)); + have_rtnl_getnsid = 0; + close(fd); + return 0; } rtnl_listen(&rth, ipnetns_accept_msg, NULL); close(fd);