aboutsummaryrefslogtreecommitdiffstats
path: root/bootstrap/make-missing-conf.pl
diff options
context:
space:
mode:
Diffstat (limited to 'bootstrap/make-missing-conf.pl')
-rwxr-xr-xbootstrap/make-missing-conf.pl154
1 files changed, 58 insertions, 96 deletions
diff --git a/bootstrap/make-missing-conf.pl b/bootstrap/make-missing-conf.pl
index e45a473..ae28d73 100755
--- a/bootstrap/make-missing-conf.pl
+++ b/bootstrap/make-missing-conf.pl
@@ -1,6 +1,7 @@
#!/usr/bin/perl -I /root/tgmanage
use strict;
use Net::IP;
+use NetAddr::IP;
BEGIN {
require "include/config.pm";
@@ -44,62 +45,42 @@ while ( <STDIN> ){
# <v4 net> <v6 net> <network-name>
# 151.216.129.0/26 2a02:ed02:129a::/64 noc
# we assume not smaller than /64 on v6
- die ("Invalid format on input") if not $line =~ m/^((\d+\.){3}\d+\/\d+)\s+(([a-fA-F0-9]+\:){1,4}\:\/\d+)\s+([\w|-]+).*/;
+ die ("Invalid format on input.\n") if not $line =~ m/^((\d+\.){3}\d+\/\d+)\s+(([a-fA-F0-9]+\:){1,4}\:\/\d+)\s+([\w|-]+).*/;
my ( $v4_net, $v6_net, $name ) = ( $1, $3, $5 );
my $master_config = $bind_conf_master . $name . ".conf";
my $slave_config = $bind_conf_slave . $name . ".conf";
my $zone_file = $bind_base . "dynamic/$name.$nms::config::tgname.gathering.org.zone";
-
- my $v4_range = Net::IP->new( $v4_net ) or die ("v4_net fail");
- my $v6_range = Net::IP->new( $v6_net ) or die ("v6_net fail");
# DHCP4
my $dhcp_dynconf_dir = $dhcpd_base . "conf-v4/";
my $dhconfig = $dhcp_dynconf_dir . $name . ".conf";
- if ( not -f $dhconfig )
- {
+ if ( not -f $dhconfig ){
print STDERR "Creating file " . $dhconfig . "\n";
- my $numhosts = $range->size();
- my $mask = $range->mask();
- my $router = $net_base . "." . ($f_oct+1);
- my $first = $net_base . "." . ( $f_oct + 5 );
-
- my $last = $first;
- if ( $size < 24 )
- {
- # Net::IP iteration is crazyslow. So, we stopped using iterations.
- my $last_ip = $range->last_ip();
- $last_ip =~ m/(\d+)\.(\d+)\.(\d+)\.(\d+)/;
- $last = sprintf("%d.%d.%d.%d", $1, $2, $3, $4-2);
- }
- else { $last = $net_base . "." . ( $f_oct + $numhosts - 2 ); }
-
- #print STDERR "Name : " . $name . "\n";
- #print STDERR "Net : " . $net . "\n";
- #print STDERR "Mask : " . $mask . "\n";
- #print STDERR "Router : " . $router . "\n";
- #print STDERR "Size : " . $size . "\n";
- #print STDERR "Numhosts : " . $numhosts . "\n";
- #print STDERR "First : " . $first . "\n";
- #print STDERR "Last : " . $last . "\n";
+
+ my $network = Net::IP->new($v4_net)->ip();
+ my $netmask = Net::IP->new($v4_net)->mask();
+ (my $first = NetAddr::IP->new($v4_net)->nth(3)) =~ s/\/[0-9]{1,2}//; # we reserve the three first addresses
+ (my $last = NetAddr::IP->new($v4_net)->last()) =~ s/\/[0-9]{1,2}//;
+ (my $gw = NetAddr::IP->new($v4_net)->first()) =~ s/\/[0-9]{1,2}//;
open DFILE, ">" . $dhconfig or die ( $! . " " . $dhconfig);
- print DFILE "zone $name.$nms::config::tgname.gathering.org {\n";
- print DFILE " primary $nms::config::ddns_to;\n";
- print DFILE " key DHCP_UPDATER;\n";
- print DFILE "}\n\n";
+ print DFILE <<"EOF";
+zone $name.$nms::config::tgname.gathering.org {
+ primary $nms::config::ddns_to;
+ key DHCP_UPDATER;
+}
+subnet $network netmask $netmask {
+ option subnet-mask $netmask;
+ option routers $gw;
+ option domain-name "$name.$nms::config::tgname.gathering.org";
+ ddns-domainname "$name.$nms::config::tgname.gathering.org";
+ range $first $last;
+}
- print DFILE "subnet $net netmask $mask {\n";
- print DFILE " authoritative;\n";
- print DFILE " option routers $router;\n";
- print DFILE " option domain-name \"$name.$nms::config::tgname.gathering.org\";\n";
- print DFILE " ddns-domainname \"$name.$nms::config::tgname.gathering.org\";\n";
- print DFILE " range $first $last;\n";
- print DFILE " ignore client-updates;\n";
- print DFILE "}\n\n";
+EOF
close DFILE;
}
@@ -108,48 +89,24 @@ while ( <STDIN> ){
my $dhcp_dynconf_dir = $dhcpd_base . "conf-v6/";
my $dhconfig = $dhcp_dynconf_dir . $name . ".conf";
- if ( not -f $dhconfig )
- {
+ if ( not -f $dhconfig ){
print STDERR "Creating file " . $dhconfig . "\n";
- my $numhosts = $range->size();
- my $mask = $range->mask();
- my $router = $net_base . "." . ($f_oct+1);
- my $first = $net_base . "." . ( $f_oct + 5 );
-
- my $last = $first;
- if ( $size < 24 )
- {
- # Net::IP iteration is crazyslow. So, we stopped using iterations.
- my $last_ip = $range->last_ip();
- $last_ip =~ m/(\d+)\.(\d+)\.(\d+)\.(\d+)/;
- $last = sprintf("%d.%d.%d.%d", $1, $2, $3, $4-2);
- }
- else { $last = $net_base . "." . ( $f_oct + $numhosts - 2 ); }
-
- #print STDERR "Name : " . $name . "\n";
- #print STDERR "Net : " . $net . "\n";
- #print STDERR "Mask : " . $mask . "\n";
- #print STDERR "Router : " . $router . "\n";
- #print STDERR "Size : " . $size . "\n";
- #print STDERR "Numhosts : " . $numhosts . "\n";
- #print STDERR "First : " . $first . "\n";
- #print STDERR "Last : " . $last . "\n";
-
- open DFILE, ">" . $dhconfig or die ( $! . " " . $dhconfig);
+
+ my $network = Net::IP->new($v6_net)->short();
+ my ($first, $last) = ("1000", "9999");
+
+ print DFILE <<"EOF";
+zone $name.$nms::config::tgname.gathering.org {
+ primary $nms::config::ddns_to;
+ key DHCP_UPDATER;
+}
+subnet6 $v6_net {
+ option domain-name "$name.$nms::config::tgname.gathering.org";
- print DFILE "zone $name.$nms::config::tgname.gathering.org {\n";
- print DFILE " primary $nms::config::ddns_to;\n";
- print DFILE " key DHCP_UPDATER;\n";
- print DFILE "}\n\n";
+ range6 ${network}${first} ${network}${last};
+}
- print DFILE "subnet $net netmask $mask {\n";
- print DFILE " authoritative;\n";
- print DFILE " option routers $router;\n";
- print DFILE " option domain-name \"$name.$nms::config::tgname.gathering.org\";\n";
- print DFILE " ddns-domainname \"$name.$nms::config::tgname.gathering.org\";\n";
- print DFILE " range $first $last;\n";
- print DFILE " ignore client-updates;\n";
- print DFILE "}\n\n";
+EOF
close DFILE;
}
@@ -182,27 +139,32 @@ EOF
$bind_file = $slave_config if ( $role eq "slave");
die ("WTF, role does not match 'master' or 'slave'" ) if ( $bind_file eq "");
- if ( not -f $bind_file )
- {
+ if ( not -f $bind_file ){
print STDERR "Creating file " . $bind_file . "\n";
open NFILE, ">" . $bind_file or die ( $! . " " . $bind_file);
- print NFILE "zone \"$name.$nms::config::tgname.gathering.org\" {\n";
+ print NFILE <<"EOF";
+zone "$name.$nms::config::tgname.gathering.org" {
+ allow-transfer { ns-xfr; };
+EOF
+
if ( $role eq "master" ) {
- print NFILE " type master;\n";
- print NFILE " notify yes;\n";
- print NFILE " allow-update { key DHCP_UPDATER; };\n";
- print NFILE " file \"dynamic/$name.$nms::config::tgname.gathering.org.zone\";\n";
- }
- else
- {
- print NFILE " type slave;\n";
- print NFILE " notify no;\n";
- print NFILE " masters { bootstrap; };\n";
- print NFILE " file \"slave/$name.$nms::config::tgname.gathering.org.zone\";\n";
+ print NFILE <<"EOF";
+ type master;
+ notify yes;
+ allow-update { key DHCP_UPDATER; };
+ file "dynamic/$name.$nms::config::tgname.gathering.org.zone";
+};
+EOF
+ } else {
+ print NFILE <<"EOF";
+ type slave;
+ notify no;
+ masters { master_ns; };
+ file "slave/$name.$nms::config::tgname.gathering.org.zone";
+};
+EOF
}
- print NFILE " allow-transfer { ns-xfr; };\n";
- print NFILE "};\n";
close NFILE;
}