}
hex_to_hostid() {
- local var="$1"
- local hex="${2#0x}" # strip optional "0x" prefix
+ 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
+ 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))
- )"
+ # convert into host id
+ export "$var=$(
+ printf "%0x:%0x" \
+ $(((0x$hex >> 16) % 65536)) \
+ $(( 0x$hex % 65536))
+ )"
- return 0
+ return 0
}
dhcp_calc() {
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"
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() {
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"
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