• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
2 /* Copyright (C) 2019 Netronome Systems, Inc. */
3 
4 #include <bpf/bpf.h>
5 #include <bpf/libbpf.h>
6 #include <string.h>
7 
8 int extra_prog_load_log_flags = 0;
9 
bpf_prog_test_load(const char * file,enum bpf_prog_type type,struct bpf_object ** pobj,int * prog_fd)10 int bpf_prog_test_load(const char *file, enum bpf_prog_type type,
11 		       struct bpf_object **pobj, int *prog_fd)
12 {
13 	struct bpf_prog_load_attr attr;
14 
15 	memset(&attr, 0, sizeof(struct bpf_prog_load_attr));
16 	attr.file = file;
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;
21 
22 	return bpf_prog_load_xattr(&attr, pobj, prog_fd);
23 }
24 
bpf_test_load_program(enum bpf_prog_type type,const struct bpf_insn * insns,size_t insns_cnt,const char * license,__u32 kern_version,char * log_buf,size_t log_buf_sz)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,
28 		     size_t log_buf_sz)
29 {
30 	struct bpf_load_program_attr load_attr;
31 
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;
42 
43 	return bpf_load_program_xattr(&load_attr, log_buf, log_buf_sz);
44 }
45