Changing the function like this allows dynamic leases without an ip address, hostname (and hostid ? I’m not sure what that is)
dhcp_host_add() {
local cfg="$1"
local hosttag nametime addrs duids macs tags mtags
config_get_bool force "$cfg" force 0
config_get networkid "$cfg" networkid
[ -n "$networkid" ] && dhcp_option_add "$cfg" "$networkid" "$force"
config_get_bool enable "$cfg" enable 1
[ "$enable" = "0" ] && return 0
config_get name "$cfg" name
config_get ip "$cfg" ip
config_get hostid "$cfg" hostid
config_get mac "$cfg" mac
config_get duid "$cfg" duid
[ -z "$ip" ] && [ -z "$name" ] && [ -z "$hostid" ] && [ -z "$mac" ] && [ -z "$duid" ] && return 0
config_get_bool dns "$cfg" dns 0
[ "$dns" = "1" ] && [ -n "$ip" ] && [ -n "$name" ] && {
echo "$ip $name${DOMAIN:+.$DOMAIN}" >> "$HOSTFILE_TMP"
}
config_get tag "$cfg" tag
add_tag() {
mtags="${mtags}tag:$1,"
}
config_list_foreach "$cfg" match_tag add_tag
if [ -n "$mac" ]; then
# --dhcp-host=00:20:e0:3b:13:af,192.168.0.199,lap
# many MAC are possible to track a laptop ON/OFF dock
for m in $mac; do append macs "$m" ","; done
fi
if [ $DNSMASQ_DHCP_VER -eq 6 ] && [ -n "$duid" ]; then
# --dhcp-host=id:00:03:00:01:12:00:00:01:02:03,[::beef],lap
# one (virtual) machine gets one DUID per RFC3315
duids="id:${duid// */}"
fi
if [ -z "$macs" ] && [ -z "$duids" ]; then
# --dhcp-host=lap,192.168.0.199,[::beef]
[ -n "$name" ] || return 0
macs="$name"
name=""
fi
if [ -n "$hostid" ]; then
hex_to_hostid hostid "$hostid"
fi
if [ -n "$tag" ]; then
for t in $tag; do append tags "$t" ",set:"; done
fi
config_get_bool broadcast "$cfg" broadcast 0
config_get leasetime "$cfg" leasetime
[ "$broadcast" = "0" ] && broadcast= || broadcast=",set:needs-broadcast"
hosttag="${networkid:+,set:${networkid}}${tags:+,set:${tags}}$broadcast"
nametime="${name:+,$name}${leasetime:+,$leasetime}"
if [ $DNSMASQ_DHCP_VER -eq 6 ]; then
addrs="${ip:+,$ip}${hostid:+,[::$hostid]}"
xappend "--dhcp-host=$mtags$macs${duids:+,$duids}$hosttag$addrs$nametime"
else
xappend "--dhcp-host=$mtags$macs$hosttag${ip:+,$ip}$nametime"
fi
}
I have tested this, it is great and works well.
The point is that this allows you to change dhcp options for a range of MAC addresses in my case.
So in my system I have all MAC which match
de:ad:be:ef:*:*
have dhcp option
3,10.0.0.254
which is a non-routing address (later will be a fakeinternet router)
The point is to block internet access to the whole range of MAC address without incumbering the router with IP filtering address, which require static lease management, which I want to avoid as much as possible. And I’ll add my cell phone, TVs and IoT devices by MAC address wildcard.
So I would like to submit this change to this file.
I have made a series of sed commands which apply the change to the original file