* [PATCH 1/4] network-functions.pl: Add ip_address_is_global()
2026-12-01 14:31 [PATCH 0/4] Use the address ddns publishes in the DDNS sync check (#14766) Antonio Quartulli
@ 2026-12-01 14:31 ` Antonio Quartulli
2026-12-01 14:31 ` [PATCH 2/4] wio.cgi: Get the address of the DDNS hosts only once Antonio Quartulli
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Antonio Quartulli @ 2026-12-01 14:31 UTC (permalink / raw)
To: development; +Cc: Antonio Quartulli
Returns whether an IPv4 address can be reached from the Internet, based
on the IANA special-purpose address registry.
Signed-off-by: Antonio Quartulli <antonio@mandelbit.com>
---
config/cfgroot/network-functions.pl | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/config/cfgroot/network-functions.pl b/config/cfgroot/network-functions.pl
index a90655305..9f37c490f 100644
--- a/config/cfgroot/network-functions.pl
+++ b/config/cfgroot/network-functions.pl
@@ -425,6 +425,23 @@ sub ip_address_in_range($$) {
return (($ipaddress_bin >= $ipstart_bin) && ($ipaddress_bin <= $ipend_bin));
}
+# Returns true if the IPv4 address can be reached from the Internet, i.e. it
+# isn't in any of the special-purpose ranges that aren't globally reachable
+# (based on the IANA registry).
+sub ip_address_is_global($) {
+ my $address = shift;
+
+ return 0 unless (&check_ip_address($address));
+
+ foreach my $network ("0.0.0.0/8", "10.0.0.0/8", "100.64.0.0/10", "127.0.0.0/8",
+ "169.254.0.0/16", "172.16.0.0/12", "192.0.0.0/24", "192.0.2.0/24", "192.168.0.0/16",
+ "198.18.0.0/15", "198.51.100.0/24", "203.0.113.0/24", "240.0.0.0/4") {
+ return 0 if (&ip_address_in_network($address, $network));
+ }
+
+ return 1;
+}
+
sub check_port
{
$_ = $_[0];
@@ -1022,6 +1039,18 @@ sub testsuite() {
$result = &ip_address_in_range("192.168.30.21", "192.168.30.10", "192.168.30.20");
assert('ip_address_in_range("192.168.30.21", "192.168.30.10", "192.168.30.20")', !$result);
+ # Check &ip_address_is_global()
+ foreach my $address ("81.3.27.37", "8.8.8.8", "1.0.0.0", "100.63.255.255", "100.128.0.0",
+ "169.253.255.255", "172.15.255.255", "172.32.0.0", "224.0.0.1", "239.255.255.255") {
+ assert("ip_address_is_global(\"$address\")", &ip_address_is_global($address));
+ }
+
+ foreach my $address ("10.1.2.3", "172.16.0.0", "172.31.255.255", "192.168.1.1", "100.64.0.0",
+ "100.127.255.255", "127.0.0.1", "169.254.0.0", "169.254.255.255", "0.255.255.255",
+ "192.0.2.1", "198.18.0.1", "240.0.0.0", "255.255.255.255", "a.b.c.d", "") {
+ assert("!ip_address_is_global(\"$address\")", !&ip_address_is_global($address));
+ }
+
# Check &get_prefix()
$result = &get_prefix("192.168.0.0/24");
assert('get_prefix("192.168.0.0/24")', $result == 24);
--
2.56.1
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH 2/4] wio.cgi: Get the address of the DDNS hosts only once
2026-12-01 14:31 [PATCH 0/4] Use the address ddns publishes in the DDNS sync check (#14766) Antonio Quartulli
2026-12-01 14:31 ` [PATCH 1/4] network-functions.pl: Add ip_address_is_global() Antonio Quartulli
@ 2026-12-01 14:31 ` Antonio Quartulli
2026-12-01 14:31 ` [PATCH 3/4] ddns.cgi: Get the address of the DDNS hosts only when needed Antonio Quartulli
2026-12-01 14:31 ` [PATCH 4/4] http-client-functions.pl: Use the address ddns publishes for the sync check Antonio Quartulli
3 siblings, 0 replies; 5+ messages in thread
From: Antonio Quartulli @ 2026-12-01 14:31 UTC (permalink / raw)
To: development; +Cc: Antonio Quartulli
GetDyndnsRedIP() can fetch the public address from a server, which was
done for each enabled host.
Signed-off-by: Antonio Quartulli <antonio@mandelbit.com>
---
html/cgi-bin/wio.cgi | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/html/cgi-bin/wio.cgi b/html/cgi-bin/wio.cgi
index 35e8ff041..8a229c92b 100755
--- a/html/cgi-bin/wio.cgi
+++ b/html/cgi-bin/wio.cgi
@@ -1030,6 +1030,9 @@ my @dyndnsnames = ();
if ( -s "$dyndnsconfig" ) {
@ddns = &General::read_file($dyndnsconfig);
+ # May have to be fetched from a server: only do it once
+ my $ddnsip;
+
foreach (@ddns) {
chomp;
@temp = split (/\,/, $_);
@@ -1037,7 +1040,8 @@ if ( -s "$dyndnsconfig" ) {
my $class = "has-text-info";
if ( $temp[7] eq "on" ) {
- $class = ( &HTTPClient::DyndnsServiceSync (&HTTPClient::GetDyndnsRedIP,$temp[1],$temp[2]) ? "has-text-success" : "has-text-danger" );
+ $ddnsip //= &HTTPClient::GetDyndnsRedIP();
+ $class = ( &HTTPClient::DyndnsServiceSync ($ddnsip,$temp[1],$temp[2]) ? "has-text-success" : "has-text-danger" );
}
push(@dyndnsnames, "<span class='$class'>@{[ &Header::escape($temp[1]) ]}.@{[ &Header::escape($temp[2]) ]}</span>");
--
2.56.1
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH 3/4] ddns.cgi: Get the address of the DDNS hosts only when needed
2026-12-01 14:31 [PATCH 0/4] Use the address ddns publishes in the DDNS sync check (#14766) Antonio Quartulli
2026-12-01 14:31 ` [PATCH 1/4] network-functions.pl: Add ip_address_is_global() Antonio Quartulli
2026-12-01 14:31 ` [PATCH 2/4] wio.cgi: Get the address of the DDNS hosts only once Antonio Quartulli
@ 2026-12-01 14:31 ` Antonio Quartulli
2026-12-01 14:31 ` [PATCH 4/4] http-client-functions.pl: Use the address ddns publishes for the sync check Antonio Quartulli
3 siblings, 0 replies; 5+ messages in thread
From: Antonio Quartulli @ 2026-12-01 14:31 UTC (permalink / raw)
To: development; +Cc: Antonio Quartulli
GetDyndnsRedIP() can fetch the public address from a server, which was
done on every page load, even without any enabled host.
Signed-off-by: Antonio Quartulli <antonio@mandelbit.com>
---
html/cgi-bin/ddns.cgi | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/html/cgi-bin/ddns.cgi b/html/cgi-bin/ddns.cgi
index e5fe7166f..2c075a4c8 100644
--- a/html/cgi-bin/ddns.cgi
+++ b/html/cgi-bin/ddns.cgi
@@ -445,8 +445,9 @@ print $form->render();
-e $datafile or die "Unable to open $datafile.";
@current = &General::read_file($datafile, { keep_newlines => 1 });
-# Get IP address of the red interface.
-my $ip = &HTTPClient::GetDyndnsRedIP();
+# The address of the hosts, which may have to be fetched from a server: only
+# get it when needed
+my $ip;
my $id = 0;
my $toggle_enabled;
@@ -484,6 +485,7 @@ if (@current) {
$fqdn =~ s/^[\*\@]\.//;
if (&Network::check_fqdn($fqdn)) {
+ $ip //= &HTTPClient::GetDyndnsRedIP();
$sync = (&HTTPClient::DyndnsServiceSync ($ip,$temp[1], $temp[2]) ? "has-text-success" : "has-text-danger");
}
--
2.56.1
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH 4/4] http-client-functions.pl: Use the address ddns publishes for the sync check
2026-12-01 14:31 [PATCH 0/4] Use the address ddns publishes in the DDNS sync check (#14766) Antonio Quartulli
` (2 preceding siblings ...)
2026-12-01 14:31 ` [PATCH 3/4] ddns.cgi: Get the address of the DDNS hosts only when needed Antonio Quartulli
@ 2026-12-01 14:31 ` Antonio Quartulli
3 siblings, 0 replies; 5+ messages in thread
From: Antonio Quartulli @ 2026-12-01 14:31 UTC (permalink / raw)
To: development; +Cc: Antonio Quartulli
GetDyndnsRedIP() only fetched the public address if "Fetch the public
IP" was selected and RED was in RFC1918 or the shared address space.
ddns uses it whenever fetching is selected, and when RED can't be
reached from the Internet, e.g. in 169.254.0.0/16, so the web interface
showed those hosts as out of sync. With RED behind a router, the page
now fetches the address like ddns does.
Bug: #14766
Signed-off-by: Antonio Quartulli <antonio@mandelbit.com>
---
config/cfgroot/http-client-functions.pl | 26 ++++++++++---------------
1 file changed, 10 insertions(+), 16 deletions(-)
diff --git a/config/cfgroot/http-client-functions.pl b/config/cfgroot/http-client-functions.pl
index aefad7639..6a0a0fa4d 100644
--- a/config/cfgroot/http-client-functions.pl
+++ b/config/cfgroot/http-client-functions.pl
@@ -313,7 +313,7 @@ sub FetchPublicIp {
}
#
-# This sub returns the red IP used to compare in DyndnsServiceSync
+# This sub returns the address that ddns publishes, to compare in DyndnsServiceSync
#
sub GetDyndnsRedIP {
my %settings;
@@ -322,21 +322,15 @@ sub GetDyndnsRedIP {
&General::readhash("${General::swroot}/ddns/settings", \%settings);
# Try to grab the address from the local-ipaddress file.
- my $ip = &Network::grab_address_from_file("${General::swroot}/red/local-ipaddress") or return 'unavailable';
-
- # 100.64.0.0/10 is reserved for dual-stack lite (http://tools.ietf.org/html/rfc6598).
- if (&Network::ip_address_in_network($ip, "10.0.0.0/255.0.0.0") ||
- &Network::ip_address_in_network($ip, "172.16.0.0/255.240.0.0") ||
- &Network::ip_address_in_network($ip, "192.168.0.0/255.255.0.0") ||
- &Network::ip_address_in_network($ip, "100.64.0.0/255.192.0.0"))
- {
- if ($settings{'BEHINDROUTER'} eq 'FETCH_IP') {
- # Call function to omit the real address.
- my $RealIP = &FetchPublicIp;
-
- # Check if the grabbed address is valid.
- $ip = (&Network::check_ip_address ($RealIP) ? $RealIP : 'unavailable');
- }
+ my $ip = &Network::grab_address_from_file("${General::swroot}/red/local-ipaddress");
+
+ # Like ddns, use the public address if asked to, or if RED is unknown or
+ # can't be reached from the Internet
+ if ($settings{'BEHINDROUTER'} eq 'FETCH_IP' || !&Network::ip_address_is_global($ip)) {
+ my $RealIP = &FetchPublicIp;
+
+ # Check if the grabbed address is valid.
+ $ip = (&Network::check_ip_address ($RealIP) ? $RealIP : 'unavailable');
}
return $ip;
--
2.56.1
^ permalink raw reply [flat|nested] 5+ messages in thread