Skip to content

Commit a08d5a5

Browse files
committed
ddns-scripts: fix IPv6 updates to IPv4-only DDNS providers
Smoke/Fix Testing Performed ========================== Tested on DuckDNS (only has A records) with personal account Ran with '-x' and with '-v 3' '-v 2' '-v 1' and without flags (happy path for this issue) Dual stack Client -> Single Stack Server (v4) Theory/Assumptions Behind Change: ================================ Making curl use v6 when its target host doesn't support it is DUMB Naively Everyone has a v4 address (client & server) - not true, but true-ish enough (maybe?) Testing Needed: ============== Dual Stack Client -> Dual stack Server Dual Stack Client -> Single Stack Server (v6) Single Stack Client (v4) -> Single Stack Server (v4) Single Stack Client (v4) -> Dual Stack Server Single Stack Client (v6) -> Single Stack Server (v6) Single Stack Client (v6) -> Dual Stack Server Signed-off-by: Rogan Lynch <[email protected]>
1 parent 4bcc482 commit a08d5a5

File tree

2 files changed

+63
-10
lines changed

2 files changed

+63
-10
lines changed

net/ddns-scripts/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ include $(TOPDIR)/rules.mk
88

99
PKG_NAME:=ddns-scripts
1010
PKG_VERSION:=2.8.2
11-
PKG_RELEASE:=81
11+
PKG_RELEASE:=82
1212

1313
PKG_LICENSE:=GPL-2.0
1414

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

Lines changed: 62 additions & 9 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
@@ -696,9 +722,18 @@ do_transfer() {
696722
write_log 7 "Force communication via IP '$__BINDIP'"
697723
__PROG="$__PROG --bind-address=$__BINDIP"
698724
fi
699-
# force ip version to use
700-
if [ $force_ipversion -eq 1 ]; then
701-
[ $use_ipv6 -eq 0 ] && __PROG="$__PROG -4" || __PROG="$__PROG -6" # force IPv4/IPv6
725+
# forced IP version
726+
if [ "$force_ipversion" -eq 1 ]; then
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+
# unforced IP version
735+
elif [ "$use_ipv6" -eq 1 ] && [ $__DNS_HAS_AAAA -eq 1 ]; then
736+
__PROG="$__PROG -6" # use IPv6 if available
702737
fi
703738
# set certificate parameters
704739
if [ $use_https -eq 1 ]; then
@@ -740,9 +775,18 @@ do_transfer() {
740775
write_log 7 "Force communication via device '$__DEVICE'"
741776
__PROG="$__PROG --interface $__DEVICE"
742777
fi
743-
# force ip version to use
744-
if [ $force_ipversion -eq 1 ]; then
745-
[ $use_ipv6 -eq 0 ] && __PROG="$__PROG -4" || __PROG="$__PROG -6" # force IPv4/IPv6
778+
# forced IP version
779+
if [ "$force_ipversion" -eq 1 ]; then
780+
if [ "$use_ipv6" -eq 0 ]; then
781+
__PROG="$__PROG -4"
782+
elif [ $__DNS_HAS_AAAA -eq 1 ]; then
783+
__PROG="$__PROG -6" # only force IPv6 if host supports it
784+
else
785+
__PROG="$__PROG -4" # fallback to IPv4 if host doesn't support IPv6
786+
fi
787+
# unforced IP version
788+
elif [ "$use_ipv6" -eq 1 ] && [ $__DNS_HAS_AAAA -eq 1 ]; then
789+
__PROG="$__PROG -6" # use IPv6 if available
746790
fi
747791
# set certificate parameters
748792
if [ $use_https -eq 1 ]; then
@@ -776,9 +820,18 @@ do_transfer() {
776820
# force network/ip not supported
777821
[ -n "$__BINDIP" ] && \
778822
write_log 14 "uclient-fetch: FORCE binding to specific address not supported"
779-
# force ip version to use
780-
if [ $force_ipversion -eq 1 ]; then
781-
[ $use_ipv6 -eq 0 ] && __PROG="$__PROG -4" || __PROG="$__PROG -6" # force IPv4/IPv6
823+
# forced IP version
824+
if [ "$force_ipversion" -eq 1 ]; then
825+
if [ "$use_ipv6" -eq 0 ]; then
826+
__PROG="$__PROG -4"
827+
elif [ $__DNS_HAS_AAAA -eq 1 ]; then
828+
__PROG="$__PROG -6" # only force IPv6 if host supports it
829+
else
830+
__PROG="$__PROG -4" # fallback to IPv4 if host doesn't support IPv6
831+
fi
832+
# unforced IP version
833+
elif [ "$use_ipv6" -eq 1 ] && [ $__DNS_HAS_AAAA -eq 1 ]; then
834+
__PROG="$__PROG -6" # use IPv6 if available
782835
fi
783836
# https possibly not supported
784837
[ $use_https -eq 1 -a -z "$UCLIENT_FETCH_SSL" ] && \

0 commit comments

Comments
 (0)