Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions deps/nghttp2/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ set(NGHTTP2_SOURCES
nghttp2_http.c
nghttp2_rcbuf.c
nghttp2_extpri.c
nghttp2_ratelim.c
nghttp2_time.c
nghttp2_debug.c
sfparse.c
)
Expand Down
4 changes: 4 additions & 0 deletions deps/nghttp2/lib/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ OBJECTS = nghttp2_pq.c nghttp2_map.c nghttp2_queue.c \
nghttp2_http.c \
nghttp2_rcbuf.c \
nghttp2_extpri.c \
nghttp2_ratelim.c \
nghttp2_time.c \
nghttp2_debug.c \
sfparse.c

Expand All @@ -69,6 +71,8 @@ HFILES = nghttp2_pq.h nghttp2_int.h nghttp2_map.h nghttp2_queue.h \
nghttp2_http.h \
nghttp2_rcbuf.h \
nghttp2_extpri.h \
nghttp2_ratelim.h \
nghttp2_time.h \
nghttp2_debug.h \
sfparse.h

Expand Down
20 changes: 16 additions & 4 deletions deps/nghttp2/lib/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ am__objects_2 = nghttp2_pq.lo nghttp2_map.lo nghttp2_queue.lo \
nghttp2_hd_huffman.lo nghttp2_hd_huffman_data.lo \
nghttp2_version.lo nghttp2_priority_spec.lo nghttp2_option.lo \
nghttp2_callbacks.lo nghttp2_mem.lo nghttp2_http.lo \
nghttp2_rcbuf.lo nghttp2_extpri.lo nghttp2_debug.lo sfparse.lo
nghttp2_rcbuf.lo nghttp2_extpri.lo nghttp2_ratelim.lo \
nghttp2_time.lo nghttp2_debug.lo sfparse.lo
am_libnghttp2_la_OBJECTS = $(am__objects_1) $(am__objects_2)
libnghttp2_la_OBJECTS = $(am_libnghttp2_la_OBJECTS)
AM_V_lt = $(am__v_lt_@AM_V@)
Expand Down Expand Up @@ -194,9 +195,10 @@ am__depfiles_remade = ./$(DEPDIR)/nghttp2_buf.Plo \
./$(DEPDIR)/nghttp2_outbound_item.Plo \
./$(DEPDIR)/nghttp2_pq.Plo \
./$(DEPDIR)/nghttp2_priority_spec.Plo \
./$(DEPDIR)/nghttp2_queue.Plo ./$(DEPDIR)/nghttp2_rcbuf.Plo \
./$(DEPDIR)/nghttp2_session.Plo ./$(DEPDIR)/nghttp2_stream.Plo \
./$(DEPDIR)/nghttp2_submit.Plo ./$(DEPDIR)/nghttp2_version.Plo \
./$(DEPDIR)/nghttp2_queue.Plo ./$(DEPDIR)/nghttp2_ratelim.Plo \
./$(DEPDIR)/nghttp2_rcbuf.Plo ./$(DEPDIR)/nghttp2_session.Plo \
./$(DEPDIR)/nghttp2_stream.Plo ./$(DEPDIR)/nghttp2_submit.Plo \
./$(DEPDIR)/nghttp2_time.Plo ./$(DEPDIR)/nghttp2_version.Plo \
./$(DEPDIR)/sfparse.Plo
am__mv = mv -f
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
Expand Down Expand Up @@ -510,6 +512,8 @@ OBJECTS = nghttp2_pq.c nghttp2_map.c nghttp2_queue.c \
nghttp2_http.c \
nghttp2_rcbuf.c \
nghttp2_extpri.c \
nghttp2_ratelim.c \
nghttp2_time.c \
nghttp2_debug.c \
sfparse.c

Expand All @@ -528,6 +532,8 @@ HFILES = nghttp2_pq.h nghttp2_int.h nghttp2_map.h nghttp2_queue.h \
nghttp2_http.h \
nghttp2_rcbuf.h \
nghttp2_extpri.h \
nghttp2_ratelim.h \
nghttp2_time.h \
nghttp2_debug.h \
sfparse.h

