vcl-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arku...@apache.org
Subject svn commit: r1645750 - in /vcl/trunk/managementnode/lib/VCL: Module/OS/Linux/firewall/iptables.pm utils.pm
Date Mon, 15 Dec 2014 21:12:52 GMT
Author: arkurth
Date: Mon Dec 15 21:12:52 2014
New Revision: 1645750

URL: http://svn.apache.org/r1645750
Log:
VCL-174
Added utils.pm::get_natport_ranges to reduce duplicated code. Added possibility of allowing
newline's in the natport_ranges variable.

Modified:
    vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/firewall/iptables.pm
    vcl/trunk/managementnode/lib/VCL/utils.pm

Modified: vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/firewall/iptables.pm
URL: http://svn.apache.org/viewvc/vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/firewall/iptables.pm?rev=1645750&r1=1645749&r2=1645750&view=diff
==============================================================================
--- vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/firewall/iptables.pm (original)
+++ vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/firewall/iptables.pm Mon Dec 15 21:12:52
2014
@@ -675,10 +675,10 @@ sub configure_nat {
 		"internal - interface: $internal_interface_name, IP address: $internal_ip_address/$internal_subnet_mask,
network: $internal_network_address/$internal_network_bits"
 	);
 	
-	my $natport_ranges_variable = get_variable('natport_ranges') || '49152-65535';
+	my @natport_ranges = get_natport_ranges();
 	my $destination_ports = '';
-	for my $natport_range (split(/[,;]+/, $natport_ranges_variable)) {
-		my ($start_port, $end_port) = $natport_range =~ /(\d+)-(\d+)/g;
+	for my $natport_range (@natport_ranges) {
+		my ($start_port, $end_port) = @$natport_range;
 		if (!defined($start_port)) {
 			notify($ERRORS{'WARNING'}, 0, "unable to parse NAT port range: '$natport_range'");
 			next;

Modified: vcl/trunk/managementnode/lib/VCL/utils.pm
URL: http://svn.apache.org/viewvc/vcl/trunk/managementnode/lib/VCL/utils.pm?rev=1645750&r1=1645749&r2=1645750&view=diff
==============================================================================
--- vcl/trunk/managementnode/lib/VCL/utils.pm (original)
+++ vcl/trunk/managementnode/lib/VCL/utils.pm Mon Dec 15 21:12:52 2014
@@ -162,6 +162,7 @@ our @EXPORT = qw(
 	get_management_node_vmhost_info
 	get_module_info
 	get_nathost_assigned_public_ports
+	get_natport_ranges
 	get_next_image_default
 	get_os_info
 	get_production_imagerevision_info
@@ -7254,6 +7255,47 @@ sub get_nathost_assigned_public_ports {
 
 #/////////////////////////////////////////////////////////////////////////////
 
+=head2 get_natport_ranges
+
+ Parameters  : none
+ Returns     : array
+ Description : Parses the 'natport_ranges' variable. Constucts an array of
+               arrays. The child arrays are in the form:
+               ($start_port, $end_port)
+
+=cut
+
+sub get_natport_ranges {
+	return @{$ENV{natport_ranges}} if defined($ENV{natport_ranges});
+	
+	# Retrieve and parse the natport_ranges variable
+	my $natport_ranges_variable = get_variable('natport_ranges') || '49152-65535';
+	my @natport_range_strings = split(/[,;\n]+/, $natport_ranges_variable);
+	my @natport_ranges;
+	for my $natport_range_string (@natport_range_strings) {
+		my ($start_port, $end_port) = $natport_range_string =~ /(\d+)-(\d+)/g;
+		if (!defined($start_port)) {
+			notify($ERRORS{'WARNING'}, 0, "unable to parse NAT port range: '$natport_range_string'");
+			next;
+		}
+		
+		# Make sure port range isn't backwards
+		if ($end_port < $start_port) {
+			my $start_port_temp = $start_port;
+			$start_port = $end_port;
+			$end_port = $start_port_temp;
+		}
+		
+		push @natport_ranges, [$start_port, $end_port];
+	}
+	
+	notify($ERRORS{'DEBUG'}, 0, "parsed natport_ranges variable:\n" . format_data(\@natport_ranges));
+	$ENV{natport_ranges} = \@natport_ranges;
+	return @natport_ranges;
+}
+
+#/////////////////////////////////////////////////////////////////////////////
+
 =head2 populate_reservation_natport
 
  Parameters  : $reservation_id
@@ -7300,23 +7342,15 @@ sub populate_reservation_natport {
 	
 	my %available_port_hash;
 	
-	# Retrieve and parse the natport_ranges variable
-	my $natport_ranges_variable = get_variable('natport_ranges') || '49152-65535';
-	my @natport_ranges = split(/[,;]+/, $natport_ranges_variable);
+	# Retrieve the natport range pairs
+	my @natport_ranges = get_natport_ranges();
 	for my $natport_range (@natport_ranges) {
-		my ($start_port, $end_port) = $natport_range =~ /(\d+)-(\d+)/g;
+		my ($start_port, $end_port) = @$natport_range;
 		if (!defined($start_port)) {
-			notify($ERRORS{'WARNING'}, 0, "unable to parse NAT port range: '$natport_range'");
+			notify($ERRORS{'WARNING'}, 0, "unable to parse NAT port range:\n" . format_data($natport_range));
 			next;
 		}
 		
-		# Make sure port range isn't backwards
-		if ($end_port < $start_port) {
-			my $start_port_temp = $start_port;
-			$start_port = $end_port;
-			$end_port = $start_port_temp;
-		}
-		
 		# Loop through all of the ports in the range, check if already assigned
 		for (my $port = $start_port; $port<=$end_port; $port++) {
 			if (!defined($assigned_port_hash{$port})) {



Mime
View raw message