From mboxrd@z Thu Jan 1 00:00:00 1970 From: Daniel Borkmann Subject: Re: [PATCH bpf-next v7 2/5] libbpf: add function to setup XDP Date: Sat, 27 Jan 2018 02:23:36 +0100 Message-ID: References: <4dc597a1-5046-3805-eb81-03a23bf0acbb@iogearbox.net> <20180125000548.12320-1-eric@regit.org> <20180125000548.12320-3-eric@regit.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Cc: alexei.starovoitov@gmail.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org To: Eric Leblond Return-path: 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 In-Reply-To: <20180125000548.12320-3-eric@regit.org> Content-Language: en-US Sender: netdev-owner@vger.kernel.org List-ID: 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 { [...]