]> git.kaiwu.me - nginx.git/commitdiff
QUIC: fixed ACK Ranges processing.
authorSergey Kandaurov <pluknet@nginx.com>
Fri, 7 Aug 2020 09:34:15 +0000 (12:34 +0300)
committerSergey Kandaurov <pluknet@nginx.com>
Fri, 7 Aug 2020 09:34:15 +0000 (12:34 +0300)
According to quic-transport draft 29, section 19.3.1:

   The value of the Gap field establishes the largest packet number
   value for the subsequent ACK Range using the following formula:

      largest = previous_smallest - gap - 2

   Thus, given a largest packet number for the range, the smallest value
   is determined by the formula:

      smallest = largest - ack_range

While here, changed min/max to uint64_t for consistency.

src/event/ngx_event_quic.c

index 47c52067e90d888a22043c43809d09e95c08a34e..866c7ea91d9bf8972462d58fb1afd9c28ea9cfd7 100644 (file)
@@ -2289,9 +2289,9 @@ ngx_quic_handle_ack_frame(ngx_connection_t *c, ngx_quic_header_t *pkt,
 {
     ssize_t                 n;
     u_char                 *pos, *end;
-    uint64_t                gap, range;
+    uint64_t                min, max, gap, range;
     ngx_msec_t              send_time;
-    ngx_uint_t              i, min, max;
+    ngx_uint_t              i;
     ngx_quic_send_ctx_t    *ctx;
     ngx_quic_connection_t  *qc;
 
@@ -2328,7 +2328,7 @@ ngx_quic_handle_ack_frame(ngx_connection_t *c, ngx_quic_header_t *pkt,
     if (ctx->largest_ack < max) {
         ctx->largest_ack = max;
         ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0,
-                       "quic updated largest received ack: %ui", max);
+                       "quic updated largest received ack: %uL", max);
 
         /*
          *  An endpoint generates an RTT sample on receiving an
@@ -2354,23 +2354,23 @@ ngx_quic_handle_ack_frame(ngx_connection_t *c, ngx_quic_header_t *pkt,
         }
         pos += n;
 
-        if (gap >= min) {
+        if (gap + 2 > min) {
             qc->error = NGX_QUIC_ERR_FRAME_ENCODING_ERROR;
             ngx_log_error(NGX_LOG_INFO, c->log, 0,
                          "quic invalid range %ui in ack frame", i);
             return NGX_ERROR;
         }
 
-        max = min - 1 - gap;
+        max = min - gap - 2;
 
-        if (range > max + 1) {
+        if (range > max) {
             qc->error = NGX_QUIC_ERR_FRAME_ENCODING_ERROR;
             ngx_log_error(NGX_LOG_INFO, c->log, 0,
                          "quic invalid range %ui in ack frame", i);
             return NGX_ERROR;
         }
 
-        min = max - range + 1;
+        min = max - range;
 
         if (ngx_quic_handle_ack_frame_range(c, ctx, min, max, &send_time)
             != NGX_OK)
@@ -2393,6 +2393,9 @@ ngx_quic_handle_ack_frame_range(ngx_connection_t *c, ngx_quic_send_ctx_t *ctx,
     ngx_quic_frame_t       *f;
     ngx_quic_connection_t  *qc;
 
+    ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,
+                   "quic handle ack range: min:%uL max:%uL", min, max);
+
     qc = c->quic;
 
     *send_time = NGX_TIMER_INFINITE;