dnsmasq: add DHCP Unique Identifier for DHCPv6
[openwrt/openwrt.git] / package / network / services / dnsmasq / files / dnsmasq.init
index 76128301037cd8c4b1387fce532cacabf4d0f1a1..45fc29e2a64c7dabb48151f0990ac2bff14b5258 100644 (file)
@@ -35,7 +35,7 @@ hex_to_hostid() {
         export "$var=$(
                 printf "%0x:%0x"  \
                         $(((0x$hex >> 16) % 65536)) \
-                        $(( 0x$hex        % 256))
+                        $(( 0x$hex        % 65536))
         )"
 
         return 0
@@ -278,6 +278,7 @@ dhcp_host_add() {
        config_get tag "$cfg" tag
 
        if [ "$DHCPv6CAPABLE" -eq 1 ]; then
+               config_get duid "$cfg" duid
                config_get hostid "$cfg" hostid
                if [ -n "$hostid" ]; then
                        hex_to_hostid hostid "$hostid"
@@ -289,7 +290,7 @@ dhcp_host_add() {
 
        config_get leasetime "$cfg" leasetime
 
-       xappend "--dhcp-host=$macs${networkid:+,net:$networkid}${broadcast:+,set:needs-broadcast}${tag:+,set:$tag}${ip:+,$ip${hostid:+,[::$hostid]}}${name:+,$name}${leasetime:+,$leasetime}"
+       xappend "--dhcp-host=$macs${duid:+,id:$duid}${networkid:+,net:$networkid}${broadcast:+,set:needs-broadcast}${tag:+,set:$tag}${ip:+,$ip${hostid:+,[::$hostid]}}${name:+,$name}${leasetime:+,$leasetime}"
 }
 
 dhcp_tag_add() {
@@ -573,6 +574,7 @@ dnsmasq_start()
        append_bool "$cfg" allservers "--all-servers"
        append_bool "$cfg" noping "--no-ping"
 
+       append_parm "$cfg" logfacility "--log-facility"
        append_parm "$cfg" dhcpscript "--dhcp-script"
        append_parm "$cfg" cachesize "--cache-size"
        append_parm "$cfg" dnsforwardmax "--dns-forward-max"
@@ -660,11 +662,17 @@ dnsmasq_start()
                append_bool "$cfg" dnsseccheckunsigned "--dnssec-check-unsigned"
        }
 
+       config_get addmac "$cfg" addmac 0
+       [ "$addmac" != "0" ] && {
+               [ "$addmac" = "1" ] && addmac=
+               xappend "--add-mac${addmac:+="$addmac"}"
+       }
+
        dhcp_option_add "$cfg" "" 0
 
        xappend "--dhcp-broadcast=tag:needs-broadcast"
 
-       xappend "--addn-hosts=$HOSTFILE"
+       xappend "--addn-hosts=$(dirname $HOSTFILE)"
 
        config_get dnsmasqconfdir "$cfg" confdir "/tmp/dnsmasq.d"
        [ ! -d "$dnsmasqconfdir" ] && mkdir -p $dnsmasqconfdir