2011-01-27 15:34:22 +00:00
|
|
|
# IBM(c) 2010 EPL license http://www.eclipse.org/legal/epl-v10.html
|
2007-10-26 22:44:33 +00:00
|
|
|
package xCAT_plugin::dhcp;
|
2010-06-08 19:22:25 +00:00
|
|
|
BEGIN
|
|
|
|
{
|
|
|
|
$::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : '/opt/xcat';
|
|
|
|
}
|
|
|
|
use lib "$::XCATROOT/lib/perl";
|
|
|
|
|
2008-07-18 18:40:45 +00:00
|
|
|
use strict;
|
2013-05-15 20:36:34 +00:00
|
|
|
use IPC::Open2;
|
2007-10-26 22:44:33 +00:00
|
|
|
use xCAT::Table;
|
2013-12-30 03:02:02 +00:00
|
|
|
#use Data::Dumper;
|
2007-10-26 22:44:33 +00:00
|
|
|
use MIME::Base64;
|
2007-11-28 14:57:57 +00:00
|
|
|
use Getopt::Long;
|
|
|
|
Getopt::Long::Configure("bundling");
|
|
|
|
Getopt::Long::Configure("pass_through");
|
2007-10-26 22:44:33 +00:00
|
|
|
use Socket;
|
2011-01-17 19:17:38 +00:00
|
|
|
my $candoipv6 = eval {
|
|
|
|
require Socket6;
|
|
|
|
1;
|
|
|
|
};
|
2007-10-26 22:44:33 +00:00
|
|
|
use Sys::Syslog;
|
|
|
|
use IPC::Open2;
|
2008-02-07 20:11:52 +00:00
|
|
|
use xCAT::Utils;
|
2012-08-09 04:07:40 +00:00
|
|
|
use xCAT::TableUtils;
|
|
|
|
use xCAT::NetworkUtils qw/getipaddr/;
|
|
|
|
use xCAT::ServiceNodeUtils;
|
2008-06-21 14:08:59 +00:00
|
|
|
use xCAT::NodeRange;
|
2009-03-28 15:03:36 +00:00
|
|
|
use Fcntl ':flock';
|
2007-10-26 22:44:33 +00:00
|
|
|
|
2011-06-01 17:41:12 +00:00
|
|
|
my @aixcfg; # hold AIX entries created by NIM
|
2007-10-26 22:44:33 +00:00
|
|
|
my @dhcpconf; #Hold DHCP config file contents to be written back.
|
2011-01-17 19:17:38 +00:00
|
|
|
my @dhcp6conf; #ipv6 equivalent
|
2008-11-26 00:00:54 +00:00
|
|
|
my @nrn; # To hold output of networks table to be consulted throughout process
|
2011-01-17 19:17:38 +00:00
|
|
|
my @nrn6; #holds ip -6 route output on Linux, yeah, name doesn't make much sense now..
|
2013-01-12 20:03:37 +00:00
|
|
|
my $site_domain;
|
|
|
|
my @alldomains;
|
2007-10-26 22:44:33 +00:00
|
|
|
my $omshell;
|
2011-01-17 19:17:38 +00:00
|
|
|
my $omshell6; #separate session to DHCPv6 instance of dhcp
|
2008-05-06 18:49:22 +00:00
|
|
|
my $statements; #Hold custom statements to be slipped into host declarations
|
2013-05-21 12:22:17 +00:00
|
|
|
my $localonly; # flag for running only on local server - needs to be global
|
2007-11-28 14:57:57 +00:00
|
|
|
my $callback;
|
2008-05-15 17:45:47 +00:00
|
|
|
my $restartdhcp;
|
2011-01-17 19:17:38 +00:00
|
|
|
my $restartdhcp6;
|
2009-03-26 20:08:18 +00:00
|
|
|
my $sitenameservers;
|
|
|
|
my $sitentpservers;
|
|
|
|
my $sitelogservers;
|
2008-07-18 18:56:38 +00:00
|
|
|
my $nrhash;
|
|
|
|
my $machash;
|
2011-01-17 19:17:38 +00:00
|
|
|
my $vpdhash;
|
2008-10-30 14:37:56 +00:00
|
|
|
my $iscsients;
|
2011-09-15 22:00:55 +00:00
|
|
|
my $nodetypeents;
|
2008-10-30 14:37:56 +00:00
|
|
|
my $chainents;
|
2012-08-09 04:07:40 +00:00
|
|
|
my $tftpdir = xCAT::TableUtils->getTftpDir();
|
2011-01-17 19:17:38 +00:00
|
|
|
use Math::BigInt;
|
2009-07-07 02:07:30 +00:00
|
|
|
my $dhcpconffile = $^O eq 'aix' ? '/etc/dhcpsd.cnf' : '/etc/dhcpd.conf';
|
2010-06-16 18:47:53 +00:00
|
|
|
my %dynamicranges; #track dynamic ranges defined to see if a host that resolves is actually a dynamic address
|
2011-01-17 19:17:38 +00:00
|
|
|
my %netcfgs;
|
2011-08-15 00:49:23 +00:00
|
|
|
my $distro = xCAT::Utils->osver();
|
2010-06-16 18:47:53 +00:00
|
|
|
|
2010-06-30 09:54:19 +00:00
|
|
|
# dhcp 4.x will use /etc/dhcp/dhcpd.conf as the config file
|
2011-01-17 19:17:38 +00:00
|
|
|
my $dhcp6conffile;
|
2010-06-30 09:54:19 +00:00
|
|
|
if ( $^O ne 'aix' and -d "/etc/dhcp" ) {
|
|
|
|
$dhcpconffile = '/etc/dhcp/dhcpd.conf';
|
2011-01-17 19:17:38 +00:00
|
|
|
$dhcp6conffile = '/etc/dhcp/dhcpd6.conf';
|
2010-06-30 09:54:19 +00:00
|
|
|
}
|
2011-01-17 19:17:38 +00:00
|
|
|
my $usingipv6;
|
2010-06-30 09:54:19 +00:00
|
|
|
|
2013-12-30 03:02:02 +00:00
|
|
|
# define usage statement
|
|
|
|
my $usage="Usage: makedhcp -n\n\tmakedhcp -a\n\tmakedhcp -a -d\n\tmakedhcp -d noderange\n\tmakedhcp <noderange> [-s statements]\n\tmakedhcp -q\n\tmakedhcp [-h|--help]";
|
|
|
|
|
|
|
|
|
2011-08-15 00:49:23 +00:00
|
|
|
# is this ubuntu ?
|
2011-10-06 17:45:08 +00:00
|
|
|
if ( $distro =~ /ubuntu.*/ ){
|
2013-01-05 02:50:27 +00:00
|
|
|
if (-e '/etc/dhcp/') {
|
2012-08-30 02:16:24 +00:00
|
|
|
$dhcpconffile = '/etc/dhcp/dhcpd.conf';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$dhcpconffile = '/etc/dhcp3/dhcpd.conf';
|
|
|
|
}
|
2011-08-15 00:49:23 +00:00
|
|
|
}
|
|
|
|
|
2011-09-15 22:00:55 +00:00
|
|
|
sub check_uefi_support {
|
|
|
|
my $ntent = shift;
|
|
|
|
my %blacklist = (
|
2011-09-19 20:34:37 +00:00
|
|
|
"win2k3.*" => 1,
|
|
|
|
"winxp.*" => 1,
|
|
|
|
"SL5.*" => 1,
|
2011-09-15 22:00:55 +00:00
|
|
|
"rhels5.*" => 1,
|
|
|
|
"centos5.*" => 1,
|
|
|
|
"sl5.*" => 1,
|
|
|
|
"sles10.*" => 1,
|
|
|
|
"esxi4.*" => 1);
|
|
|
|
if ($ntent and $ntent->{os}) {
|
|
|
|
foreach (keys %blacklist) {
|
|
|
|
if ($ntent->{os} =~ /$_/) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-01-04 21:03:47 +00:00
|
|
|
if ($ntent->{os} =~ /^win/ or $ntent->{os} =~ /^hyperv/) { #UEFI support is a tad different, need to punt..
|
2011-09-19 20:34:37 +00:00
|
|
|
return 2;
|
|
|
|
}
|
2011-09-15 22:00:55 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-12-10 10:34:09 +00:00
|
|
|
# check whether the proxydhcp has been enabled.
|
|
|
|
sub proxydhcp {
|
2013-12-19 09:53:49 +00:00
|
|
|
my $nrent = shift;
|
|
|
|
|
|
|
|
if ($nrent && defined $nrent->{'proxydhcp'} && $nrent->{'proxydhcp'} =~ /0|no|n/i) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
my @output = xCAT::Utils->runcmd("ps -C proxydhcp-xcat", -1);
|
2013-12-10 10:34:09 +00:00
|
|
|
if (@output) {
|
2013-12-19 09:53:49 +00:00
|
|
|
if (grep /proxydhcp-xcat/, @output) {
|
2013-12-10 10:34:09 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2011-09-15 22:00:55 +00:00
|
|
|
|
2011-06-01 17:41:12 +00:00
|
|
|
sub ipIsDynamic {
|
|
|
|
#meant to be v4/v6 agnostic. DHCPv6 however takes some care to allow a dynamic range to overlap static reservations
|
|
|
|
#xCAT will for now continue to advise people to keep their nodes out of the dynamic range
|
2010-06-16 18:47:53 +00:00
|
|
|
my $ip = shift;
|
2011-01-17 19:17:38 +00:00
|
|
|
my $number = getipaddr($ip,GetNumber=>1);
|
2010-06-16 18:47:53 +00:00
|
|
|
unless ($number) { # shouldn't be possible, but pessimistically presume it dynamically if so
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
foreach (values %dynamicranges) {
|
|
|
|
if ($_->[0] <= $number and $_->[1] >= $number) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0; #it isn't in any of the dynamic ranges we are aware of
|
|
|
|
}
|
2007-10-26 22:44:33 +00:00
|
|
|
|
2008-05-06 18:49:22 +00:00
|
|
|
sub handled_commands
|
|
|
|
{
|
|
|
|
return {makedhcp => "dhcp",};
|
2007-10-26 22:44:33 +00:00
|
|
|
}
|
|
|
|
|
2013-05-28 15:30:40 +00:00
|
|
|
######################################################
|
|
|
|
# List nodes in DHCP for both IPv4 and IPv6
|
|
|
|
######################################################
|
2013-05-15 20:36:34 +00:00
|
|
|
sub listnode
|
|
|
|
{
|
|
|
|
my $node = shift;
|
|
|
|
my $callback = shift;
|
|
|
|
my $lines;
|
|
|
|
my $ipaddr = "";
|
|
|
|
my $hwaddr;
|
|
|
|
my $nname;
|
|
|
|
my $rsp;
|
|
|
|
my ($OMOUT,$OMIN,$OMOUT6,$OMIN6);
|
|
|
|
|
|
|
|
my $usingipv6;
|
|
|
|
my $omapiuser;
|
|
|
|
my $omapikey;
|
|
|
|
# Collect the omapi user and key from the passwd table
|
|
|
|
my $pwtab = xCAT::Table->new("passwd");
|
|
|
|
my @pws = $pwtab->getAllAttribs('key','username','password','cryptmethod','authdomain','comments','disable');
|
|
|
|
foreach (@pws) {
|
2013-05-28 15:30:40 +00:00
|
|
|
# Look for the opapi entry in the passwd table
|
2013-05-15 20:36:34 +00:00
|
|
|
if ($_->{key} =~ "omapi") { #omapi key
|
2013-05-28 15:30:40 +00:00
|
|
|
# save username and password for omapi connection
|
2013-05-15 20:36:34 +00:00
|
|
|
$omapiuser = $_->{username};
|
|
|
|
$omapikey = $_->{password};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
# Look through the networks table for networks with IPv6 format for address
|
|
|
|
my $nettab = xCAT::Table->new("networks");
|
|
|
|
my @vnets = $nettab->getAllAttribs('net','mgtifname','mask','dynamicrange','nameservers','ddnsdomain', 'domain');
|
|
|
|
foreach (@vnets) {
|
|
|
|
if ($_->{net} =~ /:/) { #IPv6 detected
|
|
|
|
$usingipv6=1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-28 15:30:40 +00:00
|
|
|
# open ipv4 omshell file handles - $OMOUT will contain the response
|
2013-05-15 20:36:34 +00:00
|
|
|
open2($OMOUT,$OMIN,"/usr/bin/omshell ");
|
|
|
|
|
2013-05-28 15:30:40 +00:00
|
|
|
# setup omapi for the connection and check for the node requested
|
2013-05-15 20:36:34 +00:00
|
|
|
print $OMIN "key "
|
|
|
|
. $omapiuser . " \""
|
|
|
|
. $omapikey . "\"\n";
|
|
|
|
print $OMIN "connect\n";
|
|
|
|
print $OMIN "new host\n";
|
2013-05-28 15:30:40 +00:00
|
|
|
# specify which node we are looking up
|
2013-05-15 20:36:34 +00:00
|
|
|
print $OMIN "set name = \"$node\"\n";
|
|
|
|
print $OMIN "open\n";
|
2013-05-28 15:30:40 +00:00
|
|
|
# the close will put the data into $OMOUT
|
2013-05-15 20:36:34 +00:00
|
|
|
print $OMIN "close\n";
|
|
|
|
close ($OMIN);
|
|
|
|
my $name = 0;
|
2013-05-28 15:30:40 +00:00
|
|
|
|
|
|
|
# Process the output
|
2013-05-15 20:36:34 +00:00
|
|
|
while (<$OMOUT>) { # now read the output of sort(1)
|
2013-05-28 15:30:40 +00:00
|
|
|
chomp $_;
|
|
|
|
# if this line contains the node name
|
2013-05-15 20:36:34 +00:00
|
|
|
if ($_ =~ $node) {
|
2013-05-28 15:30:40 +00:00
|
|
|
# save the name returned
|
|
|
|
if ($name) {
|
|
|
|
$nname = $_;
|
|
|
|
$nname =~ s/name = //;
|
|
|
|
$nname =~ s/"//g;
|
|
|
|
}
|
|
|
|
$name =1;
|
|
|
|
}
|
|
|
|
# if this line is the hardware-address line
|
2013-05-15 20:36:34 +00:00
|
|
|
if ($_ =~ 'hardware-address') {
|
2013-05-28 15:30:40 +00:00
|
|
|
# save the hardware address as it is with the hardware-address label
|
|
|
|
$hwaddr = $_;
|
2013-05-15 20:36:34 +00:00
|
|
|
}
|
2013-05-28 15:30:40 +00:00
|
|
|
# if this line is the ip-address line
|
2013-05-15 20:36:34 +00:00
|
|
|
elsif ($_ =~ 'ip-address') {
|
2013-05-28 15:30:40 +00:00
|
|
|
# convert the hex IP address to a dotted decimal address for readability
|
|
|
|
my ($ipname,$ip) = split /= /,$_;
|
|
|
|
chomp($ip);
|
|
|
|
my ($p1, $p2, $p3, $p4) = split(/\:/, $ip);
|
|
|
|
my $dp1 = hex($p1);
|
|
|
|
my $dp2 = hex($p2);
|
|
|
|
my $dp3 = hex($p3);
|
|
|
|
my $dp4 = hex($p4);
|
|
|
|
$ipaddr = "ip-address = $dp1.$dp2.$dp3.$dp4";
|
2013-05-15 20:36:34 +00:00
|
|
|
}
|
|
|
|
}
|
2013-05-28 15:30:40 +00:00
|
|
|
# if we collected the ip address then print out the information for this node
|
2013-05-15 20:36:34 +00:00
|
|
|
if ($ipaddr) {
|
|
|
|
push @{$rsp->{data}}, "$nname: $ipaddr, $hwaddr";
|
|
|
|
xCAT::MsgUtils->message("I", $rsp, $callback);
|
|
|
|
}
|
|
|
|
close ($OMOUT);
|
|
|
|
|
2013-05-28 15:30:40 +00:00
|
|
|
# if using IPv6 addresses check using omshell IPv6 port
|
2013-05-15 20:36:34 +00:00
|
|
|
if ($usingipv6) {
|
|
|
|
open2($OMOUT6,$OMIN6,"/usr/bin/omshell ");
|
|
|
|
print $OMOUT6 "port 7912\n";
|
|
|
|
print $OMOUT6 "connect\n";
|
|
|
|
print $OMIN6 "key "
|
|
|
|
. $omapiuser . " \""
|
|
|
|
. $omapikey . "\"\n";
|
|
|
|
print $OMIN6 "connect\n";
|
|
|
|
print $OMIN6 "new host\n";
|
2013-05-28 15:30:40 +00:00
|
|
|
# check for the node specified
|
2013-05-15 20:36:34 +00:00
|
|
|
print $OMIN6 "set name = \"$node\"\n";
|
|
|
|
print $OMIN6 "open\n";
|
|
|
|
print $OMIN6 "close\n";
|
|
|
|
close ($OMIN6);
|
|
|
|
$name = 0;
|
|
|
|
$ipaddr = "";
|
2013-05-28 15:30:40 +00:00
|
|
|
while (<$OMOUT6>) { # now read the output
|
2013-05-15 20:36:34 +00:00
|
|
|
chomp $_;
|
|
|
|
if ($_ =~ $node) {
|
2013-05-28 15:30:40 +00:00
|
|
|
# save the name
|
2013-05-15 20:36:34 +00:00
|
|
|
if ($name) {
|
|
|
|
$nname = $_;
|
|
|
|
$nname =~ s/name = //;
|
|
|
|
$nname =~ s/"//g;
|
|
|
|
}
|
|
|
|
$name =1;
|
|
|
|
}
|
|
|
|
if ($_ =~ 'hardware-address') {
|
2013-05-28 15:30:40 +00:00
|
|
|
# save the hardware-address
|
2013-05-15 20:36:34 +00:00
|
|
|
$hwaddr = $_;
|
|
|
|
}
|
|
|
|
elsif ($_ =~ 'ip-address') {
|
2013-05-28 15:30:40 +00:00
|
|
|
#save the ip address
|
2013-05-15 20:36:34 +00:00
|
|
|
my ($ipname,$ipaddr) = split /= /,$_;
|
|
|
|
chomp($ipaddr);
|
|
|
|
}
|
|
|
|
}
|
2013-05-28 15:30:40 +00:00
|
|
|
# print the information if the ip address is found
|
2013-05-15 20:36:34 +00:00
|
|
|
if ($ipaddr) {
|
|
|
|
push @{$rsp->{data}}, "$nname: $ipaddr, $hwaddr";
|
|
|
|
xCAT::MsgUtils->message("I", $rsp, $callback);
|
|
|
|
}
|
2013-05-28 15:30:40 +00:00
|
|
|
# close the IPv6 output file handle
|
2013-05-15 20:36:34 +00:00
|
|
|
close ($OMOUT6);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-06 18:49:22 +00:00
|
|
|
sub delnode
|
|
|
|
{
|
|
|
|
my $node = shift;
|
|
|
|
my $inetn = inet_aton($node);
|
|
|
|
|
|
|
|
my $mactab = xCAT::Table->new('mac');
|
2008-07-18 18:40:45 +00:00
|
|
|
my $ent;
|
2008-07-18 18:56:38 +00:00
|
|
|
if ($machash) { $ent = $machash->{$node}->[0]; }
|
2008-05-06 18:49:22 +00:00
|
|
|
if ($ent and $ent->{mac})
|
|
|
|
{
|
|
|
|
my @macs = split(/\|/, $ent->{mac});
|
|
|
|
my $mace;
|
2012-03-29 02:57:21 +00:00
|
|
|
my $count = 0;
|
2008-05-06 18:49:22 +00:00
|
|
|
foreach $mace (@macs)
|
|
|
|
{
|
|
|
|
my $mac;
|
|
|
|
my $hname;
|
|
|
|
($mac, $hname) = split(/!/, $mace);
|
2012-03-26 03:48:39 +00:00
|
|
|
|
|
|
|
unless ($hname)
|
|
|
|
{
|
|
|
|
$hname = $node;
|
|
|
|
} #Default to hostname equal to nodename
|
|
|
|
unless ($mac) { next; } #Skip corrupt format
|
|
|
|
|
|
|
|
if ( !grep /:/,$mac ) {
|
|
|
|
$mac = lc($mac);
|
|
|
|
$mac =~ s/(\w{2})/$1:/g;
|
|
|
|
$mac =~ s/:$//;
|
|
|
|
}
|
|
|
|
my $hostname = $hname;
|
|
|
|
my %client_nethash = xCAT::DBobjUtils->getNetwkInfo( [$node] );
|
|
|
|
if ( $client_nethash{$node}{mgtifname} =~ /hf/ )
|
|
|
|
{
|
|
|
|
if ( scalar(@macs) > 1 ) {
|
|
|
|
if ( $hname !~ /^(.*)-hf(.*)$/ ) {
|
|
|
|
$hostname = $hname . "-hf" . $count;
|
|
|
|
} else {
|
|
|
|
$hostname = $1 . "-hf" . $count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$count = $count + 2;
|
|
|
|
|
|
|
|
unless ($hostname) { $hostname = $node; }
|
2008-05-06 18:49:22 +00:00
|
|
|
print $omshell "new host\n";
|
|
|
|
print $omshell
|
2012-03-26 03:48:39 +00:00
|
|
|
"set name = \"$hostname\"\n"; #Find and destroy conflict name
|
2008-05-06 18:49:22 +00:00
|
|
|
print $omshell "open\n";
|
|
|
|
print $omshell "remove\n";
|
|
|
|
print $omshell "close\n";
|
|
|
|
|
|
|
|
if ($mac)
|
|
|
|
{
|
|
|
|
print $omshell "new host\n";
|
|
|
|
print $omshell "set hardware-address = " . $mac
|
|
|
|
. "\n"; #find and destroy mac conflict
|
|
|
|
print $omshell "open\n";
|
|
|
|
print $omshell "remove\n";
|
|
|
|
print $omshell "close\n";
|
|
|
|
}
|
|
|
|
if ($inetn)
|
|
|
|
{
|
|
|
|
my $ip;
|
2012-03-26 03:48:39 +00:00
|
|
|
if (inet_aton($hostname))
|
2008-05-06 18:49:22 +00:00
|
|
|
{
|
2012-03-26 03:48:39 +00:00
|
|
|
$ip = inet_ntoa(inet_aton($hostname));
|
2008-05-06 18:49:22 +00:00
|
|
|
}
|
|
|
|
if ($ip)
|
|
|
|
{
|
|
|
|
print $omshell "new host\n";
|
|
|
|
print $omshell
|
|
|
|
"set ip-address = $ip\n"; #find and destroy ip conflict
|
|
|
|
print $omshell "open\n";
|
|
|
|
print $omshell "remove\n";
|
|
|
|
print $omshell "close\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-10-26 22:44:33 +00:00
|
|
|
print $omshell "new host\n";
|
2008-05-06 18:49:22 +00:00
|
|
|
print $omshell "set name = \"$node\"\n"; #Find and destroy conflict name
|
2007-10-26 22:44:33 +00:00
|
|
|
print $omshell "open\n";
|
|
|
|
print $omshell "remove\n";
|
|
|
|
print $omshell "close\n";
|
2008-05-06 18:49:22 +00:00
|
|
|
if ($inetn)
|
|
|
|
{
|
|
|
|
my $ip = inet_ntoa(inet_aton($node));
|
|
|
|
unless ($ip) { return; }
|
|
|
|
print $omshell "new host\n";
|
|
|
|
print $omshell "set ip-address = $ip\n"; #find and destroy ip conflict
|
|
|
|
print $omshell "open\n";
|
|
|
|
print $omshell "remove\n";
|
|
|
|
print $omshell "close\n";
|
|
|
|
}
|
2007-10-26 22:44:33 +00:00
|
|
|
}
|
|
|
|
|
2011-01-17 19:17:38 +00:00
|
|
|
sub addnode6 {
|
|
|
|
#omshell to add host dynamically
|
|
|
|
my $node = shift;
|
|
|
|
unless ($vpdhash) {
|
2012-04-30 19:42:06 +00:00
|
|
|
$callback->({node=>[{name=>[$node],warning => ["Skipping DHCPv6 setup due to missing vpd.uuid information."]}]});
|
2011-01-17 19:17:38 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
my $ent = $vpdhash->{$node}->[0]; #tab->getNodeAttribs($node, [qw(mac)]);
|
|
|
|
unless ($ent and $ent->{uuid})
|
|
|
|
{
|
2012-04-30 19:42:06 +00:00
|
|
|
$callback->({node=>[{name=>[$node],warning => ["Skipping DHCPv6 setup due to missing vpd.uuid information."]}]});
|
2011-01-17 19:17:38 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#phase 1, dynamic and static addresses, hopefully ddns-hostname works, may be tricky to do 'send hostname'
|
|
|
|
#since FQDN is the only thing to be sent down, and that RFC clearly suggests that the client
|
|
|
|
#assembles that data, not host
|
|
|
|
#tricky for us since the client wouldn't know it's hostname/fqdn in advance
|
|
|
|
#unless acquired via IPv4 first
|
|
|
|
#don't think dhclient is smart enough to assemble advertised domain with it's own name and then
|
|
|
|
#request FQDN update
|
|
|
|
#goal is simple enough, we want `hostname` to look sane *and* we want DNS to look right
|
|
|
|
my $uuid = $ent->{uuid};
|
|
|
|
$uuid =~ s/-//g;
|
|
|
|
$uuid =~ s/(..)/$1:/g;
|
|
|
|
$uuid =~ s/:\z//;
|
|
|
|
$uuid =~ s/^/00:04:/;
|
|
|
|
my $ip = getipaddr($node);
|
|
|
|
if ($ip and $ip =~ /:/ and not ipIsDynamic($ip)) {
|
|
|
|
$ip = getipaddr($ip,GetNumber=>1);
|
|
|
|
$ip = $ip->as_hex;
|
|
|
|
$ip =~ s/^0x//;
|
|
|
|
$ip =~ s/(..)/$1:/g;
|
|
|
|
$ip =~ s/:\z//;
|
|
|
|
print $omshell6 "set ip-address = $ip\n";
|
|
|
|
} else {
|
|
|
|
$ip=0;
|
|
|
|
}
|
|
|
|
print $omshell6 "new host\n";
|
|
|
|
print $omshell6 "set name = \"$node\"\n"; #Find and destroy conflict name
|
|
|
|
print $omshell6 "open\n";
|
|
|
|
print $omshell6 "remove\n";
|
|
|
|
print $omshell6 "close\n";
|
|
|
|
if ($ip) {
|
|
|
|
print $omshell6 "new host\n";
|
|
|
|
print $omshell6 "set ip-address = $ip\n"; #find and destroy ip conflict
|
|
|
|
print $omshell6 "open\n";
|
|
|
|
print $omshell6 "remove\n";
|
|
|
|
print $omshell6 "close\n";
|
|
|
|
}
|
|
|
|
print $omshell6 "new host\n";
|
|
|
|
print $omshell6 "set dhcp-client-identifier = " . $uuid . "\n"; #find and destroy DUID-UUID conflict
|
|
|
|
print $omshell6 "open\n";
|
|
|
|
print $omshell6 "remove\n";
|
|
|
|
print $omshell6 "close\n";
|
|
|
|
print $omshell6 "new host\n";
|
|
|
|
print $omshell6 "set name = \"$node\"\n";
|
|
|
|
print $omshell6 "set dhcp-client-identifier = $uuid\n";
|
2011-01-27 15:34:22 +00:00
|
|
|
print $omshell6 'set statements = "ddns-hostname \"'.$node.'\";";'."\n";
|
2011-01-17 19:17:38 +00:00
|
|
|
if ($ip) {
|
|
|
|
print $omshell6 "set ip-address = $ip\n";
|
|
|
|
}
|
|
|
|
print $omshell6 "create\n";
|
|
|
|
print $omshell6 "close\n";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-05-06 18:49:22 +00:00
|
|
|
sub addnode
|
|
|
|
{
|
|
|
|
|
|
|
|
#Use omshell to add the node.
|
|
|
|
#the process used is blind typing commands that should work
|
|
|
|
#it tries to delet any conflicting entries matched by name and
|
|
|
|
#hardware address and ip address before creating a brand now one
|
|
|
|
#unfortunate side effect: dhcpd.leases can look ugly over time, when
|
|
|
|
#doing updates would keep it cleaner, good news, dhcpd restart cleans
|
|
|
|
#up the lease file the way we would want anyway.
|
|
|
|
my $node = shift;
|
|
|
|
my $ent;
|
2008-10-30 14:37:56 +00:00
|
|
|
my $nrent;
|
|
|
|
my $chainent;
|
|
|
|
my $ient;
|
2011-09-15 22:00:55 +00:00
|
|
|
my $ntent;
|
2009-07-07 02:07:30 +00:00
|
|
|
my $tftpserver;
|
2008-10-30 14:37:56 +00:00
|
|
|
if ($chainents and $chainents->{$node}) {
|
|
|
|
$chainent = $chainents->{$node}->[0];
|
|
|
|
}
|
|
|
|
if ($iscsients and $iscsients->{$node}) {
|
|
|
|
$ient = $iscsients->{$node}->[0];
|
|
|
|
}
|
2011-09-15 22:00:55 +00:00
|
|
|
if ($nodetypeents and $nodetypeents->{$node}) {
|
|
|
|
$ntent = $nodetypeents->{$node}->[0];
|
|
|
|
}
|
2008-05-06 18:49:22 +00:00
|
|
|
my $lstatements = $statements;
|
|
|
|
my $guess_next_server = 0;
|
2009-08-21 23:58:12 +00:00
|
|
|
my $nxtsrv;
|
2008-07-18 18:56:38 +00:00
|
|
|
if ($nrhash)
|
2008-05-06 18:49:22 +00:00
|
|
|
{
|
2008-10-30 14:37:56 +00:00
|
|
|
$nrent = $nrhash->{$node}->[0];
|
|
|
|
if ($nrent and $nrent->{tftpserver})
|
2008-05-06 18:49:22 +00:00
|
|
|
{
|
2009-07-21 06:48:40 +00:00
|
|
|
#check the value of inet_ntoa(inet_aton("")),if the hostname cannot be resolved,
|
|
|
|
#the value of inet_ntoa() will be "undef", which will cause fatal error
|
|
|
|
my $tmp_name = inet_aton($nrent->{tftpserver});
|
|
|
|
unless($tmp_name) {
|
|
|
|
#tell the reason to the user
|
|
|
|
$callback->(
|
|
|
|
{ error => ["Unable to resolve the tftpserver for node"], errorcode => [1]}
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$tftpserver = inet_ntoa($tmp_name);
|
2009-08-21 23:58:12 +00:00
|
|
|
$nxtsrv = $tftpserver;
|
2008-05-06 18:49:22 +00:00
|
|
|
$lstatements =
|
|
|
|
'next-server '
|
2009-07-07 02:07:30 +00:00
|
|
|
. $tftpserver . ';'
|
2008-05-06 18:49:22 +00:00
|
|
|
. $statements;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$guess_next_server = 1;
|
|
|
|
}
|
2007-10-26 22:44:33 +00:00
|
|
|
|
2008-05-06 18:49:22 +00:00
|
|
|
#else {
|
2008-10-30 14:37:56 +00:00
|
|
|
# $nrent = $nrtab->getNodeAttribs($node,['servicenode']);
|
|
|
|
# if ($nrent and $nrent->{servicenode}) {
|
|
|
|
# $statements = 'next-server = \"'.inet_ntoa(inet_aton($nrent->{servicenode})).'\";'.$statements;
|
2008-05-06 18:49:22 +00:00
|
|
|
# }
|
|
|
|
#}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$guess_next_server = 1;
|
|
|
|
}
|
2008-07-18 18:56:38 +00:00
|
|
|
unless ($machash)
|
2008-05-06 18:49:22 +00:00
|
|
|
{
|
|
|
|
$callback->(
|
|
|
|
{
|
2011-06-20 14:41:28 +00:00
|
|
|
warning => ["Unable to open mac table, it may not exist yet"]
|
2008-05-06 18:49:22 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
2008-07-18 18:56:38 +00:00
|
|
|
$ent = $machash->{$node}->[0]; #tab->getNodeAttribs($node, [qw(mac)]);
|
2008-05-06 18:49:22 +00:00
|
|
|
unless ($ent and $ent->{mac})
|
|
|
|
{
|
|
|
|
$callback->(
|
|
|
|
{
|
2011-06-20 14:41:28 +00:00
|
|
|
warning => ["Unable to find mac address for $node"]
|
2008-05-06 18:49:22 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
my @macs = split(/\|/, $ent->{mac});
|
|
|
|
my $mace;
|
2010-06-15 15:21:29 +00:00
|
|
|
my $deflstaments=$lstatements;
|
2011-06-30 08:14:24 +00:00
|
|
|
my $count = 0;
|
2008-05-06 18:49:22 +00:00
|
|
|
foreach $mace (@macs)
|
|
|
|
{
|
2010-06-15 15:21:29 +00:00
|
|
|
$lstatements=$deflstaments; #force recalc on every entry
|
2008-05-06 18:49:22 +00:00
|
|
|
my $mac;
|
|
|
|
my $hname;
|
|
|
|
$hname = "";
|
|
|
|
($mac, $hname) = split(/!/, $mace);
|
|
|
|
unless ($hname)
|
|
|
|
{
|
|
|
|
$hname = $node;
|
|
|
|
} #Default to hostname equal to nodename
|
|
|
|
unless ($mac) { next; } #Skip corrupt format
|
2011-01-27 19:12:56 +00:00
|
|
|
my $ip = getipaddr($hname,OnlyV4=>1);
|
2010-04-01 19:10:37 +00:00
|
|
|
if ($hname eq '*NOIP*') {
|
|
|
|
$hname = $node . "-noip".$mac;
|
|
|
|
$hname =~ s/://g;
|
2010-06-01 20:40:23 +00:00
|
|
|
$ip='DENIED';
|
2010-06-03 12:49:23 +00:00
|
|
|
# } #if 'guess_next_server', inherit from the network provided value... see how this pans out
|
|
|
|
# if ($guess_next_server and $ip and $ip ne "DENIED")
|
|
|
|
# {
|
2012-08-09 04:07:40 +00:00
|
|
|
# $nxtsrv = xCAT::NetworkUtils->my_ip_facing($hname);
|
2010-06-03 12:49:23 +00:00
|
|
|
# if ($nxtsrv)
|
|
|
|
# {
|
|
|
|
# $tftpserver = $nxtsrv;
|
|
|
|
# $lstatements = "next-server $nxtsrv;$statements";
|
|
|
|
# } #of course, we set the xNBA variable to let that propogation carry forward into filename uri interpolation
|
2010-06-01 20:40:23 +00:00
|
|
|
} elsif ($guess_next_server) {
|
|
|
|
$nxtsrv='${next-server}'; #if floating IP support, cause gPXE command-line expansion patch to drive inheritence from network
|
2008-05-06 18:49:22 +00:00
|
|
|
}
|
2009-06-29 18:37:45 +00:00
|
|
|
my $doiscsi=0;
|
2008-10-30 14:37:56 +00:00
|
|
|
if ($ient and $ient->{server} and $ient->{target}) {
|
2009-06-29 18:37:45 +00:00
|
|
|
$doiscsi=1;
|
2009-07-06 21:05:44 +00:00
|
|
|
unless (defined ($ient->{lun})) { #Some firmware fails to properly implement the spec, so we must explicitly say zero for such firmware
|
|
|
|
$ient->{lun} = 0;
|
|
|
|
}
|
|
|
|
my $iscsirootpath ='iscsi:'.$ient->{server}.':6:3260:'.$ient->{lun}.':'.$ient->{target};
|
|
|
|
if (defined ($ient->{iname})) { #Attempt to use gPXE or IBM iSCSI formats to specify the initiator
|
|
|
|
#This all goes on one line, but will break it out to at least be readable in here
|
|
|
|
$lstatements = 'if option vendor-class-identifier = \"ISAN\" { ' #This is declared by IBM iSCSI initiators, will call it 'ISAN' mode
|
|
|
|
.'option isan.iqn \"'.$ient->{iname}.'\"; ' #Use vendor-spcefic option to declare the expected Initiator name
|
|
|
|
.'option isan.root-path \"'.$iscsirootpath.'\"; ' #We must *not* use standard root-path if using ISAN style options
|
|
|
|
.'} else { '
|
|
|
|
.'option root-path \"'.$iscsirootpath.'\"; ' #For everything but ISAN, use standard, RFC defined behavior for root
|
|
|
|
.'if exists gpxe.bus-id { ' #Since our iscsi-initiator-iqn is in no way a standardized thing, only use it for gPXE
|
|
|
|
. ' option iscsi-initiator-iqn \"'.$ient->{iname}.'\";' #gPXE will consider option 203 for initiator IQN
|
|
|
|
. '}'
|
|
|
|
. '}'
|
|
|
|
.$lstatements;
|
|
|
|
print $lstatements;
|
|
|
|
} else { #We stick to the good old RFC defined behavior, ISAN, gPXE, everyone should be content with this so long as no initiator name need be specified
|
|
|
|
$lstatements = 'option root-path \"'.$iscsirootpath.'\";'.$lstatements;
|
2008-10-30 14:37:56 +00:00
|
|
|
}
|
2009-06-29 18:37:45 +00:00
|
|
|
}
|
2011-09-15 22:00:55 +00:00
|
|
|
my $douefi=check_uefi_support($ntent);
|
2009-09-28 14:07:42 +00:00
|
|
|
if ($nrent and $nrent->{netboot} and $nrent->{netboot} eq 'xnba' and $lstatements !~ /filename/) {
|
2009-07-06 21:05:44 +00:00
|
|
|
if (-f "$tftpdir/xcat/xnba.kpxe") {
|
2009-06-29 18:37:45 +00:00
|
|
|
if ($doiscsi and $chainent and $chainent->{currstate} and ($chainent->{currstate} eq 'iscsiboot' or $chainent->{currstate} eq 'boot')) {
|
2011-10-18 15:20:03 +00:00
|
|
|
$lstatements = 'if option client-architecture = 00:00 and not exists gpxe.bus-id { filename = \"xcat/xnba.kpxe\"; } else { filename = \"\"; } '.$lstatements;
|
2009-06-29 18:37:45 +00:00
|
|
|
} else {
|
2013-12-10 10:34:09 +00:00
|
|
|
# If proxydhcp daemon is enabled for windows deployment, do vendor-class-identifier of "PXEClient" to bump it over to proxydhcp.c
|
|
|
|
if (($douefi == 2 and $chainent->{currstate} =~ /^install/) or $chainent->{currstate} =~ /^winshell/) {
|
2013-12-19 09:53:49 +00:00
|
|
|
if (proxydhcp($nrent)){ #proxy dhcp required in uefi invocation
|
2013-12-10 10:34:09 +00:00
|
|
|
$lstatements = 'if option client-architecture = 00:00 or option client-architecture = 00:07 or option client-architecture = 00:09 { filename = \"\"; option vendor-class-identifier \"PXEClient\"; } else { filename = \"\"; }'.$lstatements; #If proxydhcp daemon is enable, use it.
|
|
|
|
} else {
|
|
|
|
$lstatements = 'if option user-class-identifier = \"xNBA\" and option client-architecture = 00:00 { always-broadcast on; filename = \"http://'.$nxtsrv.'/tftpboot/xcat/xnba/nodes/'.$node.'\"; } else if option client-architecture = 00:07 or option client-architecture = 00:09 { filename = \"\"; option vendor-class-identifier \"PXEClient\"; } else if option client-architecture = 00:00 { filename = \"xcat/xnba.kpxe\"; } else { filename = \"\"; }'.$lstatements; #Only PXE compliant clients should ever receive xNBA
|
|
|
|
}
|
|
|
|
} elsif ($douefi and $chainent->{currstate} ne "boot" and $chainent->{currstate} ne "iscsiboot") {
|
2011-09-19 17:21:32 +00:00
|
|
|
$lstatements = 'if option user-class-identifier = \"xNBA\" and option client-architecture = 00:00 { always-broadcast on; filename = \"http://'.$nxtsrv.'/tftpboot/xcat/xnba/nodes/'.$node.'\"; } else if option user-class-identifier = \"xNBA\" and option client-architecture = 00:09 { filename = \"http://'.$nxtsrv.'/tftpboot/xcat/xnba/nodes/'.$node.'.uefi\"; } else if option client-architecture = 00:07 { filename = \"xcat/xnba.efi\"; } else if option client-architecture = 00:00 { filename = \"xcat/xnba.kpxe\"; } else { filename = \"\"; }'.$lstatements; #Only PXE compliant clients should ever receive xNBA
|
2013-12-10 10:34:09 +00:00
|
|
|
} else {
|
2011-09-16 22:55:25 +00:00
|
|
|
$lstatements = 'if option user-class-identifier = \"xNBA\" and option client-architecture = 00:00 { filename = \"http://'.$nxtsrv.'/tftpboot/xcat/xnba/nodes/'.$node.'\"; } else if option client-architecture = 00:00 { filename = \"xcat/xnba.kpxe\"; } else { filename = \"\"; }'.$lstatements; #Only PXE compliant clients should ever receive xNBA
|
2013-12-10 10:34:09 +00:00
|
|
|
}
|
2009-06-29 18:37:45 +00:00
|
|
|
}
|
|
|
|
} #TODO: warn when windows
|
2009-09-28 14:07:42 +00:00
|
|
|
} elsif ($nrent and $nrent->{netboot} and $nrent->{netboot} eq 'pxe' and $lstatements !~ /filename/) {
|
|
|
|
if (-f "$tftpdir/xcat/xnba.kpxe") {
|
|
|
|
if ($doiscsi and $chainent and $chainent->{currstate} and ($chainent->{currstate} eq 'iscsiboot' or $chainent->{currstate} eq 'boot')) {
|
|
|
|
$lstatements = 'if exists gpxe.bus-id { filename = \"\"; } else if exists client-architecture { filename = \"xcat/xnba.kpxe\"; } '.$lstatements;
|
|
|
|
} else {
|
2010-03-04 15:30:12 +00:00
|
|
|
$lstatements = 'if option vendor-class-identifier = \"ScaleMP\" { filename = \"vsmp/pxelinux.0\"; } else { filename = \"pxelinux.0\"; }'.$lstatements;
|
2009-09-28 14:07:42 +00:00
|
|
|
}
|
|
|
|
}
|
2008-10-30 14:37:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-07 02:07:30 +00:00
|
|
|
if ( $^O eq 'aix')
|
|
|
|
{
|
|
|
|
addnode_aix( $ip, $mac, $hname, $tftpserver);
|
2008-05-06 18:49:22 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-04-02 11:09:24 +00:00
|
|
|
if ( !grep /:/,$mac ) {
|
|
|
|
$mac = lc($mac);
|
|
|
|
$mac =~ s/(\w{2})/$1:/g;
|
|
|
|
$mac =~ s/:$//;
|
|
|
|
}
|
2011-06-30 08:14:24 +00:00
|
|
|
my $hostname = $hname;
|
|
|
|
my $hardwaretype = 1;
|
|
|
|
my %client_nethash = xCAT::DBobjUtils->getNetwkInfo( [$node] );
|
|
|
|
if ( $client_nethash{$node}{mgtifname} =~ /hf/ )
|
|
|
|
{
|
|
|
|
$hardwaretype = 37;
|
|
|
|
if ( scalar(@macs) > 1 ) {
|
|
|
|
if ( $hname !~ /^(.*)-hf(.*)$/ ) {
|
|
|
|
$hostname = $hname . "-hf" . $count;
|
|
|
|
} else {
|
|
|
|
$hostname = $1 . "-hf" . $count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-04-02 11:09:24 +00:00
|
|
|
|
2009-07-07 02:07:30 +00:00
|
|
|
#syslog("local4|err", "Setting $node ($hname|$ip) to " . $mac);
|
|
|
|
print $omshell "new host\n";
|
|
|
|
print $omshell
|
2011-06-30 08:14:24 +00:00
|
|
|
"set name = \"$hostname\"\n"; #Find and destroy conflict name
|
2009-07-07 02:07:30 +00:00
|
|
|
print $omshell "open\n";
|
|
|
|
print $omshell "remove\n";
|
|
|
|
print $omshell "close\n";
|
2010-06-01 20:40:23 +00:00
|
|
|
if ($ip and $ip ne 'DENIED') {
|
|
|
|
print $omshell "new host\n";
|
|
|
|
print $omshell "set ip-address = $ip\n"; #find and destroy ip conflict
|
|
|
|
print $omshell "open\n";
|
|
|
|
print $omshell "remove\n";
|
|
|
|
print $omshell "close\n";
|
|
|
|
}
|
2009-07-07 02:07:30 +00:00
|
|
|
print $omshell "new host\n";
|
|
|
|
print $omshell "set hardware-address = " . $mac
|
|
|
|
. "\n"; #find and destroy mac conflict
|
|
|
|
print $omshell "open\n";
|
|
|
|
print $omshell "remove\n";
|
|
|
|
print $omshell "close\n";
|
|
|
|
print $omshell "new host\n";
|
2011-06-30 08:14:24 +00:00
|
|
|
print $omshell "set name = \"$hostname\"\n";
|
2009-07-07 02:07:30 +00:00
|
|
|
print $omshell "set hardware-address = " . $mac . "\n";
|
2011-06-30 08:14:24 +00:00
|
|
|
print $omshell "set hardware-type = $hardwaretype\n";
|
2009-07-07 02:07:30 +00:00
|
|
|
|
|
|
|
if ($ip eq "DENIED")
|
|
|
|
{ #Blacklist this mac to preclude confusion, give best shot at things working
|
|
|
|
print $omshell "set statements = \"deny booting;\"\n";
|
|
|
|
}
|
|
|
|
else
|
2008-05-06 18:49:22 +00:00
|
|
|
{
|
2010-06-16 18:47:53 +00:00
|
|
|
if ($ip and not ipIsDynamic($ip)) {
|
2010-06-01 20:40:23 +00:00
|
|
|
print $omshell "set ip-address = $ip\n";
|
|
|
|
}
|
2009-07-07 02:07:30 +00:00
|
|
|
if ($lstatements)
|
|
|
|
{
|
2010-05-21 20:59:03 +00:00
|
|
|
$lstatements = 'ddns-hostname \"'.$node.'\"; send host-name \"'.$node.'\";'.$lstatements;
|
2009-07-07 02:07:30 +00:00
|
|
|
|
|
|
|
} else {
|
2010-05-21 20:59:03 +00:00
|
|
|
$lstatements = 'ddns-hostname \"'.$node.'\"; send host-name \"'.$node.'\";';
|
2009-07-07 02:07:30 +00:00
|
|
|
}
|
|
|
|
print $omshell "set statements = \"$lstatements\"\n";
|
|
|
|
}
|
2008-05-27 20:56:07 +00:00
|
|
|
|
2009-07-07 02:07:30 +00:00
|
|
|
print $omshell "create\n";
|
|
|
|
print $omshell "close\n";
|
2013-04-09 20:21:02 +00:00
|
|
|
unless ($::XCATSITEVALS{externaldhcpservers}) {
|
|
|
|
unless (grep /#definition for host $node aka host $hostname/, @dhcpconf)
|
|
|
|
{
|
|
|
|
push @dhcpconf,
|
|
|
|
"#definition for host $node aka host $hostname can be found in the dhcpd.leases file (typically /var/lib/dhcpd/dhcpd.leases)\n";
|
|
|
|
}
|
|
|
|
}
|
2008-05-06 18:49:22 +00:00
|
|
|
}
|
2011-06-30 08:14:24 +00:00
|
|
|
$count = $count + 2;
|
2009-07-07 02:07:30 +00:00
|
|
|
}
|
|
|
|
}
|
2008-01-26 17:55:34 +00:00
|
|
|
|
2011-01-17 19:17:38 +00:00
|
|
|
sub addrangedetection {
|
|
|
|
my $net = shift;
|
2011-01-26 14:13:05 +00:00
|
|
|
my $tranges = $net->{dynamicrange}; #temp range, the dollar sign makes it look strange
|
|
|
|
my $trange;
|
2011-01-17 19:17:38 +00:00
|
|
|
my $begin;
|
|
|
|
my $end;
|
2011-06-13 03:58:36 +00:00
|
|
|
my $myip;
|
2012-08-09 04:07:40 +00:00
|
|
|
$myip = xCAT::NetworkUtils->my_ip_facing($net->{net});
|
2011-06-13 03:58:36 +00:00
|
|
|
|
2011-05-10 08:21:51 +00:00
|
|
|
# convert <xcatmaster> to nameserver IP
|
|
|
|
if ($net->{nameservers} eq '<xcatmaster>')
|
|
|
|
{
|
2011-06-13 03:58:36 +00:00
|
|
|
$netcfgs{$net->{net}}->{nameservers} = $myip;
|
2011-05-10 08:21:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$netcfgs{$net->{net}}->{nameservers} = $net->{nameservers};
|
|
|
|
}
|
2011-02-15 20:54:40 +00:00
|
|
|
$netcfgs{$net->{net}}->{ddnsdomain} = $net->{ddnsdomain};
|
2013-01-12 20:03:37 +00:00
|
|
|
$netcfgs{$net->{net}}->{domain} = $net->{domain};
|
|
|
|
|
2011-01-27 15:34:22 +00:00
|
|
|
unless ($netcfgs{$net->{net}}->{nameservers}) {
|
2011-05-10 08:21:51 +00:00
|
|
|
# convert <xcatmaster> to nameserver IP
|
|
|
|
if ($::XCATSITEVALS{nameservers} eq '<xcatmaster>')
|
|
|
|
{
|
2011-06-13 03:58:36 +00:00
|
|
|
$netcfgs{$net->{net}}->{nameservers} = $myip;
|
2011-05-10 08:21:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$netcfgs{$net->{net}}->{nameservers} = $::XCATSITEVALS{nameservers};
|
|
|
|
}
|
2011-01-27 15:34:22 +00:00
|
|
|
}
|
2011-01-26 14:13:05 +00:00
|
|
|
foreach $trange (split /;/,$tranges) {
|
|
|
|
if ($trange =~ /[ ,-]/) { #a range of one number to another..
|
|
|
|
$trange =~ s/[,-]/ /g;
|
|
|
|
$netcfgs{$net->{net}}->{range}=$trange;
|
|
|
|
($begin,$end) = split / /,$trange;
|
|
|
|
$dynamicranges{$trange}=[getipaddr($begin,GetNumber=>1),getipaddr($end,GetNumber=>1)];
|
|
|
|
} elsif ($trange =~ /\//) { #a CIDR style specification for a range that could be described in subnet rules
|
|
|
|
#we are going to assume that this is a subset of the network (it really ought to be) and therefore all zeroes or all ones is good to include
|
|
|
|
my $prefix;
|
|
|
|
my $suffix;
|
|
|
|
($prefix,$suffix) = split /\//,$trange;
|
|
|
|
my $numbits;
|
|
|
|
if ($prefix =~ /:/) { #ipv6
|
|
|
|
$netcfgs{$net->{net}}->{range}=$trange; #we can put in dhcpv6 ranges verbatim as CIDR
|
|
|
|
$numbits=128;
|
|
|
|
} else {
|
|
|
|
$numbits=32;
|
|
|
|
}
|
|
|
|
my $number = getipaddr($prefix,GetNumber=>1);
|
|
|
|
my $highmask=Math::BigInt->new("0b".("1"x$suffix).("0"x($numbits-$suffix)));
|
|
|
|
my $lowmask=Math::BigInt->new("0b".("1"x($numbits-$suffix)));
|
|
|
|
$number &= $highmask; #remove any errant high bits beyond the mask.
|
|
|
|
$begin = $number->copy();
|
|
|
|
$number |= $lowmask; #get the highest number in the range,
|
|
|
|
$end=$number->copy();
|
|
|
|
$dynamicranges{$trange}=[$begin,$end];
|
|
|
|
if ($prefix !~ /:/) { #ipv4, must convert CIDR subset to range
|
|
|
|
my $lowip = inet_ntoa(pack("N*",$begin));
|
|
|
|
my $highip = inet_ntoa(pack("N*",$end));
|
|
|
|
$netcfgs{$net->{net}}->{range} = "$lowip $highip";
|
|
|
|
|
|
|
|
}
|
2011-01-17 19:17:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-07-07 02:07:30 +00:00
|
|
|
######################################################
|
|
|
|
# Add nodes into dhcpsd.cnf. For AIX only
|
|
|
|
######################################################
|
|
|
|
sub addnode_aix
|
|
|
|
{
|
|
|
|
my $ip = shift;
|
|
|
|
my $mac = shift;
|
|
|
|
my $hname = shift;
|
|
|
|
my $tftpserver = shift;
|
|
|
|
|
|
|
|
$restartdhcp = 1;
|
|
|
|
|
|
|
|
# Format the mac address to aix
|
|
|
|
$mac =~ s/://g;
|
|
|
|
$mac = lc($mac);
|
|
|
|
|
|
|
|
delnode_aix ( $hname);
|
|
|
|
|
|
|
|
#Find the location to insert node
|
|
|
|
my $isSubnetFound = 0;
|
|
|
|
my $i;
|
|
|
|
my $netmask;
|
|
|
|
for ($i = 0; $i < scalar(@dhcpconf); $i++)
|
|
|
|
{
|
2013-06-03 08:29:25 +00:00
|
|
|
if ( $dhcpconf[$i] =~ / ([\d\.]+)\/(\d+) ip configuration end/)
|
2009-07-07 02:07:30 +00:00
|
|
|
{
|
2012-08-09 04:07:40 +00:00
|
|
|
if (xCAT::NetworkUtils::isInSameSubnet( $ip, $1, $2, 1))
|
2009-07-07 02:07:30 +00:00
|
|
|
{
|
|
|
|
$isSubnetFound = 1;
|
|
|
|
$netmask = $2;
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Format the netmask from AIX format (24) to Linux format (255.255.255.0)
|
2012-08-09 04:07:40 +00:00
|
|
|
my $netmask_linux = xCAT::NetworkUtils::formatNetmask( $netmask,1,0);
|
2009-07-07 02:07:30 +00:00
|
|
|
|
|
|
|
# Create node section
|
|
|
|
my @node_section = ();
|
|
|
|
push @node_section, " client 1 $mac $ip #node $hname start\n";
|
|
|
|
push @node_section, " {\n";
|
|
|
|
push @node_section, " option 1 $netmask_linux\n";
|
|
|
|
push @node_section, " option 12 $hname\n";
|
2009-08-27 08:15:01 +00:00
|
|
|
# push @node_section, " option sa $tftpserver\n";
|
|
|
|
# push @node_section, " option bf \"/tftpboot/$hname\"\n";
|
2009-07-07 02:07:30 +00:00
|
|
|
push @node_section, " } # node $hname end\n";
|
|
|
|
|
|
|
|
|
|
|
|
if ( $isSubnetFound)
|
|
|
|
{
|
|
|
|
splice @dhcpconf, $i, 0, @node_section;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
###################################################
|
|
|
|
# Delete nodes in dhcpsd.cnf. For AIX only
|
|
|
|
###################################################
|
|
|
|
sub delnode_aix
|
|
|
|
{
|
|
|
|
my $hname = shift;
|
|
|
|
my $i;
|
|
|
|
my $node_start = 0;
|
|
|
|
my $node_end = 0;
|
|
|
|
for ($i = 0; $i < scalar(@dhcpconf); $i++)
|
|
|
|
{
|
|
|
|
if ( $dhcpconf[$i] =~ /node $hname start/)
|
2008-05-06 18:49:22 +00:00
|
|
|
{
|
2009-07-07 02:07:30 +00:00
|
|
|
$node_start = $i;
|
2008-05-06 18:49:22 +00:00
|
|
|
}
|
2009-07-07 02:07:30 +00:00
|
|
|
elsif ( $dhcpconf[$i] =~ /node $hname end/)
|
|
|
|
{
|
|
|
|
$node_end = $i;
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( $node_start && $node_end)
|
|
|
|
{
|
|
|
|
$restartdhcp = 1;
|
|
|
|
splice @dhcpconf, $node_start, ($node_end - $node_start + 1);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 0;
|
2008-05-06 18:49:22 +00:00
|
|
|
}
|
2008-01-26 17:55:34 +00:00
|
|
|
}
|
|
|
|
|
2013-05-21 12:22:17 +00:00
|
|
|
############################################################
|
|
|
|
# check_options will process the options for makedhcp and
|
|
|
|
# give a usage error for any invalid options
|
|
|
|
############################################################
|
|
|
|
sub check_options
|
2008-05-06 18:49:22 +00:00
|
|
|
{
|
|
|
|
my $req = shift;
|
2013-12-30 03:02:02 +00:00
|
|
|
my $opt = shift;
|
2013-05-15 20:36:34 +00:00
|
|
|
my $callback = shift;
|
|
|
|
my $rc = 0;
|
|
|
|
|
|
|
|
# Exit if the packet has been preprocessed
|
2013-11-06 09:31:36 +00:00
|
|
|
# Comment this line to make sure check_options can be processed on service node.
|
2014-01-10 03:20:51 +00:00
|
|
|
if ($req->{_xcatpreprocessed}->[0] == 1) { return 0; }
|
2009-07-15 14:36:56 +00:00
|
|
|
|
2013-05-15 20:36:34 +00:00
|
|
|
# display the usage if -h
|
2013-12-30 03:02:02 +00:00
|
|
|
if ($opt->{h})
|
2013-05-15 20:36:34 +00:00
|
|
|
{
|
|
|
|
my $rsp = {};
|
|
|
|
$rsp->{data}->[0] = $usage;
|
2013-11-06 09:31:36 +00:00
|
|
|
xCAT::MsgUtils->message("I", $rsp, $callback, 0);
|
2013-05-15 20:36:34 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2014-03-31 18:26:29 +00:00
|
|
|
# if not help and not -n, dhcpd needs to be running
|
|
|
|
if (!($opt->{h})&& (!($opt->{n}))) {
|
2014-03-26 17:08:41 +00:00
|
|
|
if (xCAT::Utils->isLinux()) {
|
|
|
|
my @output = xCAT::Utils->runcmd("service dhcpd status", -1);
|
|
|
|
if ($::RUNCMD_RC != 0) { # not running
|
|
|
|
my $rsp = {};
|
|
|
|
$rsp->{data}->[0] = "dhcpd is not running. Run service dhcpd start and rerun your command.";
|
|
|
|
xCAT::MsgUtils->message("E", $rsp, $callback, 1);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
} else { # AIX
|
|
|
|
my @output = xCAT::Utils->runcmd("lssrc -s dhcpsd ", -1);
|
|
|
|
if ($::RUNCMD_RC != 0) { # not running
|
|
|
|
my $rsp = {};
|
|
|
|
$rsp->{data}->[0] = "dhcpsd is not running. Run startsrc -s dhcpsd and rerun your command.";
|
|
|
|
xCAT::MsgUtils->message("E", $rsp, $callback, 1);
|
|
|
|
return 1;
|
|
|
|
} else { # check the status
|
|
|
|
# the return output varies, sometime status is the third sometimes the 4th col
|
|
|
|
if (grep /inoperative/, @output)
|
|
|
|
{
|
|
|
|
my $rsp = {};
|
|
|
|
$rsp->{data}->[0] = "dhcpsd is not running. Run startsrc -s dhcpsd and rerun your command.";
|
|
|
|
xCAT::MsgUtils->message("E", $rsp, $callback, 1);
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-15 20:36:34 +00:00
|
|
|
|
|
|
|
# check to see if -q is listed with any other options which is not allowed
|
2013-12-30 03:02:02 +00:00
|
|
|
if ($opt->{q} and ($opt->{a} || $opt->{d} || $opt->{n} || $opt->{r} || $opt->{l} || $statements)) {
|
2013-05-15 20:36:34 +00:00
|
|
|
my $rsp = {};
|
|
|
|
$rsp->{data}->[0] = "The -q option cannot be used with other options.";
|
|
|
|
xCAT::MsgUtils->message("E", $rsp, $callback, 1);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-05-28 15:30:40 +00:00
|
|
|
# check to see if -n is listed with any other options which is not allowed
|
2013-12-30 03:02:02 +00:00
|
|
|
if ($opt->{n} and ($opt->{a} || $opt->{d} || $opt->{q} || $opt->{r} || $opt->{l} || $statements)) {
|
2013-05-28 15:30:40 +00:00
|
|
|
my $rsp = {};
|
|
|
|
$rsp->{data}->[0] = "The -n option cannot be used with other options.";
|
|
|
|
xCAT::MsgUtils->message("E", $rsp, $callback, 1);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-08 19:22:25 +00:00
|
|
|
unless (($req->{arg} and (@{$req->{arg}}>0)) or $req->{node})
|
|
|
|
{
|
2013-05-15 20:36:34 +00:00
|
|
|
my $rsp = {};
|
|
|
|
$rsp->{data}->[0] = $usage;
|
|
|
|
xCAT::MsgUtils->message("I", $rsp, $callback, 1);
|
2010-06-08 19:22:25 +00:00
|
|
|
return;
|
2007-10-26 22:44:33 +00:00
|
|
|
}
|
2013-11-06 09:31:36 +00:00
|
|
|
|
|
|
|
return 0;
|
2013-05-21 12:22:17 +00:00
|
|
|
}
|
2010-06-08 19:22:25 +00:00
|
|
|
|
2013-05-28 15:30:40 +00:00
|
|
|
############################################################
|
|
|
|
# preprocess_request will perform syntax checking and do basic precess checking
|
|
|
|
############################################################
|
2013-05-21 12:22:17 +00:00
|
|
|
sub preprocess_request
|
|
|
|
{
|
|
|
|
my $req = shift;
|
|
|
|
my $callback = shift;
|
|
|
|
my $rc = 0;
|
2013-05-28 15:30:40 +00:00
|
|
|
|
2013-12-30 03:02:02 +00:00
|
|
|
|
|
|
|
Getopt::Long::Configure("bundling");
|
|
|
|
$Getopt::Long::ignorecase = 0;
|
|
|
|
Getopt::Long::Configure("no_pass_through");
|
|
|
|
|
|
|
|
# Exit if the packet has been preprocessed
|
|
|
|
if ($req->{_xcatpreprocessed}->[0] == 1) { return [$req]; }
|
|
|
|
|
|
|
|
# Save the arguements in ARGV for GetOptions
|
|
|
|
if ($req && $req->{arg}) { @ARGV = @{$req->{arg}}; }
|
|
|
|
else { @ARGV = (); }
|
|
|
|
|
|
|
|
my %opt;
|
|
|
|
# Parse the options for makedhcp
|
|
|
|
if (!GetOptions(
|
|
|
|
'h|help' => \$opt{h},
|
|
|
|
'a' => \$opt{a},
|
|
|
|
'd' => \$opt{d},
|
|
|
|
'l|localonly' => \$localonly,
|
|
|
|
'n' => \$opt{n},
|
|
|
|
'r' => \$opt{r},
|
|
|
|
's=s' => \$statements, # $statements is declared globally
|
|
|
|
'q' => \$opt{q}
|
|
|
|
))
|
|
|
|
{
|
|
|
|
# If the arguements do not pass GetOptions then issue error message and return
|
|
|
|
my $rsp = {};
|
|
|
|
$rsp->{data}->[0] = $usage;
|
|
|
|
xCAT::MsgUtils->message("E", $rsp, $callback, 1);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
# check the syntax
|
|
|
|
$rc = check_options($req, \%opt,$callback);
|
2013-11-06 09:31:36 +00:00
|
|
|
if ( $rc ) {
|
|
|
|
return [];
|
|
|
|
}
|
2014-03-26 17:08:41 +00:00
|
|
|
|
2010-06-08 19:22:25 +00:00
|
|
|
my $snonly=0;
|
2013-05-15 20:36:34 +00:00
|
|
|
my @entries = xCAT::TableUtils->get_site_attribute("disjointdhcps");
|
|
|
|
my $t_entry = $entries[0];
|
|
|
|
if (defined($t_entry)) {
|
|
|
|
$snonly=$t_entry;
|
|
|
|
}
|
2010-06-08 19:22:25 +00:00
|
|
|
my @requests=();
|
|
|
|
my $hasHierarchy=0;
|
2011-05-18 18:23:56 +00:00
|
|
|
|
|
|
|
my @nodes=();
|
2013-05-28 15:30:40 +00:00
|
|
|
# if the new option is not specified
|
2013-12-30 03:02:02 +00:00
|
|
|
if (!$opt{n}) {
|
2013-05-28 15:30:40 +00:00
|
|
|
# save the node names specified
|
2010-06-08 19:22:25 +00:00
|
|
|
if ($req->{node}) {
|
|
|
|
@nodes=@{$req->{node}};
|
|
|
|
}
|
2013-05-28 15:30:40 +00:00
|
|
|
# if option all
|
2013-12-30 03:02:02 +00:00
|
|
|
elsif($opt{a}) {
|
2013-05-15 20:36:34 +00:00
|
|
|
# if option delete - Delete all node entries, that were added by xCAT, from the DHCP server configuration.
|
2013-12-30 03:02:02 +00:00
|
|
|
if ($opt{d})
|
2010-06-08 19:22:25 +00:00
|
|
|
{
|
2011-06-01 17:41:12 +00:00
|
|
|
my $nodelist = xCAT::Table->new('nodelist');
|
|
|
|
my @entries = ($nodelist->getAllNodeAttribs([qw(node)]));
|
|
|
|
foreach (@entries)
|
|
|
|
{
|
|
|
|
push @nodes, $_->{node};
|
|
|
|
}
|
2010-06-08 19:22:25 +00:00
|
|
|
}
|
2013-05-15 20:36:34 +00:00
|
|
|
# Delete not specified so only add - Define all nodes to the DHCP server
|
2010-06-08 19:22:25 +00:00
|
|
|
else
|
|
|
|
{
|
2011-06-01 17:41:12 +00:00
|
|
|
my $mactab = xCAT::Table->new('mac');
|
|
|
|
my @entries=();
|
|
|
|
if ($mactab) {
|
|
|
|
@entries = ($mactab->getAllNodeAttribs([qw(mac)]));
|
|
|
|
}
|
|
|
|
foreach (@entries)
|
|
|
|
{
|
|
|
|
push @nodes, $_->{node};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} # end - if -a
|
|
|
|
|
|
|
|
# don't put compute node entries in for AIX nodes
|
2013-05-28 15:30:40 +00:00
|
|
|
# this is handled by NIM - duplicate entires will cause
|
|
|
|
# an error
|
2011-06-01 17:41:12 +00:00
|
|
|
if ($^O eq 'aix') {
|
|
|
|
my @tmplist;
|
|
|
|
my $Imsg;
|
|
|
|
foreach my $n (@nodes)
|
2010-06-08 19:22:25 +00:00
|
|
|
{
|
2011-06-01 17:41:12 +00:00
|
|
|
# get the nodetype for each node
|
2011-07-07 02:38:07 +00:00
|
|
|
my $ntable = xCAT::Table->new('nodetype');
|
|
|
|
if ($ntable) {
|
2011-07-13 02:48:35 +00:00
|
|
|
my $mytype = $ntable->getNodeAttribs($n,['nodetype']);
|
2011-12-06 13:18:46 +00:00
|
|
|
if ($mytype->{nodetype} =~ /osi/) {
|
2011-06-01 17:41:12 +00:00
|
|
|
$Imsg++;
|
2011-07-07 02:38:07 +00:00
|
|
|
}
|
2013-05-28 15:30:40 +00:00
|
|
|
# if its aix and not "osi" then add it to the list of nodes
|
2011-12-06 13:18:46 +00:00
|
|
|
unless ($mytype->{nodetype} =~ /osi/) {
|
2011-07-07 02:38:07 +00:00
|
|
|
push @tmplist, $n;
|
|
|
|
}
|
|
|
|
}
|
2011-06-01 17:41:12 +00:00
|
|
|
}
|
2013-05-28 15:30:40 +00:00
|
|
|
# replace nodes with the tmplist of nodes that are not osi nodetype
|
2011-06-01 17:41:12 +00:00
|
|
|
@nodes = @tmplist;
|
|
|
|
|
2013-05-28 15:30:40 +00:00
|
|
|
# if any nodes were found with a ndoetype of osi - issue message that they are handled by NIM
|
2011-06-01 17:41:12 +00:00
|
|
|
if ($Imsg) {
|
|
|
|
my $rsp;
|
|
|
|
push @{$rsp->{data}}, "AIX nodes with a nodetype of \'osi\' will not be added to the dhcp configuration file. This is handled by NIM.\n";
|
|
|
|
xCAT::MsgUtils->message("I", $rsp, $callback);
|
2010-06-08 19:22:25 +00:00
|
|
|
}
|
2013-06-04 12:29:22 +00:00
|
|
|
}
|
|
|
|
}
|
2011-06-01 17:41:12 +00:00
|
|
|
|
2013-05-28 15:30:40 +00:00
|
|
|
# If service node and not -n option
|
2013-12-30 03:02:02 +00:00
|
|
|
if (($snonly == 1) && (!$opt{n})) {
|
2013-05-28 15:30:40 +00:00
|
|
|
# if a list of nodes are specified
|
2010-06-08 19:22:25 +00:00
|
|
|
if (@nodes > 0) {
|
2013-05-28 15:30:40 +00:00
|
|
|
# get the hash of service nodes
|
2012-08-09 04:07:40 +00:00
|
|
|
my $sn_hash =xCAT::ServiceNodeUtils->getSNformattedhash(\@nodes,"xcat","MN");
|
2013-05-28 15:30:40 +00:00
|
|
|
# if processing only on the local host
|
2010-06-08 19:22:25 +00:00
|
|
|
if ($localonly) {
|
|
|
|
#check if this node is the service node for any input node
|
2012-08-09 04:07:40 +00:00
|
|
|
my @hostinfo=xCAT::NetworkUtils->determinehostname();
|
2010-06-08 19:22:25 +00:00
|
|
|
my %iphash=();
|
2013-05-28 15:30:40 +00:00
|
|
|
# flag the hostnames in iphash
|
2010-06-08 19:22:25 +00:00
|
|
|
foreach(@hostinfo) {$iphash{$_}=1;}
|
2013-05-28 15:30:40 +00:00
|
|
|
# compare the service node hash with the iphash - a match adds this service node
|
2010-06-08 19:22:25 +00:00
|
|
|
foreach(keys %$sn_hash) {
|
|
|
|
if (exists($iphash{$_})) {
|
|
|
|
my $reqcopy = {%$req};
|
|
|
|
$reqcopy->{'node'}=$sn_hash->{$_};
|
|
|
|
$reqcopy->{'_xcatdest'} = $_;
|
|
|
|
$reqcopy->{_xcatpreprocessed}->[0] = 1;
|
|
|
|
push @requests, $reqcopy;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2013-05-28 15:30:40 +00:00
|
|
|
# check to see if dhcp is running on service nodes
|
2012-08-09 04:07:40 +00:00
|
|
|
my @sn = xCAT::ServiceNodeUtils->getSNList('dhcpserver');
|
2010-06-08 19:22:25 +00:00
|
|
|
if (@sn > 0) { $hasHierarchy=1;}
|
2013-05-28 15:30:40 +00:00
|
|
|
# create a request for each service node
|
2010-06-08 19:22:25 +00:00
|
|
|
foreach(keys %$sn_hash) {
|
|
|
|
my $reqcopy = {%$req};
|
|
|
|
$reqcopy->{'node'}=$sn_hash->{$_};
|
|
|
|
$reqcopy->{'_xcatdest'} = $_;
|
|
|
|
$reqcopy->{_xcatpreprocessed}->[0] = 1;
|
|
|
|
push @requests, $reqcopy;
|
|
|
|
}
|
|
|
|
}
|
2013-05-28 15:30:40 +00:00
|
|
|
} # list of nodes specified
|
|
|
|
# if new specified or there are nodes
|
|
|
|
} # end if service node only and NOT -n option
|
2013-06-14 15:45:27 +00:00
|
|
|
# if -n option or nodes were specified
|
2013-12-30 03:02:02 +00:00
|
|
|
elsif (@nodes > 0 or $opt{n}) { #send the request to every dhservers
|
2011-12-17 14:57:55 +00:00
|
|
|
$req->{'node'}=\@nodes;
|
|
|
|
@requests = ({%$req}); #Start with a straight copy to reflect local instance
|
2013-05-28 15:30:40 +00:00
|
|
|
# if not localonly - get list of service nodes and create requests
|
2011-12-17 14:57:55 +00:00
|
|
|
unless ($localonly) {
|
2012-08-09 04:07:40 +00:00
|
|
|
my @sn = xCAT::ServiceNodeUtils->getSNList('dhcpserver');
|
2011-12-17 14:57:55 +00:00
|
|
|
if (@sn > 0) { $hasHierarchy=1; }
|
|
|
|
|
|
|
|
foreach my $s (@sn)
|
|
|
|
{
|
|
|
|
if (scalar @nodes == 1 and $nodes[0] eq $s) { next; }
|
|
|
|
my $reqcopy = {%$req};
|
|
|
|
$reqcopy->{'_xcatdest'} = $s;
|
|
|
|
$reqcopy->{_xcatpreprocessed}->[0] = 1;
|
|
|
|
push @requests, $reqcopy;
|
2010-06-08 19:22:25 +00:00
|
|
|
}
|
2011-12-17 14:57:55 +00:00
|
|
|
}
|
2007-10-26 22:44:33 +00:00
|
|
|
}
|
|
|
|
|
2010-06-08 19:22:25 +00:00
|
|
|
if ( $hasHierarchy)
|
|
|
|
{
|
|
|
|
#hierarchy detected, enforce more rigorous sanity
|
|
|
|
my $ntab = xCAT::Table->new('networks');
|
|
|
|
if ($ntab)
|
|
|
|
{
|
|
|
|
foreach (@{$ntab->getAllEntries()})
|
|
|
|
{
|
2013-05-28 15:30:40 +00:00
|
|
|
# if dynamicrange specified but dhcpserver was not - issue error message
|
2010-06-08 19:22:25 +00:00
|
|
|
if ($_->{dynamicrange} and not $_->{dhcpserver})
|
|
|
|
{
|
|
|
|
$callback->({error=>["Hierarchy requested, therefore networks.dhcpserver must be set for net=".$_->{net}.""],errorcode=>[1]});
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#print Dumper(@requests);
|
2008-05-06 18:49:22 +00:00
|
|
|
return \@requests;
|
2010-06-08 19:22:25 +00:00
|
|
|
|
2008-05-06 18:49:22 +00:00
|
|
|
}
|
2013-05-28 15:30:40 +00:00
|
|
|
|
|
|
|
#############################################################################
|
|
|
|
# process_request will perform syntax checking and do basic process checkingi
|
|
|
|
# and call other functions to complete the request to add or delete entries
|
|
|
|
#############################################################################
|
2008-05-06 18:49:22 +00:00
|
|
|
sub process_request
|
|
|
|
{
|
|
|
|
my $req = shift;
|
|
|
|
$callback = shift;
|
2013-05-28 15:30:40 +00:00
|
|
|
my $oldmask = umask 0077;
|
|
|
|
$restartdhcp=0;
|
|
|
|
my $rsp;
|
2010-06-08 19:22:25 +00:00
|
|
|
#print Dumper($req);
|
2013-05-21 12:22:17 +00:00
|
|
|
|
2013-12-30 03:02:02 +00:00
|
|
|
Getopt::Long::Configure("bundling");
|
|
|
|
$Getopt::Long::ignorecase = 0;
|
|
|
|
Getopt::Long::Configure("no_pass_through");
|
|
|
|
|
|
|
|
# Save the arguements in ARGV for GetOptions
|
|
|
|
if ($req && $req->{arg}) { @ARGV = @{$req->{arg}}; }
|
|
|
|
else { @ARGV = (); }
|
|
|
|
|
|
|
|
my %opt;
|
|
|
|
|
|
|
|
# Parse the options for makedhcp
|
|
|
|
if (!GetOptions(
|
|
|
|
'h|help' => \$opt{h},
|
|
|
|
'a' => \$opt{a},
|
|
|
|
'd' => \$opt{d},
|
|
|
|
'l|localonly' => \$localonly,
|
|
|
|
'n' => \$opt{n},
|
|
|
|
'r' => \$opt{r},
|
|
|
|
's=s' => \$statements, # $statements is declared globally
|
|
|
|
'q' => \$opt{q}
|
|
|
|
))
|
|
|
|
{
|
|
|
|
# If the arguements do not pass GetOptions then issue error message and return
|
|
|
|
my $rsp = {};
|
|
|
|
$rsp->{data}->[0] = $usage;
|
|
|
|
xCAT::MsgUtils->message("E", $rsp, $callback, 1);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-21 12:22:17 +00:00
|
|
|
# Check options again in case we are called from plugin and options have not been processed
|
2013-11-06 09:31:36 +00:00
|
|
|
my $rc = 0;
|
2013-12-30 03:02:02 +00:00
|
|
|
$rc = check_options($req, \%opt,$callback);
|
2013-11-06 09:31:36 +00:00
|
|
|
|
|
|
|
if ( $rc ) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
2013-05-21 12:22:17 +00:00
|
|
|
|
2013-05-28 15:30:40 +00:00
|
|
|
# if option is query then call listnode for each node and return
|
2013-12-30 03:02:02 +00:00
|
|
|
if ($opt{q})
|
2013-05-15 20:36:34 +00:00
|
|
|
{
|
2013-05-28 15:30:40 +00:00
|
|
|
# call listnode for each node requested
|
2013-05-15 20:36:34 +00:00
|
|
|
foreach my $node ( @{$req->{node}} ) {
|
|
|
|
listnode($node,$callback);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2010-06-08 19:22:25 +00:00
|
|
|
|
2013-05-28 15:30:40 +00:00
|
|
|
# if current node is a servicenode, make sure that it is also a dhcpserver
|
2010-06-08 19:22:25 +00:00
|
|
|
my $isok=1;
|
|
|
|
if (xCAT::Utils->isServiceNode()) {
|
2013-05-28 15:30:40 +00:00
|
|
|
$isok=0;
|
|
|
|
my @hostinfo=xCAT::NetworkUtils->determinehostname();
|
|
|
|
my %iphash=();
|
|
|
|
foreach(@hostinfo) {$iphash{$_}=1;}
|
|
|
|
my @sn = xCAT::ServiceNodeUtils->getSNList('dhcpserver');
|
|
|
|
foreach my $s (@sn)
|
|
|
|
{
|
|
|
|
if (exists($iphash{$s})) {
|
|
|
|
$isok=1;
|
|
|
|
}
|
|
|
|
}
|
2010-06-08 19:22:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if($isok == 0) { #do nothing if it is a service node, but not dhcpserver
|
|
|
|
print "Do nothing\n";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-12-11 11:09:05 +00:00
|
|
|
my $servicenodetab = xCAT::Table->new('servicenode');
|
2012-12-12 03:36:46 +00:00
|
|
|
my @nodeinfo = xCAT::NetworkUtils->determinehostname;
|
2012-12-11 11:09:05 +00:00
|
|
|
my $nodename = pop @nodeinfo; # get hostname
|
|
|
|
my $dhcpinterfaces = $servicenodetab->getNodeAttribs($nodename, ['dhcpinterfaces']);
|
|
|
|
|
2008-05-06 18:49:22 +00:00
|
|
|
my %activenics;
|
|
|
|
my $querynics = 1;
|
2012-12-11 11:09:05 +00:00
|
|
|
|
|
|
|
if ( xCAT::Utils->isServiceNode() and $dhcpinterfaces and $dhcpinterfaces->{dhcpinterfaces} ) {
|
|
|
|
my @dhcpifs = split ',', $dhcpinterfaces->{dhcpinterfaces};
|
|
|
|
foreach my $nic ( @dhcpifs ) {
|
|
|
|
$activenics{$nic} = 1;
|
|
|
|
$querynics = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-08-09 04:07:40 +00:00
|
|
|
my @entries = xCAT::TableUtils->get_site_attribute("dhcpinterfaces");
|
2012-05-22 07:02:11 +00:00
|
|
|
my $t_entry = $entries[0];
|
|
|
|
unless ( defined($t_entry) )
|
2008-05-06 18:49:22 +00:00
|
|
|
{ #LEGACY: singular keyname for old style site value
|
2012-08-09 04:07:40 +00:00
|
|
|
@entries = xCAT::TableUtils->get_site_attribute("dhcpinterface");
|
2012-05-22 07:02:11 +00:00
|
|
|
$t_entry = $entries[0];
|
2008-05-06 18:49:22 +00:00
|
|
|
}
|
2012-05-22 07:02:11 +00:00
|
|
|
if ( defined($t_entry) )
|
2008-05-07 13:49:33 +00:00
|
|
|
#syntax should be like host|ifname1,ifname2;host2|ifname3,ifname2 etc or simply ifname,ifname2
|
|
|
|
#depending on complexity of network wished to be described
|
2008-05-06 18:49:22 +00:00
|
|
|
{
|
2012-05-22 07:02:11 +00:00
|
|
|
my $dhcpinterfaces = $t_entry;
|
2008-05-07 13:49:33 +00:00
|
|
|
my $dhcpif;
|
2008-06-21 14:08:59 +00:00
|
|
|
INTF: foreach $dhcpif (split /;/,$dhcpinterfaces) {
|
2008-10-07 16:40:00 +00:00
|
|
|
my $host;
|
|
|
|
my $savehost;
|
2009-04-03 18:03:08 +00:00
|
|
|
my $foundself=1;
|
2008-05-07 13:49:33 +00:00
|
|
|
if ($dhcpif =~ /\|/) {
|
2009-04-03 18:03:08 +00:00
|
|
|
$foundself=0;
|
2008-06-21 14:08:59 +00:00
|
|
|
|
|
|
|
(my $ngroup,$dhcpif) = split /\|/,$dhcpif;
|
|
|
|
foreach $host (noderange($ngroup)) {
|
2008-10-07 16:40:00 +00:00
|
|
|
$savehost=$host;
|
2012-08-09 04:07:40 +00:00
|
|
|
unless (xCAT::NetworkUtils->thishostisnot($host)) {
|
2009-03-27 15:13:25 +00:00
|
|
|
$foundself=1;
|
|
|
|
last;
|
2008-10-07 16:40:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!defined($savehost)) { # host not defined in db,
|
|
|
|
# probably management node
|
2012-08-09 04:07:40 +00:00
|
|
|
unless (xCAT::NetworkUtils->thishostisnot($ngroup)) {
|
2009-03-27 15:13:25 +00:00
|
|
|
$foundself=1;
|
2008-06-21 14:08:59 +00:00
|
|
|
}
|
2008-05-07 13:49:33 +00:00
|
|
|
}
|
|
|
|
}
|
2009-03-27 15:13:25 +00:00
|
|
|
unless ($foundself) {
|
|
|
|
next INTF;
|
|
|
|
}
|
2008-05-07 13:49:33 +00:00
|
|
|
foreach (split /[,\s]+/, $dhcpif)
|
|
|
|
{
|
|
|
|
$activenics{$_} = 1;
|
|
|
|
$querynics = 0;
|
|
|
|
}
|
|
|
|
}
|
2008-05-06 18:49:22 +00:00
|
|
|
}
|
2012-08-09 04:07:40 +00:00
|
|
|
@entries = xCAT::TableUtils->get_site_attribute("nameservers");
|
2012-05-22 07:02:11 +00:00
|
|
|
$t_entry = $entries[0];
|
|
|
|
if ( defined($t_entry) ) {
|
|
|
|
$sitenameservers = $t_entry;
|
2009-03-26 20:08:18 +00:00
|
|
|
}
|
2012-08-09 04:07:40 +00:00
|
|
|
@entries = xCAT::TableUtils->get_site_attribute("ntpservers");
|
2012-05-22 07:02:11 +00:00
|
|
|
$t_entry = $entries[0];
|
|
|
|
if ( defined($t_entry) ) {
|
|
|
|
$sitentpservers = $t_entry;
|
2009-03-26 20:08:18 +00:00
|
|
|
}
|
2012-08-09 04:07:40 +00:00
|
|
|
@entries = xCAT::TableUtils->get_site_attribute("logservers");
|
2012-05-22 07:02:11 +00:00
|
|
|
$t_entry = $entries[0];
|
|
|
|
if ( defined($t_entry) ) {
|
|
|
|
$sitelogservers = $t_entry;
|
2009-03-26 20:08:18 +00:00
|
|
|
}
|
2012-08-09 04:07:40 +00:00
|
|
|
@entries = xCAT::TableUtils->get_site_attribute("domain");
|
2012-05-22 07:02:11 +00:00
|
|
|
$t_entry = $entries[0];
|
2013-01-12 20:03:37 +00:00
|
|
|
|
2012-05-22 07:02:11 +00:00
|
|
|
unless ( defined($t_entry) )
|
2008-05-06 18:49:22 +00:00
|
|
|
{
|
2013-01-12 20:03:37 +00:00
|
|
|
# this may not be an error
|
|
|
|
# $callback->(
|
|
|
|
# {error => ["No domain defined in site tabe"], errorcode => [1]}
|
|
|
|
# );
|
|
|
|
# return;
|
|
|
|
} else {
|
|
|
|
$site_domain = $t_entry;
|
|
|
|
}
|
2012-12-11 11:09:05 +00:00
|
|
|
}
|
2007-11-28 14:57:57 +00:00
|
|
|
|
2008-05-06 18:49:22 +00:00
|
|
|
@dhcpconf = ();
|
2011-09-27 15:23:19 +00:00
|
|
|
@dhcp6conf = ();
|
2009-02-19 10:00:28 +00:00
|
|
|
|
2009-03-28 15:03:36 +00:00
|
|
|
my $dhcplockfd;
|
2010-02-19 15:00:51 +00:00
|
|
|
open($dhcplockfd,">","/tmp/xcat/dhcplock");
|
2009-03-28 15:03:36 +00:00
|
|
|
flock($dhcplockfd,LOCK_EX);
|
2013-04-09 20:21:02 +00:00
|
|
|
if ($::XCATSITEVALS{externaldhcpservers}) { #do nothing if remote dhcpservers at this point
|
2013-12-30 03:02:02 +00:00
|
|
|
} elsif ($opt{n})
|
2008-05-06 18:49:22 +00:00
|
|
|
{
|
2009-07-07 02:07:30 +00:00
|
|
|
if (-e $dhcpconffile)
|
2008-05-06 18:49:22 +00:00
|
|
|
{
|
2011-06-01 17:41:12 +00:00
|
|
|
if ($^O eq 'aix')
|
|
|
|
{
|
|
|
|
# save NIM aix entries - to be restored later
|
|
|
|
my $aixconf;
|
|
|
|
open($aixconf, $dhcpconffile);
|
|
|
|
if ($aixconf)
|
|
|
|
{
|
|
|
|
my $save=0;
|
|
|
|
while (<$aixconf>)
|
|
|
|
{
|
|
|
|
if ($save) {
|
|
|
|
push @aixcfg, $_;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($_ =~ /#Network configuration end\n/) {
|
|
|
|
$save++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close($aixconf);
|
|
|
|
}
|
|
|
|
$restartdhcp=1;
|
|
|
|
@dhcpconf = ();
|
|
|
|
}
|
|
|
|
|
|
|
|
my $rsp;
|
|
|
|
push @{$rsp->{data}}, "Renamed existing dhcp configuration file to $dhcpconffile.xcatbak\n";
|
|
|
|
xCAT::MsgUtils->message("I", $rsp, $callback);
|
|
|
|
|
2009-07-07 02:07:30 +00:00
|
|
|
my $bakname = "$dhcpconffile.xcatbak";
|
|
|
|
rename("$dhcpconffile", $bakname);
|
2008-05-06 18:49:22 +00:00
|
|
|
}
|
2008-04-08 18:30:47 +00:00
|
|
|
}
|
2008-05-06 18:49:22 +00:00
|
|
|
else
|
|
|
|
{
|
2008-07-18 18:40:45 +00:00
|
|
|
my $rconf;
|
2009-07-07 02:07:30 +00:00
|
|
|
open($rconf, $dhcpconffile); # Read file into memory
|
2008-05-06 18:49:22 +00:00
|
|
|
if ($rconf)
|
|
|
|
{
|
|
|
|
while (<$rconf>)
|
|
|
|
{
|
|
|
|
push @dhcpconf, $_;
|
|
|
|
}
|
|
|
|
close($rconf);
|
|
|
|
}
|
|
|
|
unless ($dhcpconf[0] =~ /^#xCAT/)
|
|
|
|
{ #Discard file if not xCAT originated, like 1.x did
|
2008-05-15 17:45:47 +00:00
|
|
|
$restartdhcp=1;
|
2008-05-06 18:49:22 +00:00
|
|
|
@dhcpconf = ();
|
|
|
|
}
|
2011-01-17 19:17:38 +00:00
|
|
|
if ($dhcp6conffile and -e $dhcp6conffile) {
|
|
|
|
open($rconf, $dhcp6conffile);
|
|
|
|
while (<$rconf>) { push @dhcp6conf, $_; }
|
|
|
|
close($rconf);
|
|
|
|
}
|
|
|
|
unless ($dhcp6conf[0] =~ /^#xCAT/)
|
|
|
|
{ #Discard file if not xCAT originated
|
|
|
|
$restartdhcp6=1;
|
|
|
|
@dhcp6conf = ();
|
|
|
|
}
|
2007-10-26 22:44:33 +00:00
|
|
|
}
|
2008-11-26 00:00:54 +00:00
|
|
|
my $nettab = xCAT::Table->new("networks");
|
2013-01-12 20:03:37 +00:00
|
|
|
my @vnets = $nettab->getAllAttribs('net','mgtifname','mask','dynamicrange','nameservers','ddnsdomain', 'domain');
|
|
|
|
|
|
|
|
# get a list of all domains listed in xCAT network defs
|
|
|
|
# - include the site domain - if any
|
|
|
|
my $nettab = xCAT::Table->new("networks");
|
|
|
|
my @doms = $nettab->getAllAttribs('domain');
|
|
|
|
foreach(@doms){
|
|
|
|
if ($_->{domain}) {
|
|
|
|
push (@alldomains, $_->{domain});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$nettab->close;
|
|
|
|
|
|
|
|
# add the site domain
|
|
|
|
if ($site_domain) {
|
|
|
|
if (!grep(/^$site_domain$/, @alldomains)) {
|
|
|
|
push (@alldomains, $site_domain);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-16 19:19:47 +00:00
|
|
|
foreach (@vnets) {
|
2011-01-17 19:17:38 +00:00
|
|
|
if ($_->{net} =~ /:/) { #IPv6 detected
|
|
|
|
$usingipv6=1;
|
|
|
|
}
|
|
|
|
addrangedetection($_); #add to hash for remembering whether a node has a static address or just happens to live dynamically
|
2010-06-16 19:19:47 +00:00
|
|
|
}
|
2009-07-07 02:07:30 +00:00
|
|
|
if ($^O eq 'aix')
|
|
|
|
{
|
2012-08-09 04:07:40 +00:00
|
|
|
@nrn = xCAT::NetworkUtils::get_subnet_aix();
|
2009-07-07 02:07:30 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
my @nsrnoutput = split /\n/,`/bin/netstat -rn`;
|
|
|
|
splice @nsrnoutput, 0, 2;
|
|
|
|
foreach (@nsrnoutput) { #scan netstat
|
|
|
|
my @parts = split /\s+/;
|
|
|
|
push @nrn,$parts[0].":".$parts[7].":".$parts[2].":".$parts[3];
|
|
|
|
}
|
2011-01-17 19:17:38 +00:00
|
|
|
my @ip6routes = `ip -6 route`;
|
|
|
|
foreach (@ip6routes) {
|
|
|
|
#TODO: filter out multicast? Don't know if multicast groups *can* appear in ip -6 route...
|
2013-05-14 14:50:12 +00:00
|
|
|
if (/^default/ or /^fe80::\/64/ or /^unreachable/ or /^[^ ]+ via/) { #ignore link-local, junk, and routed networks
|
2011-01-17 19:17:38 +00:00
|
|
|
next;
|
|
|
|
}
|
|
|
|
my @parts = split /\s+/;
|
|
|
|
push @nrn6,{net=>$parts[0],iface=>$parts[2]};
|
|
|
|
}
|
2009-03-26 18:13:25 +00:00
|
|
|
}
|
|
|
|
|
2008-11-26 00:00:54 +00:00
|
|
|
foreach(@vnets){
|
2011-01-17 19:17:38 +00:00
|
|
|
#TODO: v6 relayed networks?
|
2008-11-26 00:00:54 +00:00
|
|
|
my $n = $_->{net};
|
|
|
|
my $if = $_->{mgtifname};
|
|
|
|
my $nm = $_->{mask};
|
2011-01-17 19:17:38 +00:00
|
|
|
if ($if =~ /!remote!/ and $n !~ /:/) { #only take in networks with special interface, but only v4 for now
|
2009-03-26 18:13:25 +00:00
|
|
|
push @nrn, "$n:$if:$nm";
|
|
|
|
}
|
2008-11-26 00:00:54 +00:00
|
|
|
}
|
2008-05-06 18:49:22 +00:00
|
|
|
if ($querynics)
|
|
|
|
{ #Use netstat to determine activenics only when no site ent.
|
2011-01-17 19:17:38 +00:00
|
|
|
#TODO: IPv6 auto-detect, or just really really insist people define dhcpinterfaces or suffer doom?
|
2008-05-06 18:49:22 +00:00
|
|
|
foreach (@nrn)
|
|
|
|
{
|
2008-12-02 18:36:32 +00:00
|
|
|
my @ent = split /:/;
|
2008-06-02 12:00:46 +00:00
|
|
|
my $firstoctet = $ent[0];
|
|
|
|
$firstoctet =~ s/^(\d+)\..*/$1/;
|
2009-07-07 02:07:30 +00:00
|
|
|
if ($ent[0] eq "169.254.0.0" or ($firstoctet >= 224 and $firstoctet <= 239) or $ent[0] eq "127.0.0.0" or $ent[0] eq '127')
|
2008-05-06 18:49:22 +00:00
|
|
|
{
|
|
|
|
next;
|
|
|
|
}
|
2013-12-05 04:51:49 +00:00
|
|
|
|
|
|
|
# Bridge nics
|
|
|
|
if ((-f "/usr/sbin/brctl") || (-f "/sbin/brctl"))
|
|
|
|
{
|
|
|
|
system "brctl showmacs $ent[1] 2>&1 1>/dev/null";
|
|
|
|
if ($? == 0)
|
|
|
|
{
|
|
|
|
$activenics{$ent[1]} = 1;
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
}
|
2014-03-19 15:14:00 +00:00
|
|
|
if ($ent[1] =~ m/(remote|ipoib|ib|vlan|bond|eth|myri|man|wlan|en\S*\d+|em\S*\d+)/)
|
2008-05-06 18:49:22 +00:00
|
|
|
{ #Mask out many types of interfaces, like xCAT 1.x
|
2008-11-26 00:00:54 +00:00
|
|
|
$activenics{$ent[1]} = 1;
|
2008-05-06 18:49:22 +00:00
|
|
|
}
|
|
|
|
}
|
2007-10-26 22:44:33 +00:00
|
|
|
}
|
2009-07-07 02:07:30 +00:00
|
|
|
|
|
|
|
if ( $^O ne 'aix')
|
|
|
|
{
|
2013-01-12 20:03:37 +00:00
|
|
|
#add the active nics to /etc/sysconfig/dhcpd or /etc/default/dhcp3-server(ubuntu)
|
2011-01-17 19:17:38 +00:00
|
|
|
my $dhcpver;
|
2013-01-12 20:03:37 +00:00
|
|
|
my %missingfiles = ( "dhcpd"=>1, "dhcpd6"=>1, "dhcp3-server"=>1 );
|
2012-08-30 02:16:24 +00:00
|
|
|
foreach $dhcpver ("dhcpd","dhcpd6","dhcp3-server", "isc-dhcp-server") {
|
2011-01-17 19:17:38 +00:00
|
|
|
if (-e "/etc/sysconfig/$dhcpver") {
|
2011-09-06 19:35:19 +00:00
|
|
|
if ($dhcpver eq "dhcpd") {
|
|
|
|
delete($missingfiles{dhcpd});
|
2011-09-06 19:36:47 +00:00
|
|
|
delete($missingfiles{"dhcp3-server"});
|
2011-09-06 19:35:19 +00:00
|
|
|
} else {
|
|
|
|
delete($missingfiles{$dhcpver});
|
|
|
|
}
|
2011-01-17 19:17:38 +00:00
|
|
|
open DHCPD_FD, "/etc/sysconfig/$dhcpver";
|
2009-07-07 02:07:30 +00:00
|
|
|
my $syscfg_dhcpd = "";
|
|
|
|
my $found = 0;
|
|
|
|
my $dhcpd_key = "DHCPDARGS";
|
|
|
|
my $os = xCAT::Utils->osver();
|
|
|
|
if ($os =~ /sles/i) {
|
|
|
|
$dhcpd_key = "DHCPD_INTERFACE";
|
|
|
|
}
|
2009-03-27 18:03:48 +00:00
|
|
|
|
2009-07-07 02:07:30 +00:00
|
|
|
my $ifarg = "$dhcpd_key=\"";
|
|
|
|
foreach (keys %activenics) {
|
|
|
|
if (/!remote!/) { next; }
|
|
|
|
$ifarg .= " $_";
|
|
|
|
}
|
|
|
|
$ifarg =~ s/^ //;
|
|
|
|
$ifarg .= "\"\n";
|
|
|
|
|
|
|
|
while (<DHCPD_FD>) {
|
|
|
|
if ($_ =~ m/^$dhcpd_key/) {
|
|
|
|
$found = 1;
|
|
|
|
$syscfg_dhcpd .= $ifarg;
|
|
|
|
}else {
|
|
|
|
$syscfg_dhcpd .= $_;
|
|
|
|
}
|
|
|
|
}
|
2009-03-27 18:03:48 +00:00
|
|
|
|
2009-07-07 02:07:30 +00:00
|
|
|
if ( $found eq 0 ) {
|
2009-03-27 18:03:48 +00:00
|
|
|
$syscfg_dhcpd .= $ifarg;
|
|
|
|
}
|
2009-07-07 02:07:30 +00:00
|
|
|
close DHCPD_FD;
|
2009-03-27 18:03:48 +00:00
|
|
|
|
2011-01-17 19:17:38 +00:00
|
|
|
open DBG_FD, '>', "/etc/sysconfig/$dhcpver";
|
2009-07-07 02:07:30 +00:00
|
|
|
print DBG_FD $syscfg_dhcpd;
|
|
|
|
close DBG_FD;
|
2011-08-15 00:49:23 +00:00
|
|
|
}elsif (-e "/etc/default/$dhcpver") { #ubuntu
|
2013-01-12 20:03:37 +00:00
|
|
|
delete($missingfiles{"dhcpd"});
|
2012-12-19 02:30:51 +00:00
|
|
|
#dhcpd and dhcpd6 use the same configure file
|
|
|
|
delete($missingfiles{"dhcpd6"});
|
2013-01-12 20:03:37 +00:00
|
|
|
delete($missingfiles{"dhcp3-server"});
|
|
|
|
open DHCPD_FD, "/etc/default/$dhcpver";
|
2011-08-15 00:49:23 +00:00
|
|
|
my $syscfg_dhcpd = "";
|
|
|
|
my $found = 0;
|
|
|
|
my $dhcpd_key = "INTERFACES";
|
|
|
|
my $os = xCAT::Utils->osver();
|
|
|
|
|
|
|
|
my $ifarg = "$dhcpd_key=\"";
|
|
|
|
foreach (keys %activenics) {
|
|
|
|
if (/!remote!/) { next; }
|
|
|
|
$ifarg .= " $_";
|
|
|
|
}
|
|
|
|
$ifarg =~ s/^ //;
|
|
|
|
$ifarg .= "\"\n";
|
|
|
|
|
|
|
|
while (<DHCPD_FD>) {
|
|
|
|
if ($_ =~ m/^$dhcpd_key/) {
|
|
|
|
$found = 1;
|
|
|
|
$syscfg_dhcpd .= $ifarg;
|
|
|
|
}else {
|
|
|
|
$syscfg_dhcpd .= $_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $found eq 0 ) {
|
|
|
|
$syscfg_dhcpd .= $ifarg;
|
|
|
|
}
|
|
|
|
close DHCPD_FD;
|
|
|
|
|
|
|
|
open DBG_FD, '>', "/etc/default/$dhcpver";
|
|
|
|
print DBG_FD $syscfg_dhcpd;
|
|
|
|
close DBG_FD;
|
|
|
|
|
2009-03-27 18:03:48 +00:00
|
|
|
}
|
2011-01-17 19:17:38 +00:00
|
|
|
}
|
2011-09-06 19:35:19 +00:00
|
|
|
if ($usingipv6 and $missingfiles{dhcpd6}) {
|
2012-04-04 20:08:10 +00:00
|
|
|
$callback->({error=>["The file /etc/sysconfig/dhcpd6 doesn't exist, check the dhcp server"]});
|
2011-09-06 19:35:19 +00:00
|
|
|
}
|
|
|
|
if ($missingfiles{dhcpd}) {
|
2012-04-04 20:08:10 +00:00
|
|
|
$callback->({error=>["The file /etc/sysconfig/dhcpd doesn't exist, check the dhcp server"]});
|
2011-09-06 19:35:19 +00:00
|
|
|
}
|
|
|
|
|
2009-03-27 18:03:48 +00:00
|
|
|
}
|
2009-07-07 02:07:30 +00:00
|
|
|
|
2008-05-06 18:49:22 +00:00
|
|
|
unless ($dhcpconf[0])
|
|
|
|
{ #populate an empty config with some starter data...
|
2008-05-15 17:45:47 +00:00
|
|
|
$restartdhcp=1;
|
2008-05-06 18:49:22 +00:00
|
|
|
newconfig();
|
2007-10-26 22:44:33 +00:00
|
|
|
}
|
2011-01-17 19:17:38 +00:00
|
|
|
if ($usingipv6 and not $dhcp6conf[0]) {
|
|
|
|
$restartdhcp6=1;
|
|
|
|
newconfig6();
|
|
|
|
}
|
2009-07-07 02:07:30 +00:00
|
|
|
if ( $^O ne 'aix')
|
2008-05-06 18:49:22 +00:00
|
|
|
{
|
2009-07-07 02:07:30 +00:00
|
|
|
foreach (keys %activenics)
|
|
|
|
{
|
2011-01-17 19:17:38 +00:00
|
|
|
addnic($_,\@dhcpconf);
|
|
|
|
if ($usingipv6) {
|
|
|
|
addnic($_,\@dhcp6conf);
|
|
|
|
}
|
2009-07-07 02:07:30 +00:00
|
|
|
}
|
2007-10-26 22:44:33 +00:00
|
|
|
}
|
2011-01-18 06:11:32 +00:00
|
|
|
#need to transfer CEC/Frame to FSPs/BPAs
|
|
|
|
my @inodes = ();
|
|
|
|
my @validnodes = ();
|
|
|
|
my $pnode;
|
|
|
|
my $cnode;
|
|
|
|
if ($req->{node})
|
|
|
|
{
|
|
|
|
#@inodes = split /,/,${$req->{noderange}};
|
2012-02-10 08:53:15 +00:00
|
|
|
my $typehash = xCAT::DBobjUtils->getnodetype(\@{$req->{node}});
|
2011-01-18 06:11:32 +00:00
|
|
|
foreach $pnode(@{$req->{node}})
|
|
|
|
{
|
2012-02-10 08:53:15 +00:00
|
|
|
my $ntype = $$typehash{$pnode};
|
2011-01-18 06:11:32 +00:00
|
|
|
if ($ntype =~ /^(cec|frame)$/)
|
|
|
|
{
|
|
|
|
$cnode = xCAT::DBobjUtils->getchildren($pnode);
|
|
|
|
foreach (@$cnode)
|
|
|
|
{
|
|
|
|
push @validnodes, $_;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
push @validnodes, $pnode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$req->{node} = \@validnodes;
|
|
|
|
}
|
|
|
|
|
2013-12-30 03:02:02 +00:00
|
|
|
if ((!$req->{node}) && ($opt{a}))
|
2008-05-06 18:49:22 +00:00
|
|
|
{
|
2013-12-30 03:02:02 +00:00
|
|
|
if ($opt{d}) #delete all entries
|
2008-05-06 18:49:22 +00:00
|
|
|
{
|
|
|
|
$req->{node} = [];
|
|
|
|
my $nodelist = xCAT::Table->new('nodelist');
|
|
|
|
my @entries = ($nodelist->getAllNodeAttribs([qw(node)]));
|
2012-02-10 08:53:15 +00:00
|
|
|
my @nodeentries;
|
|
|
|
foreach (@entries) {
|
|
|
|
push @nodeentries, $_->{node};
|
|
|
|
}
|
|
|
|
my $typehash = xCAT::DBobjUtils->getnodetype(\@nodeentries);
|
2008-05-06 18:49:22 +00:00
|
|
|
foreach (@entries)
|
|
|
|
{
|
2011-01-18 06:11:32 +00:00
|
|
|
#delete the CEC and Frame node
|
2012-02-10 08:53:15 +00:00
|
|
|
my $ntype = $$typehash{$_->{node}};
|
2011-01-18 06:11:32 +00:00
|
|
|
unless ($ntype =~ /^(cec|frame)$/)
|
|
|
|
{
|
|
|
|
push @{$req->{node}}, $_->{node};
|
|
|
|
}
|
2008-05-06 18:49:22 +00:00
|
|
|
}
|
|
|
|
}
|
2011-01-17 19:17:38 +00:00
|
|
|
else #add all entries
|
2008-05-06 18:49:22 +00:00
|
|
|
{
|
|
|
|
$req->{node} = [];
|
|
|
|
my $mactab = xCAT::Table->new('mac');
|
2008-08-01 14:30:26 +00:00
|
|
|
|
|
|
|
my @entries=();
|
|
|
|
if ($mactab) {
|
|
|
|
@entries = ($mactab->getAllNodeAttribs([qw(mac)]));
|
|
|
|
}
|
2011-06-01 17:41:12 +00:00
|
|
|
|
2008-05-06 18:49:22 +00:00
|
|
|
foreach (@entries)
|
|
|
|
{
|
|
|
|
push @{$req->{node}}, $_->{node};
|
|
|
|
}
|
2011-06-01 17:41:12 +00:00
|
|
|
|
|
|
|
# don't put compute node entries in for AIX nodes
|
|
|
|
# this is handled by NIM - duplicate entires will cause
|
|
|
|
# an error
|
|
|
|
if ($^O eq 'aix') {
|
|
|
|
my @tmplist;
|
|
|
|
foreach my $n (@{$req->{node}})
|
|
|
|
{
|
|
|
|
# get the nodetype for each node
|
2011-07-07 02:38:07 +00:00
|
|
|
my $ntable = xCAT::Table->new('nodetype');
|
|
|
|
if ($ntable) {
|
2011-07-13 02:48:35 +00:00
|
|
|
my $ntype = $ntable->getNodeAttribs($n,['nodetype']);
|
2011-07-07 02:38:07 +00:00
|
|
|
|
|
|
|
# don't add if it is type "osi"
|
2011-12-06 13:18:46 +00:00
|
|
|
unless ($ntype->{nodetype} =~ /osi/) {
|
2011-06-01 17:41:12 +00:00
|
|
|
push @tmplist, $n;
|
2011-07-07 02:38:07 +00:00
|
|
|
}
|
|
|
|
}
|
2011-06-01 17:41:12 +00:00
|
|
|
}
|
|
|
|
@{$req->{node}} = @tmplist;
|
|
|
|
}
|
2008-05-06 18:49:22 +00:00
|
|
|
}
|
2007-10-26 22:44:33 +00:00
|
|
|
}
|
2008-01-26 17:55:34 +00:00
|
|
|
|
2010-04-15 06:56:26 +00:00
|
|
|
foreach (@nrn)
|
|
|
|
{
|
|
|
|
my @line = split /:/;
|
|
|
|
my $firstoctet = $line[0];
|
|
|
|
$firstoctet =~ s/^(\d+)\..*/$1/;
|
|
|
|
if ($line[0] eq "169.254.0.0" or ($firstoctet >= 224 and $firstoctet <= 239))
|
|
|
|
{
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
if ($activenics{$line[1]} and $line[3] !~ /G/)
|
|
|
|
{
|
|
|
|
addnet($line[0], $line[2]);
|
|
|
|
}
|
|
|
|
}
|
2011-01-17 19:17:38 +00:00
|
|
|
foreach (@nrn6) { #do the ipv6 networks
|
|
|
|
addnet6($_); #already did all the filtering before putting into nrn6
|
|
|
|
}
|
2010-04-15 06:56:26 +00:00
|
|
|
|
2008-05-06 18:49:22 +00:00
|
|
|
if ($req->{node})
|
|
|
|
{
|
2010-04-13 11:58:33 +00:00
|
|
|
my $ip_hash;
|
|
|
|
foreach my $node ( @{$req->{node}} ) {
|
2011-01-18 07:51:06 +00:00
|
|
|
#need to change the way of finding IP for nodes
|
2012-08-09 04:07:40 +00:00
|
|
|
my $ifip = xCAT::NetworkUtils->isIpaddr($node);
|
2011-01-18 07:51:06 +00:00
|
|
|
if ($ifip)
|
|
|
|
{
|
|
|
|
$ip_hash->{ $node} = $node;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
my $hoststab = xCAT::Table->new('hosts');
|
|
|
|
my $ent = $hoststab->getNodeAttribs( $node, ['ip'] );
|
|
|
|
if ( $ent->{ip} ) {
|
|
|
|
if ( $ip_hash->{ $ent->{ip} } ) {
|
|
|
|
$callback->({error=>["Duplicated IP addresses in hosts table for following nodes: $node," . $ip_hash->{ $ent->{ip} }],errorcode=>[1]});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$ip_hash->{ $ent->{ip} } = $node;
|
2010-04-13 11:58:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-07 02:07:30 +00:00
|
|
|
if ($^O ne 'aix')
|
2008-05-06 18:49:22 +00:00
|
|
|
{
|
2009-07-07 02:07:30 +00:00
|
|
|
my $passtab = xCAT::Table->new('passwd');
|
|
|
|
my $ent;
|
|
|
|
($ent) = $passtab->getAttribs({key => "omapi"}, qw(username password));
|
|
|
|
unless ($ent->{username} and $ent->{password})
|
|
|
|
{
|
|
|
|
$callback->({error=>["Unable to access omapi key from passwd table, add the key from dhcpd.conf or makedhcp -n to create a new one"],errorcode=>[1]});
|
|
|
|
syslog("local4|err","Unable to access omapi key from passwd table, unable to update DHCP configuration");
|
|
|
|
return;
|
|
|
|
} # TODO sane err
|
|
|
|
#Have nodes to update
|
|
|
|
#open2($omshellout,$omshell,"/usr/bin/omshell");
|
|
|
|
open($omshell, "|/usr/bin/omshell > /dev/null");
|
|
|
|
print $omshell "key "
|
|
|
|
. $ent->{username} . " \""
|
|
|
|
. $ent->{password} . "\"\n";
|
2013-04-09 20:21:02 +00:00
|
|
|
if ($::XCATSITEVALS{externaldhcpservers}) {
|
|
|
|
print $omshell "server $::XCATSITEVALS{externaldhcpservers}\n";
|
|
|
|
}
|
2009-07-07 02:07:30 +00:00
|
|
|
print $omshell "connect\n";
|
2011-01-17 19:17:38 +00:00
|
|
|
if ($usingipv6) {
|
|
|
|
open($omshell6, "|/usr/bin/omshell > /dev/null");
|
2013-04-09 20:21:02 +00:00
|
|
|
if ($::XCATSITEVALS{externaldhcpservers}) {
|
|
|
|
print $omshell "server $::XCATSITEVALS{externaldhcpservers}\n";
|
|
|
|
}
|
2011-01-17 19:17:38 +00:00
|
|
|
print $omshell6 "port 7912\n";
|
|
|
|
print $omshell6 "key "
|
|
|
|
. $ent->{username} . " \""
|
|
|
|
. $ent->{password} . "\"\n";
|
|
|
|
print $omshell6 "connect\n";
|
|
|
|
}
|
2009-07-07 02:07:30 +00:00
|
|
|
}
|
|
|
|
|
2008-07-18 18:56:38 +00:00
|
|
|
my $nrtab = xCAT::Table->new('noderes');
|
2008-10-30 14:37:56 +00:00
|
|
|
my $chaintab = xCAT::Table->new('chain');
|
|
|
|
if ($chaintab) {
|
|
|
|
$chainents = $chaintab->getNodesAttribs($req->{node},['currstate']);
|
|
|
|
} else {
|
|
|
|
$chainents = undef;
|
|
|
|
}
|
2013-12-19 09:53:49 +00:00
|
|
|
$nrhash = $nrtab->getNodesAttribs($req->{node}, ['tftpserver','netboot','proxydhcp']);
|
2011-09-15 22:00:55 +00:00
|
|
|
my $nodetypetab;
|
|
|
|
$nodetypetab = xCAT::Table->new('nodetype',-create=>0);
|
|
|
|
if ($nodetypetab) {
|
|
|
|
$nodetypeents = $nodetypetab->getNodesAttribs($req->{node},[qw(os)]);
|
|
|
|
}
|
|
|
|
my $iscsitab = xCAT::Table->new('iscsi',-create=>0);
|
2008-10-30 14:37:56 +00:00
|
|
|
if ($iscsitab) {
|
2009-07-06 21:05:44 +00:00
|
|
|
$iscsients = $iscsitab->getNodesAttribs($req->{node},[qw(server target lun iname)]);
|
2008-10-30 14:37:56 +00:00
|
|
|
}
|
2008-07-18 18:56:38 +00:00
|
|
|
my $mactab = xCAT::Table->new('mac');
|
|
|
|
$machash = $mactab->getNodesAttribs($req->{node},['mac']);
|
2011-01-17 19:17:38 +00:00
|
|
|
my $vpdtab = xCAT::Table->new('vpd');
|
|
|
|
$vpdhash = $vpdtab->getNodesAttribs($req->{node},['uuid']);
|
2008-05-06 18:49:22 +00:00
|
|
|
foreach (@{$req->{node}})
|
|
|
|
{
|
2013-12-30 03:02:02 +00:00
|
|
|
if ($opt{d})
|
2008-05-06 18:49:22 +00:00
|
|
|
{
|
2009-07-07 02:07:30 +00:00
|
|
|
if ( $^O eq 'aix')
|
|
|
|
{
|
|
|
|
delnode_aix $_;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
delnode $_;
|
|
|
|
}
|
2008-05-06 18:49:22 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-08-09 04:07:40 +00:00
|
|
|
if (xCAT::NetworkUtils->getipaddr($_) and not xCAT::NetworkUtils->nodeonmynet($_))
|
2008-05-06 18:49:22 +00:00
|
|
|
{
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
addnode $_;
|
2011-01-17 19:17:38 +00:00
|
|
|
if ($usingipv6) {
|
|
|
|
addnode6 $_;
|
|
|
|
}
|
2008-05-06 18:49:22 +00:00
|
|
|
}
|
|
|
|
}
|
2009-07-07 02:07:30 +00:00
|
|
|
close($omshell) if ($^O ne 'aix');
|
2011-01-18 16:27:00 +00:00
|
|
|
close($omshell6) if ($omshell6 and $^O ne 'aix');
|
2010-12-13 07:33:33 +00:00
|
|
|
foreach my $node (@{$req->{node}})
|
|
|
|
{
|
|
|
|
unless ($machash)
|
|
|
|
{
|
|
|
|
$callback->(
|
|
|
|
{
|
|
|
|
error => ["Unable to open mac table, it may not exist yet"],
|
|
|
|
errorcode => [1]
|
|
|
|
}
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
my $ent = $machash->{$node}->[0]; #tab->getNodeAttribs($node, [qw(mac)]);
|
|
|
|
unless ($ent and $ent->{mac})
|
|
|
|
{
|
|
|
|
$callback->(
|
|
|
|
{
|
2011-08-10 11:25:48 +00:00
|
|
|
warning => ["Unable to find mac address for $node"]
|
2010-12-13 07:33:33 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
}
|
2007-10-26 22:44:33 +00:00
|
|
|
}
|
2008-05-06 18:49:22 +00:00
|
|
|
writeout();
|
2013-04-09 20:21:02 +00:00
|
|
|
if (not $::XCATSITEVALS{externaldhcpservers} and $restartdhcp) {
|
2009-07-07 02:07:30 +00:00
|
|
|
if ( $^O eq 'aix')
|
|
|
|
{
|
|
|
|
restart_dhcpd_aix();
|
|
|
|
}
|
2013-01-07 07:23:55 +00:00
|
|
|
elsif ( $distro =~ /ubuntu.*/ || $distro =~ /debian.*/i)
|
2011-08-15 00:49:23 +00:00
|
|
|
{
|
2012-08-30 02:16:24 +00:00
|
|
|
if (-e '/etc/dhcp/dhcpd.conf') {
|
|
|
|
system("chmod a+r /etc/dhcp/dhcpd.conf");
|
|
|
|
system("/etc/init.d/isc-dhcp-server restart");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
#ubuntu config
|
|
|
|
system("chmod a+r /etc/dhcp3/dhcpd.conf");
|
|
|
|
system("/etc/init.d/dhcp3-server restart");
|
|
|
|
}
|
2011-08-15 00:49:23 +00:00
|
|
|
}
|
2009-07-07 02:07:30 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
system("/etc/init.d/dhcpd restart");
|
2012-06-29 03:17:04 +00:00
|
|
|
# should not chkconfig dhcpd on every makedhcp invoation
|
|
|
|
# it is not appropriate and will cause problem for HAMN
|
|
|
|
# do it in xcatconfig instead
|
|
|
|
#system("chkconfig dhcpd on");
|
2009-07-07 02:07:30 +00:00
|
|
|
}
|
2008-05-15 17:45:47 +00:00
|
|
|
}
|
2009-03-28 15:03:36 +00:00
|
|
|
flock($dhcplockfd,LOCK_UN);
|
2009-03-26 20:33:07 +00:00
|
|
|
umask $oldmask;
|
2007-10-26 22:44:33 +00:00
|
|
|
}
|
2009-07-07 02:07:30 +00:00
|
|
|
# Restart dhcpd on aix
|
|
|
|
sub restart_dhcpd_aix
|
|
|
|
{
|
|
|
|
#Check if dhcpd is running
|
|
|
|
my @res = xCAT::Utils->runcmd('lssrc -s dhcpsd',0);
|
|
|
|
if ( $::RUNCMD_RC != 0)
|
|
|
|
{
|
|
|
|
xCAT::MsgUtils->message("E", "Failed to check dhcpsd status\n");
|
|
|
|
}
|
|
|
|
if ( grep /\sactive/, @res)
|
|
|
|
{
|
|
|
|
xCAT::Utils->runcmd('refresh -s dhcpsd',0);
|
|
|
|
xCAT::MsgUtils->message("E", "Failed to refresh dhcpsd configuration\n") if ( $::RUNCMD_RC);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
xCAT::Utils->runcmd('startsrc -s dhcpsd',0);
|
|
|
|
xCAT::MsgUtils->message("E", "Failed to start dhcpsd\n" ) if ( $::RUNCMD_RC);
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2010-06-15 15:21:29 +00:00
|
|
|
sub getzonesfornet {
|
|
|
|
my $net = shift;
|
|
|
|
my $mask = shift;
|
|
|
|
my @zones = ();
|
2011-01-27 15:34:22 +00:00
|
|
|
if ($net =~ /:/) {#ipv6, for now do the simple stuff under the assumption we won't have a mask indivisible by 4
|
|
|
|
$net =~ s/\/(.*)//;
|
|
|
|
my $maskbits=$1;
|
|
|
|
if ($mask) {
|
|
|
|
die "Not supporting having a mask like $mask on an ipv6 network like $net";
|
|
|
|
}
|
|
|
|
my $netnum= getipaddr($net,GetNumber=>1);
|
2011-07-29 07:00:45 +00:00
|
|
|
unless ($netnum) { return (); }
|
2011-01-27 15:34:22 +00:00
|
|
|
$netnum->brsft(128-$maskbits);
|
|
|
|
my $prefix=$netnum->as_hex();
|
|
|
|
my $nibbs=$maskbits/4;
|
|
|
|
$prefix =~ s/^0x//;
|
|
|
|
my $rev;
|
|
|
|
foreach (reverse(split //,$prefix)) {
|
|
|
|
$rev .= $_.".";
|
|
|
|
$nibbs--;
|
|
|
|
}
|
|
|
|
while ($nibbs) {
|
|
|
|
$rev .= "0.";
|
|
|
|
$nibbs--;
|
|
|
|
}
|
|
|
|
$rev.="ip6.arpa.";
|
|
|
|
return ($rev);
|
|
|
|
}
|
2010-06-15 15:21:29 +00:00
|
|
|
#return all in-addr reverse zones for a given mask and net
|
|
|
|
#for class a,b,c, the answer is easy
|
|
|
|
#for classless, identify the partial byte, do $netbyte | (0xff&~$maskbyte) to get the highest value
|
|
|
|
#return sequence from $net to value calculated above
|
|
|
|
#since old bind.pm only went as far as class c, we will carry that over for now (more people with smaller than class c complained
|
|
|
|
#and none hit the theoretical conflict. FYI, the 'official' method in RFC 2317 seems cumbersome, but maybe one day it makes sense
|
|
|
|
#since this is dhcpv4 for now, we'll use the inet_aton, ntop functions to generate the answers (dhcpv6 omapi would be nice...)
|
|
|
|
my $netn = inet_aton($net);
|
|
|
|
my $maskn = inet_aton($mask);
|
|
|
|
unless ($netn and $mask) { return (); }
|
|
|
|
my $netnum = unpack('N',$netn);
|
|
|
|
my $masknum = unpack('N',$maskn);
|
|
|
|
if ($masknum >= 0xffffff00) { #treat all netmasks higher than 255.255.255.0 as class C
|
|
|
|
$netnum = $netnum & 0xffffff00;
|
|
|
|
$netn = pack('N',$netnum);
|
|
|
|
$net = inet_ntoa($netn);
|
2010-06-16 18:23:30 +00:00
|
|
|
$net =~ s/\.[^\.]*$//;
|
2010-06-15 15:21:29 +00:00
|
|
|
return (join('.',reverse(split('\.',$net))).'.IN-ADDR.ARPA.');
|
2010-06-16 18:14:47 +00:00
|
|
|
} elsif ($masknum > 0xffff0000) { #class b (/16) to /23
|
2010-06-15 15:21:29 +00:00
|
|
|
my $tempnumber = ($netnum >> 8);
|
|
|
|
$masknum = $masknum >> 8;
|
|
|
|
my $highnet = $tempnumber | (0xffffff & ~$masknum);
|
|
|
|
foreach ($tempnumber..$highnet) {
|
|
|
|
$netnum = $_ << 8;
|
|
|
|
$net = inet_ntoa(pack('N',$netnum));
|
2010-06-16 18:23:30 +00:00
|
|
|
$net =~ s/\.[^\.]*$//;
|
2010-06-15 15:21:29 +00:00
|
|
|
push @zones,join('.',reverse(split('\.',$net))).'.IN-ADDR.ARPA.';
|
|
|
|
}
|
|
|
|
return @zones;
|
2010-06-16 18:14:47 +00:00
|
|
|
} elsif ($masknum > 0xff000000) { #class a (/8) to /15, could have made it more flexible, for for only two cases, not worth in
|
2010-06-15 15:21:29 +00:00
|
|
|
my $tempnumber = ($netnum >> 16); #the last two bytes are insignificant, shift them off to make math easier
|
|
|
|
$masknum = $masknum >> 16;
|
|
|
|
my $highnet = $tempnumber | (0xffff & ~$masknum);
|
|
|
|
foreach ($tempnumber..$highnet) {
|
|
|
|
$netnum = $_ << 16; #convert back to the real network value
|
|
|
|
$net = inet_ntoa(pack('N',$netnum));
|
2010-06-16 18:23:30 +00:00
|
|
|
$net =~ s/\.[^\.]*$//;
|
|
|
|
$net =~ s/\.[^\.]*$//;
|
2010-06-15 15:21:29 +00:00
|
|
|
push @zones,join('.',reverse(split('\.',$net))).'.IN-ADDR.ARPA.';
|
|
|
|
}
|
|
|
|
return @zones;
|
2010-06-16 18:14:47 +00:00
|
|
|
} else { #class a (theoretically larger, but those shouldn't exist)
|
|
|
|
my $tempnumber = ($netnum >> 24); #the last two bytes are insignificant, shift them off to make math easier
|
|
|
|
$masknum = $masknum >> 24;
|
|
|
|
my $highnet = $tempnumber | (0xff & ~$masknum);
|
|
|
|
foreach ($tempnumber..$highnet) {
|
|
|
|
$netnum = $_ << 24; #convert back to the real network value
|
|
|
|
$net = inet_ntoa(pack('N',$netnum));
|
2010-06-16 18:23:30 +00:00
|
|
|
$net =~ s/\.[^\.]*$//;
|
|
|
|
$net =~ s/\.[^\.]*$//;
|
|
|
|
$net =~ s/\.[^\.]*$//;
|
2010-06-16 18:14:47 +00:00
|
|
|
push @zones,join('.',reverse(split('\.',$net))).'.IN-ADDR.ARPA.';
|
|
|
|
}
|
|
|
|
return @zones;
|
|
|
|
}
|
2010-06-15 15:21:29 +00:00
|
|
|
}
|
2007-10-26 22:44:33 +00:00
|
|
|
|
2009-03-26 20:08:18 +00:00
|
|
|
sub putmyselffirst {
|
|
|
|
my $srvlist = shift;
|
|
|
|
if ($srvlist =~ /,/) { #TODO: only reshuffle when requested, or allow opt out of reshuffle?
|
|
|
|
my @dnsrvs = split /,/,$srvlist;
|
|
|
|
my @reordered;
|
|
|
|
foreach (@dnsrvs) {
|
2012-08-09 04:07:40 +00:00
|
|
|
if (xCAT::NetworkUtils->thishostisnot($_)) {
|
2009-03-26 20:08:18 +00:00
|
|
|
push @reordered,$_;
|
|
|
|
} else {
|
|
|
|
unshift @reordered,$_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$srvlist = join(', ',@reordered);
|
|
|
|
}
|
|
|
|
return $srvlist;
|
|
|
|
}
|
2011-01-17 19:17:38 +00:00
|
|
|
sub addnet6
|
|
|
|
{
|
2013-04-09 20:21:02 +00:00
|
|
|
if ($::XCATSITEVALS{externaldhcpservers}) { return; }
|
2011-01-17 19:17:38 +00:00
|
|
|
my $netentry = shift;
|
|
|
|
my $net = $netentry->{net};
|
|
|
|
my $iface = $netentry->{iface};
|
|
|
|
my $idx = 0;
|
2011-01-27 15:34:22 +00:00
|
|
|
if (grep /\} # $net subnet_end/,@dhcp6conf) { #need to add to dhcp6conf
|
2011-01-17 19:17:38 +00:00
|
|
|
return;
|
|
|
|
} else { #need to add to dhcp6conf
|
2011-05-01 13:29:32 +00:00
|
|
|
$restartdhcp6=1;
|
2011-01-17 19:17:38 +00:00
|
|
|
while ($idx <= $#dhcp6conf)
|
|
|
|
{
|
|
|
|
if ($dhcp6conf[$idx] =~ /\} # $iface nic_end/) {
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
$idx++;
|
|
|
|
}
|
|
|
|
unless ($dhcp6conf[$idx] =~ /\} # $iface nic_end\n/) {
|
|
|
|
return 1; #TODO: this is an error condition
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2012-05-16 12:15:47 +00:00
|
|
|
|
|
|
|
my $dhcplease = 43200;
|
|
|
|
if (defined $::XCATSITEVALS{'dhcplease'} && $::XCATSITEVALS{'dhcplease'} ne "") {
|
|
|
|
$dhcplease = $::XCATSITEVALS{'dhcplease'};
|
|
|
|
}
|
|
|
|
|
2011-01-17 19:17:38 +00:00
|
|
|
my @netent = (
|
|
|
|
" subnet6 $net {\n",
|
2012-05-16 12:15:47 +00:00
|
|
|
" max-lease-time $dhcplease;\n",
|
|
|
|
" min-lease-time $dhcplease;\n",
|
|
|
|
" default-lease-time $dhcplease;\n",
|
2011-01-17 19:17:38 +00:00
|
|
|
);
|
|
|
|
#for now, just do address allocatios (phase 1)
|
|
|
|
#phase 2 (by 2.6 presumably) will include the various things like DNS server and other options allowed by dhcpv6
|
|
|
|
#gateway is *not* currently allowed to be DHCP designated, router advertises its own self indpendent of dhcp. We'll just keep it that way
|
|
|
|
#domain search list is allowed (rfc 3646)
|
|
|
|
#nis domain is also an alloed option (rfc 3898)
|
|
|
|
#sntp server list (rfc 4075)
|
|
|
|
#ntp server rfc 5908
|
|
|
|
#fqdn rfc 4704
|
|
|
|
#posix timezone rfc 4833/tzdb timezone
|
|
|
|
#phase 3 will include whatever is required to do Netboot6. That might be in the october timeframe for lack of implementations to test
|
|
|
|
#boot url/param (rfc 59070)
|
2013-05-14 15:13:28 +00:00
|
|
|
my $netdomain = $netcfgs{$net}->{domain};
|
|
|
|
unless ($netdomain) { $netdomain = $site_domain; }
|
|
|
|
push @netent, " option domain-name \"".$netdomain."\";\n";
|
2013-01-12 20:03:37 +00:00
|
|
|
|
2013-07-16 16:33:33 +00:00
|
|
|
# add domain-search if not sles10 or rh5
|
|
|
|
my $osv = xCAT::Utils->osver();
|
|
|
|
unless ( ($osv =~ /^sle[sc]10/) || ($osv =~ /^rh.*5$/) ) {
|
|
|
|
# We want something like "option domain-search "foo.com", "bar.com";"
|
|
|
|
my $domainstring = qq~"$netcfgs{$net}->{domain}"~;
|
|
|
|
foreach my $dom (@alldomains) {
|
|
|
|
chomp $dom;
|
|
|
|
if ($dom ne $netcfgs{$net}->{domain}){
|
|
|
|
$domainstring .= qq~, "$dom"~;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($netcfgs{$net}->{domain}) {
|
|
|
|
push @netent, " option domain-search $domainstring;\n";
|
|
|
|
}
|
|
|
|
}
|
2013-01-12 20:03:37 +00:00
|
|
|
|
2011-01-27 15:34:22 +00:00
|
|
|
my $nameservers = $netcfgs{$net}->{nameservers};
|
|
|
|
if ($nameservers and $nameservers =~ /:/) {
|
|
|
|
push @netent," nameservers ".$netcfgs{$net}->{nameservers}.";\n";
|
|
|
|
}
|
|
|
|
my $ddnserver = $nameservers;
|
|
|
|
$ddnserver =~ s/,.*//;
|
2011-02-15 20:54:40 +00:00
|
|
|
my $ddnsdomain;
|
|
|
|
if ($netcfgs{$net}->{ddnsdomain}) {
|
|
|
|
$ddnsdomain = $netcfgs{$net}->{ddnsdomain};
|
|
|
|
}
|
2011-02-11 18:06:26 +00:00
|
|
|
if ($::XCATSITEVALS{dnshandler} =~ /ddns/) {
|
2011-02-15 20:54:40 +00:00
|
|
|
if ($ddnsdomain) {
|
2011-06-10 17:59:30 +00:00
|
|
|
push @netent, " ddns-domainname \"".$ddnsdomain."\";\n";
|
2011-02-15 20:54:40 +00:00
|
|
|
push @netent, " zone $ddnsdomain. {\n";
|
|
|
|
} else {
|
2013-05-14 15:13:28 +00:00
|
|
|
push @netent, " zone $netdomain. {\n";
|
2011-02-15 20:54:40 +00:00
|
|
|
}
|
2011-01-27 15:34:22 +00:00
|
|
|
push @netent, " primary $ddnserver; key xcat_key; \n";
|
|
|
|
push @netent, " }\n";
|
|
|
|
foreach (getzonesfornet($net)) {
|
|
|
|
push @netent, " zone $_ {\n";
|
|
|
|
push @netent, " primary $ddnserver; key xcat_key; \n";
|
|
|
|
push @netent, " }\n";
|
|
|
|
}
|
2011-02-11 18:06:26 +00:00
|
|
|
}
|
2011-01-17 19:17:38 +00:00
|
|
|
if ($netcfgs{$net}->{range}) {
|
|
|
|
push @netent," range6 ".$netcfgs{$net}->{range}.";\n";
|
|
|
|
} else {
|
|
|
|
$callback->({warning => ["No dynamic range specified for $net. Hosts with no static address will receive no addresses on this subnet."]});
|
|
|
|
}
|
|
|
|
push @netent, " } # $net subnet_end\n";
|
|
|
|
splice(@dhcp6conf, $idx, 0, @netent);
|
|
|
|
}
|
2008-05-06 18:49:22 +00:00
|
|
|
sub addnet
|
|
|
|
{
|
2013-04-09 20:21:02 +00:00
|
|
|
if ($::XCATSITEVALS{externaldhcpservers}) { return; }
|
2008-05-06 18:49:22 +00:00
|
|
|
my $net = shift;
|
|
|
|
my $mask = shift;
|
|
|
|
my $nic;
|
2013-01-12 20:03:37 +00:00
|
|
|
my $domain;
|
2008-06-02 12:00:46 +00:00
|
|
|
my $firstoctet = $net;
|
|
|
|
$firstoctet =~ s/^(\d+)\..*/$1/;
|
|
|
|
if ($net eq "169.254.0.0" or ($firstoctet >= 224 and $firstoctet <= 239)) {
|
2008-05-15 17:45:47 +00:00
|
|
|
return;
|
|
|
|
}
|
2008-05-06 18:49:22 +00:00
|
|
|
unless (grep /\} # $net\/$mask subnet_end/, @dhcpconf)
|
|
|
|
{
|
2008-05-15 17:45:47 +00:00
|
|
|
$restartdhcp=1;
|
2008-05-06 18:49:22 +00:00
|
|
|
foreach (@nrn)
|
|
|
|
{ # search for relevant NIC
|
2008-11-26 00:00:54 +00:00
|
|
|
my @ent = split /:/;
|
2008-06-02 12:00:46 +00:00
|
|
|
$firstoctet = $ent[0];
|
|
|
|
$firstoctet =~ s/^(\d+)\..*/$1/;
|
|
|
|
if ($ent[0] eq "169.254.0.0" or ($firstoctet >= 224 and $firstoctet <= 239))
|
2008-05-06 18:49:22 +00:00
|
|
|
{
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
if ($ent[0] eq $net and $ent[2] eq $mask)
|
|
|
|
{
|
2008-11-26 00:00:54 +00:00
|
|
|
$nic = $ent[1];
|
2013-10-29 02:48:31 +00:00
|
|
|
# The first nic that matches the network,
|
|
|
|
# what will happen if there are more than one nics in the same subnet,
|
|
|
|
# and we want to use the second nic as the dhcp interfaces?
|
|
|
|
# this is a TODO
|
|
|
|
last;
|
2008-05-06 18:49:22 +00:00
|
|
|
}
|
|
|
|
}
|
2008-05-29 17:44:51 +00:00
|
|
|
#print " add $net $mask under $nic\n";
|
2008-05-06 18:49:22 +00:00
|
|
|
my $idx = 0;
|
2009-07-07 02:07:30 +00:00
|
|
|
if ( $^O ne 'aix')
|
2008-05-06 18:49:22 +00:00
|
|
|
{
|
2009-07-07 02:07:30 +00:00
|
|
|
while ($idx <= $#dhcpconf)
|
|
|
|
{
|
|
|
|
if ($dhcpconf[$idx] =~ /\} # $nic nic_end\n/)
|
2008-05-06 18:49:22 +00:00
|
|
|
{
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
$idx++;
|
2009-07-07 02:07:30 +00:00
|
|
|
}
|
|
|
|
unless ($dhcpconf[$idx] =~ /\} # $nic nic_end\n/)
|
|
|
|
{
|
2013-10-29 02:48:31 +00:00
|
|
|
$callback->(
|
|
|
|
{
|
|
|
|
error =>
|
|
|
|
["Could not add the subnet $net/$mask for nic $nic into $dhcpconffile."],
|
|
|
|
errorcode => [1]
|
|
|
|
}
|
|
|
|
);
|
2009-07-07 02:07:30 +00:00
|
|
|
return 1; #TODO: this is an error condition
|
|
|
|
}
|
2008-05-06 18:49:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# if here, means we found the idx before which to insert
|
|
|
|
my $nettab = xCAT::Table->new("networks");
|
|
|
|
my $nameservers;
|
2009-03-26 20:08:18 +00:00
|
|
|
my $ntpservers;
|
|
|
|
my $logservers;
|
2008-05-06 18:49:22 +00:00
|
|
|
my $gateway;
|
|
|
|
my $tftp;
|
|
|
|
my $range;
|
|
|
|
my $myip;
|
2012-08-09 04:07:40 +00:00
|
|
|
$myip = xCAT::NetworkUtils->my_ip_facing($net);
|
2008-05-06 18:49:22 +00:00
|
|
|
if ($nettab)
|
|
|
|
{
|
2009-07-07 02:07:30 +00:00
|
|
|
my $mask_formated = $mask;
|
|
|
|
if ( $^O eq 'aix')
|
|
|
|
{
|
2013-05-28 15:30:40 +00:00
|
|
|
my $mask_shift = 32 - $mask;
|
|
|
|
$mask_formated = inet_ntoa(pack("N", 2**$mask - 1 << $mask_shift));
|
|
|
|
# $mask_formated = inet_ntoa(pack("N", 2**$mask - 1 << (32 - $mask)));
|
2009-07-07 02:07:30 +00:00
|
|
|
}
|
2013-01-12 20:03:37 +00:00
|
|
|
|
2008-05-06 18:49:22 +00:00
|
|
|
my ($ent) =
|
2009-07-07 02:07:30 +00:00
|
|
|
$nettab->getAttribs({net => $net, mask => $mask_formated},
|
2013-01-12 20:03:37 +00:00
|
|
|
qw(tftpserver nameservers ntpservers logservers gateway dynamicrange dhcpserver domain));
|
2009-03-26 20:08:18 +00:00
|
|
|
if ($ent and $ent->{ntpservers}) {
|
|
|
|
$ntpservers = $ent->{ntpservers};
|
|
|
|
} elsif ($sitentpservers) {
|
|
|
|
$ntpservers = $sitentpservers;
|
|
|
|
}
|
|
|
|
if ($ent and $ent->{logservers}) {
|
|
|
|
$logservers = $ent->{logservers};
|
|
|
|
} elsif ($sitelogservers) {
|
|
|
|
$logservers = $sitelogservers;
|
|
|
|
}
|
2013-01-12 20:03:37 +00:00
|
|
|
if ($ent and $ent->{domain}) {
|
|
|
|
$domain = $ent->{domain};
|
|
|
|
} elsif ($site_domain) {
|
|
|
|
$domain = $site_domain;
|
|
|
|
} else {
|
|
|
|
$callback->(
|
|
|
|
{
|
|
|
|
warning => [
|
|
|
|
"No $net specific entry for domain, and no domain defined in site table."
|
|
|
|
]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2008-05-06 18:49:22 +00:00
|
|
|
if ($ent and $ent->{nameservers})
|
|
|
|
{
|
2011-05-13 07:31:18 +00:00
|
|
|
$nameservers = $ent->{nameservers};
|
2008-05-06 18:49:22 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-03-26 20:08:18 +00:00
|
|
|
if ($sitenameservers) {
|
|
|
|
$nameservers = $sitenameservers;
|
|
|
|
} else {
|
2008-05-06 18:49:22 +00:00
|
|
|
$callback->(
|
|
|
|
{
|
|
|
|
warning => [
|
2009-03-26 20:08:18 +00:00
|
|
|
"No $net specific entry for nameservers, and no nameservers defined in site table."
|
2008-05-06 18:49:22 +00:00
|
|
|
]
|
|
|
|
}
|
|
|
|
);
|
2009-03-26 20:08:18 +00:00
|
|
|
}
|
2008-05-06 18:49:22 +00:00
|
|
|
}
|
2011-06-13 03:58:36 +00:00
|
|
|
|
|
|
|
# convert <xcatmaster> to nameserver IP
|
2014-01-02 06:23:43 +00:00
|
|
|
$nameservers =~ s/<xcatmaster>/$myip/g;
|
2012-02-09 07:53:28 +00:00
|
|
|
|
|
|
|
if (!$ntpservers || ($ntpservers eq '<xcatmaster>'))
|
|
|
|
{
|
|
|
|
$ntpservers = $myip;
|
|
|
|
}
|
2011-06-13 03:58:36 +00:00
|
|
|
|
2009-03-26 20:08:18 +00:00
|
|
|
$nameservers=putmyselffirst($nameservers);
|
2009-09-01 12:13:33 +00:00
|
|
|
$ntpservers=putmyselffirst($ntpservers);
|
|
|
|
$logservers=putmyselffirst($logservers);
|
2009-03-26 20:08:18 +00:00
|
|
|
|
|
|
|
|
2008-05-06 18:49:22 +00:00
|
|
|
if ($ent and $ent->{tftpserver})
|
|
|
|
{
|
|
|
|
$tftp = $ent->{tftpserver};
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ #presume myself to be it, dhcp no longer does this for us
|
|
|
|
$tftp = $myip;
|
|
|
|
}
|
|
|
|
if ($ent and $ent->{gateway})
|
|
|
|
{
|
|
|
|
$gateway = $ent->{gateway};
|
2011-02-24 03:15:01 +00:00
|
|
|
|
2011-03-22 02:22:58 +00:00
|
|
|
if ($gateway eq '<xcatmaster>')
|
2011-02-24 03:15:01 +00:00
|
|
|
{
|
|
|
|
if(xCAT::NetworkUtils->ip_forwarding_enabled())
|
|
|
|
{
|
|
|
|
$gateway = $myip;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$gateway = '';
|
|
|
|
}
|
|
|
|
}
|
2008-05-06 18:49:22 +00:00
|
|
|
}
|
|
|
|
if ($ent and $ent->{dynamicrange})
|
|
|
|
{
|
|
|
|
unless ($ent->{dhcpserver}
|
2012-08-09 04:07:40 +00:00
|
|
|
and xCAT::NetworkUtils->thishostisnot($ent->{dhcpserver}))
|
2008-05-06 18:49:22 +00:00
|
|
|
{ #If specific, only one dhcp server gets a dynamic range
|
2010-06-16 19:19:47 +00:00
|
|
|
$range = $ent->{dynamicrange};
|
|
|
|
$range =~ s/[,-]/ /g;
|
2008-05-06 18:49:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$callback->(
|
|
|
|
{
|
|
|
|
warning => [
|
2010-03-18 05:47:05 +00:00
|
|
|
"No dynamic range specified for $net. If hardware discovery is being used, a dynamic range is required."
|
2008-05-06 18:49:22 +00:00
|
|
|
]
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$callback->(
|
|
|
|
{
|
|
|
|
error =>
|
|
|
|
["Unable to open networks table, please run makenetworks"],
|
|
|
|
errorcode => [1]
|
|
|
|
}
|
|
|
|
);
|
|
|
|
return 1;
|
|
|
|
}
|
2007-10-26 22:44:33 +00:00
|
|
|
|
2009-07-07 02:07:30 +00:00
|
|
|
if ( $^O eq 'aix')
|
|
|
|
{
|
|
|
|
return gen_aix_net( $myip, $net, $mask, $gateway, $tftp,
|
|
|
|
$logservers, $ntpservers, $domain,
|
|
|
|
$nameservers, $range);
|
|
|
|
}
|
2008-05-06 18:49:22 +00:00
|
|
|
my @netent;
|
2009-07-07 02:07:30 +00:00
|
|
|
|
2008-05-06 18:49:22 +00:00
|
|
|
my $maskn = unpack("N", inet_aton($mask));
|
|
|
|
my $netn = unpack("N", inet_aton($net));
|
2012-05-16 12:15:47 +00:00
|
|
|
my $dhcplease = 43200;
|
|
|
|
if (defined $::XCATSITEVALS{'dhcplease'} && $::XCATSITEVALS{'dhcplease'} ne "") {
|
|
|
|
$dhcplease = $::XCATSITEVALS{'dhcplease'};
|
|
|
|
}
|
2008-05-06 18:49:22 +00:00
|
|
|
@netent = (
|
|
|
|
" subnet $net netmask $mask {\n",
|
2012-05-16 12:15:47 +00:00
|
|
|
" max-lease-time $dhcplease;\n",
|
|
|
|
" min-lease-time $dhcplease;\n",
|
|
|
|
" default-lease-time $dhcplease;\n"
|
2008-05-06 18:49:22 +00:00
|
|
|
);
|
|
|
|
if ($gateway)
|
|
|
|
{
|
|
|
|
my $gaten = unpack("N", inet_aton($gateway));
|
|
|
|
if (($gaten & $maskn) == ($maskn & $netn))
|
|
|
|
{
|
|
|
|
push @netent, " option routers $gateway;\n";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$callback->(
|
|
|
|
{
|
|
|
|
error => [
|
|
|
|
"Specified gateway $gateway is not valid for $net/$mask, must be on same network"
|
|
|
|
],
|
|
|
|
errorcode => [1]
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($tftp)
|
|
|
|
{
|
|
|
|
push @netent, " next-server $tftp;\n";
|
|
|
|
}
|
2009-03-26 20:27:55 +00:00
|
|
|
if ($logservers) {
|
|
|
|
push @netent, " option log-servers $logservers;\n";
|
|
|
|
} elsif ($myip){
|
2008-11-26 00:00:54 +00:00
|
|
|
push @netent, " option log-servers $myip;\n";
|
2009-03-26 20:27:55 +00:00
|
|
|
}
|
|
|
|
if ($ntpservers) {
|
|
|
|
push @netent, " option ntp-servers $ntpservers;\n";
|
2009-03-26 20:08:18 +00:00
|
|
|
}
|
2008-05-06 18:49:22 +00:00
|
|
|
if ($nameservers)
|
|
|
|
{
|
2011-05-24 07:58:22 +00:00
|
|
|
push @netent, " option domain-name \"$domain\";\n";
|
2008-05-06 18:49:22 +00:00
|
|
|
push @netent, " option domain-name-servers $nameservers;\n";
|
|
|
|
}
|
2013-01-12 20:03:37 +00:00
|
|
|
|
2013-07-16 16:33:33 +00:00
|
|
|
# add domain-search if not sles10 or rh5
|
|
|
|
my $osv = xCAT::Utils->osver();
|
|
|
|
unless ( ($osv =~ /^sle[sc]10/) || ($osv =~ /^rh.*5$/) ) {
|
|
|
|
# want something like "option domain-search "foo.com", "bar.com";"
|
|
|
|
my $domainstring = qq~"$domain"~;
|
|
|
|
foreach my $dom (@alldomains) {
|
|
|
|
chomp $dom;
|
|
|
|
if ($dom ne $domain){
|
|
|
|
$domainstring .= qq~, "$dom"~;
|
|
|
|
}
|
|
|
|
}
|
2013-01-12 20:03:37 +00:00
|
|
|
|
2013-07-16 16:33:33 +00:00
|
|
|
if ($domain) {
|
|
|
|
push @netent, " option domain-search $domainstring;\n";
|
|
|
|
}
|
2013-01-12 20:03:37 +00:00
|
|
|
}
|
|
|
|
|
2010-05-21 00:54:05 +00:00
|
|
|
my $ddnserver = $nameservers;
|
2010-05-21 20:38:18 +00:00
|
|
|
$ddnserver =~ s/,.*//;
|
2011-02-15 20:54:40 +00:00
|
|
|
my $ddnsdomain;
|
|
|
|
if ($netcfgs{$net}->{ddnsdomain}) {
|
|
|
|
$ddnsdomain = $netcfgs{$net}->{ddnsdomain};
|
|
|
|
}
|
|
|
|
if ($::XCATSITEVALS{dnshandler} =~ /ddns/) {
|
|
|
|
if ($ddnsdomain) {
|
2011-06-10 17:59:30 +00:00
|
|
|
push @netent, " ddns-domainname \"".$ddnsdomain."\";\n";
|
2011-02-15 20:54:40 +00:00
|
|
|
push @netent, " zone $ddnsdomain. {\n";
|
|
|
|
} else {
|
|
|
|
push @netent, " zone $domain. {\n";
|
|
|
|
}
|
2011-05-24 07:58:22 +00:00
|
|
|
if ($ddnserver)
|
|
|
|
{
|
|
|
|
push @netent, " primary $ddnserver; key xcat_key; \n";
|
|
|
|
}
|
2010-05-21 00:54:05 +00:00
|
|
|
push @netent, " }\n";
|
2010-06-15 15:28:05 +00:00
|
|
|
foreach (getzonesfornet($net,$mask)) {
|
2010-06-16 17:59:42 +00:00
|
|
|
push @netent, "zone $_ {\n";
|
2011-05-24 07:58:22 +00:00
|
|
|
if ($ddnserver)
|
|
|
|
{
|
|
|
|
push @netent, " primary $ddnserver; key xcat_key; \n";
|
|
|
|
}
|
2010-06-15 15:21:29 +00:00
|
|
|
push @netent, " }\n";
|
|
|
|
}
|
2011-02-11 18:06:26 +00:00
|
|
|
}
|
2010-06-15 15:21:29 +00:00
|
|
|
|
2009-06-29 18:37:45 +00:00
|
|
|
my $tmpmaskn = unpack("N", inet_aton($mask));
|
|
|
|
my $maskbits = 32;
|
|
|
|
while (not ($tmpmaskn & 1)) {
|
|
|
|
$maskbits--;
|
|
|
|
$tmpmaskn=$tmpmaskn>>1;
|
|
|
|
}
|
|
|
|
|
2009-07-06 21:05:44 +00:00
|
|
|
# $lstatements = 'if exists gpxe.bus-id { filename = \"\"; } else if exists client-architecture { filename = \"xcat/xnba.kpxe\"; } '.$lstatements;
|
2011-09-15 22:00:55 +00:00
|
|
|
push @netent, " if option user-class-identifier = \"xNBA\" and option client-architecture = 00:00 { #x86, xCAT Network Boot Agent\n";
|
2012-02-13 16:00:15 +00:00
|
|
|
push @netent, " always-broadcast on;\n";
|
2009-08-21 23:58:12 +00:00
|
|
|
push @netent, " filename = \"http://$tftp/tftpboot/xcat/xnba/nets/".$net."_".$maskbits."\";\n";
|
2011-09-15 22:00:55 +00:00
|
|
|
push @netent, " } else if option user-class-identifier = \"xNBA\" and option client-architecture = 00:09 { #x86, xCAT Network Boot Agent\n";
|
|
|
|
push @netent, " filename = \"http://$tftp/tftpboot/xcat/xnba/nets/".$net."_".$maskbits.".uefi\";\n";
|
2009-06-29 18:37:45 +00:00
|
|
|
push @netent, " } else if option client-architecture = 00:00 { #x86\n";
|
2009-07-06 21:05:44 +00:00
|
|
|
push @netent, " filename \"xcat/xnba.kpxe\";\n";
|
2008-09-12 13:56:48 +00:00
|
|
|
push @netent, " } else if option vendor-class-identifier = \"Etherboot-5.4\" { #x86\n";
|
2009-08-24 18:25:17 +00:00
|
|
|
push @netent, " filename \"xcat/xnba.kpxe\";\n";
|
2011-09-15 22:00:55 +00:00
|
|
|
push @netent,
|
|
|
|
" } else if option client-architecture = 00:07 { #x86_64 uefi\n ";
|
|
|
|
push @netent, " filename \"xcat/xnba.efi\";\n";
|
|
|
|
push @netent,
|
|
|
|
" } else if option client-architecture = 00:09 { #x86_64 uefi alternative id\n ";
|
|
|
|
push @netent, " filename \"xcat/xnba.efi\";\n";
|
2008-05-06 18:49:22 +00:00
|
|
|
push @netent,
|
|
|
|
" } else if option client-architecture = 00:02 { #ia64\n ";
|
|
|
|
push @netent, " filename \"elilo.efi\";\n";
|
|
|
|
push @netent,
|
|
|
|
" } else if substring(filename,0,1) = null { #otherwise, provide yaboot if the client isn't specific\n ";
|
|
|
|
push @netent, " filename \"/yaboot\";\n";
|
|
|
|
push @netent, " }\n";
|
2011-01-26 14:13:05 +00:00
|
|
|
if ($range) {
|
|
|
|
foreach my $singlerange (split /;/,$range) {
|
|
|
|
push @netent, " range dynamic-bootp $singlerange;\n"
|
|
|
|
}
|
|
|
|
}
|
2008-05-06 18:49:22 +00:00
|
|
|
push @netent, " } # $net\/$mask subnet_end\n";
|
|
|
|
splice(@dhcpconf, $idx, 0, @netent);
|
|
|
|
}
|
|
|
|
}
|
2007-10-26 22:44:33 +00:00
|
|
|
|
2009-07-07 02:07:30 +00:00
|
|
|
######################################################
|
|
|
|
# Generate network configuration for aix
|
|
|
|
######################################################
|
|
|
|
sub gen_aix_net
|
|
|
|
{
|
|
|
|
my $myip = shift;
|
|
|
|
my $net = shift;
|
|
|
|
my $mask = shift;
|
|
|
|
my $gateway = shift;
|
|
|
|
my $tftp = shift;
|
|
|
|
my $logservers = shift;
|
|
|
|
my $ntpservers = shift;
|
|
|
|
my $domain = shift;
|
|
|
|
my $nameservers = shift;
|
|
|
|
my $range = shift;
|
|
|
|
|
|
|
|
my $idx = 0;
|
|
|
|
while ( $idx <= $#dhcpconf)
|
|
|
|
{
|
|
|
|
if ($dhcpconf[$idx] =~ /#Network configuration end\n/)
|
|
|
|
{
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
$idx++;
|
|
|
|
}
|
|
|
|
|
|
|
|
unless ($dhcpconf[$idx] =~ /#Network configuration end\n/)
|
|
|
|
{
|
|
|
|
return 1; #TODO: this is an error condition
|
|
|
|
}
|
|
|
|
|
|
|
|
$range =~ s/ /-/;
|
2009-10-20 11:33:51 +00:00
|
|
|
my @netent = ( "network $net $mask\n{\n");
|
2009-07-07 02:07:30 +00:00
|
|
|
if ( $gateway)
|
|
|
|
{
|
2011-03-22 02:22:58 +00:00
|
|
|
if ($gateway eq '<xcatmaster>')
|
2011-02-24 03:15:01 +00:00
|
|
|
{
|
|
|
|
if(xCAT::NetworkUtils->ip_forwarding_enabled())
|
|
|
|
{
|
|
|
|
$gateway = $myip;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$gateway = '';
|
|
|
|
}
|
|
|
|
}
|
2012-08-09 04:07:40 +00:00
|
|
|
if (xCAT::NetworkUtils::isInSameSubnet($gateway,$net,$mask,1))
|
2009-07-07 02:07:30 +00:00
|
|
|
{
|
|
|
|
push @netent, " option 3 $gateway\n";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$callback->(
|
|
|
|
{
|
|
|
|
error => [
|
|
|
|
"Specified gateway $gateway is not valid for $net/$mask, must be on same network"
|
|
|
|
],
|
|
|
|
errorcode => [1]
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
# if ($tftp)
|
|
|
|
# {
|
|
|
|
# push @netent, " option 66 $tftp\n";
|
|
|
|
# }
|
|
|
|
if ($logservers) {
|
2009-08-27 08:15:01 +00:00
|
|
|
$logservers =~ s/,/ /g;
|
2009-07-07 02:07:30 +00:00
|
|
|
push @netent, " option 7 $logservers\n";
|
|
|
|
} elsif ($myip){
|
|
|
|
push @netent, " option 7 $myip\n";
|
|
|
|
}
|
|
|
|
if ($ntpservers) {
|
2009-08-27 08:15:01 +00:00
|
|
|
$ntpservers =~ s/,/ /g;
|
2009-07-07 02:07:30 +00:00
|
|
|
push @netent, " option 42 $ntpservers\n";
|
|
|
|
} elsif ($myip){
|
|
|
|
push @netent, " option 42 $myip\n";
|
|
|
|
}
|
|
|
|
push @netent, " option 15 \"$domain\"\n";
|
|
|
|
if ($nameservers)
|
|
|
|
{
|
2009-08-27 08:15:01 +00:00
|
|
|
$nameservers =~ s/,/ /g;
|
2009-07-07 02:07:30 +00:00
|
|
|
push @netent, " option 6 $nameservers\n";
|
|
|
|
}
|
2009-10-20 11:33:51 +00:00
|
|
|
push @netent, " subnet $net $range\n {\n";
|
2009-07-07 02:07:30 +00:00
|
|
|
push @netent, " } # $net/$mask ip configuration end\n";
|
|
|
|
push @netent, "} # $net/$mask subnet_end\n\n";
|
|
|
|
|
|
|
|
splice(@dhcpconf, $idx, 0, @netent);
|
|
|
|
}
|
|
|
|
|
2008-05-06 18:49:22 +00:00
|
|
|
sub addnic
|
|
|
|
{
|
2013-04-09 20:21:02 +00:00
|
|
|
if ($::XCATSITEVALS{externaldhcpservers}) { return; }
|
2008-05-06 18:49:22 +00:00
|
|
|
my $nic = shift;
|
2011-01-17 19:17:38 +00:00
|
|
|
my $conf = shift;
|
2008-05-06 18:49:22 +00:00
|
|
|
my $firstindex = 0;
|
|
|
|
my $lastindex = 0;
|
2011-01-17 19:17:38 +00:00
|
|
|
unless (grep /} # $nic nic_end/, @$conf)
|
2008-05-06 18:49:22 +00:00
|
|
|
{ #add a section if not there
|
2011-05-01 13:29:32 +00:00
|
|
|
#$restartdhcp=1;
|
|
|
|
#print "Adding NIC $nic\n";
|
2009-03-17 20:11:27 +00:00
|
|
|
if ($nic =~ /!remote!/) {
|
2011-01-17 19:17:38 +00:00
|
|
|
push @$conf, "#shared-network $nic {\n";
|
|
|
|
push @$conf, "#\} # $nic nic_end\n";
|
2009-03-17 20:11:27 +00:00
|
|
|
} else {
|
2011-01-17 19:17:38 +00:00
|
|
|
push @$conf, "shared-network $nic {\n";
|
|
|
|
push @$conf, "\} # $nic nic_end\n";
|
2009-03-17 20:11:27 +00:00
|
|
|
}
|
|
|
|
|
2008-05-06 18:49:22 +00:00
|
|
|
}
|
2007-10-26 22:44:33 +00:00
|
|
|
|
|
|
|
#return; #Don't touch it, it should already be fine..
|
|
|
|
#my $idx=0;
|
|
|
|
#while ($idx <= $#dhcpconf) {
|
|
|
|
# if ($dhcpconf[$idx] =~ /^shared-network $nic {/) {
|
|
|
|
# $firstindex = $idx; # found the first place to chop...
|
|
|
|
# } elsif ($dhcpconf[$idx] =~ /} # $nic network_end/) {
|
|
|
|
# $lastindex=$idx;
|
|
|
|
# }
|
|
|
|
# $idx++;
|
|
|
|
#}
|
|
|
|
#print Dumper(\@dhcpconf);
|
|
|
|
#if ($firstindex and $lastindex) {
|
|
|
|
# splice @dhcpconf,$firstindex,($lastindex-$firstindex+1);
|
|
|
|
#}
|
|
|
|
#print Dumper(\@dhcpconf);
|
|
|
|
}
|
|
|
|
|
2008-05-06 18:49:22 +00:00
|
|
|
sub writeout
|
|
|
|
{
|
2013-04-09 20:21:02 +00:00
|
|
|
if ($::XCATSITEVALS{externaldhcpservers}) { return; }
|
2011-06-01 17:41:12 +00:00
|
|
|
|
|
|
|
# add the new entries to the dhcp config file
|
2008-05-06 18:49:22 +00:00
|
|
|
my $targ;
|
2009-07-07 02:07:30 +00:00
|
|
|
open($targ, '>', $dhcpconffile);
|
2011-01-21 23:34:11 +00:00
|
|
|
my $idx;
|
|
|
|
my $skipone;
|
|
|
|
foreach $idx (0..$#dhcpconf)
|
2008-05-06 18:49:22 +00:00
|
|
|
{
|
2011-01-21 23:34:11 +00:00
|
|
|
#avoid writing out empty shared network declarations
|
|
|
|
if ($dhcpconf[$idx] =~ /^shared-network/ and $dhcpconf[$idx+1] =~ /^} .* nic_end/) {
|
|
|
|
$skipone=1;
|
|
|
|
next;
|
|
|
|
} elsif ($skipone) {
|
|
|
|
$skipone=0;
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
print $targ $dhcpconf[$idx];
|
2008-05-06 18:49:22 +00:00
|
|
|
}
|
2011-06-01 17:41:12 +00:00
|
|
|
|
|
|
|
if ($^O eq 'aix')
|
|
|
|
{
|
|
|
|
# add back any NIM entries that were saved earlier
|
|
|
|
if (@aixcfg) {
|
|
|
|
foreach $idx (0..$#aixcfg)
|
|
|
|
{
|
|
|
|
print $targ $aixcfg[$idx];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-05-06 18:49:22 +00:00
|
|
|
close($targ);
|
2011-09-27 17:55:07 +00:00
|
|
|
@dhcpconf=(); #dispose of the file contents in memory, no longer needed
|
|
|
|
@aixcfg=();
|
2011-06-01 17:41:12 +00:00
|
|
|
|
|
|
|
|
2011-01-17 19:17:38 +00:00
|
|
|
if (@dhcp6conf) {
|
|
|
|
open($targ, '>', $dhcp6conffile);
|
2011-01-27 15:34:22 +00:00
|
|
|
foreach $idx (0..$#dhcp6conf)
|
2011-01-17 19:17:38 +00:00
|
|
|
{
|
2011-01-27 15:34:22 +00:00
|
|
|
if ($dhcp6conf[$idx] =~ /^shared-network/ and $dhcp6conf[$idx+1] =~ /^} .* nic_end/) {
|
|
|
|
$skipone=1;
|
|
|
|
next;
|
|
|
|
} elsif ($skipone) {
|
|
|
|
$skipone=0;
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
print $targ $dhcp6conf[$idx];
|
2011-01-17 19:17:38 +00:00
|
|
|
}
|
|
|
|
close($targ);
|
2011-09-27 15:34:05 +00:00
|
|
|
@dhcp6conf=();
|
2011-01-17 19:17:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub newconfig6 {
|
2013-04-09 20:21:02 +00:00
|
|
|
if ($::XCATSITEVALS{externaldhcpservers}) { return; }
|
2011-01-17 19:17:38 +00:00
|
|
|
#phase 1, basic working
|
|
|
|
#phase 2, ddns too, evaluate other stuff from dhcpv4 as applicable
|
|
|
|
push @dhcp6conf, "#xCAT generated dhcp configuration\n";
|
|
|
|
push @dhcp6conf, "\n";
|
2011-01-27 15:34:22 +00:00
|
|
|
push @dhcp6conf, "ddns-update-style interim;\n";
|
|
|
|
push @dhcp6conf, "ignore client-updates;\n";
|
2011-08-19 14:37:07 +00:00
|
|
|
# push @dhcp6conf, "update-static-leases on;\n";
|
2011-01-17 19:17:38 +00:00
|
|
|
push @dhcp6conf, "omapi-port 7912;\n"; #Enable omapi...
|
|
|
|
push @dhcp6conf, "key xcat_key {\n";
|
|
|
|
push @dhcp6conf, " algorithm hmac-md5;\n";
|
|
|
|
my $passtab = xCAT::Table->new('passwd', -create => 1);
|
|
|
|
(my $passent) =
|
|
|
|
$passtab->getAttribs({key => 'omapi', username => 'xcat_key'}, 'password');
|
|
|
|
my $secret = encode_base64(genpassword(32)); #Random from set of 62^32
|
|
|
|
chomp $secret;
|
|
|
|
if ($passent->{password}) { $secret = $passent->{password}; }
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$callback->(
|
|
|
|
{
|
|
|
|
data =>
|
|
|
|
["The dhcp server must be restarted for OMAPI function to work"]
|
|
|
|
}
|
|
|
|
);
|
|
|
|
$passtab->setAttribs({key => 'omapi'},
|
|
|
|
{username => 'xcat_key', password => $secret});
|
|
|
|
}
|
|
|
|
|
|
|
|
push @dhcp6conf, " secret \"" . $secret . "\";\n";
|
|
|
|
push @dhcp6conf, "};\n";
|
|
|
|
push @dhcp6conf, "omapi-key xcat_key;\n";
|
|
|
|
#that is all for pristine ipv6 config
|
2007-10-26 22:44:33 +00:00
|
|
|
}
|
|
|
|
|
2008-05-06 18:49:22 +00:00
|
|
|
sub newconfig
|
|
|
|
{
|
2013-04-09 20:21:02 +00:00
|
|
|
if ($::XCATSITEVALS{externaldhcpservers}) { return; }
|
2009-07-07 02:07:30 +00:00
|
|
|
return newconfig_aix() if ( $^O eq 'aix');
|
2008-01-26 17:55:34 +00:00
|
|
|
|
2008-05-06 18:49:22 +00:00
|
|
|
# This function puts a standard header in and enough to make omapi work.
|
|
|
|
my $passtab = xCAT::Table->new('passwd', -create => 1);
|
|
|
|
push @dhcpconf, "#xCAT generated dhcp configuration\n";
|
|
|
|
push @dhcpconf, "\n";
|
|
|
|
push @dhcpconf, "authoritative;\n";
|
2009-07-06 21:05:44 +00:00
|
|
|
push @dhcpconf, "option space isan;\n";
|
|
|
|
push @dhcpconf, "option isan-encap-opts code 43 = encapsulate isan;\n";
|
|
|
|
push @dhcpconf, "option isan.iqn code 203 = string;\n";
|
|
|
|
push @dhcpconf, "option isan.root-path code 201 = string;\n";
|
2008-11-07 14:11:05 +00:00
|
|
|
push @dhcpconf, "option space gpxe;\n";
|
|
|
|
push @dhcpconf, "option gpxe-encap-opts code 175 = encapsulate gpxe;\n";
|
|
|
|
push @dhcpconf, "option gpxe.bus-id code 177 = string;\n";
|
2009-08-21 23:58:12 +00:00
|
|
|
push @dhcpconf, "option user-class-identifier code 77 = string;\n";
|
2009-07-06 21:05:44 +00:00
|
|
|
push @dhcpconf, "option gpxe.no-pxedhcp code 176 = unsigned integer 8;\n";
|
2011-09-13 13:59:53 +00:00
|
|
|
push @dhcpconf, "option tcode code 101 = text;\n";
|
|
|
|
|
2009-07-06 21:05:44 +00:00
|
|
|
push @dhcpconf, "option iscsi-initiator-iqn code 203 = string;\n"; #Only via gPXE, not a standard
|
2010-05-20 00:56:15 +00:00
|
|
|
push @dhcpconf, "ddns-update-style interim;\n";
|
2010-06-22 15:22:12 +00:00
|
|
|
push @dhcpconf, "ignore client-updates;\n"; #Windows clients like to do all caps, very un xCAT-like
|
2011-08-19 14:37:07 +00:00
|
|
|
# push @dhcpconf, "update-static-leases on;\n"; #makedns rendered optional
|
2008-05-06 18:49:22 +00:00
|
|
|
push @dhcpconf,
|
|
|
|
"option client-architecture code 93 = unsigned integer 16;\n";
|
2011-09-13 13:59:53 +00:00
|
|
|
if ($::XCATSITEVALS{timezone}) {
|
|
|
|
push @dhcpconf, "option tcode \"".$::XCATSITEVALS{timezone}."\";\n";
|
|
|
|
}
|
2009-07-06 21:05:44 +00:00
|
|
|
push @dhcpconf, "option gpxe.no-pxedhcp 1;\n";
|
2008-05-06 18:49:22 +00:00
|
|
|
push @dhcpconf, "\n";
|
|
|
|
push @dhcpconf, "omapi-port 7911;\n"; #Enable omapi...
|
|
|
|
push @dhcpconf, "key xcat_key {\n";
|
|
|
|
push @dhcpconf, " algorithm hmac-md5;\n";
|
|
|
|
(my $passent) =
|
2008-07-18 18:40:45 +00:00
|
|
|
$passtab->getAttribs({key => 'omapi', username => 'xcat_key'}, 'password');
|
2008-05-06 18:49:22 +00:00
|
|
|
my $secret = encode_base64(genpassword(32)); #Random from set of 62^32
|
|
|
|
chomp $secret;
|
|
|
|
if ($passent->{password}) { $secret = $passent->{password}; }
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$callback->(
|
|
|
|
{
|
|
|
|
data =>
|
|
|
|
["The dhcp server must be restarted for OMAPI function to work"]
|
|
|
|
}
|
|
|
|
);
|
2008-07-18 18:40:45 +00:00
|
|
|
$passtab->setAttribs({key => 'omapi'},
|
2008-05-06 18:49:22 +00:00
|
|
|
{username => 'xcat_key', password => $secret});
|
|
|
|
}
|
2008-01-26 17:55:34 +00:00
|
|
|
|
2008-05-06 18:49:22 +00:00
|
|
|
push @dhcpconf, " secret \"" . $secret . "\";\n";
|
|
|
|
push @dhcpconf, "};\n";
|
|
|
|
push @dhcpconf, "omapi-key xcat_key;\n";
|
2010-06-08 19:14:48 +00:00
|
|
|
push @dhcpconf, ('class "pxe" {'."\n"," match if substring (option vendor-class-identifier, 0, 9) = \"PXEClient\";\n"," ddns-updates off;\n"," max-lease-time 600;\n","}\n");
|
2007-10-26 22:44:33 +00:00
|
|
|
}
|
|
|
|
|
2009-07-07 02:07:30 +00:00
|
|
|
sub newconfig_aix
|
|
|
|
{
|
|
|
|
push @dhcpconf, "#xCAT generated dhcp configuration\n";
|
|
|
|
push @dhcpconf, "\n";
|
|
|
|
#push @dhcpconf, "numLogFiles 4\n";
|
|
|
|
#push @dhcpconf, "logFileSize 100\n";
|
|
|
|
#push @dhcpconf, "logFileName /var/log/dhcpsd.log\n";
|
|
|
|
#push @dhcpconf, "logItem SYSERR\n";
|
|
|
|
#push @dhcpconf, "logItem OBJERR\n";
|
|
|
|
#push @dhcpconf, "logItem PROTERR\n";
|
|
|
|
#push @dhcpconf, "logItem WARNING\n";
|
|
|
|
#push @dhcpconf, "logItem EVENT\n";
|
|
|
|
#push @dhcpconf, "logItem ACTION\n";
|
|
|
|
#push @dhcpconf, "logItem INFO\n";
|
|
|
|
#push @dhcpconf, "logItem ACNTING\n";
|
|
|
|
#push @dhcpconf, "logItem TRACE\n";
|
|
|
|
|
|
|
|
push @dhcpconf, "leaseTimeDefault 43200 seconds\n";
|
|
|
|
push @dhcpconf, "#Network configuration begin\n";
|
|
|
|
push @dhcpconf, "#Network configuration end\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-06 18:49:22 +00:00
|
|
|
sub genpassword
|
|
|
|
{
|
2007-10-26 22:44:33 +00:00
|
|
|
|
2008-05-06 18:49:22 +00:00
|
|
|
#Generate a pseudo-random password of specified length
|
|
|
|
my $length = shift;
|
|
|
|
my $password = '';
|
|
|
|
my $characters =
|
|
|
|
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890';
|
|
|
|
srand; #have to reseed, rand is not rand otherwise
|
|
|
|
while (length($password) < $length)
|
|
|
|
{
|
|
|
|
$password .= substr($characters, int(rand 63), 1);
|
|
|
|
}
|
|
|
|
return $password;
|
|
|
|
}
|
2007-10-26 22:44:33 +00:00
|
|
|
|
|
|
|
1;
|