From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1HIaQy-00010I-IX for qemu-devel@nongnu.org; Sat, 17 Feb 2007 20:01:44 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1HIaQw-0000z1-25 for qemu-devel@nongnu.org; Sat, 17 Feb 2007 20:01:43 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HIaQv-0000ym-F4 for qemu-devel@nongnu.org; Sat, 17 Feb 2007 20:01:41 -0500 Received: from nz-out-0506.google.com ([64.233.162.224]) by monty-python.gnu.org with esmtp (Exim 4.52) id 1HIaQu-0004mT-Vp for qemu-devel@nongnu.org; Sat, 17 Feb 2007 20:01:41 -0500 Received: by nz-out-0506.google.com with SMTP id i11so2267796nzi for ; Sat, 17 Feb 2007 17:01:40 -0800 (PST) Message-ID: <45D7A570.7030705@codemonkey.ws> Date: Sat, 17 Feb 2007 19:01:36 -0600 From: Anthony Liguori MIME-Version: 1.0 References: <45D7A43B.20808@codemonkey.ws> In-Reply-To: <45D7A43B.20808@codemonkey.ws> Content-Type: multipart/mixed; boundary="------------090302090104070902020109" Subject: [Qemu-devel] [PATCH 1/3] Add OACK support to slirp TFTP server Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Erwan Velu This is a multi-part message in MIME format. --------------090302090104070902020109 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Specifically, this patch adds tsize handling which is needed for PXELinux. Regards, Anthony Liguori --------------090302090104070902020109 Content-Type: text/x-patch; name="slirp-tftp-oack.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="slirp-tftp-oack.diff" diff -r 153828edbad3 slirp/tftp.c --- a/slirp/tftp.c Thu Feb 15 16:37:56 2007 -0600 +++ b/slirp/tftp.c Thu Feb 15 21:37:26 2007 -0600 @@ -120,6 +120,45 @@ static int tftp_read_data(struct tftp_se return bytes_read; } +static int tftp_send_oack(struct tftp_session *spt, + const char *key, uint32_t value, + struct tftp_t *recv_tp) +{ + struct sockaddr_in saddr, daddr; + struct mbuf *m; + struct tftp_t *tp; + int n = 0; + + m = m_get(); + + if (!m) + return -1; + + memset(m->m_data, 0, m->m_size); + + m->m_data += if_maxlinkhdr; + tp = (void *)m->m_data; + m->m_data += sizeof(struct udpiphdr); + + tp->tp_op = htons(TFTP_OACK); + n += sprintf(tp->x.tp_buf + n, "%s", key) + 1; + n += sprintf(tp->x.tp_buf + n, "%u", value) + 1; + + saddr.sin_addr = recv_tp->ip.ip_dst; + saddr.sin_port = recv_tp->udp.uh_dport; + + daddr.sin_addr = spt->client_ip; + daddr.sin_port = spt->client_port; + + m->m_len = sizeof(struct tftp_t) - 514 + n - + sizeof(struct ip) - sizeof(struct udphdr); + udp_output2(NULL, m, &saddr, &daddr, IPTOS_LOWDELAY); + + return 0; +} + + + static int tftp_send_error(struct tftp_session *spt, u_int16_t errorcode, const char *msg, struct tftp_t *recv_tp) @@ -273,6 +312,8 @@ static void tftp_handle_rrq(struct tftp_ return; } + k += 6;/* skipping octet*/ + /* do sanity checks on the filename */ if ((spt->filename[0] != '/') @@ -297,6 +338,48 @@ static void tftp_handle_rrq(struct tftp_ return; } + if (src[n - 1] != 0) { + tftp_send_error(spt, 2, "Access violation", tp); + return; + } + + while (k < n) { + const char *key, *value; + + key = src + k; + k += strlen(key) + 1; + + if (k >= n) { + tftp_send_error(spt, 2, "Access violation", tp); + return; + } + + value = src + k; + k += strlen(value) + 1; + + if (strcmp(key, "tsize") == 0) { + int tsize = atoi(value); + struct stat stat_p; + + if (tsize == 0 && tftp_prefix) { + char buffer[1024]; + int len; + + len = snprintf(buffer, sizeof(buffer), "%s/%s", + tftp_prefix, spt->filename); + + if (stat(buffer, &stat_p) == 0) + tsize = stat_p.st_size; + else { + tftp_send_error(spt, 1, "File not found", tp); + return; + } + } + + tftp_send_oack(spt, "tsize", tsize, tp); + } + } + tftp_send_data(spt, 1, tp); } diff -r 153828edbad3 slirp/tftp.h --- a/slirp/tftp.h Thu Feb 15 16:37:56 2007 -0600 +++ b/slirp/tftp.h Thu Feb 15 16:37:57 2007 -0600 @@ -9,6 +9,7 @@ #define TFTP_DATA 3 #define TFTP_ACK 4 #define TFTP_ERROR 5 +#define TFTP_OACK 6 #define TFTP_FILENAME_MAX 512 --------------090302090104070902020109--