From: Francesco Ruggeri <fruggeri@arista.com>
To: open list <linux-kernel@vger.kernel.org>,
netdev <netdev@vger.kernel.org>,
coreteam@netfilter.org, netfilter-devel@vger.kernel.org,
Jakub Kicinski <kuba@kernel.org>,
David Miller <davem@davemloft.net>,
fw@strlen.org, kadlec@netfilter.org,
Pablo Neira Ayuso <pablo@netfilter.org>,
Francesco Ruggeri <fruggeri@arista.com>
Subject: Re: [PATCH nf v2] netfilter: conntrack: connection timeout after re-register
Date: Thu, 8 Oct 2020 16:41:30 -0700 [thread overview]
Message-ID: <CA+HUmGhBxBHU85oFfvoAyP=hG17DG2kgO67eawk1aXmSjehOWQ@mail.gmail.com> (raw)
In-Reply-To: <20201007193252.7009D95C169C@us180.sjc.aristanetworks.com>
On Wed, Oct 7, 2020 at 12:32 PM Francesco Ruggeri <fruggeri@arista.com> wrote:
>
> If the first packet conntrack sees after a re-register is an outgoing
> keepalive packet with no data (SEG.SEQ = SND.NXT-1), td_end is set to
> SND.NXT-1.
> When the peer correctly acknowledges SND.NXT, tcp_in_window fails
> check III (Upper bound for valid (s)ack: sack <= receiver.td_end) and
> returns false, which cascades into nf_conntrack_in setting
> skb->_nfct = 0 and in later conntrack iptables rules not matching.
> In cases where iptables are dropping packets that do not match
> conntrack rules this can result in idle tcp connections to time out.
>
> v2: adjust td_end when getting the reply rather than when sending out
> the keepalive packet.
>
Any comments?
Here is a simple reproducer.
The idea is to show that keepalive packets in an idle tcp
connection will be dropped (and the connection will time out)
if conntrack hooks are de-registered and then re-registered.
The reproducer has two files.
client_server.py creates both ends of a tcp connection, bounces
a few packets back and forth, and then blocks on a recv on the
client side. The client's keepalive is configured to time out in
20 seconds. This connection should not time out.
test is a bash script that creates a net namespace where it sets
iptables rules for the connection, starts client_server.py, and
then clears and restores the iptables rules (which causes
conntrack hooks to be de-registered and re-registered).
================ file client_server.py
#!/usr/bin/python
import socket
PORT=4446
# create server socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind(('localhost', PORT))
sock.listen(1)
# create client socket
cl_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
cl_sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
cl_sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPIDLE, 2)
cl_sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPINTVL, 2)
cl_sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPCNT, 10)
cl_sock.connect(('localhost', PORT))
srv_sock, _ = sock.accept()
# Bounce a packet back and forth a few times
buf = 'aaaaaaaaaaaa'
for i in range(5):
cl_sock.send(buf)
buf = srv_sock.recv(100)
srv_sock.send(buf)
buf = cl_sock.recv(100)
print buf
# idle the connection
try:
buf = cl_sock.recv(100)
except socket.error, e:
print "Error: %s" % e
sock.close()
cl_sock.close()
srv_sock.close()
============== file test
#!/bin/bash
ip netns add dummy
ip netns exec dummy ip link set lo up
echo "Created namespace"
ip netns exec dummy iptables-restore <<END
*filter
:INPUT DROP [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p tcp -m tcp --dport 4446 -j ACCEPT
COMMIT
END
echo "Installed iptables rules"
ip netns exec dummy ./client_server.py &
echo "Created tcp connection"
sleep 2
ip netns exec dummy iptables-restore << END
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
COMMIT
END
echo "Cleared iptables rules"
sleep 4
ip netns exec dummy iptables-restore << END
*filter
:INPUT DROP [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p tcp -m tcp --dport 4446 -j ACCEPT
COMMIT
END
echo "Restored original iptables rules"
wait
ip netns del dummy
exit 0
next prev parent reply other threads:[~2020-10-08 23:41 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-07 19:32 [PATCH nf v2] netfilter: conntrack: connection timeout after re-register Francesco Ruggeri
2020-10-08 23:41 ` Francesco Ruggeri [this message]
2020-10-09 6:52 ` Jozsef Kadlecsik
2020-10-09 11:03 ` Florian Westphal
2020-10-09 18:48 ` Jozsef Kadlecsik
2020-10-09 18:55 ` Florian Westphal
2020-10-09 19:49 ` Jozsef Kadlecsik
2020-10-09 20:00 ` Francesco Ruggeri
2020-10-09 20:05 ` Florian Westphal
2020-10-14 0:06 ` Pablo Neira Ayuso
2020-10-14 8:11 ` Pablo Neira Ayuso
2020-10-14 8:23 ` Florian Westphal
2020-10-14 18:42 ` Francesco Ruggeri
2020-10-14 19:35 ` Florian Westphal
2020-10-20 15:21 ` Pablo Neira Ayuso
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='CA+HUmGhBxBHU85oFfvoAyP=hG17DG2kgO67eawk1aXmSjehOWQ@mail.gmail.com' \
--to=fruggeri@arista.com \
--cc=coreteam@netfilter.org \
--cc=davem@davemloft.net \
--cc=fw@strlen.org \
--cc=kadlec@netfilter.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=pablo@netfilter.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).