Linux Netfilter discussions
 help / color / mirror / Atom feed
* Dynamically adding rules - are connection tracking states maintained?
@ 2008-04-24 16:12 noa levy
  2008-04-24 19:24 ` Pascal Hambourg
  0 siblings, 1 reply; 9+ messages in thread
From: noa levy @ 2008-04-24 16:12 UTC (permalink / raw)
  To: netfilter

Hi All,

I'm trying to understand the impact of dynamically adding iptables rules, in terms of the resulting disruption to the firewall's performance. When I add a rule to (or delete a rule from) iptables, while it is running, does that have any effect on the states in the connection tracking table? Will the table be flushed? Are states linked to the rule that allowed the initial packet in, so that if a rule is deleted, only the corresponding state entry will be flushed?

Thank you!
Noa  


      ____________________________________________________________________________________
Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Dynamically adding rules - are connection tracking states maintained?
  2008-04-24 16:12 noa levy
@ 2008-04-24 19:24 ` Pascal Hambourg
  2008-04-25 17:39   ` Jan Engelhardt
  0 siblings, 1 reply; 9+ messages in thread
From: Pascal Hambourg @ 2008-04-24 19:24 UTC (permalink / raw)
  To: netfilter

Hello,

noa levy a écrit :
> 
> When I add a rule to (or delete a rule from) iptables,
> while it is running, does that have any effect on the states in the
> connection tracking table?

No.

> Will the table be flushed?

No.

> Are states linked  to the rule that allowed the initial packet in [...] ?

No.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Dynamically adding rules - are connection tracking states maintained?
  2008-04-24 19:24 ` Pascal Hambourg
@ 2008-04-25 17:39   ` Jan Engelhardt
  0 siblings, 0 replies; 9+ messages in thread
From: Jan Engelhardt @ 2008-04-25 17:39 UTC (permalink / raw)
  To: Pascal Hambourg; +Cc: netfilter


On Thursday 2008-04-24 21:24, Pascal Hambourg wrote:
> noa levy a écrit :
>> 
>> When I add a rule to (or delete a rule from) iptables,
>> while it is running, does that have any effect on the states in the
>> connection tracking table?
>
> No.
>
>> Will the table be flushed?
>
> No.

the conntrack table remains;
the fw rule table is atomically exchanged.

>> Are states linked  to the rule that allowed the initial packet in [...] ?
>
> No.

(No,) but parameters attached to rules may get reset when loading a
new ruleset into the kernel. Now what constutitues an "attached" data
portion hm... xt_quota for example stores its quota counter with the
rule. xt_recent for example on the other hand stores its data in a
separate malloc'ed area that is safe.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Dynamically adding rules - are connection tracking states maintained?
@ 2008-04-28 22:27 noa levy
  2008-04-29 23:37 ` Pascal Hambourg
  0 siblings, 1 reply; 9+ messages in thread
From: noa levy @ 2008-04-28 22:27 UTC (permalink / raw)
  To: Jan Engelhardt, Pascal Hambourg; +Cc: netfilter

Thank you very much for your replies. 
I still don't understand one thing though: Let's say I delete a rule that allows SSH traffic. There are probably many entries in the conntrack table for SSH sessions. Will these sessions continue to be allowed in, even though I have just deleted the rule that allowed SSH (and my default policy is DROP)? 


On Thursday 2008-04-24 21:24, Pascal Hambourg wrote:
> noa levy a écrit :
>> 
>> When I add a rule to (or delete a rule from) iptables,
>> while it is running, does that have any effect on the states in the
>> connection tracking table?
>
> No.
>
>> Will the table be flushed?
>
> No.

the conntrack table remains;
the fw rule table is atomically exchanged.

>> Are states linked  to the rule that allowed the initial packet in [....] ?
>
> No.

(No,) but parameters attached to rules may get reset when loading a
new ruleset into the kernel. Now what constutitues an "attached" data
portion hm... xt_quota for example stores its quota counter with the
rule. xt_recent for example on the other hand stores its data in a
separate malloc'ed area that is safe.
--
To unsubscribe from this list: send the line "unsubscribe netfilter" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html



      ____________________________________________________________________________________
Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Dynamically adding rules - are connection tracking states maintained?
  2008-04-28 22:27 Dynamically adding rules - are connection tracking states maintained? noa levy
@ 2008-04-29 23:37 ` Pascal Hambourg
  2008-05-01 20:22   ` noa levy
  0 siblings, 1 reply; 9+ messages in thread
From: Pascal Hambourg @ 2008-04-29 23:37 UTC (permalink / raw)
  To: netfilter

noa levy a écrit :
> I still don't understand one thing though: Let's say I delete a rule
> that allows SSH traffic. There are probably many entries in the
> conntrack table for SSH sessions. Will these sessions continue to be
> allowed in, even though I have just deleted the rule that allowed SSH
> (and my default policy is DROP)? 

You are asking the wrong question. Iptables is a packet filter, it does 
not filter "sessions" (or connections). As already said, the conntrack 
table is not affected by rule deletion/insertion. So whether packets 
belonging to existing connections are allowed or not depends on the new 
ruleset. If the new ruleset says to ACCEPT packets in the ESTABLISHED 
state, then established connections are still allowed.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Dynamically adding rules - are connection tracking states maintained?
  2008-04-29 23:37 ` Pascal Hambourg
@ 2008-05-01 20:22   ` noa levy
  2008-05-01 22:44     ` Josh Cepek
  0 siblings, 1 reply; 9+ messages in thread
From: noa levy @ 2008-05-01 20:22 UTC (permalink / raw)
  To: netfilter, Pascal Hambourg

Thank you again for your response. Suppose I do want drop existing connections, but I don't want to add the "drop" rule above the "allow established" rule, for performance reasons. Does netfilter provide any API for flushing the conntrack table (all of it or specific entries)? Will stopping the firewall completely flush these entries?


--- On Tue, 4/29/08, Pascal Hambourg <pascal.mail@plouf.fr.eu.org> wrote:

> You are asking the wrong question. Iptables is a packet
> filter, it does 
> not filter "sessions" (or connections). As
> already said, the conntrack 
> table is not affected by rule deletion/insertion. So
> whether packets 
> belonging to existing connections are allowed or not
> depends on the new 
> ruleset. If the new ruleset says to ACCEPT packets in the
> ESTABLISHED 
> state, then established connections are still allowed.




      ____________________________________________________________________________________
Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Dynamically adding rules - are connection tracking states maintained?
  2008-05-01 20:22   ` noa levy
@ 2008-05-01 22:44     ` Josh Cepek
  2008-05-01 22:56       ` Petr Pisar
  2008-05-02  1:10       ` Pablo Neira Ayuso
  0 siblings, 2 replies; 9+ messages in thread
From: Josh Cepek @ 2008-05-01 22:44 UTC (permalink / raw)
  To: levynoa, netfilter

[-- Attachment #1: Type: text/plain, Size: 2444 bytes --]

noa levy wrote:
> Thank you again for your response. Suppose I do want drop existing connections, but I don't want to add the "drop" rule above the "allow established" rule, for performance reasons. Does netfilter provide any API for flushing the conntrack table (all of it or specific entries)?

Not easily, and not without disrupting other active connections.  If 
conntrack support is compiled in as modules you can unload and reload 
them, but this requires that no iptables rules reference the conntrack 
module (ie: you must delete such rules first.)  Once unloaded, the 
kernel will forget the maintained state table, but this also has the 
side-effect of breaking any active sessions that were in an ESTABLISHED 
state when you deleted the rules and reset the state table.

AFAIK there is no way to manually flush the conntrack state table or 
remove specific entries.

> Will stopping the firewall completely flush these entries?
>   

That depends entirely on what the script "stopping the firewall" 
actually does, but general the answer is "no".  If it simply flushes all 
chains and removes non-standard chains, the state table will still exist 
as this support is provided by the conntrack kernel modules, not the 
iptables rules themselves.  Most scripts I've seen on any distro will 
not actually unload the conntrack modules when the firewall initscript 
is stopped, and of course this wouldn't even be possible if conntrack 
support is compiled into the kernel rather than as a module.

It sounds like you might be using the wrong tool for the job; to 
disconnect a user with an active ssh session why not look at running 
sshd processes and send a SIGTERM or SIGINT signal to the one with the 
user or users you wish to disconnect?  This strikes me as a problem best 
handled at an application level rather than a kernel level.

>
> --- On Tue, 4/29/08, Pascal Hambourg <pascal.mail@plouf.fr.eu.org> wrote:
>
>   
>> You are asking the wrong question. Iptables is a packet
>> filter, it does 
>> not filter "sessions" (or connections). As
>> already said, the conntrack 
>> table is not affected by rule deletion/insertion. So
>> whether packets 
>> belonging to existing connections are allowed or not
>> depends on the new 
>> ruleset. If the new ruleset says to ACCEPT packets in the
>> ESTABLISHED 
>> state, then established connections are still allowed.

-- 
Josh



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Dynamically adding rules - are connection tracking states maintained?
  2008-05-01 22:44     ` Josh Cepek
@ 2008-05-01 22:56       ` Petr Pisar
  2008-05-02  1:10       ` Pablo Neira Ayuso
  1 sibling, 0 replies; 9+ messages in thread
From: Petr Pisar @ 2008-05-01 22:56 UTC (permalink / raw)
  To: netfilter

On 2008-05-01, Josh Cepek <josh.cepek@usa.net> wrote:
>
> AFAIK there is no way to manually flush the conntrack state table or
> remove specific entries.
>
There is a way how to do it. The tool is called "conntrack", it's part
of conntrack-tools package and it's distributed by Netfilter team.

-- Petr


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Dynamically adding rules - are connection tracking states maintained?
  2008-05-01 22:44     ` Josh Cepek
  2008-05-01 22:56       ` Petr Pisar
@ 2008-05-02  1:10       ` Pablo Neira Ayuso
  1 sibling, 0 replies; 9+ messages in thread
From: Pablo Neira Ayuso @ 2008-05-02  1:10 UTC (permalink / raw)
  To: Josh Cepek; +Cc: levynoa, netfilter

Josh Cepek wrote:
> noa levy wrote:
>> Thank you again for your response. Suppose I do want drop existing
>> connections, but I don't want to add the "drop" rule above the "allow
>> established" rule, for performance reasons. Does netfilter provide any
>> API for flushing the conntrack table (all of it or specific entries)?
> 
> Not easily, and not without disrupting other active connections.  If
> conntrack support is compiled in as modules you can unload and reload
> them, but this requires that no iptables rules reference the conntrack
> module (ie: you must delete such rules first.)  Once unloaded, the
> kernel will forget the maintained state table, but this also has the
> side-effect of breaking any active sessions that were in an ESTABLISHED
> state when you deleted the rules and reset the state table.
> 
> AFAIK there is no way to manually flush the conntrack state table or
> remove specific entries.

This is no longer true as we have the conntrack-tools.

-- 
"Los honestos son inadaptados sociales" -- Les Luthiers

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2008-05-02  1:10 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-04-28 22:27 Dynamically adding rules - are connection tracking states maintained? noa levy
2008-04-29 23:37 ` Pascal Hambourg
2008-05-01 20:22   ` noa levy
2008-05-01 22:44     ` Josh Cepek
2008-05-01 22:56       ` Petr Pisar
2008-05-02  1:10       ` Pablo Neira Ayuso
  -- strict thread matches above, loose matches on Subject: below --
2008-04-24 16:12 noa levy
2008-04-24 19:24 ` Pascal Hambourg
2008-04-25 17:39   ` Jan Engelhardt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox