[OpenWrt-Devel] [PATCH] [dnsmasq] add --tftp-no-fail to ignore missing tftp root

Stefan Tomanek stefan.tomanek+openwrt at wertarbyte.de
Mon Mar 30 17:59:00 EDT 2015


This patch introduces the option --tftp-no-fail to dnsmasq and prevents the
service from aborting if the specified TFTP root directory is not available;
this might be the case if TFTP files are located on external media that might
occasionally not be present at startup.

Signed-off-by: Stefan Tomanek <stefan.tomanek+openwrt at wertarbyte.de>
---
 .../network/services/dnsmasq/files/dnsmasq.init    |    1 +
 ...-tftp-no-fail-to-ignore-missing-tftp-root.patch |  103 ++++++++++++++++++++
 2 files changed, 104 insertions(+), 0 deletions(-)
 create mode 100644 package/network/services/dnsmasq/patches/120-add-tftp-no-fail-to-ignore-missing-tftp-root.patch

diff --git a/package/network/services/dnsmasq/files/dnsmasq.init b/package/network/services/dnsmasq/files/dnsmasq.init
index 2e7fb7b..9795d1a 100644
--- a/package/network/services/dnsmasq/files/dnsmasq.init
+++ b/package/network/services/dnsmasq/files/dnsmasq.init
@@ -128,6 +128,7 @@ dnsmasq() {
 	append_bool "$cfg" boguspriv "--bogus-priv"
 	append_bool "$cfg" expandhosts "--expand-hosts"
 	append_bool "$cfg" enable_tftp "--enable-tftp"
+	append_bool "$cfg" tftp_no_fail "--tftp-no-fail"
 	append_bool "$cfg" nonwildcard "--bind-interfaces"
 	append_bool "$cfg" fqdn "--dhcp-fqdn"
 	append_bool "$cfg" proxydnssec "--proxy-dnssec"
diff --git a/package/network/services/dnsmasq/patches/120-add-tftp-no-fail-to-ignore-missing-tftp-root.patch b/package/network/services/dnsmasq/patches/120-add-tftp-no-fail-to-ignore-missing-tftp-root.patch
new file mode 100644
index 0000000..9a2a94a
--- /dev/null
+++ b/package/network/services/dnsmasq/patches/120-add-tftp-no-fail-to-ignore-missing-tftp-root.patch
@@ -0,0 +1,103 @@
+From 859e01b56ca9aa1e3a871bfd4db1e372f1a7302d Mon Sep 17 00:00:00 2001
+From: Stefan Tomanek <stefan.tomanek at wertarbyte.de>
+Date: Mon, 30 Mar 2015 22:58:10 +0200
+Subject: [PATCH] add --tftp-no-fail to ignore missing tftp root
+
+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.
+---
+ src/dnsmasq.c | 24 ++++++++++++++++++------
+ src/dnsmasq.h |  3 ++-
+ src/option.c  |  3 +++
+ 3 files changed, 23 insertions(+), 7 deletions(-)
+
+diff --git a/src/dnsmasq.c b/src/dnsmasq.c
+index 5c7750d..71e101d 100644
+--- a/src/dnsmasq.c
++++ b/src/dnsmasq.c
+@@ -632,20 +632,32 @@ 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);
++	  else
++	    closedir(dir);
+ 	}
+ 
+       for (p = daemon->if_prefix; p; p = p->next)
+ 	{
+ 	  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);
++	  else
++	    closedir(dir);
+ 	}
+     }
+ #endif
+diff --git a/src/dnsmasq.h b/src/dnsmasq.h
+index 1dd61c5..8e0d352 100644
+--- a/src/dnsmasq.h
++++ b/src/dnsmasq.h
+@@ -238,7 +238,8 @@ struct event_desc {
+ #define OPT_DNSSEC_NO_SIGN 48 
+ #define OPT_LOCAL_SERVICE  49
+ #define OPT_LOOP_DETECT    50
+-#define OPT_LAST           51
++#define OPT_TFTP_NO_FAIL   51
++#define OPT_LAST           52
+ 
+ /* 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 209fa69..fa5e4d3 100644
+--- a/src/option.c
++++ b/src/option.c
+@@ -147,6 +147,7 @@ struct myoption {
+ #define LOPT_LOCAL_SERVICE 335
+ #define LOPT_DNSSEC_TIME   336
+ #define LOPT_LOOP_DETECT   337
++#define LOPT_TFTP_NO_FAIL  338
+ 
+ #ifdef HAVE_GETOPT_LONG
+ static const struct option opts[] =  
+@@ -227,6 +228,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 },
+@@ -402,6 +404,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
+
-- 
1.7.2.5
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel



More information about the openwrt-devel mailing list