From: Anthony Liguori <anthony@codemonkey.ws>
To: qemu-devel@nongnu.org
Cc: Erwan Velu <erwan.velu@free.fr>
Subject: [Qemu-devel] [PATCH 1/3] Add OACK support to slirp TFTP server
Date: Sat, 17 Feb 2007 19:01:36 -0600 [thread overview]
Message-ID: <45D7A570.7030705@codemonkey.ws> (raw)
In-Reply-To: <45D7A43B.20808@codemonkey.ws>
[-- Attachment #1: Type: text/plain, Size: 102 bytes --]
Specifically, this patch adds tsize handling which is needed for PXELinux.
Regards,
Anthony Liguori
[-- Attachment #2: slirp-tftp-oack.diff --]
[-- Type: text/x-patch, Size: 2781 bytes --]
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
next prev parent reply other threads:[~2007-02-18 1:01 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-02-18 0:56 [Qemu-devel] [PATCH 0/3] Make BOOTP work with slirp Anthony Liguori
2007-02-18 1:01 ` Anthony Liguori [this message]
2007-02-18 1:04 ` [Qemu-devel] [PATCH 2/3] Add -bootp option for slip Anthony Liguori
2007-02-18 1:07 ` [Qemu-devel] [PATCH 3/3] Change -tftp option to take a root directory Anthony Liguori
2007-02-18 11:29 ` [Qemu-devel] Re: [PATCH 0/3] Make BOOTP work with slirp Erwan Velu
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=45D7A570.7030705@codemonkey.ws \
--to=anthony@codemonkey.ws \
--cc=erwan.velu@free.fr \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.