Commit 03adff1e authored by Marcin Adamski's avatar Marcin Adamski Committed by Yang Tse
Browse files

tftp.c: TFTP timeout and unexpected block adjustments

Set ACK timeout to 5 seconds.

If we are waiting for block X and receive block Y that is the expected one, we
should send ACK and increase X (which is already implemented). Otherwise drop
the packet and don't increase retry counter.
parent 34770b8a
Loading
Loading
Loading
Loading
+7 −12
Original line number Original line Diff line number Diff line
@@ -248,11 +248,11 @@ static CURLcode tftp_set_timeouts(tftp_state_data_t *state)


    state->max_time = state->start_time+maxtime;
    state->max_time = state->start_time+maxtime;


    /* Set per-block timeout to 10% of total */
    /* Set per-block timeout to total */
    timeout = maxtime/10 ;
    timeout = maxtime;


    /* Average reposting an ACK after 15 seconds */
    /* Average reposting an ACK after 5 seconds */
    state->retry_max = (int)timeout/15;
    state->retry_max = (int)timeout/5;
  }
  }
  /* But bound the total number */
  /* But bound the total number */
  if(state->retry_max<3)
  if(state->retry_max<3)
@@ -591,15 +591,10 @@ static CURLcode tftp_rx(tftp_state_data_t *state, tftp_event_t event)
    /* Is this the block we expect? */
    /* Is this the block we expect? */
    rblock = getrpacketblock(&state->rpacket);
    rblock = getrpacketblock(&state->rpacket);
    if(NEXT_BLOCKNUM(state->block) != rblock) {
    if(NEXT_BLOCKNUM(state->block) != rblock) {
      /* No, log it, up the retry count and fail if over the limit */
      /* No, log it */
      infof(data,
      infof(data,
            "Received unexpected DATA packet block %d\n", rblock);
            "Received unexpected DATA packet block %d, expecting block %d\n",
      state->retries++;
            rblock, NEXT_BLOCKNUM(state->block));
      if(state->retries > state->retry_max) {
        failf(data, "tftp_rx: giving up waiting for block %d",
              NEXT_BLOCKNUM(state->block));
        return CURLE_TFTP_ILLEGAL;
      }
      break;
      break;
    }
    }
    /* This is the expected block.  Reset counters and ACK it. */
    /* This is the expected block.  Reset counters and ACK it. */