From freebsd@wanadoo.es  Thu Jun  3 15:56:09 2004
Return-Path: <freebsd@wanadoo.es>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id C29E616A4CE
	for <FreeBSD-gnats-submit@freebsd.org>; Thu,  3 Jun 2004 15:56:09 -0700 (PDT)
Received: from smtp13.eresmas.com (smtp13.eresmas.com [62.81.235.113])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 9F7EE43D4C
	for <FreeBSD-gnats-submit@freebsd.org>; Thu,  3 Jun 2004 15:56:08 -0700 (PDT)
	(envelope-from freebsd@wanadoo.es)
Received: from [192.168.108.56] (helo=mx06.eresmas.com)
	by smtp13.eresmas.com with esmtp (Exim 4.10)
	id 1BW17u-0001zc-00
	for FreeBSD-gnats-submit@freebsd.org; Fri, 04 Jun 2004 00:55:58 +0200
Received: from [62.37.23.112] (helo=orion.animas.redesjm.local)
	by mx06.eresmas.com with esmtp (Exim 4.30)
	id 1BW17s-00042z-Fi
	for FreeBSD-gnats-submit@freebsd.org; Fri, 04 Jun 2004 00:55:57 +0200
Received: from orion.animas.redesjm.local (localhost.animas.redesjm.local [127.0.0.1])
	by orion.animas.redesjm.local (8.12.11/8.12.11) with ESMTP id i53Mu6Ij000632
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 4 Jun 2004 00:56:06 +0200 (CEST)
	(envelope-from freebsd@orion.animas.redesjm.local)
Received: (from freebsd@localhost)
	by orion.animas.redesjm.local (8.12.11/8.12.11/Submit) id i53Mu62j000631;
	Fri, 4 Jun 2004 00:56:06 +0200 (CEST)
	(envelope-from freebsd)
Message-Id: <200406032256.i53Mu62j000631@orion.animas.redesjm.local>
Date: Fri, 4 Jun 2004 00:56:06 +0200 (CEST)
From: Jose M Rodriguez <freebsd@wanadoo.es>
Reply-To: Jose M Rodriguez <freebsd@wanadoo.es>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: Add BLK_SIZE option to tftpd server
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         67550
>Category:       bin
>Synopsis:       [patch] tftpd(8) Add BLK_SIZE option to tftpd server
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Thu Jun 03 16:00:46 PDT 2004
>Closed-Date:    Fri Sep 24 15:02:39 UTC 2010
>Last-Modified:  Fri Sep 24 15:02:39 UTC 2010
>Originator:     Jose M Rodriguez
>Release:        FreeBSD Current
>Organization:
Redes JM
>Environment:
>Description:
	Add suport for BLK_SIZE option to tftpd server,
	usefult with PXE clientes.
>How-To-Repeat:
>Fix:

--- patch-tftp-blksize begins here ---
diff -Nru ../../orig/freebsd5/libexec/tftpd/tftpd.c ./libexec/tftpd/tftpd.c
--- ../../orig/freebsd5/libexec/tftpd/tftpd.c	Thu Nov 20 15:41:56 2003
+++ ./libexec/tftpd/tftpd.c	Tue May 11 03:30:36 2004
@@ -85,7 +85,11 @@
 int	rexmtval = TIMEOUT;
 int	max_rexmtval = 2*TIMEOUT;
 
-#define	PKTSIZE	SEGSIZE+4
+/* from tftpsubs.c */
+extern	int	blksize;
+
+#define	PKTSIZE	(SEGSIZE+4)	/* std packets here */
+
 char	buf[PKTSIZE];
 char	ackbuf[PKTSIZE];
 struct	sockaddr_storage from;
@@ -346,12 +350,14 @@
 } options[] = {
 	{ "tsize",	NULL, 0 },		/* OPT_TSIZE */
 	{ "timeout",	NULL, 0 },		/* OPT_TIMEOUT */
+	{ "blksize",	NULL, 0 },		/* OPT_BLKSIZE */
 	{ NULL,		NULL, 0 }
 };
 
 enum opt_enum {
 	OPT_TSIZE = 0,
 	OPT_TIMEOUT,
+	OPT_BLKSIZE,
 };
 
 /*
@@ -420,13 +426,13 @@
 		for (i = 0; options[i].o_type != NULL; i++)
 			if (strcmp(option, options[i].o_type) == 0) {
 				options[i].o_request = ++cp;
-				has_options = 1;
+				++has_options;
 			}
 		cp = ccp-1;
 	}
 
 option_fail:
-	if (options[OPT_TIMEOUT].o_request) {
+	if (has_options > 0 && options[OPT_TIMEOUT].o_request) {
 		int to = atoi(options[OPT_TIMEOUT].o_request);
 		if (to < 1 || to > 255) {
 			nak(EBADOP);
@@ -436,6 +442,21 @@
 			options[OPT_TIMEOUT].o_reply = rexmtval = to;
 		else
 			options[OPT_TIMEOUT].o_request = NULL;
+			--has_options;
+	}
+	if (has_options >0  && options[OPT_BLKSIZE].o_request) {
+		int bsz = atoi(options[OPT_BLKSIZE].o_request);
+		if (bsz < 8 || bsz > 65464) {
+			nak(EBADOP);
+			exit(1);
+		}
+		else if (bsz <= SEGSIZE) {
+			options[OPT_BLKSIZE].o_request = NULL;
+			--has_options;
+		}
+		else
+			options[OPT_BLKSIZE].o_reply =
+			blksize = (bsz > MAXBLKSIZE)? MAXBLKSIZE : bsz;
 	}
 
 	ecode = (*pf->f_validate)(&filename, tp->th_opcode);
@@ -653,7 +674,7 @@
 
 		}
 		block++;
-	} while (size == SEGSIZE);
+	} while (size == blksize);
 abort:
 	(void) fclose(file);
 }
@@ -721,7 +742,7 @@
 			else nak(ENOSPACE);
 			goto abort;
 		}
-	} while (size == SEGSIZE);
+	} while (size == blksize);
 	write_behind(file, pf->f_convert);
 	(void) fclose(file);            /* close data file */
 
