Commit 8905d6be authored by Mike Hibler's avatar Mike Hibler

Beginnings of support for DHCP hook to report node boot state transitions.

parent 88a87b6f
#
# dhcpd.conf.template - From the emulab software distribution
#
# This file is used with dhcpd_makeconf to generate an actual dhpd.conf file
# from the database.
#
# Make sure to change all subnets (don't forget the mask!), the DHCP and DNS
# servers' IP addresses, the router's IP, and see the comment about nodetypes
# below.
#
server-identifier @BOSSNODE_IP@;
server-name "@BOSSNODE_IP@";
# Config these too?
option root-path "/tftpboot";
filename "/tftpboot/pxeboot.emu";
default-lease-time 36000; # 10 hours
max-lease-time 36000; # 10 hours
ddns-update-style none; # req'd vers 3 directive
# Define the PXE option space
# Code 1: Multicast IP address of bootfile
# Code 2: UDP port that client should monitor for MTFTP responses
# Code 3: UDP port that MTFTP servers are using to listen for MTFTP requests
# Code 4: Number of secondes a client must listen for activity before trying
# to start a new MTFTP transfer
# Code 5: Number of secondes a client must listen before trying to restart
# a MTFTP transfer
# Code 128: IP address of Emulab bootinfo server
option space PXE;
option PXE.mtftp-ip code 1 = ip-address;
option PXE.mtftp-cport code 2 = unsigned integer 16;
option PXE.mtftp-sport code 3 = unsigned integer 16;
option PXE.mtftp-tmout code 4 = unsigned integer 8;
option PXE.mtftp-delay code 5 = unsigned integer 8;
option PXE.discovery-control code 6 = unsigned integer 8;
option PXE.discovery-mcast-addr code 7 = ip-address;
option PXE.emulab-bootinfo code 128 = ip-address;
#
# For PXE booting nodes we set the magic bits to tell the client that we are
# PXE-saavy so they don't wait around for 12 seconds or so waiting for a
# better response.
#
# If, for some reason, this doesn't work for you, just comment out the
# entire PXE class block. It will work without it, it will just take longer.
#
class "PXE" {
match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";
option vendor-class-identifier "PXEClient";
vendor-option-space PXE;
# bit 3 = If set, and a boot file name is present in the initial
# DHCP or ProxyDHCP offer packet, download the boot file (do not
# prompt/menu/discover).
option PXE.discovery-control 8;
}
on commit {
set clip = binary-to-ascii(10, 8, ".", leased-address);
set clhw = binary-to-ascii(16, 8, ":", substring(hardware, 1, 6));
if (substring (option vendor-class-identifier, 0, 9) = "PXEClient") {
set boot = "PXE";
} else {
set boot = "OS";
}
set ispxe = option vendor-class-identifier;
execute("@prefix@/sbin/reportboot", clip, clhw, boot);
}
@DHCPD_CONTROLNET_DECL@
shared-network emulab {
subnet @CONTROL_NETWORK@ netmask @CONTROL_NETMASK@ {
option subnet-mask @CONTROL_NETMASK@;
option routers @CONTROL_ROUTER_IP@;
option domain-name-servers @BOSSNODE_IP@;
option domain-name "@OURDOMAIN@";
next-server @BOSSNODE_IP@;
# Example of a dynamic range. If you uncomment the following line
# (after changing the IP addresses to suitable ones, of course)
# unknown nodes will get assigned a random IP in it
#range @DHCPD_DYNRANGE@;
# testbed PCs
group {
#
# For every PC nodetype, include a line like the one below.
# These lines will be replaced with auto-generated entries for
# nodes of that type. You can also use the class field from the
# node_types table
#
%%nodetype=pc
}
}
%%management
#
# Private network; for virtual (jailed) nodes.
#
subnet @VIRTNODE_NETWORK@ netmask @VIRTNODE_NETMASK@ {
}
}
......@@ -64,7 +64,7 @@ SBIN_STUFF = resetvlans console_setup.proxy sched_reload named_setup \
nfstrace plabinelab smbpasswd_setup smbpasswd_setup.proxy \
rmproj snmpit.proxynew snmpit.proxyv2 pool_daemon \
checknodes_daemon snmpit.proxyv3 image_setup tcpp \
arplockdown bscontrol
arplockdown bscontrol reportboot
ifeq ($(ISMAINSITE),1)
SBIN_STUFF += repos_daemon
......
#!/usr/bin/perl -w
#
# Copyright (c) 2014 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
# This file is part of the Emulab network testbed software.
#
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
#
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
# License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this file. If not, see <http://www.gnu.org/licenses/>.
#
# }}}
#
use English;
use Getopt::Std;
use POSIX qw(strftime);
use Sys::Syslog;
#
# This script is invoked on a dhcpd "commit" event.
#
# Intended to trigger Emulab node boot related activities.
#
sub usage()
{
print "Usage: $0 [-bd] IP MAC boot-type\n";
print("Options:\n");
print(" -b - Run in the background\n");
print(" -d - Turn on debugging\n");
exit(1);
}
my $optlist = "bd";
my $background = 0;
my $debug = 0;
#
# Functions
#
sub logit($);
#
# Configure variables
#
my $TB = "@prefix@";
my $TBOPS = "@TBOPSEMAIL@";
# Locals
my $logfile = "$TB/log/reportboot.log";
#
# Turn off line buffering on output
#
$| = 1;
#
# Untaint the path
#
$ENV{'PATH'} = "$TB/bin:$TB/sbin:/bin:/usr/bin:/sbin:/usr/sbin";
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
#
# Testbed Support libraries
#
use lib "@prefix@/lib";
use libtestbed;
use libdb;
use libtblog;
my %options = ();
if (! getopts($optlist, \%options)) {
usage();
}
if (defined($options{"b"})) {
$background = 1;
}
if (defined($options{"d"})) {
$debug = 1;
}
if (@ARGV != 3) {
usage();
}
my ($IP,$MAC,$boottype);
if ($ARGV[0] =~ /^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)$/) {
$IP = $1;
} else {
print STDERR "'$ARGV[0]' is not an IP address\n";
usage();
}
if ($ARGV[1] =~ /^([0-9a-fA-F]+:[0-9a-fA-F]+:[0-9a-fA-F]+:[0-9a-fA-F]+:[0-9a-fA-F]+:[0-9a-fA-F]+)$/) {
$MAC = $1;
} else {
print STDERR "'$ARGV[1]' is not a MAC address\n";
usage();
}
if ($ARGV[2] =~ /^(PXE|OS)$/) {
$boottype = $1;
} else {
print STDERR "'$ARGV[2]' must be one of PXE or OS\n";
usage();
}
if ($background) {
my $cpid = fork();
if (!defined($cpid)) {
die "$0: could not fork!";
}
if ($cpid) {
exit(0);
}
open(STDIN, "< /dev/null") or
die("opening /dev/null for STDIN: $!");
POSIX::setsid() or
die("setsid failed: $!");
}
logit("Invoked by $boottype: IP=$IP MAC=$MAC");
exit(0);
sub logit($)
{
my $message = shift;
# Time stamp log messages like:
# Sep 20 09:36:00 $message
my $tstamp = strftime("%b %e %H:%M:%S", localtime);
if (open(LOG, ">>$logfile")) {
print LOG "$tstamp: $message\n";
close(LOG);
} else {
print STDERR "Could not append to $logfile\n";
}
print STDERR "$message\n" if ($debug);
}
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