From: Henrik Nordstrom Subject: Re: conntrack performance/DoS formula Date: Thu, 4 Jul 2002 23:53:56 +0200 Sender: netfilter-devel-admin@lists.samba.org Message-ID: <200207042353.56244@henrik.marasystems.com> References: <20020628082339.I2890@oknodo.bof.de> <200207011007.25108.hno@marasystems.com> <15652.38084.704660.234319@isis.cs3-inc.com> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit Cc: netfilter-devel Return-path: To: don-nf@isis.cs3-inc.com (Don Cohen) In-Reply-To: <15652.38084.704660.234319@isis.cs3-inc.com> Errors-To: netfilter-devel-admin@lists.samba.org List-Help: List-Post: List-Subscribe: , List-Unsubscribe: , List-Archive: List-Id: netfilter-devel.vger.kernel.org On Thursday 04 July 2002 20.32, Don Cohen wrote: > [off list, but feel free to put it there if you think appropriate] It has been discussed to death on the list. Try reading the archives some weeks back (always a healthy exercise). You are welcome to forward this response to the netfilter-users mailinglist where it really belongs. But here we go again.. > My current understanding is that there are two matching conntrack > records here. The ESTABLISHED is the conntrack state of one, not > the tcp state. If it were the tcp state then this would be assured > and the other conntrack state would not be unreplied but also > established, right? > What's use, btw? ESTABLISHED is the TCP tracking state, not the conntrack state. The TCP tracking state ESTABLISHED is derived from the last packet seen on the connection (ACK). This is not to be confused with the conntrack "state" ESTABLISHED as used in the state match which is a actually packet state describing how THIS packet relates to the connection, not a connection state as such. What you have in conntrack for a TCP session is a) A set of conntrack state bits, describing the state of the connection: - SEEN_REPLY - ASSURED - EXPECTED b) A TCP tracking state, SYN_RECV, SYN_SENT, ESTABLISHED, TIME_WAIT and many more. Also keeps track of TCP window information and other crucial information for tracking a TCP session properly. The TCP tracking state mainly controls the timeouts, but also has some influence on what kind of packets conntrack expects to see on the connection. The TCP tracking state is not visible in your rulesets. The conntrack state bit SEEN_REPLY is pretty obvious what is represents. ASSURED is a little trickier. What it represents is that conntrack are sure this connection is for real. For TCP this requires that conntrack has seen the whole SYN->SYNACK->ACK handshake. EXPECTED is simply that this connection was expected by a conntrack protocol helper, for example FTP data channels expected due to commands on their FTP control channel. Now, if we take a look at the "state" match, it indicates four different packet states - INVALID - NEW - ESTABLISHED - RELATED These states has nothing to do with TCP, only packet flows. If conntrack cannot identify a session key for the packet or otherwise fails to establish connection tracking (i.e. OOM) then the paket state is INVALID. If the packet is the first packet conntrack has seen for a connection then it is a NEW (or RELATED where applicable). Note that this may well be an ACK or even a FIN, conntrack does not care, it only cares that it did not know about the connection before seeing the packet. If there has been any reply packets (including the first reply packet) then the packet state is ESTABLISHED. The ASSURED bit deserves a little more attention. As you may see from the above description of the four "state" types this bit is not used in any rulesets. The ASSURED bit is used by conntrack to defeat almost all DoS attempts. When conntrack runs out of entries it will throw away not ASSURED connections to make room for new connections. This very effectively stops almost all DoS attempts in filling the connection table. This is the last time I will answer this question. If anyone feels like using any of this in a FAQ then you are welcome. If I see much more chatter about these fundamental aspects of netfilter connection tracking that really SHOULD be common knowledge to all users (note: I am not talking about developers here.. developers looking at conntrack MUST understand these aspects) then I don't know what I will do, but I suspect I will stop following the netfilter-devel traffic. I am damn tired that so few people seem to understand what "iptables -m state --state NEW" or "--state ESTABLISED" means. Regards Henrik