Thread (167 messages) 167 messages, 15 authors, 2020-12-01

Re: [PATCH iproute2-next 3/5] lib: add libbpf support

From: Hangbin Liu <hidden>
Date: 2020-10-26 08:56:30
Also in: bpf

Hi David,

On Sun, Oct 25, 2020 at 04:12:34PM -0600, David Ahern wrote:
On 10/25/20 9:13 AM, Toke Høiland-Jørgensen wrote:
quoted
David Ahern [off-list ref] writes:
quoted
On 10/22/20 9:38 PM, Hangbin Liu wrote:
quoted
Note: ip/ipvrf.c is not convert to use libbpf as it only encodes a few
instructions and load directly.
for completeness, libbpf should be able to load a program from a buffer
as well.
It can, but the particular use in ipvrf is just loading half a dozen
instructions defined inline in C - there's no object files, BTF or
anything. So why bother with going through libbpf in this case? The
actual attachment is using the existing code anyway...
actually, it already does: bpf_load_program
Thanks for this info. Do you want to convert ipvrf.c to:
@@ -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;
Thanks
Hangbin
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help