1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (c) 2018 Facebook
3 #include <test_progs.h>
5 static int duration
= 0;
8 const char sec_name
[32];
11 enum bpf_prog_type prog_type
;
12 enum bpf_attach_type expected_attach_type
;
16 enum bpf_attach_type attach_type
;
20 static struct sec_name_test tests
[] = {
21 {"InvAliD", {-ESRCH
, 0, 0}, {-EINVAL
, 0} },
22 {"cgroup", {-ESRCH
, 0, 0}, {-EINVAL
, 0} },
23 {"socket", {0, BPF_PROG_TYPE_SOCKET_FILTER
, 0}, {-EINVAL
, 0} },
24 {"kprobe/", {0, BPF_PROG_TYPE_KPROBE
, 0}, {-EINVAL
, 0} },
25 {"uprobe/", {0, BPF_PROG_TYPE_KPROBE
, 0}, {-EINVAL
, 0} },
26 {"kretprobe/", {0, BPF_PROG_TYPE_KPROBE
, 0}, {-EINVAL
, 0} },
27 {"uretprobe/", {0, BPF_PROG_TYPE_KPROBE
, 0}, {-EINVAL
, 0} },
28 {"classifier", {0, BPF_PROG_TYPE_SCHED_CLS
, 0}, {-EINVAL
, 0} },
29 {"action", {0, BPF_PROG_TYPE_SCHED_ACT
, 0}, {-EINVAL
, 0} },
30 {"tracepoint/", {0, BPF_PROG_TYPE_TRACEPOINT
, 0}, {-EINVAL
, 0} },
31 {"tp/", {0, BPF_PROG_TYPE_TRACEPOINT
, 0}, {-EINVAL
, 0} },
34 {0, BPF_PROG_TYPE_RAW_TRACEPOINT
, 0},
37 {"raw_tp/", {0, BPF_PROG_TYPE_RAW_TRACEPOINT
, 0}, {-EINVAL
, 0} },
38 {"xdp", {0, BPF_PROG_TYPE_XDP
, BPF_XDP
}, {0, BPF_XDP
} },
39 {"perf_event", {0, BPF_PROG_TYPE_PERF_EVENT
, 0}, {-EINVAL
, 0} },
40 {"lwt_in", {0, BPF_PROG_TYPE_LWT_IN
, 0}, {-EINVAL
, 0} },
41 {"lwt_out", {0, BPF_PROG_TYPE_LWT_OUT
, 0}, {-EINVAL
, 0} },
42 {"lwt_xmit", {0, BPF_PROG_TYPE_LWT_XMIT
, 0}, {-EINVAL
, 0} },
43 {"lwt_seg6local", {0, BPF_PROG_TYPE_LWT_SEG6LOCAL
, 0}, {-EINVAL
, 0} },
46 {0, BPF_PROG_TYPE_CGROUP_SKB
, BPF_CGROUP_INET_INGRESS
},
47 {0, BPF_CGROUP_INET_INGRESS
},
51 {0, BPF_PROG_TYPE_CGROUP_SKB
, BPF_CGROUP_INET_EGRESS
},
52 {0, BPF_CGROUP_INET_EGRESS
},
54 {"cgroup/skb", {0, BPF_PROG_TYPE_CGROUP_SKB
, 0}, {-EINVAL
, 0} },
57 {0, BPF_PROG_TYPE_CGROUP_SOCK
, BPF_CGROUP_INET_SOCK_CREATE
},
58 {0, BPF_CGROUP_INET_SOCK_CREATE
},
62 {0, BPF_PROG_TYPE_CGROUP_SOCK
, BPF_CGROUP_INET4_POST_BIND
},
63 {0, BPF_CGROUP_INET4_POST_BIND
},
67 {0, BPF_PROG_TYPE_CGROUP_SOCK
, BPF_CGROUP_INET6_POST_BIND
},
68 {0, BPF_CGROUP_INET6_POST_BIND
},
72 {0, BPF_PROG_TYPE_CGROUP_DEVICE
, BPF_CGROUP_DEVICE
},
73 {0, BPF_CGROUP_DEVICE
},
77 {0, BPF_PROG_TYPE_SOCK_OPS
, BPF_CGROUP_SOCK_OPS
},
78 {0, BPF_CGROUP_SOCK_OPS
},
81 "sk_skb/stream_parser",
82 {0, BPF_PROG_TYPE_SK_SKB
, BPF_SK_SKB_STREAM_PARSER
},
83 {0, BPF_SK_SKB_STREAM_PARSER
},
86 "sk_skb/stream_verdict",
87 {0, BPF_PROG_TYPE_SK_SKB
, BPF_SK_SKB_STREAM_VERDICT
},
88 {0, BPF_SK_SKB_STREAM_VERDICT
},
90 {"sk_skb", {0, BPF_PROG_TYPE_SK_SKB
, 0}, {-EINVAL
, 0} },
93 {0, BPF_PROG_TYPE_SK_MSG
, BPF_SK_MSG_VERDICT
},
94 {0, BPF_SK_MSG_VERDICT
},
98 {0, BPF_PROG_TYPE_LIRC_MODE2
, BPF_LIRC_MODE2
},
103 {0, BPF_PROG_TYPE_FLOW_DISSECTOR
, BPF_FLOW_DISSECTOR
},
104 {0, BPF_FLOW_DISSECTOR
},
108 {0, BPF_PROG_TYPE_CGROUP_SOCK_ADDR
, BPF_CGROUP_INET4_BIND
},
109 {0, BPF_CGROUP_INET4_BIND
},
113 {0, BPF_PROG_TYPE_CGROUP_SOCK_ADDR
, BPF_CGROUP_INET6_BIND
},
114 {0, BPF_CGROUP_INET6_BIND
},
118 {0, BPF_PROG_TYPE_CGROUP_SOCK_ADDR
, BPF_CGROUP_INET4_CONNECT
},
119 {0, BPF_CGROUP_INET4_CONNECT
},
123 {0, BPF_PROG_TYPE_CGROUP_SOCK_ADDR
, BPF_CGROUP_INET6_CONNECT
},
124 {0, BPF_CGROUP_INET6_CONNECT
},
128 {0, BPF_PROG_TYPE_CGROUP_SOCK_ADDR
, BPF_CGROUP_UDP4_SENDMSG
},
129 {0, BPF_CGROUP_UDP4_SENDMSG
},
133 {0, BPF_PROG_TYPE_CGROUP_SOCK_ADDR
, BPF_CGROUP_UDP6_SENDMSG
},
134 {0, BPF_CGROUP_UDP6_SENDMSG
},
138 {0, BPF_PROG_TYPE_CGROUP_SOCK_ADDR
, BPF_CGROUP_UDP4_RECVMSG
},
139 {0, BPF_CGROUP_UDP4_RECVMSG
},
143 {0, BPF_PROG_TYPE_CGROUP_SOCK_ADDR
, BPF_CGROUP_UDP6_RECVMSG
},
144 {0, BPF_CGROUP_UDP6_RECVMSG
},
148 {0, BPF_PROG_TYPE_CGROUP_SYSCTL
, BPF_CGROUP_SYSCTL
},
149 {0, BPF_CGROUP_SYSCTL
},
153 {0, BPF_PROG_TYPE_CGROUP_SOCKOPT
, BPF_CGROUP_GETSOCKOPT
},
154 {0, BPF_CGROUP_GETSOCKOPT
},
158 {0, BPF_PROG_TYPE_CGROUP_SOCKOPT
, BPF_CGROUP_SETSOCKOPT
},
159 {0, BPF_CGROUP_SETSOCKOPT
},
163 static void test_prog_type_by_name(const struct sec_name_test
*test
)
165 enum bpf_attach_type expected_attach_type
;
166 enum bpf_prog_type prog_type
;
169 rc
= libbpf_prog_type_by_name(test
->sec_name
, &prog_type
,
170 &expected_attach_type
);
172 CHECK(rc
!= test
->expected_load
.rc
, "check_code",
173 "prog: unexpected rc=%d for %s\n", rc
, test
->sec_name
);
178 CHECK(prog_type
!= test
->expected_load
.prog_type
, "check_prog_type",
179 "prog: unexpected prog_type=%d for %s\n",
180 prog_type
, test
->sec_name
);
182 CHECK(expected_attach_type
!= test
->expected_load
.expected_attach_type
,
183 "check_attach_type", "prog: unexpected expected_attach_type=%d for %s\n",
184 expected_attach_type
, test
->sec_name
);
187 static void test_attach_type_by_name(const struct sec_name_test
*test
)
189 enum bpf_attach_type attach_type
;
192 rc
= libbpf_attach_type_by_name(test
->sec_name
, &attach_type
);
194 CHECK(rc
!= test
->expected_attach
.rc
, "check_ret",
195 "attach: unexpected rc=%d for %s\n", rc
, test
->sec_name
);
200 CHECK(attach_type
!= test
->expected_attach
.attach_type
,
201 "check_attach_type", "attach: unexpected attach_type=%d for %s\n",
202 attach_type
, test
->sec_name
);
205 void test_section_names(void)
209 for (i
= 0; i
< ARRAY_SIZE(tests
); ++i
) {
210 struct sec_name_test
*test
= &tests
[i
];
212 test_prog_type_by_name(test
);
213 test_attach_type_by_name(test
);