1 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
2 /* Copyright (C) 2019 Netronome Systems, Inc. */
5 #include <bpf/libbpf.h>
8 int extra_prog_load_log_flags
= 0;
10 int bpf_prog_test_load(const char *file
, enum bpf_prog_type type
,
11 struct bpf_object
**pobj
, int *prog_fd
)
13 struct bpf_prog_load_attr attr
;
15 memset(&attr
, 0, sizeof(struct bpf_prog_load_attr
));
17 attr
.prog_type
= type
;
18 attr
.expected_attach_type
= 0;
19 attr
.prog_flags
= BPF_F_TEST_RND_HI32
;
20 attr
.log_level
= extra_prog_load_log_flags
;
22 return bpf_prog_load_xattr(&attr
, pobj
, prog_fd
);
25 int bpf_test_load_program(enum bpf_prog_type type
, const struct bpf_insn
*insns
,
26 size_t insns_cnt
, const char *license
,
27 __u32 kern_version
, char *log_buf
,
30 struct bpf_load_program_attr load_attr
;
32 memset(&load_attr
, 0, sizeof(struct bpf_load_program_attr
));
33 load_attr
.prog_type
= type
;
34 load_attr
.expected_attach_type
= 0;
35 load_attr
.name
= NULL
;
36 load_attr
.insns
= insns
;
37 load_attr
.insns_cnt
= insns_cnt
;
38 load_attr
.license
= license
;
39 load_attr
.kern_version
= kern_version
;
40 load_attr
.prog_flags
= BPF_F_TEST_RND_HI32
;
41 load_attr
.log_level
= extra_prog_load_log_flags
;
43 return bpf_load_program_xattr(&load_attr
, log_buf
, log_buf_sz
);