forked from cloudflare/xdpcap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xdp_hook.c
37 lines (30 loc) · 868 Bytes
/
xdp_hook.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
/**
* Definitions expected to be provided by the loader
* newtools and libbpf support the same basic definitions
*/
struct bpf_map_def {
unsigned int type;
unsigned int key_size;
unsigned int value_size;
unsigned int max_entries;
unsigned int flags;
};
int tail_call(void *ctx, void *map, int index);
#include "../hook.h"
#define __section(NAME) __attribute__((section(NAME), used))
__section("license")
char __license[] = "BSD";
__section("maps")
struct bpf_map_def xdpcap_hook = XDPCAP_HOOK();
/**
* Example / test XDP program that exposes packets through an xdpcap hook.
*/
__section("xdp/hook") int xdp_hook(struct xdp_md *ctx) {
return xdpcap_exit(ctx, &xdpcap_hook, XDP_PASS);
}
/**
* Second entrypoint that doesn't use xdpcap exit() to test patching.
*/
__section("xdp/nohook") int xdp_nohook(struct xdp_md *ctx) {
return XDP_PASS;
}