session-replay-tools / tcpcopy

An online request replication and TCP stream replay tool, ideal for real testing, performance testing, stability testing, stress testing, load testing, smoke testing, and more.
http://session-replay-tools.github.io/tcpcopy/
Other
4.48k stars 1.03k forks source link

Curious about code src/tcpcopy/tc_session.c:2290 #397

Closed JINwonLEE closed 1 year ago

JINwonLEE commented 1 year ago

I'm using tcpcopy & intercept in mirroring tcp packets to target server.

Furthermore I navigated source code of tcpcopy on interest. However I saw some curious points in the source code below.

   // src/tcpcopy/tc_session.c:2288
    seq  = ntohl(tcp->seq);
    diff = tc_time() - s->create_time;
    if (diff < TCP_MS_TIMEOUT && (s->sm.state & SYN_SENT)) {
        if (before(seq, s->req_syn_seq)) {
            tc_log_debug1(LOG_INFO, 0, "timeout pack,p:%u", ntohs(s->src_port));
            return;
        }
    }

In this source code, variable diff has scaling with seconds(s). However TCP_MS_TIMEOUT has value(6000) with milliseconds.

The two different variables are comparing without matching unit(seconds vs milliseconds).

As I understand, this logic would be adding log and return after timeout(6seconds) when syn sent to target server.

If there is anything misunderstanding, please advice me.

Thanks.

wangbin579 commented 1 year ago

It is really a mistake when using TCP_MS_TIMEOUT.

JINwonLEE commented 1 year ago

Oh, I see recent commit now. TCP_INTERFERENCE_PREVENTION_TIMEOUT is set to 10 minutes. Thanks.