All of lore.kernel.org
 help / color / mirror / Atom feed
* Re-routing packets via netfilter (ip_rt_bug)
@ 2005-04-25  9:49 Yair Itzhaki
  2005-04-25  9:07   ` Patrick McHardy
                   ` (3 more replies)
  0 siblings, 4 replies; 42+ messages in thread
From: Yair Itzhaki @ 2005-04-25  9:49 UTC (permalink / raw)
  To: linux-kernel

* Summary:
While traversing packets through Netfilter, changing dest address from a foreign to a local address causes the packet to drop (and show up at ip_rt_bug(), along a syslog entry).

* Description:
I'm using libipq/ip_tables and ip_queue to trap packets to a userspace VPN product, using nothing but standard kernel modules (and my own VPN proxy app).

The packets flowing into or out of the machine get diverted to a userspace application, src/dest addresses are modified, and injected back into the IP stack. 

For example, an outgoing packet (that has a foreign dest addr) is overridden with a local dest address, hoping it would end up at the local VPN listener. 

Under kernel 2.4 this works fine.
In 2.6 it breaks. 

* Details:
An outgoing packet (has a non-local dest addr) is queued and recognized at the ip_queue userspace app. Its dest addr+port are set to that of the local machine (to get to my userspace VPN app).
The modified packet is marked NF_ACCEPT and sent back into the kernel, but ends up at the ip_rt_bug function (with a syslog entry).

* Assumed bug analysis:
Due to the destination address change, the packet needed to go through routing once again, since it's no longer an outgoing packet.
This does happen in the ip_route_me_harder function, which sets the dst->output to point at ip_rt_bug.
Since this was an outgoing packet (in the NF_IP_LOCAL_OUT chain), the final operation done on the packet is calling the *okfn function, which points to dst->output which is ip_rt_bug.

I would have expected the routing function to realize it needs to re-evaluate the route, and set the *okfn to dst->input instead.

* Kernel version:
2.6.9-prep, (Red Hat 3.4.2-6.fc3) compiled locally with no modifications.

Please advise (and please CC "YAIR at ARX.COM")

