1 // SPDX-License-Identifier: GPL-2.0
4 #include <test_progs.h>
5 #include <network_helpers.h>
7 #include <linux/sched.h>
8 #include <sys/syscall.h>
10 #include "test_pkt_md_access.skel.h"
11 #include "test_trace_ext.skel.h"
12 #include "test_trace_ext_tracing.skel.h"
14 static __u32 duration
;
16 void test_trace_ext(void)
18 struct test_pkt_md_access
*skel_pkt
= NULL
;
19 struct test_trace_ext_tracing
*skel_trace
= NULL
;
20 struct test_trace_ext_tracing__bss
*bss_trace
;
21 struct test_trace_ext
*skel_ext
= NULL
;
22 struct test_trace_ext__bss
*bss_ext
;
23 int err
, pkt_fd
, ext_fd
;
24 struct bpf_program
*prog
;
29 /* open/load/attach test_pkt_md_access */
30 skel_pkt
= test_pkt_md_access__open_and_load();
31 if (CHECK(!skel_pkt
, "setup", "classifier/test_pkt_md_access open failed\n"))
34 err
= test_pkt_md_access__attach(skel_pkt
);
35 if (CHECK(err
, "setup", "classifier/test_pkt_md_access attach failed: %d\n", err
))
38 prog
= skel_pkt
->progs
.test_pkt_md_access
;
39 pkt_fd
= bpf_program__fd(prog
);
42 skel_ext
= test_trace_ext__open();
43 if (CHECK(!skel_ext
, "setup", "freplace/test_pkt_md_access open failed\n"))
46 /* set extension's attach target - test_pkt_md_access */
47 prog
= skel_ext
->progs
.test_pkt_md_access_new
;
48 bpf_program__set_attach_target(prog
, pkt_fd
, "test_pkt_md_access");
50 /* load/attach extension */
51 err
= test_trace_ext__load(skel_ext
);
52 if (CHECK(err
, "setup", "freplace/test_pkt_md_access load failed\n")) {
53 libbpf_strerror(err
, buf
, sizeof(buf
));
54 fprintf(stderr
, "%s\n", buf
);
58 err
= test_trace_ext__attach(skel_ext
);
59 if (CHECK(err
, "setup", "freplace/test_pkt_md_access attach failed: %d\n", err
))
62 prog
= skel_ext
->progs
.test_pkt_md_access_new
;
63 ext_fd
= bpf_program__fd(prog
);
66 skel_trace
= test_trace_ext_tracing__open();
67 if (CHECK(!skel_trace
, "setup", "tracing/test_pkt_md_access_new open failed\n"))
70 /* set tracing's attach target - fentry */
71 prog
= skel_trace
->progs
.fentry
;
72 bpf_program__set_attach_target(prog
, ext_fd
, "test_pkt_md_access_new");
74 /* set tracing's attach target - fexit */
75 prog
= skel_trace
->progs
.fexit
;
76 bpf_program__set_attach_target(prog
, ext_fd
, "test_pkt_md_access_new");
78 /* load/attach tracing */
79 err
= test_trace_ext_tracing__load(skel_trace
);
80 if (CHECK(err
, "setup", "tracing/test_pkt_md_access_new load failed\n")) {
81 libbpf_strerror(err
, buf
, sizeof(buf
));
82 fprintf(stderr
, "%s\n", buf
);
86 err
= test_trace_ext_tracing__attach(skel_trace
);
87 if (CHECK(err
, "setup", "tracing/test_pkt_md_access_new attach failed: %d\n", err
))
90 /* trigger the test */
91 err
= bpf_prog_test_run(pkt_fd
, 1, &pkt_v4
, sizeof(pkt_v4
),
92 NULL
, NULL
, &retval
, &duration
);
93 CHECK(err
|| retval
, "run", "err %d errno %d retval %d\n", err
, errno
, retval
);
95 bss_ext
= skel_ext
->bss
;
96 bss_trace
= skel_trace
->bss
;
98 len
= bss_ext
->ext_called
;
100 CHECK(bss_ext
->ext_called
== 0,
101 "check", "failed to trigger freplace/test_pkt_md_access\n");
102 CHECK(bss_trace
->fentry_called
!= len
,
103 "check", "failed to trigger fentry/test_pkt_md_access_new\n");
104 CHECK(bss_trace
->fexit_called
!= len
,
105 "check", "failed to trigger fexit/test_pkt_md_access_new\n");
108 test_trace_ext_tracing__destroy(skel_trace
);
109 test_trace_ext__destroy(skel_ext
);
110 test_pkt_md_access__destroy(skel_pkt
);