[Dnsmasq-discuss] [PATCH] add --tftp-no-fail to ignore missing tftp root

Stefan Tomanek stefan.tomanek+dnsmasq at wertarbyte.de
Tue Mar 31 14:16:43 BST 2015


This change makes dnsmasq ignore any missing TFTP root directories
if --tftp-no-fail is specified; this is useful for router devices
that store TFTP data on an external storage that might not always
be present.

Signed-off-by: Stefan Tomanek <stefan.tomanek+dnsmasq at wertarbyte.de>
---
 dnsmasq.conf.example |  3 +++
 man/dnsmasq.8        |  3 +++
 src/dnsmasq.c        | 18 ++++++++++++++----
 src/dnsmasq.h        |  3 ++-
 src/option.c         |  3 +++
 5 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/dnsmasq.conf.example b/dnsmasq.conf.example
index 1bd305d..67be99a 100644
--- a/dnsmasq.conf.example
+++ b/dnsmasq.conf.example
@@ -486,6 +486,9 @@
 # Set the root directory for files available via FTP.
 #tftp-root=/var/ftpd
 
+# Do not abort if the tftp-root is unavailable
+#tftp-no-fail
+
 # Make the TFTP server more secure: with this set, only files owned by
 # the user dnsmasq is running as will be send over the net.
 #tftp-secure
diff --git a/man/dnsmasq.8 b/man/dnsmasq.8
index 1f1dd7b..6b4626c 100644
--- a/man/dnsmasq.8
+++ b/man/dnsmasq.8
@@ -1711,6 +1711,9 @@ Absolute paths (starting with /) are allowed, but they must be within
 the tftp-root. If the optional interface argument is given, the
 directory is only used for TFTP requests via that interface.
 .TP
+.B --tftp-no-fail
+Do not abort startup if specified tftp root directories are inaccessible.
+.TP
 .B --tftp-unique-root
 Add the IP address of the TFTP client as a path component on the end
 of the TFTP-root (in standard dotted-quad format). Only valid if a
diff --git a/src/dnsmasq.c b/src/dnsmasq.c
index b784951..8bf94ec 100644
--- a/src/dnsmasq.c
+++ b/src/dnsmasq.c
@@ -645,8 +645,13 @@ int main (int argc, char **argv)
 	{
 	  if (!((dir = opendir(daemon->tftp_prefix))))
 	    {
-	      send_event(err_pipe[1], EVENT_TFTP_ERR, errno, daemon->tftp_prefix);
-	      _exit(0);
+	      if (! option_bool(OPT_TFTP_NO_FAIL))
+	        {
+	          send_event(err_pipe[1], EVENT_TFTP_ERR, errno, daemon->tftp_prefix);
+	          _exit(0);
+	        }
+	      else
+	        my_syslog(LOG_WARNING, _("warning: TFTP directory '%s' inaccessible"), daemon->tftp_prefix);
 	    }
 	  closedir(dir);
 	}
@@ -655,8 +660,13 @@ int main (int argc, char **argv)
 	{
 	  if (!((dir = opendir(p->prefix))))
 	   {
-	     send_event(err_pipe[1], EVENT_TFTP_ERR, errno, p->prefix);
-	     _exit(0);
+	      if (! option_bool(OPT_TFTP_NO_FAIL))
+	        {
+	          send_event(err_pipe[1], EVENT_TFTP_ERR, errno, p->prefix);
+	          _exit(0);
+	        }
+	      else
+	        my_syslog(LOG_WARNING, _("warning: TFTP directory '%s' inaccessible"), p->prefix);
 	   } 
 	  closedir(dir);
 	}
diff --git a/src/dnsmasq.h b/src/dnsmasq.h
index de95d0e..80fcf32 100644
--- a/src/dnsmasq.h
+++ b/src/dnsmasq.h
@@ -240,7 +240,8 @@ struct event_desc {
 #define OPT_LOCAL_SERVICE  49
 #define OPT_LOOP_DETECT    50
 #define OPT_EXTRALOG       51
-#define OPT_LAST           52
+#define OPT_TFTP_NO_FAIL   52
+#define OPT_LAST           53
 
 /* extra flags for my_syslog, we use a couple of facilities since they are known 
    not to occupy the same bits as priorities, no matter how syslog.h is set up. */
diff --git a/src/option.c b/src/option.c
index 3009eb5..f91cfbb 100644
--- a/src/option.c
+++ b/src/option.c
@@ -153,6 +153,7 @@ struct myoption {
 #define LOPT_DHOPT_INOTIFY 341
 #define LOPT_HOST_INOTIFY  342
 #define LOPT_DNSSEC_STAMP  343
+#define LOPT_TFTP_NO_FAIL  344
 
 #ifdef HAVE_GETOPT_LONG
 static const struct option opts[] =  
@@ -235,6 +236,7 @@ static const struct myoption opts[] =
     { "dhcp-ignore-names", 2, 0, LOPT_NO_NAMES },
     { "enable-tftp", 2, 0, LOPT_TFTP },
     { "tftp-secure", 0, 0, LOPT_SECURE },
+    { "tftp-no-fail", 0, 0, LOPT_TFTP_NO_FAIL },
     { "tftp-unique-root", 0, 0, LOPT_APREF },
     { "tftp-root", 1, 0, LOPT_PREFIX },
     { "tftp-max", 1, 0, LOPT_TFTP_MAX },
@@ -419,6 +421,7 @@ static struct {
   { LOPT_PREFIX, ARG_DUP, "<dir>[,<iface>]", gettext_noop("Export files by TFTP only from the specified subtree."), NULL },
   { LOPT_APREF, OPT_TFTP_APREF, NULL, gettext_noop("Add client IP address to tftp-root."), NULL },
   { LOPT_SECURE, OPT_TFTP_SECURE, NULL, gettext_noop("Allow access only to files owned by the user running dnsmasq."), NULL },
+  { LOPT_TFTP_NO_FAIL, OPT_TFTP_NO_FAIL, NULL, gettext_noop("Do not terminate the service if TFTP directories are inaccessible."), NULL },
   { LOPT_TFTP_MAX, ARG_ONE, "<integer>", gettext_noop("Maximum number of conncurrent TFTP transfers (defaults to %s)."), "#" },
   { LOPT_NOBLOCK, OPT_TFTP_NOBLOCK, NULL, gettext_noop("Disable the TFTP blocksize extension."), NULL },
   { LOPT_TFTP_LC, OPT_TFTP_LC, NULL, gettext_noop("Convert TFTP filenames to lowercase"), NULL },
-- 
2.1.4



More information about the Dnsmasq-discuss mailing list