pf-tools commit: r780 [ccaillet-guest] - in /branches/next-gen: debian/changelog doc/hostfile-syntax lib/PFTools/Conf.pm lib/PFTools/Net.pm

parmelan-guest at users.alioth.debian.org parmelan-guest at users.alioth.debian.org
Thu Jul 22 16:06:28 UTC 2010


Author: ccaillet-guest
Date: Thu Jul 22 16:06:28 2010
New Revision: 780

URL: http://svn.debian.org/wsvn/pf-tools/?sc=1&rev=780
Log:
  - Init_PF_CONFIG : function for parsing new style pf-tools.conf
  - rewrite Mk_interfaces

Modified:
    branches/next-gen/debian/changelog
    branches/next-gen/doc/hostfile-syntax
    branches/next-gen/lib/PFTools/Conf.pm
    branches/next-gen/lib/PFTools/Net.pm

Modified: branches/next-gen/debian/changelog
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/debian/changelog?rev=780&op=diff
==============================================================================
--- branches/next-gen/debian/changelog (original)
+++ branches/next-gen/debian/changelog Thu Jul 22 16:06:28 2010
@@ -17,6 +17,7 @@
     - adding __Translate_old2new_host for translating Parser_pftools result hash to
     hash Parser_ini hash result with new syntax file
     - Init_GLOBAL_NETCONFIG : similar to old function Init_lib_net
+    - Init_PF_CONFIG : function for parsing new style pf-tools.conf
   * lib/PFTools/Parser.pm
     - introducing this package from splitting Conf.pm function with old parser
     - adding parsing with ini standard parser based on Config::IniFiles
@@ -37,13 +38,13 @@
     - Add_host : adding pf-tools host configuration
     - rewrite Mk_zoneheader to __Mk_zoneheader
     - rewrite Mk_zone to Mk_zone_for_site
+    - rewrite Mk_interfaces
   * lib/PFTools/Packages.pm
     - using new packages Parser.pm et Logger.pm
   * lib/PFTools/Update.pm
     - using new packages Parser.pm et Logger.pm
-  * 
-
- -- Christophe Caillet <tof at sitadelle.com>  Thu, 22 Jul 2010 12:25:05 +0200
+
+ -- Christophe Caillet <quadchris at free.fr>  Thu, 22 Jul 2010 18:04:50 +0200
 
 pf-tools (0.34.0-0WIP) unstable; urgency=low
 

Modified: branches/next-gen/doc/hostfile-syntax
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/doc/hostfile-syntax?rev=780&op=diff
==============================================================================
--- branches/next-gen/doc/hostfile-syntax (original)
+++ branches/next-gen/doc/hostfile-syntax Thu Jul 22 16:06:28 2010
@@ -22,7 +22,7 @@
 	! vlan[.%HOSTNUM%]		::= <NETWORK_NAME> as defined in network configurations part in PF-TOOLS
 	! ipv4[.%HOSTNUM%]		::= <IPV4_ADDR> if default is used then act as old ipstart directive
 	? ipv6[.%HOSTNUM%]		::= <IPV6_ADDR> if default is used then act as old ipstart directive
-	? iface_opt[.%HOSTNUM%]	::= <IFACE_OPT> define here iface options (ip link syntax)
+	? iface_opt[.%HOSTNUM%]	::= <IFACE_OPT> define here iface options (ip link syntax and comma separated list)
 	? @route[.%HOSTNUM%]	::= <SUBNET>/<NETMASK> [via <GATEWAY>] (ip route syntax)
 	? @route6[.%HOSTNUM%]	::= <SUBNET>/<NETMASK> [via <GATEWAY>] (ip route syntax)
 

Modified: branches/next-gen/lib/PFTools/Conf.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Conf.pm?rev=780&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Conf.pm (original)
+++ branches/next-gen/lib/PFTools/Conf.pm Thu Jul 22 16:06:28 2010
@@ -291,8 +291,8 @@
 	'hosttype'	=> $HOSTTYPE_CONFIG_REGEX
 };
 
