qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Hervé Poussineau" <hpoussin@reactos.org>
To: qemu-devel@nongnu.org
Cc: "Jan Kiszka" <jan.kiszka@siemens.com>,
	"Hervé Poussineau" <hpoussin@reactos.org>
Subject: [Qemu-devel] [PATCH v2 2/3] slirp: Handle more than 65535 blocks in TFTP transfers
Date: Mon, 10 Sep 2012 20:05:44 +0200	[thread overview]
Message-ID: <1347300346-14482-3-git-send-email-hpoussin@reactos.org> (raw)
In-Reply-To: <1347300346-14482-1-git-send-email-hpoussin@reactos.org>

RFC 1350 does not mention block count roll-over. However, a lot of TFTP servers
implement it to be able to transmit big files, so do it also.

Current block size is 512 bytes, so TFTP files were limited to 32 MB.

Signed-off-by: Hervé Poussineau <hpoussin@reactos.org>
Reviewed-by: Aurelien Jarno <aurelien@aurel32.net>
---
 slirp/tftp.c |    9 +++++----
 slirp/tftp.h |    1 +
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/slirp/tftp.c b/slirp/tftp.c
index 520dbd6..75c9030 100644
--- a/slirp/tftp.c
+++ b/slirp/tftp.c
@@ -97,7 +97,7 @@ static int tftp_session_find(Slirp *slirp, struct tftp_t *tp)
   return -1;
 }
 
-static int tftp_read_data(struct tftp_session *spt, uint16_t block_nr,
+static int tftp_read_data(struct tftp_session *spt, uint32_t block_nr,
                           uint8_t *buf, int len)
 {
     int bytes_read = 0;
@@ -198,7 +198,7 @@ out:
 }
 
 static int tftp_send_data(struct tftp_session *spt,
-                          uint16_t block_nr,
+                          uint32_t block_nr,
 			  struct tftp_t *recv_tp)
 {
   struct sockaddr_in saddr, daddr;
@@ -223,7 +223,7 @@ static int tftp_send_data(struct tftp_session *spt,
   m->m_data += sizeof(struct udpiphdr);
 
   tp->tp_op = htons(TFTP_DATA);
-  tp->x.tp_data.tp_block_nr = htons(block_nr);
+  tp->x.tp_data.tp_block_nr = htons(block_nr & 0xffff);
 
   saddr.sin_addr = recv_tp->ip.ip_dst;
   saddr.sin_port = recv_tp->udp.uh_dport;
@@ -255,6 +255,7 @@ static int tftp_send_data(struct tftp_session *spt,
     tftp_session_terminate(spt);
   }
 
+  spt->block_nr = block_nr;
   return 0;
 }
 
@@ -387,7 +388,7 @@ static void tftp_handle_ack(Slirp *slirp, struct tftp_t *tp, int pktlen)
   }
 
   if (tftp_send_data(&slirp->tftp_sessions[s],
-		     ntohs(tp->x.tp_data.tp_block_nr) + 1,
+		     slirp->tftp_sessions[s].block_nr + 1,
 		     tp) < 0) {
     return;
   }
diff --git a/slirp/tftp.h b/slirp/tftp.h
index 9c364ea..51704e4 100644
--- a/slirp/tftp.h
+++ b/slirp/tftp.h
@@ -37,6 +37,7 @@ struct tftp_session {
 
     struct in_addr client_ip;
     uint16_t client_port;
+    uint32_t block_nr;
 
     int timestamp;
 };
-- 
1.7.10.4

  parent reply	other threads:[~2012-09-10 18:05 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-10 18:05 [Qemu-devel] [PATCH v2 0/3] slirp: tftp server improvements Hervé Poussineau
2012-09-10 18:05 ` [Qemu-devel] [PATCH v2 1/3] slirp: improve TFTP performance Hervé Poussineau
2012-09-10 18:57   ` Jan Kiszka
2012-09-10 18:05 ` Hervé Poussineau [this message]
2012-09-10 18:41   ` [Qemu-devel] [PATCH v2 2/3] slirp: Handle more than 65535 blocks in TFTP transfers Jan Kiszka
2012-09-10 18:05 ` [Qemu-devel] [PATCH v2 3/3] slirp: Implement TFTP Blocksize option Hervé Poussineau
2012-09-10 18:49   ` Jan Kiszka

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1347300346-14482-3-git-send-email-hpoussin@reactos.org \
    --to=hpoussin@reactos.org \
    --cc=jan.kiszka@siemens.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).