-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmine.c
68 lines (54 loc) · 1.53 KB
/
mine.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <stdio.h>
#include <string.h>
#include <error.h>
#include <errno.h>
#include <linux/types.h>
#include <linux/if_ether.h>
#include <linux/ip.h>
#include <linux/udp.h>
#include <asm/byteorder.h>
#include <bpf/bpf.h>
#include <bpf/libbpf.h>
#include "mine.h"
#include "block_123.h"
int main(int argc, char **argv)
{
struct bpf_test_run_opts opts = {};
struct bpf_program *prog;
struct bpf_object *obj;
__u32 correct_nonce;
struct pkt p;
int err;
block_123_init(&p.bh, p.difficulty);
/* go back 15 nonces, current loop limit in the xdp program */
correct_nonce = p.bh.nonce;
p.bh.nonce -= 15;
obj = bpf_object__open("./mine.bpf.o");
err = libbpf_get_error(obj);
if (err < 0)
error(1, err, "bpf_object__open");
err = bpf_object__load(obj);
if (err < 0)
error(1, err, "bpf_object__load");
prog = bpf_object__find_program_by_name(obj, "mine");
err = libbpf_get_error(prog);
if (err < 0)
error(1, err, "bpf_object__find_program_by_name");
opts.repeat = 1;
opts.data_in = &p;
opts.data_size_in = sizeof(p);
opts.data_out = &p;
opts.data_size_out = sizeof(p);
opts.sz = sizeof(struct bpf_test_run_opts);
err = bpf_prog_test_run_opts(bpf_program__fd(prog), &opts);
if (err)
error(1, err, "bpf_prog_test_run_xattr");
if (opts.retval != XDP_TX)
error(1, -1, "unexpected retval %u != XDP_TX", opts.retval);
if (p.bh.nonce != correct_nonce)
error(1, -1, "unexpected nonce %u != %u", p.bh.nonce,
correct_nonce);
printf("returned XDP_TX and correct %u nonce\n", correct_nonce);
bpf_object__close(obj);
return 0;
}