Blame SOURCES/0065-curl-7.29.0-tftp-speed-limit.patch

6311d4
From 71e1317a4b44d9d81ec99c46038ada32c0e51bc9 Mon Sep 17 00:00:00 2001
6311d4
From: Daniel Stenberg <daniel@haxx.se>
6311d4
Date: Thu, 22 Aug 2013 19:23:08 +0200
6311d4
Subject: [PATCH 1/2] tftpd: support "writedelay" within <servercmd>
6311d4
6311d4
Upstream-commit: 06d1b10cbefaa7c54c73e09df746ae79b7f14e14
6311d4
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
6311d4
---
6311d4
 tests/FILEFORMAT     |  4 +++
6311d4
 tests/server/tftpd.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++--
6311d4
 2 files changed, 84 insertions(+), 3 deletions(-)
6311d4
6311d4
diff --git a/tests/FILEFORMAT b/tests/FILEFORMAT
6311d4
index 702368f..4759668 100644
6311d4
--- a/tests/FILEFORMAT
6311d4
+++ b/tests/FILEFORMAT
6311d4
@@ -137,6 +137,10 @@ rtp: part [num] channel [num] size [num]
6311d4
 connection-monitor When used, this will log [DISCONNECT] to the server.input
6311d4
                log when the connection is disconnected.
6311d4
 
6311d4
+
6311d4
+For TFTP:
6311d4
+writedelay: [secs] delay this amount between reply packets (each packet being
6311d4
+                   512 bytes payload)
6311d4
 </servercmd>
6311d4
 </reply>
6311d4
 
6311d4
diff --git a/tests/server/tftpd.c b/tests/server/tftpd.c
6311d4
index 48950c5..e2ec628 100644
6311d4
--- a/tests/server/tftpd.c
6311d4
+++ b/tests/server/tftpd.c
6311d4
@@ -107,8 +107,10 @@ struct testcase {
6311d4
   size_t bufsize; /* size of the data in buffer */
6311d4
   char *rptr;     /* read pointer into the buffer */
6311d4
   size_t rcount;  /* amount of data left to read of the file */
6311d4
-  long num;       /* test case number */
6311d4
+  long testno;    /* test case number */
6311d4
   int ofile;      /* file descriptor for output file when uploading to us */
6311d4
+
6311d4
+  int writedelay; /* number of seconds between each packet */
6311d4
 };
6311d4
 
