Skip to content

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

@ofry

Description

@ofry

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions