1 From bec366b4041df72b559e713f1c924177676e6eb0 Mon Sep 17 00:00:00 2001
2 From: Simon Kelley <simon@thekelleys.org.uk>
3 Date: Wed, 24 Feb 2016 22:03:26 +0000
4 Subject: [PATCH] Add --tftp-mtu option.
10 src/option.c | 10 +++++++++-
11 src/tftp.c | 14 ++++++++++++--
12 5 files changed, 30 insertions(+), 4 deletions(-)
14 diff --git a/CHANGELOG b/CHANGELOG
15 index 6d9ba49..9218b8c 100644
18 @@ -53,6 +53,10 @@ version 2.76
20 Add --dhcp-ttl option.
22 + Add --tftp-mtu option. Thanks to Patrick McLean for the
27 Fix reversion on 2.74 which caused 100% CPU use when a
28 dhcp-script is configured. Thanks to Adrian Davey for
29 diff --git a/man/dnsmasq.8 b/man/dnsmasq.8
30 index 2bcce20..3cf48cd 100644
33 @@ -1810,6 +1810,10 @@ require about (2*n) + 10 descriptors. If
35 is given, that can affect the number of concurrent connections.
37 +.B --tftp-mtu=<mtu size>
38 +Use size as the ceiling of the MTU supported by the intervening network when
39 +negotiating TFTP blocksize, overriding the MTU setting of the local interface if it is larger.
41 .B --tftp-no-blocksize
42 Stop the TFTP server from negotiating the "blocksize" option with a
43 client. Some buggy clients request this option but then behave badly
44 diff --git a/src/dnsmasq.h b/src/dnsmasq.h
45 index 9f73c3b..280ad9d 100644
48 @@ -975,7 +975,7 @@ extern struct daemon {
49 struct dhcp_netid_list *dhcp_ignore, *dhcp_ignore_names, *dhcp_gen_names;
50 struct dhcp_netid_list *force_broadcast, *bootp_dynamic;
51 struct hostsfile *dhcp_hosts_file, *dhcp_opts_file, *dynamic_dirs;
52 - int dhcp_max, tftp_max;
53 + int dhcp_max, tftp_max, tftp_mtu;
54 int dhcp_server_port, dhcp_client_port;
55 int start_tftp_port, end_tftp_port;
56 unsigned int min_leasetime;
57 diff --git a/src/option.c b/src/option.c
58 index 3f6d162..765965f 100644
61 @@ -158,7 +158,8 @@ struct myoption {
62 #define LOPT_CPE_ID 346
63 #define LOPT_SCRIPT_ARP 347
64 #define LOPT_DHCPTTL 348
66 +#define LOPT_TFTP_MTU 349
68 #ifdef HAVE_GETOPT_LONG
69 static const struct option opts[] =
71 @@ -244,6 +245,7 @@ static const struct myoption opts[] =
72 { "tftp-unique-root", 0, 0, LOPT_APREF },
73 { "tftp-root", 1, 0, LOPT_PREFIX },
74 { "tftp-max", 1, 0, LOPT_TFTP_MAX },
75 + { "tftp-mtu", 1, 0, LOPT_TFTP_MTU },
76 { "tftp-lowercase", 0, 0, LOPT_TFTP_LC },
77 { "ptr-record", 1, 0, LOPT_PTR },
78 { "naptr-record", 1, 0, LOPT_NAPTR },
79 @@ -432,6 +434,7 @@ static struct {
80 { LOPT_SECURE, OPT_TFTP_SECURE, NULL, gettext_noop("Allow access only to files owned by the user running dnsmasq."), NULL },
81 { LOPT_TFTP_NO_FAIL, OPT_TFTP_NO_FAIL, NULL, gettext_noop("Do not terminate the service if TFTP directories are inaccessible."), NULL },
82 { LOPT_TFTP_MAX, ARG_ONE, "<integer>", gettext_noop("Maximum number of conncurrent TFTP transfers (defaults to %s)."), "#" },
83 + { LOPT_TFTP_MTU, ARG_ONE, "<integer>", gettext_noop("Maximum MTU to use for TFTP transfers."), NULL },
84 { LOPT_NOBLOCK, OPT_TFTP_NOBLOCK, NULL, gettext_noop("Disable the TFTP blocksize extension."), NULL },
85 { LOPT_TFTP_LC, OPT_TFTP_LC, NULL, gettext_noop("Convert TFTP filenames to lowercase"), NULL },
86 { LOPT_TFTPPORTS, ARG_ONE, "<start>,<end>", gettext_noop("Ephemeral port range for use by TFTP transfers."), NULL },
87 @@ -2625,6 +2628,11 @@ static int one_opt(int option, char *arg, char *errstr, char *gen_err, int comma
91 + case LOPT_TFTP_MTU: /* --tftp-mtu */
92 + if (!atoi_check(arg, &daemon->tftp_mtu))
96 case LOPT_PREFIX: /* --tftp-prefix */
99 diff --git a/src/tftp.c b/src/tftp.c
100 index 00ed2fc..dc4aa85 100644
103 @@ -103,8 +103,10 @@ void tftp_request(struct listener *listen, time_t now)
106 addr = listen->iface->addr;
107 - mtu = listen->iface->mtu;
108 name = listen->iface->name;
109 + mtu = listen->iface->mtu;
110 + if (daemon->tftp_mtu != 0 && daemon->tftp_mtu < mtu)
111 + mtu = daemon->tftp_mtu;
115 @@ -234,9 +236,17 @@ void tftp_request(struct listener *listen, time_t now)
117 strncpy(ifr.ifr_name, name, IF_NAMESIZE);
118 if (ioctl(listen->tftpfd, SIOCGIFMTU, &ifr) != -1)
122 + if (daemon->tftp_mtu != 0 && daemon->tftp_mtu < mtu)
123 + mtu = daemon->tftp_mtu;
127 + /* Failed to get interface mtu - can use configured value. */
129 + mtu = daemon->tftp_mtu;
133 /* check for per-interface prefix */