Skip to content

Commit 5576d64

Browse files
committed
ddns-scripts: fix IPv6 updates to IPv4-only DDNS providers
When use_ipv6 is enabled but the DDNS provider only supports IPv4 (e.g., DuckDNS), the update would fail. This patch adds DNS resolution checks to detect if the update URL host supports IPv6 (AAAA records). If not, it automatically falls back to IPv4 for the transfer. Changes: - Added IPv6 capability detection for update URL hosts - Modified do_transfer() to check for AAAA records before forcing IPv6 - Implements fallback to IPv4 when host doesn't support IPv6 - Affects wget, curl, and uclient-fetch transfer methods Signed-off-by: Rogan Lynch <[email protected]>
1 parent 5369c5c commit 5576d64

File tree

1 file changed

+53
-3
lines changed

1 file changed

+53
-3
lines changed

net/ddns-scripts/files/usr/lib/ddns/dynamic_dns_functions.sh

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -677,12 +677,38 @@ do_transfer() {
677677
local __ERR=0
678678
local __CNT=0 # error counter
679679
local __PROG __RUNPROG
680+
local __URL_HOST __DNS_HAS_AAAA=0
680681

681682
[ $# -ne 1 ] && write_log 12 "Error in 'do_transfer()' - wrong number of parameters"
682683

683684
# Use ip_network as default for bind_network if not separately specified
684685
[ -z "$bind_network" ] && [ "$ip_source" = "network" ] && [ "$ip_network" ] && bind_network="$ip_network"
685686

687+
# Check if URL host supports IPv6 when use_ipv6 is enabled
688+
if [ $use_ipv6 -eq 1 ]; then
689+
# Extract hostname from URL
690+
__URL_HOST=$(echo "$__URL" | sed -e 's|^[^/]*//||' -e 's|/.*$||' -e 's|:.*$||')
691+
__DNS_HAS_AAAA=0
692+
693+
# Try to resolve IPv6 address for the host
694+
if [ -n "$BIND_HOST" ]; then
695+
$BIND_HOST -t AAAA "$__URL_HOST" >$DATFILE 2>$ERRFILE && grep -q "has IPv6 address" $DATFILE && __DNS_HAS_AAAA=1
696+
elif [ -n "$KNOT_HOST" ]; then
697+
$KNOT_HOST -t AAAA "$__URL_HOST" >$DATFILE 2>$ERRFILE && grep -q "has IPv6 address" $DATFILE && __DNS_HAS_AAAA=1
698+
elif [ -n "$DRILL" ]; then
699+
$DRILL AAAA "$__URL_HOST" >$DATFILE 2>$ERRFILE && grep -E "^$__URL_HOST\.|^$__URL_HOST[[:space:]]" $DATFILE | grep -q "$IPV6_REGEX" && __DNS_HAS_AAAA=1
700+
elif [ -n "$HOSTIP" ]; then
701+
$HOSTIP -6 "$__URL_HOST" >$DATFILE 2>$ERRFILE && grep -q "$IPV6_REGEX" $DATFILE && __DNS_HAS_AAAA=1
702+
elif [ -n "$NSLOOKUP" ]; then
703+
$NSLOOKUP "$__URL_HOST" >$DATFILE 2>$ERRFILE && grep -q "$IPV6_REGEX" $DATFILE && __DNS_HAS_AAAA=1
704+
fi
705+
706+
# If host doesn't support IPv6, we'll use IPv4 instead
707+
if [ $__DNS_HAS_AAAA -eq 0 ]; then
708+
write_log 6 "Update URL host '$__URL_HOST' does not support IPv6, using IPv4 for transfer"
709+
fi
710+
fi
711+
686712
# lets prefer GNU Wget because it does all for us - IPv4/IPv6/HTTPS/PROXY/force IP version
687713
if [ -n "$WGET_SSL" ] && [ $USE_CURL -eq 0 ]; then # except global option use_curl is set to "1"
688714
__PROG="$WGET --hsts-file=/tmp/.wget-hsts -nv -t 1 -O $DATFILE -o $ERRFILE" # non_verbose no_retry outfile errfile
@@ -698,7 +724,15 @@ do_transfer() {
698724
fi
699725
# force ip version to use
700726
if [ $force_ipversion -eq 1 ]; then
701-
[ $use_ipv6 -eq 0 ] && __PROG="$__PROG -4" || __PROG="$__PROG -6" # force IPv4/IPv6
727+
if [ $use_ipv6 -eq 0 ]; then
728+
__PROG="$__PROG -4"
729+
elif [ $__DNS_HAS_AAAA -eq 1 ]; then
730+
__PROG="$__PROG -6" # only force IPv6 if host supports it
731+
else
732+
__PROG="$__PROG -4" # fallback to IPv4 if host doesn't support IPv6
733+
fi
734+
elif [ $use_ipv6 -eq 1 ] && [ $__DNS_HAS_AAAA -eq 1 ]; then
735+
__PROG="$__PROG -6" # use IPv6 if available
702736
fi
703737
# set certificate parameters
704738
if [ $use_https -eq 1 ]; then
@@ -742,7 +776,15 @@ do_transfer() {
742776
fi
743777
# force ip version to use
744778
if [ $force_ipversion -eq 1 ]; then
745-
[ $use_ipv6 -eq 0 ] && __PROG="$__PROG -4" || __PROG="$__PROG -6" # force IPv4/IPv6
779+
if [ $use_ipv6 -eq 0 ]; then
780+
__PROG="$__PROG -4"
781+
elif [ $__DNS_HAS_AAAA -eq 1 ]; then
782+
__PROG="$__PROG -6" # only force IPv6 if host supports it
783+
else
784+
__PROG="$__PROG -4" # fallback to IPv4 if host doesn't support IPv6
785+
fi
786+
elif [ $use_ipv6 -eq 1 ] && [ $__DNS_HAS_AAAA -eq 1 ]; then
787+
__PROG="$__PROG -6" # use IPv6 if available
746788
fi
747789
# set certificate parameters
748790
if [ $use_https -eq 1 ]; then
@@ -778,7 +820,15 @@ do_transfer() {
778820
write_log 14 "uclient-fetch: FORCE binding to specific address not supported"
779821
# force ip version to use
780822
if [ $force_ipversion -eq 1 ]; then
781-
[ $use_ipv6 -eq 0 ] && __PROG="$__PROG -4" || __PROG="$__PROG -6" # force IPv4/IPv6
823+
if [ $use_ipv6 -eq 0 ]; then
824+
__PROG="$__PROG -4"
825+
elif [ $__DNS_HAS_AAAA -eq 1 ]; then
826+
__PROG="$__PROG -6" # only force IPv6 if host supports it
827+
else
828+
__PROG="$__PROG -4" # fallback to IPv4 if host doesn't support IPv6
829+
fi
830+
elif [ $use_ipv6 -eq 1 ] && [ $__DNS_HAS_AAAA -eq 1 ]; then
831+
__PROG="$__PROG -6" # use IPv6 if available
782832
fi
783833
# https possibly not supported
784834
[ $use_https -eq 1 -a -z "$UCLIENT_FETCH_SSL" ] && \

0 commit comments

Comments
 (0)