diff --git a/ddclient.in b/ddclient.in index 144bd2b..119026b 100755 --- a/ddclient.in +++ b/ddclient.in @@ -1436,6 +1436,9 @@ sub update_nics { $0 = sprintf("%s - updating %s", $program, join(',', @hosts)); local $_l = pushlogctx($p); &$update(@hosts); + for my $h (@hosts) { + delete($config{$h}{$_}) for qw(wantip wantipv4 wantipv6); + } # Backwards compatibility: # The legacy '--use' parameter sets 'wantip' and the legacy providers process this and @@ -3541,21 +3544,18 @@ sub nic_updateable { } } - $config{$host}{'status'} = $recap{$host}{'status'}; - $config{$host}{'status-ipv4'} = $recap{$host}{'status-ipv4'}; - $config{$host}{'status-ipv6'} = $recap{$host}{'status-ipv6'}; - $config{$host}{'update'} = $update; + delete($config{$host}{$_}) for qw(status status-ipv4 status-ipv6 update); if ($update) { - $config{$host}{'status'} = undef; - $config{$host}{'status-ipv4'} = undef; - $config{$host}{'status-ipv6'} = undef; - $config{$host}{'atime'} = $now; - $config{$host}{'wtime'} = 0; - $config{$host}{'warned-min-interval'} = 0; - $config{$host}{'warned-min-error-interval'} = 0; - + $config{$host}{'update'} = 1; + $config{$host}{'atime'} = $now; + delete($config{$host}{$_}) for qw(wtime warned-min-interval warned-min-error-interval); delete $recap{$host}{'warned-min-interval'}; delete $recap{$host}{'warned-min-error-interval'}; + } else { + for (qw(status status-ipv4 status-ipv6)) { + $config{$host}{$_} = $recap{$host}{$_} if defined($recap{$host}{$_}); + } + delete($config{$host}{$_}) for qw(wantip wantipv4 wantipv6); } return $update; diff --git a/t/update_nics.pl b/t/update_nics.pl index 5b48061..4b581a5 100644 --- a/t/update_nics.pl +++ b/t/update_nics.pl @@ -78,22 +78,12 @@ my @test_cases = ( 'ip' => '192.0.2.1', 'mtime' => $ddclient::now, 'status' => 'good', - 'warned-min-error-interval' => 0, - 'warned-min-interval' => 0, - 'wtime' => 0, }, want_cfg_changes => { 'atime' => $ddclient::now, 'ip' => '192.0.2.1', 'mtime' => $ddclient::now, 'status' => 'good', - 'status-ipv4' => undef, - 'status-ipv6' => undef, - 'wantipv4' => '192.0.2.1', - 'wantipv6' => undef, - 'warned-min-error-interval' => 0, - 'warned-min-interval' => 0, - 'wtime' => 0, }, %$_, }; @@ -112,22 +102,12 @@ my @test_cases = ( 'ip' => '2001:db8::1', 'mtime' => $ddclient::now, 'status' => 'good', - 'warned-min-error-interval' => 0, - 'warned-min-interval' => 0, - 'wtime' => 0, }, want_cfg_changes => { 'atime' => $ddclient::now, 'ip' => '2001:db8::1', 'mtime' => $ddclient::now, 'status' => 'good', - 'status-ipv4' => undef, - 'status-ipv6' => undef, - 'wantipv4' => undef, - 'wantipv6' => '2001:db8::1', - 'warned-min-error-interval' => 0, - 'warned-min-interval' => 0, - 'wtime' => 0, }, }, { @@ -143,22 +123,12 @@ my @test_cases = ( 'ip' => '2001:db8::1', 'mtime' => $ddclient::now, 'status' => 'good', - 'warned-min-error-interval' => 0, - 'warned-min-interval' => 0, - 'wtime' => 0, }, want_cfg_changes => { 'atime' => $ddclient::now, 'ip' => '2001:db8::1', 'mtime' => $ddclient::now, 'status' => 'good', - 'status-ipv4' => undef, - 'status-ipv6' => undef, - 'wantipv4' => undef, - 'wantipv6' => '2001:db8::1', - 'warned-min-error-interval' => 0, - 'warned-min-interval' => 0, - 'wtime' => 0, }, }, { @@ -175,22 +145,12 @@ my @test_cases = ( 'ip' => '192.0.2.1', 'mtime' => $ddclient::now, 'status' => 'good', - 'warned-min-error-interval' => 0, - 'warned-min-interval' => 0, - 'wtime' => 0, }, want_cfg_changes => { 'atime' => $ddclient::now, 'ip' => '192.0.2.1', 'mtime' => $ddclient::now, 'status' => 'good', - 'status-ipv4' => undef, - 'status-ipv6' => undef, - 'wantipv4' => '192.0.2.1', - 'wantipv6' => '2001:db8::1', - 'warned-min-error-interval' => 0, - 'warned-min-interval' => 0, - 'wtime' => 0, }, }, map({ @@ -208,13 +168,6 @@ my @test_cases = ( 'protocol' => 'legacy', %cfg, }, - want_cfg_changes => { - 'status-ipv4' => undef, - 'status-ipv6' => undef, - 'wantip' => '192.0.2.1', - 'wantipv4' => '192.0.2.1', - 'wantipv6' => undef, - }, %$_, }; } @@ -236,13 +189,6 @@ my @test_cases = ( 'protocol' => 'legacy', %cfg, }, - want_cfg_changes => { - 'status-ipv4' => undef, - 'status-ipv6' => undef, - 'wantip' => '192.0.2.1', - 'wantipv4' => '192.0.2.1', - 'wantipv6' => undef, - }, %$_, }; } @@ -267,13 +213,6 @@ my @test_cases = ( want_recap_changes => { 'warned-min-interval' => $ddclient::now, }, - want_cfg_changes => { - 'status-ipv4' => undef, - 'status-ipv6' => undef, - 'wantip' => '192.0.2.1', - 'wantipv4' => '192.0.2.1', - 'wantipv6' => undef, - }, %$_, }; } @@ -300,21 +239,11 @@ my @test_cases = ( 'atime' => $ddclient::now, 'ip' => '192.0.2.1', 'mtime' => $ddclient::now, - 'warned-min-error-interval' => 0, - 'warned-min-interval' => 0, - 'wtime' => 0, }, want_cfg_changes => { 'atime' => $ddclient::now, 'ip' => '192.0.2.1', 'mtime' => $ddclient::now, - 'status-ipv4' => undef, - 'status-ipv6' => undef, - 'wantipv4' => '192.0.2.1', - 'wantipv6' => undef, - 'warned-min-error-interval' => 0, - 'warned-min-interval' => 0, - 'wtime' => 0, }, %$_, }; @@ -343,13 +272,6 @@ my @test_cases = ( want_recap_changes => { 'warned-min-error-interval' => $ddclient::now, }, - want_cfg_changes => { - 'status-ipv4' => undef, - 'status-ipv6' => undef, - 'wantip' => '192.0.2.1', - 'wantipv4' => '192.0.2.1', - 'wantipv6' => undef, - }, %$_, }; } {cfg => {use => 'web'}}, {cfg => {usev4 => 'webv4'}}), @@ -374,22 +296,12 @@ my @test_cases = ( 'ip' => '192.0.2.1', 'mtime' => $ddclient::now, 'status' => 'good', - 'warned-min-error-interval' => 0, - 'warned-min-interval' => 0, - 'wtime' => 0, }, want_cfg_changes => { 'atime' => $ddclient::now, 'ip' => '192.0.2.1', 'mtime' => $ddclient::now, 'status' => 'good', - 'status-ipv4' => undef, - 'status-ipv6' => undef, - 'wantipv4' => '192.0.2.1', - 'wantipv6' => undef, - 'warned-min-error-interval' => 0, - 'warned-min-interval' => 0, - 'wtime' => 0, }, %$_, }; @@ -437,7 +349,7 @@ for my $tc (@test_cases) { Names => ['*got', '*want'])); } my %want_cfg = (host => { - update => $tc->{want_update} ? 1 : 0, + $tc->{want_update} ? (update => 1) : (), %cfg, %{$tc->{want_cfg_changes} // {}}, });