pespin has submitted this change. ( https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/43713?usp=email ) Change subject: HTTP2_Server_Emulation: Fix one_req_per_conn and make it configurable ...................................................................... HTTP2_Server_Emulation: Fix one_req_per_conn and make it configurable The GOAWAY must be sent upon Rx time, otherwise a quick client could sent several request headers on different streams before we answered the first one, and then those subsequent request would end up going up the stack. When the ConnHdlr sent a response down the stack, the tcp conn could already have been closed by the HTTP2 client due to receiving the GOAWAY. Fix several state transitions while at it, and make the one_req_per_conn (tx GOAWAY) configurable, supporting also receiving multiple (non-concurrent, sequential stream) requests when one_req_per_conn:=false. From the ConnHdlr PoV, setting one_req_per_conn true or false is transparent, since it simply receives HTTP2_Msg filtered by HTTP2_Server_Emulation. Change-Id: I133eac0f41cfe119531bb3a60c5f0e5cd184abc5 --- M library/HTTP2_Server_Emulation.ttcn M smf/SMF_Tests.ttcn 2 files changed, 45 insertions(+), 13 deletions(-) Approvals: Jenkins Builder: Verified pespin: Looks good to me, approved osmith: Looks good to me, but someone else must approve diff --git a/library/HTTP2_Server_Emulation.ttcn b/library/HTTP2_Server_Emulation.ttcn index 13a32a3..96eb8dc 100644 --- a/library/HTTP2_Server_Emulation.ttcn +++ b/library/HTTP2_Server_Emulation.ttcn @@ -44,6 +44,8 @@ type record HTTP2_Server_Conn { IPL4asp_Types.ConnectionId conn_id, HTTP2_Server_Conn_State state, + integer last_stream_id, + boolean goaway_sent, HTTP2_comp_context ctx_dec, HTTP2_comp_context ctx_enc, HTTP2_header_block rx_hb optional /* Contains received header while in HTTP2_SERVER_CONN_ST_WAIT_BODY */ @@ -54,6 +56,9 @@ conn := { conn_id := -1, state := HTTP2_SERVER_CONN_ST_UNUSED, + /* rfc7540 6.8: "The last stream identifier can be set to 0 if no streams were processed." */ + last_stream_id := 0, + goaway_sent := false, ctx_dec := HTTP2_comp_context_init(), ctx_enc := HTTP2_comp_context_init(), rx_hb := omit @@ -114,7 +119,9 @@ type record Http2ServerEmulationCfg { charstring http2_bind_ip, - integer http2_bind_port + integer http2_bind_port, + /* If enabled, GOAWAY will be sent after first full request is received. */ + boolean one_req_per_conn }; type record HTTP2_ConnHdlr_Entry { @@ -286,6 +293,24 @@ HTTP2.send(http2_tx); } +/* Handle and forward a full request up the stack: */ +private function f_HTTP2_Server_Conn_rx_http2_msg(inout HTTP2_Server_Conn conn, HTTP2_Msg http2_msg) +runs on HTTP2_Server_Emulation_CT { + if (not conn.goaway_sent) { + conn.last_stream_id := http2_msg.stream_id; + if (g_http2_cfg.one_req_per_conn) { + /* Send GOAWAY to avoid receiving more requests on this conn: */ + f_HTTP2_Server_Conn_tx(conn, ts_HTTP2_Frame_Goaway(conn.last_stream_id, 0 /* NO_ERROR */)); + conn.goaway_sent := true; + } + } else if (http2_msg.stream_id > conn.last_stream_id) { + log(f_HTTP2_Server_Conn_str(conn), ": Ignoring received msg since we already sent GOAWAY(", + conn.last_stream_id, "): ", http2_msg); + return; + } + forward_http2_msg(conn, valueof(http2_msg)); +} + private function f_HTTP2_Server_Conn_rx_http2(inout HTTP2_Server_Conn conn, HTTP2_Recv http2_rx) runs on HTTP2_Server_Emulation_CT { var template (value) HTTP2_Msg http2_msg; @@ -338,22 +363,20 @@ log2str(f_HTTP2_Server_Conn_str(conn), ": Rx unexpected: ", http2_rx)); } if (not match(http2_rx.frame, tr_HTTP2_Frame_Header())) { - - return; /* TODO: we should only allow WINDOW_UPDATE and SETTINGS here... */ + return; } var HTTP2_header_block hb; hb := f_HTTP2_Server_Conn_header_block_decode(conn, http2_rx.frame.header_frame.header_block_fragment); - /* TODO: store header in Conn or send to ConNHdlr? */ log(f_HTTP2_Server_Conn_str(conn), ": Decompressed header: ", hb); + if (not http2_rx.frame.header_frame.end_stream_flag) { conn.rx_hb := hb; f_HTTP2_Server_Conn_st_change(conn, HTTP2_SERVER_CONN_ST_WAIT_BODY); return; } - http2_msg := ts_HTTP2_Msg(conn.conn_id, http2_rx.frame.header_frame.stream_id, hb, omit); - forward_http2_msg(conn, valueof(http2_msg)); + f_HTTP2_Server_Conn_rx_http2_msg(conn, valueof(http2_msg)); return; } case (HTTP2_SERVER_CONN_ST_WAIT_BODY) { @@ -362,17 +385,28 @@ log2str(f_HTTP2_Server_Conn_str(conn), ": Rx unexpected: ", http2_rx)); } if (not match(http2_rx.frame, tr_HTTP2_Frame_Data())) { - return; /* TODO: we should only allow WINDOW_UPDATE and SETTINGS here... */ + if (match(http2_rx.frame, tr_HTTP2_Frame_Header())) { + log(f_HTTP2_Server_Conn_str(conn), + ": FIXME: Multiple concurrent active streams not supported! requires updating HTTP2_Server_Conn to use a list of streams!"); + setverdict(fail); + return; + } + return; } if (not http2_rx.frame.data_frame.end_stream_flag) { - log("FIXME: Multiple DATA blocks not supported! requires updating HTTP2_Msg.body to be a list!"); + log(f_HTTP2_Server_Conn_str(conn), + ": FIXME: Multiple DATA blocks not supported! requires updating HTTP2_Msg.body to be a list!"); setverdict(fail); + return; + } else { + f_HTTP2_Server_Conn_st_change(conn, HTTP2_SERVER_CONN_ST_WAIT_HEADER); } + http2_msg := ts_HTTP2_Msg(conn.conn_id, http2_rx.frame.data_frame.stream_id, conn.rx_hb, http2_rx.frame.data_frame); - forward_http2_msg(conn, valueof(http2_msg)); + f_HTTP2_Server_Conn_rx_http2_msg(conn, valueof(http2_msg)); return; } case else { @@ -442,7 +476,6 @@ [] CONN.receive(HTTP2_Msg:?) -> value http2_msg sender vc_conn { //log("HTTP2_Server: Tx ", http2_msg); - var integer last_stream_id := http2_msg.stream_id; idx := f_conn_table_find_by_conn_id(http2_msg.conn_id); if (idx < 0) { @@ -468,8 +501,6 @@ http2_msg.body.padding); f_HTTP2_Server_Conn_tx(conn_table[idx], http2_frame); } - /* Send GOAWAY since we are finished: */ - f_HTTP2_Server_Conn_tx(conn_table[idx], ts_HTTP2_Frame_Goaway(last_stream_id, 0 /* NO_ERROR */)); } [] CONN_PROC.getcall(HTTP2EM_register:{?}) -> param(path_pattern) sender vc_conn { log("HTTP2_Server: Register ", vc_conn, "path: ", path_pattern); diff --git a/smf/SMF_Tests.ttcn b/smf/SMF_Tests.ttcn index 97afed9..5b726f0 100644 --- a/smf/SMF_Tests.ttcn +++ b/smf/SMF_Tests.ttcn @@ -246,7 +246,8 @@ var Http2ServerEmulationCfg http2_srv_cfg := { http2_bind_ip := mp_scp_local_ip, - http2_bind_port := mp_scp_local_port + http2_bind_port := mp_scp_local_port, + one_req_per_conn := false }; vc_HTTP2_SRV_SCP := HTTP2_Server_Emulation_CT.create(id) alive; -- To view, visit https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/43713?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: merged Gerrit-Project: osmo-ttcn3-hacks Gerrit-Branch: master Gerrit-Change-Id: I133eac0f41cfe119531bb3a60c5f0e5cd184abc5 Gerrit-Change-Number: 43713 Gerrit-PatchSet: 2 Gerrit-Owner: pespin <pespin@sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: osmith <osmith@sysmocom.de> Gerrit-Reviewer: pespin <pespin@sysmocom.de>