Linux Netfilter discussions
 help / color / mirror / Atom feed
From: Pascal Hambourg <pascal.mail@plouf.fr.eu.org>
To: netfilter@vger.kernel.org
Subject: Re: miscellaneous netfilter questions
Date: Fri, 05 Mar 2010 00:36:00 +0100	[thread overview]
Message-ID: <4B9043E0.90608@plouf.fr.eu.org> (raw)
In-Reply-To: <1267697943.22478.17.camel@etppc09.garching.physik.uni-muenchen.de>

Christoph Anton Mitterer a écrit :
> 
>> For IPv4, indeed when conntrack is enabled incoming fragmented datagrams
>> are reassembled before the PREROUTING chains. Note that packets which
>> are to be delivered locally are reassembled by the stack (not by
>> conntrack) before the INPUT chains anyway, so you never see fragments in
>> INPUT chains.
> ok... well...
> a) What about packages not delivered locally? I assume they're simply
> passed on in the fragmented state as they are? Is this always the case?

Yes, unless conntrack is enabled.

> E.g. if the next hop network as an MTU that is smaller than the fragment
> size?

Some time ago I had observed on 2.4 kernels that packets which are too
big with DF=0 are fragmented to fit the MTU after the FORWARD chain.
However if nat is enabled, datagrams are reassembled again in
nat/POSTROUTING and fragmented again afterwards. I did not check whether
it is the same on 2.6 kernels or it was optimized in order to reassemble
and fragment only once at most.

> b) All these things which you say that are happening on the stack (e.g.
> the defragmentation here, dropping of packets with bogus addresses or
> source addresses that match the address of a local interface)... these
> things generally happen _before_ netfilter, right? Or at which place are
> they happening?

They happen at different stages of the packet path, betweek netfilter
hooks. Netfilter and the rest of the stack are interleaved. E.g, the
input routing decision is between PREROUTING and INPUT/FORWARD. Diagrams
are available throughout the web.

>> AFAIK things work a bit differently for IPv6 : fragmented datagrams are
>> "virtually" reassembled for conntrack (the reason being that an IPv6
>> router does not handle fragmentation/reassembly), but continue to exist
>> as fragments through the ip6tables chains and the IPv6 stack.
> Ah... I see... uhm... in this case, how would the following work?
> Image one wants to allow incomming packets for ssh so we have about:
> :INPUT DROP
> -A INPUT --protocol tcp -m tcp --destination-port ssh -j ACCEPT
> 
> Now packets come in fragmented,... this would not work for later
> fragments right, as the port is not known... so as soon as fragmentation
> happens, the above would not work (as expected).

I guess so. However IPv6 deprecates fragmentation by routers and makes
path MTU discovery mandatory, so fragmentation with TCP should be very
uncommon.

> But it should work with those rules:
> :INPUT DROP
> -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
> -A INPUT --protocol tcp -m tcp --destination-port ssh --syn -j ACCEPT
> 
> ..because contrack still works, and the fragmented packets are accepted
> by the first rule.
> 
> Do I understand this correctly?

I guess so. However I haven't played much with IPv6 conntrack yet,
although I use IPv6.

      parent reply	other threads:[~2010-03-04 23:36 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-03 15:54 miscellaneous netfilter questions Christoph Anton Mitterer
2010-03-03 16:57 ` Pascal Hambourg
2010-03-04  5:52   ` ratheesh k
2010-03-04 10:19   ` Christoph Anton Mitterer
2010-03-04 14:37     ` Mart Frauenlob
2010-03-04 23:36     ` Pascal Hambourg [this message]

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=4B9043E0.90608@plouf.fr.eu.org \
    --to=pascal.mail@plouf.fr.eu.org \
    --cc=netfilter@vger.kernel.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