]> TLD Linux GIT Repositories - packages/grub2.git/blob - grub2-tftp_fixes.patch
3846463a077b366f412b168cee934786c3227cc3
[packages/grub2.git] / grub2-tftp_fixes.patch
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.
6
7 (cherry picked from commit a706f4cc6bddd03e67a66620101209c471177b53)
8 ---
9  grub-core/net/tftp.c | 4 ++--
10  1 file changed, 2 insertions(+), 2 deletions(-)
11
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)
17  
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);
22  
23    err = grub_net_send_udp_packet (data->sock, &nb_ack);
24    if (err)
25 @@ -225,7 +225,7 @@ tftp_receive (grub_net_udp_socket_t sock __attribute__ ((unused)),
26             grub_priority_queue_pop (data->pq);
27  
28             if (file->device->net->packs.count < 50)
29 -             err = ack (data, tftph->u.data.block);
30 +             err = ack (data, data->block + 1);
31             else
32               {
33                 file->device->net->stall = 1;
34 -- 
35 1.8.2
36
37
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
42  closing the socket.
43
44 (cherry picked from commit 369508b3cb0a84c0118ee32adef923109ad187dc)
45 ---
46  grub-core/net/tftp.c | 2 ++
47  1 file changed, 2 insertions(+)
48
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)),
54             data->block++;
55             if (size < data->block_size)
56               {
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);
62 -- 
63 1.8.2
64
65
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.
71
72 (cherry picked from commit cf8d6bbd9eb2f5c6cbb0b6e437466c77fc7b6e9b)
73 ---
74  grub-core/net/tftp.c | 26 +++++++++++++++++---------
75  1 file changed, 17 insertions(+), 9 deletions(-)
76
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;
83    grub_uint64_t block;
84    grub_uint32_t block_size;
85 -  grub_uint32_t ack_sent;
86 +  grub_uint64_t ack_sent;
87    int have_oack;
88    struct grub_error_saved save_err;
89    grub_net_udp_socket_t sock;
90 @@ -110,6 +110,17 @@ typedef struct tftp_data
91  } *tftp_data_t;
92  
93  static int
94 +cmp_block (grub_uint16_t a, grub_uint16_t b)
95 +{
96 +  grub_int16_t i = (grub_int16_t) (a - b);
97 +  if (i > 0)
98 +    return +1;
99 +  if (i < 0)
100 +    return -1;
101 +  return 0;
102 +}
103 +
104 +static int
105  cmp (const void *a__, const void *b__)
106  {
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))
113 -    return +1;
114 -  if (grub_be_to_cpu16 (a->u.data.block) > grub_be_to_cpu16 (b->u.data.block))
115 -    return -1;
116 -  return 0;
117 +  return -cmp_block (grub_be_to_cpu16 (a->u.data.block), grub_be_to_cpu16 (b->u.data.block));
118  }
119  
120  static grub_err_t
121 -ack (tftp_data_t data, grub_uint16_t block)
122 +ack (tftp_data_t data, grub_uint64_t block)
123  {
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;
128             nb_top = *nb_top_p;
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)
132               break;
133 +           ack (data, grub_be_to_cpu16 (tftph->u.data.block));
134             grub_netbuff_free (nb_top);
135             grub_priority_queue_pop (data->pq);
136           }
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)
139           {
140             unsigned size;
141  
142 -- 
143 1.8.2
144