public inbox for development@lists.ipfire.org
 help / color / mirror / Atom feed
From: Michael Tremer <michael.tremer@ipfire.org>
To: development@lists.ipfire.org
Subject: Re: [PATCH] rules.pl: Fix SNAT over VPN.
Date: Sun, 23 Feb 2020 14:28:23 +0000	[thread overview]
Message-ID: <4FDF00FD-A040-426E-959A-F501055346DF@ipfire.org> (raw)
In-Reply-To: <20200220162423.3571-1-stefan.schantl@ipfire.org>

[-- Attachment #1: Type: text/plain, Size: 2345 bytes --]

Hello,

I just tested this patch on our main firewall in Hanover and the problem is resolved.

It is not the most beautiful piece of code, but it does the job.

-Michael

Tested-by: Michael Tremer <michael.tremer(a)ipfire.org>

> On 20 Feb 2020, at 16:24, Stefan Schantl <stefan.schantl(a)ipfire.org> wrote:
> 
> This commit adds flags which will are applied if SNAT should be used on
> the red address or any configured alias.
> 
> They prevent doing the SNAT when tranismitting packet through a VPN over the red interface.
> 
> Fixes #12162.
> 
> Signed-off-by: Stefan Schantl <stefan.schantl(a)ipfire.org>
> ---
> config/firewall/rules.pl | 19 +++++++++++++++++--
> 1 file changed, 17 insertions(+), 2 deletions(-)
> 
> diff --git a/config/firewall/rules.pl b/config/firewall/rules.pl
> index 86db47367..6129af861 100644
> --- a/config/firewall/rules.pl
> +++ b/config/firewall/rules.pl
> @@ -479,16 +479,31 @@ sub buildrules {
> 
> 						# Source NAT
> 						} elsif ($NAT_MODE eq "SNAT") {
> +							my @snat_options = ( "-m", "policy", "--dir", "out", "--pol", "none" );
> 							my @nat_options = @options;
> 
> +							# Get addresses for the configured firewall interfaces.
> +							my @local_addresses = &fwlib::get_internal_firewall_ip_addresses(1);
> +
> +							# Check if the nat_address is one of the local addresses.
> +							foreach my $local_address (@local_addresses) {
> +								if ($nat_address eq $local_address) {
> +									# Clear SNAT options.
> +									@snat_options = ();
> +
> +									# Finish loop.
> +									last;
> +								}
> +							}
> +
> 							push(@nat_options, @destination_intf_options);
> 							push(@nat_options, @source_options);
> 							push(@nat_options, @destination_options);
> 
> 							if ($LOG) {
> -								run("$IPTABLES -t nat -A $CHAIN_NAT_SOURCE @nat_options @log_limit_options -j LOG --log-prefix 'SNAT '");
> +								run("$IPTABLES -t nat -A $CHAIN_NAT_SOURCE @nat_options @snat_options @log_limit_options -j LOG --log-prefix 'SNAT '");
> 							}
> -							run("$IPTABLES -t nat -A $CHAIN_NAT_SOURCE @nat_options -j SNAT --to-source $nat_address");
> +							run("$IPTABLES -t nat -A $CHAIN_NAT_SOURCE @nat_options @snat_options -j SNAT --to-source $nat_address");
> 						}
> 					}
> 
> -- 
> 2.25.0
> 


      reply	other threads:[~2020-02-23 14:28 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-20 16:24 Stefan Schantl
2020-02-23 14:28 ` Michael Tremer [this message]

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=4FDF00FD-A040-426E-959A-F501055346DF@ipfire.org \
    --to=michael.tremer@ipfire.org \
    --cc=development@lists.ipfire.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