Fixed bug that would cause IPv4 address to be updated even if it was unchanged.

Caused by testing for IPv6 address change even though no IPv6 update was requested.
Added capability to specify whether IPv4 or IPv6 should be updated or not with new
values:
use=no
usev6=no
This commit is contained in:
David Kerr 2016-09-20 22:14:47 -04:00
parent c9523f382c
commit 15ad4b54b5

View file

@ -292,6 +292,7 @@ my %builtinfw = (
},
);
my %ip_strategies = (
'no' => ": do not obtain an IPv4 address for this host",
'ip' => ": obtain IP from -ip {address}",
'web' => ": obtain IP from an IP discovery page on the web",
'fw' => ": obtain IP from the firewall specified by -fw {type|address}",
@ -307,6 +308,7 @@ sub ip_strategies_usage {
my %ipv6_strategies = (
'no' => ": do not obtain an IPv6 address for this host",
'ip' => ": obtain IP from -ipv6 {address}",
'if' => ": obtain IP from the -if {interface}",
'cmd' => ": obtain IP from the -cmdv6 {external-command}",
@ -391,7 +393,7 @@ my %variables = (
'host' => setv(T_STRING, 1, 1, 1, '', undef),
'use' => setv(T_USE, 0, 0, 1, 'ip', undef),
'usev6' => setv(T_USE, 0, 0, 1, undef, undef),
'usev6' => setv(T_USEV6, 0, 0, 1, undef, undef),
'if' => setv(T_IF, 0, 0, 1, 'ppp0', undef),
'if-skip' => setv(T_STRING,0, 0, 1, '', undef),
'web' => setv(T_STRING,0, 0, 1, 'dyndns', undef),
@ -947,7 +949,7 @@ sub update_nics {
} else {
$ip = get_ip($use, $h);
if (!defined $ip || !$ip) {
warning("%s: unable to determine IPv4 address", $h)
warning("%s: unable to determine IPv4 address with strategy use=%s", $h, $use)
if !$daemon || opt('verbose');
} elsif ($ip !~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
warning("%s: malformed IPv4 address (%s)", $h, $ip);
@ -963,7 +965,7 @@ sub update_nics {
} else {
$ipv6 = get_ipv6($usev6, $h);
if (!defined $ipv6 || !$ipv6) {
warning("%s: unable to determine IPv6 address", $h)
warning("%s: unable to determine IPv6 address with strategy usev6=%s", $h, $usev6)
if !$daemon || opt('verbose');
} elsif ($ipv6 !~ /^(((?=.*(::))(?!.*\3.+\3))\3?|([\dA-F]{1,4}(\3|:\b|$)|\2))(?4){5}((?4){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4})\z/ai) {
# That little gem from http://home.deds.nl/~aeron/regex/
@ -2338,6 +2340,9 @@ sub get_ip {
$reply = geturl('', $url, opt('fw-login', $h), opt('fw-password', $h)) || '';
$arg = $url;
} elsif ($use eq 'no') {
$reply = '0.0.0.0';
} else {
$url = opt('fw', $h) || '';
$skip = opt('fw-skip', $h) || '';
@ -2355,6 +2360,7 @@ sub get_ip {
if (!defined $reply) {
$reply = '';
}
if ($skip) {
$skip =~ s/ /\\s/is;
$reply =~ s/^.*?${skip}//is;
@ -2418,10 +2424,13 @@ sub get_ipv6 {
$reply = geturl(opt('proxy', $h), $url, undef, undef, undef, undef, undef, '6') || '';
}
}
if (!defined $reply) {
} elsif ($usev6 eq 'no') {
$reply = '';
}
if (!defined $reply) {
$reply = '::';
}
if ($skip) {
$skip =~ s/ /\\s/is;
$reply =~ s/^.*?${skip}//is;
@ -2559,8 +2568,8 @@ sub nic_updateable {
);
$update = 1;
} elsif ((!exists($cache{$host}{'ip'})) ||
("$cache{$host}{'ip'}" ne "$ip")) {
} elsif (defined($cache{$host}{'use'} && ($cache{$host}{'use'} ne 'no')) &&
((!exists($cache{$host}{'ip'})) || ("$cache{$host}{'ip'}" ne "$ip"))) {
if (($cache{$host}{'status'} eq 'good') &&
!interval_expired($host, 'mtime', 'min-interval')) {
@ -2572,7 +2581,6 @@ sub nic_updateable {
prettyinterval($config{$host}{'min-interval'})
)
if opt('verbose') || !define($cache{$host}{'warned-min-interval'}, 0);
$cache{$host}{'warned-min-interval'} = $now;
} elsif (($cache{$host}{'status'} ne 'good') && !interval_expired($host, 'atime', 'min-error-interval')) {
@ -2586,14 +2594,14 @@ sub nic_updateable {
prettyinterval($config{$host}{'min-error-interval'})
)
if opt('verbose') || !define($cache{$host}{'warned-min-error-interval'}, 0);
$cache{$host}{'warned-min-error-interval'} = $now;
} else {
$update = 1;
}
} elsif ((!exists($cache{$host}{'ipv6'})) ||
("$cache{$host}{'ipv6'}" ne "$ipv6")) {
} elsif (defined($cache{$host}{'usev6'} && ($cache{$host}{'usev6'} ne 'no') ) &&
((!exists($cache{$host}{'ipv6'})) || ("$cache{$host}{'ipv6'}" ne "$ipv6"))) {
if (($cache{$host}{'status'} eq 'good') &&
!interval_expired($host, 'mtime', 'min-interval')) {
warning("skipping update of %s from %s to %s.\nlast updated %s.\nWait at least %s between update attempts.",
@ -2604,7 +2612,6 @@ sub nic_updateable {
prettyinterval($config{$host}{'min-interval'})
)
if opt('verbose') || !define($cache{$host}{'warned-min-interval'}, 0);
$cache{$host}{'warned-min-interval'} = $now;
} elsif (($cache{$host}{'status'} ne 'good') && !interval_expired($host, 'atime', 'min-error-interval')) {
@ -2617,12 +2624,12 @@ sub nic_updateable {
prettyinterval($config{$host}{'min-error-interval'})
)
if opt('verbose') || !define($cache{$host}{'warned-min-error-interval'}, 0);
$cache{$host}{'warned-min-error-interval'} = $now;
} else {
$update = 1;
}
} elsif (defined($sub) && &$sub($host)) {
$update = 1;
} elsif ((defined($cache{$host}{'static'}) && defined($config{$host}{'static'}) &&
@ -2655,6 +2662,7 @@ sub nic_updateable {
return $update;
}
######################################################################
## header_ok
######################################################################