diff -Nru ../../orig/freebsd5/usr.bin/tftp/tftpsubs.c ./usr.bin/tftp/tftpsubs.c
--- ../../orig/freebsd5/usr.bin/tftp/tftpsubs.c	Thu Apr 11 19:14:22 2002
+++ ./usr.bin/tftp/tftpsubs.c	Tue May 11 03:30:36 2004
@@ -61,7 +61,10 @@
 
 #include "tftpsubs.h"
 
-#define PKTSIZE SEGSIZE+4       /* should be moved to tftp.h */
+/* blksize option support */
+int	blksize = SEGSIZE;
+
+#define PKTSIZE (MAXBLKSIZE+4)	/* extended packets here */
 
 struct bf {
 	int counter;            /* size of data in buffer, or flag */
@@ -71,7 +74,7 @@
 				/* Values for bf.counter  */
 #define BF_ALLOC -3             /* alloc'd but not yet filled */
 #define BF_FREE  -2             /* free */
-/* [-1 .. SEGSIZE] = size of data in the data buffer */
+/* [-1 .. blksize] = size of data in the data buffer */
 
 static int nextone;		/* index of next buffer to use */
 static int current;		/* index of buffer in use */
@@ -144,12 +147,12 @@
 	dp = (struct tftphdr *)b->buf;
 
 	if (convert == 0) {
-		b->counter = read(fileno(file), dp->th_data, SEGSIZE);
+		b->counter = read(fileno(file), dp->th_data, blksize);
 		return;
 	}
 
 	p = dp->th_data;
-	for (i = 0 ; i < SEGSIZE; i++) {
+	for (i = 0 ; i < blksize; i++) {
 		if (newline) {
 			if (prevchar == '\n')
 				c = '\n';       /* lf to cr,lf */
diff -Nru ../../orig/freebsd5/usr.bin/tftp/tftpsubs.h ./usr.bin/tftp/tftpsubs.h
--- ../../orig/freebsd5/usr.bin/tftp/tftpsubs.h	Fri Mar 22 02:42:34 2002
+++ ./usr.bin/tftp/tftpsubs.h	Tue May 11 03:30:36 2004
@@ -35,6 +35,14 @@
  */
 
 /*
+ * blksize max: 8 .. 65464
+ */
+
+#if !defined(MAXBLKSIZE) || (MAXBLKSIZE<=SEGSIZE)
+#define	MAXBLKSIZE	(1500-4-8)
+#endif
+
+/*
  * Prototypes for read-ahead/write-behind subroutines for tftp user and
  * server.
  */
--- patch-tftp-blksize ends here ---


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->edwin 
Responsible-Changed-By: edwin 
Responsible-Changed-When: Sun Oct 7 08:38:06 UTC 2007 
Responsible-Changed-Why:  
Grab it and merge into my implementation. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=67550 
Responsible-Changed-From-To: edwin->freebsd-bugs 
Responsible-Changed-By: edwin 
Responsible-Changed-When: Thu Feb 14 10:27:36 UTC 2008 
Responsible-Changed-Why:  

Give back into the pool until later. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=67550 
State-Changed-From-To: open->patched 
State-Changed-By: imp 
State-Changed-When: Tue May 4 08:47:24 MDT 2010 
State-Changed-Why:  
New tftpd fixes this 


http://www.freebsd.org/cgi/query-pr.cgi?pr=67550 
State-Changed-From-To: patched->closed 
State-Changed-By: marius 
State-Changed-When: Fri Sep 24 15:02:22 UTC 2010 
State-Changed-Why:  
Close; the "new" tftpd(8) was merged to stable/8 in 213038 and to stable/7 
in r213039 respectively. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=67550 
>Unformatted:
