svn commit: r231539 - stable/8/libexec/tftpd
Craig Rodrigues
rodrigc at FreeBSD.org
Sat Feb 11 23:39:53 UTC 2012
Author: rodrigc
Date: Sat Feb 11 23:39:53 2012
New Revision: 231539
URL: http://svn.freebsd.org/changeset/base/231539
Log:
MFC 203377-231538. This records mergeinfo for already merged
changesets, but brings in the following changes:
MFC 222326
- Fix tftp_log() usage
MFC 223137
- Man page updates
MFC 223487
- Bring back syncnet() implementation from older tftp implementation.
MFC 229780
- Spelling fixes for libexec/
MFC 229904
- Fix warning when compiling with gcc46:
error: variable 'bp' set but not used
Modified:
stable/8/libexec/tftpd/tftp-file.c
stable/8/libexec/tftpd/tftp-io.c
stable/8/libexec/tftpd/tftp-utils.h
stable/8/libexec/tftpd/tftpd.8
Directory Properties:
stable/8/libexec/tftpd/ (props changed)
Modified: stable/8/libexec/tftpd/tftp-file.c
==============================================================================
--- stable/8/libexec/tftpd/tftp-file.c Sat Feb 11 23:15:14 2012 (r231538)
+++ stable/8/libexec/tftpd/tftp-file.c Sat Feb 11 23:39:53 2012 (r231539)
@@ -27,6 +27,8 @@
__FBSDID("$FreeBSD$");
#include <sys/types.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
#include <sys/stat.h>
#include <netinet/in.h>
@@ -249,9 +251,34 @@ read_close(void)
}
+/* When an error has occurred, it is possible that the two sides
+ * are out of synch. Ie: that what I think is the other side's
+ * response to packet N is really their response to packet N-1.
+ *
+ * So, to try to prevent that, we flush all the input queued up
+ * for us on the network connection on our host.
+ *
+ * We return the number of packets we flushed (mostly for reporting
+ * when trace is active).
+ */
+
int
-synchnet(int peer __unused)
+synchnet(int peer) /* socket to flush */
{
-
- return 0;
+ int i, j = 0;
+ char rbuf[MAXPKTSIZE];
+ struct sockaddr_storage from;
+ socklen_t fromlen;
+
+ while (1) {
+ (void) ioctl(peer, FIONREAD, &i);
+ if (i) {
+ j++;
+ fromlen = sizeof from;
+ (void) recvfrom(peer, rbuf, sizeof (rbuf), 0,
+ (struct sockaddr *)&from, &fromlen);
+ } else {
+ return(j);
+ }
+ }
}
Modified: stable/8/libexec/tftpd/tftp-io.c
==============================================================================
--- stable/8/libexec/tftpd/tftp-io.c Sat Feb 11 23:15:14 2012 (r231538)
+++ stable/8/libexec/tftpd/tftp-io.c Sat Feb 11 23:39:53 2012 (r231539)
@@ -72,13 +72,13 @@ struct errmsg {
#define DROPPACKET(s) \
if (packetdroppercentage != 0 && \
random()%100 < packetdroppercentage) { \
- tftp_log(LOG_DEBUG, "Artifical packet drop in %s", s); \
+ tftp_log(LOG_DEBUG, "Artificial packet drop in %s", s); \
return; \
}
#define DROPPACKETn(s,n) \
if (packetdroppercentage != 0 && \
random()%100 < packetdroppercentage) { \
- tftp_log(LOG_DEBUG, "Artifical packet drop in %s", s); \
+ tftp_log(LOG_DEBUG, "Artificial packet drop in %s", s); \
return (n); \
}
@@ -262,7 +262,7 @@ send_rrq(int peer, char *filename, char
n = sendto(peer, buf, size, 0,
(struct sockaddr *)&peer_sock, peer_sock.ss_len);
if (n != size) {
- tftp_log(LOG_ERR, "send_rrq: %s", n, strerror(errno));
+ tftp_log(LOG_ERR, "send_rrq: %d %s", n, strerror(errno));
return (1);
}
return (0);
@@ -323,7 +323,6 @@ send_ack(int fp, uint16_t block)
{
struct tftphdr *tp;
int size;
- char *bp;
char buf[MAXPKTSIZE];
if (debug&DEBUG_PACKETS)
@@ -332,7 +331,6 @@ send_ack(int fp, uint16_t block)
DROPPACKETn("send_ack", 0);
tp = (struct tftphdr *)buf;
- bp = buf + 2;
size = sizeof(buf) - 2;
tp->th_opcode = htons((u_short)ACK);
tp->th_block = htons((u_short)block);
Modified: stable/8/libexec/tftpd/tftp-utils.h
==============================================================================
--- stable/8/libexec/tftpd/tftp-utils.h Sat Feb 11 23:15:14 2012 (r231538)
+++ stable/8/libexec/tftpd/tftp-utils.h Sat Feb 11 23:39:53 2012 (r231539)
@@ -36,11 +36,11 @@ __FBSDID("$FreeBSD$");
#define MAXPKTSIZE (MAXSEGSIZE + 4) /* Maximum size of the packet */
/* For the blksize option */
-#define BLKSIZE_MIN 8 /* Minumum size of the data segment */
+#define BLKSIZE_MIN 8 /* Minimum size of the data segment */
#define BLKSIZE_MAX MAXSEGSIZE /* Maximum size of the data segment */
/* For the timeout option */
-#define TIMEOUT_MIN 0 /* Minumum timeout value */
+#define TIMEOUT_MIN 0 /* Minimum timeout value */
#define TIMEOUT_MAX 255 /* Maximum timeout value */
#define MIN_TIMEOUTS 3
Modified: stable/8/libexec/tftpd/tftpd.8
==============================================================================
--- stable/8/libexec/tftpd/tftpd.8 Sat Feb 11 23:15:14 2012 (r231538)
+++ stable/8/libexec/tftpd/tftpd.8 Sat Feb 11 23:39:53 2012 (r231539)
@@ -32,7 +32,7 @@
.\" @(#)tftpd.8 8.1 (Berkeley) 6/4/93
.\" $FreeBSD$
.\"
-.Dd September 14, 2000
+.Dd June 22, 2011
.Dt TFTPD 8
.Os
.Sh NAME
@@ -150,9 +150,27 @@ compatible format string for the creatio
.Fl W
is specified.
By default the string "%Y%m%d" is used.
-.It Fl d
+.It Fl d, d Ar [value]
Enables debug output.
-If specified twice, it will log DATA and ACK packets too.
+If
+.Ar value
+is not specified, then the debug level is increased by one
+for each instance of
+.Fl d
+which is specified.
+.Pp
+If
+.Ar value
+is specified, then the debug level is set to
+.Ar value .
+The debug level is a bitmask implemented in
+.Pa src/libexec/tftpd/tftp-utils.h .
+Valid values are 0 (DEBUG_NONE), 1 (DEBUG_PACKETS), 2, (DEBUG_SIMPLE),
+4 (DEBUG_OPTIONS), and 8 (DEBUG_ACCESS). Multiple debug values can be combined
+in the bitmask by logically OR'ing the values. For example, specifying
+.Fl d
+.Ar 15
+will enable all the debug values.
.It Fl l
Log all requests using
.Xr syslog 3
@@ -217,12 +235,34 @@ option.
.Xr services 5 ,
.Xr syslog.conf 5 ,
.Xr inetd 8
+.Pp
+The following RFC's are supported:
.Rs
-.%A K. R. Sollins
+RFC 1350
.%T The TFTP Protocol (Revision 2)
-.%D July 1992
-.%O RFC 1350, STD 33
.Re
+.Rs
+RFC 2347
+.%T TFTP Option Extension
+.Re
+.Rs
+RFC 2348
+.%T TFTP Blocksize Option
+.Re
+.Rs
+RFC 2349
+.%T TFTP Timeout Interval and Transfer Size Options
+.Re
+.Pp
+The non-standard
+.Cm rollover
+and
+.Cm blksize2
+TFTP options are mentioned here:
+.Rs
+.%T Extending TFTP
+.%U http://www.compuphase.com/tftp.htm
+.Re
.Sh HISTORY
The
.Nm
@@ -253,8 +293,22 @@ was introduced in
support for the TFTP Blocksize Option (RFC2348) and the blksize2 option
was introduced in
.Fx 7.4 .
-.Sh BUGS
-Files larger than 33488896 octets (65535 blocks) cannot be transferred
-without client and server supporting blocksize negotiation (RFC2348).
.Pp
-Many tftp clients will not transfer files over 16744448 octets (32767 blocks).
+Edwin Groothuis <edwin at FreeBSD.org> performed a major rewrite of the
+.Nm
+and
+.Xr tftp 1
+code to support RFC2348.
+.Sh NOTES
+Files larger than 33,553,919 octets (65535 blocks, last one <512
+octets) cannot be correctly transferred without client and server
+supporting blocksize negotiation (RFCs 2347 and 2348),
+or the non-standard TFTP rollover option.
+As a kludge,
+.Nm
+accepts a sequence of block number which wrap to zero after 65535,
+even if the rollover option is not specified.
+.Pp
+Many tftp clients will not transfer files over 16,776,703 octets
+(32767 blocks), as they incorrectly count the block number using
+a signed rather than unsigned 16-bit integer.
More information about the svn-src-all
mailing list