pf-tools/pf-tools: 3 new changesets

parmelan-guest at users.alioth.debian.org parmelan-guest at users.alioth.debian.org
Fri Sep 24 08:58:35 UTC 2010


details:   http://hg.debian.org/hg/pf-tools/pf-tools/rev/8069971a975e
changeset: 822:8069971a975e
user:      "Christophe Caillet <quadchris at free.fr>"
date:      Thu Sep 23 18:08:40 2010 +0200
description:
Fix $iface_type matching with named backref ?<iftype>

details:   http://hg.debian.org/hg/pf-tools/pf-tools/rev/c37ce83bbd51
changeset: 823:c37ce83bbd51
user:      "Christophe Caillet <quadchris at free.fr>"
date:      Thu Sep 23 18:54:23 2010 +0200
description:
Coding style and simpler code

details:   http://hg.debian.org/hg/pf-tools/pf-tools/rev/b441904c18bf
changeset: 824:b441904c18bf
user:      "Christophe Caillet <quadchris at free.fr>"
date:      Thu Sep 23 18:59:47 2010 +0200
description:
Coding style

diffstat:

0 files changed

diffs (320 lines):

diff -r eca88de2d73a -r b441904c18bf lib/PFTools/Conf/Config.pm
--- a/lib/PFTools/Conf/Config.pm	Thu Sep 23 16:37:30 2010 +0200
+++ b/lib/PFTools/Conf/Config.pm	Thu Sep 23 18:59:47 2010 +0200
@@ -23,6 +23,7 @@
 use warnings;
 
 use base qw( Exporter );
+use Carp;
 use English qw( -no_match_vars );    # Avoids regex performance penalty
 
 use PFTools::Logger;
@@ -124,13 +125,12 @@
     my $action_entry = $glob_cnf->{'ACTIONGROUP'}->{$actiongrp};
     if ( $param->{'ref_sect'}->{'depends'} ) {
         foreach my $dep ( split (/\s/, $param->{'ref_sect'}->{'depends'})) {
-            Abort ( $CODE->{'INVALID_VALUE'},
-                "Undefined depends $dep in section $name ",
-                Dumper $param->{'parsed'}
-            ) if( ! __Exists_deps ($dep, $param->{'parsed'}) );
-            Abort ( $CODE->{'INVALID_VALUE'},
-                "$dep and $name($actiongrp) are not on the same actiongroup"
-            ) if( ! __Same_actiongroup( $actiongrp, $dep, $param->{'parsed'}) );
+            croak qq{ERROR: Undefined $dep in section $name}
+                if( ! __Exists_deps ($dep, $param->{'parsed'}) );
+            croak qq{ERROR: $dep and $name not on actiongroup $actiongrp}
+                unless( __Same_actiongroup(
+                    $actiongrp, $dep, $param->{'parsed'})
+                );
                 
         }
     }
diff -r eca88de2d73a -r b441904c18bf lib/PFTools/Conf/Network.pm
--- a/lib/PFTools/Conf/Network.pm	Thu Sep 23 16:37:30 2010 +0200
+++ b/lib/PFTools/Conf/Network.pm	Thu Sep 23 18:59:47 2010 +0200
@@ -25,6 +25,7 @@
 use warnings;
 
 use base qw( Exporter );
+use Carp;
 use English qw( -no_match_vars );    # Avoids regex performance penalty
 
 use PFTools::Logger;
@@ -38,11 +39,6 @@
 );
 
 our @EXPORT_OK = qw();
-
-#########################################################################
-### Rewrite with new syntax
-### Enhancement : creating DNS entries when adding network or hosts
-### Enhancement : creating DHCP entries when adding hosts
 
 #########################################################################
 #
@@ -64,12 +60,7 @@
         my $zone_key = ( $ip_type eq 'ipv6' ) ? 'ZONE6' : 'ZONE';
         my $zone_part = $global_config->{$zone_key}->{'BY_NAME'};
         if ( defined $zone_part->{$zone_name} ) {
-            Warn( $CODE->{'WARNING'},
-                      "Zone "
-                    . $zone_name
-                    . " from file "
-                    . $netfile
-                    . " already exists : skipping the new definition" );
+            carp qq{WARN: $zone_name from $netfile is already defined};
             return;
         }
         $zone_part->{$zone_name} = {
@@ -98,69 +89,53 @@
 sub Add_site ($$$$$) {
     my ( $netfile, $site_name, $site2add, $global_config, $pf_config ) = @_;
 
-    my $site_part = $global_config->{'SITE'};
-    if ( defined $site_part->{'BY_NAME'}->{$site_name} ) {
-        Warn( $CODE->{'WARNING'},
-                  "Site "
-                . $site_name
-                . " from file "
-                . $netfile
-                . " already exists : skipping the new definition" );
+    if ( defined $global_config->{'SITE'}->{'BY_NAME'}->{$site_name} ) {
+        carp qq{WARN: $site_name from $netfile already defined};
         return;
     }
     if ( $site2add->{'state'} eq 'ROOT' ) {
-        if ( $site_part->{'ROOT'} ) {
-            Warn( $CODE->{'WARNING'},
-                      "Site "
-                    . $site_name
-                    . " from file "
-                    . $netfile
-                    . " cannot be defined as ROOT site : skipping the new definition"
-            );
+        if ( $global_config->{'SITE'}->{'ROOT'} ) {
+            carp qq{WARN: ROOT site is already defined : skipping $site_name};
         }
         else {
-            $site_part->{'ROOT'} = $site_name;
+            $global_config->{'SITE'}->{'ROOT'} = $site_name;
         }
     }
     else {
-        push( @{ $site_part->{'EDGE'} }, $site_name );
+        push( @{ $global_config->{'SITE'}->{'EDGE'} }, $site_name );
     }
-    $site_part->{'BY_NAME'}->{$site_name} = $site2add;
-    $site_part->{'BY_NAME'}->{$site_name}->{'NETWORK'} = {
+    my $site_part = $global_config->{'SITE'}->{'BY_NAME'};
+
+    $site_part->{$site_name} = $site2add;
+    $site_part->{$site_name}->{'NETWORK'} = {
         'BY_NAME' => {},
         'BY_TAG'  => {}
     };
-    $site_part->{'BY_NAME'}->{$site_name}->{'HOST'} = {
+    $site_part->{$site_name}->{'HOST'} = {
         'BY_NAME' => {},
         'BY_MAC'  => {}
     };
-    $site_part->{'BY_NAME'}->{$site_name}->{'SERVICE'} = { 'BY_NAME' => {} };
-    push( @{ $site_part->{'__site_list'} }, $site_name );
+    $site_part->{$site_name}->{'SERVICE'} = {
+        'BY_NAME' => {}
+    };
+    push( @{ $global_config->{'SITE'}->{'__site_list'} }, $site_name );
+    my $zone        = $site2add->{'zone'};
+    my $dhcpvlan    = $site2add->{'dhcpvlan'}; 
     foreach my $ip_type ( 'ipv4', 'ipv6' ) {
         next if ( !$pf_config->{'features'}->{$ip_type} );
-        my $zone_key = ( $ip_type eq 'ipv6' ) ? 'ZONE6'    : 'ZONE';
-        my $dhcp_key = ( $ip_type eq 'ipv6' ) ? 'DHCP6'    : 'DHCP';
-        my $addr_key = ( $ip_type eq 'ipv6' ) ? 'BY_ADDR6' : 'BY_ADDR';
-        if ( !defined $global_config->{$zone_key}->{'BY_NAME'}
-            ->{ $site2add->{'zone'} } )
-        {
-            Abort( $CODE->{'INVALID_VALUE'},
-                      "Zone "
-                    . $site2add->{'zone'}
-                    . " for site "
-                    . $site_name
-                    . " defined into "
-                    . $netfile
-                    . " doesn't exist in global configuration" );
+        my $suffix      = ( $ip_type eq 'ipv6' ) ? 6 : "";
+        my $zone_part   = $global_config->{'ZONE'.$suffix};
+        my $dhcp_part   = $global_config->{'DHCP'.$suffix};
+        my $addr_key    = 'BY_ADDR'.$suffix;
+        unless( $zone_part->{'BY_NAME'}->{$zone} ) {
+            croak qq{ERROR: Unknown $zone from $netfile};
         }
-        $site_part->{'BY_NAME'}->{$site_name}->{'NETWORK'}->{$addr_key} = {};
-        $site_part->{'BY_NAME'}->{$site_name}->{'HOST'}->{$addr_key}    = {};
-        $global_config->{$zone_key}->{'BY_NAME'}->{ $site2add->{'zone'} }
-            ->{'BY_SITE'}->{$site_name} = {};
-        $global_config->{$zone_key}->{'BY_SITE'}->{$site_name}
-            = $site2add->{'zone'};
-        $global_config->{$dhcp_key}->{'BY_SITE'}->{$site_name} = {
-            $site2add->{'dhcpvlan'} => {
+        $site_part->{$site_name}->{'NETWORK'}->{$addr_key} = {};
+        $site_part->{$site_name}->{'HOST'}->{$addr_key}    = {};
+        $zone_part->{'BY_NAME'}->{$zone}->{'BY_SITE'}->{$site_name} = {};
+        $zone_part->{'BY_SITE'}->{$site_name} = $zone;
+        $dhcp_part->{'BY_SITE'}->{$site_name} = {
+            $dhcpvlan => {
                 'subnet'  => '',
                 'netmask' => ''
             }
@@ -196,14 +171,7 @@
     if ( $ref_net->{'tag'}
         && ( $ref_net->{'tag'} < 0 || $ref_net->{'tag'} > 4095 ) )
     {
-        Abort( $CODE->{'INVALID_VALUE'},
-                  "Invalid 802.1q tag "
-                . $ref_net->{'tag'}
-                . " for file "
-                . $netfile
-                . " into "
-                . $net_name
-                . " definition" );
+        croak qq{ERROR: Invalid tag $ref_net->{'tag'} from file $netfile};
     }
 
     # Check IP values
@@ -211,84 +179,45 @@
         next if ( !$pf_config->{'features'}->{$ip_type} );
         my $suffix = ( $ip_type eq 'ipv6' ) ? '6' : '';
         my $net_block = Get_netblock_from_vlan( $ip_type, $ref_net );
-        my $zone_key    = ( $ip_type eq 'ipv6' ) ? 'ZONE6'    : 'ZONE';
-        my $dhcp_key    = ( $ip_type eq 'ipv6' ) ? 'DHCP6'    : 'DHCP';
-        my $netaddr_key = ( $ip_type eq 'ipv6' ) ? 'BY_ADDR6' : 'BY_ADDR';
-        my $gw_key      = ( $ip_type eq 'ipv6' ) ? 'gateway6' : 'gateway';
+        my $zone_key    = 'ZONE'.$suffix;
+        my $dhcp_key    = 'DHCP'.$suffix;
+        my $netaddr_key = 'BY_ADDR'.$suffix;
+        my $gw_key      = 'gateway'.$suffix;
         $net2add->{ 'network' . $suffix } = $net_block->addr();
         $net2add->{ 'netmask' . $suffix } = $net_block->mask();
 
-        if ( $ref_net->{ 'gateway' . $suffix } ) {
-            $ip_gw
-                = new NetAddr::IP(
-                $net_block->prefix() . $ref_net->{'gateway'},
-                $net_block->mask() );
-            if ( !defined $ip_gw ) {
-                Abort( $CODE->{'UNDEF_KEY'},
-                          "Unable to check " 
-                        . $ip_type
-                        . " gateway defined from "
-                        . $netfile
-                        . " into "
-                        . $net_name
-                        . " definition" );
+        if ( $ref_net->{$gw_key} ) {
+            $ip_gw = new NetAddr::IP(
+                $net_block->prefix() . $ref_net->{$gw_key},
+                $net_block->mask()
+            );
+            unless( $ip_gw ) {
+                croak qq{ERROR: Invalid $ip_type gateway on $net_name};
             }
-            elsif ( !$net_block->contains($ip_gw) ) {
-                Abort( $CODE->{'INVALID_VALUE'},
-                          "Gateway " 
-                        . $ip_gw
-                        . " is out of range from network "
-                        . $ref_net->{'network'}
-                        . " from file "
-                        . $netfile
-                        . " into "
-                        . $net_name
-                        . " definition" );
+            unless( $net_block->contains($ip_gw) ) {
+                croak qq{ERROR: $ip_gw->addr() is not in $net_block->cidr()};
             }
-            $net2add->{ 'gateway' . $suffix } = $ip_gw->addr();
+            $net2add->{$gw_key} = $ip_gw->addr();
         }
         $net2add->{'tag'} = $ref_net->{'tag'};
         foreach my $site ( @{$site_list} ) {
             $net_part = $site_part->{'BY_NAME'}->{$site}->{'NETWORK'};
             if ( $net_part->{'BY_NAME'}->{$net_name} ) {
-                Warn( $CODE->{'DUPLICATE_VALUE'},
-                          "Network "
-                        . $net_name
-                        . " from file "
-                        . $netfile
-                        . " is already defined for site "
-                        . $site
-                        . " : skipping declaration" );
+                carp qq{WARN: $net_name from $netfile is already defined};
+                next;
             }
-            elsif ($ref_net->{'tag'}
+            if (
+                $ref_net->{'tag'}
                 && $net_part->{'BY_TAG'}->{ $ref_net->{'tag'} } )
             {
-                Abort( $CODE->{'DUPLICATE_VALUE'},
-                          "802.1q tag "
-                        . $ref_net->{'tag'}
-                        . " for network "
-                        . $net_name
-                        . " is already in use on site "
-                        . $site
-                        . " for network "
-                        . $net_part->{'BY_TAG'}->{ $ref_net->{'tag'} } );
+                croak qq{ERROR: Duplicate tag  $ref_net->{'tag'} for $net_name};
             }
-            if (   $net_part->{'BY_ADDR'}->{ $net_block->cidr() }
+            if (
+                $net_part->{'BY_ADDR'}->{ $net_block->cidr() }
                 && $net_part->{'BY_ADDR'}->{ $net_block->cidr() } ne
                 $net_name )
             {
-                Abort( $CODE->{'DUPLICATE_VALUE'},
-                          $ip_type
-                        . " subnet "
-                        . $block
-                        . " for network "
-                        . $net_name
-                        . " from file "
-                        . $netfile
-                        . " is already in use in site "
-                        . $site
-                        . " for network "
-                        . $net_part->{'BY_ADDR'}->{$block} );
+                croak qq{ERROR: subnet for $net_name already in used};
             }
 
             # Adding network to the network part of the global structure
@@ -299,7 +228,7 @@
             $net_part->{'BY_TAG'}->{ $ref_net->{'tag'} }      = $net_name
                 if ( $ref_net->{'tag'} );
 
-       # Adding entries for network, netmask, broadcast etc. into the DNS zone
+            # 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};
diff -r eca88de2d73a -r b441904c18bf lib/PFTools/Conf/Syntax.pm
--- a/lib/PFTools/Conf/Syntax.pm	Thu Sep 23 16:37:30 2010 +0200
+++ b/lib/PFTools/Conf/Syntax.pm	Thu Sep 23 18:59:47 2010 +0200
@@ -340,7 +340,7 @@
                 (?:
                     ::
                     (?:                     # logical interface name
-                        (?:eth|bond) [\d]+  #   real interface name
+                        (?<iftype>eth|bond) [\d]+  #   real interface name
                         (?:                 #   optional 802.1Q tag
                             [.]
                             TAG [\d]+
@@ -353,7 +353,7 @@
         {
             croak qq{ERROR: Invalid section name $section_name};
         }
-
+        $iface_type = $+{iftype};
         # Clean key names by removing .default or .%HOSTNUM% suffix
         foreach my $key ( keys %{$section_hash} ) {
             my $new = $key;



More information about the pf-tools-commits mailing list