Skip to content

Commit afa43fc

Browse files
committed
Make networking a header
1 parent 53f63c4 commit afa43fc

3 files changed

Lines changed: 9 additions & 6 deletions

File tree

build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ fn main() {
7878
// 3. Re-run if relevant files change
7979
println!("cargo:rerun-if-changed=c/minecraft_filter.c");
8080
println!("cargo:rerun-if-changed=c/common.h");
81-
println!("cargo:rerun-if-changed=c/minecraft_networking.c");
81+
println!("cargo:rerun-if-changed=c/minecraft_networking.h");
8282
println!("cargo:rerun-if-changed=c/stats.h");
8383
println!("cargo:rerun-if-changed=build.rs");
8484
}

c/minecraft_filter.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@
1616
#include <linux/tcp.h>
1717
#include <linux/in.h>
1818
#include <bpf/bpf_helpers.h>
19+
#include <bpf/bpf_endian.h>
1920
#include "common.h"
20-
#include "minecraft_networking.c"
21+
#include "minecraft_networking.h"
2122
#include "stats.h"
2223

23-
// Minecraft server port
24-
const __u16 ETH_IP_PROTO = __constant_htons(ETH_P_IP);
25-
2624
struct
2725
{
2826
__uint(type,
@@ -153,7 +151,7 @@ __s32 minecraft_filter(struct xdp_md *ctx)
153151
return XDP_DROP;
154152
}
155153

156-
if (eth->h_proto != ETH_IP_PROTO)
154+
if (eth->h_proto != bpf_htons(ETH_P_IP))
157155
{
158156
return XDP_PASS;
159157
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#ifndef MINECRAFT_NETWORKING_H
2+
#define MINECRAFT_NETWORKING_H
3+
14
#include <linux/types.h>
25

36
#include "minecraft_helper.h"
@@ -153,3 +156,5 @@ static __always_inline __s32 inspect_handshake(__u8 *reader_index, const __u8 *p
153156
*current_reader_index = reader_index;
154157
return intention == 1 ? DIRECT_READ_STATUS_REQUEST : DIRECT_READ_LOGIN;
155158
}
159+
160+
#endif

0 commit comments

Comments
 (0)