From 3f4d773489493c6bd7e63f9704a8f4a35a3a94a4 Mon Sep 17 00:00:00 2001 From: teastep Date: Thu, 17 Jan 2008 19:02:40 +0000 Subject: [PATCH] Allow DNS names in DEST column of a DNAT rule git-svn-id: https://shorewall.svn.sourceforge.net/svnroot/shorewall/trunk@8076 fbd18981-670d-0410-9b5c-8dc0c1a9a2bb --- Shorewall-perl/Shorewall/IPAddrs.pm | 14 +++++++++++++- Shorewall-perl/Shorewall/Rules.pm | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Shorewall-perl/Shorewall/IPAddrs.pm b/Shorewall-perl/Shorewall/IPAddrs.pm index c2b70f9ed..fcfbed934 100644 --- a/Shorewall-perl/Shorewall/IPAddrs.pm +++ b/Shorewall-perl/Shorewall/IPAddrs.pm @@ -69,10 +69,22 @@ sub valid_address( $ ) { sub validate_address( $$ ) { my ( $addr, $allow_name ) = @_; + my @addrs = ( $addr ); + unless ( valid_address $addr ) { fatal_error "Invalid IP Address ($addr)" unless $allow_name; - fatal_error "Unknown Host ($addr)" unless defined gethostbyname $addr; + fatal_error "Unknown Host ($addr)" unless (@addrs = gethostbyname $addr); + + if ( defined wantarray ) { + shift @addrs for (1..4); + for ( @addrs ) { + my (@a) = unpack('C4',$_); + $_ = join('.', @a ); + } + } } + + defined wantarray ? wantarray ? @addrs : $addrs[0] : undef; } sub validate_net( $$ ) { diff --git a/Shorewall-perl/Shorewall/Rules.pm b/Shorewall-perl/Shorewall/Rules.pm index f9fe0101b..82801e148 100644 --- a/Shorewall-perl/Shorewall/Rules.pm +++ b/Shorewall-perl/Shorewall/Rules.pm @@ -1157,7 +1157,7 @@ sub process_rule1 ( $$$$$$$$$$$ ) { if ( $server =~ /^(.+)-(.+)$/ ) { validate_range( $1, $2 ); } else { - validate_address $server, 0; + $server = validate_address $server, 1; } if ( $action eq 'SAME' ) {