Commit 320f5788 authored by Leigh Stoller's avatar Leigh Stoller

Add support for DHCP to the NetBed CDROM.

parent 6246ff1f
......@@ -134,7 +134,7 @@ my $rawbootdisk = $ARGV[0];
my $IP = $ARGV[1];
#
# Untaint the arguments.
# Untaint stuff.
#
if ($rawbootdisk =~ /^([\w\/]+)$/) {
$rawbootdisk = $1;
......@@ -142,16 +142,9 @@ if ($rawbootdisk =~ /^([\w\/]+)$/) {
else {
fatal("Tainted argument $rawbootdisk!");
}
if ($IP =~ /^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/) {
$IP = $1;
}
else {
fatal("Tainted argument $IP!");
}
#
# Grab hostname for passing back to website so it can cons up a nickname.
# Strictly optional, but is nice for the web page display.
#
my $hostname = `hostname`;
if ($hostname =~ /^([-\w\.\@]*)$/) {
......@@ -161,6 +154,24 @@ else {
fatal("Tainted hostname $hostname!");
}
#
# If DHCP mode, must get our IP from the hostname first. Perhaps we
# should do that all the time, as a check on the nameserver, which had
# better be correct and working!
#
if ($IP eq "DHCP") {
my (undef,undef,undef,undef,@ipaddrs) = gethostbyname($hostname);
$IP = inet_ntoa($ipaddrs[0]);
}
# Now taint check IP.
if ($IP =~ /^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/) {
$IP = $1;
}
else {
fatal("Tainted value $IP!");
}
#
# Get the plain device names (ad0, rad0).
# Note, there is no difference in block/raw devices anymore.
......
......@@ -98,6 +98,23 @@ if (! -s $cdkeyfile) {
}
$cdkey = `cat $cdkeyfile`;
chomp($cdkey);
#
# If our IP came via DHCP, we need to figure out what it is.
#
if ($IP eq "DHCP") {
my $hostname = `hostname`;
if ($hostname =~ /^([-\w\.]+)$/) {
$hostname = $1;
my (undef,undef,undef,undef,@ipaddrs) = gethostbyname($hostname);
$IP = inet_ntoa($ipaddrs[0]);
}
else {
}
}
#
# Get the script from netbed central. We have to be able to get it,
......
#!/usr/bin/perl -w
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2002 University of Utah and the Flux Group.
# Copyright (c) 2000-2003 University of Utah and the Flux Group.
# All rights reserved.
#
......@@ -72,6 +72,9 @@ my $localhostrev= "$etcdir/namedb/localhost.rev";
my $hardconfig = "$etcdir/emulab-hard.txt";
my $softconfig = "$etcdir/emulab-soft.txt";
my $tbboot = "tbbootconfig";
my $dodhcp = 0;
my $DHCPTAG = "DHCP";
my $INADDR_ANY = "0.0.0.0";
#
# This is our configuration.
......@@ -164,6 +167,14 @@ sub BootFromCD()
CheckConfigBlock();
}
#
# See if a config block/file specifed DHCP. Will already be set if
# we got the config from the user, but the duplicate check is fine.
#
if (defined($config{'hostname'}) && $config{'hostname'} eq $DHCPTAG) {
$dodhcp = 1;
}
#
# Give the user a chance to override the normal operation, and specify
# alternate parameters.
......@@ -271,6 +282,46 @@ sub GetUserConfig()
$config{'bootdisk'} = Prompt("System boot disk", $rawbootdisk);
$config{'interface'} = Prompt("Network Interface", WhichInterface());
#
# Ask if they want to use DHCP. If so, we skip all the other stuff.
# If not, must prompt for the goo.
#
if (Prompt("Use DHCP?", ($dodhcp ? "Yes" : "No")) =~ /yes/i) {
$dodhcp = 1;
#
# Give the rest of the config strings a phony tag (DHCP) so they
# are not undefined, and values are written to the config file
# and to the boot block. We look for the tags when the config block
# or file is read back in.
#
# I am considering changing the bootblock to just use a boolean
# value, which would be fine since we use an entire sector, so
# backwards compatability with existing records is not an issue.
#
$config{'domain'} = $DHCPTAG;
$config{'hostname'} = $DHCPTAG;
$config{'IP'} = $INADDR_ANY;
$config{'netmask'} = $INADDR_ANY;
$config{'gateway'} = $INADDR_ANY;
$config{'nameserver'}= $INADDR_ANY;
return 0;
}
$dodhcp = 0;
#
# In case the user changed his mind, we do not want to prompt with
# the silly DHCP/INADDR_ANY strings as the default!
#
foreach my $key (keys(%config)) {
my $val = $config{$key};
if (defined($val) &&
($val eq $DHCPTAG || $val eq $INADDR_ANY)) {
$config{$key} = undef;
}
}
$config{'domain'} = Prompt("Domain", $config{'domain'});
$config{'hostname'} = Prompt("Hostname (without the domain!)",
$config{'hostname'});
......@@ -571,6 +622,14 @@ sub WriteConfigFile($)
sub PrintConfig()
{
print "\nCurrent Configuration:\n";
if ($dodhcp) {
print " bootdisk=" . $config{'bootdisk'} . "\n";
print " interface=" . $config{'interface'} . "\n";
print " DHCP=Yes\n";
return;
}
foreach my $key (keys(%config)) {
my $val = $config{$key};
......@@ -601,13 +660,27 @@ sub WriteRCFiles()
print CONFIG "#\n";
print CONFIG "# DO NOT EDIT! This file is autogenerated at reboot.\n";
print CONFIG "#\n";
print CONFIG "network_interfaces=\"".
"\$network_interfaces $config{'interface'}\"\n";
print CONFIG "# Netbed info\n";
print CONFIG "netbed_disk=\"$rawbootdisk\"\n";
#
# Its very simple if using DHCP!
#
if ($dodhcp) {
print CONFIG "netbed_IP=$DHCPTAG\"\n";
print CONFIG "ifconfig_$config{interface}=\"DHCP\"\n";
close(CONFIG);
return 0;
}
print CONFIG "netbed_IP=\"$config{IP}\"\n";
print CONFIG "#\n";
print CONFIG "hostname=\"$config{hostname}.$config{domain}\"\n";
print CONFIG "ifconfig_$config{interface}=\"".
"inet $config{IP} netmask $config{netmask}\"\n";
print CONFIG "defaultrouter=\"$config{gateway}\"\n";
print CONFIG "# Netbed info\n";
print CONFIG "netbed_disk=\"$rawbootdisk\"\n";
print CONFIG "netbed_IP=\"$config{IP}\"\n";
print CONFIG "named_enable=\"YES\"\n";
print CONFIG "# EOF\n";
close(CONFIG);
......
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