From 5effc8541c2a543570411549ee50c7f9f690a864 Mon Sep 17 00:00:00 2001 From: PoliEcho Date: Fri, 18 Sep 2026 16:14:47 +0200 Subject: [PATCH] mini fix --- src/main.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main.c b/src/main.c index f7801d2..6702dcf 100644 --- a/src/main.c +++ b/src/main.c @@ -7,6 +7,8 @@ #define ETH_HEADER_SIZE 14 +#define MAC_SIZE 6 + #define ETHER_TYPE_FIELD_OFFSET 12 #define ETHER_TYPE_IPV4 0x0800 @@ -218,7 +220,7 @@ int xdp_drop_prog(struct xdp_md *ctx) { // check SYN if (tcp_flags & SYN_MASK) { bpf_printk("packet is SYN\n"); - if (mulberry32_at((__u32)time_seed, dst_port) % 3 == 0) { + if (/*mulberry32_at((__u32)time_seed, dst_port) % 3 == 0*/1) { bpf_printk("DROPING!\n"); __u16 *src_port_ptr = (__u16 *)(tcp_packet_data + TCP_SRC_PORT_OFFSET); const __u16 src_port = bpf_ntohs(*src_port_ptr); @@ -284,9 +286,6 @@ int xdp_drop_prog(struct xdp_md *ctx) { &pseudo_header, (const __u8 *)&pseudo_header + sizeof(pseudo_header), tmp_sum); } else { - if (EtherType != ETHER_TYPE_IPV6) { - return XDP_PASS; - } if (ip_packet_data + IPV6_HEADER_SIZE > data_end) { return XDP_PASS; } @@ -319,7 +318,12 @@ int xdp_drop_prog(struct xdp_md *ctx) { tcp_checksum = bpf_htons(tcp_checksum_fold(tmp_sum)); } *(__u16 *)(tcp_packet_data + TCP_CHECKSUM_OFFSET) = tcp_checksum; - + { // swap SRC an dst MAC + __u8 src_mac[MAC_SIZE]; + __builtin_memcpy(src_mac, data + MAC_SIZE, MAC_SIZE); + __builtin_memcpy((__u8 *)data + MAC_SIZE, data, MAC_SIZE); + __builtin_memcpy((__u8 *)data, src_mac, MAC_SIZE); + } return XDP_TX; } } else {