1 // SPDX-License-Identifier: GPL-2.0-only
4 * Copyright 2020 Google LLC.
7 #include <test_progs.h>
8 #include <network_helpers.h>
10 void test_load_bytes_relative(void)
12 int server_fd
, cgroup_fd
, prog_fd
, map_fd
, client_fd
;
14 struct bpf_object
*obj
;
15 struct bpf_program
*prog
;
16 struct bpf_map
*test_result
;
22 cgroup_fd
= test__join_cgroup("/load_bytes_relative");
23 if (CHECK_FAIL(cgroup_fd
< 0))
26 server_fd
= start_server(AF_INET
, SOCK_STREAM
, NULL
, 0, 0);
27 if (CHECK_FAIL(server_fd
< 0))
30 err
= bpf_prog_load("./load_bytes_relative.o", BPF_PROG_TYPE_CGROUP_SKB
,
35 test_result
= bpf_object__find_map_by_name(obj
, "test_result");
36 if (CHECK_FAIL(!test_result
))
37 goto close_bpf_object
;
39 map_fd
= bpf_map__fd(test_result
);
41 goto close_bpf_object
;
43 prog
= bpf_object__find_program_by_name(obj
, "load_bytes_relative");
44 if (CHECK_FAIL(!prog
))
45 goto close_bpf_object
;
47 err
= bpf_prog_attach(prog_fd
, cgroup_fd
, BPF_CGROUP_INET_EGRESS
,
50 goto close_bpf_object
;
52 client_fd
= connect_to_fd(server_fd
, 0);
53 if (CHECK_FAIL(client_fd
< 0))
54 goto close_bpf_object
;
57 err
= bpf_map_lookup_elem(map_fd
, &map_key
, &map_value
);
59 goto close_bpf_object
;
61 CHECK(map_value
!= 1, "bpf", "bpf program returned failure");
64 bpf_object__close(obj
);