qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 1/3] slirp: Implement TFTP Blocksize option


From: Herve Poussineau
Subject: [Qemu-devel] [PATCH 1/3] slirp: Implement TFTP Blocksize option
Date: Mon, 11 Apr 2011 19:10:52 +0000

From: Herv� Poussineau <address@hidden>

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 <address@hidden>
---
 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 via email to

[Prev in Thread] Current Thread [Next in Thread]