h2load: Show application protocol with OpenSSL < 1.0.2

This commit also fixes the problem that application protocol is not
shown if cleartext spdy is used.
This commit is contained in:
Tatsuhiro Tsujikawa 2015-10-28 02:40:04 +09:00
parent 55bf22081e
commit b051ddec2a
1 changed files with 44 additions and 50 deletions

View File

@ -586,51 +586,37 @@ int Client::connection_made() {
const unsigned char *next_proto = nullptr; const unsigned char *next_proto = nullptr;
unsigned int next_proto_len; unsigned int next_proto_len;
SSL_get0_next_proto_negotiated(ssl, &next_proto, &next_proto_len); SSL_get0_next_proto_negotiated(ssl, &next_proto, &next_proto_len);
for (int i = 0; i < 2; ++i) { #if OPENSSL_VERSION_NUMBER >= 0x10002000L
if (next_proto == nullptr) {
SSL_get0_alpn_selected(ssl, &next_proto, &next_proto_len);
}
#endif // OPENSSL_VERSION_NUMBER >= 0x10002000L
next_proto = nullptr;
if (next_proto) { if (next_proto) {
if (util::check_h2_is_selected(next_proto, next_proto_len)) { if (util::check_h2_is_selected(next_proto, next_proto_len)) {
session = make_unique<Http2Session>(this); session = make_unique<Http2Session>(this);
break;
} else if (util::streq_l(NGHTTP2_H1_1, next_proto, next_proto_len)) { } else if (util::streq_l(NGHTTP2_H1_1, next_proto, next_proto_len)) {
session = make_unique<Http1Session>(this); session = make_unique<Http1Session>(this);
break;
} }
#ifdef HAVE_SPDYLAY #ifdef HAVE_SPDYLAY
else { else {
auto spdy_version = auto spdy_version = spdylay_npn_get_version(next_proto, next_proto_len);
spdylay_npn_get_version(next_proto, next_proto_len);
if (spdy_version) { if (spdy_version) {
session = make_unique<SpdySession>(this, spdy_version); session = make_unique<SpdySession>(this, spdy_version);
break;
} }
} }
#endif // HAVE_SPDYLAY #endif // HAVE_SPDYLAY
next_proto = nullptr; // Just assign next_proto to selected_proto anyway to show the
break; // negotiation result.
} selected_proto.assign(next_proto, next_proto + next_proto_len);
#if OPENSSL_VERSION_NUMBER >= 0x10002000L
SSL_get0_alpn_selected(ssl, &next_proto, &next_proto_len);
auto proto = std::string(reinterpret_cast<const char *>(next_proto),
next_proto_len);
if (proto.empty()) {
std::cout
<< "No protocol negotiated. Fallback behaviour may be activated"
<< std::endl;
break;
} else { } else {
selected_proto = proto; std::cout << "No protocol negotiated. Fallback behaviour may be activated"
report_app_info(); << std::endl;
}
#else // OPENSSL_VERSION_NUMBER < 0x10002000L
break;
#endif // OPENSSL_VERSION_NUMBER < 0x10002000L
}
if (!next_proto) {
for (const auto &proto : config.npn_list) { for (const auto &proto : config.npn_list) {
if (std::equal(NGHTTP2_H1_1_ALPN, if (std::equal(NGHTTP2_H1_1_ALPN,
NGHTTP2_H1_1_ALPN + str_size(NGHTTP2_H1_1_ALPN), NGHTTP2_H1_1_ALPN + str_size(NGHTTP2_H1_1_ALPN),
@ -639,9 +625,15 @@ int Client::connection_made() {
<< "Server does not support NPN/ALPN. Falling back to HTTP/1.1." << "Server does not support NPN/ALPN. Falling back to HTTP/1.1."
<< std::endl; << std::endl;
session = make_unique<Http1Session>(this); session = make_unique<Http1Session>(this);
selected_proto = NGHTTP2_H1_1;
break; break;
} }
} }
}
if (!selected_proto.empty()) {
report_app_info();
}
if (!session) { if (!session) {
std::cout std::cout
@ -653,34 +645,36 @@ int Client::connection_made() {
disconnect(); disconnect();
return -1; return -1;
} }
}
} else { } else {
switch (config.no_tls_proto) { switch (config.no_tls_proto) {
case Config::PROTO_HTTP2: case Config::PROTO_HTTP2:
session = make_unique<Http2Session>(this); session = make_unique<Http2Session>(this);
selected_proto = NGHTTP2_CLEARTEXT_PROTO_VERSION_ID; selected_proto = NGHTTP2_CLEARTEXT_PROTO_VERSION_ID;
report_app_info();
break; break;
case Config::PROTO_HTTP1_1: case Config::PROTO_HTTP1_1:
session = make_unique<Http1Session>(this); session = make_unique<Http1Session>(this);
selected_proto = NGHTTP2_H1_1; selected_proto = NGHTTP2_H1_1;
report_app_info();
break; break;
#ifdef HAVE_SPDYLAY #ifdef HAVE_SPDYLAY
case Config::PROTO_SPDY2: case Config::PROTO_SPDY2:
session = make_unique<SpdySession>(this, SPDYLAY_PROTO_SPDY2); session = make_unique<SpdySession>(this, SPDYLAY_PROTO_SPDY2);
selected_proto = "spdy/2";
break; break;
case Config::PROTO_SPDY3: case Config::PROTO_SPDY3:
session = make_unique<SpdySession>(this, SPDYLAY_PROTO_SPDY3); session = make_unique<SpdySession>(this, SPDYLAY_PROTO_SPDY3);
selected_proto = "spdy/3";
break; break;
case Config::PROTO_SPDY3_1: case Config::PROTO_SPDY3_1:
session = make_unique<SpdySession>(this, SPDYLAY_PROTO_SPDY3_1); session = make_unique<SpdySession>(this, SPDYLAY_PROTO_SPDY3_1);
selected_proto = "spdy/3.1";
break; break;
#endif // HAVE_SPDYLAY #endif // HAVE_SPDYLAY
default: default:
// unreachable // unreachable
assert(0); assert(0);
} }
report_app_info();
} }
state = CLIENT_CONNECTED; state = CLIENT_CONNECTED;