dnsmasq: support hostid ipv6 address suffix option
[openwrt/staging/yousong.git] / package / network / services / dnsmasq / files / dnsmasq.init
index 0360548e0d5eb107d85c4f5d0af9e8dab0b3cb98..1a9903e50dc8edb2eb11f6d8c23ba12ba81f846b 100644 (file)
@@ -23,6 +23,25 @@ xappend() {
        echo "${value#--}" >> $CONFIGFILE
 }
 
+hex_to_hostid() {
+        local var="$1"
+        local hex="${2#0x}"     # strip optional "0x" prefix
+
+        if [ -n "${hex//[0-9a-fA-F]/}" ]; then
+                # is invalid hex literal
+                return 1
+        fi
+
+        # convert into host id
+        export "$var=$(
+                printf "%0x:%0x"  \
+                        $(((0x$hex >> 16) % 65536)) \
+                        $(( 0x$hex        % 256))
+        )"
+
+        return 0
+}
+
 dhcp_calc() {
        local ip="$1"
        local res=0
@@ -149,6 +168,7 @@ dnsmasq() {
        append_parm "$cfg" dhcpleasemax "--dhcp-lease-max"
        append_parm "$cfg" "queryport" "--query-port"
        append_parm "$cfg" "minport" "--min-port"
+       append_parm "$cfg" "maxport" "--max-port"
        append_parm "$cfg" "domain" "--domain"
        append_parm "$cfg" "local" "--server"
        config_list_foreach "$cfg" "server" append_server
@@ -352,12 +372,19 @@ dhcp_host_add() {
 
        config_get tag "$cfg" tag
 
+       if [ "$DHCPv6CAPABLE" -eq 1 ]; then
+               config_get hostid "$cfg" hostid
+               if [ -n "$hostid" ]; then
+                       hex_to_hostid hostid "$hostid"
+               fi
+       fi
+
        config_get_bool broadcast "$cfg" broadcast 0
        [ "$broadcast" = "0" ] && broadcast=
 
        config_get leasetime "$cfg" leasetime
 
-       xappend "--dhcp-host=$macs${networkid:+,net:$networkid}${broadcast:+,set:needs-broadcast}${tag:+,set:$tag}${ip:+,$ip}${name:+,$name}${leasetime:+,$leasetime}"
+       xappend "--dhcp-host=$macs${networkid:+,net:$networkid}${broadcast:+,set:needs-broadcast}${tag:+,set:$tag}${ip:+,$ip${hostid:+,[::$hostid]}}${name:+,$name}${leasetime:+,$leasetime}"
 }
 
 dhcp_tag_add() {
@@ -613,6 +640,8 @@ start_service() {
                xappend "--conf-file=/etc/dnsmasq.conf"
        }
 
+       $PROG --version | grep -osqE "^Compile time options:.* DHCPv6( |$)" && DHCPv6CAPABLE=1 || DHCPv6CAPABLE=0
+
        args=""
        config_foreach dnsmasq dnsmasq
        config_foreach dhcp_host_add host