Use WinDivert TCP Header structure to change Window Size

This commit is contained in:
ValdikSS 2017-12-20 04:04:40 +03:00
parent a88ab4337e
commit fab9662ac9

View File

@ -20,9 +20,6 @@
#define MAX_FILTERS 4 #define MAX_FILTERS 4
#define MAX_PACKET_SIZE 9016 #define MAX_PACKET_SIZE 9016
#define IPV4_HDR_LEN 20
#define TCP_HDR_LEN 20
#define TCP_WINDOWSIZE_OFFSET 14
#define DIVERT_NO_LOCALNETS_DST "(" \ #define DIVERT_NO_LOCALNETS_DST "(" \
"(ip.DstAddr < 127.0.0.1 or ip.DstAddr > 127.255.255.255) and " \ "(ip.DstAddr < 127.0.0.1 or ip.DstAddr > 127.255.255.255) and " \
@ -216,9 +213,9 @@ static int find_header_and_get_info(const char *pktdata, int pktlen,
return FALSE; return FALSE;
} }
static void change_window_size(const char *pkt, int size) { static inline void change_window_size(const PWINDIVERT_TCPHDR ppTcpHdr, int size) {
if (size >= 1 && size <= 65535) { if (size >= 1 && size <= 65535) {
*(uint16_t*)(pkt + IPV4_HDR_LEN + TCP_WINDOWSIZE_OFFSET) = htons(size); ppTcpHdr->Window = htons(size);
} }
} }
@ -660,11 +657,11 @@ int main(int argc, char *argv[]) {
* is enabled as there could be non-HTTP data on port 80 * is enabled as there could be non-HTTP data on port 80
*/ */
if (do_fragment_http && ppTcpHdr->SrcPort == htons(80)) { if (do_fragment_http && ppTcpHdr->SrcPort == htons(80)) {
change_window_size(packet, http_fragment_size); change_window_size(ppTcpHdr, http_fragment_size);
should_recalc_checksum = 1; should_recalc_checksum = 1;
} }
else if (do_fragment_https && ppTcpHdr->SrcPort != htons(80)) { else if (do_fragment_https && ppTcpHdr->SrcPort != htons(80)) {
change_window_size(packet, https_fragment_size); change_window_size(ppTcpHdr, https_fragment_size);
should_recalc_checksum = 1; should_recalc_checksum = 1;
} }
} }