Commit 52607ea8 authored by Robert Ricci's avatar Robert Ricci
Browse files

In forward maps, put in local nodes as well as remote ones. Add MX

entries for both types to $USERSNODE.

Add support for generating reverse maps as well as forward ones.

The result is that you should no longer put the nodes into the main
.head file, and any reverse zones for which there are .head files
will get generated as well.
parent 1b155592
......@@ -28,15 +28,16 @@ my $OURDOMAIN = "@OURDOMAIN@";
my $mapdir = "/etc/namedb";
my $mapfile = "$mapdir/${OURDOMAIN}.db";
my $mapfileback = "$mapfile.backup";
my $mapfilehead = "$mapfile.head";
my $mapfiletail = "$mapfile.tail";
my $vnodesfile = "$mapdir/vnodes.${OURDOMAIN}.db";
my $vnodesback = "$mapdir/vnodes.${OURDOMAIN}.db.backup";
my $reversedir = "$mapdir/reverse";
my $lockfile = "/var/tmp/testbed_named_lockfile";
my $dbg = 0;
my @row;
use strict;
# If we're disabled, just quietly exit
if ($DISABLED) {
exit 0;
......@@ -70,7 +71,7 @@ use libdb;
# a dummy file in /var/tmp, opened for writing and flock'ed.
#
open(LOCK, ">>$lockfile") || fatal("Couldn't open $lockfile\n");
$count = 0;
my $count = 0;
if (flock(LOCK, LOCK_EX|LOCK_NB) == 0) {
#
# If we don't get it the first time, we wait for:
......@@ -87,7 +88,7 @@ if (flock(LOCK, LOCK_EX|LOCK_NB) == 0) {
$gotlock = 1;
last;
}
$locktime = (stat(LOCK))[9];
my $locktime = (stat(LOCK))[9];
if ($locktime != $oldlocktime) {
$oldlocktime = $locktime;
last;
......@@ -136,22 +137,22 @@ print MAP ";\n";
print MAP "; DO NOT EDIT below this point. Auto generated map entries!\n";
print MAP ";\n";
print MAP "\n";
print MAP "\$TTL\t1\n\n";
#
# First create the IA records for those nodes that have a named_root
# defined. We glean the IP for the node from the interfaces table.
#
$db_result =
my $db_result =
DBQueryFatal("select nt.type,nt.isremotenode,n.node_id,i.IP ".
" from nodes as n ".
"left join node_types as nt on n.type=nt.type ".
"left join interfaces as i on n.node_id=i.node_id and ".
" nt.control_net=i.card ".
"where nt.isvirtnode=0 and n.role='testnode' and ".
" nt.isremotenode=1 and i.IP is not null ".
" i.IP is not null ".
"order by nt.type,n.node_id");
my %reverse;
if ($db_result->numrows > 0) {
#
# Create an IN record for each node.
......@@ -172,16 +173,20 @@ if ($db_result->numrows > 0) {
$oldtype = $type;
}
print MAP "$node_id\tIN\tA\t$IP\n";
print MAP "\tIN\tMX 10\t$USERS.\n";
#
# Skip local nodes for now since we also need to add reverse map
# auto generation.
#
if ($isremote) {
print MAP "$node_id\tIN\tA\t$IP\n";
}
# Put it into a map so we can generate the reverse zone file later
#
$IP =~ /(\d+\.\d+\.\d+)\.(\d+)/;
my $subnet = $1;
my $host = $2;
push @{$reverse{$subnet}}, [$host, $node_id];
}
}
print MAP "\n";
print MAP "\$TTL\t1\n\n";
#
# Figure out the set of experiment nodes we are working on. These are the
......@@ -239,50 +244,9 @@ print MAP "\n";
close(MAP);
#
# Concat the head and tail files to create the new map.
#
if (-e $mapfile) {
system("mv -f $mapfile $mapfileback") == 0 or
fatal("Could not back up $mapfile to $mapfileback\n");
}
#
# Generate a warning so that no one tries to edit the file by hand
#
open(MAP, ">$mapfile") || fatal("Couldn't open $mapfile\n");
print MAP
";\n".
"; ******************************************************************\n".
"; DO NOT EDIT THIS FILE. IT IS A CREATION, A FIGMENT, A CONTRIVANCE!\n".
";\n".
"; Edit the \"head\" file, then run ${TB}bin/named_setup.\n".
"; ******************************************************************\n".
";\n";
#
# Now copy in the head part of the map, looking for the serial
# number so it can be bumped up.
#
open(MAPHEAD, "<$mapfilehead") || fatal("Couldn't open $mapfilehead\n");
while (<MAPHEAD>) {
if ( /Serial Number/i ) {
my $serial = `date +%s`;
chop $serial;
print MAP "\t\t\t$serial\t; Serial Number -- DO NOT EDIT\n";
}
else {
print MAP "$_";
}
}
close(MAPHEAD);
close(MAP);
# Make this map!
#
# Now the tail of the map.
#
system("cat $mapfiletail >> $mapfile") == 0 or
fatal("Failed to concat $mapfiletail to $mapfile\n");
make_zonefile($mapfile);
#
# Now we tack on the virtual node, but that has to go onto the end
......@@ -337,6 +301,30 @@ if ($db_result->numrows > 0) {
}
close(MAP);
#
# Look for reverse zone files that we may need to make
#
opendir(DIR,$reversedir) or fatal("Unable to open directory $reversedir\n");
while (my $dirent = readdir(DIR)) {
if ($dirent !~ /((\d+\.\d+\.\d+)\.db)\.head/) {
next;
}
my $subnet = $2;
my $basename = $1;
my $filename = "$reversedir/$basename.tail";
open MAP, ">$filename" || fatal("Couldn't open $filename: $!\n");
foreach my $aref (sort {$$a[0] <=> $$b[0]} @{$reverse{$subnet}}) {
my ($host, $name) = @$aref;
printf MAP "$host\tIN\tPTR\t$name.$OURDOMAIN.\n";
}
close MAP;
make_zonefile("$reversedir/$basename");
}
closedir DIR;
#
# This is better than HUPing the nameserver directly. Notet that we look
# for a local port of named first.
......@@ -353,8 +341,65 @@ else {
exit(0);
sub fatal {
local($msg) = $_[0];
my $msg = $_[0];
SENDMAIL($TBOPS, "Named Setup Failed", $msg);
die($msg);
}
#
# Make a zone file from the
#
sub make_zonefile($) {
my ($mapfile) = @_;
my $mapfileback = "$mapfile.backup";
my $mapfilehead = "$mapfile.head";
my $mapfiletail = "$mapfile.tail";
#
# Concat the head and tail files to create the new map.
#
if (-e $mapfile) {
system("mv -f $mapfile $mapfileback") == 0 or
fatal("Could not back up $mapfile to $mapfileback\n");
}
#
# Generate a warning so that no one tries to edit the file by hand
#
open(MAP, ">$mapfile") || fatal("Couldn't open $mapfile\n");
print MAP
";\n".
"; ******************************************************************\n".
"; DO NOT EDIT THIS FILE. IT IS A CREATION, A FIGMENT, A CONTRIVANCE!\n".
";\n".
"; Edit the \"head\" file, then run ${TB}bin/named_setup.\n".
"; ******************************************************************\n".
";\n";
#
# Now copy in the head part of the map, looking for the serial
# number so it can be bumped up.
#
open(MAPHEAD, "<$mapfilehead") || fatal("Couldn't open $mapfilehead\n");
while (<MAPHEAD>) {
if ( /;\s*Serial\s+/i ) {
my $serial = `date +%s`;
chop $serial;
print MAP "\t\t\t$serial\t; Serial Number -- DO NOT EDIT\n";
}
else {
print MAP "$_";
}
}
close(MAPHEAD);
close(MAP);
#
# Now the tail of the map.
#
system("cat $mapfiletail >> $mapfile") == 0 or
fatal("Failed to concat $mapfiletail to $mapfile\n");
}
Supports Markdown
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