pf-tools/pf-tools: 4 new changesets

parmelan-guest at users.alioth.debian.org parmelan-guest at users.alioth.debian.org
Wed Nov 17 13:45:01 UTC 2010


details:   http://hg.debian.org/hg/pf-tools/pf-tools/rev/2f5329151f21
changeset: 1028:2f5329151f21
user:      "Christophe Caillet <quadchris at free.fr>"
date:      Tue Nov 16 19:12:19 2010 +0100
description:
Add function for getting suffix according to ip_type

details:   http://hg.debian.org/hg/pf-tools/pf-tools/rev/ee9d1d049fe3
changeset: 1029:ee9d1d049fe3
user:      "Christophe Caillet <quadchris at free.fr>"
date:      Tue Nov 16 19:19:01 2010 +0100
description:
Making add_network more readable by descoping adds into zone part

details:   http://hg.debian.org/hg/pf-tools/pf-tools/rev/f4342bc55b88
changeset: 1030:f4342bc55b88
user:      "Christophe Caillet <quadchris at free.fr>"
date:      Tue Nov 16 19:26:04 2010 +0100
description:
Using call of get_suffix_from_ip_type everywhere

details:   http://hg.debian.org/hg/pf-tools/pf-tools/rev/fadccbca083c
changeset: 1031:fadccbca083c
user:      "Christophe Caillet <quadchris at free.fr>"
date:      Wed Nov 17 11:07:02 2010 +0100
description:
Using Readonly::Scalar variable for defining 802.1q max value

diffstat:

1 file changed, 1 deletion(-)
lib/PFTools/Net.pm |    1 -

diffs (271 lines):

diff -r bfbe1ebd6136 -r fadccbca083c lib/PFTools/Conf/Host.pm
--- a/lib/PFTools/Conf/Host.pm	Tue Nov 16 16:29:30 2010 +0100
+++ b/lib/PFTools/Conf/Host.pm	Wed Nov 17 11:07:02 2010 +0100
@@ -213,7 +213,7 @@
                 foreach my $ip_type ( 'ipv4', 'ipv6' ) {
                     next unless $pf_config->{'features'}->{$ip_type};
 
-                    my $ip_type_suffix = $ip_type eq 'ipv6' ? '6' : '';
+                    my $ip_type_suffix = get_suffix_from_ip_type( $ip_type );
                     my $addr_key = qq{BY_ADDR$ip_type_suffix};
                     my $zone_key = qq{ZONE$ip_type_suffix};
                     my $dhcp_key = qq{DHCP$ip_type_suffix};
@@ -812,7 +812,7 @@
             }
         );
 
-        my $suffix    = $ip_type eq 'ipv6' ? '6' : q{};
+        my $suffix    = get_suffix_from_ip_type( $ip_type );
         my $route_key = '@route' . $suffix;
         my $gw_key    = 'gateway' . $suffix;
 
@@ -1079,7 +1079,7 @@
         $vlan_def_ref,  $iface_def_ref, $pxefilename
     ) = @{$arguments_ref}{@argument_names};
 
