1 From 1ff55c8030ed529b17b02993877ac4803e7aa449 Mon Sep 17 00:00:00 2001
2 From: Vladimir 'phcoder' Serbinenko <phcoder@gmail.com>
3 Date: Mon, 2 Jul 2012 11:22:50 +0200
4 Subject: [PATCH 1/3] * grub-core/net/tftp.c (ack): Fix endianness problem.
5 (tftp_receive): Likewise. Reported by: Michael Davidsaver.
7 (cherry picked from commit a706f4cc6bddd03e67a66620101209c471177b53)
9 grub-core/net/tftp.c | 4 ++--
10 1 file changed, 2 insertions(+), 2 deletions(-)
12 diff --git a/grub-core/net/tftp.c b/grub-core/net/tftp.c
13 index 9c70efb..d0f39ea 100644
14 --- a/grub-core/net/tftp.c
15 +++ b/grub-core/net/tftp.c
16 @@ -143,7 +143,7 @@ ack (tftp_data_t data, grub_uint16_t block)
18 tftph_ack = (struct tftphdr *) nb_ack.data;
19 tftph_ack->opcode = grub_cpu_to_be16 (TFTP_ACK);
20 - tftph_ack->u.ack.block = block;
21 + tftph_ack->u.ack.block = grub_cpu_to_be16 (block);
23 err = grub_net_send_udp_packet (data->sock, &nb_ack);
25 @@ -225,7 +225,7 @@ tftp_receive (grub_net_udp_socket_t sock __attribute__ ((unused)),
26 grub_priority_queue_pop (data->pq);
28 if (file->device->net->packs.count < 50)
29 - err = ack (data, tftph->u.data.block);
30 + err = ack (data, data->block + 1);
33 file->device->net->stall = 1;
38 From 412928c729fff75cf53914cd4acac88c5e229397 Mon Sep 17 00:00:00 2001
39 From: Avik Sil <aviksil@in.ibm.com>
40 Date: Wed, 14 Aug 2013 20:32:42 -0300
41 Subject: [PATCH 2/3] * grub-core/net/tftp.c: Send tftp ack packet before
44 (cherry picked from commit 369508b3cb0a84c0118ee32adef923109ad187dc)
46 grub-core/net/tftp.c | 2 ++
47 1 file changed, 2 insertions(+)
49 diff --git a/grub-core/net/tftp.c b/grub-core/net/tftp.c
50 index d0f39ea..b9d9549 100644
51 --- a/grub-core/net/tftp.c
52 +++ b/grub-core/net/tftp.c
53 @@ -243,6 +243,8 @@ tftp_receive (grub_net_udp_socket_t sock __attribute__ ((unused)),
55 if (size < data->block_size)
57 + if (data->ack_sent < data->block)
58 + ack (data, data->block);
59 file->device->net->eof = 1;
60 file->device->net->stall = 1;
61 grub_net_udp_close (data->sock);
66 From e944f5bb19bb7f07ca065df75979ba3067306ae1 Mon Sep 17 00:00:00 2001
67 From: Vladimir Serbinenko <phcoder@gmail.com>
68 Date: Sat, 26 Oct 2013 12:48:49 +0200
69 Subject: [PATCH 3/3] * grub-core/net/tftp.c: Retransmit ack when
70 rereceiving old packet. Try to handle more than 0xFFFF packets.
72 (cherry picked from commit cf8d6bbd9eb2f5c6cbb0b6e437466c77fc7b6e9b)
74 grub-core/net/tftp.c | 26 +++++++++++++++++---------
75 1 file changed, 17 insertions(+), 9 deletions(-)
77 diff --git a/grub-core/net/tftp.c b/grub-core/net/tftp.c
78 index b9d9549..97217d2 100644
79 --- a/grub-core/net/tftp.c
80 +++ b/grub-core/net/tftp.c
81 @@ -102,7 +102,7 @@ typedef struct tftp_data
82 grub_uint64_t file_size;
84 grub_uint32_t block_size;
85 - grub_uint32_t ack_sent;
86 + grub_uint64_t ack_sent;
88 struct grub_error_saved save_err;
89 grub_net_udp_socket_t sock;
90 @@ -110,6 +110,17 @@ typedef struct tftp_data
94 +cmp_block (grub_uint16_t a, grub_uint16_t b)
96 + grub_int16_t i = (grub_int16_t) (a - b);
105 cmp (const void *a__, const void *b__)
107 struct grub_net_buff *a_ = *(struct grub_net_buff **) a__;
108 @@ -117,15 +128,11 @@ cmp (const void *a__, const void *b__)
109 struct tftphdr *a = (struct tftphdr *) a_->data;
110 struct tftphdr *b = (struct tftphdr *) b_->data;
111 /* We want the first elements to be on top. */
112 - if (grub_be_to_cpu16 (a->u.data.block) < grub_be_to_cpu16 (b->u.data.block))
114 - if (grub_be_to_cpu16 (a->u.data.block) > grub_be_to_cpu16 (b->u.data.block))
117 + return -cmp_block (grub_be_to_cpu16 (a->u.data.block), grub_be_to_cpu16 (b->u.data.block));
121 -ack (tftp_data_t data, grub_uint16_t block)
122 +ack (tftp_data_t data, grub_uint64_t block)
124 struct tftphdr *tftph_ack;
125 grub_uint8_t nbdata[512];
126 @@ -213,12 +220,13 @@ tftp_receive (grub_net_udp_socket_t sock __attribute__ ((unused)),
127 return GRUB_ERR_NONE;
129 tftph = (struct tftphdr *) nb_top->data;
130 - if (grub_be_to_cpu16 (tftph->u.data.block) >= data->block + 1)
131 + if (cmp_block (grub_be_to_cpu16 (tftph->u.data.block), data->block + 1) >= 0)
133 + ack (data, grub_be_to_cpu16 (tftph->u.data.block));
134 grub_netbuff_free (nb_top);
135 grub_priority_queue_pop (data->pq);
137 - if (grub_be_to_cpu16 (tftph->u.data.block) == data->block + 1)
138 + while (cmp_block (grub_be_to_cpu16 (tftph->u.data.block), data->block + 1) == 0)