Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752849AbeAFVQa (ORCPT + 1 other); Sat, 6 Jan 2018 16:16:30 -0500 Received: from www62.your-server.de ([213.133.104.62]:33309 "EHLO www62.your-server.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751274AbeAFVQ3 (ORCPT ); Sat, 6 Jan 2018 16:16:29 -0500 Subject: Re: [PATCH bpf-next v5 2/4] libbpf: add error reporting in XDP To: Eric Leblond , Toshiaki Makita , Philippe Ombredanne Cc: Alexei Starovoitov , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Thomas Graf References: <1515023944.7473.7.camel@regit.org> <20180104082149.13758-1-eric@regit.org> <20180104082149.13758-2-eric@regit.org> From: Daniel Borkmann Message-ID: <10a2c572-9f2e-8cad-675d-b960c215c557@iogearbox.net> Date: Sat, 6 Jan 2018 22:16:22 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <20180104082149.13758-2-eric@regit.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Authenticated-Sender: daniel@iogearbox.net Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: On 01/04/2018 09:21 AM, Eric Leblond wrote: > Parse netlink ext attribute to get the error message returned by > the card. Code is partially take from libnl. > > Signed-off-by: Eric Leblond > Acked-by: Alexei Starovoitov > --- > samples/bpf/Makefile | 2 +- > tools/lib/bpf/Build | 2 +- > tools/lib/bpf/bpf.c | 10 ++- > tools/lib/bpf/nlattr.c | 187 +++++++++++++++++++++++++++++++++++++++++++++++++ > tools/lib/bpf/nlattr.h | 70 ++++++++++++++++++ > 5 files changed, 268 insertions(+), 3 deletions(-) > create mode 100644 tools/lib/bpf/nlattr.c > create mode 100644 tools/lib/bpf/nlattr.h > > diff --git a/samples/bpf/Makefile b/samples/bpf/Makefile > index 4fb944a7ecf8..c889ebcba9b3 100644 > --- a/samples/bpf/Makefile > +++ b/samples/bpf/Makefile > @@ -44,7 +44,7 @@ hostprogs-y += xdp_monitor > hostprogs-y += syscall_tp > > # Libbpf dependencies > -LIBBPF := ../../tools/lib/bpf/bpf.o > +LIBBPF := ../../tools/lib/bpf/bpf.o ../../tools/lib/bpf/nlattr.o > CGROUP_HELPERS := ../../tools/testing/selftests/bpf/cgroup_helpers.o > > test_lru_dist-objs := test_lru_dist.o $(LIBBPF) > diff --git a/tools/lib/bpf/Build b/tools/lib/bpf/Build > index d8749756352d..64c679d67109 100644 > --- a/tools/lib/bpf/Build > +++ b/tools/lib/bpf/Build > @@ -1 +1 @@ > -libbpf-y := libbpf.o bpf.o > +libbpf-y := libbpf.o bpf.o nlattr.o > diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c > index e6c61035b64c..10d71b9fdbd0 100644 > --- a/tools/lib/bpf/bpf.c > +++ b/tools/lib/bpf/bpf.c > @@ -26,6 +26,7 @@ > #include > #include "bpf.h" > #include "libbpf.h" > +#include "nlattr.h" > #include > #include > #include > @@ -440,6 +441,7 @@ int bpf_set_link_xdp_fd(int ifindex, int fd, __u32 flags) > struct nlmsghdr *nh; > struct nlmsgerr *err; > socklen_t addrlen; > + int one; Hmm, it's not initialized here to 1 ... > memset(&sa, 0, sizeof(sa)); > sa.nl_family = AF_NETLINK; > @@ -449,6 +451,11 @@ int bpf_set_link_xdp_fd(int ifindex, int fd, __u32 flags) > return -errno; > } > > + if (setsockopt(sock, SOL_NETLINK, NETLINK_EXT_ACK, > + &one, sizeof(one)) < 0) { ... so we turn it on by chance here. > + fprintf(stderr, "Netlink error reporting not supported\n"); > + } > + > if (bind(sock, (struct sockaddr *)&sa, sizeof(sa)) < 0) { > ret = -errno; > goto cleanup; > @@ -524,7 +531,8 @@ int bpf_set_link_xdp_fd(int ifindex, int fd, __u32 flags) > err = (struct nlmsgerr *)NLMSG_DATA(nh); > if (!err->error) > continue; > - ret = err->error; > + ret = -err->error; This one looks strange. Your prior patch added the 'ret = err->error' and this one negates it. Which variant is the correct version? From digging into the kernel code, my take is that 'ret = err->error' was the correct variant since it already holds the negative error code. Could you double check? > + nla_dump_errormsg(nh); > goto cleanup; > case NLMSG_DONE: > break; Thanks, Daniel