Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ipv6 servers to all zones #237

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 57 additions & 58 deletions lib/NP/Model/DnsRoot.pm
Original file line number Diff line number Diff line change
Expand Up @@ -116,77 +116,76 @@ sub populate_country_zones {
$name = '' if $name eq '@';
$name = "$name." if $name;

if (my $entries = $zone->active_servers('v4')) {

my $min_non_duplicate_size = 2;
my $response_records = 3;
my @zones = ("0.", "1.", "2.", "3.");
my $zone_count = scalar @zones;

# add all servers to the non-numbered "NTP" zone
(my $pgeodns_group = "${name}") =~ s/\.$//;
push @{$data->{$pgeodns_group}->{a}}, $_ for @$entries;
if ($ttl) {
$data->{$pgeodns_group}->{ttl} = $ttl;
}
$data->{$pgeodns_group}->{mx} = [{mx => ".", preference => 0}];
my @ip_versions = ('v4', 'v6');
my %record_types = (v4 => 'a',
v6 => 'aaaa');

$min_non_duplicate_size = int(@$entries / $zone_count)
if (@$entries / $zone_count > $min_non_duplicate_size);
foreach my $ip_version (@ip_versions) {

# print $fh "# " . scalar @$entries . " active servers in ", $zone->name, "\n";
my $record_type = $record_types{$ip_version};

if ($#$entries < ($min_non_duplicate_size * $zone_count - 1)) {
if (my $entries = $zone->active_servers($ip_version)) {

# possible duplicates, not enough servers
foreach my $z (@zones) {
(my $pgeodns_group = "$z${name}") =~ s/\.$//;
my $min_non_duplicate_size = 2;
my $response_records = 3;
my @zones = ("0.", "1.", "2.", "3.");
my $zone_count = scalar @zones;

# already has an alias, so don't add more data
if ($data->{$pgeodns_group}->{alias}) {
next;
}
# add all servers to the non-numbered "NTP" zone
(my $pgeodns_group = "${name}") =~ s/\.$//;
push @{$data->{$pgeodns_group}->{$record_type}}, $_ for @$entries;
if ($ttl) {
$data->{$pgeodns_group}->{ttl} = $ttl;
}
$data->{$pgeodns_group}->{mx} = [{mx => ".", preference => 0}];

$data->{$pgeodns_group}->{mx} = [{mx => ".", preference => 0}];
$min_non_duplicate_size = int(@$entries / $zone_count)
if (@$entries / $zone_count > $min_non_duplicate_size);

$data->{$pgeodns_group}->{a} = [];
if ($ttl) {
$data->{$pgeodns_group}->{ttl} = $ttl;
}
@$entries = shuffle(@$entries);
foreach my $e (@$entries) {
push @{$data->{$pgeodns_group}->{a}}, $e;
# print $fh "# " . scalar @$entries . " active servers in ", $zone->name, "\n";

if ($#$entries < ($min_non_duplicate_size * $zone_count - 1)) {

# possible duplicates, not enough servers
foreach my $z (@zones) {
(my $pgeodns_group = "$z${name}") =~ s/\.$//;

# already has an alias, so don't add more data
if ($data->{$pgeodns_group}->{alias}) {
next;
}

$data->{$pgeodns_group}->{mx} = [{mx => ".", preference => 0}];

$data->{$pgeodns_group}->{$record_type} = [];
if ($ttl) {
$data->{$pgeodns_group}->{ttl} = $ttl;
}
@$entries = shuffle(@$entries);
foreach my $e (@$entries) {
push @{$data->{$pgeodns_group}->{$record_type}}, $e;
}
}
}
}
else {

# 'big' zone without duplicates
@$entries = shuffle(@$entries);
foreach my $z (@zones) {
(my $pgeodns_group = "$z${name}") =~ s/\.$//;
if ($ttl) {
$data->{$pgeodns_group}->{ttl} = $ttl;
}
$data->{$pgeodns_group}->{a} = [];
for (my $i = 0; $i < $min_non_duplicate_size; $i++) {
my $e = shift @$entries;
push @{$data->{$pgeodns_group}->{a}}, $e;
}
else {

$data->{$pgeodns_group}->{mx} = [{mx => ".", preference => 0}];
# 'big' zone without duplicates
@$entries = shuffle(@$entries);
foreach my $z (@zones) {
(my $pgeodns_group = "$z${name}") =~ s/\.$//;
if ($ttl) {
$data->{$pgeodns_group}->{ttl} = $ttl;
}
$data->{$pgeodns_group}->{$record_type} = [];
for (my $i = 0; $i < $min_non_duplicate_size; $i++) {
my $e = shift @$entries;
push @{$data->{$pgeodns_group}->{$record_type}}, $e;
}
$data->{$pgeodns_group}->{mx} = [{mx => ".", preference => 0}];
}
}
}
}

if (my $entries = $zone->active_servers('v6')) {
@$entries = shuffle(@$entries);

# for now just put all IPv6 servers in the '2' zone
(my $pgeodns_group = "2.${name}") =~ s/\.$//;
push @{$data->{$pgeodns_group}->{aaaa}}, $_ for @$entries;
}

}
}

Expand Down