qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Herve Poussineau <hpoussin@reactos.org>
To: qemu-devel@nongnu.org
Cc: "Herv� Poussineau" <hpoussin@reactos.org>
Subject: [Qemu-devel] [PATCH 1/3] slirp: Implement TFTP Blocksize option
Date: Mon, 11 Apr 2011 19:10:52 +0000	[thread overview]
Message-ID: <1302549054-2248-2-git-send-email-hpoussin@reactos.org> (raw)
In-Reply-To: <1302549054-2248-1-git-send-email-hpoussin@reactos.org>

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=utf-8, Size: 3059 bytes --]

From: Hervé Poussineau <hpoussin@reactos.org>

This option is described in RFC 1783. As this is only an optional field,
we may ignore it in some situations and handle it in some others.
Here, if client requests a block size bigger than the block size we emit
(512 bytes), accept the option with a value of 512

Signed-off-by: Hervé Poussineau <hpoussin@reactos.org>
---
 slirp/tftp.c |   40 ++++++++++++++++++++++++++++++++--------
 1 files changed, 32 insertions(+), 8 deletions(-)

diff --git a/slirp/tftp.c b/slirp/tftp.c
index 8055ccc..7ef44c9 100644
--- a/slirp/tftp.c
+++ b/slirp/tftp.c
@@ -116,13 +116,13 @@ static int tftp_read_data(struct tftp_session *spt, uint16_t block_nr,
 }
 
 static int tftp_send_oack(struct tftp_session *spt,
-                          const char *key, uint32_t value,
+                          const char *key[], uint32_t value[], int nb,
                           struct tftp_t *recv_tp)
 {
     struct sockaddr_in saddr, daddr;
     struct mbuf *m;
     struct tftp_t *tp;
-    int n = 0;
+    int i, n = 0;
 
     m = m_get(spt->slirp);
 
@@ -136,10 +136,12 @@ static int tftp_send_oack(struct tftp_session *spt,
     m->m_data += sizeof(struct udpiphdr);
 
     tp->tp_op = htons(TFTP_OACK);
-    n += snprintf(tp->x.tp_buf + n, sizeof(tp->x.tp_buf) - n, "%s",
-                  key) + 1;
-    n += snprintf(tp->x.tp_buf + n, sizeof(tp->x.tp_buf) - n, "%u",
-                  value) + 1;
+    for (i = 0; i < nb; i++) {
+      n += snprintf(tp->x.tp_buf + n, sizeof(tp->x.tp_buf) - n, "%s",
+                    key[i]) + 1;
+      n += snprintf(tp->x.tp_buf + n, sizeof(tp->x.tp_buf) - n, "%u",
+                    value[i]) + 1;
+    }
 
     saddr.sin_addr = recv_tp->ip.ip_dst;
     saddr.sin_port = recv_tp->udp.uh_dport;
@@ -260,6 +262,9 @@ static void tftp_handle_rrq(Slirp *slirp, struct tftp_t *tp, int pktlen)
   int s, k;
   size_t prefix_len;
   char *req_fname;
+  const char *option_name[2];
+  uint32_t option_value[2];
+  int nb_options = 0;
 
   /* check if a session already exists and if so terminate it */
   s = tftp_session_find(slirp, tp);
@@ -364,9 +369,28 @@ static void tftp_handle_rrq(Slirp *slirp, struct tftp_t *tp, int pktlen)
 	      }
 	  }
 
-	  tftp_send_oack(spt, "tsize", tsize, tp);
-	  return;
+	  option_name[nb_options] = "tsize";
+	  option_value[nb_options] = tsize;
+	  nb_options++;
       }
+    if (strcasecmp(key, "blksize") == 0) {
+      int blksize = atoi(value);
+
+      /* If blksize option is bigger than what we will
+       * emit, accept the option with our packet size.
+       * Otherwise, simply do as we didn't see the option.
+       */
+      if (blksize >= 512) {
+        option_name[nb_options] = "blksize";
+        option_value[nb_options] = 512;
+        nb_options++;
+      }
+    }
+  }
+
+  if (nb_options > 0) {
+    tftp_send_oack(spt, option_name, option_value, nb_options, tp);
+    return;
   }
 
   tftp_send_data(spt, 1, tp);
-- 
1.6.0.2.GIT

  reply	other threads:[~2011-04-12  1:42 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-11 19:10 [Qemu-devel] [PATCH 0/3] slirp: misc fixes Herve Poussineau
2011-04-11 19:10 ` Herve Poussineau [this message]
2011-04-11 19:10   ` [Qemu-devel] [PATCH 2/3] slirp: Handle more than 65535 blocks in TFTP transfers Herve Poussineau
2011-04-11 19:10     ` [Qemu-devel] [PATCH 3/3] slirp: improve TFTP performance Herve Poussineau
2011-04-18 14:04       ` Aurelien Jarno
2011-04-18 14:02     ` [Qemu-devel] [PATCH 2/3] slirp: Handle more than 65535 blocks in TFTP transfers Aurelien Jarno
2011-04-16  9:15   ` [Qemu-devel] [PATCH 1/3] slirp: Implement TFTP Blocksize option Stefan Hajnoczi
2011-04-17 18:16     ` Hervé Poussineau
2011-04-17 19:53       ` Stefan Hajnoczi
2011-04-17 12:39   ` Avi Kivity
2011-04-18 14:02   ` Aurelien Jarno

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=1302549054-2248-2-git-send-email-hpoussin@reactos.org \
    --to=hpoussin@reactos.org \
    --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).