Ticket #13634: tcp-rfc-5681-implemented-ideal-timer.patch

File tcp-rfc-5681-implemented-ideal-timer.patch, 4.0 KB (added by a-star, 3 years ago)
  • src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.cpp

    From 388fdd6a789bd81fda00e2d7b02b789c206ff676 Mon Sep 17 00:00:00 2001
    From: A-star-ayush <myselfthebest@yahoo.com>
    Date: Wed, 26 Jul 2017 01:44:27 +0530
    Subject: [PATCH] tcp: rfc 5681: implemented ideal timer
    
    ---
     .../kernel/network/protocols/tcp/TCPEndpoint.cpp   | 51 +++++++++++++++++-----
     src/add-ons/kernel/network/protocols/tcp/tcp.h     |  2 +
     2 files changed, 42 insertions(+), 11 deletions(-)
    
    diff --git a/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.cpp b/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.cpp
    index 0a7c5fa..a987b94 100644
    a b TCPEndpoint::_AddData(tcp_segment_header& segment, net_buffer* buffer)  
    13571357    if ((segment.flags & TCP_FLAG_PUSH) != 0)
    13581358        fReceiveQueue.SetPushPointer();
    13591359
     1360    if (fSendUnacknowledged == fSendMax) {
     1361        TRACE("data received, resetting ideal timer to: %"
     1362                B_PRIdBIGTIME, fRetransmitTimeout);
     1363            gStackModule->set_timer(&fRetransmitTimer, fRetransmitTimeout);
     1364            T(TimerSet(this, "ideal", fRetransmitTimeout));
     1365    }
     1366
    13601367    return fReceiveQueue.Available() > 0;
    13611368}
    13621369
    TCPEndpoint::_Acknowledged(tcp_segment_header& segment)  
    22212228        }
    22222229
    22232230        if (fSendUnacknowledged == fSendMax) {
    2224             TRACE("all acknowledged, cancelling retransmission timer");
    2225             gStackModule->cancel_timer(&fRetransmitTimer);
    2226             T(TimerSet(this, "retransmit", -1));
     2231            TRACE("all acknowledged, cancelling retransmission timer. Using it as ideal timer for: %"
     2232                B_PRIdBIGTIME, fRetransmitTimeout);
     2233            gStackModule->set_timer(&fRetransmitTimer, fRetransmitTimeout);
     2234            T(TimerSet(this, "ideal", fRetransmitTimeout));
    22272235        } else {
    22282236            TRACE("data acknowledged, resetting retransmission timer to: %"
    22292237                B_PRIdBIGTIME, fRetransmitTimeout);
    TCPEndpoint::_Acknowledged(tcp_segment_header& segment)  
    22612269void
    22622270TCPEndpoint::_Retransmit()
    22632271{
    2264     TRACE("Retransmit()");
     2272    if (fState < ESTABLISHED) {
     2273        fRetransmitTimeout = TCP_SYN_RETRANSMIT_TIMEOUT;
     2274        fCongestionWindow = fSendMaxSegmentSize;
     2275
     2276    } else if (fSendUnacknowledged == fSendMax) {
     2277        TRACE("Ideal timeout");
     2278        // idle period time out - did not receive any segment for a time equal
     2279        // to the retransmission timeout
     2280        uint32 initialWindow;
     2281        if (fSendMaxSegmentSize > 2190)
     2282            initialWindow = 2 * fSendMaxSegmentSize;
     2283        else if (fSendMaxSegmentSize > 1095)
     2284            initialWindow = 3 * fSendMaxSegmentSize;
     2285        else
     2286            initialWindow = 4 * fSendMaxSegmentSize;
    22652287
    2266     _ResetSlowStart();
    2267     fSendNext = fSendUnacknowledged;
     2288        fCongestionWindow = min_c(initialWindow, fCongestionWindow);
     2289        return;
    22682290
    2269     // Do exponential back off of the retransmit timeout
    2270     fRetransmitTimeout *= 2;
    2271     if (fRetransmitTimeout > TCP_MAX_RETRANSMIT_TIMEOUT)
    2272         fRetransmitTimeout = TCP_MAX_RETRANSMIT_TIMEOUT;
     2291    } else {
     2292        _ResetSlowStart();
     2293
     2294        // Do exponential back off of the retransmit timeout
     2295        fRetransmitTimeout *= 2;
     2296        if (fRetransmitTimeout > TCP_MAX_RETRANSMIT_TIMEOUT)
     2297            fRetransmitTimeout = TCP_MAX_RETRANSMIT_TIMEOUT;
     2298    }
    22732299
     2300    TRACE("Retransmit()");
     2301
     2302    fSendNext = fSendUnacknowledged;
    22742303    _SendQueued();
    22752304}
    22762305
    TCPEndpoint::_RetransmitTimer(net_timer* timer, void* _endpoint)  
    23172346    T(TimerTriggered(endpoint, "retransmit"));
    23182347
    23192348    MutexLocker locker(endpoint->fLock);
    2320     if (!locker.IsLocked())
     2349    if (!locker.IsLocked() || gStackModule->is_timer_active(timer))
    23212350        return;
    23222351
    23232352    endpoint->_Retransmit();
  • src/add-ons/kernel/network/protocols/tcp/tcp.h

    diff --git a/src/add-ons/kernel/network/protocols/tcp/tcp.h b/src/add-ons/kernel/network/protocols/tcp/tcp.h
    index 6f30ec2..24890a3 100644
    a b operator==(tcp_sequence a, tcp_sequence b)  
    193193#define TCP_MIN_RETRANSMIT_TIMEOUT      200000      // 200 msecs
    194194// Maximum retransmit timeout (per RFC6298)
    195195#define TCP_MAX_RETRANSMIT_TIMEOUT      60000000    // 60 secs
     196// New value for timeout in case of lost SYN (RFC 6298)
     197#define TCP_SYN_RETRANSMIT_TIMEOUT      3000000     // 3 secs
    196198
    197199struct tcp_sack {
    198200    uint32 left_edge;