pf-tools commit: r781 [ccaillet-guest] - in /branches/next-gen: debian/changelog lib/PFTools/Net.pm

parmelan-guest at users.alioth.debian.org parmelan-guest at users.alioth.debian.org
Fri Jul 23 12:36:41 UTC 2010


Author: ccaillet-guest
Date: Fri Jul 23 12:36:36 2010
New Revision: 781

URL: http://svn.debian.org/wsvn/pf-tools/?sc=1&rev=781
Log:
removing dead or useless code

Modified:
    branches/next-gen/debian/changelog
    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=781&op=diff
==============================================================================
--- branches/next-gen/debian/changelog (original)
+++ branches/next-gen/debian/changelog Fri Jul 23 12:36:36 2010
@@ -39,12 +39,13 @@
     - rewrite Mk_zoneheader to __Mk_zoneheader
     - rewrite Mk_zone to Mk_zone_for_site
     - rewrite Mk_interfaces
+    - removing dead or useless code
   * 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 <quadchris at free.fr>  Thu, 22 Jul 2010 18:04:50 +0200
+ -- Christophe Caillet <quadchris at free.fr>  Fri, 23 Jul 2010 14:15:49 +0200
 
 pf-tools (0.34.0-0WIP) unstable; urgency=low
 

Modified: branches/next-gen/lib/PFTools/Net.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Net.pm?rev=781&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Net.pm (original)
+++ branches/next-gen/lib/PFTools/Net.pm Fri Jul 23 12:36:36 2010
@@ -1566,7 +1566,6 @@
 					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'} );
@@ -1585,6 +1584,13 @@
 						my $zone_part	= $global_config->{$zone_key}->{'BY_NAME'}->{$zone}->{'BY_SITE'}->{$site};
 						my $dhcp_part	= $global_config->{$dhcp_key}->{'BY_SITE'}->{$site};
 						$site_part->{'HOST'}->{$addr_key}->{$if2add->{$ip_type}} = $hostname.'.'.$if2add->{'vlan'};
+# 						if ( defined $if2add->{'@route'.$suffix} ) {
+# 							foreach my $route ( @{$if2add->{'@route'.$suffix}} ) {
+# 								$route =~ /^([^\s]+)\s*(via ([^\s]+))?$/;
+# 								my $dest = $1;
+# 								push ( @{$host_part->{$hostname}->{'routes'}->{$dest}}, $iface_name." ".$route );
+# 							}
+# 						}
 						if ( ! defined $zone_part->{$hostclass} ) {
 							$zone_part->{$hostclass} = {};
 							push ( @{$global_config->{$zone_key}->{'BY_NAME'}->{$zone}->{'__hostclass_order'}->{$site}}, $hostclass );
@@ -1763,43 +1769,42 @@
 #======================================================================================
 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;
-
-	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};
+
+	my $hostclass	= Get_hosttype_from_hostname ( $hostname, $global_config );
+	my $resolve		= 0;
+	my $properties	= Get_host_config_from_CONFIG ( $hostname, $global_config, $site );
+	my $interfaces	= {};
+	my $routes		= {};
+	
+	foreach my $iface ( 'lo', sort keys %{$properties->{'interfaces'}} ) {
+		push ( @{$interfaces->{'__order'}}, $iface );
+		my $if_part = $properties->{'interfaces'}->{$iface} if ( defined $properties->{'interfaces'}->{$iface});
+		push ( @{$interfaces->{$iface}}, "auto ".$iface );
+		if ( $if_part->{'method'} ) {
+			push ( @{$interfaces->{$iface}}, "iface ".$iface." inet ".$if_part->{'method'} );
+		}
+		elsif ( $iface eq 'lo' ) {
+			push ( @{$interfaces->{$iface}}, "iface ".$iface." inet loopback" );
+		}
+		else {
+			push ( @{$interfaces->{$iface}}, "iface ".$iface." inet static" );
+		}
+		next if ( ( $if_part->{'method'} && $if_part->{'method'} eq 'dhcp' ) || $iface eq 'lo' );
 		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() );