-    my $ip_type_suffix = $ip_type eq 'ipv6' ? 6 : q{};
+    my $ip_type_suffix = get_suffix_from_ip_type( $ip_type );
     unless ( $dhcp_part_ref->{$dhcp_vlan} ) {
         $dhcp_part_ref->{$dhcp_vlan} = {
             'subnet'  => $vlan_def_ref->{"network$ip_type_suffix"},
diff -r bfbe1ebd6136 -r fadccbca083c lib/PFTools/Conf/Network.pm
--- a/lib/PFTools/Conf/Network.pm	Tue Nov 16 16:29:30 2010 +0100
+++ b/lib/PFTools/Conf/Network.pm	Wed Nov 17 11:07:02 2010 +0100
@@ -27,6 +27,7 @@
 use base qw( Exporter );
 use Carp;
 use English qw( -no_match_vars );    # Avoids regex performance penalty
+use Readonly;
 
 use PFTools::Logger;
 use PFTools::Net;
@@ -39,6 +40,11 @@
 );
 
 our @EXPORT_OK = qw();
+
+########################
+# Constants
+
+Readonly::Scalar my $VLAN_MAXVALUE => 4095;
 
 =head2 add_zone($args)
 
@@ -183,7 +189,7 @@
     foreach my $ip_type (qw( ipv4 ipv6 )) {
         next unless $pf_config->{'features'}->{$ip_type};
 
-        my $suffix    = $ip_type eq 'ipv6' ? 6 : q{};
+        my $suffix    = get_suffix_from_ip_type( $ip_type );
         my $zone_part = $global_config->{"ZONE$suffix"};
         my $dhcp_part = $global_config->{"DHCP$suffix"};
         my $addr_key  = "BY_ADDR$suffix";
@@ -194,6 +200,7 @@
         $site_part->{$section_name}->{'NETWORK'}->{$addr_key}          = {};
         $site_part->{$section_name}->{'HOST'}->{$addr_key}             = {};
         $zone_part->{'BY_NAME'}->{$zone}->{'BY_SITE'}->{$section_name} = {};
+#        $zone_part->{'ALL_SITES'}                                      = {};
         $zone_part->{'BY_SITE'}->{$section_name} = $zone;
         $dhcp_part->{'BY_SITE'}->{$section_name} = {
             $dhcpvlan => {
@@ -258,7 +265,7 @@
 
     # Check TAG
     my $tag = $section_ref->{'tag'};
-    if ( $tag and ( $tag < 0 or $tag > 4095 ) ) {
+    if ( $tag and ( $tag < 0 or $tag > $VLAN_MAXVALUE ) ) {
         croak
             qq{ERROR: Invalid tag $section_ref->{'tag'} from file $start_file};
     }
@@ -267,10 +274,7 @@
     foreach my $ip_type (qw( ipv4 ipv6 )) {
         next unless $pf_config->{'features'}->{$ip_type};
 
-        my $suffix
-            = $ip_type eq 'ipv6'
-            ? '6'
-            : q{};    # FIXME __get_suffix_from_ip_type ?
+        my $suffix      = get_suffix_from_ip_type( $ip_type );
         my $subnet_ref  = get_subnet_from_vlan( $ip_type, $section_ref );
         my $zone_key    = qq{ZONE$suffix};
         my $dhcp_key    = qq{DHCP$suffix};
@@ -327,28 +331,17 @@
                 $net_part->{'BY_TAG'}->{$tag} = $section_name;
             }
 
-       # Adding entries for network, netmask, broadcast etc. into the DNS zone
-            my $zone
-                = $global_config->{'SITE'}->{'BY_NAME'}->{$site}->{'zone'};
-            my $zone_part = $global_config->{$zone_key}->{'BY_NAME'}->{$zone};
-
-            my $zone_ref = {};
-
-            # Adding IPv4 entries
-            # FIXME what about IPv6? (see $suffix above?)
-            $zone_ref->{'network'} = qq{A\t} . $subnet_ref->addr();
-            $zone_ref->{'netmask'} = qq{A\t} . $subnet_ref->mask();
-
-            my $broadcast = $subnet_ref->broadcast();
-            $broadcast =~ s{ [/].* \z }{}xms;    # remove /prefix
-            $zone_ref->{'broadcast'} = qq{A\t} . $broadcast;
-
-            if ( $net2add->{$gw_key} ) {
-                $zone_ref->{'gateway'} = qq{A\t} . $net2add->{$gw_key};
-            }
-
-            push @{ $zone_part->{'__network_order'}->{$site} }, $section_name;
-            $zone_part->{'BY_SITE'}->{$site}->{$section_name} = $zone_ref;
+            # Adding entries for network, netmask, broadcast etc. into the
+            # DNS zone
+            my $add_args = {
+                'ref_net'       => $net2add,
+                'subnet_ref'    => $subnet_ref,
+                'site'          => $site,
+                'ip_type'       => $ip_type,
+                'net_name'      => $section_name,
+                'global_config' => $global_config,
+            };
+            __add_network_in_zone_part( $add_args );
 
             my $dhcp_part = $global_config->{$dhcp_key}->{'BY_SITE'}->{$site}
                 ->{$section_name};
@@ -365,6 +358,68 @@
     return;
 }
 
+=head2 __add_network_in_zone_part($args)
+
+This function adds a network into the zone part of global configuration.
+$args is a reference to a hash containing the following named parameters:
+
+=over
+
+=item I<ref_net>
+
+Reference to a hash containing the network to add
+
+=item I<subnet_ref>
+
+NetAddr::IP object for the specified network
+
+=item I<site>
+
+String containing the site name of the specified network
+
+=item I<net_name>
+
+String containing the network name of the specified network
+
+=item I<global_config>
+
+Reference to the global configuration hash (the network will be added in this hash)
+
+=back
+
+=cut
+
+sub __add_network_in_zone_part {
+    my ($args) = @_;
+
+    my ($ref_net, $subnet_ref, $site, $ip_type, $net_name, $global_config)
+        = @$args{
+        qw( ref_net subnet_ref site ip_type net_name global_config )
+        };
+
+    # Adding entries for network, netmask, broadcast etc. into the DNS zone
+    my $zone      = $global_config->{'SITE'}->{'BY_NAME'}->{$site}->{'zone'};
+    my $suffix    = get_suffix_from_ip_type( $ip_type );
+    my $zone_key  = qq{ZONE$suffix};
+    my $zone_part = $global_config->{$zone_key}->{'BY_NAME'}->{$zone};
+    my $zone_ref  = {};
+
+    $zone_ref->{'network'} = qq{A\t} . $ref_net->{"network$suffix"};
+    $zone_ref->{'netmask'} = qq{A\t} . $ref_net->{"netmask$suffix"};
+
+    my $broadcast = $subnet_ref->broadcast();
+    $broadcast    =~ s{ [/].* \z }{}xms;    # remove /prefix
+    $zone_ref->{'broadcast'} = qq{A\t} . $broadcast;
+
+    if ( $ref_net->{"gateway$suffix"} ) {
+        $zone_ref->{'gateway'} = qq{A\t} . $ref_net->{"gateway$suffix"};
+    }
+
+    push @{ $zone_part->{'__network_order'}->{$site} }, $net_name;
+    $zone_part->{'BY_SITE'}->{$site}->{$net_name} = $zone_ref;
+
+    return 1;
+}
 
 1;    # Magic true value required at end of module
 
diff -r bfbe1ebd6136 -r fadccbca083c lib/PFTools/Net.pm
--- a/lib/PFTools/Net.pm	Tue Nov 16 16:29:30 2010 +0100
+++ b/lib/PFTools/Net.pm	Wed Nov 17 11:07:02 2010 +0100
@@ -30,9 +30,7 @@
 use Net::DNS;
 use NetAddr::IP;
 
-use PFTools::Logger;
-
-#use PFTools::Structqueries;
+use PFTools::Structqueries;
 
 our @EXPORT = qw(
     get_subnet_from_vlan
@@ -58,7 +56,7 @@
         croak q{ERROR: non-ref $net-hash paramter};
     }
 
-    my $suffix = $type eq 'ipv6' ? '6' : q{};
+    my $suffix = get_suffix_from_ip_type( $type );
     my $net_def = $net_hash->{"network$suffix"};
 
     my $subnet_ref;
diff -r bfbe1ebd6136 -r fadccbca083c lib/PFTools/Structqueries.pm
--- a/lib/PFTools/Structqueries.pm	Tue Nov 16 16:29:30 2010 +0100
+++ b/lib/PFTools/Structqueries.pm	Wed Nov 17 11:07:02 2010 +0100
@@ -32,6 +32,7 @@
 #use PFTools::Logger;
 
 our @EXPORT = qw(
+    get_suffix_from_ip_type
     get_zone_from_hostname
     get_zone_from_site
     get_hosttype_from_hostname
@@ -49,6 +50,24 @@
 );
 
 our @EXPORT_OK = qw ();
+
+=head2 get_suffix_from_ip_type ( $ip_type )
+
+This function returns the suffix according to an IP type on the global
+structure.
+
+=cut
+
+sub get_suffix_from_ip_type {
+    my ( $ip_type ) = @_;
+
+    my $suffix
+        = $ip_type eq 'ipv6'
+        ? '6'
+        : q{};
+
+    return $suffix;
+}
 
 =head2 get_uniq_site_from_hostname( $hostname, $global_config )
 
diff -r bfbe1ebd6136 -r fadccbca083c lib/PFTools/Utils.pm
--- a/lib/PFTools/Utils.pm	Tue Nov 16 16:29:30 2010 +0100
+++ b/lib/PFTools/Utils.pm	Wed Nov 17 11:07:02 2010 +0100
@@ -695,7 +695,7 @@
                 qq{\tbroadcast\t} . $ip->broadcast()->addr();
 
             # Routes
-            my $suffix = $ip_type eq 'ipv6' ? '6' : q{};
+            my $suffix = get_suffix_from_ip_type( $ip_type );
             foreach my $route ( @{ $if_part->{ '@route' . $suffix } } ) {
                 if ( $route =~ m{ \A (\S+) \s* (?: via (?: \S+ ) )? \z }xms )
                 {



More information about the pf-tools-commits mailing list