Compare commits

...
Author SHA1 Message Date
Simon Kelley 90b248582c Remove compiler warnings for obscure combinations of build options. 2025-05-24 15:09:53 +01:00
Simon Kelley ebef27f321 Add TFTP options windowsize (RFC 7440) and timeout (RFC 2349). 2025-05-24 14:41:40 +01:00
Matthias Andree 1861a881eb Only define variable "a" if we HAVE_LINUX_NETWORK
Variable unsigned char a is defined unconditionally,
but it is only used if HAVE_LINUX_NETWORK is defined.
This triggers compiler warnings on, say, FreeBSD.

Fix by wrapping the definition in proper #ifdef.
2025-05-21 19:48:39 +01:00
Matthias Andree 96bdb42d40 Fix GCC's -Wunterminated-string-initialization warning in edns0.c.
GCC complains that writing the five-character "ODNS\0" string into
a four-element char magic[4] array truncates the NUL character.
The warning's rationale is that this is incompatible with C++, or
maybe non-intentional.

GCC 8 has added a nonstring variable attribute, clang 20.1 does
not yet support this, but clang's Git head does.

Add an ATTRIBUTE_NONSTRING macro, currently only defined on GCC >= 8
as __attribute__ ((nonstring)).  This successfully suppresses
the warning on Fedora Linux 42's default compiler.

The alternative would be to replace the "ODNS" literal by {0} and
instead memcpy(opt.magic, "ODNS", sizeof(opt.magic)); on the next line,
which is correct, C++ compatible, but also less concise.
2025-05-21 15:06:27 +01:00
Simon Kelley c7a909ad65 Add RRtypes HHIT and BRID to the table. 2025-05-21 15:03:51 +01:00
10 changed files with 193 additions and 74 deletions

No files matched your search

+2
View File
@@ -59,6 +59,8 @@ version 2.92
Fix failure to cache PTR RRs when a reply contains more than one answer. Fix failure to cache PTR RRs when a reply contains more than one answer.
Thanks to Dmitry for spotting this. Thanks to Dmitry for spotting this.
Add TFTP options windowsize (RFC 7440) and timeout (RFC 2349).
version 2.91 version 2.91
Fix spurious "resource limit exceeded messages". Thanks to Fix spurious "resource limit exceeded messages". Thanks to
+2
View File
@@ -102,6 +102,8 @@ static const struct {
{ 64, "SVCB" }, /* Service Binding [draft-ietf-dnsop-svcb-https-00] SVCB/svcb-completed-template 2020-06-30*/ { 64, "SVCB" }, /* Service Binding [draft-ietf-dnsop-svcb-https-00] SVCB/svcb-completed-template 2020-06-30*/
{ 65, "HTTPS" }, /* HTTPS Binding [draft-ietf-dnsop-svcb-https-00] HTTPS/https-completed-template 2020-06-30*/ { 65, "HTTPS" }, /* HTTPS Binding [draft-ietf-dnsop-svcb-https-00] HTTPS/https-completed-template 2020-06-30*/
{ 66, "DSYNC" }, /* Endpoint discovery for delegation synchronization [draft-ietf-dnsop-generalized-notify-03] DSYNC/dsync-completed-template 2024-12-10 */ { 66, "DSYNC" }, /* Endpoint discovery for delegation synchronization [draft-ietf-dnsop-generalized-notify-03] DSYNC/dsync-completed-template 2024-12-10 */
{ 67, "HHIT" }, /* [draft-ietf-drip-registries-28] */
{ 68, "BRID" }, /* [draft-ietf-drip-registries-28] */
{ 99, "SPF" }, /* [RFC7208] */ { 99, "SPF" }, /* [RFC7208] */
{ 100, "UINFO" }, /* [IANA-Reserved] */ { 100, "UINFO" }, /* [IANA-Reserved] */
{ 101, "UID" }, /* [IANA-Reserved] */ { 101, "UID" }, /* [IANA-Reserved] */
+2
View File
@@ -52,6 +52,8 @@
#define CHUSER "nobody" #define CHUSER "nobody"
#define CHGRP "dip" #define CHGRP "dip"
#define TFTP_MAX_CONNECTIONS 50 /* max simultaneous connections */ #define TFTP_MAX_CONNECTIONS 50 /* max simultaneous connections */
#define TFTP_MAX_WINDOW 32 /* max window size to negotiate */
#define TFTP_TRANSFER_TIME 120 /* Abandon TFTP transfers after this long. Two mins. */
#define LOG_MAX 5 /* log-queue length */ #define LOG_MAX 5 /* log-queue length */
#define RANDFILE "/dev/urandom" #define RANDFILE "/dev/urandom"
#define DNSMASQ_SERVICE "uk.org.thekelleys.dnsmasq" /* Default - may be overridden by config */ #define DNSMASQ_SERVICE "uk.org.thekelleys.dnsmasq" /* Default - may be overridden by config */
+11 -2
View File
@@ -30,7 +30,9 @@ static volatile pid_t pid = 0;
static volatile int pipewrite; static volatile int pipewrite;
static void set_dns_listeners(void); static void set_dns_listeners(void);
#ifdef HAVE_TFTP
static void set_tftp_listeners(void); static void set_tftp_listeners(void);
#endif
static void check_dns_listeners(time_t now); static void check_dns_listeners(time_t now);
static void do_tcp_connection(struct listener *listener, time_t now, int slot); static void do_tcp_connection(struct listener *listener, time_t now, int slot);
static void sig_handler(int sig); static void sig_handler(int sig);
@@ -62,14 +64,16 @@ int main (int argc, char **argv)
int need_cap_net_raw = 0; int need_cap_net_raw = 0;
int need_cap_net_bind_service = 0; int need_cap_net_bind_service = 0;
int have_cap_chown = 0; int have_cap_chown = 0;
# ifdef HAVE_DHCP
char *bound_device = NULL; char *bound_device = NULL;
int did_bind = 0; int did_bind = 0;
# endif
struct server *serv; struct server *serv;
char *netlink_warn; char *netlink_warn;
#else #else
int bind_fallback = 0; int bind_fallback = 0;
#endif #endif
#if defined(HAVE_DHCP) || defined(HAVE_DHCP6) #if defined(HAVE_DHCP)
struct dhcp_context *context; struct dhcp_context *context;
struct dhcp_relay *relay; struct dhcp_relay *relay;
#endif #endif
@@ -77,6 +81,8 @@ int main (int argc, char **argv)
int tftp_prefix_missing = 0; int tftp_prefix_missing = 0;
#endif #endif
(void)netlink_warn;
#if defined(HAVE_IDN) || defined(HAVE_LIBIDN2) || defined(LOCALEDIR) #if defined(HAVE_IDN) || defined(HAVE_LIBIDN2) || defined(LOCALEDIR)
setlocale(LC_ALL, ""); setlocale(LC_ALL, "");
#endif #endif
@@ -1939,11 +1945,14 @@ static void do_tcp_connection(struct listener *listener, time_t now, int slot)
pid_t p; pid_t p;
union mysockaddr tcp_addr; union mysockaddr tcp_addr;
socklen_t tcp_len = sizeof(union mysockaddr); socklen_t tcp_len = sizeof(union mysockaddr);
unsigned char a = 0, *buff; unsigned char *buff;
struct server *s; struct server *s;
int flags, auth_dns; int flags, auth_dns;
struct in_addr netmask; struct in_addr netmask;
int pipefd[2]; int pipefd[2];
#ifdef HAVE_LINUX_NETWORK
unsigned char a = 0;
#endif
while ((confd = accept(listener->tcpfd, NULL, NULL)) == -1 && errno == EINTR); while ((confd = accept(listener->tcpfd, NULL, NULL)) == -1 && errno == EINTR);
+9 -5
View File
@@ -48,6 +48,12 @@
#define ATTRIBUTE_NORETURN #define ATTRIBUTE_NORETURN
#endif #endif
#if __GNUC__ + 0 >= 8 // clang 20.1.0 does not yet support this
#define ATTRIBUTE_NONSTRING __attribute__ ((nonstring))
#else
#define ATTRIBUTE_NONSTRING
#endif
/* get these before config.h for IPv6 stuff... */ /* get these before config.h for IPv6 stuff... */
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
@@ -1111,14 +1117,13 @@ struct tftp_file {
struct tftp_transfer { struct tftp_transfer {
int sockfd; int sockfd;
time_t timeout; time_t retransmit, start;
int backoff; unsigned int lastack, block, blocksize, windowsize, timeout, expansion;
unsigned int block, blocksize, expansion;
off_t offset; off_t offset;
union mysockaddr peer; union mysockaddr peer;
union all_addr source; union all_addr source;
int if_index; int if_index;
char opt_blocksize, opt_transize, netascii, carrylf; unsigned char opt_blocksize, opt_transize, opt_windowsize, opt_timeout, netascii, carrylf, backoff;
struct tftp_file *file; struct tftp_file *file;
struct tftp_transfer *next; struct tftp_transfer *next;
}; };
@@ -1762,7 +1767,6 @@ void queue_relay_snoop(struct in6_addr *client, int if_index, struct in6_addr *p
/* tftp.c */ /* tftp.c */
#ifdef HAVE_TFTP #ifdef HAVE_TFTP
void tftp_request(struct listener *listen, time_t now);
void check_tftp_listeners(time_t now); void check_tftp_listeners(time_t now);
int do_tftp_script_run(void); int do_tftp_script_run(void);
#endif #endif
+1 -1
View File
@@ -494,7 +494,7 @@ int check_source(struct dns_header *header, size_t plen, unsigned char *pseudohe
#define UMBRELLA_DEVICESZ sizeof(daemon->umbrella_device) #define UMBRELLA_DEVICESZ sizeof(daemon->umbrella_device)
struct umbrella_opt { struct umbrella_opt {
u8 magic[4]; u8 magic[4] ATTRIBUTE_NONSTRING;
u8 version; u8 version;
u8 flags; u8 flags;
/* We have 4 possible fields since we'll never send both IPv4 and /* We have 4 possible fields since we'll never send both IPv4 and
+2
View File
@@ -251,6 +251,8 @@ int inotify_check(time_t now)
int hit = 0; int hit = 0;
struct dyndir *dd; struct dyndir *dd;
(void)now;
while (1) while (1)
{ {
int rc; int rc;
+4
View File
@@ -1569,6 +1569,8 @@ void check_servers(int no_loop_check)
int port = 0, count; int port = 0, count;
int locals = 0; int locals = 0;
(void)no_loop_check;
#ifdef HAVE_LOOP #ifdef HAVE_LOOP
if (!no_loop_check) if (!no_loop_check)
loop_send_probes(); loop_send_probes();
@@ -1775,7 +1777,9 @@ int reload_servers(char *fname)
/* Called when addresses are added or deleted from an interface */ /* Called when addresses are added or deleted from an interface */
void newaddress(time_t now) void newaddress(time_t now)
{ {
#ifdef HAVE_DHCP
struct dhcp_relay *relay; struct dhcp_relay *relay;
#endif
(void)now; (void)now;
+155 -66
View File
@@ -41,11 +41,11 @@ static void sanitise(char *buf);
#define ERR_ILL 4 #define ERR_ILL 4
#define ERR_TID 5 #define ERR_TID 5
void tftp_request(struct listener *listen, time_t now) static void tftp_request(struct listener *listen, time_t now)
{ {
ssize_t len; ssize_t len;
char *packet = daemon->packet; char *packet = daemon->packet;
char *filename, *mode, *p, *end, *opt; char *filename, *mode, *p, *end;
union mysockaddr addr, peer; union mysockaddr addr, peer;
struct msghdr msg; struct msghdr msg;
struct iovec iov; struct iovec iov;
@@ -309,6 +309,8 @@ void tftp_request(struct listener *listen, time_t now)
if (!transfer && !(transfer = whine_malloc(sizeof(struct tftp_transfer)))) if (!transfer && !(transfer = whine_malloc(sizeof(struct tftp_transfer))))
return; return;
memset(transfer, 0, sizeof(struct tftp_transfer));
if (option_bool(OPT_SINGLE_PORT)) if (option_bool(OPT_SINGLE_PORT))
transfer->sockfd = listen->tftpfd; transfer->sockfd = listen->tftpfd;
else if ((transfer->sockfd = socket(family, SOCK_DGRAM, 0)) == -1) else if ((transfer->sockfd = socket(family, SOCK_DGRAM, 0)) == -1)
@@ -320,14 +322,12 @@ void tftp_request(struct listener *listen, time_t now)
transfer->peer = peer; transfer->peer = peer;
transfer->source = addra; transfer->source = addra;
transfer->if_index = if_index; transfer->if_index = if_index;
transfer->timeout = now + 2; transfer->timeout = 2;
transfer->start = now;
transfer->backoff = 1; transfer->backoff = 1;
transfer->block = 1; transfer->block = 1;
transfer->blocksize = 512; transfer->blocksize = 512;
transfer->offset = 0; transfer->windowsize = 1;
transfer->file = NULL;
transfer->opt_blocksize = transfer->opt_transize = 0;
transfer->netascii = transfer->carrylf = 0;
(void)prettyprint_addr(&peer, daemon->addrbuff); (void)prettyprint_addr(&peer, daemon->addrbuff);
@@ -362,47 +362,65 @@ void tftp_request(struct listener *listen, time_t now)
p = packet + 2; p = packet + 2;
end = packet + len; end = packet + len;
if (!(filename = next(&p, end)) || len = 0;
!(mode = next(&p, end)) ||
(strcasecmp(mode, "octet") != 0 && strcasecmp(mode, "netascii") != 0) || if (ntohs(*((unsigned short *)packet)) == OP_WRQ)
ntohs(*((unsigned short *)packet)) != OP_RRQ) len = tftp_err(ERR_ILL, packet, _("unsupported write request from %s"),daemon->addrbuff, NULL);
else if (ntohs(*((unsigned short *)packet)) == OP_RRQ)
{ {
if (!filename) if (!(filename = next(&p, end)))
len = tftp_err(ERR_ILL, packet, _("empty filename in request from %s"), daemon->addrbuff, NULL); len = tftp_err(ERR_ILL, packet, _("empty filename in request from %s"), daemon->addrbuff, NULL);
else else if (!(mode = next(&p, end)) || (strcasecmp(mode, "octet") != 0 && strcasecmp(mode, "netascii") != 0))
len = tftp_err(ERR_ILL, packet, _("unsupported %srequest from %s"), len = tftp_err(ERR_ILL, packet, _("unsupported request from %s"),daemon->addrbuff, NULL);
(ntohs(*((unsigned short *)packet)) == OP_WRQ) ? _("write ") : "", daemon->addrbuff);
is_err = 1;
}
else else
{ {
char *opt, *arg;
if (strcasecmp(mode, "netascii") == 0) if (strcasecmp(mode, "netascii") == 0)
transfer->netascii = 1; transfer->netascii = 1;
while ((opt = next(&p, end))) while ((opt = next(&p, end)) && (arg = next(&p, end)))
{ {
if (strcasecmp(opt, "blksize") == 0) unsigned int val = atoi(arg);
{
if ((opt = next(&p, end)) && !option_bool(OPT_TFTP_NOBLOCK)) if (strcasecmp(opt, "blksize") == 0 && !option_bool(OPT_TFTP_NOBLOCK))
{ {
/* 32 bytes for IP, UDP and TFTP headers, 52 bytes for IPv6 */ /* 32 bytes for IP, UDP and TFTP headers, 52 bytes for IPv6 */
int overhead = (family == AF_INET) ? 32 : 52; int overhead = (family == AF_INET) ? 32 : 52;
transfer->blocksize = atoi(opt); if (val < 1)
if (transfer->blocksize < 1) val = 1;
transfer->blocksize = 1; if (val > (unsigned)daemon->packet_buff_sz - 4)
if (transfer->blocksize > (unsigned)daemon->packet_buff_sz - 4) val = (unsigned)daemon->packet_buff_sz - 4;
transfer->blocksize = (unsigned)daemon->packet_buff_sz - 4; if (mtu != 0 && val > (unsigned)mtu - overhead)
if (mtu != 0 && transfer->blocksize > (unsigned)mtu - overhead) val = (unsigned)mtu - overhead;
transfer->blocksize = (unsigned)mtu - overhead; transfer->blocksize = val;
transfer->opt_blocksize = 1; transfer->opt_blocksize = 1;
transfer->block = 0; transfer->block = 0;
} }
} else if (strcasecmp(opt, "tsize") == 0 && !transfer->netascii)
else if (strcasecmp(opt, "tsize") == 0 && next(&p, end) && !transfer->netascii)
{ {
transfer->opt_transize = 1; transfer->opt_transize = 1;
transfer->block = 0; transfer->block = 0;
} }
else if (strcasecmp(opt, "timeout") == 0)
{
if (val > 255)
val = 255;
transfer->timeout = val;
transfer->opt_timeout = 1;
transfer->block = 0;
}
else if (strcasecmp(opt, "windowsize") == 0 && !transfer->netascii)
{
/* windowsize option only supported for binary transfers. */
if (val < 1)
val = 1;
if (val > TFTP_MAX_WINDOW)
val = TFTP_MAX_WINDOW;
transfer->windowsize = val;
transfer->opt_windowsize = 1;
transfer->block = 0;
}
} }
/* cope with backslashes from windows boxen. */ /* cope with backslashes from windows boxen. */
@@ -483,18 +501,27 @@ void tftp_request(struct listener *listen, time_t now)
/* check permissions and open file */ /* check permissions and open file */
if ((transfer->file = check_tftp_fileperm(&len, prefix, daemon->addrbuff))) if ((transfer->file = check_tftp_fileperm(&len, prefix, daemon->addrbuff)))
{ {
transfer->lastack = transfer->block;
transfer->retransmit = now + transfer->timeout;
/* This packet is may be the first data packet, but only if windowsize == 1
To get windowsize greater then one requires an option negotiation,
in which case this packet is the OACK. */
if ((len = get_block(packet, transfer)) == -1) if ((len = get_block(packet, transfer)) == -1)
len = tftp_err_oops(packet, daemon->namebuff); len = tftp_err_oops(packet, daemon->namebuff);
else else
is_err = 0; is_err = 0;
} }
} }
}
if (len)
{
send_from(transfer->sockfd, !option_bool(OPT_SINGLE_PORT), packet, len, &peer, &addra, if_index); send_from(transfer->sockfd, !option_bool(OPT_SINGLE_PORT), packet, len, &peer, &addra, if_index);
#ifdef HAVE_DUMPFILE #ifdef HAVE_DUMPFILE
dump_packet_udp(DUMP_TFTP, (void *)packet, len, NULL, (union mysockaddr *)&peer, transfer->sockfd); dump_packet_udp(DUMP_TFTP, (void *)packet, len, NULL, (union mysockaddr *)&peer, transfer->sockfd);
#endif #endif
}
if (is_err) if (is_err)
free_transfer(transfer); free_transfer(transfer);
@@ -610,6 +637,10 @@ void check_tftp_listeners(time_t now)
if ((len = recvfrom(transfer->sockfd, daemon->packet, daemon->packet_buff_sz, 0, &peer.sa, &addr_len)) > 0) if ((len = recvfrom(transfer->sockfd, daemon->packet, daemon->packet_buff_sz, 0, &peer.sa, &addr_len)) > 0)
{ {
#ifdef HAVE_DUMPFILE
dump_packet_udp(DUMP_TFTP, (void *)daemon->packet, len, (union mysockaddr *)&peer, NULL, transfer->sockfd);
#endif
if (sockaddr_isequal(&peer, &transfer->peer)) if (sockaddr_isequal(&peer, &transfer->peer))
handle_tftp(now, transfer, len); handle_tftp(now, transfer, len);
else else
@@ -628,51 +659,81 @@ void check_tftp_listeners(time_t now)
for (transfer = daemon->tftp_trans, up = &daemon->tftp_trans; transfer; transfer = tmp) for (transfer = daemon->tftp_trans, up = &daemon->tftp_trans; transfer; transfer = tmp)
{ {
int endcon = 0, error = 0, timeout = 0;
tmp = transfer->next; tmp = transfer->next;
if (difftime(now, transfer->timeout) >= 0.0) /* ->start set to zero in handle_tftp() when we recv an error packet. */
if (transfer->start == 0)
endcon = error = 1;
else if (difftime(now, transfer->start) > TFTP_TRANSFER_TIME)
{ {
int endcon = 0; endcon = 1;
/* don't complain about timeout when we're awaiting the last
ACK, some clients never send it */
if (get_block(daemon->packet, transfer) > 0)
error = timeout = 1;
}
else if (difftime(now, transfer->retransmit) >= 0.0)
{
/* Do transmission or re-transmission. When we get an ACK, the call to handle_tftp()
bumps transfer->lastack and trips the retransmit timer so that we send the next block(s)
here. */
unsigned int i, winsize;
ssize_t len; ssize_t len;
/* timeout, retransmit */ transfer->retransmit += transfer->timeout + (1<<(transfer->backoff/2));
transfer->timeout += 1 + (1<<(transfer->backoff/2)); transfer->backoff++;
transfer->block = transfer->lastack;
if ((len = get_block(daemon->packet, transfer)) == 0)
endcon = 1; /* got last ACK */
else
{
/* send a window'a worth of blocks unless we're retransmitting OACK */
winsize = transfer->block ? transfer->windowsize : 1;
/* we overwrote the buffer... */ /* we overwrote the buffer... */
daemon->srv_save = NULL; daemon->srv_save = NULL;
if ((len = get_block(daemon->packet, transfer)) == -1) for (i = 0; i < winsize && !endcon; i++, transfer->block++)
{
if (i != 0)
len = get_block(daemon->packet, transfer);
if (len == 0)
break;
if (len == -1)
{ {
len = tftp_err_oops(daemon->packet, transfer->file->filename); len = tftp_err_oops(daemon->packet, transfer->file->filename);
endcon = 1; endcon = error = 1;
}
else if (++transfer->backoff > 7)
{
/* don't complain about timeout when we're awaiting the last
ACK, some clients never send it */
if ((unsigned)len == transfer->blocksize + 4)
endcon = 1;
len = 0;
} }
if (len != 0)
{
send_from(transfer->sockfd, !option_bool(OPT_SINGLE_PORT), daemon->packet, len, send_from(transfer->sockfd, !option_bool(OPT_SINGLE_PORT), daemon->packet, len,
&transfer->peer, &transfer->source, transfer->if_index); &transfer->peer, &transfer->source, transfer->if_index);
#ifdef HAVE_DUMPFILE #ifdef HAVE_DUMPFILE
dump_packet_udp(DUMP_TFTP, (void *)daemon->packet, len, NULL, (union mysockaddr *)&transfer->peer, transfer->sockfd); dump_packet_udp(DUMP_TFTP, (void *)daemon->packet, len, NULL, (union mysockaddr *)&transfer->peer, transfer->sockfd);
#endif #endif
} }
}
}
if (endcon || len == 0) if (endcon)
{ {
strcpy(daemon->namebuff, transfer->file->filename); strcpy(daemon->namebuff, transfer->file->filename);
sanitise(daemon->namebuff); sanitise(daemon->namebuff);
(void)prettyprint_addr(&transfer->peer, daemon->addrbuff); (void)prettyprint_addr(&transfer->peer, daemon->addrbuff);
my_syslog(MS_TFTP | LOG_INFO, endcon ? _("failed sending %s to %s") : _("sent %s to %s"), daemon->namebuff, daemon->addrbuff); if (timeout)
my_syslog(MS_TFTP | LOG_ERR, _("timeout sending %s to %s"), daemon->namebuff, daemon->addrbuff);
else if (error)
my_syslog(MS_TFTP | LOG_ERR, _("failed sending %s to %s"), daemon->namebuff, daemon->addrbuff);
else
my_syslog(MS_TFTP | LOG_INFO, _("sent %s to %s"), daemon->namebuff, daemon->addrbuff);
/* unlink */ /* unlink */
*up = tmp; *up = tmp;
if (endcon) if (error)
free_transfer(transfer); free_transfer(transfer);
else else
{ {
@@ -680,10 +741,8 @@ void check_tftp_listeners(time_t now)
transfer->next = daemon->tftp_done_trans; transfer->next = daemon->tftp_done_trans;
daemon->tftp_done_trans = transfer; daemon->tftp_done_trans = transfer;
} }
continue;
} }
} else
up = &transfer->next; up = &transfer->next;
} }
} }
@@ -697,14 +756,31 @@ static void handle_tftp(time_t now, struct tftp_transfer *transfer, ssize_t len)
if (len >= (ssize_t)sizeof(struct ack)) if (len >= (ssize_t)sizeof(struct ack))
{ {
if (ntohs(mess->op) == OP_ACK && ntohs(mess->block) == (unsigned short)transfer->block) if (ntohs(mess->op) == OP_ACK)
{ {
/* Got ack, ensure we take the (re)transmit path */ /* try and handle 16-bit blockno wrap-around */
transfer->timeout = now; unsigned int block = (unsigned short)ntohs(mess->block);
if (block < transfer->lastack)
block |= transfer->block & 0xffff0000;
/* ignore duplicate ACKs and ACKs for blocks we've not yet sent. */
if (block >= transfer->lastack &&
block <= transfer->block)
{
/* Got ack, move forward and ensure we take the (re)transmit path */
transfer->retransmit = transfer->start = now;
transfer->backoff = 0; transfer->backoff = 0;
if (transfer->block++ != 0) transfer->lastack = block + 1;
/* We have no easy function from block no. to file offset when
expanding line breaks in netascii mode, so we update the offset here
as each block is acknowledged. This explains why the window size must be
one for a netascii transfer; to avoid the block no. doing anything
other than incrementing by one. */
if (transfer->netascii && block != 0)
transfer->offset += transfer->blocksize - transfer->expansion; transfer->offset += transfer->blocksize - transfer->expansion;
} }
}
else if (ntohs(mess->op) == OP_ERR) else if (ntohs(mess->op) == OP_ERR)
{ {
char *p = daemon->packet + sizeof(struct ack); char *p = daemon->packet + sizeof(struct ack);
@@ -724,8 +800,7 @@ static void handle_tftp(time_t now, struct tftp_transfer *transfer, ssize_t len)
daemon->addrbuff); daemon->addrbuff);
/* Got err, ensure we take abort */ /* Got err, ensure we take abort */
transfer->timeout = now; transfer->start = 0;
transfer->backoff = 100;
} }
} }
} }
@@ -835,6 +910,16 @@ static ssize_t get_block(char *packet, struct tftp_transfer *transfer)
p += (sprintf(p,"tsize") + 1); p += (sprintf(p,"tsize") + 1);
p += (sprintf(p, "%u", (unsigned int)transfer->file->size) + 1); p += (sprintf(p, "%u", (unsigned int)transfer->file->size) + 1);
} }
if (transfer->opt_timeout)
{
p += (sprintf(p,"timeout") + 1);
p += (sprintf(p, "%u", transfer->timeout) + 1);
}
if (transfer->opt_windowsize)
{
p += (sprintf(p,"windowsize") + 1);
p += (sprintf(p, "%u", (unsigned int)transfer->windowsize) + 1);
}
return p - packet; return p - packet;
} }
@@ -846,31 +931,35 @@ static ssize_t get_block(char *packet, struct tftp_transfer *transfer)
unsigned char data[]; unsigned char data[];
} *mess = (struct datamess *)packet; } *mess = (struct datamess *)packet;
size_t size = transfer->file->size - transfer->offset; size_t size;
if (!transfer->netascii)
transfer->offset = (transfer->block - 1) * transfer->blocksize;
if (transfer->offset > transfer->file->size) if (transfer->offset > transfer->file->size)
return 0; /* finished */ return 0; /* finished */
if (size > transfer->blocksize) if ((size = transfer->file->size - transfer->offset) > transfer->blocksize)
size = transfer->blocksize; size = transfer->blocksize;
mess->op = htons(OP_DATA); mess->op = htons(OP_DATA);
mess->block = htons((unsigned short)(transfer->block)); mess->block = htons((unsigned short)(transfer->block));
if (lseek(transfer->file->fd, transfer->offset, SEEK_SET) == (off_t)-1 || if (size != 0 &&
!read_write(transfer->file->fd, mess->data, size, RW_READ)) (lseek(transfer->file->fd, transfer->offset, SEEK_SET) == (off_t)-1 ||
!read_write(transfer->file->fd, mess->data, size, RW_READ)))
return -1; return -1;
transfer->expansion = 0;
/* Map '\n' to CR-LF in netascii mode */ /* Map '\n' to CR-LF in netascii mode */
if (transfer->netascii) if (transfer->netascii)
{ {
size_t i; size_t i;
int newcarrylf; int newcarrylf;
transfer->expansion = 0;
for (i = 0, newcarrylf = 0; i < size; i++) for (i = 0, newcarrylf = 0; i < size; i++)
if (mess->data[i] == '\n' && ( i != 0 || !transfer->carrylf)) if (mess->data[i] == '\n' && (i != 0 || !transfer->carrylf))
{ {
transfer->expansion++; transfer->expansion++;
@@ -885,8 +974,8 @@ static ssize_t get_block(char *packet, struct tftp_transfer *transfer)
i++; i++;
} }
transfer->carrylf = newcarrylf;
transfer->carrylf = newcarrylf;
} }
return size + 4; return size + 4;
+5
View File
@@ -214,6 +214,11 @@ static int ubus_handle_set_connmark_allowlist(struct ubus_context *ctx, struct u
struct blob_attr *tb[policy_len]; struct blob_attr *tb[policy_len];
struct blob_attr *attr; struct blob_attr *attr;
(void)ctx;
(void)obj;
(void)req;
(void)method;
if (blobmsg_parse(policy, policy_len, tb, blob_data(msg), blob_len(msg))) if (blobmsg_parse(policy, policy_len, tb, blob_data(msg), blob_len(msg)))
return UBUS_STATUS_INVALID_ARGUMENT; return UBUS_STATUS_INVALID_ARGUMENT;