+			push ( @{$interfaces->{$iface}}, "\tslaves\t\t".$if_part->{'slaves'} ) if ( $if_part->{'slaves'} );
+			push ( @{$interfaces->{$iface}}, "\taddress\t\t".$ip->addr() );
+			push ( @{$interfaces->{$iface}}, "\tnetmask\t\t".$ip->mask() );
+			my $net	= $ip->network(); push ( @{$interfaces->{$iface}}, "\tnetwork\t\t".$net->addr() );
+			my $broad = $ip->broadcast(); push ( @{$interfaces->{$iface}}, "\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 );
-				}
+				$route =~ /^([^\s]+)\s*(via ([^\s]+))?$/;
+				push ( @{$routes->{$1}}, $iface." ".$route );
 			}
 			if ( $iface =~ /^([^\.]+)\.\d+$/ ) {
-				push ( @{$iface_result}, "\tvlan_raw_device\t".$1 );
+				push ( @{$interfaces->{$iface}}, "\tvlan_raw_device\t".$1 );
 				if ( $if_part->{'iface_opt'} && $if_part->{'iface_opt'} !~ /mtu/ ) {
 					$if_part->{'iface_opt'} .= ",mtu 1496";
 				}
@@ -1809,162 +1814,42 @@
 			}
 			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 ( @{$interfaces->{$iface}}, "\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);
+	}
+	foreach my $dest ( keys %{$routes} ) {
+		if ( scalar @{$routes->{$dest}} > 1 ) {
+			foreach my $entry ( @{$routes->{$dest}} ) {
+				my ( $if, $dst, $via, $gw ) = split ( /\s+/, $entry );
+				if ( ! defined $gw ) {
+					Warn ( $CODE->{'UNDEF_KEY'},
+						"Unable to add a route for destination ".$dst." with multiple gateway without gateway definition"
+						." on hostname ".$hostname );
+					last;
+				}
+				push ( @{$interfaces->{$if}}, "\tup\t\t/sbin/ip route add ".$dst." scope global via ".$gw." dev ".$if );
+			}
+		}
+		else {
+			my ( $entry ) = @{$routes->{$dest}};
+			print "Entry --> ".$entry."\n";
+			my ( $if, $dst, $via, $gw ) = split ( /\s+/, $entry );
+			if ( $dst eq 'default' ) {
+				if ( ! defined $gw ) {
+					Abort ( $CODE->{'UNDEF_KEY'},
+						"Unable to define default route without gateway defined for interface ".$if." on hostname ".$hostname );
+				}
+				push ( @{$interfaces->{$if}}, "\tgateway\t\t$gw" );
+			}
+			else {
+				push ( @{$interfaces->{$if}}, "\tup\t\t/sbin/ip route add ".$entry." dev ".$if );
+			}
+		}
+	}
+	return $interfaces;
 }
 
 #
@@ -2041,170 +1926,6 @@
     return undef;
 }
 
