From e34da389fbb0afeb920e7921b560fd564aeff40b Mon Sep 17 00:00:00 2001 From: Arif Ali Date: Tue, 1 Apr 2014 16:16:14 +0100 Subject: [PATCH 1/5] defect 4033: fix device based routing in makeroutes --- xCAT-server/lib/xcat/plugins/route.pm | 18 ++++++++++-- xCAT/postscripts/routeop | 42 +++++++++++++++++++++------ 2 files changed, 48 insertions(+), 12 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/route.pm b/xCAT-server/lib/xcat/plugins/route.pm index 8ec31df6c..02ece1454 100644 --- a/xCAT-server/lib/xcat/plugins/route.pm +++ b/xCAT-server/lib/xcat/plugins/route.pm @@ -614,7 +614,11 @@ sub set_route { } } else { if (xCAT::Utils->isLinux()) { - $cmd="route add -net $net netmask $mask gw $gw_ip"; + if ( $gw_ip == "" || $gw_ip == "0.0.0.0" ) { + $cmd="route add -net $net netmask $mask dev $ifname"; + } else { + $cmd="route add -net $net netmask $mask gw $gw_ip"; + } } else { $cmd="route add -net $net -netmask $mask $gw_ip"; } @@ -987,7 +991,11 @@ sub addPersistentRoute_RH { $new_config="$ifname $net/$mask $gw_ip"; } else { - $new_config="any net $net netmask $mask gw $gw_ip $ifname\n"; + if ( $gw_ip == "" || $gw_ip == "0.0.0.0" ) { + $new_config="any net $net netmask $mask dev $ifname\n"; + } else { + $new_config="any net $net netmask $mask gw $gw_ip $ifname\n"; + } } if (!$hasConfiged) { push(@output, $new_config); @@ -1125,7 +1133,11 @@ sub addPersistentRoute_Debian{ } else { #ipv4 $cmd = "grep \"-net $net netmask $mask gw $gw_ip\" $conf_file"; - $route_conf = " up route add -net $net netmask $mask gw $gw_ip \n down route del -net $net netmask $mask gw $gw_ip \n"; + if ( $gw_ip == "" || $gw_ip == "0.0.0.0" ) { + $route_conf = " up route add -net $net netmask $mask dev $ifname \n down route del -net $net netmask $mask dev $ifname \n"; + } else { + $route_conf = " up route add -net $net netmask $mask gw $gw_ip \n down route del -net $net netmask $mask gw $gw_ip\n"; + } } #fine the corresponding config in the config file diff --git a/xCAT/postscripts/routeop b/xCAT/postscripts/routeop index 7260a033a..fc1c50f0e 100755 --- a/xCAT/postscripts/routeop +++ b/xCAT/postscripts/routeop @@ -240,8 +240,13 @@ add_persistent_route() echo " up route -A inet6 add $net/$mask gw $gw" >> $tempfile echo " down route -A inet6 del $net/$mask gw $gw" >> $tempfile else - echo " up route add -net $net netmask $mask gw $gw" >> $tempfile - echo " down route del -net $net netmask $mask gw $gw" >> $tempfile + if [ "$gw" = "" -o "$gw" = "0.0.0.0" ] ; then + echo " up route add -net $net netmask $mask dev $ifname" >> $tempfile + echo " down route del -net $net netmask $mask dev $ifname" >> $tempfile + else + echo " up route add -net $net netmask $mask gw $gw" >> $tempfile + echo " down route del -net $net netmask $mask gw $gw" >> $tempfile + fi fi fi echo $LINE | grep "iface $ifname " 2>&1 1>/dev/null @@ -258,8 +263,13 @@ add_persistent_route() echo " up route -A inet6 add $net/$mask gw $gw" >> $tempfile echo " down route -A inet6 del $net/$mask gw $gw" >> $tempfile else - echo " up route add -net $net netmask $mask gw $gw" >> $tempfile - echo " down route del -net $net netmask $mask gw $gw" >> $tempfile + if [ "$gw" = "" -o "$gw" = "0.0.0.0" ] ; then + echo " up route add -net $net netmask $mask dev $ifname" >> $tempfile + echo " down route del -net $net netmask $mask dev $ifname" >> $tempfile + else + echo " up route add -net $net netmask $mask gw $gw" >> $tempfile + echo " down route del -net $net netmask $mask gw $gw" >> $tempfile + fi fi fi mv -f $tempfile $filename @@ -279,8 +289,13 @@ add_persistent_route() 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"; + if [ "$gw" = "" -o "$gw" = "0.0.0.0" ] ; then + route="any net $net netmask $mask dev $ifname"; + route1="any net $net netmask $mask dev $ifname"; + else + route="any net $net netmask $mask gw $gw $ifname"; + route1="any net $net netmask $mask gw $gw $ifname"; + fi fi if [ -f $filename ]; then grep "$route" $filename 2>&1 1>/dev/null @@ -401,8 +416,13 @@ rm_persistent_route() 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"; + if [ "$gw" = "" -o "$gw" = "0.0.0.0" ] ; then + route="any net $net netmask $mask dev $ifname"; + route1="any net $net netmask $mask dev $ifname"; + else + route="any net $net netmask $mask gw $gw $ifname"; + route1="any net $net netmask $mask gw $gw $ifname"; + fi fi if [ -f $filename ]; then grep "$route" $filename 2>&1 1>/dev/null @@ -438,7 +458,11 @@ if [ "$op" = "add" ]; then fi else if [ "$(uname -s)" = "Linux" ]; then - cmd="route add -net $net netmask $mask gw $gw" + if [ "$gw" = "" -o "$gw" = "0.0.0.0" ] ; then + cmd="route add -net $net netmask $mask dev $ifname" + else + cmd="route add -net $net netmask $mask gw $gw" + fi else cmd="route add -net $net -netmask $mask $gw" fi From 71ad311a68ca1d6b70bc3bfc2d74414e3d9ac14b Mon Sep 17 00:00:00 2001 From: Arif Ali Date: Tue, 1 Apr 2014 22:20:37 +0100 Subject: [PATCH 2/5] update route.pm, and start work on routeop --- xCAT-server/lib/xcat/plugins/route.pm | 101 +++++++++++++++++++------- xCAT/postscripts/routeop | 27 +++++-- 2 files changed, 98 insertions(+), 30 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/route.pm b/xCAT-server/lib/xcat/plugins/route.pm index 02ece1454..72d73f3b1 100644 --- a/xCAT-server/lib/xcat/plugins/route.pm +++ b/xCAT-server/lib/xcat/plugins/route.pm @@ -446,10 +446,10 @@ sub process_makeroutes { } else { #local on mn or sn if ($delete) { - delete_route($callback, $route_hash->{net}, $route_hash->{mask}, $gw_ip, $gw_name, $route_hash->{ifname}); + delete_route($callback, $route_hash->{net}, $route_hash->{mask}, $gw_ip, $gw_name, $ifname, $route_hash->{ifname}); } else { - set_route($callback, $route_hash->{net}, $route_hash->{mask}, $gw_ip, $gw_name,$route_hash->{ifname}); + set_route($callback, $route_hash->{net}, $route_hash->{mask}, $gw_ip, $gw_name, $ifname, $route_hash->{ifname}); } } } @@ -525,6 +525,7 @@ sub route_exists { my $net = shift; my $mask = shift; my $gw_ip = shift; + my $ifname = shift; my $gw=shift; my $islinux=xCAT::Utils->isLinux(); @@ -557,7 +558,8 @@ sub route_exists { 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))) { + my $ifname1=$a[7]; + if (($net1 eq $net) && ($mask1 eq $mask) && (($gw1 eq $gw) || ($gw1 eq $gw_ip) || ($ifname1 eq $ifname))) { return 1; } } @@ -602,13 +604,17 @@ sub set_route { #print "set_route get called\n"; my $result; - if (!route_exists($net, $mask, $gw_ip, $gw)) { + if (!route_exists($net, $mask, $gw_ip, $gw, $ifname)) { #set temporay route my $cmd; # ipv6 network if ($net =~ /:/) { if (xCAT::Utils->isLinux()) { - $cmd="ip -6 route add $net/$mask via $gw_ip"; + if ( $gw_ip == "" || $gw_ip == "0.0.0.0" ) { + $cmd="ip -6 route add $net/$mask dev $ifname"; + } else { + $cmd="ip -6 route add $net/$mask via $gw_ip"; + } } else { # AIX TODO } @@ -680,18 +686,26 @@ sub delete_route { #print "delete_route get called\n"; my $result; - if (route_exists($net, $mask, $gw_ip, $gw)) { + if (route_exists($net, $mask, $gw_ip, $gw, $ifname)) { #delete route temporarily my $cmd; if ($net =~ /:/) { if (xCAT::Utils->isLinux()) { - $cmd = "ip -6 route delete $net/$mask via $gw_ip"; + if ( $gw_ip == "" || $gw_ip == "0.0.0.0" ) { + $cmd = "ip -6 route delete $net/$mask dev $ifname"; + } else { + $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"; + if ( $gw_ip == "" || $gw_ip == "0.0.0.0" ) { + $cmd="route delete -net $net netmask $mask dev $ifname"; + } else { + $cmd="route delete -net $net netmask $mask gw $gw_ip"; + } } else { $cmd="route delete -net $net -netmask $mask $gw_ip"; } @@ -836,9 +850,17 @@ sub addPersistentRoute_Sles { #print "hasConfiged=$hasConfiged\n"; my $new_config; if ($net =~ /:/) { - $new_config = "$net/$mask $gw_ip - -\n"; + if ( $gw_ip == "" || $gw_ip == "0.0.0.0" ) { + $new_config = "$net/$mask 0.0.0.0 - $ifname\n"; + } else { + $new_config = "$net/$mask $gw_ip - -\n"; + } } else { - $new_config="$net $gw_ip $mask $ifname\n"; + if ( $gw_ip == "" || $gw_ip == "0.0.0.0" ) { + $new_config="$net 0.0.0.0 $mask $ifname\n"; + } else { + $new_config="$net $gw_ip $mask $ifname\n"; + } } if (!$hasConfiged) { push(@output, $new_config); @@ -876,7 +898,7 @@ sub deletePersistentRoute_Sles { my @new_output=(); my $bigfound=0; foreach my $tmp_conf (@output) { - my $found = checkConfig_Sles($net, $mask, $gw_ip, $gw, [$tmp_conf]); + my $found = checkConfig_Sles($net, $mask, $gw_ip, $gw, $ifname, [$tmp_conf]); if (!$found) { push(@new_output, $tmp_conf); } else { @@ -913,13 +935,14 @@ sub checkConfig_Sles { my $mask = shift; my $gw_ip = shift; my $gw=shift; + my $ifname=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); + my ($net1,$mask1,$gw1,$ifname1); if ($net =~ /:/) { if (@a>0) { my $ipv6net = $a[0]; @@ -929,6 +952,10 @@ sub checkConfig_Sles { $gw1=$a[1]; if ($gw1 eq '-') { $gw1=$gw_ip; } } + if (@a>3) { + $ifname1=$a[3]; + if ($ifname1 eq '-') { $ifname1=$ifname;} + } } else { if (@a>0) { @@ -943,10 +970,14 @@ sub checkConfig_Sles { $mask1=$a[2]; if ($mask1 eq '-') { $mask1=$mask;} } + if (@a>3) { + $ifname1=$a[3]; + if ($ifname1 eq '-') { $ifname1=$ifname;} + } } - #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))) { + #print "net=$net1,$net mask=$mask1,$mask gw=$gw1,$gw_ip ifname=$ifname1\n"; + if (($net1 && $net1 eq $net) && ($mask1 && $mask1 eq $mask) && (($gw1 && $gw1 eq $gw) || ($gw1 && $gw1 eq $gw_ip) || ($ifname1 && $ifname1 eq $ifname))) { return 1; } } @@ -976,7 +1007,7 @@ sub addPersistentRoute_RH { #print "old output=" . join("\n", @output) . "\n"; my $hasConfiged=0; if (@output && (@output > 0)) { - $hasConfiged=checkConfig_RH($net, $mask, $gw_ip, $gw, \@output); + $hasConfiged=checkConfig_RH($net, $mask, $gw_ip, $gw, $ifname, \@output); } #print "hasConfiged=$hasConfiged\n"; my $new_config; @@ -994,7 +1025,7 @@ sub addPersistentRoute_RH { if ( $gw_ip == "" || $gw_ip == "0.0.0.0" ) { $new_config="any net $net netmask $mask dev $ifname\n"; } else { - $new_config="any net $net netmask $mask gw $gw_ip $ifname\n"; + $new_config="any net $net netmask $mask gw $gw_ip\n"; } } if (!$hasConfiged) { @@ -1039,7 +1070,7 @@ sub deletePersistentRoute_RH { my @new_output=(); my $bigfound=0; foreach my $tmp_conf (@output) { - my $found = checkConfig_RH($net, $mask, $gw_ip, $gw, [$tmp_conf]); + my $found = checkConfig_RH($net, $mask, $gw_ip, $gw, $ifname, [$tmp_conf]); if (!$found) { push(@new_output, $tmp_conf); } else { @@ -1073,14 +1104,16 @@ sub checkConfig_RH { my $mask = shift; my $gw_ip = shift; my $gw=shift; + my $ifname=shift; my $output=shift; 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 # ipv6 format: eth1 fd60::/64 fd57::214:5eff:fe15:1 - my ($net1,$mask1,$gw1); + my ($net1,$mask1,$gw1,$ifname1); if ($net =~ /:/) { + $ifname1 = $a[0]; if (@a>1) { my $ipv6net = $a[1]; ($net1,$mask1) = split("/",$ipv6net); @@ -1098,13 +1131,18 @@ sub checkConfig_RH { if ($mask1 eq '-') { $mask1=$mask;} } if (@a>6) { - $gw1=$a[6]; - if ($gw1 eq '-') { $gw1=$gw_ip; } + if ( $a[5] eq 'dev' ) { + $ifname1=$a[6]; + if ($ifname1 eq '-') { $ifname1=$ifname;} + } else { + $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))) { + if (($net1 && $net1 eq $net) && ($mask1 && $mask1 eq $mask) && (($gw1 && $gw1 eq $gw) || ($gw1 && $gw1 eq $gw_ip) || ($ifname1 && $ifname1 eq $ifname))) { return 1; } } @@ -1128,8 +1166,13 @@ sub addPersistentRoute_Debian{ #ipv6 if ( $net =~ /:/){ - $cmd = "grep \"$net/$mask gw $gw_ip\" $conf_file"; - $route_conf = " up route -A inet6 add $net/$mask gw $gw_ip \n down route -A inet6 del $net/$mask gw $gw_ip \n"; + if ( $gw_ip == "" || $gw_ip == "0.0.0.0" ) { + $cmd = "grep \"$net/$mask dev $ifname\" $conf_file"; + $route_conf = " up route -A inet6 add $net/$mask dev $ifname \n down route -A inet6 del $net/$mask dev $ifname \n"; + } else { + $cmd = "grep \"$net/$mask gw $gw_ip\" $conf_file"; + $route_conf = " up route -A inet6 add $net/$mask gw $gw_ip \n down route -A inet6 del $net/$mask gw $gw_ip \n"; + } } else { #ipv4 $cmd = "grep \"-net $net netmask $mask gw $gw_ip\" $conf_file"; @@ -1195,10 +1238,18 @@ sub deletePersistentRoute_Debian{ preParse_Debian(); #ipv6 if ( $net =~ /:/){ - $match = "$net/$mask gw $gw_ip"; + if ( $gw_ip == "" || $gw_ip == "0.0.0.0" ) { + $match = "$net/$mask dev $ifname"; + } else { + $match = "$net/$mask gw $gw_ip"; + } } else { - $match = "net $net netmask $mask gw $gw_ip"; + if ( $gw_ip == "" || $gw_ip == "0.0.0.0" ) { + $match = "net $net netmask $mask dev $ifname"; + } else { + $match = "net $net netmask $mask gw $gw_ip"; + } } open(FH, "<", $conf_file); diff --git a/xCAT/postscripts/routeop b/xCAT/postscripts/routeop index fc1c50f0e..b8cf881fa 100755 --- a/xCAT/postscripts/routeop +++ b/xCAT/postscripts/routeop @@ -237,8 +237,13 @@ add_persistent_route() if [ $? -eq 0 -a $foundflag -eq 1 ];then foundflag=0 if [ $v6flag -eq 1 ];then - echo " up route -A inet6 add $net/$mask gw $gw" >> $tempfile - echo " down route -A inet6 del $net/$mask gw $gw" >> $tempfile + if [ "$gw" = "" -o "$gw" = "0.0.0.0" ] ; then + echo " up route -A inet6 add $net/$mask dev $ifname" >> $tempfile + echo " down route -A inet6 del $net/$mask dev $ifname" >> $tempfile + else + echo " up route -A inet6 add $net/$mask gw $gw" >> $tempfile + echo " down route -A inet6 del $net/$mask gw $gw" >> $tempfile + fi else if [ "$gw" = "" -o "$gw" = "0.0.0.0" ] ; then echo " up route add -net $net netmask $mask dev $ifname" >> $tempfile @@ -260,8 +265,13 @@ add_persistent_route() #the insert place is the last line of the config file if [ $foundflag -eq 1 ];then if [ $v6flag -eq 1 ];then - echo " up route -A inet6 add $net/$mask gw $gw" >> $tempfile - echo " down route -A inet6 del $net/$mask gw $gw" >> $tempfile + if [ "$gw" = "" -o "$gw" = "0.0.0.0" ] ; then + echo " up route -A inet6 add $net/$mask dev $ifname" >> $tempfile + echo " down route -A inet6 del $net/$mask dev $ifname" >> $tempfile + else + echo " up route -A inet6 add $net/$mask gw $gw" >> $tempfile + echo " down route -A inet6 del $net/$mask gw $gw" >> $tempfile + fi else if [ "$gw" = "" -o "$gw" = "0.0.0.0" ] ; then echo " up route add -net $net netmask $mask dev $ifname" >> $tempfile @@ -283,6 +293,9 @@ add_persistent_route() # ipv6 net if echo $net | grep : 2>&1 1>/dev/null then + if [ "$gw" = "" -o "$gw" = "0.0.0.0" ] ; then + $gw = "0.0.0.0"; + fi filename="/etc/sysconfig/static-routes-ipv6"; route="$ifname $net/$mask $gw"; # $net/mask does not work with sed cmd @@ -503,7 +516,11 @@ elif [ "$op" = "delete" ]; then fi else if [ "$(uname -s)" = "Linux" ]; then - cmd="route delete -net $net netmask $mask gw $gw" + if [ "$gw" = "" -o "$gw" = "0.0.0.0" ] ; then + cmd="route delete -net $net netmask $mask dev $ifname" + else + cmd="route delete -net $net netmask $mask gw $gw" + fi else cmd="route delete -net $net -netmask $mask $gw" fi From d730e82055397fa2c227f56464f0de16e0752fcd Mon Sep 17 00:00:00 2001 From: Arif Ali Date: Wed, 2 Apr 2014 09:43:15 +0100 Subject: [PATCH 3/5] update routeop with device based routing --- xCAT/postscripts/routeop | 84 +++++++++++++++++++++++++++++++--------- 1 file changed, 66 insertions(+), 18 deletions(-) diff --git a/xCAT/postscripts/routeop b/xCAT/postscripts/routeop index b8cf881fa..07e1e20f0 100755 --- a/xCAT/postscripts/routeop +++ b/xCAT/postscripts/routeop @@ -107,7 +107,8 @@ route_exists() 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 + ifname1=`echo $x|cut -d',' -f8` + if [ "$net" = "$net1" ] && [ "$mask" = "$mask1" ] && [ "$gw" = "$gw1" ] && [ "$ifname" = "$ifname1" ]; then ret=1 break fi @@ -174,11 +175,21 @@ add_persistent_route() filename="/etc/sysconfig/network/routes"; if echo $net | grep : 2>&1 1>/dev/null then - route="$net/$mask $gw - -" - route1="$net\/$mask $gw - -"; + if [ $gw_ip = "" -o $gw_ip = "0.0.0.0" ] ; then + route="$net/$mask 0.0.0.0 - $ifname" + route1="$net\/$mask 0.0.0.0 - $ifname"; + else + route="$net/$mask $gw - -" + route1="$net\/$mask $gw - -"; + fi else - route="$net $gw $mask $ifname"; - route1="$net $gw $mask $ifname"; + if [ $gw_ip = "" -o $gw_ip = "0.0.0.0" ] ; then + route="$net 0.0.0.0 $mask $ifname"; + route1="$net 0.0.0.0 $mask $ifname"; + else + route="$net $gw $mask $ifname"; + route1="$net $gw $mask $ifname"; + fi fi if [ -f $filename ]; then grep "$route" $filename 2>&1 1>/dev/null @@ -221,10 +232,18 @@ add_persistent_route() echo $net | grep : 2>&1 1>/dev/null #ipv6 if [ $? -eq 0 ];then - matchstr="$net/$mask gw $gw" + if [ "$gw" = "" -o "$gw" = "0.0.0.0" ] ; then + matchstr="$net/$mask dev $ifname" + else + matchstr="$net/$mask gw $gw" + fi v6flag=1 else - matchstr="net $net netmask $mask gw $gw" + if [ "$gw" = "" -o "$gw" = "0.0.0.0" ] ; then + matchstr="net $net netmask $mask dev $ifname" + else + matchstr="net $net netmask $mask gw $gw" + fi fi grep "$matchstr" $filename 2>&1 1>/dev/null @@ -293,7 +312,7 @@ add_persistent_route() # ipv6 net if echo $net | grep : 2>&1 1>/dev/null then - if [ "$gw" = "" -o "$gw" = "0.0.0.0" ] ; then + if [ "$gw" = "" ] ; then $gw = "0.0.0.0"; fi filename="/etc/sysconfig/static-routes-ipv6"; @@ -368,15 +387,23 @@ rm_persistent_route() # ipv6 net if echo $net | grep : 2>&1 1>/dev/null then - route="$net/$mask $gw - -"; - route1="$net\/$mask $gw - -"; + if [ $gw = "" -o $gw = "0.0.0.0" ] ; then + route="$net/$mask 0.0.0.0 - $ifname"; + route1="$net\/$mask 0.0.0.0 - $ifname"; + else + route="$net/$mask $gw - -"; + route1="$net\/$mask $gw - -"; + fi else + if [ $gw = "" ] ; then + $gw = "0.0.0.0"; + fi if [ -n "$ifname" ]; then route="$net $gw $mask $ifname"; route1="$net $gw $mask $ifname"; else - route="$net $gw $mask"; - route1="$net $gw $mask"; + route="$net $gw $mask -"; + route1="$net $gw $mask -"; fi fi if [ -f $filename ]; then @@ -404,10 +431,18 @@ rm_persistent_route() echo $net | grep : 2>&1 1>/dev/null #ipv6 if [ $? -eq 0 ];then - matchstr="$net/$mask gw $gw" + if [ $gw = "" -o $gw = "0.0.0.0" ] ; then + matchstr="$net/$mask dev $ifname" + else + matchstr="$net/$mask gw $gw" + fi v6flag=1 else - matchstr="net $net netmask $mask gw $gw" + if [ $gw = "" -o $gw = "0.0.0.0" ] ; then + matchstr="net $net netmask $mask dev $ifname" + else + matchstr="net $net netmask $mask gw $gw" + fi fi grep "$matchstr" $filename @@ -425,8 +460,13 @@ rm_persistent_route() then filename="/etc/sysconfig/static-routes-ipv6"; # $net/$mask does not work with sed - route="$ifname $net\/$mask $gw" - route1="$ifname $net/$mask $gw" + if [ "$gw" = "" -o "$gw" = "0.0.0.0" ] ; then + route="$ifname $net\/$mask 0.0.0.0" + route1="$ifname $net/$mask 0.0.0.0" + else + route="$ifname $net\/$mask $gw" + route1="$ifname $net/$mask $gw" + fi else filename="/etc/sysconfig/static-routes"; if [ "$gw" = "" -o "$gw" = "0.0.0.0" ] ; then @@ -464,7 +504,11 @@ if [ "$op" = "add" ]; then if echo $net | grep : 2>&1 1>/dev/null then if [ "$(uname -s)" = "Linux" ]; then - cmd="ip -6 route add $net/$mask via $gw" + if [ "$gw" = "" -o "$gw" = "0.0.0.0" ] ; then + cmd="ip -6 route add $net/$mask dev $ifname" + else + cmd="ip -6 route add $net/$mask via $gw" + fi else # AIX TODO cmd="ip -6 route add $net/$mask via $gw" @@ -509,7 +553,11 @@ elif [ "$op" = "delete" ]; then if echo $net | grep : 2>&1 1>/dev/null then if [ "$(uname -s)" = "Linux" ]; then - cmd="ip -6 route delete $net/$mask via $gw" + if [ "$gw" = "" -o "$gw" = "0.0.0.0" ] ; then + cmd="ip -6 route delete $net/$mask dev $ifname" + else + cmd="ip -6 route delete $net/$mask via $gw" + fi else # AIX TODO cmd="ip -6 route delete $net/$mask via $gw" From 795295e1a39efc4a5b8160b6780a7c8c6cb3607b Mon Sep 17 00:00:00 2001 From: Arif Ali Date: Wed, 2 Apr 2014 09:59:22 +0100 Subject: [PATCH 4/5] add ifname to arguments for checkConfig_Sles --- xCAT-server/lib/xcat/plugins/route.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/route.pm b/xCAT-server/lib/xcat/plugins/route.pm index 72d73f3b1..73cac1a9e 100644 --- a/xCAT-server/lib/xcat/plugins/route.pm +++ b/xCAT-server/lib/xcat/plugins/route.pm @@ -845,7 +845,7 @@ sub addPersistentRoute_Sles { #print "old output=" . join("\n", @output) . "\n"; my $hasConfiged=0; if (@output && (@output > 0)) { - $hasConfiged=checkConfig_Sles($net, $mask, $gw_ip, $gw, \@output); + $hasConfiged=checkConfig_Sles($net, $mask, $gw_ip, $gw, $ifname, \@output); } #print "hasConfiged=$hasConfiged\n"; my $new_config; @@ -1141,7 +1141,7 @@ sub checkConfig_RH { } } - #print "net=$net1,$net mask=$mask1,$mask gw=$gw1,$gw_ip\n"; + #print "net=$net1,$net mask=$mask1,$mask gw=$gw1,$gw_ip ifname=$ifname1,ifname\n"; if (($net1 && $net1 eq $net) && ($mask1 && $mask1 eq $mask) && (($gw1 && $gw1 eq $gw) || ($gw1 && $gw1 eq $gw_ip) || ($ifname1 && $ifname1 eq $ifname))) { return 1; } From b8e22ef5b23c5c244bb062a2f75ea48c7b27b0ba Mon Sep 17 00:00:00 2001 From: Arif Ali Date: Fri, 4 Apr 2014 01:19:09 +0100 Subject: [PATCH 5/5] fix ipv6 0.0.0.0 to ::, the equivalent ip --- xCAT-server/lib/xcat/plugins/route.pm | 22 ++++++++++-------- xCAT/postscripts/routeop | 32 +++++++++++++-------------- 2 files changed, 29 insertions(+), 25 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/route.pm b/xCAT-server/lib/xcat/plugins/route.pm index 73cac1a9e..1da3055f8 100644 --- a/xCAT-server/lib/xcat/plugins/route.pm +++ b/xCAT-server/lib/xcat/plugins/route.pm @@ -446,10 +446,10 @@ sub process_makeroutes { } else { #local on mn or sn if ($delete) { - delete_route($callback, $route_hash->{net}, $route_hash->{mask}, $gw_ip, $gw_name, $ifname, $route_hash->{ifname}); + delete_route($callback, $route_hash->{net}, $route_hash->{mask}, $gw_ip, $gw_name, $route_hash->{ifname}); } else { - set_route($callback, $route_hash->{net}, $route_hash->{mask}, $gw_ip, $gw_name, $ifname, $route_hash->{ifname}); + set_route($callback, $route_hash->{net}, $route_hash->{mask}, $gw_ip, $gw_name, $route_hash->{ifname}); } } } @@ -525,8 +525,8 @@ sub route_exists { my $net = shift; my $mask = shift; my $gw_ip = shift; - my $ifname = shift; my $gw=shift; + my $ifname = shift; my $islinux=xCAT::Utils->isLinux(); @@ -610,7 +610,7 @@ sub set_route { # ipv6 network if ($net =~ /:/) { if (xCAT::Utils->isLinux()) { - if ( $gw_ip == "" || $gw_ip == "0.0.0.0" ) { + if ( $gw_ip == "" || $gw_ip == "::" ) { $cmd="ip -6 route add $net/$mask dev $ifname"; } else { $cmd="ip -6 route add $net/$mask via $gw_ip"; @@ -691,7 +691,7 @@ sub delete_route { my $cmd; if ($net =~ /:/) { if (xCAT::Utils->isLinux()) { - if ( $gw_ip == "" || $gw_ip == "0.0.0.0" ) { + if ( $gw_ip == "" || $gw_ip == "::" ) { $cmd = "ip -6 route delete $net/$mask dev $ifname"; } else { $cmd = "ip -6 route delete $net/$mask via $gw_ip"; @@ -850,8 +850,8 @@ sub addPersistentRoute_Sles { #print "hasConfiged=$hasConfiged\n"; my $new_config; if ($net =~ /:/) { - if ( $gw_ip == "" || $gw_ip == "0.0.0.0" ) { - $new_config = "$net/$mask 0.0.0.0 - $ifname\n"; + if ( $gw_ip == "" || $gw_ip == "::" ) { + $new_config = "$net/$mask :: - $ifname\n"; } else { $new_config = "$net/$mask $gw_ip - -\n"; } @@ -938,6 +938,10 @@ sub checkConfig_Sles { my $ifname=shift; my $output=shift; + # Format: + # DESTINATION GATEWAY NETMASK INTERFACE + # DESTINATION/PREFIXLEN GATEWAY - INTERFACE + # 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) { @@ -1166,7 +1170,7 @@ sub addPersistentRoute_Debian{ #ipv6 if ( $net =~ /:/){ - if ( $gw_ip == "" || $gw_ip == "0.0.0.0" ) { + if ( $gw_ip == "" || $gw_ip == "::" ) { $cmd = "grep \"$net/$mask dev $ifname\" $conf_file"; $route_conf = " up route -A inet6 add $net/$mask dev $ifname \n down route -A inet6 del $net/$mask dev $ifname \n"; } else { @@ -1238,7 +1242,7 @@ sub deletePersistentRoute_Debian{ preParse_Debian(); #ipv6 if ( $net =~ /:/){ - if ( $gw_ip == "" || $gw_ip == "0.0.0.0" ) { + if ( $gw_ip == "" || $gw_ip == "::" ) { $match = "$net/$mask dev $ifname"; } else { $match = "$net/$mask gw $gw_ip"; diff --git a/xCAT/postscripts/routeop b/xCAT/postscripts/routeop index 07e1e20f0..2cf80a3f1 100755 --- a/xCAT/postscripts/routeop +++ b/xCAT/postscripts/routeop @@ -175,9 +175,9 @@ add_persistent_route() filename="/etc/sysconfig/network/routes"; if echo $net | grep : 2>&1 1>/dev/null then - if [ $gw_ip = "" -o $gw_ip = "0.0.0.0" ] ; then - route="$net/$mask 0.0.0.0 - $ifname" - route1="$net\/$mask 0.0.0.0 - $ifname"; + if [ $gw_ip = "" -o $gw_ip = "::" ] ; then + route="$net/$mask :: - $ifname" + route1="$net\/$mask :: - $ifname"; else route="$net/$mask $gw - -" route1="$net\/$mask $gw - -"; @@ -232,7 +232,7 @@ add_persistent_route() echo $net | grep : 2>&1 1>/dev/null #ipv6 if [ $? -eq 0 ];then - if [ "$gw" = "" -o "$gw" = "0.0.0.0" ] ; then + if [ "$gw" = "" -o "$gw" = "::" ] ; then matchstr="$net/$mask dev $ifname" else matchstr="$net/$mask gw $gw" @@ -256,7 +256,7 @@ add_persistent_route() if [ $? -eq 0 -a $foundflag -eq 1 ];then foundflag=0 if [ $v6flag -eq 1 ];then - if [ "$gw" = "" -o "$gw" = "0.0.0.0" ] ; then + if [ "$gw" = "" -o "$gw" = "::" ] ; then echo " up route -A inet6 add $net/$mask dev $ifname" >> $tempfile echo " down route -A inet6 del $net/$mask dev $ifname" >> $tempfile else @@ -284,7 +284,7 @@ add_persistent_route() #the insert place is the last line of the config file if [ $foundflag -eq 1 ];then if [ $v6flag -eq 1 ];then - if [ "$gw" = "" -o "$gw" = "0.0.0.0" ] ; then + if [ "$gw" = "" -o "$gw" = "::" ] ; then echo " up route -A inet6 add $net/$mask dev $ifname" >> $tempfile echo " down route -A inet6 del $net/$mask dev $ifname" >> $tempfile else @@ -313,7 +313,7 @@ add_persistent_route() if echo $net | grep : 2>&1 1>/dev/null then if [ "$gw" = "" ] ; then - $gw = "0.0.0.0"; + $gw = "::"; fi filename="/etc/sysconfig/static-routes-ipv6"; route="$ifname $net/$mask $gw"; @@ -387,9 +387,9 @@ rm_persistent_route() # ipv6 net if echo $net | grep : 2>&1 1>/dev/null then - if [ $gw = "" -o $gw = "0.0.0.0" ] ; then - route="$net/$mask 0.0.0.0 - $ifname"; - route1="$net\/$mask 0.0.0.0 - $ifname"; + if [ $gw = "" -o $gw = "::" ] ; then + route="$net/$mask :: - $ifname"; + route1="$net\/$mask :: - $ifname"; else route="$net/$mask $gw - -"; route1="$net\/$mask $gw - -"; @@ -431,7 +431,7 @@ rm_persistent_route() echo $net | grep : 2>&1 1>/dev/null #ipv6 if [ $? -eq 0 ];then - if [ $gw = "" -o $gw = "0.0.0.0" ] ; then + if [ $gw = "" -o $gw = "::" ] ; then matchstr="$net/$mask dev $ifname" else matchstr="$net/$mask gw $gw" @@ -460,9 +460,9 @@ rm_persistent_route() then filename="/etc/sysconfig/static-routes-ipv6"; # $net/$mask does not work with sed - if [ "$gw" = "" -o "$gw" = "0.0.0.0" ] ; then - route="$ifname $net\/$mask 0.0.0.0" - route1="$ifname $net/$mask 0.0.0.0" + if [ "$gw" = "" -o "$gw" = "::" ] ; then + route="$ifname $net\/$mask ::" + route1="$ifname $net/$mask ::" else route="$ifname $net\/$mask $gw" route1="$ifname $net/$mask $gw" @@ -504,7 +504,7 @@ if [ "$op" = "add" ]; then if echo $net | grep : 2>&1 1>/dev/null then if [ "$(uname -s)" = "Linux" ]; then - if [ "$gw" = "" -o "$gw" = "0.0.0.0" ] ; then + if [ "$gw" = "" -o "$gw" = "::" ] ; then cmd="ip -6 route add $net/$mask dev $ifname" else cmd="ip -6 route add $net/$mask via $gw" @@ -553,7 +553,7 @@ elif [ "$op" = "delete" ]; then if echo $net | grep : 2>&1 1>/dev/null then if [ "$(uname -s)" = "Linux" ]; then - if [ "$gw" = "" -o "$gw" = "0.0.0.0" ] ; then + if [ "$gw" = "" -o "$gw" = "::" ] ; then cmd="ip -6 route delete $net/$mask dev $ifname" else cmd="ip -6 route delete $net/$mask via $gw"