On Fri, Aug 13, 2021 at 10:23 AM Yonghong Song <yhs@xxxxxx> wrote: > > > > 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, just please don't use bpf_load_program and bpf_prog_load, use proper bpf_object APIs or BPF skeleton for loading programs. > prog, insns_cnt, > > They should provide an example how to attach a socket_filter program > to a socket. You can probably also look at recently added bpf_tc_* APIs in tools/testing/selftests/bpf/prog_tests/tc_bpf.c. I've CC'ed Kumar who added those APIs recently. > > > > > Thanks > > Mohan > >