Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 12 Feb 2012 01:07:15 +0000 (UTC)
From:      Craig Rodrigues <rodrigc@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-7@freebsd.org
Subject:   svn commit: r231541 - stable/7/libexec/tftpd
Message-ID:  <201202120107.q1C17FJq058329@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: rodrigc
Date: Sun Feb 12 01:07:15 2012
New Revision: 231541
URL: http://svn.freebsd.org/changeset/base/231541

Log:
  MFC 183243-231540.  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/7/libexec/tftpd/tftp-file.c
  stable/7/libexec/tftpd/tftp-io.c
  stable/7/libexec/tftpd/tftp-utils.c
  stable/7/libexec/tftpd/tftp-utils.h
  stable/7/libexec/tftpd/tftpd.8
Directory Properties:
  stable/7/libexec/tftpd/   (props changed)

Modified: stable/7/libexec/tftpd/tftp-file.c
==============================================================================
--- stable/7/libexec/tftpd/tftp-file.c	Sat Feb 11 23:58:07 2012	(r231540)
+++ stable/7/libexec/tftpd/tftp-file.c	Sun Feb 12 01:07:15 2012	(r231541)
@@ -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/7/libexec/tftpd/tftp-io.c
==============================================================================
--- stable/7/libexec/tftpd/tftp-io.c	Sat Feb 11 23:58:07 2012	(r231540)
+++ stable/7/libexec/tftpd/tftp-io.c	Sun Feb 12 01:07:15 2012	(r231541)
@@ -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/7/libexec/tftpd/tftp-utils.c
==============================================================================
--- stable/7/libexec/tftpd/tftp-utils.c	Sat Feb 11 23:58:07 2012	(r231540)
+++ stable/7/libexec/tftpd/tftp-utils.c	Sun Feb 12 01:07:15 2012	(r231541)
@@ -100,7 +100,7 @@ unmappedaddr(struct sockaddr_in6 *sin6)
 	sin4->sin_len = sizeof(struct sockaddr_in);
 }
 
-/* Get a field from a \0 seperated string */
+/* Get a field from a \0 separated string */
 ssize_t
 get_field(int peer, char *buffer, ssize_t size)
 {

Modified: stable/7/libexec/tftpd/tftp-utils.h
==============================================================================
--- stable/7/libexec/tftpd/tftp-utils.h	Sat Feb 11 23:58:07 2012	(r231540)
+++ stable/7/libexec/tftpd/tftp-utils.h	Sun Feb 12 01:07:15 2012	(r231541)
@@ -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/7/libexec/tftpd/tftpd.8
==============================================================================
--- stable/7/libexec/tftpd/tftpd.8	Sat Feb 11 23:58:07 2012	(r231540)
+++ stable/7/libexec/tftpd/tftpd.8	Sun Feb 12 01:07:15 2012	(r231541)
@@ -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@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.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201202120107.q1C17FJq058329>