All of lore.kernel.org
 help / color / mirror / Atom feed
From: Henrik Nordstrom <hno@marasystems.com>
To: Balazs Scheidler <bazsi@balabit.hu>, netfilter-devel@lists.samba.org
Subject: Re: NAT, not doing route_me_harder?
Date: Wed, 26 Jun 2002 11:13:16 +0200	[thread overview]
Message-ID: <200206261113.16886.hno@marasystems.com> (raw)
In-Reply-To: <20020626084136.GA25908@balabit.hu>

Balazs Scheidler wrote:
> Hi,
>
> I was wondering what the reason is for NAT not rerouting modified packets?
>
> If anything important is modified by a mangle rule that affects routing,
> the routing decision is automatically redone as this code fragment shows:

[snip]

This is done only in the OUTPUT chain, and only because the TCP kernel has 
already routed locally originating packets before they first hit netfilter.

> NAT doesn't do anything like this. So given an SNAT rule changes the source
> address in POSTROUTING, the routing tables are not looked up again, so
> source address dependant policy routing rules are not applied.

It sure does, in the same spot as mangle, which only is when there is a 
destnination nat transformations applied to a locally originated packet.

in ip_nat_local_fn():
        ret = ip_nat_fn(hooknum, pskb, in, out, okfn);
        if (ret != NF_DROP && ret != NF_STOLEN
            && ((*pskb)->nh.iph->saddr != saddr
                || (*pskb)->nh.iph->daddr != daddr))
                return ip_route_me_harder(pskb) == 0 ? ret : NF_DROP;

For the other cases (including mangle), all the transformations that are 
assumed to affect routing is done in PREROUTING. SNAT is not among them.

There is a number of ways to route SNAT:ed packets differently if needed. The 
method I use is usually to use the nfmark of mangle PREROUTING or OUTPUT in 
combination with SNAT in POSTROUTING. Mangle marks the packet telling that 
this should be NAT:ed according to policy X, this nfmark is then used in 
routing to route the packet in the correct direction and by nat POSTROUTING 
to apply the correct NAT rule.

Regards
Henrik

  reply	other threads:[~2002-06-26  9:13 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-06-26  8:41 NAT, not doing route_me_harder? Balazs Scheidler
2002-06-26  9:13 ` Henrik Nordstrom [this message]
2002-06-26  9:55   ` Balazs Scheidler
2002-06-26 10:04     ` Henrik Nordstrom
2002-06-26 10:18       ` Balazs Scheidler

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=200206261113.16886.hno@marasystems.com \
    --to=hno@marasystems.com \
    --cc=bazsi@balabit.hu \
    --cc=netfilter-devel@lists.samba.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 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.