@@ -1963,77 +1963,69 @@ static int handle_incoming_http(qdr_http2_connection_t *conn)
1963
1963
1964
1964
}
1965
1965
1966
- qd_http2_buffer_list_t buffers ;
1967
- DEQ_INIT (buffers );
1968
1966
pn_raw_buffer_t raw_buffers [READ_BUFFERS ];
1969
1967
size_t n ;
1970
1968
int count = 0 ;
1969
+ int rv = 0 ;
1971
1970
1972
1971
if (!conn -> pn_raw_conn )
1973
1972
return 0 ;
1974
1973
1974
+ bool close_conn = false;
1975
+
1975
1976
while ( (n = pn_raw_connection_take_read_buffers (conn -> pn_raw_conn , raw_buffers , READ_BUFFERS )) ) {
1976
1977
for (size_t i = 0 ; i < n && raw_buffers [i ].bytes ; ++ i ) {
1977
1978
qd_http2_buffer_t * buf = (qd_http2_buffer_t * ) raw_buffers [i ].context ;
1978
1979
DEQ_REMOVE (conn -> granted_read_buffs , buf );
1979
1980
uint32_t raw_buff_size = raw_buffers [i ].size ;
1980
1981
qd_http2_buffer_insert (buf , raw_buff_size );
1981
1982
count += raw_buff_size ;
1982
- DEQ_INSERT_TAIL (buffers , buf );
1983
- }
1984
- }
1985
1983
1986
- //
1987
- // Read each buffer in the buffer chain and call nghttp2_session_mem_recv with buffer content
1988
- //
1989
- qd_http2_buffer_t * buf = DEQ_HEAD (buffers );
1990
- qd_http2_buffer_t * curr_buf = 0 ;
1984
+ if (raw_buff_size > 0 && !close_conn ) {
1985
+ qd_log (http2_adaptor -> log_source , QD_LOG_DEBUG , "[C%" PRIu64 "] handle_incoming_http - Calling nghttp2_session_mem_recv qd_http2_buffer of size %" PRIu32 " " , conn -> conn_id , raw_buff_size );
1986
+ rv = nghttp2_session_mem_recv (conn -> session_data -> session , qd_http2_buffer_base (buf ), qd_http2_buffer_size (buf ));
1987
+ if (rv < 0 ) {
1988
+ qd_log (http2_adaptor -> protocol_log_source , QD_LOG_ERROR , "[C%" PRIu64 "] Error in nghttp2_session_mem_recv rv=%i" , conn -> conn_id , rv );
1989
+ if (rv == NGHTTP2_ERR_FLOODED ) {
1990
+ // Flooding was detected in this HTTP/2 session, and it must be closed. This is most likely caused by misbehavior of peer.
1991
+ // If the client magic is bad, we need to close the connection.
1992
+ qd_log (http2_adaptor -> protocol_log_source , QD_LOG_ERROR , "[C%" PRIu64 "] HTTP NGHTTP2_ERR_FLOODED" , conn -> conn_id );
1993
+ nghttp2_submit_goaway (conn -> session_data -> session , 0 , 0 , NGHTTP2_PROTOCOL_ERROR , (uint8_t * )"Protocol Error" , 14 );
1994
+ }
1995
+ else if (rv == NGHTTP2_ERR_CALLBACK_FAILURE ) {
1996
+ qd_log (http2_adaptor -> protocol_log_source , QD_LOG_ERROR , "[C%" PRIu64 "] HTTP NGHTTP2_ERR_CALLBACK_FAILURE" , conn -> conn_id );
1997
+ nghttp2_submit_goaway (conn -> session_data -> session , 0 , 0 , NGHTTP2_PROTOCOL_ERROR , (uint8_t * )"Internal Error" , 14 );
1998
+ }
1999
+ else if (rv == NGHTTP2_ERR_BAD_CLIENT_MAGIC ) {
2000
+ qd_log (http2_adaptor -> protocol_log_source , QD_LOG_ERROR , "[C%" PRIu64 "] HTTP2 Protocol error, NGHTTP2_ERR_BAD_CLIENT_MAGIC, closing connection" , conn -> conn_id );
2001
+ nghttp2_submit_goaway (conn -> session_data -> session , 0 , 0 , NGHTTP2_PROTOCOL_ERROR , (uint8_t * )"Bad Client Magic" , 16 );
2002
+ }
2003
+ else {
2004
+ nghttp2_submit_goaway (conn -> session_data -> session , 0 , 0 , NGHTTP2_PROTOCOL_ERROR , (uint8_t * )"Protocol Error" , 14 );
2005
+ }
2006
+ nghttp2_session_send (conn -> session_data -> session );
1991
2007
1992
- int rv = 0 ;
1993
- while (buf ) {
1994
- size_t http2_buffer_size = qd_http2_buffer_size (buf );
1995
- if (http2_buffer_size > 0 ) {
1996
- qd_log (http2_adaptor -> log_source , QD_LOG_DEBUG , "[C%" PRIu64 "] handle_incoming_http - Calling nghttp2_session_mem_recv qd_http2_buffer of size %" PRIu32 " " , conn -> conn_id , http2_buffer_size );
1997
- rv = nghttp2_session_mem_recv (conn -> session_data -> session , qd_http2_buffer_base (buf ), qd_http2_buffer_size (buf ));
1998
- if (rv < 0 ) {
1999
- qd_log (http2_adaptor -> protocol_log_source , QD_LOG_ERROR , "[C%" PRIu64 "] Error in nghttp2_session_mem_recv rv=%i" , conn -> conn_id , rv );
2000
- if (rv == NGHTTP2_ERR_FLOODED ) {
2001
- // Flooding was detected in this HTTP/2 session, and it must be closed. This is most likely caused by misbehavior of peer.
2002
- // If the client magic is bad, we need to close the connection.
2003
- qd_log (http2_adaptor -> protocol_log_source , QD_LOG_ERROR , "[C%" PRIu64 "] HTTP NGHTTP2_ERR_FLOODED" , conn -> conn_id );
2004
- nghttp2_submit_goaway (conn -> session_data -> session , 0 , 0 , NGHTTP2_PROTOCOL_ERROR , (uint8_t * )"Protocol Error" , 14 );
2005
- }
2006
- else if (rv == NGHTTP2_ERR_CALLBACK_FAILURE ) {
2007
- qd_log (http2_adaptor -> protocol_log_source , QD_LOG_ERROR , "[C%" PRIu64 "] HTTP NGHTTP2_ERR_CALLBACK_FAILURE" , conn -> conn_id );
2008
- nghttp2_submit_goaway (conn -> session_data -> session , 0 , 0 , NGHTTP2_PROTOCOL_ERROR , (uint8_t * )"Internal Error" , 14 );
2009
- }
2010
- else if (rv == NGHTTP2_ERR_BAD_CLIENT_MAGIC ) {
2011
- qd_log (http2_adaptor -> protocol_log_source , QD_LOG_ERROR , "[C%" PRIu64 "] HTTP2 Protocol error, NGHTTP2_ERR_BAD_CLIENT_MAGIC, closing connection" , conn -> conn_id );
2012
- nghttp2_submit_goaway (conn -> session_data -> session , 0 , 0 , NGHTTP2_PROTOCOL_ERROR , (uint8_t * )"Bad Client Magic" , 16 );
2013
- }
2014
- else {
2015
- nghttp2_submit_goaway (conn -> session_data -> session , 0 , 0 , NGHTTP2_PROTOCOL_ERROR , (uint8_t * )"Protocol Error" , 14 );
2008
+ //
2009
+ // An error was received from nghttp2, the connection needs to be closed.
2010
+ //
2011
+ close_conn = true;
2016
2012
}
2017
- nghttp2_session_send (conn -> session_data -> session );
2018
- pn_raw_connection_close (conn -> pn_raw_conn );
2019
- break ;
2020
2013
}
2014
+ free_qd_http2_buffer_t (buf );
2021
2015
}
2022
- curr_buf = buf ;
2023
- DEQ_REMOVE_HEAD (buffers );
2024
- buf = DEQ_HEAD (buffers );
2025
- free_qd_http2_buffer_t (curr_buf );
2026
2016
}
2027
2017
2028
- if (rv > 0 )
2018
+ if (close_conn ) {
2019
+ pn_raw_connection_close (conn -> pn_raw_conn );
2020
+ }
2021
+ else {
2029
2022
grant_read_buffers (conn );
2030
-
2023
+ }
2031
2024
nghttp2_session_send (conn -> session_data -> session );
2032
2025
2033
2026
return count ;
2034
2027
}
2035
2028
2036
-
2037
2029
qdr_http2_connection_t * qdr_http_connection_ingress_accept (qdr_http2_connection_t * ingress_http_conn )
2038
2030
{
2039
2031
ingress_http_conn -> remote_address = get_address_string (ingress_http_conn -> pn_raw_conn );
0 commit comments