-#
-#	VOID Mk_routes (HASHREF $M, HASHREF $Z, STRING $iface)
-#
-#	Calcule les commandes routes du fichier interface
-#
-#======================================================================================
-sub Mk_routes {
-    my ( $M, $Z, $iface ) = @_;
-
-    my $r;
-    foreach $r ( sort ( keys %{ $M->{'route'}->{$iface} } ) ) {
-	my ( $dst, @gw ) = split( /\s+/, $M->{'route'}->{$iface}->{$r} );
-	my $gw;
-	my @gw2;
-	foreach $gw (@gw) {
-	    my @resolved = Resolv( $gw, $Z );
-	    if ( $#resolved >= 0 && defined $resolved[0] ) {
-		my $resolved;
-		foreach $resolved (@resolved) {
-		    push @gw2, $resolved;
-		}
-	    }
-	    else {
-		push @gw2, $gw;
-	    }
-	}
-	if ( $Z->{'NETWORK'}->{'BY_NAME'}->{$dst} ) {
-	    if ( $#gw2 >= 2 ) {
-		print "\tup              ip route add ";
-
-		print $Z->{'NETWORK'}->{'BY_NAME'}->{$dst}->{'network'};
-		print "/";
-		print netmask2prefix(
-		    $Z->{'NETWORK'}->{'BY_NAME'}->{$dst}->{'netmask'} );
-
-		print " scope global";
-
-		print " ", join( ' nexthop via ', @gw2 );
-
-		print " dev " . $iface;
-
-		print "\n";
-	    }
-	    else {
-		print "\tup              route add -net ";
-
-		#print "network.".$dst.".".$Z->{SOA}->{name};
-		print $Z->{'NETWORK'}->{'BY_NAME'}->{$dst}->{'network'};
-		print " netmask ";
-
-		#print "netmask.".$dst.".".$Z->{SOA}->{name};
-		print $Z->{'NETWORK'}->{'BY_NAME'}->{$dst}->{'netmask'};
-
-		print " gateway " . $gw2[0] if ( defined $gw2[0] );
-
-		print " dev " . $iface;
-
-		print "\n";
-	    }
-	}
-	elsif ( $dst eq 'default' ) {
-	    if ( $#gw >= 2 ) {
-		print "\tup              ip route add ";
-
-		print "default";
-
-		print " scope global";
-
-		print " ", join( ' nexthop via ', @gw2 );
-
-		print " dev " . $iface;
-
-		print "\n";
-	    }
-	    else {
-		print "\tgateway " . $gw2[0] if ( defined $gw2[0] );
-
-		#print " dev " . $iface;
-
-		print "\n";
-	    }
-	}
-	else {
-	    if ( $#gw >= 2 ) {
-		print "\tup              ip route add ";
-
-		my $dst2 = Resolv( $dst, $Z );
-		if ( !defined $dst2 ) {
-		    $dst2 = $dst;
-		}
-
-		print $dst2;
-
-		print " scope global";
-
-		print " ", join( ' nexthop via ', @gw2 );
-
-		print " dev " . $iface;
-
-		print "\n";
-	    }
-	    else {
-		print "\tup              route add -host ";
-
-		my $dst2 = Resolv( $dst, $Z );
-		if ( !defined $dst2 ) {
-		    $dst2 = $dst;
-		}
-		print $dst2;
-		print " gateway  " . $gw2[0] if ( defined $gw2[0] );
-
-		print " dev " . $iface;
-
-		print "\n";
-	    }
-	}
-    }
-
-    foreach $r ( sort ( keys %{ $M->{'delroute'}->{$iface} } ) ) {
-	my ($dst) = split( /\s+/, $M->{'route'}->{$iface}->{$r} );
-
-	if ( $Z->{'NETWORK'}->{'BY_NAME'}->{$dst} ) {
-	    print "\tup              ip route del ";
-
-	    print $Z->{'NETWORK'}->{'BY_NAME'}->{$dst}->{network};
-	    print "/";
-	    print netmask2prefix(
-		$Z->{'NETWORK'}->{'BY_NAME'}->{$dst}->{'netmask'} );
-
-	    print " scope global";
-
-	    print " dev " . $iface;
-
-	    print "\n";
-	}
-	elsif ( $dst eq 'default' ) {
-	    print "\tup              ip route del ";
-
-	    print "default";
-
-	    print " scope global";
-
-	    print " dev " . $iface;
-
-	    print "\n";
-	}
-	else {
-	    print "\tup              ip route del ";
-
-	    my $dst2 = Resolv( $dst, $Z );
-	    if ( !defined $dst2 ) {
-		$dst2 = $dst;
-	    }
-
-	    print $dst2;
-
-	    print " scope global";
-
-	    print " dev " . $iface;
-
-	    print "\n";
-	}
-    }
-}
 
 if ( `grep -e '^host[ 	]*:' /proc/cpuinfo 2>/dev/null` ne "" ) {
     $PFTOOLS_VARS->{'UML'} = 1;




More information about the pf-tools-commits mailing list