41 lines
1.2 KiB
C
41 lines
1.2 KiB
C
|
// SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
|
||
|
/* Copyright (C) 2019 Netronome Systems, Inc. */
|
||
|
|
||
|
#include <bpf/bpf.h>
|
||
|
#include <bpf/libbpf.h>
|
||
|
#include <string.h>
|
||
|
|
||
|
int bpf_prog_test_load(const char *file, enum bpf_prog_type type,
|
||
|
struct bpf_object **pobj, int *prog_fd)
|
||
|
{
|
||
|
struct bpf_prog_load_attr attr;
|
||
|
|
||
|
memset(&attr, 0, sizeof(struct bpf_prog_load_attr));
|
||
|
attr.file = file;
|
||
|
attr.prog_type = type;
|
||
|
attr.expected_attach_type = 0;
|
||
|
attr.prog_flags = BPF_F_TEST_RND_HI32;
|
||
|
|
||
|
return bpf_prog_load_xattr(&attr, pobj, prog_fd);
|
||
|
}
|
||
|
|
||
|
int 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)
|
||
|
{
|
||
|
struct bpf_load_program_attr load_attr;
|
||
|
|
||
|
memset(&load_attr, 0, sizeof(struct bpf_load_program_attr));
|
||
|
load_attr.prog_type = type;
|
||
|
load_attr.expected_attach_type = 0;
|
||
|
load_attr.name = NULL;
|
||
|
load_attr.insns = insns;
|
||
|
load_attr.insns_cnt = insns_cnt;
|
||
|
load_attr.license = license;
|
||
|
load_attr.kern_version = kern_version;
|
||
|
load_attr.prog_flags = BPF_F_TEST_RND_HI32;
|
||
|
|
||
|
return bpf_load_program_xattr(&load_attr, log_buf, log_buf_sz);
|
||
|
}
|