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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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:
> > David Ahern <dsahern@xxxxxxxxx> writes:
> > 
> >> On 10/22/20 9:38 PM, Hangbin Liu wrote:
> >>> 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




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux