forked from jperon/lunatik_snihook
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxdp.c
More file actions
30 lines (21 loc) · 736 Bytes
/
xdp.c
File metadata and controls
30 lines (21 loc) · 736 Bytes
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
/*
* SPDX-FileCopyrightText: (c) 2024 Ring Zero Desenvolvimento de Software LTDA
* SPDX-License-Identifier: MIT OR GPL-2.0-only
*/
#include "vmlinux.h"
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_endian.h>
extern int bpf_luaxdp_run(char *key, size_t key__sz, struct xdp_md *xdp_ctx, void *arg, size_t arg__sz) __ksym;
static char runtime[] = "snihook/hook";
struct bpf_luaxdp_arg {
__u16 offset;
} __attribute__((packed));
SEC("xdp")
int filter(struct xdp_md *ctx)
{
struct bpf_luaxdp_arg arg;
arg.offset = bpf_htons((__u16)(sizeof(struct ethhdr)));
int action = bpf_luaxdp_run(runtime, sizeof(runtime), ctx, &arg, sizeof(arg));
return action < 0 ? XDP_PASS : action;
}
char _license[] SEC("license") = "Dual MIT/GPL";