named_makerev.in 7.2 KB
Newer Older
1 2 3
#!/usr/bin/perl -w

#
4
# Copyright (c) 2000-2018 University of Utah and the Flux Group.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
# 
# {{{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/>.
# 
# }}}
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
#
use Getopt::Std;
use Socket;

#
# named_makeconf - helper script to create named.conf file. The template
# looks like standard file, only with %token% strings that need to be
# replaced. See below.
#
sub usage {
	print "Usage: $0 <templatefile>\n";
}

#
# Configure variables
#
40
my $ELABINELAB		     = "@ELABINELAB@";
41
my $CONFIG_TARGETSYS         = @CONFIG_TARGETSYS@;
42 43 44 45 46 47 48
my $OURDOMAIN                = "@OURDOMAIN@";
my $TESTBED_NETWORK          = "@TESTBED_NETWORK@";
my $TESTBED_NETMASK          = "@TESTBED_NETMASK@";
my $EXTERNAL_TESTBED_NETWORK = "@EXTERNAL_TESTBED_NETWORK@";
my $EXTERNAL_TESTBED_NETMASK = "@EXTERNAL_TESTBED_NETMASK@";
my $BOSSNODE_IP              = "@BOSSNODE_IP@";
my $USERNODE_IP              = "@USERNODE_IP@";
49
my $FSNODE_IP                = "@FSNODE_IP@";
50 51
my $EXTERNAL_BOSSNODE_IP     = "@EXTERNAL_BOSSNODE_IP@";
my $EXTERNAL_USERNODE_IP     = "@EXTERNAL_USERNODE_IP@";
52
my $EXTERNAL_FSNODE_IP       = "@EXTERNAL_FSNODE_IP@";
53 54 55 56 57 58 59 60 61 62 63

my $CONTROL_ROUTER_IP  = "@CONTROL_ROUTER_IP@";
my $CONTROL_NETWORK    = "@CONTROL_NETWORK@";
my $CONTROL_NETMASK    = "@CONTROL_NETMASK@";
my $PRIVATE_NETWORK    = "@PRIVATE_NETWORK@";
my $PRIVATE_ROUTER     = "@PRIVATE_ROUTER@";
my $PRIVATE_NETMASK    = "@PRIVATE_NETMASK@";
my $PUBLIC_NETWORK     = "@PUBLIC_NETWORK@";
my $PUBLIC_ROUTER      = "@PUBLIC_ROUTER@";
my $PUBLIC_NETMASK     = "@PUBLIC_NETMASK@";
my $NAMED_FORWARDERS   = "@NAMED_FORWARDERS@";
64 65
my $VIRTNODE_NETWORK   = "@VIRTNODE_NETWORK@";
my $VIRTNODE_NETMASK   = "@VIRTNODE_NETMASK@";
66 67
my $IPV6_ENABLED       = @IPV6_ENABLED@;
my $IPV6_SUBNET_PREFIX = "@IPV6_SUBNET_PREFIX@";
68 69 70 71

# Testbed libraries.
use lib "@prefix@/lib";

72
#
73
# This is for the dotted and reverse dotted notation needed for the
74 75 76
# reverse maps. This is probably all wrong ...
#
# XXX I assume that the netmask falls between /16 and /24 ... 
77
#
78 79 80 81
my ($ia, $ib, $ic, $id) =
    ($TESTBED_NETWORK =~ /(\d+)\.(\d+)\.(\d+)\.(\d+)/);
my ($ea, $eb, $ec, $ed) =
    ($EXTERNAL_TESTBED_NETWORK =~ /(\d+)\.(\d+)\.(\d+)\.(\d+)/);
82 83
my ($ja, $jb, $jc, $jd) =
    ($VIRTNODE_NETWORK =~ /(\d+)\.(\d+)\.(\d+)\.(\d+)/);
84

85 86 87 88
my ($ima, $imb, $imc, $imd) =
    ($TESTBED_NETMASK =~ /(\d+)\.(\d+)\.(\d+)\.(\d+)/);
my ($ema, $emb, $emc, $emd) =
    ($EXTERNAL_TESTBED_NETMASK =~ /(\d+)\.(\d+)\.(\d+)\.(\d+)/);
89 90
my ($jma, $jmb, $jmc, $kmd) =
    ($VIRTNODE_NETMASK =~ /(\d+)\.(\d+)\.(\d+)\.(\d+)/);
91

92
$infile = shift @ARGV || exit &usage;
93

