]> git.ipfire.org Git - ipfire-2.x.git/blob - src/patches/dnsmasq/004-Add_--tftp-mtu_option.patch
Merge remote-tracking branch 'origin/master' into next
[ipfire-2.x.git] / src / patches / dnsmasq / 004-Add_--tftp-mtu_option.patch
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.
5
6 ---
7 CHANGELOG | 4 ++++
8 man/dnsmasq.8 | 4 ++++
9 src/dnsmasq.h | 2 +-
10 src/option.c | 10 +++++++++-
11 src/tftp.c | 14 ++++++++++++--
12 5 files changed, 30 insertions(+), 4 deletions(-)
13
14 diff --git a/CHANGELOG b/CHANGELOG
15 index 6d9ba49..9218b8c 100644
16 --- a/CHANGELOG
17 +++ b/CHANGELOG
18 @@ -53,6 +53,10 @@ version 2.76
19
20 Add --dhcp-ttl option.
21
22 + Add --tftp-mtu option. Thanks to Patrick McLean for the
23 + initial patch.
24 +
25 +
26 version 2.75
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
31 --- a/man/dnsmasq.8
32 +++ b/man/dnsmasq.8
33 @@ -1810,6 +1810,10 @@ require about (2*n) + 10 descriptors. If
34 .B --tftp-port-range
35 is given, that can affect the number of concurrent connections.
36 .TP
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.
40 +.TP
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
46 --- a/src/dnsmasq.h
47 +++ b/src/dnsmasq.h
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
59 --- a/src/option.c
60 +++ b/src/option.c
61 @@ -158,7 +158,8 @@ struct myoption {
62 #define LOPT_CPE_ID 346
63 #define LOPT_SCRIPT_ARP 347
64 #define LOPT_DHCPTTL 348
65 -
66 +#define LOPT_TFTP_MTU 349
67 +
68 #ifdef HAVE_GETOPT_LONG
69 static const struct option opts[] =
70 #else
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
88 ret_err(gen_err);
89 break;
90
91 + case LOPT_TFTP_MTU: /* --tftp-mtu */
92 + if (!atoi_check(arg, &daemon->tftp_mtu))
93 + ret_err(gen_err);
94 + break;
95 +
96 case LOPT_PREFIX: /* --tftp-prefix */
97 comma = split(arg);
98 if (comma)
99 diff --git a/src/tftp.c b/src/tftp.c
100 index 00ed2fc..dc4aa85 100644
101 --- a/src/tftp.c
102 +++ b/src/tftp.c
103 @@ -103,8 +103,10 @@ void tftp_request(struct listener *listen, time_t now)
104 if (listen->iface)
105 {
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;
112 }
113 else
114 {
115 @@ -234,9 +236,17 @@ void tftp_request(struct listener *listen, time_t now)
116
117 strncpy(ifr.ifr_name, name, IF_NAMESIZE);
118 if (ioctl(listen->tftpfd, SIOCGIFMTU, &ifr) != -1)
119 - mtu = ifr.ifr_mtu;
120 + {
121 + mtu = ifr.ifr_mtu;
122 + if (daemon->tftp_mtu != 0 && daemon->tftp_mtu < mtu)
123 + mtu = daemon->tftp_mtu;
124 + }
125 }
126
127 + /* Failed to get interface mtu - can use configured value. */
128 + if (mtu == 0)
129 + mtu = daemon->tftp_mtu;
130 +
131 if (name)
132 {
133 /* check for per-interface prefix */
134 --
135 1.7.10.4
136