diff --git a/perl-xCAT-2.0/xCAT/Utils.pm b/perl-xCAT-2.0/xCAT/Utils.pm index 95ec13f4d..9c13ffc7e 100644 --- a/perl-xCAT-2.0/xCAT/Utils.pm +++ b/perl-xCAT-2.0/xCAT/Utils.pm @@ -993,6 +993,31 @@ sub isServiceNode } } +sub my_ip_facing { + my $peer = shift; + if (@_) { + $peer = shift; + } + my $noden = unpack("N", inet_aton($peer)); + my @nets = split /\n/, `/sbin/ip addr`; + foreach (@nets) + { + my @elems = split /\s+/; + unless (/^\s*inet\s/) + { + next; + } + (my $curnet, my $maskbits) = split /\//, $elems[2]; + my $curmask = 2**$maskbits - 1 << (32 - $maskbits); + my $curn = unpack("N", inet_aton($curnet)); + if (($noden & $curmask) == ($curn & $curmask)) + { + return $curnet; + } + } + return undef; +} + #------------------------------------------------------------------------------- =head3 nodeonmynet diff --git a/xCAT-server-2.0/lib/xcat/plugins/dhcp.pm b/xCAT-server-2.0/lib/xcat/plugins/dhcp.pm index 9570e9192..affdd3c4c 100644 --- a/xCAT-server-2.0/lib/xcat/plugins/dhcp.pm +++ b/xCAT-server-2.0/lib/xcat/plugins/dhcp.pm @@ -9,6 +9,7 @@ Getopt::Long::Configure("pass_through"); use Socket; use Sys::Syslog; use IPC::Open2; +use xCAT::Utils; my @dhcpconf; #Hold DHCP config file contents to be written back. my @nrn; # To hold output of netstat -rn to be consulted throughout process @@ -87,7 +88,13 @@ sub addnode { $ent = $nrtab->getNodeAttribs($node,['tftpserver']); if ($ent and $ent->{tftpserver}) { $statements = 'next-server '.inet_ntoa(inet_aton($ent->{tftpserver})).';'.$statements; - } #else { + } else { + my $nxtsrv = xCAT::Utils->my_ip_facing($node); + if ($nxtsrv) { + $statements = "next-server $nxtsrv;$statements"; + } + } + #else { # $ent = $nrtab->getNodeAttribs($node,['servicenode']); # if ($ent and $ent->{servicenode}) { # $statements = 'next-server = \"'.inet_ntoa(inet_aton($ent->{servicenode})).'\";'.$statements; @@ -150,23 +157,6 @@ sub addnode { } } } -sub thishostisnot { - my $comparison = shift; - my @ips = split /\n/,`/sbin/ip addr`; - my $comp=inet_aton($comparison); - foreach (@ips) { - if (/^\s*inet/) { - my @ents = split(/\s+/); - my $ip=$ents[2]; - $ip =~ s/\/.*//; - if (inet_aton($ip) eq $comp) { - return 0; - } - #print Dumper(inet_aton($ip)); - } - } - return 1; -} sub preprocess_request { my $req = shift; $callback = shift; @@ -177,7 +167,7 @@ sub preprocess_request { $sitetab->close; if ($ent and $ent->{value}) { foreach (split /,/,$ent->{value}) { - if (thishostisnot($_)) { + if (xCAT::Utils->thishostisnot($_)) { my $reqcopy = {%$req}; $reqcopy->{'_xcatdest'} = $_; push @requests,$reqcopy; @@ -289,6 +279,9 @@ sub process_request { if (grep /^-d$/,@{$req->{arg}}) { delnode $_; } else { + unless (xCAT::Utils->nodeonmynet($_)) { + next; + } addnode $_; } } @@ -340,12 +333,14 @@ sub addnet { } if ($ent and $ent->{tftpserver}) { $tftp = $ent->{tftpserver}; + } else { #presume myself to be it, dhcp no longer does this for us + $tftp = xCAT::Utils->my_ip_facing($net); } if ($ent and $ent->{gateway}) { $gateway = $ent->{gateway}; } if ($ent and $ent->{dynamicrange}) { - unless ($ent->{dhcpserver} and thishostisnot($ent->{dhcpserver})) { #If specific, only one dhcp server gets a dynamic range + unless ($ent->{dhcpserver} and xCAT::Utils->thishostisnot($ent->{dhcpserver})) { #If specific, only one dhcp server gets a dynamic range $range = $ent->{dynamicrange}; $range =~ s/[,-]/ /g; }