From patchwork Sat Nov 9 00:00:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= X-Patchwork-Id: 1192326 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 478y380D8Jz9sPT for ; Sat, 9 Nov 2019 11:01:08 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729951AbfKIABF (ORCPT ); Fri, 8 Nov 2019 19:01:05 -0500 Received: from mx1.redhat.com ([209.132.183.28]:43447 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728714AbfKIABD (ORCPT ); Fri, 8 Nov 2019 19:01:03 -0500 Received: from mail-lf1-f69.google.com (mail-lf1-f69.google.com [209.85.167.69]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 78D99369AC for ; Sat, 9 Nov 2019 00:01:02 +0000 (UTC) Received: by mail-lf1-f69.google.com with SMTP id t6so1613015lfd.13 for ; Fri, 08 Nov 2019 16:01:02 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:date:message-id:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=+uTEROvAXIn7cfXeWKiRQvoN+m0g9SUDb6vRM4Q9nmw=; b=K6Ow5mKsXnCze/CueW8aCQ4eJh2YM+1Y08LWozbtPyIuuJcbHbH+8rFbA2grBuSX7S dhtFvxE3Dc52QzbMDwC2m7XmFym5Snlgegi3/Ps8paEMm9NNLefbVqYdjN6gY3MyQXYm l79Bs+ccuyK551KHkMozb+CMJw+puvoHMdAitHx74C4YSOXNIzowTVQZVYUZxfMtpbI/ V157FxGXRXeArPg+AFKsZ95ekWotEuXkfPVwVQ/37jxS5ZGeXbYAfQnVoXvrLeMxnEcY Z9G4mABbS7X2qFN9m/KEjk8AqA0+FSIJlNND8S+mRLxsBLb6Kk/pcpNMIxyxYQ7TfEez Bieg== X-Gm-Message-State: APjAAAVzxgQ5IBufLcAdiNWMPUgymsRRDbJGRGxDKVujmQWzD3FCibGi 1GODpG4en59k/qi4C3Psg4yg85tpBLnM5CwmE99gk8zNKzzAQ8aCT5gJEj66f8ryK0dsXPLw/tl MN3gEQzdMFE1FRRtB X-Received: by 2002:ac2:4243:: with SMTP id m3mr8294101lfl.24.1573257661019; Fri, 08 Nov 2019 16:01:01 -0800 (PST) X-Google-Smtp-Source: APXvYqxDwHhM4tgnFRifupGTocCo05Wf5BWkcj5RkRjmPSq8AGbXGdhvRmr5WpcPOUG+Y66lZCYzgw== X-Received: by 2002:ac2:4243:: with SMTP id m3mr8294095lfl.24.1573257660863; Fri, 08 Nov 2019 16:01:00 -0800 (PST) Received: from alrua-x1.borgediget.toke.dk (borgediget.toke.dk. [85.204.121.218]) by smtp.gmail.com with ESMTPSA id v21sm3126954lfe.68.2019.11.08.16.00.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Nov 2019 16:01:00 -0800 (PST) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id 1BAE71800CC; Sat, 9 Nov 2019 01:00:59 +0100 (CET) Subject: [PATCH bpf-next v3 4/6] libbpf: Use pr_warn() when printing netlink errors From: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= To: Daniel Borkmann Cc: Alexei Starovoitov , Martin KaFai Lau , Song Liu , Yonghong Song , Jesper Dangaard Brouer , Andrii Nakryiko , David Miller , netdev@vger.kernel.org, bpf@vger.kernel.org Date: Sat, 09 Nov 2019 01:00:59 +0100 Message-ID: <157325765904.27401.7758657875953932781.stgit@toke.dk> In-Reply-To: <157325765467.27401.1930972466188738545.stgit@toke.dk> References: <157325765467.27401.1930972466188738545.stgit@toke.dk> User-Agent: StGit/0.21 MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Toke Høiland-Jørgensen The netlink functions were using fprintf(stderr, ) directly to print out error messages, instead of going through the usual logging macros. This makes it impossible for the calling application to silence or redirect those error messages. Fix this by switching to pr_warn() in nlattr.c and netlink.c. Acked-by: Andrii Nakryiko Acked-by: David S. Miller Acked-by: Song Liu Signed-off-by: Toke Høiland-Jørgensen --- tools/lib/bpf/netlink.c | 3 ++- tools/lib/bpf/nlattr.c | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/tools/lib/bpf/netlink.c b/tools/lib/bpf/netlink.c index ce3ec81b71c0..a261df9cb488 100644 --- a/tools/lib/bpf/netlink.c +++ b/tools/lib/bpf/netlink.c @@ -12,6 +12,7 @@ #include "bpf.h" #include "libbpf.h" +#include "libbpf_internal.h" #include "nlattr.h" #ifndef SOL_NETLINK @@ -43,7 +44,7 @@ int libbpf_netlink_open(__u32 *nl_pid) if (setsockopt(sock, SOL_NETLINK, NETLINK_EXT_ACK, &one, sizeof(one)) < 0) { - fprintf(stderr, "Netlink error reporting not supported\n"); + pr_warn("Netlink error reporting not supported\n"); } if (bind(sock, (struct sockaddr *)&sa, sizeof(sa)) < 0) { diff --git a/tools/lib/bpf/nlattr.c b/tools/lib/bpf/nlattr.c index 1e69c0c8d413..8db44bbfc66d 100644 --- a/tools/lib/bpf/nlattr.c +++ b/tools/lib/bpf/nlattr.c @@ -8,6 +8,7 @@ #include #include "nlattr.h" +#include "libbpf_internal.h" #include #include #include @@ -121,8 +122,8 @@ int libbpf_nla_parse(struct nlattr *tb[], int maxtype, struct nlattr *head, } if (tb[type]) - fprintf(stderr, "Attribute of type %#x found multiple times in message, " - "previous attribute is being ignored.\n", type); + pr_warn("Attribute of type %#x found multiple times in message, " + "previous attribute is being ignored.\n", type); tb[type] = nla; } @@ -181,15 +182,14 @@ int libbpf_nla_dump_errormsg(struct nlmsghdr *nlh) if (libbpf_nla_parse(tb, NLMSGERR_ATTR_MAX, attr, alen, extack_policy) != 0) { - fprintf(stderr, - "Failed to parse extended error attributes\n"); + pr_warn("Failed to parse extended error attributes\n"); return 0; } if (tb[NLMSGERR_ATTR_MSG]) errmsg = (char *) libbpf_nla_data(tb[NLMSGERR_ATTR_MSG]); - fprintf(stderr, "Kernel error message: %s\n", errmsg); + pr_warn("Kernel error message: %s\n", errmsg); return 0; }