code drop: IPv6 support on Linux
git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/branches/2.8@15319 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
parent
b6d19b4c8e
commit
58e96b4a07
@ -1216,7 +1216,7 @@ routes => {
|
||||
routename => 'Name used to identify this route.',
|
||||
net => 'The network address.',
|
||||
mask => 'The network mask.',
|
||||
ifname => '(optional) The interface name of the management node facing the gateway.',
|
||||
ifname => 'The interface name that facing the gateway. It is optional for IPv4 routes, but it is required for IPv6 routes.',
|
||||
gateway => 'The gateway that routes the ip traffic from the mn to the nodes. It is usually a service node.',
|
||||
comments => 'Any user-written notes.',
|
||||
disable => "Set to 'yes' or '1' to comment out this row.",
|
||||
|
@ -405,6 +405,19 @@ sub process_makeroutes {
|
||||
my ($gw_name, $gw_ip)=xCAT::NetworkUtils->gethostnameandip($route_hash->{gateway});
|
||||
push(@sns, $gw_name);
|
||||
|
||||
if ($route_hash->{net} =~ /:/) {
|
||||
# Remove the subnet postfix like /64
|
||||
if ($route_hash->{net} =~ /\//) {
|
||||
$route_hash->{net} =~ s/\/.*$//;
|
||||
}
|
||||
# Remove the "/" from the ipv6 prefixlength
|
||||
if ($route_hash->{mask}) {
|
||||
if ($route_hash->{mask} =~ /\//) {
|
||||
$route_hash->{mask} =~ s/^\///;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($remote) { #to the nodes
|
||||
my $nodes_tmp=$route_hash->{nodes};
|
||||
#print "nodes=@$nodes_tmp, remote=$remote, delete=$delete\n";
|
||||
@ -414,7 +427,7 @@ sub process_makeroutes {
|
||||
{
|
||||
command => ["xdsh"],
|
||||
node => $nodes_tmp,
|
||||
arg => ["-e", "/$installdir/postscripts/routeop $op " . $route_hash->{net} . " " . $route_hash->{mask} . " $gw_ip"],
|
||||
arg => ["-e", "/$installdir/postscripts/routeop $op " . $route_hash->{net} . " " . $route_hash->{mask} . " $gw_ip" . " $route_hash->{ifname}"],
|
||||
_xcatpreprocessed => [1],
|
||||
},
|
||||
$sub_req, -1, 1);
|
||||
@ -505,46 +518,63 @@ sub route_exists {
|
||||
my $gw=shift;
|
||||
|
||||
my $islinux=xCAT::Utils->isLinux();
|
||||
my $result;
|
||||
$result=`netstat -nr|grep $net`;
|
||||
if ($? == 0) {
|
||||
if ($result) {
|
||||
my @b=split('\n', $result);
|
||||
foreach my $tmp (@b) {
|
||||
chomp($tmp);
|
||||
my @a=split(' ', $tmp);
|
||||
if ($islinux) { #Linux
|
||||
if (@a >= 3) {
|
||||
my $net1=$a[0];
|
||||
my $mask1=$a[2];
|
||||
my $gw1=$a[1];
|
||||
if (($net1 eq $net) && ($mask1 eq $mask) && (($gw1 eq $gw) || ($gw1 eq $gw_ip))) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else { #AIX
|
||||
if (@a >= 2) {
|
||||
my $tmp1=$a[0];
|
||||
my $gw1=$a[1];
|
||||
|
||||
#now convert $mask to bits
|
||||
$net =~ /([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)/;
|
||||
my $netnum = ($1<<24)+($2<<16)+($3<<8)+$4;
|
||||
my $bits=32;
|
||||
while (($netnum % 2) == 0) {
|
||||
$bits--;
|
||||
$netnum=$netnum>>1;
|
||||
}
|
||||
my $tmp2="$net/$bits";
|
||||
if (($tmp1 eq $tmp2) && (($gw1 eq $gw) || ($gw1 eq $gw_ip))) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
# ipv6 net
|
||||
if ($net =~ /:/) {
|
||||
if ($islinux) {
|
||||
my $result = `ip -6 route show $net/$mask`;
|
||||
# ip -6 route show will return nothing if the route does not exist
|
||||
if (!$result || ($? != 0))
|
||||
{
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
} else { # AIX
|
||||
# TODO
|
||||
}
|
||||
} else {
|
||||
my $result;
|
||||
$result=`netstat -nr|grep $net`;
|
||||
if ($? == 0) {
|
||||
if ($result) {
|
||||
my @b=split('\n', $result);
|
||||
foreach my $tmp (@b) {
|
||||
chomp($tmp);
|
||||
my @a=split(' ', $tmp);
|
||||
if ($islinux) { #Linux
|
||||
if (@a >= 3) {
|
||||
my $net1=$a[0];
|
||||
my $mask1=$a[2];
|
||||
my $gw1=$a[1];
|
||||
if (($net1 eq $net) && ($mask1 eq $mask) && (($gw1 eq $gw) || ($gw1 eq $gw_ip))) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else { #AIX
|
||||
if (@a >= 2) {
|
||||
my $tmp1=$a[0];
|
||||
my $gw1=$a[1];
|
||||
|
||||
#now convert $mask to bits
|
||||
$net =~ /([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)/;
|
||||
my $netnum = ($1<<24)+($2<<16)+($3<<8)+$4;
|
||||
my $bits=32;
|
||||
while (($netnum % 2) == 0) {
|
||||
$bits--;
|
||||
$netnum=$netnum>>1;
|
||||
}
|
||||
my $tmp2="$net/$bits";
|
||||
if (($tmp1 eq $tmp2) && (($gw1 eq $gw) || ($gw1 eq $gw_ip))) {
|
||||
return 1;
|
||||
}
|
||||
} # end if (@a >= 2)
|
||||
} #end else linux/aix
|
||||
} # end foreach
|
||||
} # end if ($result)
|
||||
} # end if ($? == 0
|
||||
} # end else ipv4/ipv6
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -564,12 +594,21 @@ sub set_route {
|
||||
my $result;
|
||||
if (!route_exists($net, $mask, $gw_ip, $gw)) {
|
||||
#set temporay route
|
||||
my $cmd;
|
||||
if (xCAT::Utils->isLinux()) {
|
||||
$cmd="route add -net $net netmask $mask gw $gw_ip";
|
||||
} else {
|
||||
$cmd="route add -net $net -netmask $mask $gw_ip";
|
||||
}
|
||||
my $cmd;
|
||||
# ipv6 network
|
||||
if ($net =~ /:/) {
|
||||
if (xCAT::Utils->isLinux()) {
|
||||
$cmd="ip -6 route add $net/$mask via $gw_ip";
|
||||
} else {
|
||||
# AIX TODO
|
||||
}
|
||||
} else {
|
||||
if (xCAT::Utils->isLinux()) {
|
||||
$cmd="route add -net $net netmask $mask gw $gw_ip";
|
||||
} else {
|
||||
$cmd="route add -net $net -netmask $mask $gw_ip";
|
||||
}
|
||||
}
|
||||
#print "cmd=$cmd\n";
|
||||
my $rsp={};
|
||||
$rsp->{data}->[0]= "$host: Adding temporary route: $cmd";
|
||||
@ -642,15 +681,23 @@ sub delete_route {
|
||||
my $result;
|
||||
if (route_exists($net, $mask, $gw_ip, $gw)) {
|
||||
#delete route temporarily
|
||||
my $cmd;
|
||||
if (xCAT::Utils->isLinux()) {
|
||||
$cmd="route delete -net $net netmask $mask gw $gw_ip";
|
||||
} else {
|
||||
$cmd="route delete -net $net -netmask $mask $gw_ip";
|
||||
}
|
||||
my $cmd;
|
||||
if ($net =~ /:/) {
|
||||
if (xCAT::Utils->isLinux()) {
|
||||
$cmd = "ip -6 route delete $net/$mask via $gw_ip";
|
||||
} else {
|
||||
# AIX TODO
|
||||
}
|
||||
} else {
|
||||
if (xCAT::Utils->isLinux()) {
|
||||
$cmd="route delete -net $net netmask $mask gw $gw_ip";
|
||||
} else {
|
||||
$cmd="route delete -net $net -netmask $mask $gw_ip";
|
||||
}
|
||||
}
|
||||
#print "cmd=$cmd\n";
|
||||
my $rsp={};
|
||||
$rsp->{data}->[0]= "$host: Removin the temporary route: $cmd";
|
||||
$rsp->{data}->[0]= "$host: Removing the temporary route: $cmd";
|
||||
$callback->($rsp);
|
||||
|
||||
$result=`$cmd 2>&1`;
|
||||
@ -661,7 +708,11 @@ sub delete_route {
|
||||
}
|
||||
} else {
|
||||
my $rsp={};
|
||||
$rsp->{data}->[0]= "$host: The temporary route does not exist for $net.";
|
||||
if ($net =~ /:/) {
|
||||
$rsp->{data}->[0]= "$host: The temporary route does not exist for $net/$mask.";
|
||||
} else {
|
||||
$rsp->{data}->[0]= "$host: The temporary route does not exist for $net.";
|
||||
}
|
||||
$callback->($rsp);
|
||||
|
||||
}
|
||||
@ -793,7 +844,12 @@ sub addPersistentRoute_Sles {
|
||||
$hasConfiged=checkConfig_Sles($net, $mask, $gw_ip, $gw, \@output);
|
||||
}
|
||||
#print "hasConfiged=$hasConfiged\n";
|
||||
my $new_config="$net $gw_ip $mask $ifname\n";
|
||||
my $new_config;
|
||||
if ($net =~ /:/) {
|
||||
$new_config = "$net/$mask $gw_ip - -\n";
|
||||
} else {
|
||||
$new_config="$net $gw_ip $mask $ifname\n";
|
||||
}
|
||||
if (!$hasConfiged) {
|
||||
push(@output, $new_config);
|
||||
#print "new output=" . join("\n", @output) . "\n";
|
||||
@ -842,11 +898,19 @@ sub deletePersistentRoute_Sles {
|
||||
setConfig($filename, \@new_output);
|
||||
if ($bigfound) {
|
||||
my $rsp={};
|
||||
$rsp->{data}->[0]= "$host: Removed persistent route \"$net $gw_ip $mask $ifname\" from $filename.";
|
||||
if ($net =~ /:/) {
|
||||
$rsp->{data}->[0]= "$host: Removed persistent route \"$net/$mask $gw_ip\" from $filename.";
|
||||
} else {
|
||||
$rsp->{data}->[0]= "$host: Removed persistent route \"$net $gw_ip $mask $ifname\" from $filename.";
|
||||
}
|
||||
$callback->($rsp);
|
||||
} else {
|
||||
my $rsp={};
|
||||
$rsp->{data}->[0]= "$host: Persistent route \"$net $gw_ip $mask $ifname\" does not exist in $filename.";
|
||||
if ($net =~ /:/) {
|
||||
$rsp->{data}->[0]= "$host: Persistent route \"$net/$mask $gw_ip\" does not exist in $filename.";
|
||||
} else {
|
||||
$rsp->{data}->[0]= "$host: Persistent route \"$net $gw_ip $mask $ifname\" does not exist in $filename.";
|
||||
}
|
||||
$callback->($rsp);
|
||||
}
|
||||
}
|
||||
@ -861,21 +925,35 @@ sub checkConfig_Sles {
|
||||
my $gw=shift;
|
||||
my $output=shift;
|
||||
|
||||
# ipv4 format: 192.168.0.0 207.68.156.51 255.255.0.0 eth1
|
||||
# ipv6 format: fd59::/64 fd57:faaf:e1ab:336:21a:64ff:fe01:1 - -
|
||||
foreach my $line (@$output) {
|
||||
my @a=split(' ', $line);
|
||||
my ($net1,$mask1,$gw1);
|
||||
if (@a>0) {
|
||||
$net1=$a[0];
|
||||
if ($net1 eq '-') { $net1=$net;}
|
||||
}
|
||||
if (@a>1) {
|
||||
$gw1=$a[1];
|
||||
if ($gw1 eq '-') { $gw1=$gw_ip; }
|
||||
}
|
||||
if (@a>2) {
|
||||
$mask1=$a[2];
|
||||
if ($mask1 eq '-') { $mask1=$mask;}
|
||||
}
|
||||
if ($net =~ /:/) {
|
||||
if (@a>0) {
|
||||
my $ipv6net = $a[0];
|
||||
($net1,$mask1) = split("/",$ipv6net);
|
||||
}
|
||||
if (@a>1) {
|
||||
$gw1=$a[1];
|
||||
if ($gw1 eq '-') { $gw1=$gw_ip; }
|
||||
}
|
||||
|
||||
} else {
|
||||
if (@a>0) {
|
||||
$net1=$a[0];
|
||||
if ($net1 eq '-') { $net1=$net;}
|
||||
}
|
||||
if (@a>1) {
|
||||
$gw1=$a[1];
|
||||
if ($gw1 eq '-') { $gw1=$gw_ip; }
|
||||
}
|
||||
if (@a>2) {
|
||||
$mask1=$a[2];
|
||||
if ($mask1 eq '-') { $mask1=$mask;}
|
||||
}
|
||||
}
|
||||
|
||||
#print "net=$net1,$net mask=$mask1,$mask gw=$gw1,$gw_ip\n";
|
||||
if (($net1 && $net1 eq $net) && ($mask1 && $mask1 eq $mask) && (($gw1 && $gw1 eq $gw) || ($gw1 && $gw1 eq $gw_ip))) {
|
||||
@ -897,7 +975,13 @@ sub addPersistentRoute_RH {
|
||||
|
||||
my $host=hostname();
|
||||
|
||||
my $filename="/etc/sysconfig/static-routes";
|
||||
my $filename;
|
||||
# ipv6
|
||||
if ($net =~ /:/) {
|
||||
$filename="/etc/sysconfig/static-routes-ipv6";
|
||||
} else {
|
||||
$filename="/etc/sysconfig/static-routes";
|
||||
}
|
||||
my @output=getConfig($filename);
|
||||
#print "old output=" . join("\n", @output) . "\n";
|
||||
my $hasConfiged=0;
|
||||
@ -905,7 +989,20 @@ sub addPersistentRoute_RH {
|
||||
$hasConfiged=checkConfig_RH($net, $mask, $gw_ip, $gw, \@output);
|
||||
}
|
||||
#print "hasConfiged=$hasConfiged\n";
|
||||
my $new_config="any net $net netmask $mask gw $gw_ip $ifname\n";
|
||||
my $new_config;
|
||||
if ($net =~ /:/) {
|
||||
# ifname is required for ipv6 routing
|
||||
if (!$ifname) {
|
||||
my $rsp={};
|
||||
$rsp->{data}->[0]= "$host: Could not add persistent route for ipv6 network $net/$mask, the ifname is required in the routes table.";
|
||||
$callback->($rsp);
|
||||
return;
|
||||
}
|
||||
|
||||
$new_config="$ifname $net/$mask $gw_ip";
|
||||
} else {
|
||||
$new_config="any net $net netmask $mask gw $gw_ip $ifname\n";
|
||||
}
|
||||
if (!$hasConfiged) {
|
||||
push(@output, $new_config);
|
||||
#print "new output=" . join("\n", @output) . "\n";
|
||||
@ -936,7 +1033,13 @@ sub deletePersistentRoute_RH {
|
||||
|
||||
my $host=hostname();
|
||||
|
||||
my $filename="/etc/sysconfig/static-routes";
|
||||
my $filename;
|
||||
# ipv6
|
||||
if ($net =~ /:/) {
|
||||
$filename="/etc/sysconfig/static-routes-ipv6";
|
||||
} else {
|
||||
$filename="/etc/sysconfig/static-routes";
|
||||
}
|
||||
my @output=getConfig($filename);
|
||||
#print "old output=" . join("\n", @output) . "\n";
|
||||
my @new_output=();
|
||||
@ -954,11 +1057,19 @@ sub deletePersistentRoute_RH {
|
||||
setConfig($filename, \@new_output);
|
||||
if ($bigfound) {
|
||||
my $rsp={};
|
||||
$rsp->{data}->[0]= "$host: Removed persistent route \"any net $net netmask $mask gw $gw_ip $ifname\" from $filename.";
|
||||
if ($net =~ /:/) {
|
||||
$rsp->{data}->[0]= "$host: Removed persistent route \"$ifname $net/$mask $gw_ip\" from $filename.";
|
||||
} else {
|
||||
$rsp->{data}->[0]= "$host: Removed persistent route \"any net $net netmask $mask gw $gw_ip $ifname\" from $filename.";
|
||||
}
|
||||
$callback->($rsp);
|
||||
} else {
|
||||
my $rsp={};
|
||||
$rsp->{data}->[0]= "$host: Persistent route \"any net $net netmask $mask gw $gw_ip $ifname\" does not exist in $filename.";
|
||||
if ($net =~ /:/) {
|
||||
$rsp->{data}->[0]= "$host: Persistent route \"$ifname $net/$mask $gw_ip\" does not exist in $filename.";
|
||||
} else {
|
||||
$rsp->{data}->[0]= "$host: Persistent route \"any net $net netmask $mask gw $gw_ip $ifname\" does not exist in $filename.";
|
||||
}
|
||||
$callback->($rsp);
|
||||
}
|
||||
}
|
||||
@ -972,20 +1083,31 @@ sub checkConfig_RH {
|
||||
|
||||
foreach my $line (@$output) {
|
||||
my @a=split(' ', $line);
|
||||
#The format is: any net 172.16.0.0 netmask 255.240.0.0 gw 192.168.0.1 eth0
|
||||
#The format is: any net 172.16.0.0 netmask 255.240.0.0 gw 192.168.0.1 eth0
|
||||
# ipv6 format: eth1 fd60::/64 fd57::214:5eff:fe15:1
|
||||
my ($net1,$mask1,$gw1);
|
||||
if (@a>2) {
|
||||
$net1=$a[2];
|
||||
if ($net1 eq '-') { $net1=$net;}
|
||||
}
|
||||
if (@a>4) {
|
||||
$mask1=$a[4];
|
||||
if ($mask1 eq '-') { $mask1=$mask;}
|
||||
}
|
||||
if (@a>6) {
|
||||
$gw1=$a[6];
|
||||
if ($gw1 eq '-') { $gw1=$gw_ip; }
|
||||
}
|
||||
if ($net =~ /:/) {
|
||||
if (@a>1) {
|
||||
my $ipv6net = $a[1];
|
||||
($net1,$mask1) = split("/",$ipv6net);
|
||||
}
|
||||
if (@a>2) {
|
||||
$gw1 = $a[2];
|
||||
}
|
||||
} else {
|
||||
if (@a>2) {
|
||||
$net1=$a[2];
|
||||
if ($net1 eq '-') { $net1=$net;}
|
||||
}
|
||||
if (@a>4) {
|
||||
$mask1=$a[4];
|
||||
if ($mask1 eq '-') { $mask1=$mask;}
|
||||
}
|
||||
if (@a>6) {
|
||||
$gw1=$a[6];
|
||||
if ($gw1 eq '-') { $gw1=$gw_ip; }
|
||||
}
|
||||
}
|
||||
|
||||
#print "net=$net1,$net mask=$mask1,$mask gw=$gw1,$gw_ip\n";
|
||||
if (($net1 && $net1 eq $net) && ($mask1 && $mask1 eq $mask) && (($gw1 && $gw1 eq $gw) || ($gw1 && $gw1 eq $gw_ip))) {
|
||||
|
@ -28,10 +28,16 @@ my $netmask ='';
|
||||
my $ipaddr = '';
|
||||
my $nic_num = '';
|
||||
my $subnet = '';
|
||||
my $gateway = ''; # this is only used for ipv6, ipv4 gateway is assigned by dhcp
|
||||
my $ipv4nic = 0;
|
||||
my $nic_net = '';
|
||||
my $net_name = '';
|
||||
my @nic_nets = (); # array of networks for this nic
|
||||
my @nic_ips =(); # array of ipaddresses for this nic
|
||||
my @nic_nets_all = (); # array of all networks for this nic
|
||||
my @nic_nets4 = (); # array of ipv4 networks for this nic
|
||||
my @nic_nets6 = (); # array of ipv6 networks for this nic
|
||||
my @nic_ips_all =(); # array of all ip addresses for this nic
|
||||
my @nic_ips4 =(); # array of ipv4 addresses for this nic
|
||||
my @nic_ips6 =(); # array of ipv6 addresses for this nic
|
||||
my @networks = (); # array of all networks from networks table.
|
||||
# { network_name, subnet, netmask }
|
||||
|
||||
@ -52,7 +58,9 @@ while ( $cnt <= $net_cnt ) {
|
||||
$subnet = $1;
|
||||
$net_info =~ /mask=([^\|]*)\|\|/;
|
||||
$netmask = $1;
|
||||
push @{ $networks[$cnt-1] }, ($net_name, $subnet, $netmask);
|
||||
$net_info =~ /gateway=([^\|]*)\|\|/;
|
||||
$gateway = $1;
|
||||
push @{ $networks[$cnt-1] }, ($net_name, $subnet, $netmask, $gateway);
|
||||
$cnt +=1;
|
||||
}
|
||||
|
||||
@ -67,11 +75,35 @@ foreach my $nic_networks (split(/,/,$nicnetworks)) {
|
||||
@net = split(/:/,$nic_networks);
|
||||
}
|
||||
if ($net[0] eq $nic) {
|
||||
@nic_nets = split(/\|/,$net[1]);
|
||||
@nic_nets_all = split(/\|/,$net[1]);
|
||||
last;
|
||||
}
|
||||
}
|
||||
|
||||
# Put all ipv4 nets into nic_nets4,
|
||||
# put all ipv6 nets into nic_nets6.
|
||||
my $i = 0;
|
||||
for ($i=0; $i < (scalar @nic_nets_all) ; $i++ ) {
|
||||
# The network name itself does not indicate ipv4 or ipv6
|
||||
# should use the subnet to determine.
|
||||
# Do not use foreach (@networks), needs to keep the order of nets and ips
|
||||
my $net = $nic_nets_all[$i];
|
||||
foreach my $netinfo (@networks)
|
||||
{
|
||||
if ($netinfo->[0] eq $net)
|
||||
{
|
||||
if ($netinfo->[1] =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/)
|
||||
{
|
||||
push @nic_nets4, $net;
|
||||
} elsif ($netinfo->[1] =~ /:/) {
|
||||
push @nic_nets6, $net;
|
||||
} else {
|
||||
system("logger -t xcat -p local4.err 'The subnet $net is not valid.'");
|
||||
}
|
||||
last;
|
||||
}
|
||||
}
|
||||
}
|
||||
# get all nic ipaddress from $nicips: i.e. eth0:1.0.0.1|2.0.0.1,eth1:1.1.1.1
|
||||
# Then get all ips for this specific nic, i.e. eth0.
|
||||
foreach my $ips (split(/,/,$nicips)) {
|
||||
@ -82,12 +114,29 @@ foreach my $ips (split(/,/,$nicips)) {
|
||||
@ip = split(/:/,$ips);
|
||||
}
|
||||
if ($ip[0] eq $nic ) {
|
||||
@nic_ips = split(/\|/,$ip[1]);
|
||||
@nic_ips_all = split(/\|/,$ip[1]);
|
||||
}
|
||||
}
|
||||
|
||||
my $i;
|
||||
for ($i=0; $i < (scalar @nic_ips) ; $i++ ) {
|
||||
# Put all ipv4 addresses in @nic_ips4,
|
||||
# put all ipv6 addresses in @nic_ips6.
|
||||
# Do not use forach, needs to keep the order of networks and ips
|
||||
for ($i=0; $i < (scalar @nic_ips_all) ; $i++ ) {
|
||||
my $ip = $nic_ips_all[$i];
|
||||
# ipv4 address
|
||||
if ($ip =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/) {
|
||||
push @nic_ips4, $ip;
|
||||
} elsif ($ip =~ /:/) { # ipv6
|
||||
push @nic_ips6, $ip;
|
||||
} else {
|
||||
system("logger -t xcat -p local4.err 'configeth: The ip address $ip is not valid.'");
|
||||
}
|
||||
}
|
||||
|
||||
for ($i=0; $i < (scalar @nic_ips4) ; $i++ ) {
|
||||
|
||||
# ipv6 configuration needs to know if this nic as ipv4 configured
|
||||
$ipv4nic = 1;
|
||||
|
||||
# Time to create the interfaces.
|
||||
# loop through the nic networks, find the matching networks to get the
|
||||
@ -103,7 +152,7 @@ for ($i=0; $i < (scalar @nic_ips) ; $i++ ) {
|
||||
$netmask = "";
|
||||
$net_name = "";
|
||||
while ( $cnt < $net_cnt ) {
|
||||
if ( $networks[$cnt][0] eq $nic_nets[$i] ) {
|
||||
if ( $networks[$cnt][0] eq $nic_nets4[$i] ) {
|
||||
|
||||
$subnet = $networks[$cnt][1];
|
||||
$netmask = $networks[$cnt][2];
|
||||
@ -122,14 +171,14 @@ for ($i=0; $i < (scalar @nic_ips) ; $i++ ) {
|
||||
|
||||
if ($^O =~ /^aix/i) {
|
||||
if ($i == 0) {
|
||||
if ($nic_ips[$i] =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/) {
|
||||
runcmd("chdev -l '$nic' -a netaddr=$nic_ips[$i] -a netmask=$netmask -a state='up'");
|
||||
if ($nic_ips4[$i] =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/) {
|
||||
runcmd("chdev -l '$nic' -a netaddr=$nic_ips4[$i] -a netmask=$netmask -a state='up'");
|
||||
# } else { #ipv6
|
||||
# runcmd("autoconf6 -6i en$nic_num");
|
||||
}
|
||||
} else {
|
||||
if ($nic_ips[$i] =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/) {
|
||||
runcmd("chdev -l '$nic' -a alias4=$nic_ips[$i],$netmask");
|
||||
if ($nic_ips4[$i] =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/) {
|
||||
runcmd("chdev -l '$nic' -a alias4=$nic_ips4[$i],$netmask");
|
||||
# } else { #ipv6
|
||||
# runcmd("autoconf6 -6i en$nic_num");
|
||||
}
|
||||
@ -147,7 +196,7 @@ for ($i=0; $i < (scalar @nic_ips) ; $i++ ) {
|
||||
print FILE "BOOTPROTO=\'static\'\n";
|
||||
print FILE "BROADCAST=\'\'\n";
|
||||
print FILE "ETHTOOL_OPTIONS=\'\'\n";
|
||||
print FILE "IPADDR=\'".$nic_ips[$i]."\'\n";
|
||||
print FILE "IPADDR=\'".$nic_ips4[$i]."\'\n";
|
||||
print FILE "MTU=\'\'\n";
|
||||
print FILE "NAME=\'\'\n";
|
||||
print FILE "NETMASK=\'".$netmask."\'\n";
|
||||
@ -163,7 +212,7 @@ for ($i=0; $i < (scalar @nic_ips) ; $i++ ) {
|
||||
# open ifconfig-eth file and append additional info.
|
||||
if (!open(FILE, ">>$dir/ifcfg-$nic")) { system("logger -t xcat -p local4.err 'configeth: cannot open $dir/ifcfg-$nic for appending ip alias info'"); exit 1; }
|
||||
|
||||
print FILE "IPADDR_$i=\'".$nic_ips[$i]."\'\n";
|
||||
print FILE "IPADDR_$i=\'".$nic_ips4[$i]."\'\n";
|
||||
print FILE "NETMASK_$i=\'".$netmask."\'\n";
|
||||
print FILE "NETWORK_$i=\'".$subnet."\'\n";
|
||||
print FILE "LABEL_$i=\'".$i."\'\n";
|
||||
@ -177,7 +226,7 @@ for ($i=0; $i < (scalar @nic_ips) ; $i++ ) {
|
||||
if (!open(FILE, ">$dir/ifcfg-$specific_nic")) { system("logger -t xcat -p local4.err 'configeth: cannot open $dir/ifcfg-$specific_nic.'"); exit 1; }
|
||||
print FILE "DEVICE=$specific_nic\n";
|
||||
print FILE "BOOTPROTO=none\n";
|
||||
print FILE "IPADDR=$nic_ips[$i]\n";
|
||||
print FILE "IPADDR=$nic_ips4[$i]\n";
|
||||
print FILE "NETMASK=$netmask\n";
|
||||
#if (defined($gateway)) { print FILE "GATEWAY=$gateway\n"; }
|
||||
print FILE "ONBOOT=yes\n";
|
||||
@ -187,6 +236,123 @@ for ($i=0; $i < (scalar @nic_ips) ; $i++ ) {
|
||||
}
|
||||
# system("logger -t xcat -p local4.info 'configeth: successfully configured $specific_nic.'");
|
||||
}
|
||||
|
||||
|
||||
# ipv6 configuration
|
||||
# ipv6 address does not use the nic alias like eth0:1,
|
||||
# should use the main nic like eth0
|
||||
my $configured = 0;
|
||||
for ($i=0; $i < (scalar @nic_ips6) ; $i++ )
|
||||
{
|
||||
# Get the network information: netname, subnet, netmask
|
||||
my $found = 0;
|
||||
my $subnet;
|
||||
my $prefixlen;
|
||||
my $ipv6gateway;
|
||||
my $ip6addr = $nic_ips6[$i];
|
||||
my $net = $nic_nets6[$i];
|
||||
foreach my $netinfo (@networks)
|
||||
{
|
||||
if ($netinfo->[0] eq $net)
|
||||
{
|
||||
$found = 1;
|
||||
$subnet = $netinfo->[1];
|
||||
$prefixlen = $netinfo->[2];
|
||||
$ipv6gateway = $netinfo->[3];
|
||||
}
|
||||
# Remove the postfix like /64 from subnet
|
||||
if ($subnet && ($subnet =~ /\//)) {
|
||||
$subnet =~ s/\/.*$//;
|
||||
}
|
||||
|
||||
# Remove the "/" from prefixlen
|
||||
if ($prefixlen && ($prefixlen =~ /^\//))
|
||||
{
|
||||
$prefixlen =~ s/^\///;
|
||||
}
|
||||
}
|
||||
if ($found == 0)
|
||||
{
|
||||
system("logger -t xcat -p local4.err 'configeth: Could not find network entry for ip address $ip6addr'");
|
||||
next;
|
||||
}
|
||||
|
||||
if ($^O =~ /^aix/i) {
|
||||
if (!$configured)
|
||||
{
|
||||
runcmd("chdev -l en0 -a netaddr6=$ip6addr -a prefixlen=$prefixlen -a state=up");
|
||||
$configured = 1;
|
||||
} else {
|
||||
runcmd("chdev -l en0 -a alias6=$ip6addr/$prefixlen");
|
||||
}
|
||||
} elsif (($ENV{OSVER} && ($ENV{OSVER} =~ /sles|suse/i)) || (-f "/etc/SuSE-release")) {
|
||||
my $dir = "/etc/sysconfig/network";
|
||||
# If there are only ipv6 addresses on this nic,
|
||||
# needs to flush the ifcfg-$nic file when configuring the first ipv6 addr,
|
||||
# to avoid duplicate entries when run confignics/configeth multiple times.
|
||||
if (!$ipv4nic && !$configured)
|
||||
{
|
||||
if (!open(FILE, ">$dir/ifcfg-$nic")) {
|
||||
system("logger -t xcat -p local4.err 'configeth: cannot open $dir/ifcfg-$nic.'");
|
||||
exit 1;
|
||||
}
|
||||
print FILE "DEVICE=$nic\n";
|
||||
print FILE "BOOTPROTO=static\n";
|
||||
print FILE "STARTMODE=onboot\n";
|
||||
} else {
|
||||
if (!open(FILE, ">>$dir/ifcfg-$nic")) {
|
||||
system("logger -t xcat -p local4.err 'configeth: cannot open $dir/ifcfg-$nic.'");
|
||||
exit 1;
|
||||
}
|
||||
}
|
||||
# Use the label=ipv6$i in ifcfg-ethx file, like ipv60, ipv61
|
||||
print FILE "LABEL_ipv6$i=ipv6$i\n";
|
||||
print FILE "IPADDR_ipv6$i=$ip6addr\n";
|
||||
print FILE "PREFIXLEN_ipv6$i=$prefixlen\n";
|
||||
close FILE;
|
||||
if ($ipv6gateway && $ipv6gateway !~ /xcatmaster/) {
|
||||
# Do not add duplicate entries
|
||||
`grep -E "default\\s+$ipv6gateway\\s+" /etc/sysconfig/network/routes 2>&1 1>/dev/null`;
|
||||
if ($? != 0) {
|
||||
`echo "default $ipv6gateway - -" >> /etc/sysconfig/network/routes`;
|
||||
}
|
||||
}
|
||||
runcmd("ifup $nic");
|
||||
} else {
|
||||
# Ubuntu TODO
|
||||
my $dir = "/etc/sysconfig/network-scripts";
|
||||
# If there are only ipv6 addresses on this nic,
|
||||
# needs to flush the ifcfg-$nic file when configuring the first ipv6 addr,
|
||||
# to avoid duplicate entries when run confignics/configeth multiple times.
|
||||
if (!$ipv4nic && !$configured)
|
||||
{
|
||||
if (!open(FILE, ">$dir/ifcfg-$nic")) {
|
||||
system("logger -t xcat -p local4.err 'configeth: cannot open $dir/ifcfg-$nic.'");
|
||||
exit 1;
|
||||
}
|
||||
print FILE "DEVICE=$nic\n";
|
||||
print FILE "BOOTPROTO=static\n";
|
||||
print FILE "ONBOOT=yes\n";
|
||||
} else {
|
||||
if (!open(FILE, ">>$dir/ifcfg-$nic")) {
|
||||
system("logger -t xcat -p local4.err 'configeth: cannot open $dir/ifcfg-$nic.'");
|
||||
exit 1;
|
||||
}
|
||||
}
|
||||
if (!$configured) {
|
||||
print FILE "IPV6INIT=yes\n";
|
||||
print FILE "IPV6ADDR=$ip6addr/$prefixlen\n";
|
||||
$configured = 1;
|
||||
} else {
|
||||
print FILE "IPV6ADDR_SECONDARIES=$ip6addr/$prefixlen\n";
|
||||
}
|
||||
if ($ipv6gateway && $ipv6gateway !~ /xcatmaster/) {
|
||||
print FILE "IPV6_DEFAULTGW=$ipv6gateway\n";
|
||||
}
|
||||
close FILE;
|
||||
runcmd("$dir/ifup-ipv6 $nic");
|
||||
}
|
||||
}
|
||||
exit 0;
|
||||
|
||||
sub runcmd {
|
||||
@ -197,7 +363,7 @@ sub runcmd {
|
||||
if ($rc) {
|
||||
system("logger -t xcat -p local4.err 'configeth: command $cmd failed with rc $rc: " . join('',@output) . "'");
|
||||
my $errout= "configeth: command $cmd failed with rc $rc.";
|
||||
echo $errout;
|
||||
`echo $errout`;
|
||||
exit $rc;
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
# IBM(c) 2013 EPL license http://www.eclipse.org/legal/epl-v10.html
|
||||
|
||||
# xCAT post script for configuring ib adaptors.
|
||||
# Work for both IPv4 and IPv6
|
||||
# The following are a sample of the env used:
|
||||
# NIC_IBNICS=ib0,ib1
|
||||
# NIC_IBAPORTS=1 (or 2)
|
||||
@ -74,7 +75,7 @@ then
|
||||
if [ $? -eq 1 ]
|
||||
then
|
||||
echo "Not found the driver dameon: rdma or openibd"
|
||||
logger -p local4.info -t xcat "Not found the driver dameon: rdma or openibd"
|
||||
logger -p local4.info -t xcat "Not found the driver dameon: rdma or openibd"
|
||||
exit
|
||||
fi
|
||||
fi
|
||||
@ -95,12 +96,12 @@ then
|
||||
|
||||
if [ -f "/etc/modprobe.conf" ]
|
||||
then
|
||||
if [ "$portnum" == "1" ]; then
|
||||
if [ "$portnum" == "1" ]; then
|
||||
sed -i "/options ib_ehca nr_ports/d" /etc/modprobe.conf
|
||||
echo 'options ib_ehca nr_ports=1' >> /etc/modprobe.conf
|
||||
else
|
||||
else
|
||||
sed -i "/options ib_ehca nr_ports=1/d" /etc/modprobe.conf
|
||||
fi
|
||||
fi
|
||||
sed -i "/options ib_ehca lock_hcalls/d" /etc/modprobe.conf
|
||||
echo 'options ib_ehca lock_hcalls=0' >> /etc/modprobe.conf
|
||||
fi
|
||||
@ -120,7 +121,7 @@ then
|
||||
OS_name="suse"
|
||||
else
|
||||
echo "Unsupported to config IB on this OS!"
|
||||
logger -p local4.info -t xcat "Unsupported to config IB on this OS!"
|
||||
logger -p local4.info -t xcat "Unsupported to config IB on this OS!"
|
||||
exit
|
||||
fi
|
||||
|
||||
@ -132,12 +133,14 @@ then
|
||||
fi
|
||||
for nic in `echo "$NIC_IBNICS" | tr "," "\n"`
|
||||
do
|
||||
`rm -f $dir/ifcfg-$nic`
|
||||
`rm -f $dir/ifcfg-$nic` 2>&1 1>/dev/null
|
||||
# nic aliases
|
||||
`rm -f $dir/ifcfg-$nic:*` 2>&1 1>/dev/null
|
||||
done
|
||||
else
|
||||
for nic in `echo "$NIC_IBNICS" | tr "," "\n"`
|
||||
do
|
||||
`rmdev -d -l $nic >/dev/null 2>&1`
|
||||
`rmdev -d -l $nic >/dev/null 2>&1`
|
||||
done
|
||||
fi
|
||||
|
||||
@ -145,197 +148,290 @@ fi
|
||||
goodnics=""
|
||||
for nic in `echo "$NIC_IBNICS" | tr "," "\n"`
|
||||
do
|
||||
#Get nic ip
|
||||
nicip=""
|
||||
#Get nic ips
|
||||
nicips=""
|
||||
for tmp in `echo "$NICIPS" | tr "," "\n"`
|
||||
do
|
||||
nic_tmp=`echo "$tmp" | awk -F"!" '{print $1}'`;
|
||||
if [ $nic_tmp == $nic ]; then
|
||||
nicip=`echo "$tmp" | awk -F"!" '{print $2}'`;
|
||||
break
|
||||
fi
|
||||
nic_tmp=`echo "$tmp" | awk -F"!" '{print $1}'`;
|
||||
if [ $nic_tmp == $nic ]; then
|
||||
# nicips=ip1|ip2|ip3
|
||||
nicips=`echo "$tmp" | awk -F"!" '{print $2}'`;
|
||||
break
|
||||
fi
|
||||
done
|
||||
# echo "nic=$nic, nicip=$nicip"
|
||||
|
||||
#get nic network name
|
||||
nicnet=""
|
||||
#get nic networks name
|
||||
nicnets=""
|
||||
for tmp in `echo "$NICNETWORKS" | tr "," "\n"`
|
||||
do
|
||||
nic_tmp=`echo "$tmp" | awk -F"!" '{print $1}'`;
|
||||
if [ $nic_tmp == $nic ]; then
|
||||
nicnet=`echo "$tmp" | awk -F"!" '{print $2}'`;
|
||||
break
|
||||
# nicnets=net1|net2|net3
|
||||
nicnets=`echo "$tmp" | awk -F"!" '{print $2}'`;
|
||||
break
|
||||
fi
|
||||
done
|
||||
#echo "nic=$nic, nicnet=$nicnet"
|
||||
|
||||
if [ -z "$nicnet" ]; then
|
||||
if [ -z "$nicnets" ]; then
|
||||
echo "No network defined for $nic"
|
||||
logger -p local4.info -t xcat "No network defined for $nic"
|
||||
continue
|
||||
fi
|
||||
|
||||
#get netmask and gateway
|
||||
index=0;
|
||||
found=0
|
||||
while [ $index -lt $NETWORKS_LINES ]
|
||||
ipindex=0
|
||||
for nicip in `echo $nicips | tr "|" "\n"`
|
||||
do
|
||||
index=$((index+1))
|
||||
eval netline=\$NETWORKS_LINE$index
|
||||
if [[ -n "$netline" ]]; then
|
||||
for tmp in `echo "$netline" | tr "\|" "\n"`
|
||||
do
|
||||
key=`echo "$tmp" | awk -F"=" '{print $1}'`;
|
||||
case $key in
|
||||
netname)
|
||||
netname=`echo "$tmp" | awk -F"=" '{print $2}'`
|
||||
if [ "$netname" != "$nicnet" ];
|
||||
then
|
||||
break;
|
||||
fi
|
||||
;;
|
||||
net)
|
||||
net=`echo "$tmp" | awk -F"=" '{print $2}'`
|
||||
;;
|
||||
mask)
|
||||
netmask=`echo "$tmp" | awk -F"=" '{print $2}'`
|
||||
;;
|
||||
gateway)
|
||||
gateway=`echo "$tmp" | awk -F"=" '{print $2}'`
|
||||
found=1
|
||||
;;
|
||||
esac
|
||||
if [ $found -eq 1 ]; then
|
||||
break;
|
||||
fi
|
||||
done
|
||||
if [ $found -eq 1 ]; then
|
||||
break;
|
||||
fi
|
||||
fi
|
||||
done
|
||||
#echo "found=$found"
|
||||
#echo "index=$index netname=$nicnet net=$net mask=$netmask gateway=$gateway"
|
||||
ipindex=`expr $ipindex + 1`
|
||||
nicnet=`echo $nicnets | cut -d '|' -f$ipindex`
|
||||
|
||||
if [ "$found" == "0" ]; then
|
||||
echo "Cannot find network $nicnet for $nic"
|
||||
logger -p local4.info -t xcat "Cannot find network $nicnet for $nic"
|
||||
continue
|
||||
else
|
||||
if [ -z "$goodnics" ]; then
|
||||
goodnics=$nic
|
||||
#get netmask and gateway
|
||||
index=0;
|
||||
found=0
|
||||
while [ $index -lt $NETWORKS_LINES ]
|
||||
do
|
||||
index=$((index+1))
|
||||
eval netline=\$NETWORKS_LINE$index
|
||||
if [[ -n "$netline" ]]; then
|
||||
for tmp in `echo "$netline" | tr "\|" "\n"`
|
||||
do
|
||||
key=`echo "$tmp" | awk -F"=" '{print $1}'`;
|
||||
case $key in
|
||||
netname)
|
||||
netname=`echo "$tmp" | awk -F"=" '{print $2}'`
|
||||
if [ "$netname" != "$nicnet" ];
|
||||
then
|
||||
break;
|
||||
fi
|
||||
;;
|
||||
net)
|
||||
net=`echo "$tmp" | awk -F"=" '{print $2}'`
|
||||
;;
|
||||
mask)
|
||||
netmask=`echo "$tmp" | awk -F"=" '{print $2}'`
|
||||
# remove the prefix "/" from ipv6 mask
|
||||
if echo $netmask | grep "/" 2>&1 1>/dev/null
|
||||
then
|
||||
netmask=`echo $netmask | awk -F'/' '{print $2}'`
|
||||
fi
|
||||
;;
|
||||
gateway)
|
||||
gateway=`echo "$tmp" | awk -F"=" '{print $2}'`
|
||||
found=1
|
||||
;;
|
||||
esac
|
||||
if [ $found -eq 1 ]; then
|
||||
break;
|
||||
fi
|
||||
done # end for tmp in `echo "$netline" | tr "\|" "\n"`
|
||||
if [ $found -eq 1 ]; then
|
||||
break;
|
||||
fi
|
||||
fi # end if [[ -n "$netline" ]]
|
||||
done # end while [ $index -lt $NETWORKS_LINES ]
|
||||
|
||||
#echo "found=$found"
|
||||
#echo "index=$index netname=$nicnet net=$net mask=$netmask gateway=$gateway"
|
||||
|
||||
# Setup goodnics list
|
||||
if [ "$found" == "0" ]; then
|
||||
echo "Cannot find network $nicnet for $nic"
|
||||
logger -p local4.info -t xcat "Cannot find network $nicnet for $nic"
|
||||
continue
|
||||
else
|
||||
goodnics="$goodnics,$nic"
|
||||
if [ -z "$goodnics" ]; then
|
||||
goodnics=$nic
|
||||
else
|
||||
goodnics="$goodnics,$nic"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
#there should be only one gateway on a node and that should go through the to the xcat management node and would be set up from the install nic. Anything else should be a route
|
||||
if [ "$gateway" == "<xcatmaster>" ]; then
|
||||
gateway=''
|
||||
fi
|
||||
#there should be only one gateway on a node and that should go through the to the xcat management node and would be set up from the install nic. Anything else should be a route
|
||||
if [ "$gateway" == "<xcatmaster>" ]; then
|
||||
gateway=''
|
||||
fi
|
||||
|
||||
|
||||
if [ $PLTFRM == "Linux" ]
|
||||
then
|
||||
# Issue openibd for Linux at boot time
|
||||
|
||||
if [ -f /etc/sysctl.conf ]
|
||||
if [ $PLTFRM == "Linux" ]
|
||||
then
|
||||
sed -i "/net.ipv4.conf.$nic.arp_filter=1/d" /etc/sysctl.conf
|
||||
sed -i "/net.ipv4.conf.$nic.arp_ignore=1/d" /etc/sysctl.conf
|
||||
echo "net.ipv4.conf.$nic.arp_filter=1" >> /etc/sysctl.conf
|
||||
echo "net.ipv4.conf.$nic.arp_ignore=1" >> /etc/sysctl.conf
|
||||
fi
|
||||
# Issue openibd for Linux at boot time
|
||||
|
||||
# Write the info to the ifcfg file
|
||||
echo "DEVICE=$nic
|
||||
BOOTPROTO=static
|
||||
IPADDR=$nicip
|
||||
NETMASK=$netmask" > $dir/ifcfg-$nic
|
||||
if [ -n "$gateway" ]; then
|
||||
echo "GATEWAY=$gateway" >> $dir/ifcfg-$nic
|
||||
fi
|
||||
|
||||
if [[ "$OSVER" == rhels6* ]]
|
||||
then
|
||||
#get prefix from netmask, this is for IPv4 only
|
||||
prefix=24
|
||||
if [ -n "$netmask" ]; then
|
||||
prefix=$(convert_netmask_to_cidr $netmask)
|
||||
fi
|
||||
|
||||
echo "DEVICE=$nic
|
||||
BOOTPROTO=static
|
||||
IPADDR=$nicip
|
||||
PREFIX=$prefix" > $dir/ifcfg-$nic
|
||||
if [ -n "$gateway" ]; then
|
||||
echo "GATEWAY=$gateway" >> $dir/ifcfg-$nic
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ $OS_name == 'redhat' ]
|
||||
then
|
||||
echo "ONBOOT=yes" >> $dir/ifcfg-$nic
|
||||
else
|
||||
echo "STARTMODE=auto" >> $dir/ifcfg-$nic
|
||||
fi
|
||||
elif [ $PLTFRM == "AIX" ]; then
|
||||
if ( pmatch $nic "ml*" ); then #for ml* interface
|
||||
num=${nic##ml}
|
||||
mlt="mlt$num"
|
||||
#Check whether the mlt is available
|
||||
lsdev -C | grep $mlt | grep Available 2>&1 >/dev/null
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
echo "$mltnum is not available."
|
||||
logger -p local4.info -t xcat "$mltnum is not available."
|
||||
continue
|
||||
fi
|
||||
|
||||
#Check whether the ml0 is available
|
||||
lsdev -C | grep $nic 2>&1 >/dev/null
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
cfgmgr 2>&1 >/dev/null
|
||||
fi
|
||||
|
||||
chdev -l $nic -a state=detach 2>&1
|
||||
chdev -l $nic -a netaddr=$nicip -a netmask=$netmask -a state=up 2>&1
|
||||
else #assume it is ib*
|
||||
lsdev -C | grep icm | grep Available
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
mkdev -c management -s infiniband -t icm
|
||||
if [ -f /etc/sysctl.conf ]
|
||||
then
|
||||
sed -i "/net.ipv4.conf.$nic.arp_filter=1/d" /etc/sysctl.conf 2>&1 1>/dev/null
|
||||
sed -i "/net.ipv4.conf.$nic.arp_ignore=1/d" /etc/sysctl.conf 2>&1 1>/dev/null
|
||||
cfg="net.ipv4.conf.$nic.arp_filter=1"
|
||||
grep "$cfg" /etc/sysctl.conf 2>&1 1>/dev/null
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
mkdev -l icm
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
exit $?
|
||||
fi
|
||||
echo "net.ipv4.conf.$nic.arp_filter=1" >> /etc/sysctl.conf
|
||||
fi
|
||||
fi
|
||||
|
||||
#Configure the IB interfaces. Customize the port num.
|
||||
num=${nic##ib} #this assumes that all the nics starts with 'ib'
|
||||
if [ "$portnum" == "1" ]; then
|
||||
iba_num=$num
|
||||
ib_adapter="iba$iba_num"
|
||||
port=1
|
||||
else
|
||||
iba_num=`expr $num / 2`
|
||||
ib_adapter="iba$iba_num"
|
||||
if [ $(($num % 2)) == 0 ]
|
||||
then
|
||||
port=1
|
||||
else
|
||||
port=2
|
||||
fi
|
||||
fi
|
||||
mkiba -a $nicip -i $nic -A $ib_adapter -p $port -P -1 -S up -m $netmask
|
||||
fi
|
||||
fi
|
||||
done
|
||||
cfg="net.ipv4.conf.$nic.arp_ignore=1"
|
||||
grep "$cfg" /etc/sysctl.conf 2>&1 1>/dev/null
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
echo "net.ipv4.conf.$nic.arp_ignore=1" >> /etc/sysctl.conf
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ $OS_name == 'suse' ]
|
||||
then
|
||||
# First ip address
|
||||
if [ $ipindex -eq 1 ]
|
||||
then
|
||||
# Write the info to the ifcfg file
|
||||
echo "DEVICE=$nic
|
||||
BOOTPROTO=static
|
||||
STARTMODE=onboot
|
||||
IPADDR=$nicip" > $dir/ifcfg-$nic
|
||||
# ipv6
|
||||
if echo $nicip | grep : 2>&1 1>/dev/null
|
||||
then
|
||||
echo "PREFIXLEN=$netmask" >> $dir/ifcfg-$nic
|
||||
else
|
||||
echo "NETMASK=$netmask" >> $dir/ifcfg-$nic
|
||||
fi
|
||||
if [ -n "$gateway" ]; then
|
||||
echo "GATEWAY=$gateway" >> $dir/ifcfg-$nic
|
||||
fi
|
||||
else # not the first ip address
|
||||
echo "LABEL_$ipindex=$ipindex
|
||||
IPADDR_$ipindex=$nicip" >> $dir/ifcfg-$nic
|
||||
# ipv6
|
||||
if echo $nicip | grep : 2>&1 1>/dev/null
|
||||
then
|
||||
echo "PREFIXLEN_$ipindex=$netmask" >> $dir/ifcfg-$nic
|
||||
else
|
||||
echo "NETMASK_$ipindex=$netmask" >> $dir/ifcfg-$nic
|
||||
fi
|
||||
fi # end if [ $ipindex -eq 1 ]
|
||||
elif [ $OS_name == 'redhat' ]
|
||||
then
|
||||
# First ip address
|
||||
if [ $ipindex -eq 1 ]
|
||||
then
|
||||
# Write the info to the ifcfg file
|
||||
echo "DEVICE=$nic
|
||||
BOOTPROTO=static
|
||||
ONBOOT=yes
|
||||
IPADDR=$nicip" > $dir/ifcfg-$nic
|
||||
# ipv6
|
||||
if echo $nicip | grep : 2>&1 1>/dev/null
|
||||
then
|
||||
echo "PREFIXLEN=$netmask" >> $dir/ifcfg-$nic
|
||||
else
|
||||
if [[ "$OSVER" == rhels6* ]]
|
||||
then
|
||||
#get prefix from netmask, this is for IPv4 only
|
||||
prefix=24
|
||||
prefix=$(convert_netmask_to_cidr $netmask)
|
||||
echo "PREFIX=$prefix" >> $dir/ifcfg-$nic
|
||||
else
|
||||
echo "NETMASK=$netmask" >> $dir/ifcfg-$nic
|
||||
fi
|
||||
fi
|
||||
if [ -n "$gateway" ]; then
|
||||
echo "GATEWAY=$gateway" >> $dir/ifcfg-$nic
|
||||
fi
|
||||
else # not the first ip address
|
||||
# ipv6
|
||||
if echo $nicip | grep : 2>&1 1>/dev/null
|
||||
then
|
||||
grep "IPV6INIT" $dir/ifcfg-$nic 2>&1 1>/dev/null
|
||||
# The first ipv6 address
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
echo "IPV6INIT=yes
|
||||
IPV6ADDR=$nicip/$netmask" >> $dir/ifcfg-$nic
|
||||
else
|
||||
echo "IPV6ADDR_SECONDARIES=$nicip/$netmask" >> $dir/ifcfg-$nic
|
||||
fi
|
||||
else # ipv4 address
|
||||
echo "DEVICE=$nic:$ipindex
|
||||
BOOTPROTO=static
|
||||
ONBOOT=yes
|
||||
IPADDR=$nicip" > $dir/ifcfg-$nic:$ipindex
|
||||
if [[ "$OSVER" == rhels6* ]]
|
||||
then
|
||||
#get prefix from netmask, this is for IPv4 only
|
||||
prefix=24
|
||||
prefix=$(convert_netmask_to_cidr $netmask)
|
||||
echo "PREFIX=$prefix" >> $dir/ifcfg-$nic:$ipindex
|
||||
else
|
||||
echo "NETMASK=$netmask" >> $dir/ifcfg-$nic:$ipindex
|
||||
fi
|
||||
|
||||
if [ -n "$gateway" ]; then
|
||||
echo "GATEWAY=$gateway" >> $dir/ifcfg-$nic:$ipindex
|
||||
fi
|
||||
# need to run ifup eth1:1 for RedHat
|
||||
goodnics="$goodnics,$nic:$ipindex"
|
||||
fi
|
||||
fi # end not the first ip address
|
||||
else
|
||||
echo "Unsupported operating system"
|
||||
logger -p local4.err -t xcat "Unsupported operating system"
|
||||
fi
|
||||
|
||||
elif [ $PLTFRM == "AIX" ]; then
|
||||
if ( pmatch $nic "ml*" ); then #for ml* interface
|
||||
num=${nic##ml}
|
||||
mlt="mlt$num"
|
||||
#Check whether the mlt is available
|
||||
lsdev -C | grep $mlt | grep Available 2>&1 >/dev/null
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
echo "$mltnum is not available."
|
||||
logger -p local4.info -t xcat "$mltnum is not available."
|
||||
continue
|
||||
fi
|
||||
|
||||
#Check whether the ml0 is available
|
||||
lsdev -C | grep $nic 2>&1 >/dev/null
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
cfgmgr 2>&1 >/dev/null
|
||||
fi
|
||||
|
||||
chdev -l $nic -a state=detach 2>&1
|
||||
chdev -l $nic -a netaddr=$nicip -a netmask=$netmask -a state=up 2>&1
|
||||
else #assume it is ib*
|
||||
lsdev -C | grep icm | grep Available
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
mkdev -c management -s infiniband -t icm
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
mkdev -l icm
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
exit $?
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
#Configure the IB interfaces. Customize the port num.
|
||||
num=${nic##ib} #this assumes that all the nics starts with 'ib'
|
||||
if [ "$portnum" == "1" ]; then
|
||||
iba_num=$num
|
||||
ib_adapter="iba$iba_num"
|
||||
port=1
|
||||
else
|
||||
iba_num=`expr $num / 2`
|
||||
ib_adapter="iba$iba_num"
|
||||
if [ $(($num % 2)) == 0 ]
|
||||
then
|
||||
port=1
|
||||
else
|
||||
port=2
|
||||
fi
|
||||
fi
|
||||
mkiba -a $nicip -i $nic -A $ib_adapter -p $port -P -1 -S up -m $netmask
|
||||
fi # end assume it is ib*
|
||||
fi # end if AIX
|
||||
done # end for nicip
|
||||
done # end for nic
|
||||
|
||||
# echo "goodnics=$goodnics"
|
||||
# Bringup all the ib interfaces
|
||||
|
@ -33,43 +33,55 @@ route_exists()
|
||||
|
||||
os_type=$(uname -s)
|
||||
|
||||
result=`netstat -nr|grep $net`;
|
||||
if [ $? -eq 0 ] && [ -n "$result" ]; then
|
||||
for x in `echo "$result"|tr -s " " ","`
|
||||
do
|
||||
if [ "$os_type" = "Linux" ]; then
|
||||
net1=`echo $x|cut -d',' -f1`
|
||||
gw1=`echo $x|cut -d',' -f2`
|
||||
mask1=`echo $x|cut -d',' -f3`
|
||||
if [ "$net" = "$net1" ] && [ "$mask" = "$mask1" ] && [ "$gw" = "$gw1" ]; then
|
||||
ret=1
|
||||
break
|
||||
fi
|
||||
else
|
||||
tmp1=`echo $x|cut -d',' -f1`
|
||||
gw1=`echo $x|cut -d',' -f2`
|
||||
# ipv6
|
||||
if echo $net | grep : 2>&1 1>/dev/null
|
||||
then
|
||||
result=`ip -6 route show $net/$mask`
|
||||
if [ $? -ne 0 ] || [ -z "$result" ]
|
||||
then
|
||||
ret=0
|
||||
else
|
||||
ret=1
|
||||
fi
|
||||
else
|
||||
result=`netstat -nr|grep $net`;
|
||||
if [ $? -eq 0 ] && [ -n "$result" ]; then
|
||||
for x in `echo "$result"|tr -s " " ","`
|
||||
do
|
||||
if [ "$os_type" = "Linux" ]; then
|
||||
net1=`echo $x|cut -d',' -f1`
|
||||
gw1=`echo $x|cut -d',' -f2`
|
||||
mask1=`echo $x|cut -d',' -f3`
|
||||
if [ "$net" = "$net1" ] && [ "$mask" = "$mask1" ] && [ "$gw" = "$gw1" ]; then
|
||||
ret=1
|
||||
break
|
||||
fi
|
||||
else
|
||||
tmp1=`echo $x|cut -d',' -f1`
|
||||
gw1=`echo $x|cut -d',' -f2`
|
||||
|
||||
n1=`echo $net |cut -d'.' -f1`
|
||||
n2=`echo $net |cut -d'.' -f2`
|
||||
n3=`echo $net |cut -d'.' -f3`
|
||||
n4=`echo $net |cut -d'.' -f4`
|
||||
n1=`echo $net |cut -d'.' -f1`
|
||||
n2=`echo $net |cut -d'.' -f2`
|
||||
n3=`echo $net |cut -d'.' -f3`
|
||||
n4=`echo $net |cut -d'.' -f4`
|
||||
|
||||
netnum="$(( ($n1 << 24) + ($n2 << 16) + ($n3 << 8) + $n4 ))"
|
||||
bits=32
|
||||
while [ `expr $netnum % 2` -eq 0 ]
|
||||
do
|
||||
bits="$(( $bits - 1 ))"
|
||||
netnum="$(( $netnum >> 1 ))"
|
||||
done
|
||||
netnum="$(( ($n1 << 24) + ($n2 << 16) + ($n3 << 8) + $n4 ))"
|
||||
bits=32
|
||||
while [ `expr $netnum % 2` -eq 0 ]
|
||||
do
|
||||
bits="$(( $bits - 1 ))"
|
||||
netnum="$(( $netnum >> 1 ))"
|
||||
done
|
||||
|
||||
tmp2="$net/$bits";
|
||||
#echo "$tmp2=$tmp2"
|
||||
if [ "$tmp1" = "$tmp2" ] && [ "$gw" = "$gw1" ]; then
|
||||
ret=1
|
||||
break
|
||||
fi
|
||||
fi
|
||||
done
|
||||
tmp2="$net/$bits";
|
||||
#echo "$tmp2=$tmp2"
|
||||
if [ "$tmp1" = "$tmp2" ] && [ "$gw" = "$gw1" ]; then
|
||||
ret=1
|
||||
break
|
||||
fi
|
||||
fi
|
||||
done
|
||||
fi
|
||||
fi
|
||||
|
||||
echo $ret
|
||||
@ -101,18 +113,26 @@ add_persistent_route()
|
||||
case $OS_name in
|
||||
sles)
|
||||
#echo "sles"
|
||||
# ipv6 net
|
||||
filename="/etc/sysconfig/network/routes";
|
||||
route="$net $gw $mask $ifname";
|
||||
if echo $net | grep : 2>&1 1>/dev/null
|
||||
then
|
||||
route="$net/$mask $gw - -"
|
||||
route1="$net\/$mask $gw - -";
|
||||
else
|
||||
route="$net $gw $mask $ifname";
|
||||
route1="$net $gw $mask $ifname";
|
||||
fi
|
||||
if [ -f $filename ]; then
|
||||
grep "$route" $filename
|
||||
grep "$route" $filename 2>&1 1>/dev/null
|
||||
if [ $? -ne 0 ]; then #route does not exist
|
||||
grep "$xcat_config_start" $filename
|
||||
grep "$xcat_config_start" $filename 2>&1 1>/dev/null
|
||||
if [ $? -ne 0 ]; then #no xCAT section
|
||||
echo $xcat_config_start >> $filename
|
||||
echo $route >> $filename
|
||||
echo $xcat_config_end >> $filename
|
||||
else
|
||||
sed -i -e s/"$xcat_config_end"/"$route\n$xcat_config_end"/g $filename
|
||||
sed -i -e s/"$xcat_config_end"/"$route1\n$xcat_config_end"/g $filename
|
||||
fi
|
||||
echo "Persistent route \"$route\" added in $filename."
|
||||
else
|
||||
@ -132,31 +152,41 @@ add_persistent_route()
|
||||
;;
|
||||
redhat)
|
||||
#echo "rh/fedora/centos"
|
||||
filename="/etc/sysconfig/static-routes";
|
||||
route="any net $net netmask $mask gw $gw $ifname";
|
||||
# ipv6 net
|
||||
if echo $net | grep : 2>&1 1>/dev/null
|
||||
then
|
||||
filename="/etc/sysconfig/static-routes-ipv6";
|
||||
route="$ifname $net/$mask $gw";
|
||||
# $net/mask does not work with sed cmd
|
||||
route1="$ifname $net\/$mask $gw";
|
||||
else
|
||||
filename="/etc/sysconfig/static-routes";
|
||||
route="any net $net netmask $mask gw $gw $ifname";
|
||||
route1="any net $net netmask $mask gw $gw $ifname";
|
||||
fi
|
||||
if [ -f $filename ]; then
|
||||
grep "$route" $filename
|
||||
grep "$route" $filename 2>&1 1>/dev/null
|
||||
if [ $? -ne 0 ]; then #route does not exist
|
||||
grep "$xcat_config_start" $filename
|
||||
if [ $? -ne 0 ]; then #no xCAT section
|
||||
echo $xcat_config_start >> $filename
|
||||
echo $route >> $filename
|
||||
echo $xcat_config_end >> $filename
|
||||
else
|
||||
sed -i -e s/"$xcat_config_end"/"$route\n$xcat_config_end"/g $filename
|
||||
fi
|
||||
echo "Persistent route \"$route\" added in $filename."
|
||||
grep "$xcat_config_start" $filename 2>&1 1>/dev/null
|
||||
if [ $? -ne 0 ]; then #no xCAT section
|
||||
echo $xcat_config_start >> $filename
|
||||
echo $route >> $filename
|
||||
echo $xcat_config_end >> $filename
|
||||
else
|
||||
sed -i -e s/"$xcat_config_end"/"$route1\n$xcat_config_end"/g $filename
|
||||
fi
|
||||
echo "Persistent route \"$route\" added in $filename."
|
||||
else
|
||||
echo "Persistent route \"$route\" already exists in $filename."
|
||||
echo "Persistent route \"$route\" already exists in $filename."
|
||||
fi
|
||||
else
|
||||
#echo "got here"
|
||||
echo "$xcat_config_start" > $filename
|
||||
echo "$route" >> $filename
|
||||
echo "$xcat_config_end" >> $filename
|
||||
echo "Persistent route \"$route\" added in $filename."
|
||||
fi
|
||||
;;
|
||||
#echo "got here"
|
||||
echo "$xcat_config_start" > $filename
|
||||
echo "$route" >> $filename
|
||||
echo "$xcat_config_end" >> $filename
|
||||
echo "Persistent route \"$route\" added in $filename."
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
else #AIX
|
||||
echo "Adding persistent route on AIX is not supported yet."
|
||||
@ -187,9 +217,17 @@ rm_persistent_route()
|
||||
sles)
|
||||
#echo "sles"
|
||||
filename="/etc/sysconfig/network/routes";
|
||||
route="$net $gw $mask $ifname";
|
||||
# ipv6 net
|
||||
if echo $net | grep : 2>&1 1>/dev/null
|
||||
then
|
||||
route="$net/$mask $gw - -";
|
||||
route1="$net\/$mask $gw - -";
|
||||
else
|
||||
route="$net $gw $mask";
|
||||
route1="$net $gw $mask";
|
||||
fi
|
||||
if [ -f $filename ]; then
|
||||
sed -i -e s/"$route"//g $filename
|
||||
sed -i -e s/"$route1"//g $filename
|
||||
fi
|
||||
echo "Persistent route \"$route\" removed from $filename."
|
||||
;;
|
||||
@ -198,12 +236,22 @@ rm_persistent_route()
|
||||
;;
|
||||
redhat)
|
||||
#echo "rh/fedora/centos"
|
||||
filename="/etc/sysconfig/static-routes";
|
||||
route="any net $net netmask $mask gw $gw $ifname";
|
||||
#ipv6
|
||||
if echo $net | grep : 2>&1 1>/dev/null
|
||||
then
|
||||
filename="/etc/sysconfig/static-routes-ipv6";
|
||||
# $net/$mask does not work with sed
|
||||
route="$ifname $net\/$mask $gw"
|
||||
route1="$ifname $net/$mask $gw"
|
||||
else
|
||||
filename="/etc/sysconfig/static-routes";
|
||||
route="any net $net netmask $mask gw $gw $ifname";
|
||||
route1="any net $net netmask $mask gw $gw $ifname";
|
||||
fi
|
||||
if [ -f $filename ]; then
|
||||
sed -i -e s/"$route"//g $filename
|
||||
fi
|
||||
echo "Persistent route \"$route\" removed from $filename."
|
||||
echo "Persistent route \"$route1\" removed from $filename."
|
||||
;;
|
||||
esac
|
||||
else #AIX
|
||||
@ -216,21 +264,38 @@ rm_persistent_route()
|
||||
if [ "$op" = "add" ]; then
|
||||
result=$(route_exists $net $mask $gw)
|
||||
if [ "$result" = "0" ]; then
|
||||
if [ "$(uname -s)" = "Linux" ]; then
|
||||
cmd="route add -net $net netmask $mask gw $gw"
|
||||
else
|
||||
cmd="route add -net $net -netmask $mask $gw"
|
||||
fi
|
||||
echo "Adding temporary route: $cmd"
|
||||
result=`$cmd 2>&1`
|
||||
code=$?
|
||||
if [ $code -ne 0 ]; then
|
||||
logger -t xCAT -p local4.err "$cmd\nerror code=$code, result=$result."
|
||||
echo " error code=$code, result=$result."
|
||||
#exit 1;
|
||||
fi
|
||||
#ipv6
|
||||
if echo $net | grep : 2>&1 1>/dev/null
|
||||
then
|
||||
if [ "$(uname -s)" = "Linux" ]; then
|
||||
cmd="ip -6 route add $net/$mask via $gw"
|
||||
else
|
||||
# AIX TODO
|
||||
cmd="ip -6 route add $net/$mask via $gw"
|
||||
fi
|
||||
else
|
||||
if [ "$(uname -s)" = "Linux" ]; then
|
||||
cmd="route add -net $net netmask $mask gw $gw"
|
||||
else
|
||||
cmd="route add -net $net -netmask $mask $gw"
|
||||
fi
|
||||
fi
|
||||
echo "Adding temporary route: $cmd"
|
||||
result=`$cmd 2>&1`
|
||||
code=$?
|
||||
if [ $code -ne 0 ]; then
|
||||
logger -t xCAT -p local4.err "$cmd\nerror code=$code, result=$result."
|
||||
echo " error code=$code, result=$result."
|
||||
#exit 1;
|
||||
fi
|
||||
else
|
||||
echo "The temporary route ($net $mask $gw) already exists."
|
||||
#ipv6
|
||||
if echo $net | grep : 2>&1 1>/dev/null
|
||||
then
|
||||
echo "The temporary route ($net/$mask $gw) already exists."
|
||||
else
|
||||
echo "The temporary route ($net $mask $gw) already exists."
|
||||
fi
|
||||
fi
|
||||
|
||||
#add persistent route
|
||||
@ -238,11 +303,23 @@ if [ "$op" = "add" ]; then
|
||||
elif [ "$op" = "delete" ]; then
|
||||
result=$(route_exists $net $mask $gw)
|
||||
if [ "$result" = "1" ]; then
|
||||
if [ "$(uname -s)" = "Linux" ]; then
|
||||
cmd="route delete -net $net netmask $mask gw $gw"
|
||||
else
|
||||
cmd="route delete -net $net -netmask $mask $gw"
|
||||
fi
|
||||
# ipv6
|
||||
if echo $net | grep : 2>&1 1>/dev/null
|
||||
then
|
||||
if [ "$(uname -s)" = "Linux" ]; then
|
||||
cmd="ip -6 route delete $net/$mask via $gw"
|
||||
else
|
||||
# AIX TODO
|
||||
cmd="ip -6 route delete $net/$mask via $gw"
|
||||
fi
|
||||
else
|
||||
if [ "$(uname -s)" = "Linux" ]; then
|
||||
cmd="route delete -net $net netmask $mask gw $gw"
|
||||
else
|
||||
cmd="route delete -net $net -netmask $mask $gw"
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "Removing temporary route: $cmd"
|
||||
result=`$cmd 2>&1`
|
||||
code=$?
|
||||
|
@ -22,6 +22,18 @@ do
|
||||
gw=`echo $route_string |cut -d',' -f3`
|
||||
ifname=`echo $route_string |cut -d',' -f4`
|
||||
|
||||
# remove the suffix /64 from ipv6 net
|
||||
if echo $net | grep "/" 2>&1 1>/dev/null
|
||||
then
|
||||
net=`echo $net | awk -F'/' '{print $1}'`
|
||||
fi
|
||||
|
||||
# remove the prefix "/" from ipv6 mask
|
||||
if echo $mask | grep "/" 2>&1 1>/dev/null
|
||||
then
|
||||
mask=`echo $mask | awk -F'/' '{print $2}'`
|
||||
fi
|
||||
|
||||
cmd="routeop add $net $mask $gw $ifname"
|
||||
result=`$cmd 2>&1`
|
||||
echo $result
|
||||
|
Loading…
x
Reference in New Issue
Block a user