From owner-freebsd-bugs@FreeBSD.ORG Thu Jun 3 16:00:47 2004 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 11E4716A4D0 for ; Thu, 3 Jun 2004 16:00:47 -0700 (PDT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 0244543D55 for ; Thu, 3 Jun 2004 16:00:47 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) i53N0kPm046025 for ; Thu, 3 Jun 2004 16:00:46 -0700 (PDT) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.11/8.12.11/Submit) id i53N0kdw046024; Thu, 3 Jun 2004 16:00:46 -0700 (PDT) (envelope-from gnats) Resent-Date: Thu, 3 Jun 2004 16:00:46 -0700 (PDT) Resent-Message-Id: <200406032300.i53N0kdw046024@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Jose M Rodriguez Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id C29E616A4CE for ; 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 ; 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])i53Mu6Ij000632 for ; Fri, 4 Jun 2004 00:56:06 +0200 (CEST) (envelope-from freebsd@orion.animas.redesjm.local) Received: (from freebsd@localhost)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 To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Subject: bin/67550: Add BLK_SIZE option to tftpd server X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: Jose M Rodriguez List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 Jun 2004 23:00:47 -0000 >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: