pf-tools commit: r779 [ccaillet-guest] - /branches/next-gen/lib/PFTools/Net.pm
parmelan-guest at users.alioth.debian.org
parmelan-guest at users.alioth.debian.org
Thu Jul 22 10:46:41 UTC 2010
Author: ccaillet-guest
Date: Thu Jul 22 10:46:40 2010
New Revision: 779
URL: http://svn.debian.org/wsvn/pf-tools/?sc=1&rev=779
Log:
Adding source docs and optimizing Add_network
Modified:
branches/next-gen/lib/PFTools/Net.pm
Modified: branches/next-gen/lib/PFTools/Net.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Net.pm?rev=779&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Net.pm (original)
+++ branches/next-gen/lib/PFTools/Net.pm Thu Jul 22 10:46:40 2010
@@ -804,7 +804,7 @@
#
# STR __Get_site_prefix ( STR , HASHREF )
#
-# This function adds zone into global configuration
+# This function returns the site's prefix value
# Inputs :
# - $site : site name
# - $ref_site : hashref where are stored site definitions according to networkfile-syntax
@@ -830,12 +830,36 @@
}
}
+#########################################################################
+#
+# STR __Get_site_zone ( STR , HASHREF )
+#
+# This function returns the zone name which is defined for the specified site
+# Inputs :
+# - $site : site name
+# - $ref_site : hashref where are stored site definitions according to networkfile-syntax
+#
+# Output :
+# Return a string containing the zone defined for this site.
+#
sub __Get_site_zone ($$) {
my ( $site, $ref_site ) = @_;
return $ref_site->{'zone'};
}
+#########################################################################
+#
+# ARRAYREF __Get_site_list ( HASHREF , HASHREF )
+#
+# This function adds build the site list for a given section
+# Inputs :
+# - $sect_hash : hashref containing the section where site key is defined
+# - $global_config : hashref where is stored global configuration
+#
+# Output :
+# Return an array reference containing the built site list.
+#
sub Get_site_list ($$) {
my ( $sect_hash, $global_config ) = @_;
my $ref_list;
@@ -849,6 +873,19 @@
}
}
+#########################################################################
+#
+# NetAddr::IP __Get_netblock_from_vlan ( STR , HASHREF )
+#
+# This function build a NetAddr::IP object, in the same time permits the control
+# of IP values defined for a given network definition
+# Inputs :
+# - $sect_hash : hashref containing the section where site key is defined
+# - $global_config : hashref where is stored global configuration
+#
+# Output :
+# Return a NetAddr::IP object containing the netblock for a specifed network definition
+#
sub __Get_netblock_from_vlan ($$) {
my ( $type, $net_hash ) = @_;
@@ -874,6 +911,18 @@
return $block;
}
+#########################################################################
+#
+# VOID Add_network ( STR , STR, HASHREF , HASHREF, HASHREF )
+#
+# This function adds zone into global configuration
+# Inputs :
+# - $netfile : filename where network is parsed
+# - $net_name : network name
+# - $ref_net : hashref where are stored network definitions according to networkfile-syntax
+# - $global_config : hashref where are stored global configuration datas
+# - $pf_config : hashref where are stored pf-tools configuration datas
+#
sub Add_network ($$$$$) {
my ( $netfile, $net_name, $ref_net, $global_config, $pf_config ) = @_;
my ( $block, $block6, $site_list, $net_part, $dhcp_part, $net2add, $ip_gw, $ip6_gw );
@@ -892,11 +941,10 @@
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 );
-# if ( ! defined $net_block ) {
-# Abort ( $CODE->{'INVALID_VALUE'},
-# "Invalid ".$ip_type." definition for network ".$ref_net->{'network'}
-# ." and/or ".$ref_net->{'netmask'}." from file ".$netfile." into ".$net_name." definition" );
-# }
+ 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';
$net2add->{'network'.$suffix} = $net_block->addr();
$net2add->{'netmask'.$suffix} = $net_block->mask();
if ( $ref_net->{'gateway'.$suffix} ) {
@@ -913,45 +961,22 @@
$net2add->{'gateway'.$suffix} = $ip_gw->addr();
}
$net2add->{'tag'} = $ref_net->{'tag'};
- }
-
- # Already defined in sites for which it will be : by name ? by 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" );
- }
- elsif ( $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'}} );
- }
- foreach my $ip_type ( 'ipv4', 'ipv6' ) {
- next if ( ! $pf_config->{'features'}->{$ip_type} ) ;
- my $net_block = __Get_netblock_from_vlan ( $ip_type, $ref_net );
-# if ( ! defined $net_block ) {
-# Abort ( $CODE->{'INVALID_VALUE'},
-# "Invalid ".$ip_type." definition for network ".$ref_net->{'network'}
-# ." and/or ".$ref_net->{'netmask'}." from file ".$netfile." into ".$net_name." definition" );
-# }
- my $block = $net_block->cidr();
- if ( $net_part->{'BY_ADDR'}->{$block} && $net_part->{'BY_ADDR'}->{$block} ne $net_name ) {
+ 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" );
+ }
+ elsif ( $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'}} );
+ }
+ 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} );
}
- }
- }
-
- 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 $netaddr_key = ( $ip_type eq 'ipv6') ? 'BY_ADDR6' : 'BY_ADDR';
- my $net_block = __Get_netblock_from_vlan ( $ip_type, $ref_net );
- my $gw_key = ( $ip_type eq 'ipv6') ? 'gateway6' : 'gateway';
- foreach my $site ( @{$site_list} ) {
# Adding network to the network part of the global structure
$net_part = $site_part->{'BY_NAME'}->{$site}->{'NETWORK'};
$dhcp_part = $global_config->{$dhcp_key}->{'BY_SITE'}->{$site};
More information about the pf-tools-commits
mailing list