[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <db14a227-1d5e-ed3a-9ada-ecf99b526bf6@gmail.com>
Date: Mon, 2 Nov 2020 08:41:09 -0700
From: David Ahern <dsahern@...il.com>
To: Hangbin Liu <haliu@...hat.com>,
Stephen Hemminger <stephen@...workplumber.org>,
Daniel Borkmann <daniel@...earbox.net>,
Alexei Starovoitov <ast@...nel.org>
Cc: Martin KaFai Lau <kafai@...com>, Song Liu <songliubraving@...com>,
Yonghong Song <yhs@...com>, David Miller <davem@...emloft.net>,
Jesper Dangaard Brouer <brouer@...hat.com>,
netdev@...r.kernel.org, bpf@...r.kernel.org,
Jiri Benc <jbenc@...hat.com>,
Andrii Nakryiko <andrii@...nel.org>,
Toke Høiland-Jørgensen
<toke@...hat.com>
Subject: Re: [PATCHv3 iproute2-next 3/5] lib: add libbpf support
On 10/29/20 9:11 AM, Hangbin Liu wrote:
> diff --git a/ip/ipvrf.c b/ip/ipvrf.c
> index 33150ac2..afaf1de7 100644
> --- a/ip/ipvrf.c
> +++ b/ip/ipvrf.c
> @@ -28,8 +28,14 @@
> #include "rt_names.h"
> #include "utils.h"
> #include "ip_common.h"
> +
> #include "bpf_util.h"
>
> +#ifdef HAVE_LIBBPF
> +#include <bpf/bpf.h>
> +#include <bpf/libbpf.h>
> +#endif
> +
> #define CGRP_PROC_FILE "/cgroup.procs"
>
> static struct link_filter vrf_filter;
> @@ -256,8 +262,13 @@ static int prog_load(int idx)
> BPF_EXIT_INSN(),
> };
>
> +#ifdef HAVE_LIBBPF
> + return bpf_load_program(BPF_PROG_TYPE_CGROUP_SOCK, prog, sizeof(prog),
> + "GPL", 0, bpf_log_buf, sizeof(bpf_log_buf));
> +#else
> return bpf_prog_load_buf(BPF_PROG_TYPE_CGROUP_SOCK, prog, sizeof(prog),
> "GPL", bpf_log_buf, sizeof(bpf_log_buf));
> +#endif
> }
>
> static int vrf_configure_cgroup(const char *path, int ifindex)
> @@ -288,7 +299,11 @@ static int vrf_configure_cgroup(const char *path, int ifindex)
> goto out;
> }
>
> +#ifdef HAVE_LIBBPF
> + if (bpf_prog_attach(prog_fd, cg_fd, BPF_CGROUP_INET_SOCK_CREATE, 0)) {
> +#else
> if (bpf_prog_attach_fd(prog_fd, cg_fd, BPF_CGROUP_INET_SOCK_CREATE)) {
> +#endif
> fprintf(stderr, "Failed to attach prog to cgroup: '%s'\n",
> strerror(errno));
> goto out;
I would prefer to have these #ifdef .. #endif checks consolidated in the
lib code. Create a bpf_compat file for these. e.g.,
int bpf_program_load(enum bpf_prog_type type, const struct bpf_insn *insns,
size_t size_insns, const char *license, char *log,
size_t size_log)
{
+#ifdef HAVE_LIBBPF
+ return bpf_load_program(BPF_PROG_TYPE_CGROUP_SOCK, prog, sizeof(prog),
+ "GPL", 0, bpf_log_buf, sizeof(bpf_log_buf));
+#else
return bpf_prog_load_buf(BPF_PROG_TYPE_CGROUP_SOCK, prog, sizeof(prog),
"GPL", bpf_log_buf, sizeof(bpf_log_buf));
+#endif
}
Similarly for bpf_program_attach.
I think even the includes can be done once in bpf_util.h with a single
+#ifdef HAVE_LIBBPF
+#include <bpf/bpf.h>
+#include <bpf/libbpf.h>
+#endif
+
The iproute2_* functions added later in this patch can be in the compat
file as well.
Powered by blists - more mailing lists