pf-tools commit: r774 [ccaillet-guest] - in /branches/next-gen: doc/hostfile-syntax doc/networkfile-syntax lib/PFTools/Conf.pm lib/PFTools/Net.pm
parmelan-guest at users.alioth.debian.org
parmelan-guest at users.alioth.debian.org
Tue Jul 20 15:30:46 UTC 2010
Author: ccaillet-guest
Date: Tue Jul 20 15:30:45 2010
New Revision: 774
URL: http://svn.debian.org/wsvn/pf-tools/?sc=1&rev=774
Log:
Add new functions and grant declaration of network with CIDR format directly into the key network or network6
Modified:
branches/next-gen/doc/hostfile-syntax
branches/next-gen/doc/networkfile-syntax
branches/next-gen/lib/PFTools/Conf.pm
branches/next-gen/lib/PFTools/Net.pm
Modified: branches/next-gen/doc/hostfile-syntax
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/doc/hostfile-syntax?rev=774&op=diff
==============================================================================
--- branches/next-gen/doc/hostfile-syntax (original)
+++ branches/next-gen/doc/hostfile-syntax Tue Jul 20 15:30:45 2010
@@ -42,6 +42,7 @@
? dhcpvlan[.%HOSTNUM%] ::= <NETWORK_NAME>
[hostgroup]
+ ? prefix ::= true|false
! site ::= <SITE_NAME>
? comment ::= <STR>
? model ::= <MODEL_NAME> if model is defined then <MODEL_NAME> file is parsed from model directory and hashes are merged with right precedency
Modified: branches/next-gen/doc/networkfile-syntax
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/doc/networkfile-syntax?rev=774&op=diff
==============================================================================
--- branches/next-gen/doc/networkfile-syntax (original)
+++ branches/next-gen/doc/networkfile-syntax Tue Jul 20 15:30:45 2010
@@ -29,9 +29,9 @@
? comment ::= <STR>
! site ::= <STR>
? tag ::= <INT> 802.1q tag
- ! network ::= <NETWORK> define here the prefix in IPv4 format
+ ! network ::= <NETWORK> define here the network in IPv4 format if CIDR format is used netmask key is not needed
? network6 ::= <NETWORK> define here the prefix in IPv6 format
- ! netmask ::= <NETMASK> define here the netmask in IPv4 format or in CIDR format e.g. /XX
+ ? netmask ::= <NETMASK> define here the netmask in IPv4 format or in CIDR format e.g. /XX
? netmask6 ::= <NETMASK> define here the netmask in IPv6 format or in CIDR format e.g. /XX
! scope ::= private|public, if private is defined this network will be ONLY added on zone private for site
? gateway ::= <IPV4>
Modified: branches/next-gen/lib/PFTools/Conf.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Conf.pm?rev=774&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Conf.pm (original)
+++ branches/next-gen/lib/PFTools/Conf.pm Tue Jul 20 15:30:45 2010
@@ -130,6 +130,7 @@
'number' => '[\d]+',
'order' => '[\d]+',
'nodes' => '[\d]+',
+ 'prefix' => '(true|false)',
'hostname' => $HOST_CONFIG_REGEX,
'hosttype' => $HOSTTYPE_CONFIG_REGEX
};
@@ -171,14 +172,15 @@
'zone' => '\w+',
'state' => 'ROOT|EDGE',
'dhcpvlan' => '[\w\-]+',
+ 'prefix' => '\w+',
'console' => '(default|ttyS0,115200n8)'
};
$DEF_SECTIONS->{'network'}->{'network'} = {
- 'MANDATORY_KEYS' => [ 'network','netmask', 'site' ],
+ 'MANDATORY_KEYS' => [ 'network', 'site' ],
'comment' => 'undefined',
'tag' => '\d{1,4}',
- 'network' => '([\d]{1,3}\.){3}[\d]{1,3}',
+ 'network' => '([\d]{1,3}\.){3}[\d]{1,3}(\/\d+)?',
'network6' => 'undefined',
'netmask' => '(/\d{2}|([\d]{1,3}\.){3}[\d]{1,3})',
'netmask6' => 'undefined',
Modified: branches/next-gen/lib/PFTools/Net.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Net.pm?rev=774&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Net.pm (original)
+++ branches/next-gen/lib/PFTools/Net.pm Tue Jul 20 15:30:45 2010
@@ -714,7 +714,20 @@
#########################################################################
### 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 ) = @_;
@@ -737,6 +750,18 @@
}
}
+#########################################################################
+#
+# 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 ) = @_;
@@ -790,13 +815,34 @@
}
}
+#########################################################################
+#
+# STR __Get_site_prefix ( STR , HASHREF )
+#
+# This function adds zone into global configuration
+# Inputs :
+# - $site : site name
+# - $ref_site : hashref where are stored site definitions according to networkfile-syntax
+#
+# Output :
+# Return a string containing the site prefix as defined into site parsed data.
+#
+# WARNING : by convention only EDGE sites are authorized for prefixing hostname
+#
sub __Get_site_prefix ($$) {
my ( $site, $ref_site ) = @_;
- my $prefix = ( $ref_site->{'state'} eq 'EDGE' )
- ? $site.'-'
- : '';
- return $prefix;
+ if ( $ref_site->{'state'} eq 'EDGE' ) {
+ if ( defined $ref_site->{'prefix'} ) {
+ return $ref_site->{'prefix'}.'-';
+ }
+ else {
+ return $site.'-';
+ }
+ }
+ else {
+ return '';
+ }
}
sub __Get_site_zone ($$) {
@@ -822,9 +868,24 @@
my ( $type, $net_hash ) = @_;
my $suffix = ( $type eq 'ipv6' ) ? '6' : '';
- my $block = ( $net_hash->{'netmask'.$suffix} =~/^\// )
- ? new NetAddr::IP ( $net_hash->{'network'.$suffix}.$net_hash->{'netmask'.$suffix} )
- : new NetAddr::IP ( $net_hash->{'network'.$suffix}, $net_hash->{'netmask'.$suffix} );
+ my @net_def; my $msg;
+ if ( $net_hash->{'network'.$suffix} =~ /\/\d+$/ ) {
+ @net_def = ( $net_hash->{'network'.$suffix} );
+ $msg = "Invalid network ".$net_hash->{'network'.$suffix}." ".$type." defintion";
+ }
+ elsif ( $net_hash->{'netmask'.$suffix} =~/^\// ) {
+ @net_def = ( $net_hash->{'network'.$suffix}.$net_hash->{'netmask'.$suffix} );
+ $msg = "Invalid network ".$net_hash->{'network'.$suffix}.$net_hash->{'netmask'.$suffix}." ".$type." defintion";
+ }
+ else {
+ @net_def = ( $net_hash->{'network'.$suffix}, $net_hash->{'netmask'.$suffix} );
+ $msg = "Invalid network ".$net_hash->{'network'.$suffix}." and/or netmask ".$net_hash->{'netmask'.$suffix}." ".$type." defintion";
+ }
+ my $block = new NetAddr::IP ( @net_def );
+ if ( ! defined $block ) {
+ Abort ( $CODE->{'UNDEF_KEY'},
+ $msg );
+ }
return $block;
}
@@ -845,11 +906,11 @@
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" );
- }
+# 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" );
+# }
$net2add->{'network'.$suffix} = $net_block->addr();
$net2add->{'netmask'.$suffix} = $net_block->mask();
if ( $ref_net->{'gateway'.$suffix} ) {
@@ -883,11 +944,11 @@
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" );
- }
+# 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 ) {
Abort ( $CODE->{'DUPLICATE_VALUE'},
@@ -903,6 +964,7 @@
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'};
@@ -916,10 +978,11 @@
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}->{'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();
@@ -965,7 +1028,7 @@
}
sub __Get_hostname_from_model ($$$$) {
- my ( $hostname_model, $hostnum, $hostnode, $site_prefix ) = @_;
+ my ( $hostname_model, $hostnum, $hostnode, $site_prefix, $ref_host ) = @_;
my ( $hostname, $digits, $nodes, $index );
$hostname = $hostname_model;
@@ -984,10 +1047,80 @@
? $index.$hostnum.$hostnode
: $index.$hostnum;
$hostname =~ s/(%*)(_*)$/$index/;
- $hostname = $site_prefix.$hostname;
+ $hostname = $site_prefix.$hostname if ( $ref_host->{'prefix'} && $ref_host->{'prefix'} eq 'true' );
return $hostname;
}
+sub Get_hosttype_from_hostname ($$) {
+ my ( $hostname, $global_config ) = @_;
+
+ 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} ) {
+ return $hostclass if ( $hostclass eq $hostname );
+ foreach my $host ( keys %{$host_part->{$hostclass}} ) {
+ return $hostclass if ( $host eq $hostname );
+ }
+ }
+ }
+ return undef;
+}
+
+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;
+}
+
+#
+# Backward compatibility with previous function
+sub Host_class {
+ my ( $hostclass, $global_config ) = @_;
+
+ return Get_hosttype_from_hostname ( $hostclass, $global_config );
+}
+
+sub Get_hostname_model_from_hostname ($$$) {
+ my ( $hostname, $global_config ) = @_;
+
+ my $hostclass = __Get_hosttype_from_hostname ( $hostname, $global_config );
+ if ( ! defined $hostclass ) {
+ Abort ( $CODE->{'UNDEF_KEY'},
+ "Unable to get hosttype from hostname ".$hostname." : unexistant hostname" );
+ }
+ my $site_list = Get_site_from_hostname ( $hostname, $global_config );
+ if ( ! defined $site_list ) {
+ Abort ( $CODE->{'UNDEF_KEY'},
+ "Unable to get site list from hostname ".$hostname." : unexistant hostname" );
+ }
+ else {
+ if ( scalar @{$site_list} > 1 ) {
+ Warn ( $CODE->{'DUPLICATE_VALUE'},
+ "Hostname ".$hostname." is defined on multiple sites : unable to choose the right one" );
+ return undef;
+ }
+ else {
+ my ( $site ) = @{$site_list};
+ return $global_config->{'SITE'}->{'BY_NAME'}->{$site}->{'HOST'}->{'BY_NAME'}->{$hostclass}->{'deployment'}->{'hostname_model'};
+ }
+ }
+}
sub __Get_host_interfaces ($) {
my ( $ref_src ) = @_;
@@ -1152,7 +1285,7 @@
sub __Add_host_interface ($$$$$$$$$) {
my ( $iface, $hostname, $hostnum, $hostnode, $ref_host, $ref_if_list, $site, $ref_site, $pf_config ) = @_;
- my ( @if_list, $vlan, $ifraw, $iftag, $add_if );
+ my ( @if_list, $vlan, $ifraw, $iftag, $add_if, $iface_opt );
my $network_site = $ref_site->{'NETWORK'};
my $host_site = $ref_site->{'HOST'};
@@ -1346,6 +1479,7 @@
next if ( ! defined $value );
$host_part->{$hostname}->{'deployment'}->{$key} = $value;
}
+ $host_part->{$hostname}->{'deployment'}->{'hostname_model'} = $host2add->{'hostgroup'}->{'hostname'};
# Check interfaces
my @if_list = __Get_host_interfaces ($host2add);
foreach my $iface ( @if_list ) {
@@ -1409,30 +1543,6 @@
}
}
-#
-# STRING Host_class (STRING $host)
-#
-# Retourne la classe de serveur a laquelle appartient le serveur $h
-#
-#================================================================================
-sub Host_class {
- my ( $h, $Z ) = @_;
-
-# !!!!!! Attention ne marchera pas si la classe se termine par de chiffres !!!!
-# Gros fix qui tache
- if ( defined $Z->{'SERVERS'}->{'BY_NAME'}->{$h} ) {
- return ($h);
- }
-
- # Gros fix qui tache encore plus...
- $h =~ s/(\d)[a-z]+$/$1/;
- if ( defined $Z->{'SERVERS'}->{'BY_NAME'}->{$h} ) {
- return ($h);
- }
-
- $h =~ s/\d+$//;
- return ($h);
-}
sub Mk_zoneheader {
my ( $fic_zone, $Z ) = @_;
More information about the pf-tools-commits
mailing list