#!/bin/sh

# shellcheck disable=SC1091

. /lib/functions/guard.sh
guard "dhcp"

# quieten down dnsmasq a bit (do not log lease-mgmt)
uci set dhcp.@dnsmasq[0].quietdhcp=1

# set the domain to ff
uci set dhcp.@dnsmasq[0].domain='ff'

# dnsmasq should not care for 'wan',
# prevents: daemon.warn dnsmasq-dhcp: DHCP packet received on xxx-wan which has no address.
uci add_list dhcp.@dnsmasq[0].notinterface='wan'

# on IPv6-islands we also should give a default-route to the clients,
# so they can also reach IPv6-neighbours.
uci set dhcp.lan.ra_default=1

# add dns entry frei.funk
uci set dhcp.frei_funk=domain
uci set dhcp.frei_funk.name=frei.funk
uci set dhcp.frei_funk.ip=192.168.42.1

# add dns entry frei.funk for ipv6
router_ula=$(uci get network.globals.ula_prefix | sed -e 's/\/48/1/')
uci set dhcp.frei_funk_ipv6=domain
uci set dhcp.frei_funk_ipv6.name=frei.funk
uci set dhcp.frei_funk_ipv6.ip="$router_ula"

# don't send default-route to clients to prevent them sending pakets
# to us, that we can't forward now
uci add_list dhcp.lan.dhcp_option='3'

# default DNS, will be overwritten by community profile later on
uci add_list dhcp.@dnsmasq[0].server='9.9.9.10'        # Quad9 unfiltered
uci add_list dhcp.@dnsmasq[0].server='194.150.168.168' # AS250 dns resolver

uci commit dhcp
