* fwmark & iptables
@ 2010-01-28 10:37 Matt Hakim
2010-01-28 11:36 ` Pascal Hambourg
2010-01-28 11:37 ` Oskar Berggren
0 siblings, 2 replies; 8+ messages in thread
From: Matt Hakim @ 2010-01-28 10:37 UTC (permalink / raw)
To: netfilter
Hi,
I want to mark packets for a particular user (iptables -t mangle -A
OUTPUT -mowner --uid-owner rtorrent -j MARK --set-mark 1), and then
route these packets to a VPN (ip rule add fwmark 1 lookup 200; ip
route add default dev ppp0 table 200). Unfortunately, after I do this
tcpdump shows that the default interfaces source address is being put
out on the ppp0 link which I don't understand, as I would have
expected the ppp0 interface address to be the source address. Anyway
it fails.
Without using MARK and ip routing based on destination works OK though
(from all to 66.102.11.104 lookup 200; ip route add default dev ppp0
table 200).
Any tips? I'll hack around in the source now see what i can find.
Thanks,
Matt
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: fwmark & iptables
2010-01-28 10:37 fwmark & iptables Matt Hakim
@ 2010-01-28 11:36 ` Pascal Hambourg
2010-01-28 13:26 ` Matt Hakim
2010-01-28 11:37 ` Oskar Berggren
1 sibling, 1 reply; 8+ messages in thread
From: Pascal Hambourg @ 2010-01-28 11:36 UTC (permalink / raw)
To: netfilter
Hello,
Matt Hakim a écrit :
> Hi,
> I want to mark packets for a particular user (iptables -t mangle -A
> OUTPUT -mowner --uid-owner rtorrent -j MARK --set-mark 1), and then
> route these packets to a VPN (ip rule add fwmark 1 lookup 200; ip
> route add default dev ppp0 table 200). Unfortunately, after I do this
> tcpdump shows that the default interfaces source address is being put
> out on the ppp0 link which I don't understand, as I would have
> expected the ppp0 interface address to be the source address.
The source address is selected before when the packet is created, before
it enters the OUTPUT chain and gets marked and then rerouted according
to the mark. Rerouting only updates the output interface and nexthop, it
cannot update the source address.
> Any tips? I'll hack around in the source now see what i can find.
Either select the source address in the application or SNAT/MASQUERADE
on ppp0 for IPv4 traffic. The former is not always possible (application
does not allow it, or address is not fixed) and the latter is not
applicable to IPv6 as Linux has no IPv6 NAT and will hopefully never.
Couldn't there be a way to achieve proper source address selection,
maybe by the use of a "virtual" packet that would be sent through
iptables' OUTPUT chains and MARKed/DNATed as part of the source address
selection prior to sending the real packet ?
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: fwmark & iptables
2010-01-28 10:37 fwmark & iptables Matt Hakim
2010-01-28 11:36 ` Pascal Hambourg
@ 2010-01-28 11:37 ` Oskar Berggren
1 sibling, 0 replies; 8+ messages in thread
From: Oskar Berggren @ 2010-01-28 11:37 UTC (permalink / raw)
To: Matt Hakim; +Cc: netfilter
Since this is output (not forward) the first routing of the packet
takes place before iptables have had a change to mark it. After the
mark it is rerouted, but the source ip-address is taken from the
output interface that comes from the first routing. At least, this is
my understanding of it.
/Oskar
2010/1/28 Matt Hakim <thepigs@gmail.com>:
> Hi,
> I want to mark packets for a particular user (iptables -t mangle -A
> OUTPUT -mowner --uid-owner rtorrent -j MARK --set-mark 1), and then
> route these packets to a VPN (ip rule add fwmark 1 lookup 200; ip
> route add default dev ppp0 table 200). Unfortunately, after I do this
> tcpdump shows that the default interfaces source address is being put
> out on the ppp0 link which I don't understand, as I would have
> expected the ppp0 interface address to be the source address. Anyway
> it fails.
> Without using MARK and ip routing based on destination works OK though
> (from all to 66.102.11.104 lookup 200; ip route add default dev ppp0
> table 200).
> Any tips? I'll hack around in the source now see what i can find.
> Thanks,
> Matt
> --
> 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
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: fwmark & iptables
2010-01-28 11:36 ` Pascal Hambourg
@ 2010-01-28 13:26 ` Matt Hakim
2010-01-28 13:35 ` Pascal Hambourg
0 siblings, 1 reply; 8+ messages in thread
From: Matt Hakim @ 2010-01-28 13:26 UTC (permalink / raw)
To: Pascal Hambourg; +Cc: netfilter
Thanks for your replies.
> Either select the source address in the application or SNAT/MASQUERADE
> on ppp0 for IPv4 traffic.
Tried that. Worked outbound, but inbound I could only LOG the packets
at mangle PREROUTING (I think), and then they disappeared. No idea
why.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: fwmark & iptables
2010-01-28 13:26 ` Matt Hakim
@ 2010-01-28 13:35 ` Pascal Hambourg
2010-01-28 20:50 ` Matt Hakim
0 siblings, 1 reply; 8+ messages in thread
From: Pascal Hambourg @ 2010-01-28 13:35 UTC (permalink / raw)
To: netfilter
Matt Hakim a écrit :
>
>> Either select the source address in the application or SNAT/MASQUERADE
>> on ppp0 for IPv4 traffic.
>
> Tried that. Worked outbound, but inbound I could only LOG the packets
> at mangle PREROUTING (I think), and then they disappeared. No idea
> why.
Forgot about that, sorry. Make sure sysctl net.ipv4.conf.ppp0.rp_filter
is set to 0 after ppp0 is created, otherwise the packet is discarded at
the input routing decision stage. sysctl net.ipv4.conf.default.rp_filter
contains the value that will be set for any new interface.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: fwmark & iptables
2010-01-28 13:35 ` Pascal Hambourg
@ 2010-01-28 20:50 ` Matt Hakim
2010-01-28 23:06 ` Matt Hakim
0 siblings, 1 reply; 8+ messages in thread
From: Matt Hakim @ 2010-01-28 20:50 UTC (permalink / raw)
To: netfilter
> Forgot about that, sorry. Make sure sysctl net.ipv4.conf.ppp0.rp_filter
> is set to 0 after ppp0 is created, otherwise the packet is discarded at
> the input routing decision stage. sysctl net.ipv4.conf.default.rp_filter
> contains the value that will be set for any new interface.
Didn't seem to help.
Currently I've got this:
sysctl net.ipv4.conf.default.rp_filter=0
pon VPN (rp_filter for ppp0 is 0 at this point)
iptables -t mangle -A OUTPUT -mowner --uid-owner rtorrent -j MARK --set-mark 1
ip rule add fwmark 1 lookup 200
ip route add default dev ppp0 table 200
iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE
I can see packets go out and replies come back and then get lost at
mangle PREROUTING. Maybe I need to mark the packets coming back in or
is it some connection tracking prob?
Thanks,
Matt
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: fwmark & iptables
2010-01-28 20:50 ` Matt Hakim
@ 2010-01-28 23:06 ` Matt Hakim
2010-01-29 6:24 ` Pascal Hambourg
0 siblings, 1 reply; 8+ messages in thread
From: Matt Hakim @ 2010-01-28 23:06 UTC (permalink / raw)
To: netfilter
On Fri, Jan 29, 2010 at 7:50 AM, Matt Hakim <thepigs@gmail.com> wrote:
>> Forgot about that, sorry. Make sure sysctl net.ipv4.conf.ppp0.rp_filter
>> is set to 0 after ppp0 is created, otherwise the packet is discarded at
>> the input routing decision stage. sysctl net.ipv4.conf.default.rp_filter
>> contains the value that will be set for any new interface.
>
> Didn't seem to help.
>
OK its working now, after I did various:
echo 0 > /proc/sys/net/ipv4/conf/all/rp_filter
echo 0 > /proc/sys/net/ipv4/conf/eth0/rp_filter
Thanks for your help,
Matt
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: fwmark & iptables
2010-01-28 23:06 ` Matt Hakim
@ 2010-01-29 6:24 ` Pascal Hambourg
0 siblings, 0 replies; 8+ messages in thread
From: Pascal Hambourg @ 2010-01-29 6:24 UTC (permalink / raw)
To: Matt Hakim; +Cc: netfilter
Matt Hakim a écrit :
> On Fri, Jan 29, 2010 at 7:50 AM, Matt Hakim <thepigs@gmail.com> wrote:
>>
>>> Forgot about that, sorry. Make sure sysctl net.ipv4.conf.ppp0.rp_filter
>>> is set to 0 after ppp0 is created, otherwise the packet is discarded at
>>> the input routing decision stage. sysctl net.ipv4.conf.default.rp_filter
>>> contains the value that will be set for any new interface.
>>
>> Didn't seem to help.
>
> OK its working now, after I did various:
>
> echo 0 > /proc/sys/net/ipv4/conf/all/rp_filter
> echo 0 > /proc/sys/net/ipv4/conf/eth0/rp_filter
What is the kernel version ? In 2.6.31 and newer versions, because of
the previous addition of "loose mode" to reverse path filtering in
version 2.6.30 (see Documentation/networking/ip-sysct.txt [1]), the
combination of net.ipv4.conf.$interface.rp_filter and
net.ipv4.conf.all.rp_filter to produce the functional value for
$interface was changed from a logical AND into an arithmetic MAX, so
net.ipv4.conf.all.rp_filter must also be set to 0 to disable reverse
path filtering on an interface. However it should not be necessary to
set rp_filter to 0 for eth0 too if it is not used for advanced routing.
> Thanks for your help,
You're welcome. This is a common but tricky issue.
[1] Note for myself : ask to change "conf/all/rp_filter must also be set
to non-zero to do source validation on the interface" in ip-sysctl.txt
which is no longer true and thus misleading.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2010-01-29 6:24 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-01-28 10:37 fwmark & iptables Matt Hakim
2010-01-28 11:36 ` Pascal Hambourg
2010-01-28 13:26 ` Matt Hakim
2010-01-28 13:35 ` Pascal Hambourg
2010-01-28 20:50 ` Matt Hakim
2010-01-28 23:06 ` Matt Hakim
2010-01-29 6:24 ` Pascal Hambourg
2010-01-28 11:37 ` Oskar Berggren
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox