Skip to content

Commit

Permalink
QUIC: added path limiting function ngx_quic_path_limit().
Browse files Browse the repository at this point in the history
  • Loading branch information
arut committed Dec 14, 2021
1 parent 10fd8be commit 3341a85
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions src/event/quic/ngx_event_quic_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ static ssize_t ngx_quic_send(ngx_connection_t *c, u_char *buf, size_t len,
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
Expand Down Expand Up @@ -137,7 +139,6 @@ ngx_quic_socket_output(ngx_connection_t *c, ngx_quic_socket_t *qsock)
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;
Expand All @@ -160,12 +161,7 @@ ngx_quic_create_datagrams(ngx_connection_t *c, ngx_quic_socket_t *qsock)
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);

Expand Down Expand Up @@ -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;
Expand All @@ -1228,14 +1223,7 @@ ngx_quic_frame_sendto(ngx_connection_t *c, ngx_quic_frame_t *frame,

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;

Expand Down Expand Up @@ -1279,3 +1267,23 @@ ngx_quic_frame_sendto(ngx_connection_t *c, ngx_quic_frame_t *frame,

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;
}

0 comments on commit 3341a85

Please sign in to comment.