Received: by 10.223.176.46 with SMTP id f43csp169131wra; Thu, 18 Jan 2018 15:37:35 -0800 (PST) X-Google-Smtp-Source: ACJfBouLVgBaUJjSrG9ln/YGjmPJzod6Fe1UvvquQHseqLcqrvShEaPpL+bo/raj0qksJn6K3EyC X-Received: by 10.99.188.17 with SMTP id q17mr24742451pge.43.1516318654936; Thu, 18 Jan 2018 15:37:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516318654; cv=none; d=google.com; s=arc-20160816; b=qtKkQZRqaX7M2Iwb1V8P4wBrWxR8f/+Rt4fl4iD5Ubo7lxAukkOGizpubs/IscPe8+ bY2yQdFWVbJuLK2B+YlDiu7ZKmlEH9R1hWMgwMrTdO233pBLrz9M7ePQ3yr6hM9k58u7 WyEEFVhlQjQtJfahipk+oOn5SEJ3W3/YOyf/zw3Hzvzq8sdqBTWNx7nRXsEYNbC0/GlB DfdYGXsYC7ftE21IH5nX4cs6o+Z2RTp5frteCpaQBdw62EpM2GXsfVtzaKtder73UGrY 1Tus2YaciM45dp7YNHq7pgX3uhIM/7xUi7OA6gO7TpV5c/aYsvoiS1XSclrSzrcL9iPS bfJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:date:cc:to:from:subject:message-id :arc-authentication-results; bh=cisMLOly+dIBivdOysQwxFPyZqgka+39wQlx04m6R6U=; b=n10aWIopm9tvbm6GyIGXsIIiEGLZjOoxKUS/BOJBHEEKowI+/UoaQORSRa/29SUOAp mCGstHJp1C3H0+InkPLr9Ub72OOAB6Kf1yqWq9EIs2mo6jfODBMLUpT7iRzA2fmWKsrd Ozc8spmk0UCh5Bc//fMJ+oX0tlXfk5+1zTU0ulb1ZpRVL5A77/X+qqhf4Y6G+Rfau8Pq 9SatdSjJVgnMAntMm9KgUaE09T5jQb/PC2xdXkUbXlIKnBv4E5ptxEi6hZNWQ5uM8dqR 4WiE4hZ9sh8jggNeNCvOLpTdCGzBdAdeAXjRxCjYG4yvc43hEFrGZOauTzrrbvjL2WdI pR6g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d1si7138826pge.538.2018.01.18.15.37.20; Thu, 18 Jan 2018 15:37:34 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932843AbeARXf6 (ORCPT + 99 others); Thu, 18 Jan 2018 18:35:58 -0500 Received: from home.regit.org ([37.187.126.138]:43536 "EHLO home.regit.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932753AbeARXfw (ORCPT ); Thu, 18 Jan 2018 18:35:52 -0500 Received: from va-67-76-165-20.dyn.embarqhsd.net ([67.76.165.20] helo=tiger2) by home.regit.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1ecJie-0004r9-FQ; Fri, 19 Jan 2018 00:35:41 +0100 Message-ID: <1516318537.24936.7.camel@regit.org> Subject: Re: [PATCH bpf-next v5 2/4] libbpf: add error reporting in XDP From: Eric Leblond To: Daniel Borkmann , Toshiaki Makita , Philippe Ombredanne Cc: Alexei Starovoitov , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Thomas Graf Date: Fri, 19 Jan 2018 00:35:37 +0100 In-Reply-To: <10a2c572-9f2e-8cad-675d-b960c215c557@iogearbox.net> References: <1515023944.7473.7.camel@regit.org> <20180104082149.13758-1-eric@regit.org> <20180104082149.13758-2-eric@regit.org> <10a2c572-9f2e-8cad-675d-b960c215c557@iogearbox.net> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.26.3-1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-Spam-Score: -1.0 (-) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, Sorry for the delay, missed the mail. On Sat, 2018-01-06 at 22:16 +0100, Daniel Borkmann wrote: > 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. Indeed, fixing that. > > + 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? Yes all netlink_ack usage I have seen are using the negative value of the error. Fixing that too. BR, -- Eric Leblond Blog: https://home.regit.org/