TS-3492 Only send SETTINGS which are different than protocol defaults
Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/213a7003 Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/213a7003 Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/213a7003 Branch: refs/heads/master Commit: 213a70036ccbf39d5298674bdaa70d31f4fe1fca Parents: 8a2b241 Author: Masaori Koshiba <[email protected]> Authored: Thu Jul 30 14:09:54 2015 -0600 Committer: Leif Hedstrom <[email protected]> Committed: Thu Jul 30 14:09:54 2015 -0600 ---------------------------------------------------------------------- proxy/http2/HTTP2.cc | 9 +++++- proxy/http2/HTTP2.h | 2 +- proxy/http2/Http2ConnectionState.cc | 55 ++++++++++++++++++++++---------- proxy/http2/Http2ConnectionState.h | 4 +-- 4 files changed, 49 insertions(+), 21 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/trafficserver/blob/213a7003/proxy/http2/HTTP2.cc ---------------------------------------------------------------------- diff --git a/proxy/http2/HTTP2.cc b/proxy/http2/HTTP2.cc index f089081..3b4ad96 100644 --- a/proxy/http2/HTTP2.cc +++ b/proxy/http2/HTTP2.cc @@ -255,7 +255,7 @@ http2_write_rst_stream(uint32_t error_code, IOVec iov) } bool -http2_write_settings(const Http2SettingsParameter ¶m, IOVec iov) +http2_write_settings(const Http2SettingsParameter ¶m, const IOVec &iov) { byte_pointer ptr(iov.iov_base); @@ -772,6 +772,13 @@ Http2::init() REC_EstablishStaticConfigInt32U(max_header_list_size, "proxy.config.http2.max_header_list_size"); REC_EstablishStaticConfigInt32U(max_request_header_size, "proxy.config.http.request_header_max_size"); + // If any settings is broken, ATS should not start + ink_release_assert(http2_settings_parameter_is_valid({HTTP2_SETTINGS_MAX_CONCURRENT_STREAMS, max_concurrent_streams}) && + http2_settings_parameter_is_valid({HTTP2_SETTINGS_INITIAL_WINDOW_SIZE, initial_window_size}) && + http2_settings_parameter_is_valid({HTTP2_SETTINGS_MAX_FRAME_SIZE, max_frame_size}) && + http2_settings_parameter_is_valid({HTTP2_SETTINGS_HEADER_TABLE_SIZE, header_table_size}) && + http2_settings_parameter_is_valid({HTTP2_SETTINGS_MAX_HEADER_LIST_SIZE, max_header_list_size})); + // Setup statistics http2_rsb = RecAllocateRawStatBlock(static_cast<int>(HTTP2_N_STATS)); RecRegisterRawStat(http2_rsb, RECT_PROCESS, HTTP2_STAT_CURRENT_CLIENT_SESSION_NAME, RECD_INT, RECP_NON_PERSISTENT, http://git-wip-us.apache.org/repos/asf/trafficserver/blob/213a7003/proxy/http2/HTTP2.h ---------------------------------------------------------------------- diff --git a/proxy/http2/HTTP2.h b/proxy/http2/HTTP2.h index a577a15..a398e0e 100644 --- a/proxy/http2/HTTP2.h +++ b/proxy/http2/HTTP2.h @@ -270,7 +270,7 @@ bool http2_write_headers(const uint8_t *, size_t, const IOVec &); bool http2_write_rst_stream(uint32_t, IOVec); -bool http2_write_settings(const Http2SettingsParameter &, IOVec); +bool http2_write_settings(const Http2SettingsParameter &, const IOVec &); bool http2_write_ping(const uint8_t *, IOVec); http://git-wip-us.apache.org/repos/asf/trafficserver/blob/213a7003/proxy/http2/Http2ConnectionState.cc ---------------------------------------------------------------------- diff --git a/proxy/http2/Http2ConnectionState.cc b/proxy/http2/Http2ConnectionState.cc index 32921fc..3bec688 100644 --- a/proxy/http2/Http2ConnectionState.cc +++ b/proxy/http2/Http2ConnectionState.cc @@ -614,23 +614,11 @@ Http2ConnectionState::main_event_handler(int event, void *edata) // determination that HTTP/2 will be used by both peers, each endpoint MUST // send a connection preface as a final confirmation ... The server connection // preface consists of a potentially empty SETTINGS frame. - Http2Frame settings(HTTP2_FRAME_TYPE_SETTINGS, 0, 0); - settings.alloc(buffer_size_index[HTTP2_FRAME_TYPE_SETTINGS]); - - // Send all settings values - IOVec iov = settings.write(); - for (int i = 1; i < HTTP2_SETTINGS_MAX; i++) { - Http2SettingsIdentifier id = static_cast<Http2SettingsIdentifier>(i); - Http2SettingsParameter param; - param.id = id; - param.value = server_settings.get(id); - http2_write_settings(param, iov); - iov.iov_base = reinterpret_cast<uint8_t *>(iov.iov_base) + HTTP2_SETTINGS_PARAMETER_LEN; - iov.iov_len -= HTTP2_SETTINGS_PARAMETER_LEN; - } - settings.finalize(HTTP2_SETTINGS_PARAMETER_LEN * (HTTP2_SETTINGS_MAX - 1)); - this->ua_session->handleEvent(HTTP2_SESSION_EVENT_XMIT, &settings); + // Load the server settings from the records.config / RecordsConfig.cc settings. + Http2ConnectionSettings configured_settings; + configured_settings.settings_from_configs(); + send_settings_frame(configured_settings); if (server_settings.get(HTTP2_SETTINGS_INITIAL_WINDOW_SIZE) > HTTP2_INITIAL_WINDOW_SIZE) { send_window_update_frame(0, server_settings.get(HTTP2_SETTINGS_INITIAL_WINDOW_SIZE) - HTTP2_INITIAL_WINDOW_SIZE); @@ -955,6 +943,41 @@ Http2ConnectionState::send_rst_stream_frame(Http2StreamId id, Http2ErrorCode ec) } void +Http2ConnectionState::send_settings_frame(const Http2ConnectionSettings &new_settings) +{ + Http2Frame settings(HTTP2_FRAME_TYPE_SETTINGS, 0, 0); + settings.alloc(buffer_size_index[HTTP2_FRAME_TYPE_SETTINGS]); + + IOVec iov = settings.write(); + uint32_t settings_length = 0; + + for (int i = HTTP2_SETTINGS_HEADER_TABLE_SIZE; i < HTTP2_SETTINGS_MAX; ++i) { + Http2SettingsIdentifier id = static_cast<Http2SettingsIdentifier>(i); + unsigned settings_value = new_settings.get(id); + + // Send only difference + if (settings_value != server_settings.get(id)) { + const Http2SettingsParameter param = {static_cast<uint16_t>(id), settings_value}; + + // Write settings to send buffer + if (!http2_write_settings(param, iov)) { + send_goaway_frame(0, HTTP2_ERROR_INTERNAL_ERROR); + return; + } + iov.iov_base = reinterpret_cast<uint8_t *>(iov.iov_base) + HTTP2_SETTINGS_PARAMETER_LEN; + iov.iov_len -= HTTP2_SETTINGS_PARAMETER_LEN; + settings_length += HTTP2_SETTINGS_PARAMETER_LEN; + + // Update current settings + server_settings.set(id, new_settings.get(id)); + } + } + + settings.finalize(settings_length); + this->ua_session->handleEvent(HTTP2_SESSION_EVENT_XMIT, &settings); +} + +void Http2ConnectionState::send_ping_frame(Http2StreamId id, uint8_t flag, const uint8_t *opaque_data) { Http2Frame ping(HTTP2_FRAME_TYPE_PING, id, flag); http://git-wip-us.apache.org/repos/asf/trafficserver/blob/213a7003/proxy/http2/Http2ConnectionState.h ---------------------------------------------------------------------- diff --git a/proxy/http2/Http2ConnectionState.h b/proxy/http2/Http2ConnectionState.h index 42f05f4..6ba0753 100644 --- a/proxy/http2/Http2ConnectionState.h +++ b/proxy/http2/Http2ConnectionState.h @@ -223,9 +223,6 @@ public: continued_buffer.iov_base = NULL; continued_buffer.iov_len = 0; - - // Load the server settings from the records.config / RecordsConfig.cc settings. - server_settings.settings_from_configs(); } void @@ -273,6 +270,7 @@ public: void send_data_frame(FetchSM *fetch_sm); void send_headers_frame(FetchSM *fetch_sm); void send_rst_stream_frame(Http2StreamId id, Http2ErrorCode ec); + void send_settings_frame(const Http2ConnectionSettings &new_settings); void send_ping_frame(Http2StreamId id, uint8_t flag, const uint8_t *opaque_data); void send_goaway_frame(Http2StreamId id, Http2ErrorCode ec); void send_window_update_frame(Http2StreamId id, uint32_t size);
