1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2020 Facebook */
6 #include <bpf/libbpf.h>
7 #include "test_progs.h"
8 #include "network_helpers.h"
9 #include "test_sk_storage_trace_itself.skel.h"
10 #include "test_sk_storage_tracing.skel.h"
12 #define LO_ADDR6 "::1"
13 #define TEST_COMM "test_progs"
17 __u32 last_notclose_state;
21 static struct test_sk_storage_tracing *skel;
22 static __u32 duration;
25 static int check_sk_stg(int sk_fd, __u32 expected_state)
30 err = bpf_map_lookup_elem(bpf_map__fd(skel->maps.sk_stg_map), &sk_fd,
32 if (!ASSERT_OK(err, "map_lookup(sk_stg_map)"))
35 if (!ASSERT_EQ(sk_stg.last_notclose_state, expected_state,
36 "last_notclose_state"))
39 if (!ASSERT_EQ(sk_stg.pid, my_pid, "pid"))
42 if (!ASSERT_STREQ(sk_stg.comm, skel->bss->task_comm, "task_comm"))
48 static void do_test(void)
50 int listen_fd = -1, passive_fd = -1, active_fd = -1, value = 1, err;
53 listen_fd = start_server(AF_INET6, SOCK_STREAM, LO_ADDR6, 0, 0);
54 if (CHECK(listen_fd == -1, "start_server",
55 "listen_fd:%d errno:%d\n", listen_fd, errno))
58 active_fd = connect_to_fd(listen_fd, 0);
59 if (CHECK(active_fd == -1, "connect_to_fd", "active_fd:%d errno:%d\n",
63 err = bpf_map_update_elem(bpf_map__fd(skel->maps.del_sk_stg_map),
64 &active_fd, &value, 0);
65 if (!ASSERT_OK(err, "map_update(del_sk_stg_map)"))
68 passive_fd = accept(listen_fd, NULL, 0);
69 if (CHECK(passive_fd == -1, "accept", "passive_fd:%d errno:%d\n",
73 shutdown(active_fd, SHUT_WR);
74 err = read(passive_fd, &abyte, 1);
75 if (!ASSERT_OK(err, "read(passive_fd)"))
78 shutdown(passive_fd, SHUT_WR);
79 err = read(active_fd, &abyte, 1);
80 if (!ASSERT_OK(err, "read(active_fd)"))
83 err = bpf_map_lookup_elem(bpf_map__fd(skel->maps.del_sk_stg_map),
85 if (!ASSERT_ERR(err, "map_lookup(del_sk_stg_map)"))
88 err = check_sk_stg(listen_fd, BPF_TCP_LISTEN);
89 if (!ASSERT_OK(err, "listen_fd sk_stg"))
92 err = check_sk_stg(active_fd, BPF_TCP_FIN_WAIT2);
93 if (!ASSERT_OK(err, "active_fd sk_stg"))
96 err = check_sk_stg(passive_fd, BPF_TCP_LAST_ACK);
97 ASSERT_OK(err, "passive_fd sk_stg");
102 if (passive_fd != -1)
108 void serial_test_sk_storage_tracing(void)
110 struct test_sk_storage_trace_itself *skel_itself;
115 skel_itself = test_sk_storage_trace_itself__open_and_load();
117 if (!ASSERT_NULL(skel_itself, "test_sk_storage_trace_itself")) {
118 test_sk_storage_trace_itself__destroy(skel_itself);
122 skel = test_sk_storage_tracing__open_and_load();
123 if (!ASSERT_OK_PTR(skel, "test_sk_storage_tracing"))
126 err = test_sk_storage_tracing__attach(skel);
127 if (!ASSERT_OK(err, "test_sk_storage_tracing__attach")) {
128 test_sk_storage_tracing__destroy(skel);
134 test_sk_storage_tracing__destroy(skel);