Expand Down Expand Up @@ -633,10 +639,12 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nghttp2_pq.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nghttp2_priority_spec.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nghttp2_queue.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nghttp2_ratelim.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nghttp2_rcbuf.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nghttp2_session.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nghttp2_stream.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nghttp2_submit.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nghttp2_time.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nghttp2_version.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sfparse.Plo@am__quote@ # am--include-marker

Expand Down Expand Up @@ -916,10 +924,12 @@ distclean: distclean-recursive
-rm -f ./$(DEPDIR)/nghttp2_pq.Plo
-rm -f ./$(DEPDIR)/nghttp2_priority_spec.Plo
-rm -f ./$(DEPDIR)/nghttp2_queue.Plo
-rm -f ./$(DEPDIR)/nghttp2_ratelim.Plo
-rm -f ./$(DEPDIR)/nghttp2_rcbuf.Plo
-rm -f ./$(DEPDIR)/nghttp2_session.Plo
-rm -f ./$(DEPDIR)/nghttp2_stream.Plo
-rm -f ./$(DEPDIR)/nghttp2_submit.Plo
-rm -f ./$(DEPDIR)/nghttp2_time.Plo
-rm -f ./$(DEPDIR)/nghttp2_version.Plo
-rm -f ./$(DEPDIR)/sfparse.Plo
-rm -f Makefile
Expand Down Expand Up @@ -985,10 +995,12 @@ maintainer-clean: maintainer-clean-recursive
-rm -f ./$(DEPDIR)/nghttp2_pq.Plo
-rm -f ./$(DEPDIR)/nghttp2_priority_spec.Plo
-rm -f ./$(DEPDIR)/nghttp2_queue.Plo
-rm -f ./$(DEPDIR)/nghttp2_ratelim.Plo
-rm -f ./$(DEPDIR)/nghttp2_rcbuf.Plo
-rm -f ./$(DEPDIR)/nghttp2_session.Plo
-rm -f ./$(DEPDIR)/nghttp2_stream.Plo
-rm -f ./$(DEPDIR)/nghttp2_submit.Plo
-rm -f ./$(DEPDIR)/nghttp2_time.Plo
-rm -f ./$(DEPDIR)/nghttp2_version.Plo
-rm -f ./$(DEPDIR)/sfparse.Plo
-rm -f Makefile
Expand Down
17 changes: 17 additions & 0 deletions deps/nghttp2/lib/includes/nghttp2/nghttp2.h
Original file line number Diff line number Diff line change
Expand Up @@ -2756,6 +2756,23 @@ NGHTTP2_EXTERN void
nghttp2_option_set_no_rfc9113_leading_and_trailing_ws_validation(
nghttp2_option *option, int val);

/**
* @function
*
* This function sets the rate limit for the incoming stream reset
* (RST_STREAM frame). It is server use only. It is a token-bucket
* based rate limiter. |burst| specifies the number of tokens that is
* initially available. The maximum number of tokens is capped to
* this value. |rate| specifies the number of tokens that are
* regenerated per second. An incoming RST_STREAM consumes one token.
* If there is no token available, GOAWAY is sent to tear down the
* connection. |burst| and |rate| default to 1000 and 33
* respectively.
*/
NGHTTP2_EXTERN void
nghttp2_option_set_stream_reset_rate_limit(nghttp2_option *option,
uint64_t burst, uint64_t rate);

/**
* @function
*
Expand Down
4 changes: 2 additions & 2 deletions deps/nghttp2/lib/includes/nghttp2/nghttp2ver.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
* @macro
* Version number of the nghttp2 library release
*/
#define NGHTTP2_VERSION "1.56.0"
#define NGHTTP2_VERSION "1.57.0"

