On 04/23/2018 04:56 AM, Wang Sheng-Hui wrote: > Sorry to trouble you! > > I run samples/bpf/sockex2 failed with > "Assertion `setsockopt(sock, SOL_SOCKET, SO_ATTACH_BPF, prog_fd, > sizeof(prog_fd[0])) == 0' failed." > > Then I run " strace ./sockex2" and got: > ... > bind(3, {sa_family=AF_PACKET, sll_protocol=htons(ETH_P_ALL), > sll_ifindex=if_nametoindex("lo"), sll_hatype=ARPHRD_NETROM, > sll_pkttype=PACKET_HOST, sll_halen=0}, 20) = 0 > setsockopt(3, SOL_SOCKET, SO_ATTACH_BPF, [0], 4) = -1 EINVAL (Invalid > argument) > write(2, "sockex2: /root/linux/samples/bpf"..., 156sockex2: > /root/linux/samples/bpf/sockex2_user.c:35: main: Assertion `setsockopt(sock, > SOL_SOCKET, SO_ATTACH_BPF, prog_fd, sizeof(prog_fd[0])) == 0' failed. > ) = 156 > mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = > 0x7fb8ec4bf000 > rt_sigprocmask(SIG_UNBLOCK, [ABRT], NULL, 8) = 0 > rt_sigprocmask(SIG_BLOCK, ~[RTMIN RT_1], [], 8) = 0 > getpid() = 3513 > gettid() = 3513 > tgkill(3513, 3513, SIGABRT) = 0 > rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0 > --- SIGABRT {si_signo=SIGABRT, si_code=SI_TKILL, si_pid=3513, si_uid=0} --- > +++ killed by SIGABRT +++ > Aborted
[...] bpf(BPF_MAP_CREATE, {map_type=BPF_MAP_TYPE_HASH, key_size=4, value_size=16, max_entries=1024}, 72) = 4 bpf(BPF_PROG_LOAD, {prog_type=BPF_PROG_TYPE_SOCKET_FILTER, insn_cnt=201, insns=0x2676cd0, license="GPL", log_level=0, log_size=0, log_buf=0, kern_version=0}, 72) = 5 close(3) = 0 socket(AF_PACKET, SOCK_RAW|SOCK_CLOEXEC|SOCK_NONBLOCK, 768) = 3 access("/proc/net", R_OK) = 0 access("/proc/net/unix", R_OK) = 0 socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0) = 6 ioctl(6, SIOCGIFINDEX, {ifr_name="lo", }) = 0 close(6) = 0 bind(3, {sa_family=AF_PACKET, sll_protocol=htons(ETH_P_ALL), sll_ifindex=if_nametoindex("lo"), sll_hatype=ARPHRD_NETROM, sll_pkttype=PACKET_HOST, sll_halen=0}, 20) = 0 setsockopt(3, SOL_SOCKET, SO_ATTACH_BPF, [5], 4) = 0 pipe2([6, 7], O_CLOEXEC) = 0 [...] Works fine for me. The EINVAL in your case comes from the 'setsockopt(3, SOL_SOCKET, SO_ATTACH_BPF, [0], 4)'. So you send fd 0 to SO_ATTACH_BPF, which is not a valid BPF fd and therefore bails out here. You might want to debug bpf_load.c why it's failing to load the program in your case, or check strace a bit further above where you do the map and prog creation (as I copied in my case). Cheers, Daniel