Re: libbpf attaching a raw socket

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

 





On 8/11/21 6:36 PM, Mohan Parthasarathy wrote:
Hi,

I looked in the samples and header files, but could not find an
example for this. How does one convert this from bcc to libbpf. This
is the userspace code.

bpf = BPF(src_file = "socket_filter.c", debug=0)
socket_filter = bpf.load_func("socket_filter", BPF.SOCKET_FILTER)
BPF.attach_raw_socket(socket_filter, "eth2")
socket_fd = socket_filter.sock

I can do the following to set the type:

err = bpf_program__set_socket_filter(obj);

Is there any sample I can follow or any header files where I can look
for attaching a socket to the bpf code.

There are a few examples in linux/samples/bpf directory:

[~/work/bpf-next/samples/bpf] grep SOCKET_F *.c
cookie_uid_helper_example.c: prog_fd = bpf_load_program(BPF_PROG_TYPE_SOCKET_FILTER, prog,
fds_example.c:          return bpf_load_program(BPF_PROG_TYPE_SOCKET_FILTER,
sockex1_user.c: if (bpf_prog_load(filename, BPF_PROG_TYPE_SOCKET_FILTER,
sockex2_user.c: if (bpf_prog_load(filename, BPF_PROG_TYPE_SOCKET_FILTER,
sock_example.c: prog_fd = bpf_load_program(BPF_PROG_TYPE_SOCKET_FILTER, prog, insns_cnt,

They should provide an example how to attach a socket_filter program
to a socket.


Thanks
Mohan




[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