/**
* @macro
* Numerical representation of the version number of the nghttp2 library
* release. This is a 24 bit number with 8 bits for major number, 8 bits
* for minor and 8 bits for patch. Version 1.2.3 becomes 0x010203.
*/
#define NGHTTP2_VERSION_NUM 0x013800
#define NGHTTP2_VERSION_NUM 0x013900

#endif /* NGHTTP2VER_H */
7 changes: 7 additions & 0 deletions deps/nghttp2/lib/nghttp2_option.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,10 @@ void nghttp2_option_set_no_rfc9113_leading_and_trailing_ws_validation(
NGHTTP2_OPT_NO_RFC9113_LEADING_AND_TRAILING_WS_VALIDATION;
option->no_rfc9113_leading_and_trailing_ws_validation = val;
}

void nghttp2_option_set_stream_reset_rate_limit(nghttp2_option *option,
uint64_t burst, uint64_t rate) {
option->opt_set_mask |= NGHTTP2_OPT_STREAM_RESET_RATE_LIMIT;
option->stream_reset_burst = burst;
option->stream_reset_rate = rate;
}
6 changes: 6 additions & 0 deletions deps/nghttp2/lib/nghttp2_option.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,18 @@ typedef enum {
NGHTTP2_OPT_MAX_SETTINGS = 1 << 12,
NGHTTP2_OPT_SERVER_FALLBACK_RFC7540_PRIORITIES = 1 << 13,
NGHTTP2_OPT_NO_RFC9113_LEADING_AND_TRAILING_WS_VALIDATION = 1 << 14,
NGHTTP2_OPT_STREAM_RESET_RATE_LIMIT = 1 << 15,
} nghttp2_option_flag;

