Skip to content

Commit

Permalink
Merge pull request ddclient#604 from indrajitr/nsupdate-v4-v6
Browse files Browse the repository at this point in the history
nsupdate: Adjust script to support simultaneous IPv4 and IPv6 updates
  • Loading branch information
LenardHess authored Jan 13, 2024
2 parents ad854ab + bfe20e7 commit 203fe47
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions ddclient.in
Original file line number Diff line number Diff line change
Expand Up @@ -5977,16 +5977,13 @@ sub nic_nsupdate_update {
## nsupdate requires a port number to be separated by whitepace, not colon
$server =~ s/:/ /;
my $zone = $config{$h}{'zone'};
my $ip = $config{$h}{'wantip'};
my $recordtype = '';
if (is_ipv6($ip)) {
$recordtype = 'AAAA';
} else {
$recordtype = 'A';
}
delete $config{$_}{'wantip'} foreach @hosts;
my $ipv4 = $config{$h}{'wantipv4'};
my $ipv6 = $config{$h}{'wantipv6'};
delete $config{$_}{'wantipv4'} foreach @hosts;
delete $config{$_}{'wantipv6'} foreach @hosts;

info("setting IP address to %s for %s", $ip, $hosts);
info("setting IPv4 address to %s for %s", $ipv4, $hosts) if ($ipv4);
info("setting IPv6 address to %s for %s", $ipv6, $hosts) if ($ipv6);
verbose("UPDATE:", "updating %s", $hosts);

## send separate requests for each zone with all hosts in that zone
Expand All @@ -5995,14 +5992,18 @@ server $server
zone $zone.
EoINSTR1
foreach (@hosts) {
$instructions .= <<"EoINSTR2";
update delete $_. $recordtype
update add $_. $config{$_}{'ttl'} $recordtype $ip
foreach my $ip ($ipv4, $ipv6) {
next if (!$ip);
my $type = ($ip eq ($ipv6 // '')) ? 'AAAA' : 'A';
$instructions .= <<"EoINSTR2";
update delete $_. $type
update add $_. $config{$_}{'ttl'} $type $ip
EoINSTR2
}
}
$instructions .= <<"EoINSTR3";
$instructions .= <<"EoINSTR4";
send
EoINSTR3
EoINSTR4
my $command = "$binary -k $keyfile";
$command .= " -v" if ynu($config{$h}{'tcp'}, 1, 0, 0);
$command .= " -d" if (opt('debug'));
Expand All @@ -6012,9 +6013,14 @@ EoINSTR3
my $status = pipecmd($command, $instructions);
if ($status eq 1) {
foreach (@hosts) {
$config{$_}{'ip'} = $ip;
$config{$_}{'mtime'} = $now;
success("updating %s: %s: IP address set to %s", $_, $status, $ip);
foreach my $ip ($ipv4, $ipv6) {
next if (!$ip);
my $ipv = ($ip eq ($ipv6 // '')) ? '6' : '4';
$config{$_}{"ipv$ipv"} = $ip;
$config{$_}{"status-ipv$ipv"} = 'good';
success("updating %s: good: IPv%s address set to %s", $_, $ipv, $ip);
}
}
} else {
foreach (@hosts) {
Expand Down

0 comments on commit 203fe47

Please sign in to comment.