6311d4
 struct formats {
6311d4
@@ -579,7 +581,7 @@ static ssize_t write_behind(struct testcase *test, int convert)
6311d4
 
6311d4
   if(!test->ofile) {
6311d4
     char outfile[256];
6311d4
-    snprintf(outfile, sizeof(outfile), "log/upload.%ld", test->num);
6311d4
+    snprintf(outfile, sizeof(outfile), "log/upload.%ld", test->testno);
6311d4
     test->ofile=open(outfile, O_CREAT|O_RDWR, 0777);
6311d4
     if(test->ofile == -1) {
6311d4
       logmsg("Couldn't create and/or open file %s for upload!", outfile);
6311d4
@@ -1026,6 +1028,73 @@ again:
6311d4
   return 0;
6311d4
 }
6311d4
 
6311d4
+/* Based on the testno, parse the correct server commands. */
6311d4
+static int parse_servercmd(struct testcase *req)
6311d4
+{
6311d4
+  FILE *stream;
6311d4
+  char *filename;
6311d4
+  int error;
6311d4
+
6311d4
+  filename = test2file(req->testno);
6311d4
+
6311d4
+  stream=fopen(filename, "rb");
6311d4
+  if(!stream) {
6311d4
+    error = errno;
6311d4
+    logmsg("fopen() failed with error: %d %s", error, strerror(error));
6311d4
+    logmsg("  [1] Error opening file: %s", filename);
6311d4
+    logmsg("  Couldn't open test file %ld", req->testno);
6311d4
+    return 1; /* done */
6311d4
+  }
6311d4
+  else {
6311d4
+    char *orgcmd = NULL;
6311d4
+    char *cmd = NULL;
6311d4
+    size_t cmdsize = 0;
6311d4
+    int num=0;
6311d4
+
6311d4
+    /* get the custom server control "commands" */
6311d4
+    error = getpart(&orgcmd, &cmdsize, "reply", "servercmd", stream);
6311d4
+    fclose(stream);
6311d4
+    if(error) {
6311d4
+      logmsg("getpart() failed with error: %d", error);
6311d4
+      return 1; /* done */
6311d4
+    }
6311d4
+
6311d4
+    cmd = orgcmd;
6311d4
+    while(cmd && cmdsize) {
6311d4
+      char *check;
6311d4
+      if(1 == sscanf(cmd, "writedelay: %d", &num)) {
6311d4
+        logmsg("instructed to delay %d secs between packets", num);
6311d4
+        req->writedelay = num;
6311d4
+      }
6311d4
+      else {
6311d4
+        logmsg("Unknown <servercmd> instruction found: %s", cmd);
6311d4
+      }
6311d4
+      /* try to deal with CRLF or just LF */
6311d4
+      check = strchr(cmd, '\r');
6311d4
+      if(!check)
6311d4
+        check = strchr(cmd, '\n');
6311d4
+
6311d4
+      if(check) {
6311d4
+        /* get to the letter following the newline */
6311d4
+        while((*check == '\r') || (*check == '\n'))
6311d4
+          check++;
6311d4
+
6311d4
+        if(!*check)
6311d4
+          /* if we reached a zero, get out */
6311d4
+          break;
6311d4
+        cmd = check;
6311d4
+      }
6311d4
+      else
6311d4
+        break;
6311d4
+    }
6311d4
+    if(orgcmd)
6311d4
+      free(orgcmd);
6311d4
+  }
6311d4
+
6311d4
+  return 0; /* OK! */
6311d4
+}
6311d4
+
6311d4
+
6311d4
 /*
6311d4
  * Validate file access.
6311d4
  */
6311d4
@@ -1076,7 +1145,9 @@ static int validate_access(struct testcase *test,
6311d4
 
6311d4
     logmsg("requested test number %ld part %ld", testno, partno);
6311d4
 
6311d4
-    test->num = testno;
6311d4
+    test->testno = testno;
6311d4
+
6311d4
+    (void)parse_servercmd(test);
6311d4
 
6311d4
     file = test2file(testno);
6311d4
 
6311d4
@@ -1147,6 +1218,12 @@ static void sendtftp(struct testcase *test, struct formats *pf)
6311d4
 #ifdef HAVE_SIGSETJMP
6311d4
     (void) sigsetjmp(timeoutbuf, 1);
6311d4
 #endif
6311d4
+    if(test->writedelay) {
6311d4
+      logmsg("Pausing %d seconds before %d bytes", test->writedelay,
6311d4
+             size);
6311d4
+      wait_ms(1000*test->writedelay);
6311d4
+    }
6311d4
+
6311d4
     send_data:
6311d4
     if (swrite(peer, sdp, size + 4) != size + 4) {
6311d4
       logmsg("write");
6311d4
-- 
6311d4
2.14.4
6311d4
6311d4
6311d4
From fd692a86883109c1ab5b57b9b9ab19ae0ab15a1f Mon Sep 17 00:00:00 2001
6311d4
From: Daniel Stenberg <daniel@haxx.se>
6311d4
Date: Thu, 22 Aug 2013 22:40:38 +0200
6311d4
Subject: [PATCH 2/2] TFTP: make the CURLOPT_LOW_SPEED* options work
6311d4
6311d4
... this also makes sure that the progess callback gets called more
6311d4
often during TFTP transfers.
6311d4
6311d4
Added test 1238 to verify.
6311d4
6311d4
Bug: http://curl.haxx.se/bug/view.cgi?id=1269
6311d4
Reported-by: Jo3
6311d4
6311d4
Upstream-commit: 4bea91fc677359f3dcedb05a431258b6cd5d98f3
6311d4
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
6311d4
---
6311d4
 lib/tftp.c             | 10 ++++++++++
6311d4
 tests/data/Makefile.am |  2 +-
6311d4
 tests/data/test1238    | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
6311d4
 3 files changed, 60 insertions(+), 1 deletion(-)
6311d4
 create mode 100644 tests/data/test1238
6311d4
6311d4
diff --git a/lib/tftp.c b/lib/tftp.c
6311d4
index ef740b8..79b4f41 100644
6311d4
--- a/lib/tftp.c
6311d4
+++ b/lib/tftp.c
6311d4
@@ -56,6 +56,7 @@
6311d4
 #include "multiif.h"
6311d4
 #include "url.h"
6311d4
 #include "rawstr.h"
6311d4
+#include "speedcheck.h"
6311d4
 
6311d4
 #define _MPRINTF_REPLACE /* use our functions only */
6311d4
 #include <curl/mprintf.h>
6311d4
@@ -1259,6 +1260,15 @@ static CURLcode tftp_doing(struct connectdata *conn, bool *dophase_done)
6311d4
   if(*dophase_done) {
6311d4
     DEBUGF(infof(conn->data, "DO phase is complete\n"));
6311d4
   }
6311d4
+  else {
6311d4
+    /* The multi code doesn't have this logic for the DOING state so we
6311d4
+       provide it for TFTP since it may do the entire transfer in this
6311d4
+       state. */
6311d4
+    if(Curl_pgrsUpdate(conn))
6311d4
+      result = CURLE_ABORTED_BY_CALLBACK;
6311d4
+    else
6311d4
+      result = Curl_speedcheck(conn->data, Curl_tvnow());
6311d4
+  }
6311d4
   return result;
6311d4
 }
6311d4
 
6311d4
diff --git a/tests/data/Makefile.am b/tests/data/Makefile.am
6311d4
index 677564b..9d9b9ea 100644
6311d4
--- a/tests/data/Makefile.am
6311d4
+++ b/tests/data/Makefile.am
6311d4
@@ -81,7 +81,7 @@ test1118 test1119 test1120 test1121 test1122 test1123 test1124 test1125	\
6311d4
 test1126 test1127 test1128 test1129 test1130 test1131 test1132 test1133 \
6311d4
 test1200 test1201 test1202 test1203 test1204 test1205 test1206 test1207 \
6311d4
 test1208 test1209 test1210 test1211 test1213 test1214 test1216 test1218 \
6311d4
-test1220 test1221 test1222 test1223 test1233 test1236 \
6311d4
+test1220 test1221 test1222 test1223 test1233 test1236 test1238 \
6311d4
 test1300 test1301 test1302 test1303 test1304 test1305	\
6311d4
 test1306 test1307 test1308 test1309 test1310 test1311 test1312 test1313 \
6311d4
 test1314 test1315 test1316 test1317 test1318 test1319 test1320 test1321 \
6311d4
diff --git a/tests/data/test1238 b/tests/data/test1238
6311d4
new file mode 100644
6311d4
index 0000000..1859339
6311d4
--- /dev/null
6311d4
+++ b/tests/data/test1238
6311d4
@@ -0,0 +1,49 @@
6311d4
+<testcase>
6311d4
+<info>
6311d4
+<keywords>
6311d4
+TFTP
6311d4
+TFTP RRQ
6311d4
+</keywords>
6311d4
+</info>
6311d4
+
6311d4
+#
6311d4
+# Server-side
6311d4
+<reply>
6311d4
+<servercmd>
6311d4
+writedelay: 2
6311d4
+</servercmd>
6311d4
+# ~1200 bytes (so that they don't fit in two 512 byte chunks)
6311d4
+<data nocheck="yes">
6311d4
+012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
6311d4
+</data>
6311d4
+</reply>
6311d4
+
6311d4
+#
6311d4
+# Client-side
6311d4
+<client>
6311d4
+<server>
6311d4
+tftp
6311d4
+</server>
6311d4
+ <name>
6311d4
+slow TFTP retrieve cancel due to -Y and -y
6311d4
+ </name>
6311d4
+# if less than 1000 bytes/sec within 2 seconds, abort!
6311d4
+ <command>
6311d4
+tftp://%HOSTIP:%TFTPPORT//1238 -Y1000 -y2
6311d4
+</command>
6311d4
+</client>
6311d4
+
6311d4
+#
6311d4
+# Verify pseudo protocol after the test has been "shot"
6311d4
+<verify>
6311d4
+<protocol>
6311d4
+opcode: 1
6311d4
+filename: /1238
6311d4
+mode: octet
6311d4
+</protocol>
6311d4
+# 28 = CURLE_OPERATION_TIMEDOUT
6311d4
+<errorcode>
6311d4
+28
6311d4
+</errorcode>
6311d4
+</verify>
6311d4
+</testcase>
6311d4
-- 
6311d4
2.14.4
6311d4