From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:56588) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q9ScD-0003Sg-3n for qemu-devel@nongnu.org; Mon, 11 Apr 2011 21:42:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q9MVx-0005rk-Ca for qemu-devel@nongnu.org; Mon, 11 Apr 2011 15:11:10 -0400 Received: from smtp5-g21.free.fr ([212.27.42.5]:36196) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q9MVw-0005pO-Qx for qemu-devel@nongnu.org; Mon, 11 Apr 2011 15:11:09 -0400 From: Herve Poussineau Date: Mon, 11 Apr 2011 19:10:52 +0000 Message-Id: <1302549054-2248-2-git-send-email-hpoussin@reactos.org> In-Reply-To: <1302549054-2248-1-git-send-email-hpoussin@reactos.org> References: <1302549054-2248-1-git-send-email-hpoussin@reactos.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH 1/3] slirp: Implement TFTP Blocksize option List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: =?utf-8?q?Herv=E9=20Poussineau?= From: Herv=E9 Poussineau 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=E9 Poussineau --- 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, } =20 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 =3D 0; + int i, n =3D 0; =20 m =3D m_get(spt->slirp); =20 @@ -136,10 +136,12 @@ static int tftp_send_oack(struct tftp_session *spt, m->m_data +=3D sizeof(struct udpiphdr); =20 tp->tp_op =3D htons(TFTP_OACK); - n +=3D snprintf(tp->x.tp_buf + n, sizeof(tp->x.tp_buf) - n, "%s", - key) + 1; - n +=3D snprintf(tp->x.tp_buf + n, sizeof(tp->x.tp_buf) - n, "%u", - value) + 1; + for (i =3D 0; i < nb; i++) { + n +=3D snprintf(tp->x.tp_buf + n, sizeof(tp->x.tp_buf) - n, "%s", + key[i]) + 1; + n +=3D snprintf(tp->x.tp_buf + n, sizeof(tp->x.tp_buf) - n, "%u", + value[i]) + 1; + } =20 saddr.sin_addr =3D recv_tp->ip.ip_dst; saddr.sin_port =3D 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 =3D 0; =20 /* check if a session already exists and if so terminate it */ s =3D tftp_session_find(slirp, tp); @@ -364,9 +369,28 @@ static void tftp_handle_rrq(Slirp *slirp, struct tft= p_t *tp, int pktlen) } } =20 - tftp_send_oack(spt, "tsize", tsize, tp); - return; + option_name[nb_options] =3D "tsize"; + option_value[nb_options] =3D tsize; + nb_options++; } + if (strcasecmp(key, "blksize") =3D=3D 0) { + int blksize =3D 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 >=3D 512) { + option_name[nb_options] =3D "blksize"; + option_value[nb_options] =3D 512; + nb_options++; + } + } + } + + if (nb_options > 0) { + tftp_send_oack(spt, option_name, option_value, nb_options, tp); + return; } =20 tftp_send_data(spt, 1, tp); --=20 1.6.0.2.GIT