bin/67550: Add BLK_SIZE option to tftpd server
Jose M Rodriguez
freebsd at wanadoo.es
Thu Jun 3 16:00:47 PDT 2004
>Number: 67550
>Category: bin
>Synopsis: Add BLK_SIZE option to tftpd server
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: change-request
>Submitter-Id: current-users
>Arrival-Date: Thu Jun 03 16:00:46 PDT 2004
>Closed-Date:
>Last-Modified:
>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:
>Unformatted:
More information about the freebsd-bugs
mailing list