Skip to content

Commit 7c63158

Browse files
christycyleeNobody
authored andcommitted
libbpf: rename bpf_prog_attach_xattr to bpf_prog_attach_opts
All xattr APIs are being dropped, let's converge to the convention used in high-level APIs and rename bpf_prog_attach_xattr to bpf_prog_attach_opts. [0] Closes: libbpf/libbpf#285 Signed-off-by: Christy Lee <christylee@fb.com>
1 parent 2427c00 commit 7c63158

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

tools/lib/bpf/bpf.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -754,10 +754,10 @@ int bpf_prog_attach(int prog_fd, int target_fd, enum bpf_attach_type type,
754754
.flags = flags,
755755
);
756756

757-
return bpf_prog_attach_xattr(prog_fd, target_fd, type, &opts);
757+
return bpf_prog_attach_opts(prog_fd, target_fd, type, &opts);
758758
}
759759

760-
int bpf_prog_attach_xattr(int prog_fd, int target_fd,
760+
int bpf_prog_attach_opts(int prog_fd, int target_fd,
761761
enum bpf_attach_type type,
762762
const struct bpf_prog_attach_opts *opts)
763763
{
@@ -778,6 +778,13 @@ int bpf_prog_attach_xattr(int prog_fd, int target_fd,
778778
return libbpf_err_errno(ret);
779779
}
780780

781+
int bpf_prog_attach_xattr(int prog_fd, int target_fd,
782+
enum bpf_attach_type type,
783+
const struct bpf_prog_attach_opts *opts)
784+
{
785+
return bpf_prog_attach_opts(prog_fd, target_fd, type, opts);
786+
}
787+
781788
int bpf_prog_detach(int target_fd, enum bpf_attach_type type)
782789
{
783790
union bpf_attr attr;

tools/lib/bpf/bpf.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,10 @@ struct bpf_prog_attach_opts {
280280

281281
LIBBPF_API int bpf_prog_attach(int prog_fd, int attachable_fd,
282282
enum bpf_attach_type type, unsigned int flags);
283+
LIBBPF_API int bpf_prog_attach_opts(int prog_fd, int attachable_fd,
284+
enum bpf_attach_type type,
285+
const struct bpf_prog_attach_opts *opts);
286+
LIBBPF_DEPRECATED_SINCE(0, 8, "use bpf_prog_attach_opts() instead")
283287
LIBBPF_API int bpf_prog_attach_xattr(int prog_fd, int attachable_fd,
284288
enum bpf_attach_type type,
285289
const struct bpf_prog_attach_opts *opts);

tools/lib/bpf/libbpf.map

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ LIBBPF_0.0.8 {
246246
bpf_link__update_program;
247247
bpf_link_create;
248248
bpf_link_update;
249+
bpf_prog_attach_opts;
249250
bpf_map__set_initial_value;
250251
bpf_program__attach_cgroup;
251252
bpf_program__attach_lsm;

tools/testing/selftests/bpf/prog_tests/cgroup_attach_multi.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,45 +194,45 @@ void serial_test_cgroup_attach_multi(void)
194194

195195
attach_opts.flags = BPF_F_ALLOW_OVERRIDE | BPF_F_REPLACE;
196196
attach_opts.replace_prog_fd = allow_prog[0];
197-
if (CHECK(!bpf_prog_attach_xattr(allow_prog[6], cg1,
197+
if (CHECK(!bpf_prog_attach_opts(allow_prog[6], cg1,
198198
BPF_CGROUP_INET_EGRESS, &attach_opts),
199199
"fail_prog_replace_override", "unexpected success\n"))
200200
goto err;
201201
CHECK_FAIL(errno != EINVAL);
202202

203203
attach_opts.flags = BPF_F_REPLACE;
204-
if (CHECK(!bpf_prog_attach_xattr(allow_prog[6], cg1,
204+
if (CHECK(!bpf_prog_attach_opts(allow_prog[6], cg1,
205205
BPF_CGROUP_INET_EGRESS, &attach_opts),
206206
"fail_prog_replace_no_multi", "unexpected success\n"))
207207
goto err;
208208
CHECK_FAIL(errno != EINVAL);
209209

210210
attach_opts.flags = BPF_F_ALLOW_MULTI | BPF_F_REPLACE;
211211
attach_opts.replace_prog_fd = -1;
212-
if (CHECK(!bpf_prog_attach_xattr(allow_prog[6], cg1,
212+
if (CHECK(!bpf_prog_attach_opts(allow_prog[6], cg1,
213213
BPF_CGROUP_INET_EGRESS, &attach_opts),
214214
"fail_prog_replace_bad_fd", "unexpected success\n"))
215215
goto err;
216216
CHECK_FAIL(errno != EBADF);
217217

218218
/* replacing a program that is not attached to cgroup should fail */
219219
attach_opts.replace_prog_fd = allow_prog[3];
220-
if (CHECK(!bpf_prog_attach_xattr(allow_prog[6], cg1,
220+
if (CHECK(!bpf_prog_attach_opts(allow_prog[6], cg1,
221221
BPF_CGROUP_INET_EGRESS, &attach_opts),
222222
"fail_prog_replace_no_ent", "unexpected success\n"))
223223
goto err;
224224
CHECK_FAIL(errno != ENOENT);
225225

226226
/* replace 1st from the top program */
227227
attach_opts.replace_prog_fd = allow_prog[0];
228-
if (CHECK(bpf_prog_attach_xattr(allow_prog[6], cg1,
228+
if (CHECK(bpf_prog_attach_opts(allow_prog[6], cg1,
229229
BPF_CGROUP_INET_EGRESS, &attach_opts),
230230
"prog_replace", "errno=%d\n", errno))
231231
goto err;
232232

233233
/* replace program with itself */
234234
attach_opts.replace_prog_fd = allow_prog[6];
235-
if (CHECK(bpf_prog_attach_xattr(allow_prog[6], cg1,
235+
if (CHECK(bpf_prog_attach_opts(allow_prog[6], cg1,
236236
BPF_CGROUP_INET_EGRESS, &attach_opts),
237237
"prog_replace", "errno=%d\n", errno))
238238
goto err;

0 commit comments

Comments
 (0)