mini fix
This commit is contained in:
+9
-5
@@ -7,6 +7,8 @@
|
|||||||
|
|
||||||
#define ETH_HEADER_SIZE 14
|
#define ETH_HEADER_SIZE 14
|
||||||
|
|
||||||
|
#define MAC_SIZE 6
|
||||||
|
|
||||||
#define ETHER_TYPE_FIELD_OFFSET 12
|
#define ETHER_TYPE_FIELD_OFFSET 12
|
||||||
|
|
||||||
#define ETHER_TYPE_IPV4 0x0800
|
#define ETHER_TYPE_IPV4 0x0800
|
||||||
@@ -218,7 +220,7 @@ int xdp_drop_prog(struct xdp_md *ctx) {
|
|||||||
// check SYN
|
// check SYN
|
||||||
if (tcp_flags & SYN_MASK) {
|
if (tcp_flags & SYN_MASK) {
|
||||||
bpf_printk("packet is SYN\n");
|
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");
|
bpf_printk("DROPING!\n");
|
||||||
__u16 *src_port_ptr = (__u16 *)(tcp_packet_data + TCP_SRC_PORT_OFFSET);
|
__u16 *src_port_ptr = (__u16 *)(tcp_packet_data + TCP_SRC_PORT_OFFSET);
|
||||||
const __u16 src_port = bpf_ntohs(*src_port_ptr);
|
const __u16 src_port = bpf_ntohs(*src_port_ptr);
|
||||||
@@ -284,9 +286,6 @@ int xdp_drop_prog(struct xdp_md *ctx) {
|
|||||||
&pseudo_header,
|
&pseudo_header,
|
||||||
(const __u8 *)&pseudo_header + sizeof(pseudo_header), tmp_sum);
|
(const __u8 *)&pseudo_header + sizeof(pseudo_header), tmp_sum);
|
||||||
} else {
|
} else {
|
||||||
if (EtherType != ETHER_TYPE_IPV6) {
|
|
||||||
return XDP_PASS;
|
|
||||||
}
|
|
||||||
if (ip_packet_data + IPV6_HEADER_SIZE > data_end) {
|
if (ip_packet_data + IPV6_HEADER_SIZE > data_end) {
|
||||||
return XDP_PASS;
|
return XDP_PASS;
|
||||||
}
|
}
|
||||||
@@ -319,7 +318,12 @@ int xdp_drop_prog(struct xdp_md *ctx) {
|
|||||||
tcp_checksum = bpf_htons(tcp_checksum_fold(tmp_sum));
|
tcp_checksum = bpf_htons(tcp_checksum_fold(tmp_sum));
|
||||||
}
|
}
|
||||||
*(__u16 *)(tcp_packet_data + TCP_CHECKSUM_OFFSET) = tcp_checksum;
|
*(__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;
|
return XDP_TX;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user