A similar problem has been reported a while back but never replied (http://groups-beta.google.com/group/linux.kernel/msg/455c04e17e354d04?dmode=source&hl=en)


Yair

^ permalink raw reply	[flat|nested] 42+ messages in thread
* RE: Re-routing packets via netfilter (ip_rt_bug)
@ 2005-04-25 16:51 ` Yair Itzhaki
  0 siblings, 0 replies; 42+ messages in thread
From: Yair Itzhaki @ 2005-04-25 16:51 UTC (permalink / raw)
  To: Patrick McHardy; +Cc: linux-kernel, Netfilter Development Mailinglist

No, this does not help.
The failure is now inside "ip_route_output_slow", since the reversed address packet has the source address of the remote machine, and the call to "ip_dev_find" fails to find a device with matching address.

In 2.4 the okfn pointer used to point to "ip_queue_xmit2" which evaluated the new route from scratch. 
It was passed in as the completion function when calling the NF_HOOK chain.
In 2.6 this function is gone (replaced with a reference to "dst_output).

Was removing it a mistake?


-----Original Message-----
From: Patrick McHardy [mailto:kaber@trash.net]
Sent: Monday, April 25, 2005 11:07
To: Yair Itzhaki
Cc: linux-kernel@vger.kernel.org; Netfilter Development Mailinglist
Subject: Re: Re-routing packets via netfilter (ip_rt_bug)


Yair Itzhaki wrote:
> While traversing packets through Netfilter, changing dest address from a foreign to a local address causes the packet to drop (and show up at ip_rt_bug(), along a syslog entry).

Does this patch fix your problem?


^ permalink raw reply	[flat|nested] 42+ messages in thread
* RE: Re-routing packets via netfilter (ip_rt_bug)
@ 2005-04-26 15:39 Yair Itzhaki
  0 siblings, 0 replies; 42+ messages in thread
From: Yair Itzhaki @ 2005-04-26 15:39 UTC (permalink / raw)
  To: Herbert Xu, Patrick McHardy; +Cc: linux-kernel, netfilter-devel, netdev

I'm afraid I'm not following you.
Where did you want to set saddr=0 ?

Yair


> -----Original Message-----
> From: Herbert Xu [mailto:herbert@gondor.apana.org.au]
> Sent: Tuesday, April 26, 2005 02:39
> To: Patrick McHardy
> Cc: Yair Itzhaki; linux-kernel@vger.kernel.org; 
> netfilter-devel@lists.netfilter.org; netdev@oss.sgi.com
> Subject: Re: Re-routing packets via netfilter (ip_rt_bug)
> 
> 
> On Tue, Apr 26, 2005 at 02:08:18AM +0200, Patrick McHardy wrote:
> > Herbert Xu wrote:
> > >You're right.  But then we can't call ip_route_output in the case
> > >where saddr is foreign but daddr is local.  Nor can we call
> > >ip_route_input since the output will be ip_rt_bug.
> > 
> > In that case we need to use saddr=0, which shouldn't make 
> any difference
> > with sane routing.
> 
> Makes sense.  But what about the case where saddr is foreign but
> daddr is broadcast/multicast?
> 
> Cheers,
> -- 
> Visit Openswan at http://www.openswan.org/
> Email: Herbert Xu ~{PmV>HI~} <herbert@gondor.apana.org.au>
> Home Page: http://gondor.apana.org.au/~herbert/
> PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
> 

^ permalink raw reply	[flat|nested] 42+ messages in thread
* RE: Re-routing packets via netfilter (ip_rt_bug)
@ 2005-05-02 17:17 Yair Itzhaki
  2005-07-14 12:27 ` Ric Wheeler
  2005-07-14 12:27 ` Ric Wheeler
  0 siblings, 2 replies; 42+ messages in thread
From: Yair Itzhaki @ 2005-05-02 17:17 UTC (permalink / raw)
  To: Patrick McHardy, Herbert Xu
  Cc: Jozsef Kadlecsik, netdev, netfilter-devel, linux-kernel

Can anyone propose a patch that I can start checking?

I have come up with the following:

--- net/core/netfilter.c.orig   2005-04-18 21:55:30.000000000 +0300
+++ net/core/netfilter.c        2005-05-02 17:35:20.000000000 +0300
@@ -622,9 +622,10 @@
        /* some non-standard hacks like ipt_REJECT.c:send_reset() can cause
         * packets with foreign saddr to appear on the NF_IP_LOCAL_OUT hook.
         */
-       if (inet_addr_type(iph->saddr) == RTN_LOCAL) {
+       if ((inet_addr_type(iph->saddr) == RTN_LOCAL) ||
+           (inet_addr_type(iph->daddr) == RTN_LOCAL)) {
                fl.nl_u.ip4_u.daddr = iph->daddr;
-               fl.nl_u.ip4_u.saddr = iph->saddr;
+               fl.nl_u.ip4_u.saddr = 0;
                fl.nl_u.ip4_u.tos = RT_TOS(iph->tos);
                fl.oif = (*pskb)->sk ? (*pskb)->sk->sk_bound_dev_if : 0;
 #ifdef CONFIG_IP_ROUTE_FWMARK

Please advise,
Yair


> -----Original Message-----
> From: Patrick McHardy [mailto:kaber@trash.net]
> Sent: Wednesday, April 27, 2005 14:05
> To: Herbert Xu
> Cc: Jozsef Kadlecsik; netdev@oss.sgi.com; 
> netfilter-devel@lists.netfilter.org; Yair Itzhaki; 
> linux-kernel@vger.kernel.org
> Subject: Re: Re-routing packets via netfilter (ip_rt_bug)
> 
> 
> Herbert Xu wrote:
> > Here is another reason why these packets should go through FORWARD.
> > They were generated in response to packets in INPUT/FORWARD/OUTPUT.
> > The original packet has not undergone SNAT in any of these cases.
> > 
> > However, if we feed the response packet through LOCAL_OUT it will
> > be subject to DNAT.  This creates a NAT asymmetry and we may end
> > up with the wrong destination address.
> > 
> > By pushing it through FORWARD it will only undergo SNAT which is
> > correct since the original packet would have undergone DNAT.
> 
> This is only a problem since the recent NAT changes, but I agree
> that we should fix it by moving these packets to FORWARD.
> 
> Regards
> Patrick
> 

^ permalink raw reply	[flat|nested] 42+ messages in thread

end of thread, other threads:[~2020-07-23  7:31 UTC | newest]

Thread overview: 42+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-04-25  9:49 Re-routing packets via netfilter (ip_rt_bug) Yair Itzhaki
2005-04-25  9:07 ` Patrick McHardy
2005-04-25  9:07   ` Patrick McHardy
2005-04-25 10:52   ` Herbert Xu
2005-04-25 10:52     ` Herbert Xu
2005-04-25 15:28     ` Patrick McHardy
2005-04-25 15:28       ` Patrick McHardy
2005-04-25 21:34       ` Herbert Xu
2005-04-25 21:34         ` Herbert Xu
2005-04-26  0:08         ` Patrick McHardy
2005-04-26  0:08           ` Patrick McHardy
2005-04-26  0:39           ` Herbert Xu
2005-04-26  0:39             ` Herbert Xu
2005-04-26 13:17             ` Patrick McHardy
2005-04-26 13:17               ` Patrick McHardy
2005-04-26 23:28               ` Herbert Xu
2005-04-26 23:28                 ` Herbert Xu
2005-04-27  0:56                 ` Patrick McHardy
2005-04-27  0:56                   ` Patrick McHardy
2005-04-27  1:07                   ` Herbert Xu
2005-04-27  1:07                     ` Herbert Xu
2005-04-27 10:26                     ` Patrick McHardy
2005-04-27 10:26                       ` Patrick McHardy
2005-04-27 10:30                       ` Herbert Xu
2005-04-27 10:30                         ` Herbert Xu
2005-04-27 10:41                         ` Jozsef Kadlecsik
2005-04-27 10:41                           ` Jozsef Kadlecsik
2005-04-27 11:35                           ` Herbert Xu
2005-04-27 11:35                             ` Herbert Xu
2005-04-27 11:54                             ` Herbert Xu
2005-04-27 11:54                               ` Herbert Xu
2005-04-27 12:05                               ` Patrick McHardy
2005-04-27 12:05                                 ` Patrick McHardy
2017-07-10  9:20 ` Helbing63
2020-07-23  7:25 ` technical support jollyzula
2020-07-23  7:25 ` Canon.com/ijsetup jollyzula
2005-04-25 16:51 Re-routing packets via netfilter (ip_rt_bug) Yair Itzhaki
2005-04-25 16:51 ` Yair Itzhaki
2005-04-26 15:39 Yair Itzhaki
2005-05-02 17:17 Yair Itzhaki
2005-07-14 12:27 ` Ric Wheeler
2005-07-14 12:27 ` Ric Wheeler

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.