pf-tools commit: r854 [ccaillet-guest] - in /branches/next-gen: debian/changelog lib/PFTools/Conf.pm lib/PFTools/Conf/Host.pm lib/PFTools/Conf/Net.pm lib/PFTools/Host.pm lib/PFTools/Net.pm lib/PFTools/Structqueries.pm
parmelan-guest at users.alioth.debian.org
parmelan-guest at users.alioth.debian.org
Fri Aug 27 14:04:56 UTC 2010
Author: ccaillet-guest
Date: Fri Aug 27 14:04:49 2010
New Revision: 854
URL: http://svn.debian.org/wsvn/pf-tools/?sc=1&rev=854
Log:
* lib/PFTools/Conf/Host.pm
- moving PFTools::Host to PFTools::Conf::Host because functions are
dedicated to configuration structure building
* lib/PFTools/Conf/Net.pm
- extracting structure functions from PFTools::Net to PFTools::Conf::Net
which is dedicated to configuration structure building
*
Added:
branches/next-gen/lib/PFTools/Conf/Host.pm
- copied, changed from r851, branches/next-gen/lib/PFTools/Host.pm
branches/next-gen/lib/PFTools/Conf/Net.pm (with props)
Removed:
branches/next-gen/lib/PFTools/Host.pm
Modified:
branches/next-gen/debian/changelog
branches/next-gen/lib/PFTools/Conf.pm
branches/next-gen/lib/PFTools/Net.pm
branches/next-gen/lib/PFTools/Structqueries.pm
Modified: branches/next-gen/debian/changelog
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/debian/changelog?rev=854&op=diff
==============================================================================
--- branches/next-gen/debian/changelog (original)
+++ branches/next-gen/debian/changelog Fri Aug 27 14:04:49 2010
@@ -21,6 +21,12 @@
* lib/PFTools/Conf/Syntax.pm
- extracting syntax checks from PFTools::Conf to PFTools::Conf::Syntax
which is more flexible for future evolutions
+ * lib/PFTools/Conf/Host.pm
+ - moving PFTools::Host to PFTools::Conf::Host because functions are
+ dedicated to configuration structure building
+ * lib/PFTools/Conf/Net.pm
+ - extracting structure functions from PFTools::Net to PFTools::Conf::Net
+ which is dedicated to configuration structure building
* lib/PFTools/Utils.pm
- fix on Ini_TOOLS : if storable file doesn't exist we need to parse
- cosmetic for building zone in __Mk_zoneheader and Mk_zone_for_site
@@ -62,8 +68,9 @@
- basic documentation about update file
* TODO
- adding more TODOs :)
-
- -- Christophe Caillet <quadchris at free.fr> Fri, 27 Aug 2010 15:28:30 +0200
+ *
+
+ -- Christophe Caillet <tof at sitadelle.com> Fri, 27 Aug 2010 16:02:24 +0200
pf-tools (0.99.98-1) unstable; urgency=low
Modified: branches/next-gen/lib/PFTools/Conf.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Conf.pm?rev=854&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Conf.pm (original)
+++ branches/next-gen/lib/PFTools/Conf.pm Fri Aug 27 14:04:49 2010
@@ -27,11 +27,12 @@
use Exporter;
use PFTools::Net;
-use PFTools::Host;
use PFTools::Parser;
use PFTools::Logger;
use PFTools::Structqueries;
use PFTools::Conf::Syntax;
+use PFTools::Conf::Host;
+use PFTools::Conf::Net;
use Sys::Hostname;
use Fcntl ':mode';
use Data::Dumper;
Copied: branches/next-gen/lib/PFTools/Conf/Host.pm (from r851, branches/next-gen/lib/PFTools/Host.pm)
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Conf/Host.pm?rev=854&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Host.pm (original)
+++ branches/next-gen/lib/PFTools/Conf/Host.pm Fri Aug 27 14:04:49 2010
@@ -1,4 +1,4 @@
-package PFTools::Host;
+package PFTools::Conf::Host;
##
## $Id: Net.pm 786 2010-07-27 15:16:09Z ccaillet-guest $
##
@@ -165,42 +165,6 @@
#########################################################################
#
-# STR __Get_site_from_hostname ( STR, STR, STR, STR, HASHREF )
-#
-# This function returns the sites list for a given hostname
-# Inputs :
-# - $hostname : string containing the model definition for building hostname
-# - $global_config : hashref containing the parsed global configuration
-#
-# Output :
-# Returns an array ref containing the sites list or undef if hostname doesn't exist
-
-# sub __Get_site_from_hostname ($$) {
-# my ( $hostname, $global_config ) = @_;
-# my $site_list;
-#
-# foreach my $site ( @{$global_config->{'SITE'}->{'__site_list'}} ) {
-# my $host_part = $global_config->{'SITE'}->{'BY_NAME'}->{$site}->{'HOST'}->{'BY_NAME'};
-# foreach my $hostclass ( keys %{$host_part} ) {
-# if ( $hostclass eq $hostname ) {
-# push ( @{$site_list}, $site ) if ( ! grep ( /^$site$/, @{$site_list} ) );
-# next;
-# }
-# foreach my $host ( keys %{$host_part->{$hostclass}} ) {
-# if ( $host eq $hostname ) {
-# push ( @{$site_list}, $site ) if ( ! grep ( /^$site$/, @{$site_list} ) );
-# last;
-# }
-# }
-# }
-# }
-# return $site_list;
-# }
-
-
-
-#########################################################################
-#
# STR __Get_host_interfaces ( HASHREF )
#
# This function returns the interfaces list for a given parsed hostfile
Added: branches/next-gen/lib/PFTools/Conf/Net.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Conf/Net.pm?rev=854&op=file
==============================================================================
--- branches/next-gen/lib/PFTools/Conf/Net.pm (added)
+++ branches/next-gen/lib/PFTools/Conf/Net.pm Fri Aug 27 14:04:49 2010
@@ -1,0 +1,246 @@
+package PFTools::Conf::Net;
+##
+## $Id$
+##
+## Copyright (C) 2007-2009 Christophe Caillet <quadchris at free.fr>
+## Copyright (C) 2005-2007 Thomas Parmelan <tom+pf-tools at ankh.fr.EU.org>
+## Copyright (C) 2003-2005 Damien Clermonte <damien at sitadelle.com>
+## Copyright (C) 2001-2003 Olivier Molteni <olivier at molteni.net>
+##
+## This program is free software; you can redistribute it and/or
+## modify it under the terms of the GNU General Public License
+## as published by the Free Software Foundation; either version 2
+## of the License, or (at your option) any later version.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program; if not, write to the Free Software
+## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+##
+
+use strict;
+use warnings;
+
+use Exporter;
+
+our @ISA = ('Exporter');
+
+our @EXPORT = qw(
+ Add_network
+ Add_site
+ Add_zone
+);
+
+our @EXPORT_OK = qw();
+
+use Fcntl ':mode';
+use POSIX qw(ceil floor);
+
+use PFTools::Logger;
+use PFTools::Structqueries;
+use PFTools::Net;
+use Data::Dumper;
+
+#########################################################################
+### Rewrite with new syntax
+### Enhancement : creating DNS entries when adding network or hosts
+### Enhancement : creating DHCP entries when adding hosts
+
+#########################################################################
+#
+# VOID Add_zone ( STR , STR, HASHREF , HASHREF, HASHREF )
+#
+# This function adds zone into global configuration
+# Inputs :
+# - $netfile : filename where zone is parsed
+# - $zone_name : zone name
+# - $zone2add : hashref where are stored zone definitions according to networkfile-syntax
+# - $global_config : hashref where are stored datas
+# - $pf_config : hashref where are stored pf-tools configuration
+#
+sub Add_zone ($$$$$) {
+ my ( $netfile, $zone_name, $zone2add, $global_config, $pf_config ) = @_;
+
+ foreach my $ip_type ( 'ipv4', 'ipv6' ) {
+ next if ( ! $pf_config->{'features'}->{$ip_type} );
+ 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" );
+ return;
+ }
+ $zone_part->{$zone_name} = {
+ 'SOA' => $zone2add,
+ 'BY_SITE' => {},
+ '__network_order' => {},
+ '__hostclass_order' => {}
+ };
+ $zone_part->{$zone_name}->{'SOA'} = $zone2add;
+ $zone_part->{$zone_name}->{'BY_SITE'} = {};
+ }
+}
+
+#########################################################################
+#
+# VOID Add_site ( STR , STR, HASHREF , HASHREF, HASHREF )
+#
+# This function adds zone into global configuration
+# Inputs :
+# - $netfile : filename where zone is parsed
+# - $site_name : site name
+# - $site2add : hashref where are stored site definitions according to networkfile-syntax
+# - $global_config : hashref where are stored datas
+# - $pf_config : hashref where are stored pf-tools configuration
+#
+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" );
+ 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" );
+ }
+ else {
+ $site_part->{'ROOT'} = $site_name;
+ }
+ } else {
+ push ( @{$site_part->{'EDGE'}}, $site_name );
+ }
+ $site_part->{'BY_NAME'}->{$site_name} = $site2add;
+ $site_part->{'BY_NAME'}->{$site_name}->{'NETWORK'} = {
+ 'BY_NAME' => {},
+ 'BY_TAG' => {}
+ };
+ $site_part->{'BY_NAME'}->{$site_name}->{'HOST'} = {
+ 'BY_NAME' => {},
+ 'BY_MAC' => {}
+ };
+ $site_part->{'BY_NAME'}->{$site_name}->{'SERVICE'} = {
+ 'BY_NAME' => {}
+ };
+ push ( @{$site_part->{'__site_list'}}, $site_name );
+ 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" );
+ }
+ $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'} => {
+ 'subnet' => '',
+ 'netmask' => ''
+ }
+ };
+ }
+}
+
+#########################################################################
+#
+# 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 );
+
+ my $site_part = $global_config->{'SITE'};
+ $site_list = Get_site_list ( $ref_net, $global_config );
+ $net2add->{'scope'} = $ref_net->{'scope'};
+ $net2add->{'comment'} = $ref_net->{'comment'} if ( $ref_net->{'comment'} );
+ # Check TAG
+ 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" );
+ }
+ # Check IP values
+ foreach my $ip_type ( 'ipv4', 'ipv6' ) {
+ 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';
+ $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" );
+ }
+ 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" );
+ }
+ $net2add->{'gateway'.$suffix} = $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" );
+ }
+ 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} );
+ }
+ # 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};
+ $net_part->{'BY_NAME'}->{$net_name} = $net2add;
+ $net_part->{$netaddr_key}->{$net_block->cidr()} = $net_name;
+ $net_part->{'BY_TAG'}->{$ref_net->{'tag'}} = $net_name if ( $ref_net->{'tag'} );
+ # 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};
+ push ( @{$zone_part->{'__network_order'}->{$site}}, $net_name );
+ $zone_part->{'BY_SITE'}->{$site}->{$net_name} = {};
+ # Adding IPv4 entries
+ $zone_part->{'BY_SITE'}->{$site}->{$net_name}->{'network'} = "A\t".$net_block->addr();
+ $zone_part->{'BY_SITE'}->{$site}->{$net_name}->{'netmask'} = "A\t".$net_block->mask();
+ my $broad = $net_block->broadcast(); $broad =~ s/\/.*$//;
+ $zone_part->{'BY_SITE'}->{$site}->{$net_name}->{'broadcast'} = "A\t".$broad;
+ $zone_part->{'BY_SITE'}->{$site}->{$net_name}->{'gateway'} = "A\t".$net2add->{$gw_key} if ( defined $net2add->{$gw_key} );
+ if ( defined $dhcp_part->{$net_name} ) {
+ $dhcp_part->{$net_name}->{'subnet'} = $net_block->addr();
+ $dhcp_part->{$net_name}->{'netmask'} = $net_block->mask();
+ if ( defined $net2add->{'gateway'} ) {
+ $dhcp_part->{$net_name}->{'routers'} = $net2add->{'gateway'};
+ }
+ }
+ }
+ }
+}
+
+1;
Propchange: branches/next-gen/lib/PFTools/Conf/Net.pm
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Fri Aug 27 14:04:49 2010
@@ -1,0 +1,2 @@
+Id
+Revision
Modified: branches/next-gen/lib/PFTools/Net.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Net.pm?rev=854&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Net.pm (original)
+++ branches/next-gen/lib/PFTools/Net.pm Fri Aug 27 14:04:49 2010
@@ -30,12 +30,8 @@
our @ISA = ('Exporter');
our @EXPORT = qw(
- Add_network
- Add_site
- Add_zone
Get_netblock_from_vlan
Resolv_hostname_from_DNS
- Resolv_hostname_from_GLOBAL
);
our @EXPORT_OK = qw();
@@ -44,123 +40,15 @@
use POSIX qw(ceil floor);
use PFTools::Logger;
-use PFTools::Parser;
use PFTools::Structqueries;
use NetAddr::IP;
use Net::DNS;
-
use Data::Dumper;
-#$Data::Dumper::Sortkeys = 1;
-#$Data::Dumper::Useperl = 1;
-
-##############################################################
-### Prototypes
-
-sub Resolv_hostname_from_GLOBAL ($$$$$);
#########################################################################
### Rewrite with new syntax
### Enhancement : creating DNS entries when adding network or hosts
### Enhancement : creating DHCP entries when adding hosts
-
-#########################################################################
-#
-# VOID Add_zone ( STR , STR, HASHREF , HASHREF, HASHREF )
-#
-# This function adds zone into global configuration
-# Inputs :
-# - $netfile : filename where zone is parsed
-# - $zone_name : zone name
-# - $zone2add : hashref where are stored zone definitions according to networkfile-syntax
-# - $global_config : hashref where are stored datas
-# - $pf_config : hashref where are stored pf-tools configuration
-#
-sub Add_zone ($$$$$) {
- my ( $netfile, $zone_name, $zone2add, $global_config, $pf_config ) = @_;
-
- foreach my $ip_type ( 'ipv4', 'ipv6' ) {
- next if ( ! $pf_config->{'features'}->{$ip_type} );
- 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" );
- return;
- }
- $zone_part->{$zone_name} = {
- 'SOA' => $zone2add,
- 'BY_SITE' => {},
- '__network_order' => {},
- '__hostclass_order' => {}
- };
- $zone_part->{$zone_name}->{'SOA'} = $zone2add;
- $zone_part->{$zone_name}->{'BY_SITE'} = {};
- }
-}
-
-#########################################################################
-#
-# VOID Add_site ( STR , STR, HASHREF , HASHREF, HASHREF )
-#
-# This function adds zone into global configuration
-# Inputs :
-# - $netfile : filename where zone is parsed
-# - $site_name : site name
-# - $site2add : hashref where are stored site definitions according to networkfile-syntax
-# - $global_config : hashref where are stored datas
-# - $pf_config : hashref where are stored pf-tools configuration
-#
-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" );
- 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" );
- }
- else {
- $site_part->{'ROOT'} = $site_name;
- }
- } else {
- push ( @{$site_part->{'EDGE'}}, $site_name );
- }
- $site_part->{'BY_NAME'}->{$site_name} = $site2add;
- $site_part->{'BY_NAME'}->{$site_name}->{'NETWORK'} = {
- 'BY_NAME' => {},
- 'BY_TAG' => {}
- };
- $site_part->{'BY_NAME'}->{$site_name}->{'HOST'} = {
- 'BY_NAME' => {},
- 'BY_MAC' => {}
- };
- $site_part->{'BY_NAME'}->{$site_name}->{'SERVICE'} = {
- 'BY_NAME' => {}
- };
- push ( @{$site_part->{'__site_list'}}, $site_name );
- 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" );
- }
- $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'} => {
- 'subnet' => '',
- 'netmask' => ''
- }
- };
- }
-}
#########################################################################
#
@@ -200,137 +88,6 @@
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 );
-
- my $site_part = $global_config->{'SITE'};
- $site_list = Get_site_list ( $ref_net, $global_config );
- $net2add->{'scope'} = $ref_net->{'scope'};
- $net2add->{'comment'} = $ref_net->{'comment'} if ( $ref_net->{'comment'} );
- # Check TAG
- 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" );
- }
- # Check IP values
- foreach my $ip_type ( 'ipv4', 'ipv6' ) {
- 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';
- $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" );
- }
- 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" );
- }
- $net2add->{'gateway'.$suffix} = $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" );
- }
- 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} );
- }
- # 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};
- $net_part->{'BY_NAME'}->{$net_name} = $net2add;
- $net_part->{$netaddr_key}->{$net_block->cidr()} = $net_name;
- $net_part->{'BY_TAG'}->{$ref_net->{'tag'}} = $net_name if ( $ref_net->{'tag'} );
- # 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};
- push ( @{$zone_part->{'__network_order'}->{$site}}, $net_name );
- $zone_part->{'BY_SITE'}->{$site}->{$net_name} = {};
- # Adding IPv4 entries
- $zone_part->{'BY_SITE'}->{$site}->{$net_name}->{'network'} = "A\t".$net_block->addr();
- $zone_part->{'BY_SITE'}->{$site}->{$net_name}->{'netmask'} = "A\t".$net_block->mask();
- my $broad = $net_block->broadcast(); $broad =~ s/\/.*$//;
- $zone_part->{'BY_SITE'}->{$site}->{$net_name}->{'broadcast'} = "A\t".$broad;
- $zone_part->{'BY_SITE'}->{$site}->{$net_name}->{'gateway'} = "A\t".$net2add->{$gw_key} if ( defined $net2add->{$gw_key} );
- if ( defined $dhcp_part->{$net_name} ) {
- $dhcp_part->{$net_name}->{'subnet'} = $net_block->addr();
- $dhcp_part->{$net_name}->{'netmask'} = $net_block->mask();
- if ( defined $net2add->{'gateway'} ) {
- $dhcp_part->{$net_name}->{'routers'} = $net2add->{'gateway'};
- }
- }
- }
- }
-}
-
-sub Resolv_hostname_from_GLOBAL ($$$$$) {
- my ( $hostname, $global_config, $site, $zone, $hosttype ) = @_;
- my $resolved = [];
-
- $hostname =~ /^([^.]+)(\.([^.]+))?$/;
- my ( $hostshort, $hostvlan ) = ( $1, $3 );
- my $zone_part = $global_config->{'ZONE'}->{'BY_NAME'}->{$zone}->{'BY_SITE'}->{$site};
- if ( $hostname =~ /^(network|netmask|broadcast|gateway)/ ) {
- return undef if ( $hostvlan && ! defined $zone_part->{$hostvlan} );
- my ( $type, $field ) = split ( /\s+/, $zone_part->{$hostvlan}->{$hostshort} );
- push ( @{$resolved}, $field );
- }
- else {
- foreach my $entry ( keys %{$zone_part->{$hosttype}} ) {
- next if ( $entry !~ /^$hostname$/ );
- my @fields;
- if ( ref ( $zone_part->{$hosttype}->{$entry} ) eq 'ARRAY' ) {
- @fields = @{$zone_part->{$hosttype}->{$entry}}
- }
- else {
- @fields = ( $zone_part->{$hosttype}->{$entry} );
- }
- foreach my $line ( @fields ) {
- my ( $type, $field ) = split ( /\s+/, $line );
- if ( $type eq 'A' ) {
- push ( @{$resolved}, $field );
- }
- elsif ( $type eq 'CNAME' ) {
- my $cname_resolved = Resolv_hostname_from_GLOBAL ( $field, $global_config, $site, $zone, $hosttype );
- push ( @{$resolved}, @{$cname_resolved} );
- }
- }
- }
- }
- return $resolved;
-}
-
sub Resolv_hostname_from_DNS ($) {
my ( $hostname ) = @_;
my $resolved = [];
Modified: branches/next-gen/lib/PFTools/Structqueries.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Structqueries.pm?rev=854&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Structqueries.pm (original)
+++ branches/next-gen/lib/PFTools/Structqueries.pm Fri Aug 27 14:04:49 2010
@@ -44,10 +44,15 @@
Get_cmdline_from_hostprops
Get_pkgtype_from_hostname
Get_host_config_from_CONFIG
+ Resolv_hostname_from_GLOBAL
);
our @EXPORT_OK = qw ();
+##############################################################
+### Prototypes
+
+sub Resolv_hostname_from_GLOBAL ($$$$$);
#########################################################################
#
@@ -313,4 +318,41 @@
return ( $cmdline, $bond_cmdline );
}
+sub Resolv_hostname_from_GLOBAL ($$$$$) {
+ my ( $hostname, $global_config, $site, $zone, $hosttype ) = @_;
+ my $resolved = [];
+
+ $hostname =~ /^([^.]+)(\.([^.]+))?$/;
+ my ( $hostshort, $hostvlan ) = ( $1, $3 );
+ my $zone_part = $global_config->{'ZONE'}->{'BY_NAME'}->{$zone}->{'BY_SITE'}->{$site};
+ if ( $hostname =~ /^(network|netmask|broadcast|gateway)/ ) {
+ return undef if ( $hostvlan && ! defined $zone_part->{$hostvlan} );
+ my ( $type, $field ) = split ( /\s+/, $zone_part->{$hostvlan}->{$hostshort} );
+ push ( @{$resolved}, $field );
+ }
+ else {
+ foreach my $entry ( keys %{$zone_part->{$hosttype}} ) {
+ next if ( $entry !~ /^$hostname$/ );
+ my @fields;
+ if ( ref ( $zone_part->{$hosttype}->{$entry} ) eq 'ARRAY' ) {
+ @fields = @{$zone_part->{$hosttype}->{$entry}}
+ }
+ else {
+ @fields = ( $zone_part->{$hosttype}->{$entry} );
+ }
+ foreach my $line ( @fields ) {
+ my ( $type, $field ) = split ( /\s+/, $line );
+ if ( $type eq 'A' ) {
+ push ( @{$resolved}, $field );
+ }
+ elsif ( $type eq 'CNAME' ) {
+ my $cname_resolved = Resolv_hostname_from_GLOBAL ( $field, $global_config, $site, $zone, $hosttype );
+ push ( @{$resolved}, @{$cname_resolved} );
+ }
+ }
+ }
+ }
+ return $resolved;
+}
+
1;
More information about the pf-tools-commits
mailing list