Commit c4c14e35 authored by David G Andersen's avatar David G Andersen

And another one - DHCP support now works for the initial boot in

the case that they didn't give us a hostname.  It just mocks up a
bogus hostname of dhcp-ip.wa.emulab.net and sends that along.
The substantive change is that it now prefers extracting the IP
address from the ifconfig for the interface instead of via hostname,
which is pretty unreliable.  But it'll try both.
parent 2dbc0cac
......@@ -56,6 +56,7 @@ my $slicetag = "slicetag";
my $softconfig = "$etcdir/emulab-soft.txt";
my $tbboot = "tbbootconfig";
my $wget = "wget";
my $ifconfig = "ifconfig";
my $logfile = "/tmp/netbed-setup.log";
#
......@@ -72,6 +73,7 @@ my $showprogress= 1;
my $cdkey;
my $privkey;
my %slicesizes;
my $uses_dhcp = 0;
my $PATIENCEMSG = "This could take several minutes, please be patient!\n";
......@@ -161,15 +163,39 @@ else {
# If our IP came via DHCP, we need to figure out what it is.
#
if ($IP eq "DHCP") {
my @ipaddrs;
if ($hostname) {
(undef, undef, undef, undef, @ipaddrs) = gethostbyname($hostname);
my $ip_found = 0;
my $dhcp_if;
$uses_dhcp = 1;
open(SOFT, $softconfig);
while (<SOFT>) {
if (/^interface=(.*)$/) {
$dhcp_if = $1;
last;
}
}
close(SOFT);
if ($dhcp_if) {
open(IFCONFIG, "$ifconfig $dhcp_if|");
while (<IFCONFIG>) {
if (/inet (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}) /) {
$ip_found = 1;
$IP = $1;
last;
}
}
}
if (scalar @ipaddrs) {
$IP = inet_ntoa($ipaddrs[0]);
if (!$ip_found && $hostname) {
my @ipaddrs;
(undef, undef, undef, undef, @ipaddrs) = gethostbyname($hostname);
if (scalar @ipaddrs) {
$IP = inet_ntoa($ipaddrs[0]);
}
}
else {
fatal("Invalid hostname: $hostname");
if ($ip_found && !$hostname) {
my $iptrans = $IP;
$iptrans =~ s/\./\-/;
$hostname = "dhcp-$iptrans.wa.emulab.net";
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment