From e188bde6c48f88451dec15c9f0b12eb7a4bfe7b6 Mon Sep 17 00:00:00 2001 From: Tom Eastep Date: Tue, 1 Nov 2016 18:42:16 -0700 Subject: [PATCH] Fix additional masq/snat issues. Signed-off-by: Tom Eastep --- Shorewall/Perl/Shorewall/Nat.pm | 16 +++++++++++++--- Shorewall/Perl/Shorewall/Rules.pm | 10 ++++++++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/Shorewall/Perl/Shorewall/Nat.pm b/Shorewall/Perl/Shorewall/Nat.pm index 60cb56534..4801ff7f0 100644 --- a/Shorewall/Perl/Shorewall/Nat.pm +++ b/Shorewall/Perl/Shorewall/Nat.pm @@ -286,8 +286,14 @@ sub process_one_masq1( $$$$$$$$$$$$ ) } else { validate_address $ipaddr, 0; } - validate_portpair1( $proto, $rest ) if supplied $rest; - $addrlist .= "--to-source $ipaddr "; + + if ( supplied $rest ) { + validate_portpair1( $proto, $rest ); + $addrlist .= "--to-source $addr "; + } else { + $addrlist .= "--to-source $ipaddr"; + } + $exceptionrule = do_proto( $proto, '', '' ) if $addr =~ /:/; } else { my $ports = $addr; @@ -399,7 +405,11 @@ sub process_one_masq1( $$$$$$$$$$$$ ) if ( $snat ) { $target =~ s/ .*//; $target .= '+' if $pre_nat; - $target .= '(' . $addresses . ')' if $addresses ne '-' && $addresses ne 'NONAT'; + + if ( $addresses ne '-' && $addresses ne 'NONAT' ) { + $addresses =~ s/^://; + $target .= '(' . $addresses . ')'; + } my $line = "$target\t$networks\t$savelist\t$proto\t$ports\t$ipsec\t$mark\t$user\t$condition\t$origdest\t$probability"; # diff --git a/Shorewall/Perl/Shorewall/Rules.pm b/Shorewall/Perl/Shorewall/Rules.pm index 81ab37abb..497177985 100644 --- a/Shorewall/Perl/Shorewall/Rules.pm +++ b/Shorewall/Perl/Shorewall/Rules.pm @@ -5559,8 +5559,14 @@ sub process_snat1( $$$$$$$$$$$$ ) { } else { validate_address $ipaddr, 0; } - validate_portpair1( $proto, $rest ) if supplied $rest; - $addrlist .= " --to-source $ipaddr"; + + if ( supplied $rest ) { + validate_portpair1( $proto, $rest ); + $addrlist .= " --to-source $addr"; + } else { + $addrlist .= " --to-source $ipaddr"; + } + $exceptionrule = do_proto( $proto, '', '' ) if $addr =~ /:/; } else { my $ports = $addr;