TRUSTANCHORSFILE="/usr/share/dnsmasq/trust-anchors.conf"
TIMEVALIDFILE="/var/state/dnsmasqsec"
BASEDHCPSTAMPFILE="/var/run/dnsmasq"
+RFC6761FILE="/usr/share/dnsmasq/rfc6761.conf"
DNSMASQ_DHCP_VER=4
dhcp_option_add "$cfg" "$networkid"
}
+dhcp_option_append() {
+ local option="$1"
+ local networkid="$2"
+ local force="$3"
+
+ xappend "--dhcp-option${force:+-force}=${networkid:+$networkid,}$option"
+}
+
dhcp_option_add() {
# NOTE: dnsmasq has explicit "option6:" prefix for DHCPv6 so no collisions
local cfg="$1"
[ "$force" = "0" ] && force=
- config_get dhcp_option "$cfg" dhcp_option
- for o in $dhcp_option; do
- xappend "--dhcp-option${force:+-force}=${networkid:+$networkid,}$o"
- done
+ local list_len
+ config_get list_len "$cfg" dhcp_option_LENGTH
+
+ if [ -n "$list_len" ]; then
+ config_list_foreach "$cfg" dhcp_option dhcp_option_append "$networkid" "$force"
+ else
+ config_get dhcp_option "$cfg" dhcp_option
+ [ -n "$dhcp_option" ] && echo "Warning: the 'option dhcp_option' syntax is deprecated, use 'list dhcp_option'" >&2
+
+ local option
+ for option in $dhcp_option; do
+ dhcp_option_append "$option" "$networkid" "$force"
+ done
+ fi
}
dhcp_domain_add() {
if [ -z "$interface" ]; then
xappend "--dhcp-relay=$local_addr,$server_addr"
else
- xappend "--dhcp-relay=$local_addr,$server_addr,$interface"
+ network_get_device ifname "$interface" || return
+ xappend "--dhcp-relay=$local_addr,$server_addr,$ifname"
fi
}
dnsmasq_start()
{
- local cfg="$1" disabled
+ local cfg="$1" disabled resolvfile
config_get_bool disabled "$cfg" disabled 0
[ "$disabled" -gt 0 ] && return 0
if [ -x /usr/sbin/odhcpd -a -x /etc/init.d/odhcpd ] ; then
local odhcpd_is_main odhcpd_is_enabled
- config_get odhcpd_is_main odhcpd maindhcp
+ config_get odhcpd_is_main odhcpd maindhcp 0
/etc/init.d/odhcpd enabled && odhcpd_is_enabled=1 || odhcpd_is_enabled=0
DNSMASQ_DHCP_VER=4
fi
+ # Allow DHCP/DHCPv6 to be handled by ISC DHCPD
+ if [ -x /usr/sbin/dhcpd ] ; then
+ if [ -x /etc/init.d/dhcpd ] ; then
+ /etc/init.d/dhcpd enabled && DNSMASQ_DHCP_VER=0
+ fi
+ if [ -x /etc/init.d/dhcpd6 -a "$DNSMASQ_DHCP_VER" -gt 0 ] ; then
+ /etc/init.d/dhcpd6 enabled && DNSMASQ_DHCP_VER=4
+ fi
+ fi
append_bool "$cfg" authoritative "--dhcp-authoritative"
append_bool "$cfg" nodaemon "--no-daemon"
append_bool "$cfg" localise_queries "--localise-queries"
append_bool "$cfg" readethers "--read-ethers"
append_bool "$cfg" dbus "--enable-dbus"
- append_bool "$cfg" boguspriv "--bogus-priv"
append_bool "$cfg" expandhosts "--expand-hosts"
config_get tftp_root "$cfg" "tftp_root"
[ -d "$tftp_root" ] && append_bool "$cfg" enable_tftp "--enable-tftp"
config_list_foreach "$cfg" "addnhosts" append_addnhosts
config_list_foreach "$cfg" "bogusnxdomain" append_bogusnxdomain
append_parm "$cfg" "leasefile" "--dhcp-leasefile" "/tmp/dhcp.leases"
- append_parm "$cfg" "resolvfile" "--resolv-file" "/tmp/resolv.conf.auto"
append_parm "$cfg" "serversfile" "--servers-file"
append_parm "$cfg" "tftp_root" "--tftp-root"
append_parm "$cfg" "dhcp_boot" "--dhcp-boot"
config_get_bool readethers "$cfg" readethers
[ "$readethers" = "1" -a \! -e "/etc/ethers" ] && touch /etc/ethers
- config_get resolvfile $cfg resolvfile
config_get dhcpscript $cfg dhcpscript
config_get leasefile $cfg leasefile "/tmp/dhcp.leases"
[ -n "$resolvfile" -a \! -e "$resolvfile" ] && touch "$resolvfile"
fi
+ [ -n "$resolvfile" ] && xappend "--resolv-file=$resolvfile"
+
config_get hostsfile "$cfg" dhcphostsfile
[ -e "$hostsfile" ] && xappend "--dhcp-hostsfile=$hostsfile"
config_foreach filter_dnsmasq mxhost dhcp_mx_add "$cfg"
echo >> $CONFIGFILE_TMP
+ config_get_bool boguspriv "$cfg" boguspriv 1
+ [ "$boguspriv" -gt 0 ] && {
+ xappend "--bogus-priv"
+ [ -r "$RFC6761FILE" ] && xappend "--conf-file=$RFC6761FILE"
+ }
if [ "$DNSMASQ_DHCP_VER" -gt 4 ] ; then
# Enable RA feature for when/if it is constructed,
fi
procd_add_jail dnsmasq ubus log
- procd_add_jail_mount $CONFIGFILE $TRUSTANCHORSFILE $HOSTFILE /etc/passwd /etc/group /etc/TZ /dev/null /dev/urandom $dnsmasqconffile $dnsmasqconfdir $resolvfile $dhcpscript /etc/hosts /etc/ethers $EXTRA_MOUNT
+ procd_add_jail_mount $CONFIGFILE $TRUSTANCHORSFILE $HOSTFILE $RFC6761FILE /etc/passwd /etc/group /etc/TZ /dev/null /dev/urandom $dnsmasqconffile $dnsmasqconfdir $resolvfile $dhcpscript /etc/hosts /etc/ethers $EXTRA_MOUNT
procd_add_jail_mount_rw /var/run/dnsmasq/ $leasefile
procd_close_instance