From patchwork Thu Jan 7 17:01:28 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Horsten X-Patchwork-Id: 42446 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 7C187B6EE8 for ; Fri, 8 Jan 2010 04:14:49 +1100 (EST) Received: from localhost ([127.0.0.1]:53015 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NSvwc-0003Fq-7a for incoming@patchwork.ozlabs.org; Thu, 07 Jan 2010 12:14:46 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NSvk0-0008H8-9J for qemu-devel@nongnu.org; Thu, 07 Jan 2010 12:01:44 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NSvju-0008C0-I4 for qemu-devel@nongnu.org; Thu, 07 Jan 2010 12:01:42 -0500 Received: from [199.232.76.173] (port=59176 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NSvjs-0008BY-KF for qemu-devel@nongnu.org; Thu, 07 Jan 2010 12:01:36 -0500 Received: from jehova.dsm.dk ([194.182.129.245]:48915) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1NSvjr-0004YF-RD for qemu-devel@nongnu.org; Thu, 07 Jan 2010 12:01:36 -0500 Received: (qmail 6752 invoked by uid 1000); 7 Jan 2010 17:01:28 -0000 Date: 7 Jan 2010 17:01:28 -0000 Message-ID: <20100107170128.6751.qmail@jehova.dsm.dk> MBOX-Line: From d78e03157099b0638dfb60f89c82c8c88c35ce64 Mon Sep 17 00:00:00 2001 From: Thomas Horsten To: qemu-devel@nongnu.org X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) Subject: [Qemu-devel] [PATCH] [tftp] Handle TFTP ERROR from client X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org If a PXE client only wants to find out the size of a file, it will open the file and then abort the transfer by sending a TFTP ERROR packet. The ERROR packet should cause qemu to terminate the session. If not, the sessions will soon run out and cause timeouts in the client. Also, if a TFTP session already exists with same IP/UDP port, it should be terminated when a new RRQ is received, instead of creating a duplicate (which will never be used). A patch for gPXE to send the ERROR packet is also being submitted to gPXE. Together they resolve slowness/hanging when booting pxegrub from qemu's internal TFTP server. The patch from Milan Plzik to return after sending OACK is also required for a complete fix. Signed-off-by: Thomas Horsten Signed-off-by: Milan Plzik --- slirp/tftp.c | 23 +++++++++++++++++++++++ 1 files changed, 23 insertions(+), 0 deletions(-) diff --git a/slirp/tftp.c b/slirp/tftp.c index db869fc..96c0e0c 100644 --- a/slirp/tftp.c +++ b/slirp/tftp.c @@ -264,6 +264,12 @@ static void tftp_handle_rrq(Slirp *slirp, struct tftp_t *tp, int pktlen) size_t prefix_len; char *req_fname; + /* check if a session already exists and if so terminate it */ + s = tftp_session_find(slirp, tp); + if (s >= 0) { + tftp_session_terminate(&slirp->tftp_sessions[s]); + } + s = tftp_session_allocate(slirp, tp); if (s < 0) { @@ -386,6 +392,19 @@ static void tftp_handle_ack(Slirp *slirp, struct tftp_t *tp, int pktlen) } } +static void tftp_handle_error(Slirp *slirp, struct tftp_t *tp, int pktlen) +{ + int s; + + s = tftp_session_find(slirp, tp); + + if (s < 0) { + return; + } + + tftp_session_terminate(&slirp->tftp_sessions[s]); +} + void tftp_input(struct mbuf *m) { struct tftp_t *tp = (struct tftp_t *)m->m_data; @@ -398,5 +417,9 @@ void tftp_input(struct mbuf *m) case TFTP_ACK: tftp_handle_ack(m->slirp, tp, m->m_len); break; + + case TFTP_ERROR: + tftp_handle_error(m->slirp, tp, m->m_len); + break; } }