All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joel Newkirk <netfilter@newkirk.us>
To: Tony Clayton <tony-netfilter@enfusion-group.com>,
	netfilter@lists.netfilter.org
Subject: Re: lifecycle of a packet
Date: Thu, 9 Jan 2003 19:47:09 -0500	[thread overview]
Message-ID: <200301091947.09864.netfilter@newkirk.us> (raw)
In-Reply-To: <1042152892.3e1dfdbc6f5d1@webmail.enfusion-group.com>

On Thursday 09 January 2003 05:54 pm, Tony Clayton wrote:
> I've been reading the various docs linked to from netfilter.org,
> hoping to figure out the exact order in which a packet traverses the
> various tables and chains as it passes through the network stack.
>
> Unfortunately, I couldn't find a definative resource that contained
> this information, so I decided to figure it out myself.

Oskar's tutorial at http://iptables-tutorial.frozentux.net covers it 
pretty nicely, although his main diagrams and tables don't clarify the 
single-hit nature of the NAT chains.  (he covers this elsewhere)

> I build a quick script to insert LOG rules into every chain of every
> table, so that I could log the order in which the tables and chains
> are traversed.

That's the best solution anyway.  Until you do it yourself you can't 
/really/ know it, and IIRC some earlier versions traversals were 
slightly different.  (All through my childhood my mom had a sign in one 
room "I hear and I forget, I see and I remember, I do and I understand" 
which seems pretty accurate usually :^)

> Here are my findings, using the three test cases below:

[snipped]

> This is quite interesting, and not at all what I was expecting based
> on what I'd read.

One you missed, which threw me when I first discovered it:  Firewall box 
to itself.  This one bypasses nat PREROUTING entirely...  I guess since 
it's inbound on interface lo then there is only one rational destination 
anyway, so that chain would be pretty much useless.  If you want to DNAT 
a localhost connection you do it in nat OUTPUT.

> I have a list of questions about this behaviour, keeping in mind that
> I'm fairly new to iptables/netfilter:
>
> 1. Why does only the first packet for a TCP/IP connection seem to pass
> through the nat table?  Does connection tracking take over if the
> packet is (ESTABLISHED,RELATED) and work some magic under the covers?

Precisely, plus some.  Even if you don't have an 'EST/REL' rule, 
conntrack's still there under the hood.  (check "lsmod | grep ip" and 
you'll see that ip_conntrack is a dependancy for iptable_nat)  This is 
how netfilter knows that return traffic IS return traffic, and what IP 
to forward it back to when unSNATting packets.

> 2. Why do both OUTPUT and POSTROUTING chains get traversed for packets
> that the firewall sends out?  Is this useful at all?

As an example, you can DNAT in nat OUTPUT, (but not POSTROUTING - the 
routing decision has already been made) to allow you to change 
destination without the local process knowing or needing to know.  You 
can SNAT in nat POSTROUTING but not OUTPUT.  You can change TTL in 
mangle POSTROUTING for all packets, whether OUTPUT or FORWARD fed them 
in, so that for example they are all the same, (a few ISP's apparently 
look for differing TTL's when policing for 'hidden' machines that they 
want to charge connection fees for) and you can change TOS or mark in 
mangle OUTPUT so that routing can be based on those, which again has 
already been decided before the packet reaches any POSTROUTING chains.

> 3. Most of the documents I looked at were fairly old.  Is there a
> somewhat recent document that perhaps might benefit from including
> these tests?

Oskar Andreasson's tutorial is updated and tweaked frequently, I believe 
he announced the latest update on this list Dec 19.  The only references 
I've EVER used for iptables are his tutorial and the main documentation.  
He also recommends setting up log rules the way you did to double-check 
that traversal works the way you believe it does.

> thanks,
>
> Tony

j



      parent reply	other threads:[~2003-01-10  0:47 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-01-09 22:54 lifecycle of a packet Tony Clayton
2003-01-10  0:33 ` Anders Fugmann
2003-01-10 16:09   ` Oskar Andreasson
2003-01-10 16:52     ` lifecycle of a packet (OT) Anders Fugmann
2003-01-10 19:24       ` tony
2003-01-10 19:37       ` Tony Clayton
2003-01-22 15:51       ` Oskar Andreasson
2003-01-22 16:29         ` Kevin McConnell
2003-01-10  0:47 ` Joel Newkirk [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=200301091947.09864.netfilter@newkirk.us \
    --to=netfilter@newkirk.us \
    --cc=netfilter@lists.netfilter.org \
    --cc=tony-netfilter@enfusion-group.com \
    /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.