dnsmasq: export tftp root to the procd jail
[openwrt.git] / package / network / services / dnsmasq / files / dnsmasq.init
index efc9627..90e3dc4 100644 (file)
@@ -128,7 +128,8 @@ dnsmasq() {
        append_bool "$cfg" dbus "--enable-dbus"
        append_bool "$cfg" boguspriv "--bogus-priv"
        append_bool "$cfg" expandhosts "--expand-hosts"
-       append_bool "$cfg" enable_tftp "--enable-tftp"
+       config_get tftp_root "$cfg" "tftp_root"
+       [ -d "$tftp_root" ] && append_bool "$cfg" enable_tftp "--enable-tftp"
        append_bool "$cfg" tftp_no_fail "--tftp-no-fail"
        append_bool "$cfg" nonwildcard "--bind-dynamic"
        append_bool "$cfg" fqdn "--dhcp-fqdn"
@@ -219,6 +220,12 @@ dnsmasq() {
        xappend "--conf-dir=/tmp/dnsmasq.d"
 
        echo >> $CONFIGFILE
+
+       config_get_bool enable_tftp "$cfg" enable_tftp 0
+       [ "$enable_tftp" -gt 0 ] && {
+               config_get tftp_root "$cfg" tftp_root
+               append EXTRA_MOUNT $tftp_root
+       }
 }
 
 dhcp_subscrid_add() {
@@ -554,17 +561,6 @@ start_service() {
 
        config_load dhcp
 
-       procd_open_instance
-       procd_set_param command $PROG -C $CONFIGFILE -k -x /var/run/dnsmasq/dnsmasq.pid
-       procd_set_param file $CONFIGFILE
-       procd_set_param respawn
-
-       procd_add_jail dnsmasq ubus log
-       procd_add_jail_mount $CONFIGFILE $TRUSTANCHORSFILE $HOSTFILE /etc/passwd /etc/group /etc/TZ /dev/null /dev/urandom /etc/dnsmasq.conf /tmp/dnsmasq.d /tmp/resolv.conf.auto /etc/hosts /etc/ethers
-       procd_add_jail_mount_rw /var/run/dnsmasq/ /tmp/dhcp.leases $TIMESTAMPFILE
-       
-       procd_close_instance
-
        # before we can call xappend
        mkdir -p /var/run/dnsmasq/
        mkdir -p $(dirname $CONFIGFILE)
@@ -609,11 +605,11 @@ start_service() {
                        dhcp_domain_add "" "$hostname" "$lanaddr"
                }
 
-               network_get_ipaddrs6 lanaddr6 "lan" && {
+               [ -n "$ulaprefix" ] && network_get_ipaddrs6 lanaddr6 "lan" && {
                        for lanaddr6 in $lanaddr6; do
                                case "$lanaddr6" in
                                        "${ulaprefix%%:/*}"*)
-                                               dhcp_domain_add "" "$hostname" "${ulaprefix%%/*}1"
+                                               dhcp_domain_add "" "$hostname" "$lanaddr6"
                                        ;;
                                esac
                        done
@@ -642,6 +638,17 @@ start_service() {
        for DNS_SERVER in $DNS_SERVERS ; do
                echo "nameserver $DNS_SERVER" >> /tmp/resolv.conf
        done
+
+       procd_open_instance
+       procd_set_param command $PROG -C $CONFIGFILE -k -x /var/run/dnsmasq/dnsmasq.pid
+       procd_set_param file $CONFIGFILE
+       procd_set_param respawn
+
+       procd_add_jail dnsmasq ubus log
+       procd_add_jail_mount $CONFIGFILE $TRUSTANCHORSFILE $HOSTFILE /etc/passwd /etc/group /etc/TZ /dev/null /dev/urandom /etc/dnsmasq.conf /tmp/dnsmasq.d /tmp/resolv.conf.auto /etc/hosts /etc/ethers $EXTRA_MOUNT
+       procd_add_jail_mount_rw /var/run/dnsmasq/ /tmp/dhcp.leases $TIMESTAMPFILE
+
+       procd_close_instance
 }
 
 reload_service() {