/**
* Struct to store option values for nghttp2_session.
*/
struct nghttp2_option {
/**
* NGHTTP2_OPT_STREAM_RESET_RATE_LIMIT
*/
uint64_t stream_reset_burst;
uint64_t stream_reset_rate;
/**
* NGHTTP2_OPT_MAX_SEND_HEADER_BLOCK_LENGTH
*/
Expand Down
75 changes: 75 additions & 0 deletions deps/nghttp2/lib/nghttp2_ratelim.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* nghttp2 - HTTP/2 C Library
*
* Copyright (c) 2023 nghttp2 contributors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "nghttp2_ratelim.h"
#include "nghttp2_helper.h"

void nghttp2_ratelim_init(nghttp2_ratelim *rl, uint64_t burst, uint64_t rate) {
rl->val = rl->burst = burst;
rl->rate = rate;
rl->tstamp = 0;
}

void nghttp2_ratelim_update(nghttp2_ratelim *rl, uint64_t tstamp) {
uint64_t d, gain;

if (tstamp == rl->tstamp) {
return;
}

if (tstamp > rl->tstamp) {
d = tstamp - rl->tstamp;
} else {
d = 1;
}

rl->tstamp = tstamp;

if (UINT64_MAX / d < rl->rate) {
rl->val = rl->burst;

return;
}

gain = rl->rate * d;

if (UINT64_MAX - gain < rl->val) {
rl->val = rl->burst;

return;
}

rl->val += gain;
rl->val = nghttp2_min(rl->val, rl->burst);
}

int nghttp2_ratelim_drain(nghttp2_ratelim *rl, uint64_t n) {
if (rl->val < n) {
return -1;
}

rl->val -= n;

return 0;
}
57 changes: 57 additions & 0 deletions deps/nghttp2/lib/nghttp2_ratelim.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* nghttp2 - HTTP/2 C Library
*
* Copyright (c) 2023 nghttp2 contributors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NGHTTP2_RATELIM_H
#define NGHTTP2_RATELIM_H

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* HAVE_CONFIG_H */

#include <nghttp2/nghttp2.h>

typedef struct nghttp2_ratelim {
/* burst is the maximum value of val. */
uint64_t burst;
/* rate is the amount of value that is regenerated per 1 tstamp. */
uint64_t rate;
/* val is the amount of value available to drain. */
uint64_t val;
/* tstamp is the last timestamp in second resolution that is known
to this object. */
uint64_t tstamp;
} nghttp2_ratelim;

/* nghttp2_ratelim_init initializes |rl| with the given parameters. */
void nghttp2_ratelim_init(nghttp2_ratelim *rl, uint64_t burst, uint64_t rate);

/* nghttp2_ratelim_update updates rl->val with the current |tstamp|
given in second resolution. */
void nghttp2_ratelim_update(nghttp2_ratelim *rl, uint64_t tstamp);

/* nghttp2_ratelim_drain drains |n| from rl->val. It returns 0 if it
succeeds, or -1. */
int nghttp2_ratelim_drain(nghttp2_ratelim *rl, uint64_t n);

#endif /* NGHTTP2_RATELIM_H */
34 changes: 33 additions & 1 deletion deps/nghttp2/lib/nghttp2_session.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "nghttp2_http.h"
#include "nghttp2_pq.h"
#include "nghttp2_extpri.h"
#include "nghttp2_time.h"
#include "nghttp2_debug.h"

/*
Expand Down Expand Up @@ -475,6 +476,10 @@ static int session_new(nghttp2_session **session_ptr,
(*session_ptr)->pending_enable_push = 1;
(*session_ptr)->pending_no_rfc7540_priorities = UINT8_MAX;

nghttp2_ratelim_init(&(*session_ptr)->stream_reset_ratelim,
NGHTTP2_DEFAULT_STREAM_RESET_BURST,
NGHTTP2_DEFAULT_STREAM_RESET_RATE);

if (server) {
(*session_ptr)->server = 1;
}
Expand Down Expand Up @@ -573,6 +578,12 @@ static int session_new(nghttp2_session **session_ptr,
(*session_ptr)->opt_flags |=
NGHTTP2_OPTMASK_NO_RFC9113_LEADING_AND_TRAILING_WS_VALIDATION;
}

if (option->opt_set_mask & NGHTTP2_OPT_STREAM_RESET_RATE_LIMIT) {
nghttp2_ratelim_init(&(*session_ptr)->stream_reset_ratelim,
option->stream_reset_burst,
option->stream_reset_rate);
}
}

rv = nghttp2_hd_deflate_init2(&(*session_ptr)->hd_deflater,
Expand Down Expand Up @@ -4449,6 +4460,23 @@ static int session_process_priority_frame(nghttp2_session *session) {
return nghttp2_session_on_priority_received(session, frame);
}

static int session_update_stream_reset_ratelim(nghttp2_session *session) {
if (!session->server || (session->goaway_flags & NGHTTP2_GOAWAY_SUBMITTED)) {
return 0;
}

nghttp2_ratelim_update(&session->stream_reset_ratelim,
nghttp2_time_now_sec());

if (nghttp2_ratelim_drain(&session->stream_reset_ratelim, 1) == 0) {
return 0;
}

return nghttp2_session_add_goaway(session, session->last_recv_stream_id,
NGHTTP2_INTERNAL_ERROR, NULL, 0,
NGHTTP2_GOAWAY_AUX_NONE);
}

int nghttp2_session_on_rst_stream_received(nghttp2_session *session,
nghttp2_frame *frame) {
int rv;
Expand Down Expand Up @@ -4478,7 +4506,8 @@ int nghttp2_session_on_rst_stream_received(nghttp2_session *session,
if (nghttp2_is_fatal(rv)) {
return rv;
}
return 0;

return session_update_stream_reset_ratelim(session);
}

static int session_process_rst_stream_frame(nghttp2_session *session) {
Expand Down Expand Up @@ -7434,6 +7463,9 @@ int nghttp2_session_add_goaway(nghttp2_session *session, int32_t last_stream_id,
nghttp2_mem_free(mem, item);
return rv;
}

session->goaway_flags |= NGHTTP2_GOAWAY_SUBMITTED;

return 0;
}

Expand Down
Loading