netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ipt_REDIRECT: only change dest-ip if not local ip
@ 2010-07-16 10:00 Bas van Sisseren
  2010-07-16 12:21 ` Patrick McHardy
  2010-07-16 12:42 ` Pascal Hambourg
  0 siblings, 2 replies; 14+ messages in thread
From: Bas van Sisseren @ 2010-07-16 10:00 UTC (permalink / raw)
  To: netfilter-devel

Hello,

When redirecting, the destination address is replaced by the first
ip-address on the receiving interface.

If the packet originally was sent to the second ip-address (or third,
fourth, etc..), this patch doesn't change the destination ip.

============
--- linux.orig/net/ipv4/netfilter/ipt_REDIRECT.c
+++ linux/net/ipv4/netfilter/ipt_REDIRECT.c
@@ -78,7 +78,21 @@
        rcu_read_lock();
        indev = __in_dev_get_rcu((*pskb)->dev);
        if (indev && (ifa = indev->ifa_list))
+       {
+           struct in_ifaddr *ifa_cur; // interface ip-list cursor
+
+           // set current destination ip
+           newdst = ((struct iphdr*)skb_network_header(*pskb))->daddr;
+
+           // iterate through interface ip list
+           for (ifa_cur = ifa; ifa_cur; ifa_cur = ifa_cur->ifa_next)
+               if (newdst == ifa_cur->ifa_local)
+                   goto newdst_is_local;
+
+           // set new destination to first ip of this interface
            newdst = ifa->ifa_local;
+       }
+   newdst_is_local:
        rcu_read_unlock();

        if (!newdst)
============

Kind regards,

Bas van Sisseren

-- 
Bas van Sisseren <bas@quarantainenet.nl>
Quarantainenet



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

end of thread, other threads:[~2010-07-19  8:03 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-16 10:00 [PATCH] ipt_REDIRECT: only change dest-ip if not local ip Bas van Sisseren
2010-07-16 12:21 ` Patrick McHardy
2010-07-16 12:42   ` Bas van Sisseren
2010-07-16 12:49     ` Patrick McHardy
2010-07-16 14:56       ` Jan Engelhardt
2010-07-16 14:58         ` Patrick McHardy
2010-07-16 15:14         ` Bas van Sisseren
2010-07-16 19:18           ` Jan Engelhardt
2010-07-19  8:02             ` Bas van Sisseren
2010-07-16 13:03     ` Pascal Hambourg
2010-07-16 12:42 ` Pascal Hambourg
2010-07-16 13:23   ` Bas van Sisseren
2010-07-16 15:04     ` Pascal Hambourg
2010-07-16 15:21       ` Bas van Sisseren

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).