# load uci functions . /lib/functions.sh configure() { ## dns uci -q del dhcp.@dnsmasq[0].server if dnsservers=$(uci -q get gateway.@dns[0].server); then for f in $dnsservers; do uci add_list dhcp.@dnsmasq[0].server=$f uci add_list dhcp.@dnsmasq[0].server="/in-addr.arpa/$f" uci add_list dhcp.@dnsmasq[0].server="/ip6.arpa/$f" done else echo "WARNING: No DNS servers set!" fi # remove all domain autogenerated entries remove_domains() { local name="$1" case $(uci -q get dhcp."$name".addedbyautoconfig) in /etc/layer3.d/35-dns | /etc/uci-defaults/90-fff-dhcp) uci -q del dhcp."$name" ;; esac } config_load dhcp config_foreach remove_domains domain local dnsips local have_dns=false # gather all ips belonging to the router dnsips=$( uci -q batch <<- EOF | cut -d / -f1 | sort -u get network.client.ip6addr get network.client.ipaddr get gateway.@gateway[0].peer_ip get gateway.@gateway[0].peer_ip6 EOF ) for ip in $dnsips; do ip=$(echo "$ip" | cut -d / -f1) case "$ip" in fe80*) continue ;; esac have_dns=true uci -q add dhcp domain > /dev/null uci -q set dhcp.@domain[-1].ip="$ip" uci -q set dhcp.@domain[-1].name="local.fff.community" uci -q set dhcp.@domain[-1].addedbyautoconfig="/etc/layer3.d/35-dns" done if ! $have_dns; then echo "WARNING: No valid device ip available for local DNS." fi } apply() { uci commit dhcp } revert() { uci revert dhcp }