mirror of
				https://github.com/xcat2/xcat-core.git
				synced 2025-10-28 09:55:44 +00:00 
			
		
		
		
	keyword <myself> as gateway in networks table
git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@8916 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
		| @@ -1938,6 +1938,18 @@ sub getNetwkInfo | ||||
| 						$nethash{$node}{$attr} = $_->{$attr}; | ||||
| 					} | ||||
|                                 } | ||||
|                                 if($nethash{$node}{'gateway'} eq '<myself>') | ||||
|                                 { | ||||
|                                     if(xCAT::NetworkUtils->ip_forwarding_enabled()) | ||||
|                                     { | ||||
|                                         $nethash{$node}{'gateway'} = xCAT::NetworkUtils->my_ip_in_subnet($net, $NM); | ||||
|                                     } | ||||
|                                     else | ||||
|                                     { | ||||
|                                         $nethash{$node}{'gateway'} = ''; | ||||
|                                     } | ||||
|                                     $nethash{$node}{'myselfgw'} = 1; | ||||
|                                 } | ||||
|                                 next; | ||||
|                         } | ||||
|                              | ||||
|   | ||||
| @@ -444,4 +444,79 @@ sub prefixtomask { | ||||
|     $mask =~ s/(....)/$1/g; | ||||
|     return $mask; | ||||
| } | ||||
|  | ||||
| #------------------------------------------------------------------------------- | ||||
|  | ||||
| =head3  my_ip_in_subnet  | ||||
|     Get the facing ip for some specific network | ||||
|  | ||||
|     Arguments: | ||||
|        net - subnet, such as 192.168.0.01 | ||||
|        mask - netmask, such as 255.255.255.0 | ||||
|     Returns: | ||||
|        facing_ip - The local ip address in the subnet, | ||||
|                    returns undef if no local ip address is in the subnet | ||||
|     Globals: | ||||
|     Error: | ||||
|         none | ||||
|     Example: | ||||
|         my $facingip = xCAT::NetworkUtils->my_ip_in_subnet($net, $mask); | ||||
|     Comments: | ||||
|         none | ||||
| =cut | ||||
|  | ||||
| #------------------------------------------------------------------------------- | ||||
| sub my_ip_in_subnet | ||||
| { | ||||
|     my ($class, $net, $mask) = @_; | ||||
|  | ||||
|     if (!$net || !$mask) | ||||
|     { | ||||
|         return undef; | ||||
|     }  | ||||
|  | ||||
|     my $fmask = xCAT::Utils::formatNetmask($mask, 0, 1); | ||||
|  | ||||
|     my $localnets = xCAT::Utils->my_nets(); | ||||
|  | ||||
|     return $localnets->{"$net\/$fmask"}; | ||||
| } | ||||
|  | ||||
| #------------------------------------------------------------------------------- | ||||
|  | ||||
| =head3  ip_forwarding_enabled  | ||||
|     Check if the ip_forward enabled on the system  | ||||
|  | ||||
|     Arguments: | ||||
|     Returns: | ||||
|        1 - The ip_forwarding is eanbled | ||||
|        0 - The ip_forwarding is not eanbled | ||||
|     Globals: | ||||
|     Error: | ||||
|         none | ||||
|     Example: | ||||
|         if(xCAT::NetworkUtils->ip_forwarding_enabled()) | ||||
|     Comments: | ||||
|         none | ||||
| =cut | ||||
|  | ||||
| #------------------------------------------------------------------------------- | ||||
| sub ip_forwarding_enabled | ||||
| { | ||||
|  | ||||
|     my $enabled; | ||||
|     if (xCAT::Utils->isLinux()) | ||||
|     { | ||||
|         $enabled = `sysctl -n net.ipv4.ip_forward`; | ||||
|         chomp($enabled); | ||||
|     } | ||||
|     else | ||||
|     { | ||||
|         $enabled = `no -o ipforwarding`; | ||||
|         chomp($enabled); | ||||
|         $enabled =~ s/ipforwarding\s+=\s+//; | ||||
|     } | ||||
|     return $enabled; | ||||
| } | ||||
|  | ||||
| 1; | ||||
|   | ||||
| @@ -877,6 +877,17 @@ sub net_parms | ||||
|         my $net  = $_->{'net'}; | ||||
|         my $mask = $_->{'mask'}; | ||||
|         my $gw   = $_->{'gateway'}; | ||||
|         if($gw eq '<myself>') | ||||
|         { | ||||
|              if(xCAT::NetworkUtils->ip_forwarding_enabled()) | ||||
|              { | ||||
|                  $gw = xCAT::NetworkUtils->my_ip_in_subnet($net, $mask); | ||||
|              } | ||||
|              else | ||||
|              { | ||||
|                  $gw = ''; | ||||
|              } | ||||
|         } | ||||
|         if (xCAT::NetworkUtils->ishostinsubnet($ip, $mask, $net)) | ||||
|         { | ||||
|             return ($ip, $mask, $gw); | ||||
|   | ||||
| @@ -443,6 +443,22 @@ sub process_request | ||||
| 	my $nimhash   = $flatreq->{'nimhash'}; | ||||
|     my $nodes     = $flatreq->{node}; | ||||
|  | ||||
|     my $ip_forwarding_enabled = xCAT::NetworkUtils->ip_forwarding_enabled(); | ||||
|     foreach my $fnode (keys %{$nethash}) | ||||
|     { | ||||
|         if($nethash->{$fnode}->{'myselfgw'} eq '1') | ||||
|         { | ||||
|             if ($ip_forwarding_enabled) | ||||
|             { | ||||
|                 $nethash->{$fnode}->{'gateway'} = xCAT::NetworkUtils->my_ip_in_subnet($nethash->{$fnode}->{'net'}, $nethash->{$fnode}->{'mask'}); | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 $nethash->{$fnode}->{'gateway'} = ''; | ||||
|             } | ||||
|         } | ||||
|      } | ||||
|          | ||||
|     # figure out which cmd and call the subroutine to process | ||||
|     if ($command eq "mkdsklsnode") | ||||
|     { | ||||
|   | ||||
| @@ -1532,6 +1532,18 @@ sub addnet | ||||
|             if ($ent and $ent->{gateway}) | ||||
|             { | ||||
|                 $gateway = $ent->{gateway}; | ||||
|  | ||||
|                 if ($gateway eq '<myself>') | ||||
|                 { | ||||
|                     if(xCAT::NetworkUtils->ip_forwarding_enabled()) | ||||
|                     { | ||||
|                         $gateway = $myip; | ||||
|                     } | ||||
|                     else | ||||
|                     { | ||||
|                         $gateway = ''; | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|             if ($ent and $ent->{dynamicrange}) | ||||
|             { | ||||
| @@ -1707,6 +1719,17 @@ sub gen_aix_net | ||||
|     my @netent = ( "network $net $mask\n{\n"); | ||||
|     if ( $gateway) | ||||
|     { | ||||
|         if ($gateway eq '<myself>') | ||||
|         { | ||||
|             if(xCAT::NetworkUtils->ip_forwarding_enabled()) | ||||
|             { | ||||
|                 $gateway = $myip; | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 $gateway = ''; | ||||
|             } | ||||
|         } | ||||
|         if (xCAT::Utils::isInSameSubnet($gateway,$net,$mask,1)) | ||||
|         { | ||||
|             push @netent, "    option 3 $gateway\n"; | ||||
|   | ||||
| @@ -276,7 +276,22 @@ sub donets | ||||
|             		} | ||||
|             		$ipaddr = $fields[1]; | ||||
|             		$netmask = $fields[2]; | ||||
|             		$gateway = $fields[6]; | ||||
|                         if ($fields[6]) | ||||
|                         { | ||||
|                             if(xCAT::Utils::isInSameSubnet($fields[6], $ipaddr, $netmask, 0)) | ||||
|                             { | ||||
|                                 $gateway = $fields[6];  | ||||
|                             } | ||||
|                         } | ||||
|  | ||||
|                         # set gateway to keyword <myself>, | ||||
|                         # to indicate to use the cluster-facing ip address  | ||||
|                         # on this management node or service node | ||||
|                         if (!$gateway) | ||||
|                         { | ||||
|                             $gateway = "<myself>"; | ||||
|                         } | ||||
|                          | ||||
|      | ||||
|             		# split interface IP | ||||
|                     my ($ip1, $ip2, $ip3, $ip4) = split('\.', $ipaddr); | ||||
| @@ -460,11 +475,12 @@ sub donets | ||||
|             	$net       = $ent[0]; | ||||
|             	$mask      = $ent[2]; | ||||
| 				$mgtifname = $ent[7]; | ||||
|                 if (defined($netgw{$net}{$mask})) | ||||
|                 if (defined($netgw{'0.0.0.0'}{'0.0.0.0'})) | ||||
|                 { | ||||
|                     $gw =  $netgw{$net}{$mask}; #gateway for this network | ||||
|                 } else {    | ||||
|                     $gw =  $netgw{'0.0.0.0'}{'0.0.0.0'}; #default gatetway | ||||
|                     if(xCAT::NetworkUtils->ishostinsubnet($netgw{'0.0.0.0'}{'0.0.0.0'}, $mask, $net)) | ||||
|                     { | ||||
|                         $gw =  $netgw{'0.0.0.0'}{'0.0.0.0'}; #default gatetway | ||||
|                     } | ||||
|                 } | ||||
|  | ||||
| 				# use convention for netname attr | ||||
|   | ||||
		Reference in New Issue
	
	Block a user