valid ip-id
This commit is contained in:
+11
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
#define IPV4_TTL_OFFSET 8
|
#define IPV4_TTL_OFFSET 8
|
||||||
|
|
||||||
|
#define IPV4_ID_OFFSET 4
|
||||||
#define IPV4_PROTOCOL_OFFSET 9
|
#define IPV4_PROTOCOL_OFFSET 9
|
||||||
#define IPV4_CHECKSUM_OFFSET 10
|
#define IPV4_CHECKSUM_OFFSET 10
|
||||||
#define IPV4_SRC_ADDR_OFFSET 12
|
#define IPV4_SRC_ADDR_OFFSET 12
|
||||||
@@ -34,6 +35,7 @@
|
|||||||
#define TCP_SRC_PORT_OFFSET 0
|
#define TCP_SRC_PORT_OFFSET 0
|
||||||
|
|
||||||
#define TCP_SEQ_OFFSET 4
|
#define TCP_SEQ_OFFSET 4
|
||||||
|
#define TCP_ACK_NUM_OFFSET 8
|
||||||
|
|
||||||
#define TCP_DATA_OFFSET_OFFSET 12
|
#define TCP_DATA_OFFSET_OFFSET 12
|
||||||
#define TCP_DATA_OFFSET_SHIFT 4
|
#define TCP_DATA_OFFSET_SHIFT 4
|
||||||
@@ -230,6 +232,11 @@ int xdp_drop_prog(struct xdp_md *ctx) {
|
|||||||
|
|
||||||
*tcp_flags_ptr = tcp_flags | ACK_MASK;
|
*tcp_flags_ptr = tcp_flags | ACK_MASK;
|
||||||
|
|
||||||
|
// set ISN and ack number
|
||||||
|
*(__u32 *)(tcp_packet_data + TCP_ACK_NUM_OFFSET) = bpf_htonl(
|
||||||
|
bpf_ntohl(*(__u32 *)(tcp_packet_data + TCP_SEQ_OFFSET))+1);
|
||||||
|
*(__u32 *)(tcp_packet_data + TCP_SEQ_OFFSET) = bpf_get_prandom_u32();
|
||||||
|
|
||||||
*(__u16 *)(tcp_packet_data + TCP_CHECKSUM_OFFSET) = 0; // must be zero for calculation
|
*(__u16 *)(tcp_packet_data + TCP_CHECKSUM_OFFSET) = 0; // must be zero for calculation
|
||||||
|
|
||||||
const __u8 tcp_data_offset =
|
const __u8 tcp_data_offset =
|
||||||
@@ -278,6 +285,10 @@ int xdp_drop_prog(struct xdp_md *ctx) {
|
|||||||
*ipv4_checksum_ptr = bpf_htons((__u16)new_checksum);
|
*ipv4_checksum_ptr = bpf_htons((__u16)new_checksum);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// set ID
|
||||||
|
*(__u16*)(ip_packet_data+IPV4_ID_OFFSET) = bpf_get_prandom_u32();
|
||||||
|
|
||||||
|
|
||||||
struct tcp_v4_pseudo_header pseudo_header = {
|
struct tcp_v4_pseudo_header pseudo_header = {
|
||||||
*src_ip_ptr, *dst_ip_ptr, 0, TCP_PROTO_ID,
|
*src_ip_ptr, *dst_ip_ptr, 0, TCP_PROTO_ID,
|
||||||
bpf_htons(data_end - tcp_packet_data)};
|
bpf_htons(data_end - tcp_packet_data)};
|
||||||
|
|||||||
Reference in New Issue
Block a user