From 051eaae467adf2d2b7e24698ebabebc7b3efdaf7 Mon Sep 17 00:00:00 2001 From: ligc Date: Thu, 6 May 2010 09:32:49 +0000 Subject: [PATCH] ipv6 support git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@5988 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- perl-xCAT/xCAT/DBobjUtils.pm | 26 +++++++++----------------- perl-xCAT/xCAT/InstUtils.pm | 13 ++++++------- perl-xCAT/xCAT/PPCmac.pm | 8 +++++--- perl-xCAT/xCAT/PPCscan.pm | 2 +- 4 files changed, 21 insertions(+), 28 deletions(-) diff --git a/perl-xCAT/xCAT/DBobjUtils.pm b/perl-xCAT/xCAT/DBobjUtils.pm index f1f035d91..ffebe5e1e 100644 --- a/perl-xCAT/xCAT/DBobjUtils.pm +++ b/perl-xCAT/xCAT/DBobjUtils.pm @@ -1813,7 +1813,6 @@ sub getGroupMembers %nethash = xCAT::DBobjUtils->getNetwkInfo(\@targetnodes); Comments: - Not supporting IPv6 yet =cut @@ -1845,11 +1844,11 @@ sub getNetwkInfo { # get, check, split the node IP - my $IP = inet_ntoa(inet_aton($node)); + my $IP = xCAT::Utils->getipaddr($node); chomp $IP; - unless ($IP =~ /\d+\.\d+\.\d+\.\d+/) + unless (($IP =~ /\d+\.\d+\.\d+\.\d+/) || ($IP =~ /:/)) { - next; #Not supporting IPv6 yet + next; } my ($ia, $ib, $ic, $id) = split('\.', $IP); @@ -1861,25 +1860,18 @@ sub getNetwkInfo my $net=$_->{'net'}; chomp $NM; chomp $net; - my ($n1, $n2, $n3, $n4) = split('\.', $net); - my ($na, $nb, $nc, $nd) = split('\.', $NM); - # Convert to integers so the bitwise and (&) works correctly. - my $sa = (int($ia) & int($na)); - my $sb = (int($ib) & int($nb)); - my $sc = (int($ic) & int($nc)); - my $sd = (int($id) & int($nd)); - - # if all the octals match then we have the right network - if ( ($n1 == $sa) && ($n2 ==$sb) && ($n3 == $sc) && ($n4 == $sd) ) { + if(xCAT::Utils->ishostinsubnet($IP, $NM, $net)) + { # fill in the hash - foreach my $attr (@attrnames) { if ( defined($_->{$attr}) ) { $nethash{$node}{$attr} = $_->{$attr}; } - } - next; - } + } + next; + } + } } #end - for each node diff --git a/perl-xCAT/xCAT/InstUtils.pm b/perl-xCAT/xCAT/InstUtils.pm index e964d0c1a..bcd36cb3a 100644 --- a/perl-xCAT/xCAT/InstUtils.pm +++ b/perl-xCAT/xCAT/InstUtils.pm @@ -185,14 +185,14 @@ sub is_me my ($class, $name) = @_; # convert to IP - my $nameIP = inet_ntoa(inet_aton($name)); + my $nameIP = xCAT::Utils->getipaddr($name); chomp $nameIP; # split into octets - my ($b1, $b2, $b3, $b4) = split /\./, $nameIP; + #my ($b1, $b2, $b3, $b4) = split /\./, $nameIP; # get all the possible IPs for the node I'm running on - my $ifcmd = "ifconfig -a | grep 'inet '"; + my $ifcmd = "ifconfig -a | grep 'inet'"; my $result = xCAT::Utils->runcmd($ifcmd, 0, 1); if ($::RUNCMD_RC != 0) { @@ -207,11 +207,10 @@ sub is_me { my ($inet, $myIP, $str) = split(" ", $int); chomp $myIP; + $myIP =~ s/\/.*//; # ipv6 address 4000::99/64 + $myIP =~ s/\%.*//; # ipv6 address ::1%1/128 - # Split the two ip addresses up into octets - my ($a1, $a2, $a3, $a4) = split /\./, $myIP; - - if (($a1 == $b1) && ($a2 == $b2) && ($a3 == $b3) && ($a4 == $b4)) + if ($myIP eq $nameIP) { return 1; } diff --git a/perl-xCAT/xCAT/PPCmac.pm b/perl-xCAT/xCAT/PPCmac.pm index 1cab2d706..52dd773ff 100644 --- a/perl-xCAT/xCAT/PPCmac.pm +++ b/perl-xCAT/xCAT/PPCmac.pm @@ -96,7 +96,7 @@ sub parse_args { push @network, $_; } else { # get, check the node IP - $client_ip = inet_ntoa(inet_aton(@$node[0])); + $client_ip = xCAT::Utils->getipaddr(@$node[0]); chomp $client_ip; if ( $client_ip ) { $opt{C} = $client_ip; @@ -118,7 +118,7 @@ sub parse_args { # Service node is returned as hostname, Convert # hostname to IP #################################### - $server_ip = inet_ntoa(inet_aton($key)); + $server_ip = xCAT::Utils->getipaddr($key); chomp $server_ip; } else { #################################### @@ -139,7 +139,9 @@ sub parse_args { # Fulfill in the server network information for gateway resolving #################################################################### if ( exists($opt{S}) ) { - $server = gethostbyaddr( inet_aton($opt{S}), AF_INET ); + # why convert to hostname?? + #$server = gethostbyaddr( inet_aton($opt{S}), AF_INET ); + $server = $opt{S}; if ( $server ) { %server_nethash = xCAT::DBobjUtils->getNetwkInfo( [$server] ); } diff --git a/perl-xCAT/xCAT/PPCscan.pm b/perl-xCAT/xCAT/PPCscan.pm index e7df4fa15..73eed353d 100644 --- a/perl-xCAT/xCAT/PPCscan.pm +++ b/perl-xCAT/xCAT/PPCscan.pm @@ -107,7 +107,7 @@ sub getshorthost { my $ip = shift; - my $host = gethostbyaddr( inet_aton($ip), AF_INET ); + my $host = xCAT::Utils->gethostname($ip); if ( $host and !$! ) { ############################## # Get short-hostname