-sub Init_PF_CONFIG ($;$) {
-	my ( $config_file, $syntax ) = @_;
+sub Init_PF_CONFIG (;$) {
+	my ( $config_file ) = @_;
 
 # 		my ( $dev, $ino, $mode, $nlink, $uid, $gid, $rdev,
 # 		$size, $atime, $mtime, $ctime, $blksize, $blocks
@@ -300,34 +300,22 @@
 	if ( -r $PFTOOLSCONF ) {
 		my ( $dev, $ino, $mode, $nlink, $uid, $gid, @lstat_vars ) = lstat($PFTOOLSCONF);
 		unless ( $uid == 0 && $gid == 0 && S_IMODE($mode) == 0600 && S_ISREG($mode) ) {
-			Warn ( $CODE->{'RIGHTS'}, "Ignoring weak config (check owner/group/mode)" );
-			return 1;
-		}
-	}
-	else {
-		if ( $syntax eq 'nx' ) {
-			my $conf_parsed = Parser_ini ( $config_file );
-			Abort ( $CODE->{'SYNTAX'}, "Unable to parse configuration file ".$config_file ) if ( ! defined $conf_parsed );
-			foreach my $section ( keys %{$PF_CONFIG} ) {
-				next if ( ! defined $conf_parsed->{$section} );
-				foreach my $key ( keys %{$PF_CONFIG->{$section}} ) {
-					if ( defined $conf_parsed->{$section}->{$key} ) {
-						$PF_CONFIG->{$section}->{$key} = $conf_parsed->{$section}->{$key};
-					}
-				}
-			}
-		}
-		else {
-			my $result;
-			my $return;
-			unless ( $result = do $PFTOOLSCONF ) {
-				warn "couldn't parse $PFTOOLSCONF: $@" if $@;
-				warn "couldn't do $PFTOOLSCONF: $!" unless defined $return;
-				warn "couldn't run $PFTOOLSCONF"    unless $return;
-			}
-		}
-	}
-	return 0;
+			Abort ( $CODE->{'RIGHTS'}, "Ignoring weak config (check owner/group/mode)" );
+		}
+	}
+	return $PF_CONFIG if ( ! defined $config_file );
+	
+	my $conf_parsed = Parser_ini ( $config_file );
+	Abort ( $CODE->{'SYNTAX'}, "Unable to parse configuration file ".$config_file ) if ( ! defined $conf_parsed );
+	foreach my $section ( keys %{$PF_CONFIG} ) {
+		next if ( ! defined $conf_parsed->{$section} );
+		foreach my $key ( keys %{$PF_CONFIG->{$section}} ) {
+			if ( defined $conf_parsed->{$section}->{$key} ) {
+				$PF_CONFIG->{$section}->{$key} = $conf_parsed->{$section}->{$key};
+			}
+		}
+	}
+	return $PF_CONFIG;
 }
 
 sub Init_SUBST ($;$$) {

Modified: branches/next-gen/lib/PFTools/Net.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Net.pm?rev=780&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Net.pm (original)
+++ branches/next-gen/lib/PFTools/Net.pm Thu Jul 22 16:06:28 2010
@@ -52,7 +52,6 @@
     Cmp_routing_table
     
     cmpif
-    Host_class
     
     Add_network
     Add_site
@@ -1005,6 +1004,18 @@
 	}
 }
 
+#########################################################################
+#
+# ARRAY __Get_host_indexes ( HASHREF, STR )
+#
+# This function returns the maximum numbers and nodes for a specified hostgroup definition
+# Inputs :
+#  - $ref_hostgroup		: hashref containing the section where site key is defined
+#  - $hostname_model	: string containing the model definition for building hostname
+#
+# Output :
+#  Returns a list containing last number and last nodes for a hostgroup
+#
 sub __Get_host_indexes ($$) {
 	my ( $ref_hostgroup, $hostname_model ) = @_;
 	my ( $node_last, $num_last, $digits, $nodes );
@@ -1038,11 +1049,21 @@
 	return ( $num_last, $node_last );
 }
 
