1998-08-20 08:19:55 +00:00
|
|
|
/* $NetBSD: tftp.c,v 1.4 1997/09/17 16:57:07 drochner Exp $ */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1996
|
|
|
|
* Matthias Drochner. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed for the NetBSD Project
|
|
|
|
* by Matthias Drochner.
|
|
|
|
* 4. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2001-09-30 22:28:01 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1998-08-20 08:19:55 +00:00
|
|
|
/*
|
|
|
|
* Simple TFTP implementation for libsa.
|
|
|
|
* Assumes:
|
|
|
|
* - socket descriptor (int) at open_file->f_devdata
|
|
|
|
* - server host IP in global servip
|
|
|
|
* Restrictions:
|
|
|
|
* - read only
|
|
|
|
* - lseek only with SEEK_SET or SEEK_CUR
|
|
|
|
* - no big time differences between transfers (<tftp timeout)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/udp.h>
|
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
#include <arpa/tftp.h>
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "stand.h"
|
|
|
|
#include "net.h"
|
|
|
|
#include "netif.h"
|
|
|
|
|
|
|
|
#include "tftp.h"
|
|
|
|
|
(1) When sending the TFTP RRQ packet to read a file,
send along the "blksize" option specified in RFC2348,
and the "tsize" option specified in RFC2349.
Add code to parse the TFTP Option Acknowledgement (OACK) packet as
specified in RFC2347.
For TFTP servers which support the "blksize" option, we can
specify a TFTP Data block size larger than the default 512 bytes
specified in RFC1350. This offers greater read performance when
downloading files.
We request an initial size of 1428 bytes, which is less than the
Ethernet MTU of 1500 bytes. If the TFTP server sends back an OACK
packet, then use the block size specified in the OACK packet.
Most times it is usually the same value as what we request.
If the TFTP server supports RFC2348, we will see performance improvements
by transferring files over TFTP with larger block sizes.
If we do not get back an OACK packet, then we most likely we
are interoperating with a legacy TFTP server that does not
support TFTP extension options, so default to the block size of
512 bytes.
(2) If the "tftp.blksize" environment variable is set, then
take that value and use it when sending the TFTP RRQ packet,
instead of 1428. This allows us to set different values of
"tftp.blksize" in the loader, so that we can test out different
TFTP block sizes at run time.
Obtained from: Juniper Networks
Fixed by: rodrigc
2011-06-15 22:13:22 +00:00
|
|
|
struct tftp_handle;
|
|
|
|
|
1998-09-18 22:58:01 +00:00
|
|
|
static int tftp_open(const char *path, struct open_file *f);
|
1998-08-20 08:19:55 +00:00
|
|
|
static int tftp_close(struct open_file *f);
|
(1) When sending the TFTP RRQ packet to read a file,
send along the "blksize" option specified in RFC2348,
and the "tsize" option specified in RFC2349.
Add code to parse the TFTP Option Acknowledgement (OACK) packet as
specified in RFC2347.
For TFTP servers which support the "blksize" option, we can
specify a TFTP Data block size larger than the default 512 bytes
specified in RFC1350. This offers greater read performance when
downloading files.
We request an initial size of 1428 bytes, which is less than the
Ethernet MTU of 1500 bytes. If the TFTP server sends back an OACK
packet, then use the block size specified in the OACK packet.
Most times it is usually the same value as what we request.
If the TFTP server supports RFC2348, we will see performance improvements
by transferring files over TFTP with larger block sizes.
If we do not get back an OACK packet, then we most likely we
are interoperating with a legacy TFTP server that does not
support TFTP extension options, so default to the block size of
512 bytes.
(2) If the "tftp.blksize" environment variable is set, then
take that value and use it when sending the TFTP RRQ packet,
instead of 1428. This allows us to set different values of
"tftp.blksize" in the loader, so that we can test out different
TFTP block sizes at run time.
Obtained from: Juniper Networks
Fixed by: rodrigc
2011-06-15 22:13:22 +00:00
|
|
|
static void tftp_parse_oack(struct tftp_handle *h, char *buf, size_t len);
|
1998-08-20 08:19:55 +00:00
|
|
|
static int tftp_read(struct open_file *f, void *buf, size_t size, size_t *resid);
|
|
|
|
static int tftp_write(struct open_file *f, void *buf, size_t size, size_t *resid);
|
|
|
|
static off_t tftp_seek(struct open_file *f, off_t offset, int where);
|
(1) When sending the TFTP RRQ packet to read a file,
send along the "blksize" option specified in RFC2348,
and the "tsize" option specified in RFC2349.
Add code to parse the TFTP Option Acknowledgement (OACK) packet as
specified in RFC2347.
For TFTP servers which support the "blksize" option, we can
specify a TFTP Data block size larger than the default 512 bytes
specified in RFC1350. This offers greater read performance when
downloading files.
We request an initial size of 1428 bytes, which is less than the
Ethernet MTU of 1500 bytes. If the TFTP server sends back an OACK
packet, then use the block size specified in the OACK packet.
Most times it is usually the same value as what we request.
If the TFTP server supports RFC2348, we will see performance improvements
by transferring files over TFTP with larger block sizes.
If we do not get back an OACK packet, then we most likely we
are interoperating with a legacy TFTP server that does not
support TFTP extension options, so default to the block size of
512 bytes.
(2) If the "tftp.blksize" environment variable is set, then
take that value and use it when sending the TFTP RRQ packet,
instead of 1428. This allows us to set different values of
"tftp.blksize" in the loader, so that we can test out different
TFTP block sizes at run time.
Obtained from: Juniper Networks
Fixed by: rodrigc
2011-06-15 22:13:22 +00:00
|
|
|
static int tftp_set_blksize(struct tftp_handle *h, const char *str);
|
1998-08-20 08:19:55 +00:00
|
|
|
static int tftp_stat(struct open_file *f, struct stat *sb);
|
(1) When sending the TFTP RRQ packet to read a file,
send along the "blksize" option specified in RFC2348,
and the "tsize" option specified in RFC2349.
Add code to parse the TFTP Option Acknowledgement (OACK) packet as
specified in RFC2347.
For TFTP servers which support the "blksize" option, we can
specify a TFTP Data block size larger than the default 512 bytes
specified in RFC1350. This offers greater read performance when
downloading files.
We request an initial size of 1428 bytes, which is less than the
Ethernet MTU of 1500 bytes. If the TFTP server sends back an OACK
packet, then use the block size specified in the OACK packet.
Most times it is usually the same value as what we request.
If the TFTP server supports RFC2348, we will see performance improvements
by transferring files over TFTP with larger block sizes.
If we do not get back an OACK packet, then we most likely we
are interoperating with a legacy TFTP server that does not
support TFTP extension options, so default to the block size of
512 bytes.
(2) If the "tftp.blksize" environment variable is set, then
take that value and use it when sending the TFTP RRQ packet,
instead of 1428. This allows us to set different values of
"tftp.blksize" in the loader, so that we can test out different
TFTP block sizes at run time.
Obtained from: Juniper Networks
Fixed by: rodrigc
2011-06-15 22:13:22 +00:00
|
|
|
static ssize_t sendrecv_tftp(struct tftp_handle *h,
|
|
|
|
ssize_t (*sproc)(struct iodesc *, void *, size_t),
|
|
|
|
void *sbuf, size_t ssize,
|
|
|
|
ssize_t (*rproc)(struct tftp_handle *h, void *, ssize_t, time_t, unsigned short *),
|
|
|
|
void *rbuf, size_t rsize, unsigned short *rtype);
|
1998-08-20 08:19:55 +00:00
|
|
|
|
|
|
|
struct fs_ops tftp_fsops = {
|
2000-04-29 20:47:10 +00:00
|
|
|
"tftp",
|
|
|
|
tftp_open,
|
|
|
|
tftp_close,
|
|
|
|
tftp_read,
|
|
|
|
tftp_write,
|
|
|
|
tftp_seek,
|
|
|
|
tftp_stat,
|
|
|
|
null_readdir
|
1998-08-20 08:19:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extern struct in_addr servip;
|
|
|
|
|
|
|
|
static int tftpport = 2000;
|
(1) When sending the TFTP RRQ packet to read a file,
send along the "blksize" option specified in RFC2348,
and the "tsize" option specified in RFC2349.
Add code to parse the TFTP Option Acknowledgement (OACK) packet as
specified in RFC2347.
For TFTP servers which support the "blksize" option, we can
specify a TFTP Data block size larger than the default 512 bytes
specified in RFC1350. This offers greater read performance when
downloading files.
We request an initial size of 1428 bytes, which is less than the
Ethernet MTU of 1500 bytes. If the TFTP server sends back an OACK
packet, then use the block size specified in the OACK packet.
Most times it is usually the same value as what we request.
If the TFTP server supports RFC2348, we will see performance improvements
by transferring files over TFTP with larger block sizes.
If we do not get back an OACK packet, then we most likely we
are interoperating with a legacy TFTP server that does not
support TFTP extension options, so default to the block size of
512 bytes.
(2) If the "tftp.blksize" environment variable is set, then
take that value and use it when sending the TFTP RRQ packet,
instead of 1428. This allows us to set different values of
"tftp.blksize" in the loader, so that we can test out different
TFTP block sizes at run time.
Obtained from: Juniper Networks
Fixed by: rodrigc
2011-06-15 22:13:22 +00:00
|
|
|
static int is_open = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The legacy TFTP_BLKSIZE value was 512.
|
|
|
|
* TFTP_REQUESTED_BLKSIZE of 1428 is (Ethernet MTU, less the TFTP, UDP and
|
|
|
|
* IP header lengths).
|
|
|
|
*/
|
|
|
|
#define TFTP_REQUESTED_BLKSIZE 1428
|
1998-08-20 08:19:55 +00:00
|
|
|
|
(1) When sending the TFTP RRQ packet to read a file,
send along the "blksize" option specified in RFC2348,
and the "tsize" option specified in RFC2349.
Add code to parse the TFTP Option Acknowledgement (OACK) packet as
specified in RFC2347.
For TFTP servers which support the "blksize" option, we can
specify a TFTP Data block size larger than the default 512 bytes
specified in RFC1350. This offers greater read performance when
downloading files.
We request an initial size of 1428 bytes, which is less than the
Ethernet MTU of 1500 bytes. If the TFTP server sends back an OACK
packet, then use the block size specified in the OACK packet.
Most times it is usually the same value as what we request.
If the TFTP server supports RFC2348, we will see performance improvements
by transferring files over TFTP with larger block sizes.
If we do not get back an OACK packet, then we most likely we
are interoperating with a legacy TFTP server that does not
support TFTP extension options, so default to the block size of
512 bytes.
(2) If the "tftp.blksize" environment variable is set, then
take that value and use it when sending the TFTP RRQ packet,
instead of 1428. This allows us to set different values of
"tftp.blksize" in the loader, so that we can test out different
TFTP block sizes at run time.
Obtained from: Juniper Networks
Fixed by: rodrigc
2011-06-15 22:13:22 +00:00
|
|
|
/*
|
|
|
|
* Choose a blksize big enough so we can test with Ethernet
|
|
|
|
* Jumbo frames in the future.
|
|
|
|
*/
|
|
|
|
#define TFTP_MAX_BLKSIZE 9008
|
1998-08-20 08:19:55 +00:00
|
|
|
|
|
|
|
struct tftp_handle {
|
|
|
|
struct iodesc *iodesc;
|
|
|
|
int currblock; /* contents of lastdata */
|
|
|
|
int islastblock; /* flag */
|
|
|
|
int validsize;
|
|
|
|
int off;
|
|
|
|
char *path; /* saved for re-requests */
|
(1) When sending the TFTP RRQ packet to read a file,
send along the "blksize" option specified in RFC2348,
and the "tsize" option specified in RFC2349.
Add code to parse the TFTP Option Acknowledgement (OACK) packet as
specified in RFC2347.
For TFTP servers which support the "blksize" option, we can
specify a TFTP Data block size larger than the default 512 bytes
specified in RFC1350. This offers greater read performance when
downloading files.
We request an initial size of 1428 bytes, which is less than the
Ethernet MTU of 1500 bytes. If the TFTP server sends back an OACK
packet, then use the block size specified in the OACK packet.
Most times it is usually the same value as what we request.
If the TFTP server supports RFC2348, we will see performance improvements
by transferring files over TFTP with larger block sizes.
If we do not get back an OACK packet, then we most likely we
are interoperating with a legacy TFTP server that does not
support TFTP extension options, so default to the block size of
512 bytes.
(2) If the "tftp.blksize" environment variable is set, then
take that value and use it when sending the TFTP RRQ packet,
instead of 1428. This allows us to set different values of
"tftp.blksize" in the loader, so that we can test out different
TFTP block sizes at run time.
Obtained from: Juniper Networks
Fixed by: rodrigc
2011-06-15 22:13:22 +00:00
|
|
|
unsigned int tftp_blksize;
|
|
|
|
unsigned long tftp_tsize;
|
1998-08-20 08:19:55 +00:00
|
|
|
struct {
|
|
|
|
u_char header[HEADER_SIZE];
|
|
|
|
struct tftphdr t;
|
(1) When sending the TFTP RRQ packet to read a file,
send along the "blksize" option specified in RFC2348,
and the "tsize" option specified in RFC2349.
Add code to parse the TFTP Option Acknowledgement (OACK) packet as
specified in RFC2347.
For TFTP servers which support the "blksize" option, we can
specify a TFTP Data block size larger than the default 512 bytes
specified in RFC1350. This offers greater read performance when
downloading files.
We request an initial size of 1428 bytes, which is less than the
Ethernet MTU of 1500 bytes. If the TFTP server sends back an OACK
packet, then use the block size specified in the OACK packet.
Most times it is usually the same value as what we request.
If the TFTP server supports RFC2348, we will see performance improvements
by transferring files over TFTP with larger block sizes.
If we do not get back an OACK packet, then we most likely we
are interoperating with a legacy TFTP server that does not
support TFTP extension options, so default to the block size of
512 bytes.
(2) If the "tftp.blksize" environment variable is set, then
take that value and use it when sending the TFTP RRQ packet,
instead of 1428. This allows us to set different values of
"tftp.blksize" in the loader, so that we can test out different
TFTP block sizes at run time.
Obtained from: Juniper Networks
Fixed by: rodrigc
2011-06-15 22:13:22 +00:00
|
|
|
u_char space[TFTP_MAX_BLKSIZE];
|
2011-06-15 23:22:35 +00:00
|
|
|
} __packed __aligned(4) lastdata;
|
1998-08-20 08:19:55 +00:00
|
|
|
};
|
|
|
|
|
2011-06-15 23:22:35 +00:00
|
|
|
static const int tftperrors[8] = {
|
1998-08-20 08:19:55 +00:00
|
|
|
0, /* ??? */
|
|
|
|
ENOENT,
|
|
|
|
EPERM,
|
|
|
|
ENOSPC,
|
|
|
|
EINVAL, /* ??? */
|
|
|
|
EINVAL, /* ??? */
|
|
|
|
EEXIST,
|
|
|
|
EINVAL /* ??? */
|
|
|
|
};
|
|
|
|
|
|
|
|
static ssize_t
|
(1) When sending the TFTP RRQ packet to read a file,
send along the "blksize" option specified in RFC2348,
and the "tsize" option specified in RFC2349.
Add code to parse the TFTP Option Acknowledgement (OACK) packet as
specified in RFC2347.
For TFTP servers which support the "blksize" option, we can
specify a TFTP Data block size larger than the default 512 bytes
specified in RFC1350. This offers greater read performance when
downloading files.
We request an initial size of 1428 bytes, which is less than the
Ethernet MTU of 1500 bytes. If the TFTP server sends back an OACK
packet, then use the block size specified in the OACK packet.
Most times it is usually the same value as what we request.
If the TFTP server supports RFC2348, we will see performance improvements
by transferring files over TFTP with larger block sizes.
If we do not get back an OACK packet, then we most likely we
are interoperating with a legacy TFTP server that does not
support TFTP extension options, so default to the block size of
512 bytes.
(2) If the "tftp.blksize" environment variable is set, then
take that value and use it when sending the TFTP RRQ packet,
instead of 1428. This allows us to set different values of
"tftp.blksize" in the loader, so that we can test out different
TFTP block sizes at run time.
Obtained from: Juniper Networks
Fixed by: rodrigc
2011-06-15 22:13:22 +00:00
|
|
|
recvtftp(struct tftp_handle *h, void *pkt, ssize_t len, time_t tleft,
|
|
|
|
unsigned short *rtype)
|
1998-08-20 08:19:55 +00:00
|
|
|
{
|
(1) When sending the TFTP RRQ packet to read a file,
send along the "blksize" option specified in RFC2348,
and the "tsize" option specified in RFC2349.
Add code to parse the TFTP Option Acknowledgement (OACK) packet as
specified in RFC2347.
For TFTP servers which support the "blksize" option, we can
specify a TFTP Data block size larger than the default 512 bytes
specified in RFC1350. This offers greater read performance when
downloading files.
We request an initial size of 1428 bytes, which is less than the
Ethernet MTU of 1500 bytes. If the TFTP server sends back an OACK
packet, then use the block size specified in the OACK packet.
Most times it is usually the same value as what we request.
If the TFTP server supports RFC2348, we will see performance improvements
by transferring files over TFTP with larger block sizes.
If we do not get back an OACK packet, then we most likely we
are interoperating with a legacy TFTP server that does not
support TFTP extension options, so default to the block size of
512 bytes.
(2) If the "tftp.blksize" environment variable is set, then
take that value and use it when sending the TFTP RRQ packet,
instead of 1428. This allows us to set different values of
"tftp.blksize" in the loader, so that we can test out different
TFTP block sizes at run time.
Obtained from: Juniper Networks
Fixed by: rodrigc
2011-06-15 22:13:22 +00:00
|
|
|
struct iodesc *d = h->iodesc;
|
1998-08-20 08:19:55 +00:00
|
|
|
struct tftphdr *t;
|
|
|
|
|
2001-06-30 21:39:09 +00:00
|
|
|
errno = 0;
|
|
|
|
|
1998-08-20 08:19:55 +00:00
|
|
|
len = readudp(d, pkt, len, tleft);
|
|
|
|
|
2001-05-28 22:25:44 +00:00
|
|
|
if (len < 4)
|
1998-08-20 08:19:55 +00:00
|
|
|
return (-1);
|
|
|
|
|
|
|
|
t = (struct tftphdr *) pkt;
|
(1) When sending the TFTP RRQ packet to read a file,
send along the "blksize" option specified in RFC2348,
and the "tsize" option specified in RFC2349.
Add code to parse the TFTP Option Acknowledgement (OACK) packet as
specified in RFC2347.
For TFTP servers which support the "blksize" option, we can
specify a TFTP Data block size larger than the default 512 bytes
specified in RFC1350. This offers greater read performance when
downloading files.
We request an initial size of 1428 bytes, which is less than the
Ethernet MTU of 1500 bytes. If the TFTP server sends back an OACK
packet, then use the block size specified in the OACK packet.
Most times it is usually the same value as what we request.
If the TFTP server supports RFC2348, we will see performance improvements
by transferring files over TFTP with larger block sizes.
If we do not get back an OACK packet, then we most likely we
are interoperating with a legacy TFTP server that does not
support TFTP extension options, so default to the block size of
512 bytes.
(2) If the "tftp.blksize" environment variable is set, then
take that value and use it when sending the TFTP RRQ packet,
instead of 1428. This allows us to set different values of
"tftp.blksize" in the loader, so that we can test out different
TFTP block sizes at run time.
Obtained from: Juniper Networks
Fixed by: rodrigc
2011-06-15 22:13:22 +00:00
|
|
|
*rtype = ntohs(t->th_opcode);
|
1998-08-20 08:19:55 +00:00
|
|
|
switch (ntohs(t->th_opcode)) {
|
|
|
|
case DATA: {
|
|
|
|
int got;
|
|
|
|
|
|
|
|
if (htons(t->th_block) != d->xid) {
|
|
|
|
/*
|
|
|
|
* Expected block?
|
|
|
|
*/
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if (d->xid == 1) {
|
|
|
|
/*
|
|
|
|
* First data packet from new port.
|
|
|
|
*/
|
2002-03-21 23:39:28 +00:00
|
|
|
struct udphdr *uh;
|
1998-08-20 08:19:55 +00:00
|
|
|
uh = (struct udphdr *) pkt - 1;
|
|
|
|
d->destport = uh->uh_sport;
|
|
|
|
} /* else check uh_sport has not changed??? */
|
|
|
|
got = len - (t->th_data - (char *) t);
|
|
|
|
return got;
|
|
|
|
}
|
|
|
|
case ERROR:
|
|
|
|
if ((unsigned) ntohs(t->th_code) >= 8) {
|
|
|
|
printf("illegal tftp error %d\n", ntohs(t->th_code));
|
|
|
|
errno = EIO;
|
|
|
|
} else {
|
2011-05-03 07:46:02 +00:00
|
|
|
#ifdef TFTP_DEBUG
|
1998-08-20 08:19:55 +00:00
|
|
|
printf("tftp-error %d\n", ntohs(t->th_code));
|
|
|
|
#endif
|
|
|
|
errno = tftperrors[ntohs(t->th_code)];
|
|
|
|
}
|
|
|
|
return (-1);
|
(1) When sending the TFTP RRQ packet to read a file,
send along the "blksize" option specified in RFC2348,
and the "tsize" option specified in RFC2349.
Add code to parse the TFTP Option Acknowledgement (OACK) packet as
specified in RFC2347.
For TFTP servers which support the "blksize" option, we can
specify a TFTP Data block size larger than the default 512 bytes
specified in RFC1350. This offers greater read performance when
downloading files.
We request an initial size of 1428 bytes, which is less than the
Ethernet MTU of 1500 bytes. If the TFTP server sends back an OACK
packet, then use the block size specified in the OACK packet.
Most times it is usually the same value as what we request.
If the TFTP server supports RFC2348, we will see performance improvements
by transferring files over TFTP with larger block sizes.
If we do not get back an OACK packet, then we most likely we
are interoperating with a legacy TFTP server that does not
support TFTP extension options, so default to the block size of
512 bytes.
(2) If the "tftp.blksize" environment variable is set, then
take that value and use it when sending the TFTP RRQ packet,
instead of 1428. This allows us to set different values of
"tftp.blksize" in the loader, so that we can test out different
TFTP block sizes at run time.
Obtained from: Juniper Networks
Fixed by: rodrigc
2011-06-15 22:13:22 +00:00
|
|
|
case OACK: {
|
|
|
|
struct udphdr *uh;
|
|
|
|
int tftp_oack_len = len - sizeof(t->th_opcode);
|
|
|
|
tftp_parse_oack(h, t->th_u.tu_stuff, tftp_oack_len);
|
|
|
|
/*
|
|
|
|
* Remember which port this OACK came from,
|
|
|
|
* because we need to send the ACK back to it.
|
|
|
|
*/
|
|
|
|
uh = (struct udphdr *) pkt - 1;
|
|
|
|
d->destport = uh->uh_sport;
|
|
|
|
return (0);
|
|
|
|
}
|
1998-08-20 08:19:55 +00:00
|
|
|
default:
|
2011-05-03 07:46:02 +00:00
|
|
|
#ifdef TFTP_DEBUG
|
1998-08-20 08:19:55 +00:00
|
|
|
printf("tftp type %d not handled\n", ntohs(t->th_opcode));
|
|
|
|
#endif
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* send request, expect first block (or error) */
|
|
|
|
static int
|
2011-05-03 04:44:50 +00:00
|
|
|
tftp_makereq(struct tftp_handle *h)
|
1998-08-20 08:19:55 +00:00
|
|
|
{
|
|
|
|
struct {
|
|
|
|
u_char header[HEADER_SIZE];
|
|
|
|
struct tftphdr t;
|
|
|
|
u_char space[FNAME_SIZE + 6];
|
2011-06-15 23:22:35 +00:00
|
|
|
} __packed __aligned(4) wbuf;
|
1998-08-20 08:19:55 +00:00
|
|
|
char *wtail;
|
|
|
|
int l;
|
|
|
|
ssize_t res;
|
|
|
|
struct tftphdr *t;
|
(1) When sending the TFTP RRQ packet to read a file,
send along the "blksize" option specified in RFC2348,
and the "tsize" option specified in RFC2349.
Add code to parse the TFTP Option Acknowledgement (OACK) packet as
specified in RFC2347.
For TFTP servers which support the "blksize" option, we can
specify a TFTP Data block size larger than the default 512 bytes
specified in RFC1350. This offers greater read performance when
downloading files.
We request an initial size of 1428 bytes, which is less than the
Ethernet MTU of 1500 bytes. If the TFTP server sends back an OACK
packet, then use the block size specified in the OACK packet.
Most times it is usually the same value as what we request.
If the TFTP server supports RFC2348, we will see performance improvements
by transferring files over TFTP with larger block sizes.
If we do not get back an OACK packet, then we most likely we
are interoperating with a legacy TFTP server that does not
support TFTP extension options, so default to the block size of
512 bytes.
(2) If the "tftp.blksize" environment variable is set, then
take that value and use it when sending the TFTP RRQ packet,
instead of 1428. This allows us to set different values of
"tftp.blksize" in the loader, so that we can test out different
TFTP block sizes at run time.
Obtained from: Juniper Networks
Fixed by: rodrigc
2011-06-15 22:13:22 +00:00
|
|
|
char *tftp_blksize = NULL;
|
|
|
|
int blksize_l;
|
|
|
|
unsigned short rtype = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allow overriding default TFTP block size by setting
|
|
|
|
* a tftp.blksize environment variable.
|
|
|
|
*/
|
|
|
|
if ((tftp_blksize = getenv("tftp.blksize")) != NULL) {
|
|
|
|
tftp_set_blksize(h, tftp_blksize);
|
|
|
|
}
|
1998-08-20 08:19:55 +00:00
|
|
|
|
|
|
|
wbuf.t.th_opcode = htons((u_short) RRQ);
|
|
|
|
wtail = wbuf.t.th_stuff;
|
|
|
|
l = strlen(h->path);
|
(1) When sending the TFTP RRQ packet to read a file,
send along the "blksize" option specified in RFC2348,
and the "tsize" option specified in RFC2349.
Add code to parse the TFTP Option Acknowledgement (OACK) packet as
specified in RFC2347.
For TFTP servers which support the "blksize" option, we can
specify a TFTP Data block size larger than the default 512 bytes
specified in RFC1350. This offers greater read performance when
downloading files.
We request an initial size of 1428 bytes, which is less than the
Ethernet MTU of 1500 bytes. If the TFTP server sends back an OACK
packet, then use the block size specified in the OACK packet.
Most times it is usually the same value as what we request.
If the TFTP server supports RFC2348, we will see performance improvements
by transferring files over TFTP with larger block sizes.
If we do not get back an OACK packet, then we most likely we
are interoperating with a legacy TFTP server that does not
support TFTP extension options, so default to the block size of
512 bytes.
(2) If the "tftp.blksize" environment variable is set, then
take that value and use it when sending the TFTP RRQ packet,
instead of 1428. This allows us to set different values of
"tftp.blksize" in the loader, so that we can test out different
TFTP block sizes at run time.
Obtained from: Juniper Networks
Fixed by: rodrigc
2011-06-15 22:13:22 +00:00
|
|
|
if (l > FNAME_SIZE)
|
|
|
|
return (ENAMETOOLONG);
|
1998-08-20 08:19:55 +00:00
|
|
|
bcopy(h->path, wtail, l + 1);
|
|
|
|
wtail += l + 1;
|
|
|
|
bcopy("octet", wtail, 6);
|
|
|
|
wtail += 6;
|
(1) When sending the TFTP RRQ packet to read a file,
send along the "blksize" option specified in RFC2348,
and the "tsize" option specified in RFC2349.
Add code to parse the TFTP Option Acknowledgement (OACK) packet as
specified in RFC2347.
For TFTP servers which support the "blksize" option, we can
specify a TFTP Data block size larger than the default 512 bytes
specified in RFC1350. This offers greater read performance when
downloading files.
We request an initial size of 1428 bytes, which is less than the
Ethernet MTU of 1500 bytes. If the TFTP server sends back an OACK
packet, then use the block size specified in the OACK packet.
Most times it is usually the same value as what we request.
If the TFTP server supports RFC2348, we will see performance improvements
by transferring files over TFTP with larger block sizes.
If we do not get back an OACK packet, then we most likely we
are interoperating with a legacy TFTP server that does not
support TFTP extension options, so default to the block size of
512 bytes.
(2) If the "tftp.blksize" environment variable is set, then
take that value and use it when sending the TFTP RRQ packet,
instead of 1428. This allows us to set different values of
"tftp.blksize" in the loader, so that we can test out different
TFTP block sizes at run time.
Obtained from: Juniper Networks
Fixed by: rodrigc
2011-06-15 22:13:22 +00:00
|
|
|
bcopy("blksize", wtail, 8);
|
|
|
|
wtail += 8;
|
|
|
|
blksize_l = sprintf(wtail, "%d", h->tftp_blksize);
|
|
|
|
wtail += blksize_l + 1;
|
|
|
|
bcopy("tsize", wtail, 6);
|
|
|
|
wtail += 6;
|
|
|
|
bcopy("0", wtail, 2);
|
|
|
|
wtail += 2;
|
1998-08-20 08:19:55 +00:00
|
|
|
|
|
|
|
t = &h->lastdata.t;
|
|
|
|
|
|
|
|
/* h->iodesc->myport = htons(--tftpport); */
|
|
|
|
h->iodesc->myport = htons(tftpport + (getsecs() & 0x3ff));
|
|
|
|
h->iodesc->destport = htons(IPPORT_TFTP);
|
|
|
|
h->iodesc->xid = 1; /* expected block */
|
|
|
|
|
(1) When sending the TFTP RRQ packet to read a file,
send along the "blksize" option specified in RFC2348,
and the "tsize" option specified in RFC2349.
Add code to parse the TFTP Option Acknowledgement (OACK) packet as
specified in RFC2347.
For TFTP servers which support the "blksize" option, we can
specify a TFTP Data block size larger than the default 512 bytes
specified in RFC1350. This offers greater read performance when
downloading files.
We request an initial size of 1428 bytes, which is less than the
Ethernet MTU of 1500 bytes. If the TFTP server sends back an OACK
packet, then use the block size specified in the OACK packet.
Most times it is usually the same value as what we request.
If the TFTP server supports RFC2348, we will see performance improvements
by transferring files over TFTP with larger block sizes.
If we do not get back an OACK packet, then we most likely we
are interoperating with a legacy TFTP server that does not
support TFTP extension options, so default to the block size of
512 bytes.
(2) If the "tftp.blksize" environment variable is set, then
take that value and use it when sending the TFTP RRQ packet,
instead of 1428. This allows us to set different values of
"tftp.blksize" in the loader, so that we can test out different
TFTP block sizes at run time.
Obtained from: Juniper Networks
Fixed by: rodrigc
2011-06-15 22:13:22 +00:00
|
|
|
res = sendrecv_tftp(h, &sendudp, &wbuf.t, wtail - (char *) &wbuf.t,
|
|
|
|
&recvtftp, t, sizeof(*t) + h->tftp_blksize, &rtype);
|
|
|
|
|
|
|
|
if (rtype == OACK) {
|
|
|
|
wbuf.t.th_opcode = htons((u_short)ACK);
|
|
|
|
wtail = (char *) &wbuf.t.th_block;
|
|
|
|
wbuf.t.th_block = htons(0);
|
|
|
|
wtail += 2;
|
|
|
|
rtype = 0;
|
|
|
|
res = sendrecv_tftp(h, &sendudp, &wbuf.t, wtail - (char *) &wbuf.t,
|
|
|
|
&recvtftp, t, sizeof(*t) + h->tftp_blksize, &rtype);
|
|
|
|
}
|
1998-08-20 08:19:55 +00:00
|
|
|
|
(1) When sending the TFTP RRQ packet to read a file,
send along the "blksize" option specified in RFC2348,
and the "tsize" option specified in RFC2349.
Add code to parse the TFTP Option Acknowledgement (OACK) packet as
specified in RFC2347.
For TFTP servers which support the "blksize" option, we can
specify a TFTP Data block size larger than the default 512 bytes
specified in RFC1350. This offers greater read performance when
downloading files.
We request an initial size of 1428 bytes, which is less than the
Ethernet MTU of 1500 bytes. If the TFTP server sends back an OACK
packet, then use the block size specified in the OACK packet.
Most times it is usually the same value as what we request.
If the TFTP server supports RFC2348, we will see performance improvements
by transferring files over TFTP with larger block sizes.
If we do not get back an OACK packet, then we most likely we
are interoperating with a legacy TFTP server that does not
support TFTP extension options, so default to the block size of
512 bytes.
(2) If the "tftp.blksize" environment variable is set, then
take that value and use it when sending the TFTP RRQ packet,
instead of 1428. This allows us to set different values of
"tftp.blksize" in the loader, so that we can test out different
TFTP block sizes at run time.
Obtained from: Juniper Networks
Fixed by: rodrigc
2011-06-15 22:13:22 +00:00
|
|
|
switch (rtype) {
|
|
|
|
case DATA: {
|
|
|
|
h->currblock = 1;
|
|
|
|
h->validsize = res;
|
|
|
|
h->islastblock = 0;
|
|
|
|
if (res < h->tftp_blksize)
|
|
|
|
h->islastblock = 1; /* very short file */
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
case ERROR:
|
|
|
|
default:
|
|
|
|
return (errno);
|
|
|
|
}
|
1998-08-20 08:19:55 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ack block, expect next */
|
|
|
|
static int
|
2011-05-03 04:44:50 +00:00
|
|
|
tftp_getnextblock(struct tftp_handle *h)
|
1998-08-20 08:19:55 +00:00
|
|
|
{
|
|
|
|
struct {
|
|
|
|
u_char header[HEADER_SIZE];
|
|
|
|
struct tftphdr t;
|
2011-06-15 23:22:35 +00:00
|
|
|
} __packed __aligned(4) wbuf;
|
1998-08-20 08:19:55 +00:00
|
|
|
char *wtail;
|
|
|
|
int res;
|
|
|
|
struct tftphdr *t;
|
(1) When sending the TFTP RRQ packet to read a file,
send along the "blksize" option specified in RFC2348,
and the "tsize" option specified in RFC2349.
Add code to parse the TFTP Option Acknowledgement (OACK) packet as
specified in RFC2347.
For TFTP servers which support the "blksize" option, we can
specify a TFTP Data block size larger than the default 512 bytes
specified in RFC1350. This offers greater read performance when
downloading files.
We request an initial size of 1428 bytes, which is less than the
Ethernet MTU of 1500 bytes. If the TFTP server sends back an OACK
packet, then use the block size specified in the OACK packet.
Most times it is usually the same value as what we request.
If the TFTP server supports RFC2348, we will see performance improvements
by transferring files over TFTP with larger block sizes.
If we do not get back an OACK packet, then we most likely we
are interoperating with a legacy TFTP server that does not
support TFTP extension options, so default to the block size of
512 bytes.
(2) If the "tftp.blksize" environment variable is set, then
take that value and use it when sending the TFTP RRQ packet,
instead of 1428. This allows us to set different values of
"tftp.blksize" in the loader, so that we can test out different
TFTP block sizes at run time.
Obtained from: Juniper Networks
Fixed by: rodrigc
2011-06-15 22:13:22 +00:00
|
|
|
unsigned short rtype = 0;
|
1998-08-20 08:19:55 +00:00
|
|
|
wbuf.t.th_opcode = htons((u_short) ACK);
|
|
|
|
wtail = (char *) &wbuf.t.th_block;
|
|
|
|
wbuf.t.th_block = htons((u_short) h->currblock);
|
|
|
|
wtail += 2;
|
|
|
|
|
|
|
|
t = &h->lastdata.t;
|
|
|
|
|
|
|
|
h->iodesc->xid = h->currblock + 1; /* expected block */
|
|
|
|
|
(1) When sending the TFTP RRQ packet to read a file,
send along the "blksize" option specified in RFC2348,
and the "tsize" option specified in RFC2349.
Add code to parse the TFTP Option Acknowledgement (OACK) packet as
specified in RFC2347.
For TFTP servers which support the "blksize" option, we can
specify a TFTP Data block size larger than the default 512 bytes
specified in RFC1350. This offers greater read performance when
downloading files.
We request an initial size of 1428 bytes, which is less than the
Ethernet MTU of 1500 bytes. If the TFTP server sends back an OACK
packet, then use the block size specified in the OACK packet.
Most times it is usually the same value as what we request.
If the TFTP server supports RFC2348, we will see performance improvements
by transferring files over TFTP with larger block sizes.
If we do not get back an OACK packet, then we most likely we
are interoperating with a legacy TFTP server that does not
support TFTP extension options, so default to the block size of
512 bytes.
(2) If the "tftp.blksize" environment variable is set, then
take that value and use it when sending the TFTP RRQ packet,
instead of 1428. This allows us to set different values of
"tftp.blksize" in the loader, so that we can test out different
TFTP block sizes at run time.
Obtained from: Juniper Networks
Fixed by: rodrigc
2011-06-15 22:13:22 +00:00
|
|
|
res = sendrecv_tftp(h, &sendudp, &wbuf.t, wtail - (char *) &wbuf.t,
|
|
|
|
&recvtftp, t, sizeof(*t) + h->tftp_blksize, &rtype);
|
1998-08-20 08:19:55 +00:00
|
|
|
|
|
|
|
if (res == -1) /* 0 is OK! */
|
|
|
|
return (errno);
|
|
|
|
|
|
|
|
h->currblock++;
|
|
|
|
h->validsize = res;
|
(1) When sending the TFTP RRQ packet to read a file,
send along the "blksize" option specified in RFC2348,
and the "tsize" option specified in RFC2349.
Add code to parse the TFTP Option Acknowledgement (OACK) packet as
specified in RFC2347.
For TFTP servers which support the "blksize" option, we can
specify a TFTP Data block size larger than the default 512 bytes
specified in RFC1350. This offers greater read performance when
downloading files.
We request an initial size of 1428 bytes, which is less than the
Ethernet MTU of 1500 bytes. If the TFTP server sends back an OACK
packet, then use the block size specified in the OACK packet.
Most times it is usually the same value as what we request.
If the TFTP server supports RFC2348, we will see performance improvements
by transferring files over TFTP with larger block sizes.
If we do not get back an OACK packet, then we most likely we
are interoperating with a legacy TFTP server that does not
support TFTP extension options, so default to the block size of
512 bytes.
(2) If the "tftp.blksize" environment variable is set, then
take that value and use it when sending the TFTP RRQ packet,
instead of 1428. This allows us to set different values of
"tftp.blksize" in the loader, so that we can test out different
TFTP block sizes at run time.
Obtained from: Juniper Networks
Fixed by: rodrigc
2011-06-15 22:13:22 +00:00
|
|
|
if (res < h->tftp_blksize)
|
1998-08-20 08:19:55 +00:00
|
|
|
h->islastblock = 1; /* EOF */
|
(1) When sending the TFTP RRQ packet to read a file,
send along the "blksize" option specified in RFC2348,
and the "tsize" option specified in RFC2349.
Add code to parse the TFTP Option Acknowledgement (OACK) packet as
specified in RFC2347.
For TFTP servers which support the "blksize" option, we can
specify a TFTP Data block size larger than the default 512 bytes
specified in RFC1350. This offers greater read performance when
downloading files.
We request an initial size of 1428 bytes, which is less than the
Ethernet MTU of 1500 bytes. If the TFTP server sends back an OACK
packet, then use the block size specified in the OACK packet.
Most times it is usually the same value as what we request.
If the TFTP server supports RFC2348, we will see performance improvements
by transferring files over TFTP with larger block sizes.
If we do not get back an OACK packet, then we most likely we
are interoperating with a legacy TFTP server that does not
support TFTP extension options, so default to the block size of
512 bytes.
(2) If the "tftp.blksize" environment variable is set, then
take that value and use it when sending the TFTP RRQ packet,
instead of 1428. This allows us to set different values of
"tftp.blksize" in the loader, so that we can test out different
TFTP block sizes at run time.
Obtained from: Juniper Networks
Fixed by: rodrigc
2011-06-15 22:13:22 +00:00
|
|
|
|
|
|
|
if (h->islastblock == 1) {
|
|
|
|
/* Send an ACK for the last block */
|
|
|
|
wbuf.t.th_block = htons((u_short) h->currblock);
|
|
|
|
sendudp(h->iodesc, &wbuf.t, wtail - (char *)&wbuf.t);
|
|
|
|
}
|
|
|
|
|
1998-08-20 08:19:55 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2011-05-03 04:44:50 +00:00
|
|
|
tftp_open(const char *path, struct open_file *f)
|
1998-08-20 08:19:55 +00:00
|
|
|
{
|
|
|
|
struct tftp_handle *tftpfile;
|
|
|
|
struct iodesc *io;
|
|
|
|
int res;
|
|
|
|
|
2003-03-03 00:58:47 +00:00
|
|
|
#ifndef __i386__
|
2002-07-07 23:01:36 +00:00
|
|
|
if (strcmp(f->f_dev->dv_name, "net") != 0)
|
|
|
|
return (EINVAL);
|
|
|
|
#endif
|
2003-03-03 00:58:47 +00:00
|
|
|
|
(1) When sending the TFTP RRQ packet to read a file,
send along the "blksize" option specified in RFC2348,
and the "tsize" option specified in RFC2349.
Add code to parse the TFTP Option Acknowledgement (OACK) packet as
specified in RFC2347.
For TFTP servers which support the "blksize" option, we can
specify a TFTP Data block size larger than the default 512 bytes
specified in RFC1350. This offers greater read performance when
downloading files.
We request an initial size of 1428 bytes, which is less than the
Ethernet MTU of 1500 bytes. If the TFTP server sends back an OACK
packet, then use the block size specified in the OACK packet.
Most times it is usually the same value as what we request.
If the TFTP server supports RFC2348, we will see performance improvements
by transferring files over TFTP with larger block sizes.
If we do not get back an OACK packet, then we most likely we
are interoperating with a legacy TFTP server that does not
support TFTP extension options, so default to the block size of
512 bytes.
(2) If the "tftp.blksize" environment variable is set, then
take that value and use it when sending the TFTP RRQ packet,
instead of 1428. This allows us to set different values of
"tftp.blksize" in the loader, so that we can test out different
TFTP block sizes at run time.
Obtained from: Juniper Networks
Fixed by: rodrigc
2011-06-15 22:13:22 +00:00
|
|
|
if (is_open)
|
|
|
|
return (EBUSY);
|
|
|
|
|
1998-08-20 08:19:55 +00:00
|
|
|
tftpfile = (struct tftp_handle *) malloc(sizeof(*tftpfile));
|
|
|
|
if (!tftpfile)
|
|
|
|
return (ENOMEM);
|
|
|
|
|
(1) When sending the TFTP RRQ packet to read a file,
send along the "blksize" option specified in RFC2348,
and the "tsize" option specified in RFC2349.
Add code to parse the TFTP Option Acknowledgement (OACK) packet as
specified in RFC2347.
For TFTP servers which support the "blksize" option, we can
specify a TFTP Data block size larger than the default 512 bytes
specified in RFC1350. This offers greater read performance when
downloading files.
We request an initial size of 1428 bytes, which is less than the
Ethernet MTU of 1500 bytes. If the TFTP server sends back an OACK
packet, then use the block size specified in the OACK packet.
Most times it is usually the same value as what we request.
If the TFTP server supports RFC2348, we will see performance improvements
by transferring files over TFTP with larger block sizes.
If we do not get back an OACK packet, then we most likely we
are interoperating with a legacy TFTP server that does not
support TFTP extension options, so default to the block size of
512 bytes.
(2) If the "tftp.blksize" environment variable is set, then
take that value and use it when sending the TFTP RRQ packet,
instead of 1428. This allows us to set different values of
"tftp.blksize" in the loader, so that we can test out different
TFTP block sizes at run time.
Obtained from: Juniper Networks
Fixed by: rodrigc
2011-06-15 22:13:22 +00:00
|
|
|
memset(tftpfile, 0, sizeof(*tftpfile));
|
|
|
|
tftpfile->tftp_blksize = TFTP_REQUESTED_BLKSIZE;
|
1998-08-20 08:19:55 +00:00
|
|
|
tftpfile->iodesc = io = socktodesc(*(int *) (f->f_devdata));
|
2000-12-08 05:02:12 +00:00
|
|
|
if (io == NULL)
|
|
|
|
return (EINVAL);
|
|
|
|
|
1998-08-20 08:19:55 +00:00
|
|
|
io->destip = servip;
|
|
|
|
tftpfile->off = 0;
|
1998-09-18 22:58:01 +00:00
|
|
|
tftpfile->path = strdup(path);
|
|
|
|
if (tftpfile->path == NULL) {
|
|
|
|
free(tftpfile);
|
|
|
|
return(ENOMEM);
|
|
|
|
}
|
1998-08-20 08:19:55 +00:00
|
|
|
|
2009-05-31 21:29:07 +00:00
|
|
|
res = tftp_makereq(tftpfile);
|
1998-08-20 08:19:55 +00:00
|
|
|
|
|
|
|
if (res) {
|
1998-09-18 22:58:01 +00:00
|
|
|
free(tftpfile->path);
|
1998-08-20 08:19:55 +00:00
|
|
|
free(tftpfile);
|
|
|
|
return (res);
|
|
|
|
}
|
|
|
|
f->f_fsdata = (void *) tftpfile;
|
(1) When sending the TFTP RRQ packet to read a file,
send along the "blksize" option specified in RFC2348,
and the "tsize" option specified in RFC2349.
Add code to parse the TFTP Option Acknowledgement (OACK) packet as
specified in RFC2347.
For TFTP servers which support the "blksize" option, we can
specify a TFTP Data block size larger than the default 512 bytes
specified in RFC1350. This offers greater read performance when
downloading files.
We request an initial size of 1428 bytes, which is less than the
Ethernet MTU of 1500 bytes. If the TFTP server sends back an OACK
packet, then use the block size specified in the OACK packet.
Most times it is usually the same value as what we request.
If the TFTP server supports RFC2348, we will see performance improvements
by transferring files over TFTP with larger block sizes.
If we do not get back an OACK packet, then we most likely we
are interoperating with a legacy TFTP server that does not
support TFTP extension options, so default to the block size of
512 bytes.
(2) If the "tftp.blksize" environment variable is set, then
take that value and use it when sending the TFTP RRQ packet,
instead of 1428. This allows us to set different values of
"tftp.blksize" in the loader, so that we can test out different
TFTP block sizes at run time.
Obtained from: Juniper Networks
Fixed by: rodrigc
2011-06-15 22:13:22 +00:00
|
|
|
is_open = 1;
|
1998-08-20 08:19:55 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2011-05-03 04:44:50 +00:00
|
|
|
tftp_read(struct open_file *f, void *addr, size_t size,
|
|
|
|
size_t *resid /* out */)
|
1998-08-20 08:19:55 +00:00
|
|
|
{
|
|
|
|
struct tftp_handle *tftpfile;
|
|
|
|
static int tc = 0;
|
|
|
|
tftpfile = (struct tftp_handle *) f->f_fsdata;
|
|
|
|
|
|
|
|
while (size > 0) {
|
|
|
|
int needblock, count;
|
|
|
|
|
|
|
|
if (!(tc++ % 16))
|
|
|
|
twiddle();
|
|
|
|
|
(1) When sending the TFTP RRQ packet to read a file,
send along the "blksize" option specified in RFC2348,
and the "tsize" option specified in RFC2349.
Add code to parse the TFTP Option Acknowledgement (OACK) packet as
specified in RFC2347.
For TFTP servers which support the "blksize" option, we can
specify a TFTP Data block size larger than the default 512 bytes
specified in RFC1350. This offers greater read performance when
downloading files.
We request an initial size of 1428 bytes, which is less than the
Ethernet MTU of 1500 bytes. If the TFTP server sends back an OACK
packet, then use the block size specified in the OACK packet.
Most times it is usually the same value as what we request.
If the TFTP server supports RFC2348, we will see performance improvements
by transferring files over TFTP with larger block sizes.
If we do not get back an OACK packet, then we most likely we
are interoperating with a legacy TFTP server that does not
support TFTP extension options, so default to the block size of
512 bytes.
(2) If the "tftp.blksize" environment variable is set, then
take that value and use it when sending the TFTP RRQ packet,
instead of 1428. This allows us to set different values of
"tftp.blksize" in the loader, so that we can test out different
TFTP block sizes at run time.
Obtained from: Juniper Networks
Fixed by: rodrigc
2011-06-15 22:13:22 +00:00
|
|
|
needblock = tftpfile->off / tftpfile->tftp_blksize + 1;
|
1998-08-20 08:19:55 +00:00
|
|
|
|
|
|
|
if (tftpfile->currblock > needblock) /* seek backwards */
|
|
|
|
tftp_makereq(tftpfile); /* no error check, it worked
|
|
|
|
* for open */
|
|
|
|
|
|
|
|
while (tftpfile->currblock < needblock) {
|
|
|
|
int res;
|
|
|
|
|
|
|
|
res = tftp_getnextblock(tftpfile);
|
|
|
|
if (res) { /* no answer */
|
2011-05-03 07:46:02 +00:00
|
|
|
#ifdef TFTP_DEBUG
|
1998-08-20 08:19:55 +00:00
|
|
|
printf("tftp: read error\n");
|
|
|
|
#endif
|
|
|
|
return (res);
|
|
|
|
}
|
|
|
|
if (tftpfile->islastblock)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tftpfile->currblock == needblock) {
|
|
|
|
int offinblock, inbuffer;
|
|
|
|
|
(1) When sending the TFTP RRQ packet to read a file,
send along the "blksize" option specified in RFC2348,
and the "tsize" option specified in RFC2349.
Add code to parse the TFTP Option Acknowledgement (OACK) packet as
specified in RFC2347.
For TFTP servers which support the "blksize" option, we can
specify a TFTP Data block size larger than the default 512 bytes
specified in RFC1350. This offers greater read performance when
downloading files.
We request an initial size of 1428 bytes, which is less than the
Ethernet MTU of 1500 bytes. If the TFTP server sends back an OACK
packet, then use the block size specified in the OACK packet.
Most times it is usually the same value as what we request.
If the TFTP server supports RFC2348, we will see performance improvements
by transferring files over TFTP with larger block sizes.
If we do not get back an OACK packet, then we most likely we
are interoperating with a legacy TFTP server that does not
support TFTP extension options, so default to the block size of
512 bytes.
(2) If the "tftp.blksize" environment variable is set, then
take that value and use it when sending the TFTP RRQ packet,
instead of 1428. This allows us to set different values of
"tftp.blksize" in the loader, so that we can test out different
TFTP block sizes at run time.
Obtained from: Juniper Networks
Fixed by: rodrigc
2011-06-15 22:13:22 +00:00
|
|
|
offinblock = tftpfile->off % tftpfile->tftp_blksize;
|
1998-08-20 08:19:55 +00:00
|
|
|
|
|
|
|
inbuffer = tftpfile->validsize - offinblock;
|
|
|
|
if (inbuffer < 0) {
|
2011-05-03 07:46:02 +00:00
|
|
|
#ifdef TFTP_DEBUG
|
1998-08-20 08:19:55 +00:00
|
|
|
printf("tftp: invalid offset %d\n",
|
|
|
|
tftpfile->off);
|
|
|
|
#endif
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
count = (size < inbuffer ? size : inbuffer);
|
|
|
|
bcopy(tftpfile->lastdata.t.th_data + offinblock,
|
|
|
|
addr, count);
|
|
|
|
|
2004-10-03 15:58:20 +00:00
|
|
|
addr = (char *)addr + count;
|
1998-08-20 08:19:55 +00:00
|
|
|
tftpfile->off += count;
|
|
|
|
size -= count;
|
|
|
|
|
|
|
|
if ((tftpfile->islastblock) && (count == inbuffer))
|
|
|
|
break; /* EOF */
|
|
|
|
} else {
|
2011-05-03 07:46:02 +00:00
|
|
|
#ifdef TFTP_DEBUG
|
1998-08-20 08:19:55 +00:00
|
|
|
printf("tftp: block %d not found\n", needblock);
|
|
|
|
#endif
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (resid)
|
|
|
|
*resid = size;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2011-05-03 04:44:50 +00:00
|
|
|
tftp_close(struct open_file *f)
|
1998-08-20 08:19:55 +00:00
|
|
|
{
|
|
|
|
struct tftp_handle *tftpfile;
|
|
|
|
tftpfile = (struct tftp_handle *) f->f_fsdata;
|
|
|
|
|
|
|
|
/* let it time out ... */
|
|
|
|
|
1998-09-18 22:58:01 +00:00
|
|
|
if (tftpfile) {
|
|
|
|
free(tftpfile->path);
|
1998-08-20 08:19:55 +00:00
|
|
|
free(tftpfile);
|
1998-09-18 22:58:01 +00:00
|
|
|
}
|
(1) When sending the TFTP RRQ packet to read a file,
send along the "blksize" option specified in RFC2348,
and the "tsize" option specified in RFC2349.
Add code to parse the TFTP Option Acknowledgement (OACK) packet as
specified in RFC2347.
For TFTP servers which support the "blksize" option, we can
specify a TFTP Data block size larger than the default 512 bytes
specified in RFC1350. This offers greater read performance when
downloading files.
We request an initial size of 1428 bytes, which is less than the
Ethernet MTU of 1500 bytes. If the TFTP server sends back an OACK
packet, then use the block size specified in the OACK packet.
Most times it is usually the same value as what we request.
If the TFTP server supports RFC2348, we will see performance improvements
by transferring files over TFTP with larger block sizes.
If we do not get back an OACK packet, then we most likely we
are interoperating with a legacy TFTP server that does not
support TFTP extension options, so default to the block size of
512 bytes.
(2) If the "tftp.blksize" environment variable is set, then
take that value and use it when sending the TFTP RRQ packet,
instead of 1428. This allows us to set different values of
"tftp.blksize" in the loader, so that we can test out different
TFTP block sizes at run time.
Obtained from: Juniper Networks
Fixed by: rodrigc
2011-06-15 22:13:22 +00:00
|
|
|
is_open = 0;
|
1998-08-20 08:19:55 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2011-05-03 04:44:50 +00:00
|
|
|
tftp_write(struct open_file *f __unused, void *start __unused, size_t size __unused,
|
(1) When sending the TFTP RRQ packet to read a file,
send along the "blksize" option specified in RFC2348,
and the "tsize" option specified in RFC2349.
Add code to parse the TFTP Option Acknowledgement (OACK) packet as
specified in RFC2347.
For TFTP servers which support the "blksize" option, we can
specify a TFTP Data block size larger than the default 512 bytes
specified in RFC1350. This offers greater read performance when
downloading files.
We request an initial size of 1428 bytes, which is less than the
Ethernet MTU of 1500 bytes. If the TFTP server sends back an OACK
packet, then use the block size specified in the OACK packet.
Most times it is usually the same value as what we request.
If the TFTP server supports RFC2348, we will see performance improvements
by transferring files over TFTP with larger block sizes.
If we do not get back an OACK packet, then we most likely we
are interoperating with a legacy TFTP server that does not
support TFTP extension options, so default to the block size of
512 bytes.
(2) If the "tftp.blksize" environment variable is set, then
take that value and use it when sending the TFTP RRQ packet,
instead of 1428. This allows us to set different values of
"tftp.blksize" in the loader, so that we can test out different
TFTP block sizes at run time.
Obtained from: Juniper Networks
Fixed by: rodrigc
2011-06-15 22:13:22 +00:00
|
|
|
size_t *resid __unused /* out */)
|
1998-08-20 08:19:55 +00:00
|
|
|
{
|
|
|
|
return (EROFS);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
(1) When sending the TFTP RRQ packet to read a file,
send along the "blksize" option specified in RFC2348,
and the "tsize" option specified in RFC2349.
Add code to parse the TFTP Option Acknowledgement (OACK) packet as
specified in RFC2347.
For TFTP servers which support the "blksize" option, we can
specify a TFTP Data block size larger than the default 512 bytes
specified in RFC1350. This offers greater read performance when
downloading files.
We request an initial size of 1428 bytes, which is less than the
Ethernet MTU of 1500 bytes. If the TFTP server sends back an OACK
packet, then use the block size specified in the OACK packet.
Most times it is usually the same value as what we request.
If the TFTP server supports RFC2348, we will see performance improvements
by transferring files over TFTP with larger block sizes.
If we do not get back an OACK packet, then we most likely we
are interoperating with a legacy TFTP server that does not
support TFTP extension options, so default to the block size of
512 bytes.
(2) If the "tftp.blksize" environment variable is set, then
take that value and use it when sending the TFTP RRQ packet,
instead of 1428. This allows us to set different values of
"tftp.blksize" in the loader, so that we can test out different
TFTP block sizes at run time.
Obtained from: Juniper Networks
Fixed by: rodrigc
2011-06-15 22:13:22 +00:00
|
|
|
tftp_stat(struct open_file *f, struct stat *sb)
|
1998-08-20 08:19:55 +00:00
|
|
|
{
|
|
|
|
struct tftp_handle *tftpfile;
|
|
|
|
tftpfile = (struct tftp_handle *) f->f_fsdata;
|
|
|
|
|
2000-04-08 01:18:04 +00:00
|
|
|
sb->st_mode = 0444 | S_IFREG;
|
1998-08-20 08:19:55 +00:00
|
|
|
sb->st_nlink = 1;
|
|
|
|
sb->st_uid = 0;
|
|
|
|
sb->st_gid = 0;
|
|
|
|
sb->st_size = -1;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static off_t
|
2011-05-03 04:44:50 +00:00
|
|
|
tftp_seek(struct open_file *f, off_t offset, int where)
|
1998-08-20 08:19:55 +00:00
|
|
|
{
|
|
|
|
struct tftp_handle *tftpfile;
|
|
|
|
tftpfile = (struct tftp_handle *) f->f_fsdata;
|
|
|
|
|
|
|
|
switch (where) {
|
|
|
|
case SEEK_SET:
|
|
|
|
tftpfile->off = offset;
|
|
|
|
break;
|
|
|
|
case SEEK_CUR:
|
|
|
|
tftpfile->off += offset;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
errno = EOFFSET;
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
return (tftpfile->off);
|
|
|
|
}
|
2011-06-15 22:04:14 +00:00
|
|
|
|
|
|
|
static ssize_t
|
(1) When sending the TFTP RRQ packet to read a file,
send along the "blksize" option specified in RFC2348,
and the "tsize" option specified in RFC2349.
Add code to parse the TFTP Option Acknowledgement (OACK) packet as
specified in RFC2347.
For TFTP servers which support the "blksize" option, we can
specify a TFTP Data block size larger than the default 512 bytes
specified in RFC1350. This offers greater read performance when
downloading files.
We request an initial size of 1428 bytes, which is less than the
Ethernet MTU of 1500 bytes. If the TFTP server sends back an OACK
packet, then use the block size specified in the OACK packet.
Most times it is usually the same value as what we request.
If the TFTP server supports RFC2348, we will see performance improvements
by transferring files over TFTP with larger block sizes.
If we do not get back an OACK packet, then we most likely we
are interoperating with a legacy TFTP server that does not
support TFTP extension options, so default to the block size of
512 bytes.
(2) If the "tftp.blksize" environment variable is set, then
take that value and use it when sending the TFTP RRQ packet,
instead of 1428. This allows us to set different values of
"tftp.blksize" in the loader, so that we can test out different
TFTP block sizes at run time.
Obtained from: Juniper Networks
Fixed by: rodrigc
2011-06-15 22:13:22 +00:00
|
|
|
sendrecv_tftp(struct tftp_handle *h,
|
|
|
|
ssize_t (*sproc)(struct iodesc *, void *, size_t),
|
|
|
|
void *sbuf, size_t ssize,
|
|
|
|
ssize_t (*rproc)(struct tftp_handle *, void *, ssize_t, time_t, unsigned short *),
|
|
|
|
void *rbuf, size_t rsize, unsigned short *rtype)
|
2011-06-15 22:04:14 +00:00
|
|
|
{
|
(1) When sending the TFTP RRQ packet to read a file,
send along the "blksize" option specified in RFC2348,
and the "tsize" option specified in RFC2349.
Add code to parse the TFTP Option Acknowledgement (OACK) packet as
specified in RFC2347.
For TFTP servers which support the "blksize" option, we can
specify a TFTP Data block size larger than the default 512 bytes
specified in RFC1350. This offers greater read performance when
downloading files.
We request an initial size of 1428 bytes, which is less than the
Ethernet MTU of 1500 bytes. If the TFTP server sends back an OACK
packet, then use the block size specified in the OACK packet.
Most times it is usually the same value as what we request.
If the TFTP server supports RFC2348, we will see performance improvements
by transferring files over TFTP with larger block sizes.
If we do not get back an OACK packet, then we most likely we
are interoperating with a legacy TFTP server that does not
support TFTP extension options, so default to the block size of
512 bytes.
(2) If the "tftp.blksize" environment variable is set, then
take that value and use it when sending the TFTP RRQ packet,
instead of 1428. This allows us to set different values of
"tftp.blksize" in the loader, so that we can test out different
TFTP block sizes at run time.
Obtained from: Juniper Networks
Fixed by: rodrigc
2011-06-15 22:13:22 +00:00
|
|
|
struct iodesc *d = h->iodesc;
|
2011-06-15 22:04:14 +00:00
|
|
|
ssize_t cc;
|
|
|
|
time_t t, t1, tleft;
|
|
|
|
|
|
|
|
#ifdef TFTP_DEBUG
|
|
|
|
if (debug)
|
|
|
|
printf("sendrecv: called\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
tleft = MINTMO;
|
|
|
|
t = t1 = getsecs();
|
|
|
|
for (;;) {
|
|
|
|
if ((getsecs() - t) > MAXTMO) {
|
|
|
|
errno = ETIMEDOUT;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
cc = (*sproc)(d, sbuf, ssize);
|
|
|
|
if (cc != -1 && cc < ssize)
|
|
|
|
panic("sendrecv: short write! (%zd < %zu)",
|
|
|
|
cc, ssize);
|
|
|
|
|
|
|
|
if (cc == -1) {
|
|
|
|
/* Error on transmit; wait before retrying */
|
|
|
|
while ((getsecs() - t1) < tleft);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-06-15 22:08:18 +00:00
|
|
|
recvnext:
|
2011-06-15 22:04:14 +00:00
|
|
|
/* Try to get a packet and process it. */
|
(1) When sending the TFTP RRQ packet to read a file,
send along the "blksize" option specified in RFC2348,
and the "tsize" option specified in RFC2349.
Add code to parse the TFTP Option Acknowledgement (OACK) packet as
specified in RFC2347.
For TFTP servers which support the "blksize" option, we can
specify a TFTP Data block size larger than the default 512 bytes
specified in RFC1350. This offers greater read performance when
downloading files.
We request an initial size of 1428 bytes, which is less than the
Ethernet MTU of 1500 bytes. If the TFTP server sends back an OACK
packet, then use the block size specified in the OACK packet.
Most times it is usually the same value as what we request.
If the TFTP server supports RFC2348, we will see performance improvements
by transferring files over TFTP with larger block sizes.
If we do not get back an OACK packet, then we most likely we
are interoperating with a legacy TFTP server that does not
support TFTP extension options, so default to the block size of
512 bytes.
(2) If the "tftp.blksize" environment variable is set, then
take that value and use it when sending the TFTP RRQ packet,
instead of 1428. This allows us to set different values of
"tftp.blksize" in the loader, so that we can test out different
TFTP block sizes at run time.
Obtained from: Juniper Networks
Fixed by: rodrigc
2011-06-15 22:13:22 +00:00
|
|
|
cc = (*rproc)(h, rbuf, rsize, tleft, rtype);
|
2011-06-15 22:04:14 +00:00
|
|
|
/* Return on data, EOF or real error. */
|
|
|
|
if (cc != -1 || errno != 0)
|
|
|
|
return (cc);
|
2011-06-15 22:08:18 +00:00
|
|
|
if ((getsecs() - t1) < tleft) {
|
|
|
|
goto recvnext;
|
|
|
|
}
|
2011-06-15 22:04:14 +00:00
|
|
|
|
|
|
|
/* Timed out or didn't get the packet we're waiting for */
|
|
|
|
tleft += MINTMO;
|
|
|
|
if (tleft > (2 * MINTMO)) {
|
|
|
|
tleft = (2 * MINTMO);
|
|
|
|
}
|
|
|
|
t1 = getsecs();
|
|
|
|
}
|
|
|
|
}
|
(1) When sending the TFTP RRQ packet to read a file,
send along the "blksize" option specified in RFC2348,
and the "tsize" option specified in RFC2349.
Add code to parse the TFTP Option Acknowledgement (OACK) packet as
specified in RFC2347.
For TFTP servers which support the "blksize" option, we can
specify a TFTP Data block size larger than the default 512 bytes
specified in RFC1350. This offers greater read performance when
downloading files.
We request an initial size of 1428 bytes, which is less than the
Ethernet MTU of 1500 bytes. If the TFTP server sends back an OACK
packet, then use the block size specified in the OACK packet.
Most times it is usually the same value as what we request.
If the TFTP server supports RFC2348, we will see performance improvements
by transferring files over TFTP with larger block sizes.
If we do not get back an OACK packet, then we most likely we
are interoperating with a legacy TFTP server that does not
support TFTP extension options, so default to the block size of
512 bytes.
(2) If the "tftp.blksize" environment variable is set, then
take that value and use it when sending the TFTP RRQ packet,
instead of 1428. This allows us to set different values of
"tftp.blksize" in the loader, so that we can test out different
TFTP block sizes at run time.
Obtained from: Juniper Networks
Fixed by: rodrigc
2011-06-15 22:13:22 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
tftp_set_blksize(struct tftp_handle *h, const char *str)
|
|
|
|
{
|
|
|
|
char *endptr;
|
|
|
|
int new_blksize;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (h == NULL || str == NULL)
|
|
|
|
return (ret);
|
|
|
|
|
|
|
|
new_blksize =
|
|
|
|
(unsigned int)strtol(str, &endptr, 0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Only accept blksize value if it is numeric.
|
|
|
|
* RFC2348 specifies that acceptable valuesare 8-65464
|
|
|
|
* 8-65464 . Let's choose a limit less than MAXRSPACE
|
|
|
|
*/
|
|
|
|
if (*endptr == '\0' && new_blksize >= 8
|
|
|
|
&& new_blksize <= TFTP_MAX_BLKSIZE) {
|
|
|
|
h->tftp_blksize = new_blksize;
|
|
|
|
ret = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* In RFC2347, the TFTP Option Acknowledgement package (OACK)
|
|
|
|
* is used to acknowledge a client's option negotiation request.
|
|
|
|
* The format of an OACK packet is:
|
|
|
|
* +-------+---~~---+---+---~~---+---+---~~---+---+---~~---+---+
|
|
|
|
* | opc | opt1 | 0 | value1 | 0 | optN | 0 | valueN | 0 |
|
|
|
|
* +-------+---~~---+---+---~~---+---+---~~---+---+---~~---+---+
|
|
|
|
*
|
|
|
|
* opc
|
|
|
|
* The opcode field contains a 6, for Option Acknowledgment.
|
|
|
|
*
|
|
|
|
* opt1
|
|
|
|
* The first option acknowledgment, copied from the original
|
|
|
|
* request.
|
|
|
|
*
|
|
|
|
* value1
|
|
|
|
* The acknowledged value associated with the first option. If
|
|
|
|
* and how this value may differ from the original request is
|
|
|
|
* detailed in the specification for the option.
|
|
|
|
*
|
|
|
|
* optN, valueN
|
|
|
|
* The final option/value acknowledgment pair.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
tftp_parse_oack(struct tftp_handle *h, char *buf, size_t len)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* We parse the OACK strings into an array
|
|
|
|
* of name-value pairs.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
char *tftp_options[128] = { 0 };
|
|
|
|
char *val = buf;
|
|
|
|
int i = 0;
|
|
|
|
int option_idx = 0;
|
|
|
|
int blksize_is_set = 0;
|
|
|
|
int tsize = 0;
|
|
|
|
|
|
|
|
|
|
|
|
while ( option_idx < 128 && i < len ) {
|
|
|
|
if (buf[i] == '\0') {
|
|
|
|
if (&buf[i] > val) {
|
|
|
|
tftp_options[option_idx] = val;
|
|
|
|
val = &buf[i] + 1;
|
|
|
|
++option_idx;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Parse individual TFTP options.
|
|
|
|
* * "blksize" is specified in RFC2348.
|
|
|
|
* * "tsize" is specified in RFC2349.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < option_idx; i += 2) {
|
|
|
|
if (strcasecmp(tftp_options[i], "blksize") == 0) {
|
|
|
|
if (i + 1 < option_idx) {
|
|
|
|
blksize_is_set =
|
|
|
|
tftp_set_blksize(h, tftp_options[i + 1]);
|
|
|
|
}
|
|
|
|
} else if (strcasecmp(tftp_options[i], "tsize") == 0) {
|
|
|
|
if (i + 1 < option_idx) {
|
|
|
|
tsize = strtol(tftp_options[i + 1], (char **)NULL, 10);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!blksize_is_set) {
|
|
|
|
/*
|
|
|
|
* If TFTP blksize was not set, try defaulting
|
|
|
|
* to the legacy TFTP blksize of 512
|
|
|
|
*/
|
|
|
|
h->tftp_blksize = 512;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef TFTP_DEBUG
|
|
|
|
printf("tftp_blksize: %u\n", h->tftp_blksize);
|
|
|
|
printf("tftp_tsize: %lu\n", h->tftp_tsize);
|
|
|
|
#endif
|
|
|
|
}
|