94 95 96 97 98 99 100 101 102
#
# Generate maps for the jail network. 
#
for (my $i = $jb; $i <= $jb + (255 - $jmb); $i++) {
    my $internal_revfile = "${ja}.${i}.db.head";

    print "Generating internal reverse lookup file ...\n";
    system("cp -f reverse.head $internal_revfile") == 0 or
	die("Unable to copy $infile to $internal_revfile\n");
103

104
    if ($CONFIG_TARGETSYS) {
105 106 107
	system("echo '	IN	NS	ns.emulab.net.' >> $internal_revfile");
    }

108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
    #
    # This is for the case that boss/ops/fs are actually *in* the jail
    # network space, as would happen in an elabinelab that is using a
    # private IP space for the servers (XEN mode).
    #
    if ($ELABINELAB) {
	open(REV, ">>$internal_revfile")
	    or die("Unable to open $internal_revfile for appending!\n");
	print REV "\n";
	
	if ($BOSSNODE_IP =~ /$ja\.$i\.(\d+)\.(\d+)/) {
	    print REV "\$ORIGIN ${1}.${i}.${ja}.in-addr.arpa.\n";
	    print REV "${2}\tIN\tPTR\tboss.${OURDOMAIN}.\n";
	}
	if ($USERNODE_IP =~ /$ja\.$i\.(\d+)\.(\d+)/) {
	    print REV "\$ORIGIN ${1}.${i}.${ja}.in-addr.arpa.\n";
	    print REV "${2}\tIN\tPTR\tops.${OURDOMAIN}.\n";
	}
	if ($FSNODE_IP ne $USERNODE_IP && $FSNODE_IP ne $BOSSNODE_IP &&
	    $FSNODE_IP =~  /$ja\.$i\.(\d+)\.(\d+)/) {
	    print REV "\$ORIGIN ${1}.${i}.${ja}.in-addr.arpa.\n";
	    print REV "${2}\tIN\tPTR\tops.${OURDOMAIN}.\n";
	}
	close(REV);
    }
133 134
}

135
#
136
# Generate a set of maps for all indicies in the 3rd octet.
137
#
138 139 140 141 142 143 144 145 146 147
for (my $i = $ic; $i <= $ic + (255 - $imc); $i++) {
    my $internal_revfile = "${ia}.${ib}.${i}.db.head";

    #
    # Create internal version.
    #
    print "Generating internal reverse lookup file ...\n";
    system("cp -f reverse.head $internal_revfile") == 0 or
	die("Unable to copy $infile to $internal_revfile\n");

148
    if ($CONFIG_TARGETSYS) {
149 150 151
	system("echo '	IN	NS	ns.emulab.net.' >> $internal_revfile");
    }

152 153 154 155 156 157 158 159 160 161 162
    open(REV, ">>$internal_revfile")
	or die("Unable to open $internal_revfile for appending!\n");
    print REV "\n";

    # Need to put boss/ops into the proper zone file.
    if ($BOSSNODE_IP =~ /\d+\.\d+\.$i\.(\d+)/) {
	print REV "${1}\tIN\tPTR\tboss.${OURDOMAIN}.\n";
    }
    if ($USERNODE_IP =~ /\d+\.\d+\.$i\.(\d+)/) {
	print REV "${1}\tIN\tPTR\tops.${OURDOMAIN}.\n";
    }
163
    if ($FSNODE_IP ne $USERNODE_IP && $FSNODE_IP ne $BOSSNODE_IP &&
164 165 166 167
	$FSNODE_IP =~ /\d+\.\d+\.$i\.(\d+)/) {
	print REV "${1}\tIN\tPTR\tfs.${OURDOMAIN}.\n";
    }
    close(REV);
168
}
169

170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
if ($IPV6_ENABLED) {
    my $revfile = ${IPV6_SUBNET_PREFIX} . ".db.head";
    my @digits = ();

    # Switch : to dot since it messes up gmake.
    $revfile =~ s/\:/./g;

    foreach my $nibblet (split(":", $IPV6_SUBNET_PREFIX)) {
	if ($nibblet =~ /^(\w)(\w)(\w)(\w)$/) {
	    push(@digits, $1, $2, $3, $4);
	}
	else {
	    die("*** $0:\n".
		"    Bad format for ipv6 address: $IPV6_SUBNET_PREFIX!\n");
	}
    }
    my $dotted = join(".", reverse(@digits));

    print "Generating IPV6 reverse lookup file ...\n";
    system("cp -f reverse.head $revfile") == 0 or
	die("Unable to copy $infile to $revfile\n");
}

193 194 195 196 197
# No need is just one big IP space.
exit(0)
    if ($TESTBED_NETWORK eq $EXTERNAL_TESTBED_NETWORK);

#
198
# Generate a set of maps for all indicies in the 3rd octet.
199
#
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
for (my $i = $ec; $i <= $ec + (255 - $emc); $i++) {
    my $external_revfile = "${ea}.${eb}.${i}.db.head";
    
    #
    # Create external version.
    #
    print "Generating external reverse lookup file ...\n";
    system("cp -f reverse.head $external_revfile") == 0 or
	die("Unable to copy $infile to $external_revfile\n");

    open(REV, ">>$external_revfile")
	or die("Unable to open $external_revfile for appending!\n");
    print REV "\n";
    
    # Need to put boss/ops into the proper zone file.
    if ($EXTERNAL_BOSSNODE_IP =~ /\d+\.\d+\.$i\.(\d+)/) {
	print REV "${1}\tIN\tPTR\tboss.${OURDOMAIN}.\n";
    }
    if ($EXTERNAL_USERNODE_IP =~ /\d+\.\d+\.$i\.(\d+)/) {
	print REV "${1}\tIN\tPTR\tops.${OURDOMAIN}.\n";
    }
    if ($EXTERNAL_FSNODE_IP ne $EXTERNAL_USERNODE_IP &&
222
	$EXTERNAL_FSNODE_IP ne $EXTERNAL_BOSSNODE_IP &&
223 224 225 226
	$EXTERNAL_FSNODE_IP =~ /\d+\.\d+\.$i\.(\d+)/) {
	print REV "${1}\tIN\tPTR\tfs.${OURDOMAIN}.\n";
    }
    close(REV);
227
}
228 229
    
exit(0);