add ipv6 support
This commit is contained in:
parent
027fa03895
commit
dc01f09224
2 changed files with 95 additions and 65 deletions
|
@ -25,7 +25,7 @@ Dynamic DNS services currently supported include:
|
||||||
nsupdate - See nsupdate(1) and ddns-confgen(8) for details
|
nsupdate - See nsupdate(1) and ddns-confgen(8) for details
|
||||||
CloudFlare - See https://www.cloudflare.com/ for details
|
CloudFlare - See https://www.cloudflare.com/ for details
|
||||||
Google - See http://www.google.com/domains for details
|
Google - See http://www.google.com/domains for details
|
||||||
Duckdns - See https://duckdns.org/ for details
|
Duckdns - See https://duckdns.org/ for details
|
||||||
woima.fi - See https://woima.fi/ for details
|
woima.fi - See https://woima.fi/ for details
|
||||||
|
|
||||||
DDclient now supports many of cable/dsl broadband routers.
|
DDclient now supports many of cable/dsl broadband routers.
|
||||||
|
@ -42,8 +42,9 @@ REQUIREMENTS:
|
||||||
- one or more accounts from one of the dynamic DNS services
|
- one or more accounts from one of the dynamic DNS services
|
||||||
|
|
||||||
- Perl 5.014 or later
|
- Perl 5.014 or later
|
||||||
(you need the IO::Socket::SSL perl library for ssl-support
|
(you need the IO::Socket::SSL perl library for ssl-support,
|
||||||
and JSON::Any perl library for JSON support)
|
JSON::Any perl library for JSON support and
|
||||||
|
IO::Socket:INET6 perl library for ipv6-support)
|
||||||
|
|
||||||
- Linux or probably any common Unix system
|
- Linux or probably any common Unix system
|
||||||
|
|
||||||
|
|
153
ddclient
153
ddclient
|
@ -345,12 +345,12 @@ my %variables = (
|
||||||
'retry' => setv(T_BOOL, 0, 0, 0, 0, undef),
|
'retry' => setv(T_BOOL, 0, 0, 0, 0, undef),
|
||||||
'force' => setv(T_BOOL, 0, 0, 0, 0, undef),
|
'force' => setv(T_BOOL, 0, 0, 0, 0, undef),
|
||||||
'ssl' => setv(T_BOOL, 0, 0, 0, 0, undef),
|
'ssl' => setv(T_BOOL, 0, 0, 0, 0, undef),
|
||||||
|
'ipv6' => setv(T_BOOL, 0, 0, 0, 0, undef),
|
||||||
'syslog' => setv(T_BOOL, 0, 0, 1, 0, undef),
|
'syslog' => setv(T_BOOL, 0, 0, 1, 0, undef),
|
||||||
'facility' => setv(T_STRING,0, 0, 1, 'daemon', undef),
|
'facility' => setv(T_STRING,0, 0, 1, 'daemon', undef),
|
||||||
'priority' => setv(T_STRING,0, 0, 1, 'notice', undef),
|
'priority' => setv(T_STRING,0, 0, 1, 'notice', undef),
|
||||||
'mail' => setv(T_EMAIL, 0, 0, 1, '', undef),
|
'mail' => setv(T_EMAIL, 0, 0, 1, '', undef),
|
||||||
'mail-failure' => setv(T_EMAIL, 0, 0, 1, '', undef),
|
'mail-failure' => setv(T_EMAIL, 0, 0, 1, '', undef),
|
||||||
|
|
||||||
'exec' => setv(T_BOOL, 0, 0, 1, 1, undef),
|
'exec' => setv(T_BOOL, 0, 0, 1, 1, undef),
|
||||||
'debug' => setv(T_BOOL, 0, 0, 1, 0, undef),
|
'debug' => setv(T_BOOL, 0, 0, 1, 0, undef),
|
||||||
|
@ -380,7 +380,7 @@ my %variables = (
|
||||||
'fw-password' => setv(T_PASSWD,0, 0, 1, '', undef),
|
'fw-password' => setv(T_PASSWD,0, 0, 1, '', undef),
|
||||||
'cmd' => setv(T_PROG, 0, 0, 1, '', undef),
|
'cmd' => setv(T_PROG, 0, 0, 1, '', undef),
|
||||||
'cmd-skip' => setv(T_STRING,0, 0, 1, '', undef),
|
'cmd-skip' => setv(T_STRING,0, 0, 1, '', undef),
|
||||||
|
'ipv6' => setv(T_BOOL, 0, 0, 0, 0, undef),
|
||||||
'ip' => setv(T_IP, 0, 1, 0, undef, undef),
|
'ip' => setv(T_IP, 0, 1, 0, undef, undef),
|
||||||
'wtime' => setv(T_DELAY, 0, 1, 1, 0, interval('30s')),
|
'wtime' => setv(T_DELAY, 0, 1, 1, 0, interval('30s')),
|
||||||
'mtime' => setv(T_NUMBER, 0, 1, 0, 0, undef),
|
'mtime' => setv(T_NUMBER, 0, 1, 0, 0, undef),
|
||||||
|
@ -681,7 +681,7 @@ my @opt = (
|
||||||
"usage: ${program} [options]",
|
"usage: ${program} [options]",
|
||||||
"options are:",
|
"options are:",
|
||||||
[ "daemon", "=s", "-daemon delay : run as a daemon, specify delay as an interval." ],
|
[ "daemon", "=s", "-daemon delay : run as a daemon, specify delay as an interval." ],
|
||||||
[ "foreground", "!", "-foreground : do not fork" ],
|
[ "foreground", "!", "-foreground : do not fork" ],
|
||||||
[ "proxy", "=s", "-proxy host : use 'host' as the HTTP proxy" ],
|
[ "proxy", "=s", "-proxy host : use 'host' as the HTTP proxy" ],
|
||||||
[ "server", "=s", "-server host : update DNS information on 'host'" ],
|
[ "server", "=s", "-server host : update DNS information on 'host'" ],
|
||||||
[ "protocol", "=s", "-protocol type : update protocol used" ],
|
[ "protocol", "=s", "-protocol type : update protocol used" ],
|
||||||
|
@ -729,6 +729,7 @@ my @opt = (
|
||||||
[ "debug", "!", "-{no}debug : print {no} debugging information" ],
|
[ "debug", "!", "-{no}debug : print {no} debugging information" ],
|
||||||
[ "verbose", "!", "-{no}verbose : print {no} verbose information" ],
|
[ "verbose", "!", "-{no}verbose : print {no} verbose information" ],
|
||||||
[ "quiet", "!", "-{no}quiet : print {no} messages for unnecessary updates" ],
|
[ "quiet", "!", "-{no}quiet : print {no} messages for unnecessary updates" ],
|
||||||
|
[ "ipv6", "!", "-{no}ipv6 : use ipv6" ],
|
||||||
[ "help", "", "-help : this message" ],
|
[ "help", "", "-help : this message" ],
|
||||||
[ "postscript", "", "-postscript : script to run after updating ddclient, has new IP as param" ],
|
[ "postscript", "", "-postscript : script to run after updating ddclient, has new IP as param" ],
|
||||||
|
|
||||||
|
@ -1048,7 +1049,7 @@ sub parse_assignment {
|
||||||
my ($c, $name, $value);
|
my ($c, $name, $value);
|
||||||
my ($escape, $quote) = (0, '');
|
my ($escape, $quote) = (0, '');
|
||||||
|
|
||||||
if ($rest =~ /^\s*([a-z][a-z_-]*)=(.*)/i) {
|
if ($rest =~ /^\s*([a-z][0-9a-z_-]*)=(.*)/i) {
|
||||||
($name, $rest, $value) = ($1, $2, '');
|
($name, $rest, $value) = ($1, $2, '');
|
||||||
|
|
||||||
while (length($c = substr($rest,0,1))) {
|
while (length($c = substr($rest,0,1))) {
|
||||||
|
@ -1161,7 +1162,7 @@ sub _read_config {
|
||||||
|
|
||||||
## verify that keywords are valid...and check the value
|
## verify that keywords are valid...and check the value
|
||||||
foreach my $k (keys %locals) {
|
foreach my $k (keys %locals) {
|
||||||
$locals{$k} = $passwords{$k} if defined $passwords{$k};
|
$locals{$k} = $passwords{$k} if defined $passwords{$k};
|
||||||
if (!exists $variables{'merged'}{$k}) {
|
if (!exists $variables{'merged'}{$k}) {
|
||||||
warning("unrecognized keyword '%s' (ignored)", $k);
|
warning("unrecognized keyword '%s' (ignored)", $k);
|
||||||
delete $locals{$k};
|
delete $locals{$k};
|
||||||
|
@ -1258,14 +1259,14 @@ sub init_config {
|
||||||
## and those in -options=...
|
## and those in -options=...
|
||||||
if (exists $options{'host'}) {
|
if (exists $options{'host'}) {
|
||||||
foreach my $h (split_by_comma($options{'host'})) {
|
foreach my $h (split_by_comma($options{'host'})) {
|
||||||
push @hosts, $h;
|
push @hosts, $h;
|
||||||
}
|
}
|
||||||
delete $options{'host'};
|
delete $options{'host'};
|
||||||
}
|
}
|
||||||
## merge options into host definitions or globals
|
## merge options into host definitions or globals
|
||||||
if (@hosts) {
|
if (@hosts) {
|
||||||
foreach my $h (@hosts) {
|
foreach my $h (@hosts) {
|
||||||
$config{$h} = merge(\%options, $config{$h});
|
$config{$h} = merge(\%options, $config{$h});
|
||||||
}
|
}
|
||||||
$opt{'host'} = join(',', @hosts);
|
$opt{'host'} = join(',', @hosts);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1275,14 +1276,14 @@ sub init_config {
|
||||||
|
|
||||||
## override global options with those on the command-line.
|
## override global options with those on the command-line.
|
||||||
foreach my $o (keys %opt) {
|
foreach my $o (keys %opt) {
|
||||||
if (defined $opt{$o} && exists $variables{'global-defaults'}{$o}) {
|
if (defined $opt{$o} && exists $variables{'global-defaults'}{$o}) {
|
||||||
$globals{$o} = $opt{$o};
|
$globals{$o} = $opt{$o};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
## sanity check
|
## sanity check
|
||||||
if (defined $opt{'host'} && defined $opt{'retry'}) {
|
if (defined $opt{'host'} && defined $opt{'retry'}) {
|
||||||
usage("options -retry and -host (or -option host=..) are mutually exclusive");
|
usage("options -retry and -host (or -option host=..) are mutually exclusive");
|
||||||
}
|
}
|
||||||
|
|
||||||
## determine hosts to update (those on the cmd-line, config-file, or failed cached)
|
## determine hosts to update (those on the cmd-line, config-file, or failed cached)
|
||||||
|
@ -1312,14 +1313,14 @@ sub init_config {
|
||||||
## make sure config entries have all defaults and they meet minimums
|
## make sure config entries have all defaults and they meet minimums
|
||||||
## first the globals...
|
## first the globals...
|
||||||
foreach my $k (keys %globals) {
|
foreach my $k (keys %globals) {
|
||||||
my $def = $variables{'merged'}{$k};
|
my $def = $variables{'merged'}{$k};
|
||||||
my $ovalue = define($globals{$k}, $def->{'default'});
|
my $ovalue = define($globals{$k}, $def->{'default'});
|
||||||
my $value = check_value($ovalue, $def);
|
my $value = check_value($ovalue, $def);
|
||||||
if ($def->{'required'} && !defined $value) {
|
if ($def->{'required'} && !defined $value) {
|
||||||
$value = default($k);
|
$value = default($k);
|
||||||
warning("'%s=%s' is an invalid %s. (using default of %s)", $k, $ovalue, $def->{'type'}, $value);
|
warning("'%s=%s' is an invalid %s. (using default of %s)", $k, $ovalue, $def->{'type'}, $value);
|
||||||
}
|
}
|
||||||
$globals{$k} = $value;
|
$globals{$k} = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
## now the host definitions...
|
## now the host definitions...
|
||||||
|
@ -1893,6 +1894,24 @@ EOM
|
||||||
import IO::Socket::SSL;
|
import IO::Socket::SSL;
|
||||||
{ no warnings; $IO::Socket::SSL::DEBUG = 0; }
|
{ no warnings; $IO::Socket::SSL::DEBUG = 0; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
######################################################################
|
||||||
|
## load_ipv6_support
|
||||||
|
######################################################################
|
||||||
|
sub load_ipv6_support {
|
||||||
|
my $ipv6_loaded = eval {require IO::Socket::INET6};
|
||||||
|
unless ($ipv6_loaded) {
|
||||||
|
fatal(<<"EOM");
|
||||||
|
Error loading the Perl module IO::Socket::INET6 needed for ipv6 connect.
|
||||||
|
On Debian, the package libio-socket-ssl-perl must be installed.
|
||||||
|
On Red Hat, the package perl-IO-Socket-SSL must be installed.
|
||||||
|
On Alpine, the package perl-io-socket-ssl must be installed.
|
||||||
|
EOM
|
||||||
|
}
|
||||||
|
import IO::Socket::INET6;
|
||||||
|
{ no warnings; $IO::Socket::INET6::DEBUG = 0; }
|
||||||
|
}
|
||||||
|
|
||||||
######################################################################
|
######################################################################
|
||||||
## load_sha1_support
|
## load_sha1_support
|
||||||
######################################################################
|
######################################################################
|
||||||
|
@ -1988,8 +2007,8 @@ sub geturl {
|
||||||
# local $^W = 0;
|
# local $^W = 0;
|
||||||
$0 = sprintf("%s - connecting to %s port %s", $program, $peer, $port);
|
$0 = sprintf("%s - connecting to %s port %s", $program, $peer, $port);
|
||||||
if (! opt('exec')) {
|
if (! opt('exec')) {
|
||||||
debug("skipped network connection");
|
debug("skipped network connection");
|
||||||
verbose("SENDING:", "%s", $request);
|
verbose("SENDING:", "%s", $request);
|
||||||
} elsif ($use_ssl) {
|
} elsif ($use_ssl) {
|
||||||
$sd = IO::Socket::SSL->new(
|
$sd = IO::Socket::SSL->new(
|
||||||
PeerAddr => $peer,
|
PeerAddr => $peer,
|
||||||
|
@ -1999,6 +2018,16 @@ sub geturl {
|
||||||
Timeout => opt('timeout'),
|
Timeout => opt('timeout'),
|
||||||
);
|
);
|
||||||
defined $sd or warning("cannot connect to $peer:$port socket: $@ " . IO::Socket::SSL::errstr());
|
defined $sd or warning("cannot connect to $peer:$port socket: $@ " . IO::Socket::SSL::errstr());
|
||||||
|
} elsif ($globals{'ipv6'}) {
|
||||||
|
load_ipv6_support;
|
||||||
|
$sd = IO::Socket::INET6->new(
|
||||||
|
PeerAddr => $peer,
|
||||||
|
PeerPort => $port,
|
||||||
|
Proto => 'tcp',
|
||||||
|
MultiHomed => 1,
|
||||||
|
Timeout => opt('timeout'),
|
||||||
|
);
|
||||||
|
defined $sd or warning("cannot connect to $peer:$port socket: $@");
|
||||||
} else {
|
} else {
|
||||||
$sd = IO::Socket::INET->new(
|
$sd = IO::Socket::INET->new(
|
||||||
PeerAddr => $peer,
|
PeerAddr => $peer,
|
||||||
|
@ -2141,63 +2170,63 @@ sub get_ip {
|
||||||
}
|
}
|
||||||
|
|
||||||
} elsif (($use eq 'cisco')) {
|
} elsif (($use eq 'cisco')) {
|
||||||
# Stuff added to support Cisco router ip http daemon
|
# Stuff added to support Cisco router ip http daemon
|
||||||
# User fw-login should only have level 1 access to prevent
|
# User fw-login should only have level 1 access to prevent
|
||||||
# password theft. This is pretty harmless.
|
# password theft. This is pretty harmless.
|
||||||
my $queryif = opt('if', $h);
|
my $queryif = opt('if', $h);
|
||||||
$skip = opt('fw-skip', $h) || '';
|
$skip = opt('fw-skip', $h) || '';
|
||||||
|
|
||||||
# Convert slashes to protected value "\/"
|
# Convert slashes to protected value "\/"
|
||||||
$queryif =~ s%\/%\\\/%g;
|
$queryif =~ s%\/%\\\/%g;
|
||||||
|
|
||||||
# Protect special HTML characters (like '?')
|
# Protect special HTML characters (like '?')
|
||||||
$queryif =~ s/([\?&= ])/sprintf("%%%02x",ord($1))/ge;
|
$queryif =~ s/([\?&= ])/sprintf("%%%02x",ord($1))/ge;
|
||||||
|
|
||||||
$url = "http://".opt('fw', $h)."/level/1/exec/show/ip/interface/brief/${queryif}/CR";
|
$url = "http://".opt('fw', $h)."/level/1/exec/show/ip/interface/brief/${queryif}/CR";
|
||||||
$reply = geturl('', $url, opt('fw-login', $h), opt('fw-password', $h)) || '';
|
$reply = geturl('', $url, opt('fw-login', $h), opt('fw-password', $h)) || '';
|
||||||
$arg = $url;
|
$arg = $url;
|
||||||
|
|
||||||
} elsif (($use eq 'cisco-asa')) {
|
} elsif (($use eq 'cisco-asa')) {
|
||||||
# Stuff added to support Cisco ASA ip https daemon
|
# Stuff added to support Cisco ASA ip https daemon
|
||||||
# User fw-login should only have level 1 access to prevent
|
# User fw-login should only have level 1 access to prevent
|
||||||
# password theft. This is pretty harmless.
|
# password theft. This is pretty harmless.
|
||||||
my $queryif = opt('if', $h);
|
my $queryif = opt('if', $h);
|
||||||
$skip = opt('fw-skip', $h) || '';
|
$skip = opt('fw-skip', $h) || '';
|
||||||
|
|
||||||
# Convert slashes to protected value "\/"
|
# Convert slashes to protected value "\/"
|
||||||
$queryif =~ s%\/%\\\/%g;
|
$queryif =~ s%\/%\\\/%g;
|
||||||
|
|
||||||
# Protect special HTML characters (like '?')
|
# Protect special HTML characters (like '?')
|
||||||
$queryif =~ s/([\?&= ])/sprintf("%%%02x",ord($1))/ge;
|
$queryif =~ s/([\?&= ])/sprintf("%%%02x",ord($1))/ge;
|
||||||
|
|
||||||
$url = "https://".opt('fw', $h)."/exec/show%20interface%20${queryif}";
|
$url = "https://".opt('fw', $h)."/exec/show%20interface%20${queryif}";
|
||||||
$reply = geturl('', $url, opt('fw-login', $h), opt('fw-password', $h)) || '';
|
$reply = geturl('', $url, opt('fw-login', $h), opt('fw-password', $h)) || '';
|
||||||
$arg = $url;
|
$arg = $url;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$url = opt('fw', $h) || '';
|
$url = opt('fw', $h) || '';
|
||||||
$skip = opt('fw-skip', $h) || '';
|
$skip = opt('fw-skip', $h) || '';
|
||||||
|
|
||||||
if (exists $builtinfw{$use}) {
|
if (exists $builtinfw{$use}) {
|
||||||
$skip = $builtinfw{$use}->{'skip'} unless $skip;
|
$skip = $builtinfw{$use}->{'skip'} unless $skip;
|
||||||
$url = "http://${url}" . $builtinfw{$use}->{'url'} unless $url =~ /\//;
|
$url = "http://${url}" . $builtinfw{$use}->{'url'} unless $url =~ /\//;
|
||||||
}
|
}
|
||||||
$arg = $url;
|
$arg = $url;
|
||||||
|
|
||||||
if ($url) {
|
if ($url) {
|
||||||
$reply = geturl('', $url, opt('fw-login', $h), opt('fw-password', $h)) || '';
|
$reply = geturl('', $url, opt('fw-login', $h), opt('fw-password', $h)) || '';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
if (!defined $reply) {
|
||||||
if (!defined $reply) {
|
$reply = '';
|
||||||
$reply = '';
|
|
||||||
}
|
}
|
||||||
if ($skip) {
|
if ($skip) {
|
||||||
$skip =~ s/ /\\s/is;
|
$skip =~ s/ /\\s/is;
|
||||||
$reply =~ s/^.*?${skip}//is;
|
$reply =~ s/^.*?${skip}//is;
|
||||||
}
|
}
|
||||||
if ($reply =~ /^.*?\b(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\b.*/is) {
|
if ($reply =~ /^.*?\b(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\b.*/is) {
|
||||||
$ip = $1;
|
$ip = $1;
|
||||||
$ip = un_zero_pad($ip);
|
$ip = un_zero_pad($ip);
|
||||||
$ip = filter_local($ip) if opt('fw-banlocal', $h);
|
$ip = filter_local($ip) if opt('fw-banlocal', $h);
|
||||||
} elsif ( $ip = ipv6_match($reply) ) {
|
} elsif ( $ip = ipv6_match($reply) ) {
|
||||||
$ip = un_zero_pad($ip);
|
$ip = un_zero_pad($ip);
|
||||||
|
|
Loading…
Reference in a new issue