changeset 8941:0433e69f5425 quic

QUIC: added path limiting function ngx_quic_path_limit().
author Roman Arutyunyan <arut@nginx.com>
date Tue, 14 Dec 2021 16:24:20 +0300
parents fb41e37ddeb0
children 5c86189a1c1b
files src/event/quic/ngx_event_quic_output.c
diffstat 1 files changed, 24 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/src/event/quic/ngx_event_quic_output.c
+++ b/src/event/quic/ngx_event_quic_output.c
@@ -63,6 +63,8 @@ static ssize_t ngx_quic_send(ngx_connect
     struct sockaddr *sockaddr, socklen_t socklen);
 static void ngx_quic_set_packet_number(ngx_quic_header_t *pkt,
     ngx_quic_send_ctx_t *ctx);
+static size_t ngx_quic_path_limit(ngx_connection_t *c, ngx_quic_path_t *path,
+    size_t size);
 
 
 size_t
@@ -137,7 +139,6 @@ ngx_quic_socket_output(ngx_connection_t 
 static ngx_int_t
 ngx_quic_create_datagrams(ngx_connection_t *c, ngx_quic_socket_t *qsock)
 {
-    off_t                   max;
     size_t                  len, min;
     ssize_t                 n;
     u_char                 *p;
@@ -160,12 +161,7 @@ ngx_quic_create_datagrams(ngx_connection
         len = ngx_min(qc->ctp.max_udp_payload_size,
                       NGX_QUIC_MAX_UDP_PAYLOAD_SIZE);
 
-        if (path->limited) {
-            max = path->received * 3;
-            max = (path->sent >= max) ? 0 : max - path->sent;
-
-            len = ngx_min(len, (size_t) max);
-        }
+        len = ngx_quic_path_limit(c, path, len);
 
         pad = ngx_quic_get_padding_level(c);
 
@@ -1212,7 +1208,6 @@ ngx_int_t
 ngx_quic_frame_sendto(ngx_connection_t *c, ngx_quic_frame_t *frame,
     size_t min, ngx_quic_path_t *path)
 {
-    off_t                   max;
     size_t                  min_payload, pad;
     ssize_t                 len, sent;
     ngx_str_t               res;
@@ -1228,14 +1223,7 @@ ngx_quic_frame_sendto(ngx_connection_t *
 
     ngx_quic_init_packet(c, ctx, qc->socket, &pkt);
 
-    /* account for anti-amplification limit: expand to allowed size */
-    if (path->limited) {
-        max = path->received * 3;
-        max = (path->sent >= max) ? 0 : max - path->sent;
-        if ((off_t) min > max) {
-            min = max;
-        }
-    }
+    min = ngx_quic_path_limit(c, path, min);
 
     min_payload = min ? ngx_quic_payload_size(&pkt, min) : 0;
 
@@ -1279,3 +1267,23 @@ ngx_quic_frame_sendto(ngx_connection_t *
 
     return NGX_OK;
 }
+
+
+static size_t
+ngx_quic_path_limit(ngx_connection_t *c, ngx_quic_path_t *path, size_t size)
+{
+    off_t  max;
+
+    if (path->limited) {
+        max = path->received * 3;
+        max = (path->sent >= max) ? 0 : max - path->sent;
+
+        if ((off_t) size > max) {
+            ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,
+                           "quic path limit %uz - %O", size, max);
+            return max;
+        }
+    }
+
+    return size;
+}