Received: by 10.223.176.5 with SMTP id f5csp55955wra; Fri, 26 Jan 2018 17:25:17 -0800 (PST) X-Google-Smtp-Source: AH8x2244l/c02oNQSf9e6LquZh7txMq/mAb1gBbeQ76pFnGCmYcgj1hR5YZWLXns1fjaDYDqZCjs X-Received: by 2002:a17:902:b212:: with SMTP id t18-v6mr14957684plr.293.1517016317122; Fri, 26 Jan 2018 17:25:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517016317; cv=none; d=google.com; s=arc-20160816; b=A62qkO1oGzVODf9EMfWGrw/Ha9ZW7vvljJJ6KV5/jS28zBRLOT44HgrUGdQG11pjmu Njkypuqt5SptMezYDXGyH0r6lkJjnkNPhoykMgPBjx5wKDrpTPRwapE3cr5S2pI7fpqI c4aBId6EiQnv9Wf8TOq/bly6AdBTDSDsn7S0nn7cUqb1uWq/guzdQVNAJdR25OmxCH5z 61csdgaVIWwdt4MQ8LyD9EDEv6uiJNfHyCUkP0wK7oyLnu666QtDFcjCczAh5SABKlxP 8Y74K5IftjA8WLA6jCJViYnWLx3x+TvqJej2X9dMt46evfyKZ69sJoECdlw1M2DIriU+ lAAA== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=+crNKucWGCf6lkCAnRz9VaH4k6/24hr74sphamYtAek=; b=EISB6eHZbIoiS5G0LLyffuECbNdgaSuGUAjDBMNOnGb3mKfEyxC1JNXpY8y2u0Y0DQ JeXALQcUEZC+7W7w6L4H3qnbiA9f56O6Yhv8JPFAf3QTsF+eu32/tcF2aPpnVY+Yo0eI 4OzZYr/0mwZwuNvL1ngNcLzCm3WRKj0MH1lIKKI8GjU8La4PqQFunC/YxpXTxv/0tmtp Ia1U5shRJ+1lh00BVai1Co1fn2kn4xCbjWhobGNsJb8BMoPFjo/WkSpPf5To+D28DMlE 1wHKYsysdnacwORodI4RhbGEdm88ibhnHe0e6ypzL7V/b/7PlXf7qtm0feyc6n3QrpJL H6zg== 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 s133si3743684pgc.86.2018.01.26.17.24.31; Fri, 26 Jan 2018 17:25:17 -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 S1752158AbeA0BXl (ORCPT + 99 others); Fri, 26 Jan 2018 20:23:41 -0500 Received: from www62.your-server.de ([213.133.104.62]:57844 "EHLO www62.your-server.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751264AbeA0BXi (ORCPT ); Fri, 26 Jan 2018 20:23:38 -0500 Received: from [62.202.221.5] (helo=linux.home) by www62.your-server.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-SHA:256) (Exim 4.85_2) (envelope-from ) id 1efFDU-0007R1-HQ; Sat, 27 Jan 2018 02:23:36 +0100 Subject: Re: [PATCH bpf-next v7 2/5] libbpf: add function to setup XDP To: Eric Leblond Cc: alexei.starovoitov@gmail.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org References: <4dc597a1-5046-3805-eb81-03a23bf0acbb@iogearbox.net> <20180125000548.12320-1-eric@regit.org> <20180125000548.12320-3-eric@regit.org> From: Daniel Borkmann Message-ID: Date: Sat, 27 Jan 2018 02:23:36 +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: <20180125000548.12320-3-eric@regit.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Authenticated-Sender: daniel@iogearbox.net X-Virus-Scanned: Clear (ClamAV 0.99.2/24253/Thu Jan 25 02:22:43 2018) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 01/25/2018 01:05 AM, Eric Leblond wrote: > Most of the code is taken from set_link_xdp_fd() in bpf_load.c and > slightly modified to be library compliant. > > Signed-off-by: Eric Leblond > Acked-by: Alexei Starovoitov > --- > tools/lib/bpf/bpf.c | 127 +++++++++++++++++++++++++++++++++++++++++++++++++ > tools/lib/bpf/libbpf.c | 2 + > tools/lib/bpf/libbpf.h | 4 ++ > 3 files changed, 133 insertions(+) > > diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c > index 5128677e4117..749a447ec9ed 100644 > --- a/tools/lib/bpf/bpf.c > +++ b/tools/lib/bpf/bpf.c > @@ -25,6 +25,17 @@ > #include > #include > #include "bpf.h" > +#include "libbpf.h" > +#include "nlattr.h" > +#include Doesn't libbpf pull in already -I$(srctree)/tools/include/uapi? Seems the other headers don't need 'uapi/' path prefix. > +#include > +#include > + > +#ifndef IFLA_XDP_MAX > +#define IFLA_XDP 43 > +#define IFLA_XDP_FD 1 > +#define IFLA_XDP_FLAGS 3 > +#endif Hm, given we pull in tools/include/uapi/linux/netlink.h, shouldn't we also get include/uapi/linux/if_link.h dependency in here, so above ifdef workaround can be avoided? > /* > * When building perf, unistd.h is overridden. __NR_bpf is > @@ -46,7 +57,9 @@ > # endif > #endif > > +#ifndef min > #define min(x, y) ((x) < (y) ? (x) : (y)) > +#endif > > static inline __u64 ptr_to_u64(const void *ptr) > { > @@ -413,3 +426,117 @@ int bpf_obj_get_info_by_fd(int prog_fd, void *info, __u32 *info_len) > > return err; > } > + > +int bpf_set_link_xdp_fd(int ifindex, int fd, __u32 flags) > +{ > + struct sockaddr_nl sa; > + int sock, seq = 0, len, ret = -1; > + char buf[4096]; > + struct nlattr *nla, *nla_xdp; > + struct { [...]