ddns-scripts: update to 2.6.1-1 with several fixes 2351/head
authorChristian Schoenebeck <christian.schoenebeck@gmail.com>
Sat, 6 Feb 2016 14:48:39 +0000 (15:48 +0100)
committerChristian Schoenebeck <christian.schoenebeck@gmail.com>
Sat, 6 Feb 2016 14:48:39 +0000 (15:48 +0100)
- new function expand_ipv6()
- expand IPv6 before compare https://dev.openwrt.org/ticket/21725
- Fix split_FQDN() to return host.subdomain correctly  #2334
- modified check for musl library used by nslookup #2341 #2346 thanks to Arjen de Korte

Signed-off-by: Christian Schoenebeck <christian.schoenebeck@gmail.com>
net/ddns-scripts/Makefile
net/ddns-scripts/files/dynamic_dns_functions.sh
net/ddns-scripts/files/dynamic_dns_updater.sh

index 03700f4d97ca6bae7c8b6143f03294999577522f..852ab08f6be056b443f42b1694b259d7d6b13dd9 100755 (executable)
@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
 PKG_NAME:=ddns-scripts
 # Version == major.minor.patch
 # increase on new functionality (minor) or patches (patch)
-PKG_VERSION:=2.6.0
+PKG_VERSION:=2.6.1
 # Release == build
 # increase on changes of services files or tld_names.dat
 PKG_RELEASE:=1
index 85eca0db7ac4eb90b1094b511c7e428ad50ef372..ca605dfbe1d0823daac3fb23d6344f1198253e63 100755 (executable)
@@ -21,7 +21,7 @@
 . /lib/functions/network.sh
 
 # GLOBAL VARIABLES #
-VERSION="2.6.0-1"
+VERSION="2.6.1-1"
 SECTION_ID=""          # hold config's section name
 VERBOSE_MODE=1         # default mode is log to console, but easily changed with parameter
 
@@ -950,7 +950,7 @@ get_registered_ip() {
        local __CNT=0   # error counter
        local __ERR=255
        local __REGEX  __PROG  __RUNPROG  __DATA  __IP
-       local __MUSL=$(/usr/bin/nslookup 127.0.0.1 0 >/dev/null 2>&1; echo $?) # 0 == busybox compiled with musl
+       local __MUSL=$(nslookup localhost 2>&1 | grep -qF "(null)"; echo $?) # 0 == busybox compiled with musl "(null)" found
        # return codes
        # 1     no IP detected
 
@@ -1158,7 +1158,7 @@ split_FQDN() {
 
        # the leftover parameters are the HOST/SUBDOMAIN
        while [ -n "$1" ]; do
-               _HOST="$1 $HOST"                # remember we need to invert
+               _HOST="$1 $_HOST"               # remember we need to invert
                shift
        done
        _HOST=$(echo $_HOST | tr " " ".")       # insert DOT
@@ -1175,3 +1175,68 @@ split_FQDN() {
        eval "$4=''"            # clear HOST/SUBDOMAIN
        return 1
 }
+
+expand_ipv6() {
+       # Original written for bash by
+       # Author:  Florian Streibelt <florian@f-streibelt.de>
+       # Date:    08.04.2012
+       # License: Public Domain, but please be fair and
+       #          attribute the original author(s) and provide
+       #          a link to the original source for corrections:
+       #.         https://github.com/mutax/IPv6-Address-checks
+
+       # $1    IPv6 t0 expand
+       # $2    name of variable to store expanded IPv6
+       [ $# -ne 2 ] && write_log 12 "Error calling 'expand_ipv6()' - wrong number of parameters"
+
+       INPUT="$(echo "$1" | tr 'A-F' 'a-f')"
+       [ "$INPUT" = "::" ] && INPUT="::0"      # special case ::
+
+       O=""
+
+       while [ "$O" != "$INPUT" ]; do
+               O="$INPUT"
+
+               # fill all words with zeroes
+               INPUT=$( echo "$INPUT" | sed    -e 's|:\([0-9a-f]\{3\}\):|:0\1:|g' \
+                                               -e 's|:\([0-9a-f]\{3\}\)$|:0\1|g' \
+                                               -e 's|^\([0-9a-f]\{3\}\):|0\1:|g' \
+                                               -e 's|:\([0-9a-f]\{2\}\):|:00\1:|g' \
+                                               -e 's|:\([0-9a-f]\{2\}\)$|:00\1|g' \
+                                               -e 's|^\([0-9a-f]\{2\}\):|00\1:|g' \
+                                               -e 's|:\([0-9a-f]\):|:000\1:|g' \
+                                               -e 's|:\([0-9a-f]\)$|:000\1|g' \
+                                               -e 's|^\([0-9a-f]\):|000\1:|g' )
+
+       done
+
+       # now expand the ::
+       ZEROES=""
+
+       echo "$INPUT" | grep -qs "::"
+       if [ "$?" -eq 0 ]; then
+               GRPS="$( echo "$INPUT" | sed  's|[0-9a-f]||g' | wc -m )"
+               GRPS=$(( GRPS-1 ))              # remove carriage return
+               MISSING=$(( 8-GRPS ))
+               while [ $MISSING -gt 0 ]; do
+                       ZEROES="$ZEROES:0000"
+                       MISSING=$(( MISSING-1 ))
+               done
+
+               # be careful where to place the :
+               INPUT=$( echo "$INPUT" | sed    -e 's|\(.\)::\(.\)|\1'$ZEROES':\2|g' \
+                                               -e 's|\(.\)::$|\1'$ZEROES':0000|g' \
+                                               -e 's|^::\(.\)|'$ZEROES':0000:\1|g;s|^:||g' )
+       fi
+
+       # an expanded address has 39 chars + CR
+       if [ $(echo $INPUT | wc -m) != 40 ]; then
+               write_log 4 "Error in 'expand_ipv6()' - invalid IPv6 found: '$1' expanded: '$INPUT'"
+               eval "$2='invalid'"
+               return 1
+       fi
+
+       # echo the fully expanded version of the address
+       eval "$2=$INPUT"
+       return 0
+}
index d0bd5f05e8c41e38a30d37d82967ee0d1b0c7d55..78b3df74d9b837d22daa446fc40fa08512b66fc5 100755 (executable)
@@ -272,6 +272,12 @@ while : ; do
 
        get_local_ip LOCAL_IP           # read local IP
 
+       # on IPv6 we use expanded version to be shure when comparing
+       [ $use_ipv6 -eq 1 ] && {
+               expand_ipv6 "$LOCAL_IP" LOCAL_IP
+               expand_ipv6 "$REGISTERED_IP" REGISTERED_IP
+       }
+
        # prepare update
        # never updated or forced immediate then NEXT_TIME = 0
        [ $FORCE_SECONDS -eq 0 -o $LAST_TIME -eq 0 ] \