`smartdns`: `dhcp_option` incorrectly includes CIDR suffix from network.lan.ipaddr

Open Beginner friendly
#29,053 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
shell
Domain
networking

Research direction

Start with /etc/init.d/smartdns and inspect set_main_dns(), especially the network.lan.ipaddr lookup and dhcp_option update. Reproduce the behavior with the listed UCI commands and restart sequence. Done means DHCP option 6 contains only plain IP addresses and repeated restarts do not add invalid or duplicate entries.

Written by the indexing model from the issue text.

Description

bug
Package Name

smartdns

Maintainer

Nick Peng pymumu@gmail.com

OpenWrt Version

25.12.2

OpenWrt Target/Subtarget

mediatek/filogic

Steps to Reproduce
  1. Use OpenWrt 23.x / 24.x / 25.x (DSA-based system)

  2. Ensure LAN IP is in CIDR format:

uci get network.lan.ipaddr
# example output:
192.168.1.1/24
  1. Ensure no existing DHCP option 6 (optional, for clean test):
uci del dhcp.lan.dhcp_option
uci commit dhcp
  1. Restart smartdns:
/etc/init.d/smartdns restart
  1. Check DHCP options:
uci show dhcp | grep dhcp_option
Actual Behaviour

/etc/init.d/smartdns executes set_main_dns() (lines ~87–107):

set_main_dns() {
    local hostip
    hostip="$(uci -q get network.lan.ipaddr)"      # retrieves LAN IP
    dnsmasq_port="$(uci -q get dhcp.@dnsmasq[0].port)"
    [ -z "$dnsmasq_port" ] && dnsmasq_port="53"

    [ -z "$hostip" ] && return
    [ "$dnsmasq_port" = "53" ] && {
        uci -q set dhcp.@dnsmasq[0].port=0
        uci -q add_list dhcp.lan.dhcp_option="6,$hostip"   # <-- adds DHCP option
    }
    uci commit dhcp
}
root@OpenWrt:~# uci get network.lan.ipaddr
192.168.1.1/24

After /etc/init.d/smartdns restart

uci show dhcp | grep dhcp_option
dhcp.lan.dhcp_option='6,192.168.1.1' '6,192.168.1.1/24' # <-- invalid, breaks DHCP
Consequences:

DHCP option 6 expects plain IP addresses; /24 suffix leads to invalid DNS assignment (24.192.168.1 on clients).
Duplicate entries accumulate on multiple restarts.
Breaks DNS resolution on all DHCP clients.

Expected Behavior:

dhcp.lan.dhcp_option should only contain plain IP addresses, without CIDR.
Restarting smartdns should not introduce invalid or duplicate DHCP options.

Notes / Additional Info:

The problematic code is specific to set_main_dns() in /etc/init.d/smartdns.
Root cause: the script blindly appends network.lan.ipaddr to dhcp_option without stripping CIDR.

Confirmation Checklist
Dominant language
Makefile
Stars
4.6k
Forks
4k
Avg merge
3d 34m
Merged PRs (30d)
115

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from openwrt/packages

All issues in openwrt/packages

Similar issues

More Networking issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.