Ticket #13632: 0004-tcp-rfc-7323-added-PAWS-timestamp-check-on-Receive.patch

File 0004-tcp-rfc-7323-added-PAWS-timestamp-check-on-Receive.patch, 2.5 KB (added by a-star, 3 years ago)
  • src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.cpp

    From 0a38fdc3f68f08eb0e9e67bb8ed60b96374e811b Mon Sep 17 00:00:00 2001
    From: A-star-ayush <myselfthebest@yahoo.com>
    Date: Thu, 17 Aug 2017 12:29:56 +0530
    Subject: [PATCH] tcp: rfc 7323: added PAWS timestamp check on Receive
    
    ---
     src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.cpp | 9 +++++++++
     src/add-ons/kernel/network/protocols/tcp/tcp.cpp         | 5 ++---
     2 files changed, 11 insertions(+), 3 deletions(-)
    
    diff --git a/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.cpp b/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.cpp
    index af2027b..64ffe5e 100644
    a b TCPEndpoint::_SynchronizeSentReceive(tcp_segment_header &segment,  
    15511551int32
    15521552TCPEndpoint::_Receive(tcp_segment_header& segment, net_buffer* buffer)
    15531553{
     1554    // PAWS processing takes precedence over regular TCP acceptability check
     1555    if ((fFlags & FLAG_OPTION_TIMESTAMP) != 0 && (segment.flags & TCP_FLAG_RESET) == 0) {
     1556        if ((segment.options & TCP_HAS_TIMESTAMPS) == 0)
     1557            return DROP;
     1558        if ((int32)(fReceivedTimestamp - segment.timestamp_value) > 0
     1559            && (fReceivedTimestamp - segment.timestamp_value) <= INT32_MAX)
     1560            return DROP | IMMEDIATE_ACKNOWLEDGE;
     1561    }
     1562
    15541563    uint32 advertisedWindow = (uint32)segment.advertised_window
    15551564        << fSendWindowShift;
    15561565    size_t segmentLength = buffer->size;
  • src/add-ons/kernel/network/protocols/tcp/tcp.cpp

    diff --git a/src/add-ons/kernel/network/protocols/tcp/tcp.cpp b/src/add-ons/kernel/network/protocols/tcp/tcp.cpp
    index 7c1dbb4..b14f662 100644
    a b add_options(tcp_segment_header &segment, uint8 *buffer, size_t bufferSize)  
    117117        option->kind = TCP_OPTION_TIMESTAMP;
    118118        option->length = 10;
    119119        option->timestamp.value = htonl(segment.timestamp_value);
    120         // TSecr is opaque to us, we send it as we received it.
    121         option->timestamp.reply = segment.timestamp_reply;
     120        option->timestamp.reply = htonl(segment.timestamp_reply);
    122121        bump_option(option, length);
    123122    }
    124123
    process_options(tcp_segment_header &segment, net_buffer *buffer, size_t size)  
    210209            case TCP_OPTION_TIMESTAMP:
    211210                if (option->length == 10 && size >= 10) {
    212211                    segment.options |= TCP_HAS_TIMESTAMPS;
    213                     segment.timestamp_value = option->timestamp.value;
     212                    segment.timestamp_value = ntohl(option->timestamp.value);
    214213                    segment.timestamp_reply =
    215214                        ntohl(option->timestamp.reply);
    216215                }