All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pascal Hambourg <pascal@plouf.fr.eu.org>
To: netfilter@vger.kernel.org
Subject: Re: Wrong routing when combining ip rule with SNAT
Date: Sat, 14 Sep 2013 19:17:22 +0200	[thread overview]
Message-ID: <52349A22.9060307@plouf.fr.eu.org> (raw)
In-Reply-To: <52348363.6080804@rath.org>

Nikolaus Rath a écrit :
> 
> I see. Out of curiosity: how is the source address selected when the
> packet is created, and in which situation would the source entry in the
> routing table become effective?

The source address selection process is quite complicated and I'm not
sure I know all the details. As far as I know, the selected source
address is, in decreasing order of priority :
- the source address specified by the sending process/socket
- the source address specified in the routing table entry used for the
destination
- the address of the output interface matching the destination prefix of
the routing table entry
- the address of the output interface
- any other suitable address of any other interface (i.e. not a loopback
address if the destination is not local)

>> Possible workarounds :
>> - Add a route on ebox to let it know that 192.168.17.47 is reachable
>> through rath. My favourite choice.
> 
> Yes, that would be the simplest solution. But the problem is that this
> address varies depending how and where vostro got its connectivity. Or
> did you mean something other than a static extra route?

I mean any means to create that route. May be dynamic, using a routing
protocol. However if ath is a tunnel using the other address for
encapsulation, this workaround may not be applicable easily
(encapsulated packets must still be routed normally).

>> - Use SNAT to the address of the output interface on vostro.
> 
> Sounds ugly...

Yes. But simple to setup and effective.

>> - Use connection mark (connmark) by iptables on ebox so that replies to
>> original packets received on a given interface are forwarded to the same
>> interface.
> 
> I guess I'll try this. Could you give some more details? I'm not sure
> how to create a rule that *changes* the outgoing interface.

It's not very different from marking packets for advanced routing.
I haven't done that recently, but here is a basic overview :

# mark the connections of packets received on rath
iptables -t mangle -A PREROUTING -i rath -j CONNMARK --set-mark 1

# copy the connection mark to the packets received on eth0
iptables -t mangle -A PREROUTING -i eth0 -j CONNMARK --restore-mark

# use the mark to route packets received on eth0
ip rule add fwmark 1 dev eth0 table tovpn

  reply	other threads:[~2013-09-14 17:17 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-13  5:10 Wrong routing when combining ip rule with SNAT Nikolaus Rath
2013-09-13  6:26 ` Vigneswaran R
2013-09-13 16:09   ` Nikolaus Rath
2013-09-13 22:03     ` Nikolaus Rath
2013-09-14 13:41   ` Pascal Hambourg
2013-09-14 15:40     ` Nikolaus Rath
2013-09-14 17:17       ` Pascal Hambourg [this message]
2013-09-16  7:14       ` Vigneswaran R
2013-09-16 23:38 ` Eliezer Croitoru
2013-09-17  0:58   ` Nikolaus Rath
2013-09-17 12:35     ` Alex Bligh
2013-09-17 23:23       ` Pascal Hambourg
2013-09-18  0:55         ` Nikolaus Rath
2013-09-18  7:58           ` Alex Bligh
2013-09-18 17:38             ` Nikolaus Rath
2013-09-18 20:11               ` Alex Bligh
2013-09-19  2:29                 ` Nikolaus Rath
2013-09-17 21:58     ` Eliezer Croitoru
2013-09-18  0:58       ` Nikolaus Rath
2013-09-18  5:54     ` Vigneswaran R
2013-09-18 17:51       ` Nikolaus Rath
2013-09-19  9:25         ` Vigneswaran R

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=52349A22.9060307@plouf.fr.eu.org \
    --to=pascal@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 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.