2007-10-26 22:44:33 +00:00
|
|
|
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
package xCAT_plugin::dhcp;
|
2008-07-18 18:40:45 +00:00
|
|
|
use strict;
|
2007-10-26 22:44:33 +00:00
|
|
|
use xCAT::Table;
|
|
|
|
use Data::Dumper;
|
|
|
|
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;
|
|
|
|
use Sys::Syslog;
|
|
|
|
use IPC::Open2;
|
2008-02-07 20:11:52 +00:00
|
|
|
use xCAT::Utils;
|
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
|
|
|
|
|
|
|
my @dhcpconf; #Hold DHCP config file contents to be written back.
|
2008-11-26 00:00:54 +00:00
|
|
|
my @nrn; # To hold output of networks table to be consulted throughout process
|
2007-10-26 22:44:33 +00:00
|
|
|
my $domain;
|
|
|
|
my $omshell;
|
2008-05-06 18:49:22 +00:00
|
|
|
my $statements; #Hold custom statements to be slipped into host declarations
|
2007-11-28 14:57:57 +00:00
|
|
|
my $callback;
|
2008-05-15 17:45:47 +00:00
|
|
|
my $restartdhcp;
|
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;
|
2008-10-30 14:37:56 +00:00
|
|
|
my $iscsients;
|
|
|
|
my $chainents;
|
|
|
|
my $tftpdir='/tftpboot';
|
2009-07-07 02:07:30 +00:00
|
|
|
my $dhcpconffile = $^O eq 'aix' ? '/etc/dhcpsd.cnf' : '/etc/dhcpd.conf';
|
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
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
foreach $mace (@macs)
|
|
|
|
{
|
|
|
|
my $mac;
|
|
|
|
my $hname;
|
|
|
|
($mac, $hname) = split(/!/, $mace);
|
|
|
|
unless ($hname) { $hname = $node; }
|
|
|
|
print $omshell "new host\n";
|
|
|
|
print $omshell
|
|
|
|
"set name = \"$hname\"\n"; #Find and destroy conflict name
|
|
|
|
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;
|
|
|
|
if (inet_aton($hname))
|
|
|
|
{
|
|
|
|
$ip = inet_ntoa(inet_aton($hname));
|
|
|
|
}
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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;
|
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];
|
|
|
|
}
|
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->(
|
|
|
|
{
|
|
|
|
error => ["Unable to open mac table, it may not exist yet"],
|
|
|
|
errorcode => [1]
|
|
|
|
}
|
|
|
|
);
|
|
|
|
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->(
|
|
|
|
{
|
|
|
|
error => ["Unable to find mac address for $node"],
|
|
|
|
errorcode => [1]
|
|
|
|
}
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
my @macs = split(/\|/, $ent->{mac});
|
|
|
|
my $mace;
|
|
|
|
foreach $mace (@macs)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
my $inetn;
|
|
|
|
$inetn = "";
|
|
|
|
if ($hname eq '*NOIP*')
|
|
|
|
{
|
|
|
|
$inetn = "DENIED";
|
|
|
|
$hname = $node . "-noip" . $mac;
|
|
|
|
$hname =~ s/://g;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$inetn = inet_aton($hname);
|
|
|
|
}
|
|
|
|
unless ($inetn)
|
|
|
|
{
|
|
|
|
syslog(
|
|
|
|
"local1|err",
|
|
|
|
"xCAT DHCP plugin unable to resolve IP for $hname (for $node)"
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
2008-03-21 20:00:07 +00:00
|
|
|
my $ip;
|
2008-05-06 18:49:22 +00:00
|
|
|
$ip = "";
|
|
|
|
if ($inetn eq "DENIED")
|
|
|
|
{
|
|
|
|
$ip = "DENIED";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$ip = inet_ntoa(inet_aton($hname));
|
|
|
|
}
|
|
|
|
if ($guess_next_server and $ip ne "DENIED")
|
|
|
|
{
|
2009-08-21 23:58:12 +00:00
|
|
|
$nxtsrv = xCAT::Utils->my_ip_facing($hname);
|
2008-05-06 18:49:22 +00:00
|
|
|
if ($nxtsrv)
|
|
|
|
{
|
2009-07-07 02:07:30 +00:00
|
|
|
$tftpserver = $nxtsrv;
|
2008-05-06 18:49:22 +00:00
|
|
|
$lstatements = "next-server $nxtsrv;$statements";
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
if ($nrent and $nrent->{netboot} and $nrent->{netboot} eq 'pxe') {
|
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')) {
|
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;
|
2009-06-29 18:37:45 +00:00
|
|
|
} else {
|
2009-08-21 23:58:12 +00:00
|
|
|
$lstatements = 'if option user-class-identifier = \"xNBA\" { filename = \"http://'.$nxtsrv.'/tftpboot/xcat/xnba/nodes/'.$node.'\"; } else if exists client-architecture { filename = \"xcat/xnba.kpxe\"; } '.$lstatements; #Only PXE compliant clients should ever receive xNBA
|
2009-06-29 18:37:45 +00:00
|
|
|
}
|
|
|
|
} #TODO: warn when windows
|
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
|
|
|
|
{
|
2009-07-07 02:07:30 +00:00
|
|
|
#syslog("local4|err", "Setting $node ($hname|$ip) to " . $mac);
|
|
|
|
print $omshell "new host\n";
|
|
|
|
print $omshell
|
|
|
|
"set name = \"$hname\"\n"; #Find and destroy conflict name
|
|
|
|
print $omshell "open\n";
|
|
|
|
print $omshell "remove\n";
|
|
|
|
print $omshell "close\n";
|
|
|
|
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";
|
|
|
|
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";
|
|
|
|
print $omshell "set name = \"$hname\"\n";
|
|
|
|
print $omshell "set hardware-address = " . $mac . "\n";
|
|
|
|
print $omshell "set hardware-type = 1\n";
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2009-07-07 02:07:30 +00:00
|
|
|
print $omshell "set ip-address = $ip\n";
|
|
|
|
if ($lstatements)
|
|
|
|
{
|
|
|
|
$lstatements = 'send host-name \"'.$node.'\";'.$lstatements;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
$lstatements = 'send host-name \"'.$node.'\";';
|
|
|
|
}
|
|
|
|
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";
|
|
|
|
unless (grep /#definition for host $node aka host $hname/, @dhcpconf)
|
|
|
|
{
|
|
|
|
push @dhcpconf,
|
|
|
|
"#definition for host $node aka host $hname can be found in the dhcpd.leases file\n";
|
2008-01-26 17:55:34 +00:00
|
|
|
}
|
2008-05-06 18:49:22 +00:00
|
|
|
}
|
2009-07-07 02:07:30 +00:00
|
|
|
}
|
|
|
|
}
|
2008-01-26 17:55:34 +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++)
|
|
|
|
{
|
|
|
|
if ( $dhcpconf[$i] =~ / ([\d\.]+)\/(\d+) ip configuration end/)
|
|
|
|
{
|
|
|
|
if (xCAT::Utils::isInSameSubnet( $ip, $1, $2, 1))
|
|
|
|
{
|
|
|
|
$isSubnetFound = 1;
|
|
|
|
$netmask = $2;
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Format the netmask from AIX format (24) to Linux format (255.255.255.0)
|
|
|
|
my $netmask_linux = xCAT::Utils::formatNetmask( $netmask,1,0);
|
|
|
|
|
|
|
|
# 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";
|
|
|
|
push @node_section, " option sa $tftpserver\n";
|
|
|
|
push @node_section, " option bf \"/tftpboot/$hname\"\n";
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2008-05-06 18:49:22 +00:00
|
|
|
sub preprocess_request
|
|
|
|
{
|
|
|
|
my $req = shift;
|
|
|
|
$callback = shift;
|
2009-03-27 21:08:42 +00:00
|
|
|
my $localonly;
|
2009-03-28 07:03:25 +00:00
|
|
|
if (ref $req->{arg}) {
|
|
|
|
@ARGV = @{$req->{arg}};
|
|
|
|
GetOptions('l' => \$localonly);
|
|
|
|
}
|
2009-07-15 14:36:56 +00:00
|
|
|
#Exit if the packet has been preprocessed
|
|
|
|
if ($req->{_xcatpreprocessed}->[0] == 1) { return [$req]; }
|
|
|
|
|
2008-05-06 18:49:22 +00:00
|
|
|
my @requests =
|
|
|
|
({%$req}); #Start with a straight copy to reflect local instance
|
2009-03-27 21:00:36 +00:00
|
|
|
unless ($localonly) {
|
|
|
|
my @sn = xCAT::Utils->getSNList('dhcpserver');
|
|
|
|
foreach my $s (@sn)
|
|
|
|
{
|
|
|
|
my $reqcopy = {%$req};
|
|
|
|
$reqcopy->{'_xcatdest'} = $s;
|
2009-07-15 14:36:56 +00:00
|
|
|
$reqcopy->{_xcatpreprocessed}->[0] = 1;
|
2009-03-27 21:00:36 +00:00
|
|
|
push @requests, $reqcopy;
|
|
|
|
}
|
2007-10-26 22:44:33 +00:00
|
|
|
}
|
2008-05-06 18:49:22 +00:00
|
|
|
if (scalar(@requests) > 1)
|
|
|
|
{ #hierarchy detected, enforce more rigorous sanity
|
|
|
|
my $ntab = xCAT::Table->new('networks');
|
|
|
|
if ($ntab)
|
|
|
|
{
|
|
|
|
foreach (@{$ntab->getAllEntries()})
|
|
|
|
{
|
|
|
|
if ($_->{dynamicrange} and not $_->{dhcpserver})
|
|
|
|
{
|
|
|
|
$callback->({error=>["Hierarchy requested, therefore networks.dhcpserver must be set for net=".$_->{net}.""],errorcode=>[1]});
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-10-26 22:44:33 +00:00
|
|
|
}
|
|
|
|
|
2008-05-06 18:49:22 +00:00
|
|
|
return \@requests;
|
|
|
|
}
|
2008-03-20 21:15:34 +00:00
|
|
|
|
2008-05-06 18:49:22 +00:00
|
|
|
sub process_request
|
|
|
|
{
|
2009-03-26 20:33:07 +00:00
|
|
|
my $oldmask = umask 0077;
|
2008-05-15 17:45:47 +00:00
|
|
|
$restartdhcp=0;
|
2008-05-06 18:49:22 +00:00
|
|
|
my $req = shift;
|
|
|
|
$callback = shift;
|
|
|
|
my $sitetab = xCAT::Table->new('site');
|
|
|
|
my %activenics;
|
|
|
|
my $querynics = 1;
|
|
|
|
if ($sitetab)
|
|
|
|
{
|
|
|
|
my $href;
|
|
|
|
($href) = $sitetab->getAttribs({key => 'dhcpinterfaces'}, 'value');
|
|
|
|
unless ($href and $href->{value})
|
|
|
|
{ #LEGACY: singular keyname for old style site value
|
|
|
|
($href) = $sitetab->getAttribs({key => 'dhcpinterface'}, 'value');
|
|
|
|
}
|
|
|
|
if ($href and $href->{value})
|
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
|
|
|
{
|
2008-05-07 13:49:33 +00:00
|
|
|
my $dhcpinterfaces = $href->{value};
|
|
|
|
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;
|
2009-03-27 15:13:25 +00:00
|
|
|
unless (xCAT::Utils->thishostisnot($host)) {
|
|
|
|
$foundself=1;
|
|
|
|
last;
|
2008-10-07 16:40:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!defined($savehost)) { # host not defined in db,
|
|
|
|
# probably management node
|
2009-03-27 15:13:25 +00:00
|
|
|
unless (xCAT::Utils->thishostisnot($ngroup)) {
|
|
|
|
$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
|
|
|
}
|
2009-03-26 20:08:18 +00:00
|
|
|
($href) = $sitetab->getAttribs({key => 'nameservers'}, 'value');
|
|
|
|
if ($href and $href->{value}) {
|
|
|
|
$sitenameservers = $href->{value};
|
|
|
|
}
|
|
|
|
($href) = $sitetab->getAttribs({key => 'ntpservers'}, 'value');
|
|
|
|
if ($href and $href->{value}) {
|
|
|
|
$sitentpservers = $href->{value};
|
|
|
|
}
|
|
|
|
($href) = $sitetab->getAttribs({key => 'logservers'}, 'value');
|
|
|
|
if ($href and $href->{value}) {
|
|
|
|
$sitelogservers = $href->{value};
|
|
|
|
}
|
|
|
|
($href) = $sitetab->getAttribs({key => 'domain'}, 'value');
|
2008-05-06 18:49:22 +00:00
|
|
|
($href) = $sitetab->getAttribs({key => 'domain'}, 'value');
|
|
|
|
unless ($href and $href->{value})
|
|
|
|
{
|
|
|
|
$callback->(
|
|
|
|
{error => ["No domain defined in site tabe"], errorcode => [1]}
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$domain = $href->{value};
|
|
|
|
}
|
2007-11-28 14:57:57 +00:00
|
|
|
|
2008-05-06 18:49:22 +00:00
|
|
|
@dhcpconf = ();
|
|
|
|
unless ($req->{arg} or $req->{node})
|
|
|
|
{
|
|
|
|
$callback->({data => ["Usage: makedhcp <-n> <noderange>"]});
|
|
|
|
return;
|
2007-10-26 22:44:33 +00:00
|
|
|
}
|
2009-02-19 10:00:28 +00:00
|
|
|
|
|
|
|
if(grep /-h/,@{$req->{arg}}) {
|
|
|
|
my $usage="Usage: makedhcp -n\n\tmakedhcp -a\n\tmakedhcp -a -d\n\tmakedhcp -d noderange\n\tmakedhcp <noderange> [-s statements]\n\tmakedhcp [-h|--help]";
|
|
|
|
$callback->({data => [$usage]});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-03-28 15:03:36 +00:00
|
|
|
my $dhcplockfd;
|
|
|
|
open($dhcplockfd,"/tmp/xcat/dhcplock");
|
|
|
|
flock($dhcplockfd,LOCK_EX);
|
2009-02-19 10:00:28 +00:00
|
|
|
if (grep /^-n$/, @{$req->{arg}})
|
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
|
|
|
{
|
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 = ();
|
|
|
|
}
|
2007-10-26 22:44:33 +00:00
|
|
|
}
|
2008-11-26 00:00:54 +00:00
|
|
|
my $nettab = xCAT::Table->new("networks");
|
|
|
|
my @vnets = $nettab->getAllAttribs('net','mgtifname','mask');
|
2009-07-07 02:07:30 +00:00
|
|
|
if ($^O eq 'aix')
|
|
|
|
{
|
|
|
|
@nrn = xCAT::Utils::get_subnet_aix();
|
|
|
|
}
|
|
|
|
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];
|
|
|
|
}
|
2009-03-26 18:13:25 +00:00
|
|
|
}
|
|
|
|
|
2008-11-26 00:00:54 +00:00
|
|
|
foreach(@vnets){
|
|
|
|
my $n = $_->{net};
|
|
|
|
my $if = $_->{mgtifname};
|
|
|
|
my $nm = $_->{mask};
|
|
|
|
#$callback->({data => ["array of nets $n : $if : $nm"]});
|
2009-03-26 18:13:25 +00:00
|
|
|
if ($if =~ /!remote!/) { #only take in networks with special interface
|
|
|
|
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.
|
|
|
|
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;
|
|
|
|
}
|
2009-07-07 02:07:30 +00:00
|
|
|
if ($ent[1] =~ m/(remote|ipoib|ib|vlan|bond|eth|myri|man|wlan|en\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')
|
|
|
|
{
|
|
|
|
#add the active nics to /etc/sysconfig/dhcpd
|
|
|
|
if (-e "/etc/sysconfig/dhcpd") {
|
|
|
|
open DHCPD_FD, "/etc/sysconfig/dhcpd";
|
|
|
|
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
|
|
|
|
2009-07-07 02:07:30 +00:00
|
|
|
open DBG_FD, '>', "/etc/sysconfig/dhcpd";
|
|
|
|
print DBG_FD $syscfg_dhcpd;
|
|
|
|
close DBG_FD;
|
|
|
|
} else {
|
|
|
|
$callback->({error=>"The file /etc/sysconfig/dhcpd doesn't exist, check the dhcp server"});
|
|
|
|
# return;
|
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
|
|
|
}
|
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)
|
|
|
|
{
|
|
|
|
addnic($_);
|
|
|
|
}
|
2007-10-26 22:44:33 +00:00
|
|
|
}
|
2008-05-06 18:49:22 +00:00
|
|
|
if (grep /^-a$/, @{$req->{arg}})
|
|
|
|
{
|
|
|
|
if (grep /-d$/, @{$req->{arg}})
|
|
|
|
{
|
|
|
|
$req->{node} = [];
|
|
|
|
my $nodelist = xCAT::Table->new('nodelist');
|
|
|
|
my @entries = ($nodelist->getAllNodeAttribs([qw(node)]));
|
|
|
|
foreach (@entries)
|
|
|
|
{
|
|
|
|
push @{$req->{node}}, $_->{node};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$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)]));
|
|
|
|
}
|
2008-05-06 18:49:22 +00:00
|
|
|
foreach (@entries)
|
|
|
|
{
|
|
|
|
push @{$req->{node}}, $_->{node};
|
|
|
|
}
|
|
|
|
}
|
2007-10-26 22:44:33 +00:00
|
|
|
}
|
2008-01-26 17:55:34 +00:00
|
|
|
|
2008-05-06 18:49:22 +00:00
|
|
|
if ($req->{node})
|
|
|
|
{
|
|
|
|
@ARGV = @{$req->{arg}};
|
|
|
|
$statements = "";
|
|
|
|
GetOptions('s|statements=s' => \$statements);
|
|
|
|
|
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";
|
|
|
|
print $omshell "connect\n";
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
$nrhash = $nrtab->getNodesAttribs($req->{node}, ['tftpserver','netboot']);
|
|
|
|
my $iscsitab = xCAT::Table->new('iscsi');
|
|
|
|
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']);
|
2008-05-06 18:49:22 +00:00
|
|
|
foreach (@{$req->{node}})
|
|
|
|
{
|
|
|
|
if (grep /^-d$/, @{$req->{arg}})
|
|
|
|
{
|
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
|
|
|
|
{
|
2009-04-17 20:29:52 +00:00
|
|
|
unless (xCAT::Utils->nodeonmynet($_))
|
2008-05-06 18:49:22 +00:00
|
|
|
{
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
addnode $_;
|
|
|
|
}
|
|
|
|
}
|
2009-07-07 02:07:30 +00:00
|
|
|
close($omshell) if ($^O ne 'aix');
|
2007-10-26 22:44:33 +00:00
|
|
|
}
|
2008-05-06 18:49:22 +00:00
|
|
|
foreach (@nrn)
|
|
|
|
{
|
2008-11-26 00:00:54 +00:00
|
|
|
my @line = split /:/;
|
2008-06-02 12:00:46 +00:00
|
|
|
my $firstoctet = $line[0];
|
|
|
|
$firstoctet =~ s/^(\d+)\..*/$1/;
|
|
|
|
if ($line[0] eq "169.254.0.0" or ($firstoctet >= 224 and $firstoctet <= 239))
|
2008-05-06 18:49:22 +00:00
|
|
|
{
|
|
|
|
next;
|
|
|
|
}
|
2009-03-26 18:21:36 +00:00
|
|
|
if ($activenics{$line[1]} and $line[3] !~ /G/)
|
2008-05-06 18:49:22 +00:00
|
|
|
{
|
|
|
|
addnet($line[0], $line[2]);
|
|
|
|
}
|
2007-10-26 22:44:33 +00:00
|
|
|
}
|
2008-05-06 18:49:22 +00:00
|
|
|
writeout();
|
2008-05-15 17:45:47 +00:00
|
|
|
if ($restartdhcp) {
|
2009-07-07 02:07:30 +00:00
|
|
|
if ( $^O eq 'aix')
|
|
|
|
{
|
|
|
|
restart_dhcpd_aix();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
system("/etc/init.d/dhcpd restart");
|
|
|
|
system("chkconfig dhcpd on");
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
if (xCAT::Utils->thishostisnot($_)) {
|
|
|
|
push @reordered,$_;
|
|
|
|
} else {
|
|
|
|
unshift @reordered,$_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$srvlist = join(', ',@reordered);
|
|
|
|
}
|
|
|
|
return $srvlist;
|
|
|
|
}
|
2008-05-06 18:49:22 +00:00
|
|
|
sub addnet
|
|
|
|
{
|
|
|
|
my $net = shift;
|
|
|
|
my $mask = shift;
|
|
|
|
my $nic;
|
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];
|
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/)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
$myip = xCAT::Utils->my_ip_facing($net);
|
|
|
|
if ($nettab)
|
|
|
|
{
|
2009-07-07 02:07:30 +00:00
|
|
|
my $mask_formated = $mask;
|
|
|
|
if ( $^O eq 'aix')
|
|
|
|
{
|
|
|
|
$mask_formated = inet_ntoa(pack("N", 2**$mask - 1 << (32 - $mask)));
|
|
|
|
}
|
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},
|
2009-03-26 20:08:18 +00:00
|
|
|
qw(tftpserver nameservers ntpservers logservers gateway dynamicrange dhcpserver));
|
|
|
|
if ($ent and $ent->{ntpservers}) {
|
|
|
|
$ntpservers = $ent->{ntpservers};
|
|
|
|
} elsif ($sitentpservers) {
|
|
|
|
$ntpservers = $sitentpservers;
|
|
|
|
}
|
|
|
|
if ($ent and $ent->{logservers}) {
|
|
|
|
$logservers = $ent->{logservers};
|
|
|
|
} elsif ($sitelogservers) {
|
|
|
|
$logservers = $sitelogservers;
|
|
|
|
}
|
2008-05-06 18:49:22 +00:00
|
|
|
if ($ent and $ent->{nameservers})
|
|
|
|
{
|
|
|
|
$nameservers = $ent->{nameservers};
|
|
|
|
}
|
|
|
|
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
|
|
|
}
|
2009-03-26 20:08:18 +00:00
|
|
|
$nameservers=putmyselffirst($nameservers);
|
|
|
|
$ntpservers=putmyselffirst($nameservers);
|
|
|
|
$logservers=putmyselffirst($nameservers);
|
|
|
|
|
|
|
|
|
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};
|
|
|
|
}
|
|
|
|
if ($ent and $ent->{dynamicrange})
|
|
|
|
{
|
|
|
|
unless ($ent->{dhcpserver}
|
|
|
|
and xCAT::Utils->thishostisnot($ent->{dhcpserver}))
|
|
|
|
{ #If specific, only one dhcp server gets a dynamic range
|
|
|
|
$range = $ent->{dynamicrange};
|
|
|
|
$range =~ s/[,-]/ /g;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$callback->(
|
|
|
|
{
|
|
|
|
warning => [
|
|
|
|
"No dynamic range specified for $net, unknown systems on this network will not receive an address"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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));
|
|
|
|
@netent = (
|
|
|
|
" subnet $net netmask $mask {\n",
|
|
|
|
" max-lease-time 43200;\n",
|
|
|
|
" min-lease-time 43200;\n",
|
|
|
|
" default-lease-time 43200;\n"
|
|
|
|
);
|
|
|
|
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";
|
|
|
|
} elsif ($myip){
|
2008-11-26 00:00:54 +00:00
|
|
|
push @netent, " option ntp-servers $myip;\n";
|
2009-03-26 20:08:18 +00:00
|
|
|
}
|
2008-05-06 18:49:22 +00:00
|
|
|
push @netent, " option domain-name \"$domain\";\n";
|
|
|
|
if ($nameservers)
|
|
|
|
{
|
|
|
|
push @netent, " option domain-name-servers $nameservers;\n";
|
|
|
|
}
|
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;
|
2009-08-21 23:58:12 +00:00
|
|
|
push @netent, " if option user-class-identifier = \"xNBA\" { #x86, xCAT Network Boot Agent\n";
|
|
|
|
push @netent, " filename = \"http://$tftp/tftpboot/xcat/xnba/nets/".$net."_".$maskbits."\";\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";
|
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";
|
|
|
|
if ($range) { push @netent, " range dynamic-bootp $range;\n" }
|
|
|
|
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/ /-/;
|
|
|
|
my @netent = ( "network $net $mask $range\n{\n");
|
|
|
|
if ( $gateway)
|
|
|
|
{
|
|
|
|
if (xCAT::Utils::isInSameSubnet($gateway,$net,$mask,1))
|
|
|
|
{
|
|
|
|
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) {
|
|
|
|
push @netent, " option 7 $logservers\n";
|
|
|
|
} elsif ($myip){
|
|
|
|
push @netent, " option 7 $myip\n";
|
|
|
|
}
|
|
|
|
if ($ntpservers) {
|
|
|
|
push @netent, " option 42 $ntpservers\n";
|
|
|
|
} elsif ($myip){
|
|
|
|
push @netent, " option 42 $myip\n";
|
|
|
|
}
|
|
|
|
push @netent, " option 15 \"$domain\"\n";
|
|
|
|
if ($nameservers)
|
|
|
|
{
|
|
|
|
push @netent, " option 6 $nameservers\n";
|
|
|
|
}
|
|
|
|
push @netent, " subnet $net\n {\n";
|
|
|
|
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
|
|
|
|
{
|
|
|
|
my $nic = shift;
|
|
|
|
my $firstindex = 0;
|
|
|
|
my $lastindex = 0;
|
|
|
|
unless (grep /} # $nic nic_end/, @dhcpconf)
|
|
|
|
{ #add a section if not there
|
2008-05-15 17:45:47 +00:00
|
|
|
$restartdhcp=1;
|
2008-05-06 18:49:22 +00:00
|
|
|
print "Adding NIC $nic\n";
|
2009-03-17 20:11:27 +00:00
|
|
|
if ($nic =~ /!remote!/) {
|
|
|
|
push @dhcpconf, "#shared-network $nic {\n";
|
|
|
|
push @dhcpconf, "#\} # $nic nic_end\n";
|
|
|
|
} else {
|
|
|
|
push @dhcpconf, "shared-network $nic {\n";
|
|
|
|
push @dhcpconf, "\} # $nic nic_end\n";
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
my $targ;
|
2009-07-07 02:07:30 +00:00
|
|
|
open($targ, '>', $dhcpconffile);
|
2008-05-06 18:49:22 +00:00
|
|
|
foreach (@dhcpconf)
|
|
|
|
{
|
|
|
|
print $targ $_;
|
|
|
|
}
|
|
|
|
close($targ);
|
2007-10-26 22:44:33 +00:00
|
|
|
}
|
|
|
|
|
2008-05-06 18:49:22 +00:00
|
|
|
sub newconfig
|
|
|
|
{
|
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";
|
|
|
|
push @dhcpconf, "option iscsi-initiator-iqn code 203 = string;\n"; #Only via gPXE, not a standard
|
2008-05-06 18:49:22 +00:00
|
|
|
push @dhcpconf, "ddns-update-style none;\n";
|
|
|
|
push @dhcpconf,
|
|
|
|
"option client-architecture code 93 = unsigned integer 16;\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";
|
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;
|