All of lore.kernel.org
 help / color / mirror / Atom feed
From: Patrick McHardy <kaber@trash.net>
To: Krzysztof Oledzki <ole@ans.pl>
Cc: Netfilter Developer Mailing List
	<netfilter-devel@vger.kernel.org>,
	Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
Subject: Re: PATCH: "invalid SYNIN=" - a patch and a question
Date: Thu, 04 Oct 2007 08:15:53 +0200	[thread overview]
Message-ID: <47048519.50701@trash.net> (raw)
In-Reply-To: <Pine.LNX.4.64.0710031420130.5307@bizon.gios.gov.pl>

Krzysztof Oledzki wrote:
> Small update to this issue. It seems that both ip stack and netfilter
> indeed handle connections using different timers:
> 
> # wget --bind-address 192.168.0.1 192.168.129.28 -O /dev/null
> 
> --14:36:00--  http://192.168.129.28/
>            => `/dev/null'
> Connecting to 192.168.129.28:80... connected.
> HTTP request sent, awaiting response... 200 OK
> Length: 915 [text/html]
> 
> 100%[==========================================================================================>]
> 915           --.--K/s
> 
> 14:36:00 (13.43 MB/s) - `/dev/null' saved [915/915]
> 
> # conntrack -L |grep =192.168.129.28|grep 192.168.0.1:
> tcp      6 119 TIME_WAIT src=192.168.0.1 dst=192.168.129.28 sport=18300
> dport=80 packets=6 bytes=422 src=192.168.129.28 dst=192.168.0.1 sport=80
> dport=18300 packets=4 bytes=1475 [ASSURED] mark=0 use=1
> 
> # ss -anto |egrep "192.168.0.1.*192.168.129.28":
> TIME-WAIT  0      0               192.168.0.1:18300      
> 192.168.129.28:80     timer:(timewait,58sec,0)
> 
> 
> After 60s kernel is able to reuse this (18300) port but it will be
> blocked by local netfilter with this "invalid SYN" message. This is
> especially more likely in newer kernels with tcp port randomization.
> 
> This does not solve my problem but it think we should consider changing
> net.ipv4.netfilter.ip_conntrack_tcp_timeout_time_wait from 120s to 60s.


As you quoted below, we should use 2*MSL, which would actually be
240s. Not sure why Linux TCP uses 60s ..

> 
> I also wondering if the code from nf_conntrack_proto_tcp.c is correct:
> 
> --- cut here ---
> new_state = tcp_conntracks[dir][index][old_state];
> 
> switch (new_state)
> (...)
> case TCP_CONNTRACK_SYN_SENT:
> if (old_state < TCP_CONNTRACK_TIME_WAIT)
>         break;
> if ((conntrack->proto.tcp.seen[dir].flags &
>         IP_CT_TCP_FLAG_CLOSE_INIT)
>     || after(ntohl(th->seq),
>              conntrack->proto.tcp.seen[dir].td_end)) {
>         /* Attempt to reopen a closed connection.
>         * Delete this connection and look up again. */
>         write_unlock_bh(&tcp_lock);
>         if (del_timer(&conntrack->timeout))
>                 conntrack->timeout.function((unsigned long)
>                                             conntrack);
>         return -NF_REPEAT;
> } else {
>         write_unlock_bh(&tcp_lock);
>         if (LOG_INVALID(IPPROTO_TCP))
>                 nf_log_packet(pf, 0, skb, NULL, NULL,
>                               NULL, "nf_ct_tcp: invalid SYN");
>         return -NF_ACCEPT;
> }
> --- cut here ---
> 
> It seems that tcp_conntracks allows such (TCP_CONNTRACK_TIME_WAIT ->
> TCP_CONNTRACK_SYN_SENT) transition, pointing to rfc1122:
> 
> When a connection is closed actively, it MUST linger in
> TIME-WAIT state for a time 2xMSL (Maximum Segment Lifetime).
> However, it MAY accept a new SYN from the remote TCP to
> reopen the connection directly from TIME-WAIT state, if it:
> 
> (1)  assigns its initial sequence number for the new
>      connection to be larger than the largest sequence
>      number it used on the previous connection incarnation,
>      and
> 
> (2)  returns to TIME-WAIT state if the SYN turns out to be
>      an old duplicate.
> 
> So, it seems that this "after(...)" does not match this packet, right?
> 
> Patric, what do you think about this?


Yes, that seems to be the case. Could you post a tcpdump (and
add a few printks printing the td_end and the flag values
of both directions if possible)?

  parent reply	other threads:[~2007-10-04  6:16 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-26 12:27 PATCH: "invalid SYNIN=" - a patch and a question Krzysztof Oledzki
2007-10-03 13:06 ` Krzysztof Oledzki
2007-10-03 13:54   ` Jozsef Kadlecsik
2007-10-03 19:57     ` Krzysztof Oledzki
2007-10-04  7:26       ` Jozsef Kadlecsik
2007-10-04  5:59     ` Patrick McHardy
2007-10-04  7:52       ` Jozsef Kadlecsik
2007-10-04  7:59         ` Patrick McHardy
2007-10-04  8:41           ` Jozsef Kadlecsik
2007-10-05 20:06             ` Krzysztof Oledzki
2007-10-08  9:32               ` Jozsef Kadlecsik
2007-10-08  9:45                 ` Jozsef Kadlecsik
2007-10-08 13:56                   ` Krzysztof Oledzki
2007-10-08 14:01                     ` Krzysztof Oledzki
2007-10-08 13:58                 ` Krzysztof Oledzki
2007-10-08 14:01                   ` Jozsef Kadlecsik
2007-10-08 17:28                     ` Krzysztof Oledzki
2007-10-09  8:11                       ` Jozsef Kadlecsik
2007-10-09 13:17                         ` Krzysztof Oledzki
2007-10-09 13:22                           ` Krzysztof Oledzki
2007-10-08 16:39                 ` Patrick McHardy
2007-10-08 17:23                   ` Krzysztof Oledzki
2007-10-04  6:15   ` Patrick McHardy [this message]
2007-10-10 19:26   ` Jozsef Kadlecsik
2007-10-11  4:04     ` Patrick McHardy
2007-10-11 13:52       ` Krzysztof Oledzki
2007-10-31 19:34         ` Krzysztof Oledzki
2007-11-05 11:11           ` Patrick McHardy
2007-11-14 21:46             ` [stable] " Greg KH
2007-10-11 13:50     ` Krzysztof Oledzki
     [not found]     ` <Pine.LNX.4.64.0710112238010.29814@bizon.gios.gov.pl>
2007-10-11 22:42       ` Jozsef Kadlecsik
2007-10-12 10:09         ` Krzysztof Oledzki
2007-10-12 14:48           ` Jozsef Kadlecsik
2007-10-12 18:09             ` Krzysztof Oledzki
2007-10-17 17:41               ` Jozsef Kadlecsik
2007-10-17 20:08                 ` Krzysztof Oledzki
2007-10-18  8:43                 ` Patrick McHardy
2007-10-04  5:45 ` Patrick McHardy
2007-10-17 20:13   ` Krzysztof Oledzki
2007-10-18  8:43     ` Patrick McHardy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=47048519.50701@trash.net \
    --to=kaber@trash.net \
    --cc=kadlec@blackhole.kfki.hu \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=ole@ans.pl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.