-sub __Get_numbers_from_hostclass_CONFIG ($$$) {
-	my ( $hostclass, $site, $global_config ) = @_;
-	
-}
-
+#########################################################################
+#
+# STR __Get_hostname_from_model ( STR, STR, STR, STR, HASHREF )
+#
+# This function returns the hostname for a given model, number and node
+# Inputs :
+#  - $hostname_model	: string containing the model definition for building hostname
+#  - $hostnum			: string containing the number
+#  - $hostnode			: string containing th node
+#  - $site_prefix		: string containing the site's prefix
+#  - $ref_host			: hashref containing the parsed sections where host is defined
+#
+# Output :
+#  Returns a string containing th hostname
+#
 sub __Get_hostname_from_model ($$$$) {
 	my ( $hostname_model, $hostnum, $hostnode, $site_prefix, $ref_host ) = @_;
 	my ( $hostname, $digits, $nodes, $index );
@@ -1067,21 +1088,18 @@
 	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;
-}
-
+#########################################################################
+#
+# 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;
@@ -1104,15 +1122,46 @@
 	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 ($$$) {
+#########################################################################
+#
+# STR Get_hosttype_from_hostname ( STR, STR, STR, STR, HASHREF )
+#
+# This function returns the hostname for a given model, number and node
+# Inputs :
+#  - $hostname		: string containing the model definition for building hostname
+#  - $global_config	: hashref containing the parsed global configuration
+#
+# Output :
+#  Returns a string containing the hosttype or undef if hostname doesn't exist
+#
+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;
+}
+
+#########################################################################
+#
+# STR Get_hostname_model_from_hostname ( STR, STR, STR, STR, HASHREF )
+#
+# This function returns the hostname for a given model, number and node
+# Inputs :
+#  - $hostname		: string containing the model definition for building hostname
+#  - $global_config	: hashref containing the parsed global configuration
+#
+# Output :
+#  Returns a string containing the hosttype or undef if hostname doesn't exist
+#
+sub Get_hostname_model_from_hostname ($$) {
 	my ( $hostname, $global_config ) = @_;
 	
 	my $hostclass = __Get_hosttype_from_hostname ( $hostname, $global_config );
@@ -1145,7 +1194,7 @@
 	foreach my $section ( keys %{$ref_src} ) {
 		next if ( $section !~ /^interface/ );
 		$section =~ /^interface::(((eth|bond)[\d]+)(\.(TAG[\d]+))?)$/;
-		push ( @if_list, $2 );
+		push ( @if_list, $1 );
 	}
 	return @if_list;
 }
@@ -1210,6 +1259,15 @@
 			&& ! grep ( /^$name$/, @{$alias_list} ) );
 	}
 	return $alias_list;
+}
+
+sub __Get_tag_from_vlan ($$$) {
+	my ( $vlan, $site, $global_config ) = @_;
+	
+	foreach my $tag ( keys %{$global_config->{'SITE'}->{'BY_NAME'}->{$site}->{'NETWORK'}->{'BY_TAG'}} ) {
+		return $tag if ( $global_config->{'SITE'}->{'BY_NAME'}->{$site}->{'NETWORK'}->{'BY_TAG'}->{$tag} eq $vlan );
+	}
+	return;
 }
 
 sub Add_server ($$$$$) {
@@ -1308,8 +1366,8 @@
 	my $iface_section	= 'interface::'.$iface;
 	my $nodes			= $ref_host->{'hostgroup'}->{'nodes'} || 0;
 	my $host_number		= ( $hostnode ) ? $hostnum.$hostnode : $hostnum;
-	$iface =~ /^(eth|bond[\d]+)(\.(TAG[\d]+))?$/;
-	( $ifraw, $iftag )	= ( $1, $3 );
+	$iface =~ /^((eth|bond)[\d]+)(\.(TAG[\d]+))?$/;
+	( $ifraw, $iftag )	= ( $1, $4 );
 	$vlan		= $ref_host->{$iface_section}->{'vlan.'.$host_number} || $ref_host->{$iface_section}->{'vlan'};
 	$iface_opt	= $ref_host->{$iface_section}->{'iface_opt.'.$host_number} || $ref_host->{$iface_section}->{'iface_opt'};
 	$add_if->{'vlan'}		= $vlan;
@@ -1319,6 +1377,9 @@
 		my $mac = $ref_host->{$iface_section}->{'mac.'.$host_number};
 		if ( $host_site->{'BY_MAC'}->{$mac} ) {
 			my ( $ifdef, $hostdef, $vlandef ) = split ( /\./, $host_site->{'BY_MAC'}->{$mac} );
+			print $hostname." -- ".$iface."\n";
+			print Dumper $ref_if_list;
+			print Dumper $ref_host->{$iface_section};
 			Abort ( $CODE->{'DUPLICATE_VALUE'},
 				"MAC address ".$mac." is already defined for interface ".$ifdef." in host ".$hostdef
 				." which is on vlan ".$vlandef );
@@ -1341,6 +1402,7 @@
 				"Interface ".$if." cannot be enslaved by ".$iface." : already in use for "
 				.$hostname ) if ( grep ( /$if/, @{$ref_if_list} ) );
 		}
+		$add_if->{'slaves'} = join ( " ", @slaves );
 	}
 	# Check vlan
 	if ( ! defined $network_site->{'BY_NAME'}->{$vlan} ) {
@@ -1365,8 +1427,9 @@
 		else {
 			$realip = __Check_host_ip ( $ip_type, $netblock, $ref_host->{$iface_section}->{$ip_type}, $hostnum, $hostnode, $nodes, $site, $ref_site );
 		}
- 		$add_if->{$ip_type}				= $realip->addr();
-		$add_if->{'netmask'.$suffix}	= $realip->mask();
+		$add_if->{$ip_type}				= $realip->cidr();
+# 		$add_if->{'netmask'.$suffix}	= $realip->mask();
+# 		$add_if->{'broadcast'.$suffix}	= $realip->broadcast(); $add_if->{'broadcast'.$suffix} =~ s/\/.+$//;
 		my $route_key	= ( $ip_type eq 'ipv6' ) ? '@route6' : '@route';
 		$route_key		.= $hostnum if ( $ref_host->{$iface_section}->{$route_key.'.'.$host_number} );
 		my $gw_key		= ( $ip_type eq 'ipv6' ) ? 'gateway6' : 'gateway';
@@ -1500,9 +1563,14 @@
 				my @if_list = __Get_host_interfaces ($host2add);
 				foreach my $iface ( @if_list ) {
 					my $if2add = __Add_host_interface ( $iface, $hostname, $hostnum, $hostnode, $host2add, \@if_list, $site, $site_part, $pf_config );
+					my $iface_name = $iface;
+					if ( $iface =~ /^((eth|bond)[\d]+)(\.(TAG[\d]+))$/ ) {
+						$iface_name = $1.'.'.__Get_tag_from_vlan ( $if2add->{'vlan'}, $site, $global_config );
+						warn "Nee to change iface ".$iface." to ".$iface_name."\n";
+					}
 					# Adding interface and IPs into site's zone
 					$host_part->{$hostname}->{'interfaces'}						= {} if ( ! defined $host_part->{$hostname}->{'interfaces'} );
-					$host_part->{$hostname}->{'interfaces'}->{$iface}			= $if2add;
+					$host_part->{$hostname}->{'interfaces'}->{$iface_name}		= $if2add;
 					$site_part->{'HOST'}->{'BY_MAC'}->{$if2add->{'mac'}}		= $iface.'.'.$hostname.'.'.$if2add->{'vlan'} if ( $if2add->{'mac'} );
 					if ( $if2add->{'vlan'} eq $dhcpvlan && ! defined $if2add->{'mac'} ) {
 						Abort ( $CODE->{'UNDEF_KEY'},
@@ -1693,185 +1761,210 @@
 #	machine $host a partir des informations contenues dans la structure $Z
 #
 #======================================================================================
-sub Mk_interfaces {
-    my ( $host, $fic_iface, $Z ) = @_;
-
-    # Calcul de la classe d'appartenance du serveur
-    my $hostclass = Host_class( $host, $Z );
+sub Mk_interfaces ($$$;$){
+    my ( $hostname, $global_config, $pf_config, $site ) = @_;
+	my $iface_result;
+    my $hostclass = Get_hosttype_from_hostname ( $hostname, $global_config );
+    
     my $resolve = 0;
 
-    # Recherche des informations dans la base de configuration
-    my $N = $Z->{'SERVERS'}->{'BY_NAME'}->{$hostclass};
-    if ( !ref($N) ) {
-	Abort( $ERR_SYNTAX,
-	          "La classe de serveurs "
-		. $hostclass
-		. " n'existe pas dans la configuration" );
-    }
-    my $M = $N->{'SRVLIST'}->{$host};
-
-    if ( !ref($M) ) {
-	Abort( $ERR_SYNTAX,
-	    "La machine " . $host . " n'existe pas dans la configuration" );
-    }
-
-    # Ouverture du fichier de destination
-    open( FIC_IFACE, "> " . $fic_iface )
-	|| Abort( $ERR_OPEN, "Impossible d'ouvrir " . $fic_iface );
-    my $old_STDOUT = select(FIC_IFACE);
-
-    # Ajout de l'interface de bouclage
-    print "auto lo\n";
-    print "iface lo inet loopback\n";
-
+	my $properties = Get_host_config_from_CONFIG ( $hostname, $global_config, $site );
+	# Loopback interface
+	push ( @{$iface_result}, "auto lo" );
+	push ( @{$iface_result}, "iface lo inet loopback" );
+	push ( @{$iface_result}, "" );
+
+	foreach my $iface ( sort keys %{$properties->{'interfaces'}} ) {
+		push ( @{$iface_result}, "auto ".$iface );
+		push ( @{$iface_result}, "iface ".$iface." inet static" );
+		my $if_part = $properties->{'interfaces'}->{$iface};
+		foreach my $ip_type ( 'ipv4', 'ipv6' ) {
+			next if ( ! $pf_config->{'features'}->{$ip_type} );
+			my $suffix = ( $ip_type eq 'ipv6' ) ? '6' : '';
+			my $ip = new NetAddr::IP ( $if_part->{$ip_type} );
+			push ( @{$iface_result}, "\tslaves\t\t".$if_part->{'slaves'} ) if ( $if_part->{'slaves'} );
+			push ( @{$iface_result}, "\taddress\t\t".$ip->addr() );
+			push ( @{$iface_result}, "\tnetmask\t\t".$ip->mask() );
+			my $net	= $ip->network(); push ( @{$iface_result}, "\tnetwork\t\t".$net->addr() );
+			my $broad = $ip->broadcast(); push ( @{$iface_result}, "\tbroadcast\t".$broad->addr() );
+			foreach my $route ( @{$if_part->{'@route'.$suffix}} ) {
+				if ( $route =~ /^default via ([^\s]+)$/ ) {
+					push ( @{$iface_result}, "\tgateway\t\t".$1 );
+				}
+				elsif ( $route =~ /via (^\s+)$/ ) {
+					push ( @{$iface_result}, "\tup\t\t/sbin/ip route add ".$route );
+				}
+				else {
+					push ( @{$iface_result}, "\tup\t\t/sbin/ip route add ".$route." dev ".$iface );
+				}
+			}
+			if ( $iface =~ /^([^\.]+)\.\d+$/ ) {
+				push ( @{$iface_result}, "\tvlan_raw_device\t".$1 );
+				if ( $if_part->{'iface_opt'} && $if_part->{'iface_opt'} !~ /mtu/ ) {
+					$if_part->{'iface_opt'} .= ",mtu 1496";
+				}
+				else {
+					$if_part->{'iface_opt'} = "mtu 1496";
+				}
+			}
+			if ( defined $if_part->{'iface_opt'} ) {
+				foreach my $option ( split ( /\s*,\s*/, $if_part->{'iface_opt'} ) ) {
+					push ( @{$iface_result}, "\tup\t\t/sbin/ip link set ".$iface." ".$option );
+				}
+			}
+			
+		}
+		push ( @{$iface_result}, "" );
+	}
+	return $iface_result;
     # Ajout de l'interface automatique si presente
-    if ( defined( $M->{'ifup'}->{'dhcp'} ) ) {
-	print "auto ",  $M->{'ifup'}->{'dhcp'}, "\n";
-	print "iface ", $M->{'ifup'}->{'dhcp'}, " inet dhcp\n";
-	Mk_routes( $M, $Z, $M->{'ifup'}->{'dhcp'} );
-    }
-    else {
-	$resolve = 1;
-    }
-
-    # Ajout des interfaces statiques
-    #foreach $nam ( sort { $M->{ifup}->{$a} cmp $M->{ifup}->{$b} }
-    foreach my $nam (
-	sort { cmpif( $M->{'ifup'}->{$a}, $M->{'ifup'}->{$b} ) }
-	keys %{ $M->{'ifup'} }
-	)
-    {
-	next if ( $nam eq 'dhcp' );
-
-	my $iface = $M->{'ifup'}->{$nam};
-
-	print "\nauto $iface\n";
-	print "iface $iface inet static\n";
-
-	my $net = $nam;
-	$net =~ s/^[^\.]+\.//;
-	my $NET = $Z->{'NETWORK'}->{'BY_NAME'}->{$net};
-
-	if ( $M->{'bonding'}->{$iface} ) {
-	    print
-		"\tslaves          ",
-		join(' ', @{ $M->{'bonding'}->{$iface} }),
-		"\n" ;
-	}
-
-	if ($resolve) {
-	    print "\taddress         ", $M->{'zone'}->{$nam}->{'FIELD'}, "\n";
-	    print "\tnetmask         ", $NET->{'netmask'},   "\n";
-	    print "\tbroadcast       ", $NET->{'broadcast'}, "\n";
-	    print "\tnetwork         ", $NET->{'network'},   "\n";
-	}
-	else {
-	    print "\taddress         " 
-		. $nam . '.'
-		. $Z->{'SOA'}->{'name'} . "\n";
-	    print "\tnetmask         netmask." 
-		. $net . '.'
-		. $Z->{'SOA'}->{'name'} . "\n";
-	    print "\tbroadcast       broadcast." 
-		. $net . '.'
-		. $Z->{'SOA'}->{'name'} . "\n";
-	    print "\tnetwork         network." 
-		. $net . '.'
-		. $Z->{'SOA'}->{'name'} . "\n";
-	}
-
-	my $defaultmtu = ($PFTOOLS_VARS->{'UML'}) ? 1496 : 1500;
-	if ( $iface =~ m/^([^:.]+)\.(\d+)(:\d+)?$/ ) {
-	    my $ifname = $1;
-	    my $iftag  = $2;
-
-	    print "\tvlan_raw_device $ifname\n";
-	    $defaultmtu = 1496;
-
-	    if ( defined $NET->{'tag'} and $NET->{'tag'} != $iftag ) {
-		Warn( $ERR_SYNTAX,
-		      "Les tags de $iface et de $net different ($iftag != $NET->{'tag'})!" );
-	    }
-	}
-
-	if ( defined $NET->{'mtu'} ) {
-	    $defaultmtu = $NET->{'mtu'};
-	}
-
-	print "\tup              ifconfig $iface mtu ",
-	    defined $M->{'mtu'}->{$iface} ?  $M->{'mtu'}->{$iface} : $defaultmtu,
-	    " ",
-	    defined $M->{'noarp'}->{$iface} ? "-arp" : "arp",
-	    "\n";
-
-	my $defaultmedia = "autoneg on";
-	if ( defined $NET->{'media'} ) {
-	    $defaultmedia = $NET->{'media'};
-	}
-	if ( defined $M->{'media'}->{$iface} ) {
-	    $defaultmedia = $M->{'media'}->{$iface};
-	}
-
-	my @defaultmedia = split ' ', $defaultmedia;
-	my $mediaerror = 0;
-	while ( @defaultmedia ) {
-	    my $mediaopt = shift @defaultmedia;
-	    my $mediaval = shift @defaultmedia;
-
-	    unless ( defined $mediaopt and defined $mediaval ) {
-		Warn( $ERR_SYNTAX, "Media syntax error: $defaultmedia" );
-		$mediaerror = 1;
-		next;
-	    }
-
-	    if ( $mediaopt eq 'speed' ) {
-		unless ( $mediaval =~ m/^\d+$/ ) {
-		    Warn( $ERR_SYNTAX, "Media syntax error: $defaultmedia" );
-		    $mediaerror = 1;
-		    next;
-		}
-	    }
-	    elsif ( $mediaopt eq 'duplex' ) {
-		unless ( $mediaval =~ m/^(half|full)$/ ) {
-		    Warn( $ERR_SYNTAX, "Media syntax error: $defaultmedia" );
-		    $mediaerror = 1;
-		    next;
-		}
-	    }
-	    elsif ( $mediaopt eq 'autoneg' ) {
-		unless ( $mediaval =~ m/^(on|off)$/ ) {
-		    Warn( $ERR_SYNTAX, "Media syntax error: $defaultmedia" );
-		    $mediaerror = 1;
-		    next;
-		}
-	    }
-	    else {
-		Warn( $ERR_SYNTAX, "Media syntax error: $defaultmedia" );
-		$mediaerror = 1;
-		next;
-	    }
-	}
-
-	if ( !$mediaerror ) {
-	    my $ifname = $iface;
-	    my $iftag;
-	    if ( $ifname =~ m/^([^:.]+)\.(\d+)(:\d+)?$/ ) {
-		$ifname = $1;
-		$iftag = $2;
-	    }
-	    unless ( $M->{'bonding'}->{$ifname} || $iftag ) {
-		print "\tup              ethtool -s $ifname $defaultmedia || true\n";
-	    }
-	}
-
-	Mk_routes( $M, $Z, $iface );
-
-    }
-    print "\n";
-
-    # Fermeture du fichier de destination
-    close(FIC_IFACE);
-    select($old_STDOUT);
+#     if ( defined( $M->{'ifup'}->{'dhcp'} ) ) {
+# 	print "auto ",  $M->{'ifup'}->{'dhcp'}, "\n";
+# 	print "iface ", $M->{'ifup'}->{'dhcp'}, " inet dhcp\n";
+# 	Mk_routes( $M, $Z, $M->{'ifup'}->{'dhcp'} );
+#     }
+#     else {
+# 	$resolve = 1;
+#     }
+# 
+#     # Ajout des interfaces statiques
+#     #foreach $nam ( sort { $M->{ifup}->{$a} cmp $M->{ifup}->{$b} }
+#     foreach my $nam (
+# 	sort { cmpif( $M->{'ifup'}->{$a}, $M->{'ifup'}->{$b} ) }
+# 	keys %{ $M->{'ifup'} }
+# 	)
+#     {
+# 	next if ( $nam eq 'dhcp' );
+# 
+# 	my $iface = $M->{'ifup'}->{$nam};
+# 
+# 	print "\nauto $iface\n";
+# 	print "iface $iface inet static\n";
+# 
+# 	my $net = $nam;
+# 	$net =~ s/^[^\.]+\.//;
+# 	my $NET = $Z->{'NETWORK'}->{'BY_NAME'}->{$net};
+# 
+# 	if ( $M->{'bonding'}->{$iface} ) {
+# 	    print
+# 		"\tslaves          ",
+# 		join(' ', @{ $M->{'bonding'}->{$iface} }),
+# 		"\n" ;
+# 	}
+# 
+# 	if ($resolve) {
+# 	    print "\taddress         ", $M->{'zone'}->{$nam}->{'FIELD'}, "\n";
+# 	    print "\tnetmask         ", $NET->{'netmask'},   "\n";
+# 	    print "\tbroadcast       ", $NET->{'broadcast'}, "\n";
+# 	    print "\tnetwork         ", $NET->{'network'},   "\n";
+# 	}
+# 	else {
+# 	    print "\taddress         " 
+# 		. $nam . '.'
+# 		. $Z->{'SOA'}->{'name'} . "\n";
+# 	    print "\tnetmask         netmask." 
+# 		. $net . '.'
+# 		. $Z->{'SOA'}->{'name'} . "\n";
+# 	    print "\tbroadcast       broadcast." 
+# 		. $net . '.'
+# 		. $Z->{'SOA'}->{'name'} . "\n";
+# 	    print "\tnetwork         network." 
+# 		. $net . '.'
+# 		. $Z->{'SOA'}->{'name'} . "\n";
+# 	}
+# 
+# 	my $defaultmtu = ($PFTOOLS_VARS->{'UML'}) ? 1496 : 1500;
+# 	if ( $iface =~ m/^([^:.]+)\.(\d+)(:\d+)?$/ ) {
+# 	    my $ifname = $1;
+# 	    my $iftag  = $2;
+# 
+# 	    print "\tvlan_raw_device $ifname\n";
+# 	    $defaultmtu = 1496;
+# 
+# 	    if ( defined $NET->{'tag'} and $NET->{'tag'} != $iftag ) {
+# 		Warn( $ERR_SYNTAX,
+# 		      "Les tags de $iface et de $net different ($iftag != $NET->{'tag'})!" );
+# 	    }
+# 	}
+# 
+# 	if ( defined $NET->{'mtu'} ) {
+# 	    $defaultmtu = $NET->{'mtu'};
+# 	}
+# 
+# 	print "\tup              ifconfig $iface mtu ",
+# 	    defined $M->{'mtu'}->{$iface} ?  $M->{'mtu'}->{$iface} : $defaultmtu,
+# 	    " ",
+# 	    defined $M->{'noarp'}->{$iface} ? "-arp" : "arp",
+# 	    "\n";
+# 
+# 	my $defaultmedia = "autoneg on";
+# 	if ( defined $NET->{'media'} ) {
+# 	    $defaultmedia = $NET->{'media'};
+# 	}
+# 	if ( defined $M->{'media'}->{$iface} ) {
+# 	    $defaultmedia = $M->{'media'}->{$iface};
+# 	}
+# 
+# 	my @defaultmedia = split ' ', $defaultmedia;
+# 	my $mediaerror = 0;
+# 	while ( @defaultmedia ) {
+# 	    my $mediaopt = shift @defaultmedia;
+# 	    my $mediaval = shift @defaultmedia;
+# 
+# 	    unless ( defined $mediaopt and defined $mediaval ) {
+# 		Warn( $ERR_SYNTAX, "Media syntax error: $defaultmedia" );
+# 		$mediaerror = 1;
+# 		next;
+# 	    }
+# 
+# 	    if ( $mediaopt eq 'speed' ) {
+# 		unless ( $mediaval =~ m/^\d+$/ ) {
+# 		    Warn( $ERR_SYNTAX, "Media syntax error: $defaultmedia" );
+# 		    $mediaerror = 1;
+# 		    next;
+# 		}
+# 	    }
+# 	    elsif ( $mediaopt eq 'duplex' ) {
+# 		unless ( $mediaval =~ m/^(half|full)$/ ) {
+# 		    Warn( $ERR_SYNTAX, "Media syntax error: $defaultmedia" );
+# 		    $mediaerror = 1;
+# 		    next;
+# 		}
+# 	    }
+# 	    elsif ( $mediaopt eq 'autoneg' ) {
+# 		unless ( $mediaval =~ m/^(on|off)$/ ) {
+# 		    Warn( $ERR_SYNTAX, "Media syntax error: $defaultmedia" );
+# 		    $mediaerror = 1;
+# 		    next;
+# 		}
+# 	    }
+# 	    else {
+# 		Warn( $ERR_SYNTAX, "Media syntax error: $defaultmedia" );
+# 		$mediaerror = 1;
+# 		next;
+# 	    }
+# 	}
+# 
+# 	if ( !$mediaerror ) {
+# 	    my $ifname = $iface;
+# 	    my $iftag;
+# 	    if ( $ifname =~ m/^([^:.]+)\.(\d+)(:\d+)?$/ ) {
+# 		$ifname = $1;
+# 		$iftag = $2;
+# 	    }
+# 	    unless ( $M->{'bonding'}->{$ifname} || $iftag ) {
+# 		print "\tup              ethtool -s $ifname $defaultmedia || true\n";
+# 	    }
+# 	}
+# 
+# 	Mk_routes( $M, $Z, $iface );
+# 
+#     }
+#     print "\n";
+# 
+#     # Fermeture du fichier de destination
+#     close(FIC_IFACE);
+#     select($old_STDOUT);
 }
 
 #




More information about the pf-tools-commits mailing list