SO_ORIGINAL_DST does not work in nat/OUTPUT anymore
Subsystems (4)
Hi,
the upstream patch from
https://bugzilla.netfilter.org/bugzilla/show_bug.cgi?id=91
destroys the functionality of SO_ORIGINAL_DST for local generated packets. It returns the local address the connection is redirected to instead of the original destination address. As a result you cannot use local transparent proxies anymore.
The responsible change is
net/ipv4/ip_output.c +2 -0
@@ -195,6 +195,8 @@nf_debug_ip_finish_output2 (skb);#endif /*CONFIG_NETFILTER_DEBUG*/ +nf_reset (skb); +if (hh) {int hh_alen;
After removing the added line SO_ORIGINAL_DST returns the expected address.
Should I open a new bug or reopen the old one?
Regards,
Jens
Quoted 10 lines · Jens Hoelldampf
Hi,
the upstream patch from
https://bugzilla.netfilter.org/bugzilla/show_bug.cgi?id=91
destroys the functionality of
SO_ORIGINAL_DSTfor local generated packets. It returns the local address the connection is redirected to instead of the original destination address. As a result you cannot use local transparent proxies anymore.
ouch. It seems like we really need to revert that change and find a different solution for conntrack unloading :(
Thanks for reporting this.
Patrick, are you already working on this?
Quoted 1 line
Should I open a new bug or reopen the old one?
please open a new one, since it's a different problem.
Signature · 5 lines
- Harald Welte <[email protected]> http://netfilter.org/ ============================================================================ "Fragmentation is like classful addressing -- an interesting early architectural error that shows how much experimentation was going on while IP was being designed." -- Paul Vixie
Quoted 11 lines · Harald Welte
Quoted 8 lines · Jens Hoelldampf
the upstream patch from
https://bugzilla.netfilter.org/bugzilla/show_bug.cgi?id=91
destroys the functionality of
SO_ORIGINAL_DSTfor local generated packets. It returns the local address the connection is redirected to instead of the original destination address. As a result you cannot use local transparent proxies anymore.
Quoted 6 lines
ouch. It seems like we really need to revert that change and find a different solution for conntrack unloading :(
Thanks for reporting this.
Patrick, are you already working on this?
I was thinking about reverting it because of the RST over loopback problem reported in another thread, but wanted to discuss it with you first. I don't see how this change can affect SO_ORIGINAL_DST though, all it does is look up the conntrack entry by a tuple generated from data stored in the socket. It never even gets to see a packet.
Regards
Patrick
Quoted 4 lines · Patrick McHardy
you first. I don't see how this change can affect
SO_ORIGINAL_DSTthough, all it does is look up the conntrack entry by a tuple generated from data stored in the socket. It never even gets to see a packet.
I would guess the problem is that there may be two conntracks for the session, one before nat and another after, or that the tuple lookup does not look at the expected tuple variant needed to find the conntrack.. If I understood the Jens problem correctly this traffic goes over loopback via DNAT.. (output -> DNAT -> loopback -> input -> socket)
Regards
Henrik
Quoted 7 lines · Henrik Nordstrom
Quoted 4 lines · Patrick McHardy
you first. I don't see how this change can affect
SO_ORIGINAL_DSTthough, all it does is look up the conntrack entry by a tuple generated from data stored in the socket. It never even gets to see a packet.
Quoted 5 lines
I would guess the problem is that there may be two conntracks for the session, one before nat and another after, or that the tuple lookup does not look at the expected tuple variant needed to find the conntrack.. If I understood the Jens problem correctly this traffic goes over loopback via DNAT.. (output -> DNAT -> loopback -> input -> socket)
You're absolutely right. After performing DNAT the packet doesn't match either side of the conntrack in PRE_ROUTING and a new one is created.
iptables -t nat -A OUTPUT -d 1.2.3.4 -j DNAT --to-dest 127.0.0.1
telnet 1.2.3.4 22 results in this conntrack:
tcp 6 431997 ESTABLISHED src=172.16.1.123 dst=1.2.3.4 sport=37395
dport=22 packets=3 bytes=164 src=127.0.0.1 dst=172.16.1.123 sport=22 dport=37395 packets=2 bytes=153 [ASSURED] mark=0 use=1
In PRE_ROUTING the packet will be 172.16.1.123:37395->127.0.0.1:22, which doesn't match and a new conntrack is created:
tcp 6 431997 ESTABLISHED src=172.16.1.123 dst=127.0.0.1 sport=37395
dport=22 packets=3 bytes=164 src=127.0.0.1 dst=172.16.1.123 sport=22 dport=1024 packets=2 bytes=153 [ASSURED] mark=0 use=1
This is the one where SO_ORIGINAL_DST gets its destination from.
Thanks for the hint. Harald, if I can't think of anything else (seems likely) I'll revert the patch.
Regards
Patrick
Quoted 2 lines · Patrick McHardy
Thanks for the hint. Harald, if I can't think of anything else (seems likely) I'll revert the patch.
Yes, I'm also in favour of reverting the patch. The number of functional bugs it has caused by far outweigh the gain of save 'rmmod' without loops.
Signature · 5 lines
- Harald Welte <[email protected]> http://netfilter.org/ ============================================================================ "Fragmentation is like classful addressing -- an interesting early architectural error that shows how much experimentation was going on while IP was being designed." -- Paul Vixie
Quoted 2 lines · Harald Welte
Yes, I'm also in favour of reverting the patch. The number of functional bugs it has caused by far outweigh the gain of save 'rmmod' without loops.
Agreed, unfortunately. If we can't get module unload to work reliably we should introduce another way to flush the conntrack table however. I'm thinking of something easy like a /proc file.
Regards
Patrick
Quoted 7 lines · Harald Welte
Quoted 2 lines · Patrick McHardy
Thanks for the hint. Harald, if I can't think of anything else (seems likely) I'll revert the patch.
Yes, I'm also in favour of reverting the patch. The number of functional bugs it has caused by far outweigh the gain of save 'rmmod' without loops.
I humbly re-resubmit my original patch. The problem occurs (most frequently) in the case of raw sockets, which my patch addresses. Patrick will point out that stopped qdiscs are not handled by this patch, and I concur. However, it would seem that fixing the most common cause of module unload problems is better than the plethora of problems the alternative patch has caused...
Phil
net/ipv4/ip_output.c +0 -2
@@ -196,8 +196,6 @@ static inline int ip_finish_output2(strunf_debug_ip_finish_output2 (skb);#endif /*CONFIG_NETFILTER_DEBUG*/ -nf_reset (skb); -if (hh) {int hh_alen;
net/ipv4/netfilter/ip_conntrack_standalone.c +7 -0
@@ -432,6 +432,13 @@ static unsigned int ip_conntrack_defrag( const struct net_device *out, int (*okfn)(struct sk_buff *)) { +#if !defined(CONFIG_IP_NF_NAT ) && !defined(CONFIG_IP_NF_NAT_MODULE ) +/* Previously seen (loopback)? Ignore. Do this before +fragment check. */ +if ((*pskb)->nfct) +return NF_ACCEPT ; +#endif +/* Gather fragments. */ if ((*pskb)->nh.iph->frag_off &htons (IP_MF |IP_OFFSET )) { *pskb = ip_ct_gather_frags(*pskb,
net/packet/af_packet.c +6 -0
@@ -274,6 +274,9 @@ static int packet_rcv_spkt(struct sk_bufdst_release (skb->dst); skb->dst =NULL ; +/* drop conntrack reference */ +nf_reset (skb); + spkt = (struct sockaddr_pkt *)skb->cb;skb_push (skb, skb->data-skb->mac.raw);
@@ -517,6 +520,9 @@ static int packet_rcv(struct sk_buff *skdst_release (skb->dst); skb->dst =NULL ; +/* drop conntrack reference */ +nf_reset (skb); +spin_lock (&sk->sk_receive_queue.lock); po->stats.tp_packets++;__skb_queue_tail (&sk->sk_receive_queue, skb);
Quoted 1 line · Phil Oester
I humbly re-resubmit my original patch.
It doesn't apply to the current tree. I'm going to fix it up manually, but please base future patches on linus's latest tree.
Quoted 2 lines
The problem occurs (most frequently)
in the case of raw sockets, which my patch addresses.
Unfortunately this is only true in your case. There was a report without any packet sockets involved just two weeks ago and I have multiple reports at work without any packet sockets. In these cases qdiscs aren't the problem either, so it seems there are still spots that need fixing after reverting the patch.
Anyway, your patch is the best we can do right now, thanks.
Quoted 7 lines · Patrick McHardy
Quoted 1 line · Phil Oester
I humbly re-resubmit my original patch.
It doesn't apply to the current tree. I'm going to fix it up manually, but please base future patches on linus's latest tree.
... and for the 2.4.x case? I most certainly haven't had the time to test this use case yet but the problems should be the same.
Cheers,
Roberto Nibali, ratz
Signature · 6 lines
------------------------------------------------------------- addr://Rathausgasse 31, CH-5001 Aarau tel://++41 62 823 9355 http://www.terreactive.com fax://++41 62 823 9356 ------------------------------------------------------------- terreActive AG Wir sichern Ihren Erfolg -------------------------------------------------------------
Quoted 6 lines
Quoted 2 lines
Yes, I'm also in favour of reverting the patch. The number of functional bugs it has caused by far outweigh the gain of save 'rmmod' without loops.
Agreed, unfortunately. If we can't get module unload to work reliably we should introduce another way to flush the conntrack table however. I'm thinking of something easy like a /proc file.
But in the time that passes between echo 1 >/proc/flushme and rmmod new entries could show up, if it's "just" a flush and not a flush-and-disable operation.
Jan Engelhardt
Signature · 1 line
| Alphagate Systems, http://alphagate.hopto.org/
Quoted 2 lines · Roberto Nibali
... and for the 2.4.x case? I most certainly haven't had the time to test this use case yet but the problems should be the same.
Yes, we can't submit the patch for 2.4 either. It has no bridging, so this problem is 2.6 only, but the RST over loopback and the SO_ORIGINAL_DST problem remain. This means we still need to figure out where your hangs are coming from.
Regards
Patrick
Quoted 8 lines · Jan Engelhardt
Quoted 6 lines
Quoted 2 lines
Yes, I'm also in favour of reverting the patch. The number of functional bugs it has caused by far outweigh the gain of save 'rmmod' without loops.
Agreed, unfortunately. If we can't get module unload to work reliably we should introduce another way to flush the conntrack table however. I'm thinking of something easy like a /proc file.
But in the time that passes between echo 1 >/proc/flushme and rmmod new entries could show up, if it's "just" a flush and not a flush-and-disable operation.
"flush-and-disable" (should actually be disable-and-flush) can be achieved by adding a rule to drop everything before flushing. Its not meant to clean up before rmmod (conntrack tries to do this itself) but to kick out old conntrack entries after ruleset changes.
Regards
Patrick
Quoted 7 lines · Patrick McHardy
Quoted 3 lines · Roberto Nibali
... and for the 2.4.x case? I most certainly haven't had the time to test this
use case yet but the problems should be the same.Yes, we can't submit the patch for 2.4 either.
Darn. But glad we didn't.
Quoted 1 line
It has no bridging,
Well, I do have the bridging code patch in my 2.4.x patchset because we need the bridging functionality for a couple of setups. But haven't come around to testing it yet. I think a considerable amount of people running 2.4.x still also have the bridging code patched.
Quoted 3 lines
so this problem is 2.6 only, but the RST over loopback and the
SO_ORIGINAL_DSTproblem remain. This means we still need to figure out where your hangs are coming from.
How may I assist in resolving this issue? Can't we track those references in a better way?
Regards,
Roberto Nibali, ratz
Signature · 6 lines
------------------------------------------------------------- addr://Rathausgasse 31, CH-5001 Aarau tel://++41 62 823 9355 http://www.terreactive.com fax://++41 62 823 9356 ------------------------------------------------------------- terreActive AG Wir sichern Ihren Erfolg -------------------------------------------------------------
Quoted 7 lines · Roberto Nibali
Quoted 3 lines · Patrick McHardy
so this problem is 2.6 only, but the RST over loopback and the
SO_ORIGINAL_DSTproblem remain. This means we still need to figure out where your hangs are coming from.How may I assist in resolving this issue?
I'm looking for spots where we hold the reference but don't need it anymore. If I find something interesting I'll let you know.
Quoted 1 line
Can't we track those references in a better way?
None I can think of.
Regards
Patrick
Quoted 10 lines · Jan Engelhardt
Quoted 6 lines
Quoted 2 lines
Yes, I'm also in favour of reverting the patch. The number of functional bugs it has caused by far outweigh the gain of save 'rmmod' without loops.
Agreed, unfortunately. If we can't get module unload to work reliably we should introduce another way to flush the conntrack table however. I'm thinking of something easy like a /proc file.
But in the time that passes between echo 1 >/proc/flushme and rmmod new entries could show up, if it's "just" a flush and not a flush-and-disable operation.
I think you misunderstood Patrkick. The /proc file would be to flush the table and therefore making the rmmod-insmod cycle if ip_conntrack no longer necessarry.
If we could easily get rid of all conntracks [and their references], we wouldn't need the /proc file, but could do it in the modules fini() function.
Signature · 5 lines
- Harald Welte <[email protected]> http://netfilter.org/ ============================================================================ "Fragmentation is like classful addressing -- an interesting early architectural error that shows how much experimentation was going on while IP was being designed." -- Paul Vixie