diff options
Diffstat (limited to 'samples/bpf/sock_example.c')
-rw-r--r-- | samples/bpf/sock_example.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/samples/bpf/sock_example.c b/samples/bpf/sock_example.c index 28b60baa9fa8..6fc6e193ef1b 100644 --- a/samples/bpf/sock_example.c +++ b/samples/bpf/sock_example.c @@ -27,6 +27,9 @@ #include <linux/ip.h> #include <stddef.h> #include "libbpf.h" +#include "sock_example.h" + +char bpf_log_buf[BPF_LOG_BUF_SIZE]; static int test_sock(void) { @@ -54,9 +57,10 @@ static int test_sock(void) BPF_MOV64_IMM(BPF_REG_0, 0), /* r0 = 0 */ BPF_EXIT_INSN(), }; + size_t insns_cnt = sizeof(prog) / sizeof(struct bpf_insn); - prog_fd = bpf_prog_load(BPF_PROG_TYPE_SOCKET_FILTER, prog, sizeof(prog), - "GPL", 0); + prog_fd = bpf_load_program(BPF_PROG_TYPE_SOCKET_FILTER, prog, insns_cnt, + "GPL", 0, bpf_log_buf, BPF_LOG_BUF_SIZE); if (prog_fd < 0) { printf("failed to load prog '%s'\n", strerror(errno)); goto cleanup; @@ -72,13 +76,13 @@ static int test_sock(void) for (i = 0; i < 10; i++) { key = IPPROTO_TCP; - assert(bpf_lookup_elem(map_fd, &key, &tcp_cnt) == 0); + assert(bpf_map_lookup_elem(map_fd, &key, &tcp_cnt) == 0); key = IPPROTO_UDP; - assert(bpf_lookup_elem(map_fd, &key, &udp_cnt) == 0); + assert(bpf_map_lookup_elem(map_fd, &key, &udp_cnt) == 0); key = IPPROTO_ICMP; - assert(bpf_lookup_elem(map_fd, &key, &icmp_cnt) == 0); + assert(bpf_map_lookup_elem(map_fd, &key, &icmp_cnt) == 0); printf("TCP %lld UDP %lld ICMP %lld packets\n", tcp_cnt, udp_cnt, icmp_cnt); |