netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Patrick McHardy <kaber@trash.net>
To: Bas van Sisseren <bas@quarantainenet.nl>
Cc: netfilter-devel@vger.kernel.org
Subject: Re: [PATCH] ipt_REDIRECT: only change dest-ip if not local ip
Date: Fri, 16 Jul 2010 14:21:00 +0200	[thread overview]
Message-ID: <4C404EAC.7050509@trash.net> (raw)
In-Reply-To: <4C402DBD.3010007@quarantainenet.nl>

Am 16.07.2010 12:00, schrieb Bas van Sisseren:
> 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.

So I guess you use statically configured address that are known
in advance. So why don't you simply set up your ruleset to only
redirect packets sent to the first address? That avoids iterating
through the entire address list for each new connection, which
can be quite large.

> 
> ============
> --- 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
> 


  reply	other threads:[~2010-07-16 12:21 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

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=4C404EAC.7050509@trash.net \
    --to=kaber@trash.net \
    --cc=bas@quarantainenet.nl \
    --cc=netfilter-devel@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 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).