2012-06-04 16:48:31 +02:00
|
|
|
/*
|
2014-03-30 12:09:21 +02:00
|
|
|
* nghttp2 - HTTP/2 C Library
|
2012-06-04 16:48:31 +02:00
|
|
|
*
|
|
|
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
|
|
|
*
|
|
|
|
* 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 "shrpx_client_handler.h"
|
|
|
|
|
2015-05-13 15:30:35 +02:00
|
|
|
#ifdef HAVE_UNISTD_H
|
2012-08-21 17:14:02 +02:00
|
|
|
#include <unistd.h>
|
2015-05-13 15:30:35 +02:00
|
|
|
#endif // HAVE_UNISTD_H
|
2016-01-15 15:04:58 +01:00
|
|
|
#ifdef HAVE_SYS_SOCKET_H
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#endif // HAVE_SYS_SOCKET_H
|
|
|
|
#ifdef HAVE_NETDB_H
|
|
|
|
#include <netdb.h>
|
|
|
|
#endif // HAVE_NETDB_H
|
|
|
|
|
2012-07-15 14:15:28 +02:00
|
|
|
#include <cerrno>
|
|
|
|
|
2012-06-04 16:48:31 +02:00
|
|
|
#include "shrpx_upstream.h"
|
2013-07-26 12:38:54 +02:00
|
|
|
#include "shrpx_http2_upstream.h"
|
2012-06-04 16:48:31 +02:00
|
|
|
#include "shrpx_https_upstream.h"
|
|
|
|
#include "shrpx_config.h"
|
2012-11-18 13:23:13 +01:00
|
|
|
#include "shrpx_http_downstream_connection.h"
|
2013-11-04 09:53:57 +01:00
|
|
|
#include "shrpx_http2_downstream_connection.h"
|
2014-01-01 16:53:07 +01:00
|
|
|
#include "shrpx_ssl.h"
|
2014-06-26 15:55:22 +02:00
|
|
|
#include "shrpx_worker.h"
|
2014-10-13 14:09:00 +02:00
|
|
|
#include "shrpx_downstream_connection_pool.h"
|
2014-11-18 16:56:44 +01:00
|
|
|
#include "shrpx_downstream.h"
|
2015-07-12 15:16:20 +02:00
|
|
|
#include "shrpx_http2_session.h"
|
2016-04-02 16:11:03 +02:00
|
|
|
#include "shrpx_connect_blocker.h"
|
2016-06-02 16:47:41 +02:00
|
|
|
#include "shrpx_api_downstream_connection.h"
|
2016-06-16 17:00:37 +02:00
|
|
|
#include "shrpx_health_monitor_downstream_connection.h"
|
2013-07-26 13:12:55 +02:00
|
|
|
#ifdef HAVE_SPDYLAY
|
|
|
|
#include "shrpx_spdy_upstream.h"
|
|
|
|
#endif // HAVE_SPDYLAY
|
2013-09-23 17:02:02 +02:00
|
|
|
#include "util.h"
|
2015-02-05 15:21:53 +01:00
|
|
|
#include "template.h"
|
2015-08-19 16:33:53 +02:00
|
|
|
#include "ssl.h"
|
2013-09-23 17:02:02 +02:00
|
|
|
|
|
|
|
using namespace nghttp2;
|
2013-07-26 13:12:55 +02:00
|
|
|
|
2012-06-04 16:48:31 +02:00
|
|
|
namespace shrpx {
|
|
|
|
|
|
|
|
namespace {
|
2014-12-27 18:59:06 +01:00
|
|
|
void timeoutcb(struct ev_loop *loop, ev_timer *w, int revents) {
|
2015-02-04 13:15:58 +01:00
|
|
|
auto conn = static_cast<Connection *>(w->data);
|
|
|
|
auto handler = static_cast<ClientHandler *>(conn->data);
|
2014-12-27 18:59:06 +01:00
|
|
|
|
|
|
|
if (LOG_ENABLED(INFO)) {
|
|
|
|
CLOG(INFO, handler) << "Time out";
|
2012-06-04 16:48:31 +02:00
|
|
|
}
|
2014-12-27 18:59:06 +01:00
|
|
|
|
|
|
|
delete handler;
|
2012-06-04 16:48:31 +02:00
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
namespace {
|
2014-12-27 18:59:06 +01:00
|
|
|
void shutdowncb(struct ev_loop *loop, ev_timer *w, int revents) {
|
|
|
|
auto handler = static_cast<ClientHandler *>(w->data);
|
|
|
|
|
|
|
|
if (LOG_ENABLED(INFO)) {
|
|
|
|
CLOG(INFO, handler) << "Close connection due to TLS renegotiation";
|
2014-09-18 16:03:36 +02:00
|
|
|
}
|
2014-06-10 17:07:51 +02:00
|
|
|
|
2014-12-27 18:59:06 +01:00
|
|
|
delete handler;
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
void readcb(struct ev_loop *loop, ev_io *w, int revents) {
|
2015-02-04 13:15:58 +01:00
|
|
|
auto conn = static_cast<Connection *>(w->data);
|
|
|
|
auto handler = static_cast<ClientHandler *>(conn->data);
|
2014-11-05 16:56:07 +01:00
|
|
|
|
2014-12-27 18:59:06 +01:00
|
|
|
if (handler->do_read() != 0) {
|
|
|
|
delete handler;
|
2012-11-21 19:13:30 +01:00
|
|
|
return;
|
|
|
|
}
|
2015-03-28 17:47:22 +01:00
|
|
|
if (handler->do_write() != 0) {
|
|
|
|
delete handler;
|
|
|
|
return;
|
2015-02-10 16:44:30 +01:00
|
|
|
}
|
2014-12-27 18:59:06 +01:00
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
void writecb(struct ev_loop *loop, ev_io *w, int revents) {
|
2015-02-04 13:15:58 +01:00
|
|
|
auto conn = static_cast<Connection *>(w->data);
|
|
|
|
auto handler = static_cast<ClientHandler *>(conn->data);
|
2014-12-27 18:59:06 +01:00
|
|
|
|
|
|
|
if (handler->do_write() != 0) {
|
2012-06-04 16:48:31 +02:00
|
|
|
delete handler;
|
2014-01-19 15:32:07 +01:00
|
|
|
return;
|
|
|
|
}
|
2014-12-27 18:59:06 +01:00
|
|
|
}
|
|
|
|
} // namespace
|
2014-09-18 16:03:36 +02:00
|
|
|
|
2015-09-07 15:35:02 +02:00
|
|
|
int ClientHandler::noop() { return 0; }
|
|
|
|
|
2014-12-27 18:59:06 +01:00
|
|
|
int ClientHandler::read_clear() {
|
2017-01-08 08:41:02 +01:00
|
|
|
rb_.ensure_chunk();
|
2014-12-27 18:59:06 +01:00
|
|
|
for (;;) {
|
|
|
|
if (rb_.rleft() && on_read() != 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
2015-02-13 14:41:50 +01:00
|
|
|
if (rb_.rleft() == 0) {
|
|
|
|
rb_.reset();
|
|
|
|
} else if (rb_.wleft() == 0) {
|
|
|
|
conn_.rlimit.stopw();
|
2015-01-06 14:48:17 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2015-01-29 14:47:37 +01:00
|
|
|
|
2016-01-27 07:26:06 +01:00
|
|
|
if (!ev_is_active(&conn_.rev)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-01-08 08:41:02 +01:00
|
|
|
auto nread = conn_.read_clear(rb_.last(), rb_.wleft());
|
2014-12-27 18:59:06 +01:00
|
|
|
|
2015-02-04 13:15:58 +01:00
|
|
|
if (nread == 0) {
|
2017-01-08 08:41:02 +01:00
|
|
|
if (rb_.rleft() == 0) {
|
|
|
|
rb_.release_chunk();
|
|
|
|
}
|
2015-02-04 13:15:58 +01:00
|
|
|
return 0;
|
2014-12-27 18:59:06 +01:00
|
|
|
}
|
|
|
|
|
2015-02-04 13:15:58 +01:00
|
|
|
if (nread < 0) {
|
2014-12-27 18:59:06 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
rb_.write(nread);
|
2014-01-19 15:32:07 +01:00
|
|
|
}
|
2014-12-27 18:59:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int ClientHandler::write_clear() {
|
2015-10-02 15:42:46 +02:00
|
|
|
std::array<iovec, 2> iov;
|
|
|
|
|
2014-12-27 18:59:06 +01:00
|
|
|
for (;;) {
|
|
|
|
if (on_write() != 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
2015-10-02 15:42:46 +02:00
|
|
|
|
|
|
|
auto iovcnt = upstream_->response_riovec(iov.data(), iov.size());
|
|
|
|
if (iovcnt == 0) {
|
2014-12-27 18:59:06 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-10-02 15:42:46 +02:00
|
|
|
auto nwrite = conn_.writev_clear(iov.data(), iovcnt);
|
|
|
|
if (nwrite < 0) {
|
2015-10-01 16:10:53 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2015-10-02 15:42:46 +02:00
|
|
|
|
|
|
|
if (nwrite == 0) {
|
|
|
|
return 0;
|
2015-10-01 16:10:53 +02:00
|
|
|
}
|
2015-10-02 15:42:46 +02:00
|
|
|
|
|
|
|
upstream_->response_drain(nwrite);
|
2015-10-01 16:10:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
conn_.wlimit.stopw();
|
|
|
|
ev_timer_stop(conn_.loop, &conn_.wt);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-12-27 18:59:06 +01:00
|
|
|
int ClientHandler::tls_handshake() {
|
2015-02-04 13:15:58 +01:00
|
|
|
ev_timer_again(conn_.loop, &conn_.rt);
|
2014-12-27 18:59:06 +01:00
|
|
|
|
2015-01-08 16:07:28 +01:00
|
|
|
ERR_clear_error();
|
|
|
|
|
2015-02-04 13:15:58 +01:00
|
|
|
auto rv = conn_.tls_handshake();
|
2014-12-27 18:59:06 +01:00
|
|
|
|
2015-02-04 13:15:58 +01:00
|
|
|
if (rv == SHRPX_ERR_INPROGRESS) {
|
|
|
|
return 0;
|
2014-12-27 18:59:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (rv < 0) {
|
2015-02-04 13:15:58 +01:00
|
|
|
return -1;
|
2012-06-04 16:48:31 +02:00
|
|
|
}
|
2014-12-27 18:59:06 +01:00
|
|
|
|
|
|
|
if (LOG_ENABLED(INFO)) {
|
|
|
|
CLOG(INFO, this) << "SSL/TLS handshake completed";
|
|
|
|
}
|
2015-02-04 13:15:58 +01:00
|
|
|
|
2014-12-27 18:59:06 +01:00
|
|
|
if (validate_next_proto() != 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
read_ = &ClientHandler::read_tls;
|
2015-10-02 15:42:46 +02:00
|
|
|
write_ = &ClientHandler::write_tls;
|
2014-12-27 18:59:06 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ClientHandler::read_tls() {
|
2015-01-08 16:07:28 +01:00
|
|
|
ERR_clear_error();
|
|
|
|
|
2017-01-08 08:41:02 +01:00
|
|
|
rb_.ensure_chunk();
|
|
|
|
|
2014-12-27 18:59:06 +01:00
|
|
|
for (;;) {
|
2015-01-06 14:48:17 +01:00
|
|
|
// we should process buffered data first before we read EOF.
|
2014-12-27 18:59:06 +01:00
|
|
|
if (rb_.rleft() && on_read() != 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
2015-02-13 14:41:50 +01:00
|
|
|
if (rb_.rleft() == 0) {
|
|
|
|
rb_.reset();
|
|
|
|
} else if (rb_.wleft() == 0) {
|
|
|
|
conn_.rlimit.stopw();
|
2015-01-06 14:48:17 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2015-01-29 14:47:37 +01:00
|
|
|
|
2016-01-27 07:26:06 +01:00
|
|
|
if (!ev_is_active(&conn_.rev)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-01-08 08:41:02 +01:00
|
|
|
auto nread = conn_.read_tls(rb_.last(), rb_.wleft());
|
2014-12-27 18:59:06 +01:00
|
|
|
|
2015-02-04 13:15:58 +01:00
|
|
|
if (nread == 0) {
|
2017-01-08 08:41:02 +01:00
|
|
|
if (rb_.rleft() == 0) {
|
|
|
|
rb_.release_chunk();
|
|
|
|
}
|
2015-02-04 13:15:58 +01:00
|
|
|
return 0;
|
2012-06-04 16:48:31 +02:00
|
|
|
}
|
2014-12-27 18:59:06 +01:00
|
|
|
|
2015-02-04 13:15:58 +01:00
|
|
|
if (nread < 0) {
|
|
|
|
return -1;
|
2014-12-27 18:59:06 +01:00
|
|
|
}
|
|
|
|
|
2015-02-04 13:15:58 +01:00
|
|
|
rb_.write(nread);
|
2012-06-04 16:48:31 +02:00
|
|
|
}
|
2014-12-27 18:59:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int ClientHandler::write_tls() {
|
2015-10-02 15:42:46 +02:00
|
|
|
struct iovec iov;
|
|
|
|
|
2015-01-08 16:07:28 +01:00
|
|
|
ERR_clear_error();
|
|
|
|
|
2016-09-08 15:49:36 +02:00
|
|
|
if (on_write() != 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
2015-10-02 15:42:46 +02:00
|
|
|
|
2016-09-08 15:49:36 +02:00
|
|
|
auto iovcnt = upstream_->response_riovec(&iov, 1);
|
|
|
|
if (iovcnt == 0) {
|
|
|
|
conn_.start_tls_write_idle();
|
|
|
|
|
|
|
|
conn_.wlimit.stopw();
|
|
|
|
ev_timer_stop(conn_.loop, &conn_.wt);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2014-12-27 18:59:06 +01:00
|
|
|
|
2016-09-08 15:49:36 +02:00
|
|
|
for (;;) {
|
2015-10-02 15:42:46 +02:00
|
|
|
auto nwrite = conn_.write_tls(iov.iov_base, iov.iov_len);
|
|
|
|
if (nwrite < 0) {
|
2015-10-01 16:10:53 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2015-10-02 15:42:46 +02:00
|
|
|
|
|
|
|
if (nwrite == 0) {
|
|
|
|
return 0;
|
2015-10-01 16:10:53 +02:00
|
|
|
}
|
2015-10-02 15:42:46 +02:00
|
|
|
|
|
|
|
upstream_->response_drain(nwrite);
|
2015-10-01 16:10:53 +02:00
|
|
|
|
2016-09-08 15:49:36 +02:00
|
|
|
iovcnt = upstream_->response_riovec(&iov, 1);
|
|
|
|
if (iovcnt == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2015-10-01 16:10:53 +02:00
|
|
|
}
|
|
|
|
|
2014-12-27 18:59:06 +01:00
|
|
|
int ClientHandler::upstream_noop() { return 0; }
|
|
|
|
|
|
|
|
int ClientHandler::upstream_read() {
|
|
|
|
assert(upstream_);
|
|
|
|
if (upstream_->on_read() != 0) {
|
|
|
|
return -1;
|
2013-07-26 14:35:14 +02:00
|
|
|
}
|
2014-12-27 18:59:06 +01:00
|
|
|
return 0;
|
2013-07-26 14:35:14 +02:00
|
|
|
}
|
|
|
|
|
2014-12-27 18:59:06 +01:00
|
|
|
int ClientHandler::upstream_write() {
|
|
|
|
assert(upstream_);
|
|
|
|
if (upstream_->on_write() != 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-10-02 15:42:46 +02:00
|
|
|
if (get_should_close_after_write() && upstream_->response_empty()) {
|
2014-12-27 18:59:06 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ClientHandler::upstream_http2_connhd_read() {
|
2015-01-29 14:47:37 +01:00
|
|
|
auto nread = std::min(left_connhd_len_, rb_.rleft());
|
2015-04-05 15:35:40 +02:00
|
|
|
if (memcmp(NGHTTP2_CLIENT_MAGIC + NGHTTP2_CLIENT_MAGIC_LEN - left_connhd_len_,
|
2017-01-08 08:41:02 +01:00
|
|
|
rb_.pos(), nread) != 0) {
|
2015-01-29 14:47:37 +01:00
|
|
|
// There is no downgrade path here. Just drop the connection.
|
|
|
|
if (LOG_ENABLED(INFO)) {
|
|
|
|
CLOG(INFO, this) << "invalid client connection header";
|
2014-12-27 18:59:06 +01:00
|
|
|
}
|
|
|
|
|
2015-01-29 14:47:37 +01:00
|
|
|
return -1;
|
|
|
|
}
|
2014-12-27 18:59:06 +01:00
|
|
|
|
2015-01-29 14:47:37 +01:00
|
|
|
left_connhd_len_ -= nread;
|
|
|
|
rb_.drain(nread);
|
2015-02-13 14:41:50 +01:00
|
|
|
conn_.rlimit.startw();
|
2015-01-29 14:47:37 +01:00
|
|
|
|
|
|
|
if (left_connhd_len_ == 0) {
|
|
|
|
on_read_ = &ClientHandler::upstream_read;
|
|
|
|
// Run on_read to process data left in buffer since they are not
|
|
|
|
// notified further
|
|
|
|
if (on_read() != 0) {
|
|
|
|
return -1;
|
2014-12-27 18:59:06 +01:00
|
|
|
}
|
2015-01-29 14:47:37 +01:00
|
|
|
return 0;
|
2013-08-03 11:51:01 +02:00
|
|
|
}
|
2014-12-27 18:59:06 +01:00
|
|
|
|
|
|
|
return 0;
|
2013-08-03 11:51:01 +02:00
|
|
|
}
|
|
|
|
|
2014-12-27 18:59:06 +01:00
|
|
|
int ClientHandler::upstream_http1_connhd_read() {
|
2015-01-29 14:47:37 +01:00
|
|
|
auto nread = std::min(left_connhd_len_, rb_.rleft());
|
2015-04-05 15:35:40 +02:00
|
|
|
if (memcmp(NGHTTP2_CLIENT_MAGIC + NGHTTP2_CLIENT_MAGIC_LEN - left_connhd_len_,
|
2017-01-08 08:41:02 +01:00
|
|
|
rb_.pos(), nread) != 0) {
|
2015-01-29 14:47:37 +01:00
|
|
|
if (LOG_ENABLED(INFO)) {
|
|
|
|
CLOG(INFO, this) << "This is HTTP/1.1 connection, "
|
|
|
|
<< "but may be upgraded to HTTP/2 later.";
|
|
|
|
}
|
2014-12-27 18:59:06 +01:00
|
|
|
|
2015-01-29 14:47:37 +01:00
|
|
|
// Reset header length for later HTTP/2 upgrade
|
2015-04-05 15:35:40 +02:00
|
|
|
left_connhd_len_ = NGHTTP2_CLIENT_MAGIC_LEN;
|
2015-01-29 14:47:37 +01:00
|
|
|
on_read_ = &ClientHandler::upstream_read;
|
|
|
|
on_write_ = &ClientHandler::upstream_write;
|
2014-12-27 18:59:06 +01:00
|
|
|
|
2015-01-29 14:47:37 +01:00
|
|
|
if (on_read() != 0) {
|
|
|
|
return -1;
|
2014-12-27 18:59:06 +01:00
|
|
|
}
|
|
|
|
|
2015-01-29 14:47:37 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2014-12-27 18:59:06 +01:00
|
|
|
|
2015-01-29 14:47:37 +01:00
|
|
|
left_connhd_len_ -= nread;
|
|
|
|
rb_.drain(nread);
|
2015-02-13 14:41:50 +01:00
|
|
|
conn_.rlimit.startw();
|
2014-12-27 18:59:06 +01:00
|
|
|
|
2015-01-29 14:47:37 +01:00
|
|
|
if (left_connhd_len_ == 0) {
|
|
|
|
if (LOG_ENABLED(INFO)) {
|
|
|
|
CLOG(INFO, this) << "direct HTTP/2 connection";
|
|
|
|
}
|
2014-12-27 18:59:06 +01:00
|
|
|
|
2015-01-29 14:47:37 +01:00
|
|
|
direct_http2_upgrade();
|
|
|
|
on_read_ = &ClientHandler::upstream_read;
|
|
|
|
on_write_ = &ClientHandler::upstream_write;
|
2014-12-27 18:59:06 +01:00
|
|
|
|
2015-01-29 14:47:37 +01:00
|
|
|
// Run on_read to process data left in buffer since they are not
|
|
|
|
// notified further
|
|
|
|
if (on_read() != 0) {
|
|
|
|
return -1;
|
2014-12-27 18:59:06 +01:00
|
|
|
}
|
2015-01-29 14:47:37 +01:00
|
|
|
|
|
|
|
return 0;
|
2014-12-27 18:59:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-02-11 11:18:41 +01:00
|
|
|
ClientHandler::ClientHandler(Worker *worker, int fd, SSL *ssl,
|
2016-09-30 16:09:02 +02:00
|
|
|
const StringRef &ipaddr, const StringRef &port,
|
|
|
|
int family, const UpstreamAddr *faddr)
|
2016-10-24 13:56:36 +02:00
|
|
|
: // We use balloc_ for TLS session ID (64), ipaddr (IPv6) (39),
|
|
|
|
// port (5), forwarded-for (IPv6) (41), alpn (5), proxyproto
|
|
|
|
// ipaddr (15), proxyproto port (5), sni (32, estimated). we
|
|
|
|
// need terminal NULL byte for each. We also require 8 bytes
|
|
|
|
// header for each allocation. We align at 16 bytes boundary,
|
|
|
|
// so the required space is 64 + 48 + 16 + 48 + 16 + 16 + 16 +
|
|
|
|
// 32 + 8 + 8 * 8 = 328.
|
|
|
|
balloc_(512, 512),
|
2017-01-08 08:41:02 +01:00
|
|
|
rb_(worker->get_mcpool()),
|
2016-09-30 16:09:02 +02:00
|
|
|
conn_(worker->get_loop(), fd, ssl, worker->get_mcpool(),
|
2016-01-19 08:56:12 +01:00
|
|
|
get_config()->conn.upstream.timeout.write,
|
|
|
|
get_config()->conn.upstream.timeout.read,
|
|
|
|
get_config()->conn.upstream.ratelimit.write,
|
|
|
|
get_config()->conn.upstream.ratelimit.read, writecb, readcb,
|
|
|
|
timeoutcb, this, get_config()->tls.dyn_rec.warmup_threshold,
|
2016-02-28 08:56:14 +01:00
|
|
|
get_config()->tls.dyn_rec.idle_timeout, PROTO_NONE),
|
2016-09-30 16:09:02 +02:00
|
|
|
ipaddr_(make_string_ref(balloc_, ipaddr)),
|
|
|
|
port_(make_string_ref(balloc_, port)),
|
2016-01-31 11:41:56 +01:00
|
|
|
faddr_(faddr),
|
2016-01-27 13:14:07 +01:00
|
|
|
worker_(worker),
|
2015-04-05 15:35:40 +02:00
|
|
|
left_connhd_len_(NGHTTP2_CLIENT_MAGIC_LEN),
|
2016-07-06 15:31:28 +02:00
|
|
|
affinity_hash_(0),
|
|
|
|
should_close_after_write_(false),
|
|
|
|
affinity_hash_computed_(false) {
|
2014-03-09 06:53:28 +01:00
|
|
|
|
2015-02-11 11:18:41 +01:00
|
|
|
++worker_->get_worker_stat()->num_connections;
|
2014-06-26 15:55:22 +02:00
|
|
|
|
2014-12-27 18:59:06 +01:00
|
|
|
ev_timer_init(&reneg_shutdown_timer_, shutdowncb, 0., 0.);
|
|
|
|
|
|
|
|
reneg_shutdown_timer_.data = this;
|
|
|
|
|
2015-02-04 13:15:58 +01:00
|
|
|
conn_.rlimit.startw();
|
|
|
|
ev_timer_again(conn_.loop, &conn_.rt);
|
2014-03-09 06:53:28 +01:00
|
|
|
|
2016-10-08 04:34:23 +02:00
|
|
|
auto config = get_config();
|
|
|
|
|
2017-01-03 04:47:03 +01:00
|
|
|
if (faddr_->accept_proxy_protocol ||
|
|
|
|
config->conn.upstream.accept_proxy_protocol) {
|
2015-09-07 15:35:02 +02:00
|
|
|
read_ = &ClientHandler::read_clear;
|
|
|
|
write_ = &ClientHandler::noop;
|
2015-09-06 11:39:32 +02:00
|
|
|
on_read_ = &ClientHandler::proxy_protocol_read;
|
|
|
|
on_write_ = &ClientHandler::upstream_noop;
|
|
|
|
} else {
|
|
|
|
setup_upstream_io_callback();
|
|
|
|
}
|
2016-01-15 15:04:58 +01:00
|
|
|
|
2016-10-08 04:34:23 +02:00
|
|
|
auto &fwdconf = config->http.forwarded;
|
2016-01-18 09:00:20 +01:00
|
|
|
|
2016-02-01 15:29:17 +01:00
|
|
|
if (fwdconf.params & FORWARDED_FOR) {
|
|
|
|
if (fwdconf.for_node_type == FORWARDED_NODE_OBFUSCATED) {
|
2016-09-30 16:09:02 +02:00
|
|
|
// 1 for '_'
|
|
|
|
auto len = SHRPX_OBFUSCATED_NODE_LENGTH + 1;
|
|
|
|
// 1 for terminating NUL.
|
|
|
|
auto buf = make_byte_ref(balloc_, len + 1);
|
|
|
|
auto p = buf.base;
|
|
|
|
*p++ = '_';
|
2016-10-03 15:07:18 +02:00
|
|
|
p = util::random_alpha_digit(p, p + SHRPX_OBFUSCATED_NODE_LENGTH,
|
|
|
|
worker_->get_randgen());
|
2016-09-30 16:09:02 +02:00
|
|
|
*p = '\0';
|
|
|
|
|
|
|
|
forwarded_for_ = StringRef{buf.base, p};
|
2016-02-01 15:29:17 +01:00
|
|
|
} else if (family == AF_INET6) {
|
2016-09-30 16:09:02 +02:00
|
|
|
// 2 for '[' and ']'
|
|
|
|
auto len = 2 + ipaddr_.size();
|
|
|
|
// 1 for terminating NUL.
|
|
|
|
auto buf = make_byte_ref(balloc_, len + 1);
|
|
|
|
auto p = buf.base;
|
|
|
|
*p++ = '[';
|
|
|
|
p = std::copy(std::begin(ipaddr_), std::end(ipaddr_), p);
|
|
|
|
*p++ = ']';
|
|
|
|
*p = '\0';
|
|
|
|
|
|
|
|
forwarded_for_ = StringRef{buf.base, p};
|
2016-02-01 15:29:17 +01:00
|
|
|
} else {
|
|
|
|
// family == AF_INET or family == AF_UNIX
|
|
|
|
forwarded_for_ = ipaddr_;
|
|
|
|
}
|
2016-01-15 15:04:58 +01:00
|
|
|
}
|
2015-09-06 11:39:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ClientHandler::setup_upstream_io_callback() {
|
2015-02-04 13:15:58 +01:00
|
|
|
if (conn_.tls.ssl) {
|
2015-07-25 15:22:17 +02:00
|
|
|
conn_.prepare_server_handshake();
|
2014-12-27 18:59:06 +01:00
|
|
|
read_ = write_ = &ClientHandler::tls_handshake;
|
|
|
|
on_read_ = &ClientHandler::upstream_noop;
|
|
|
|
on_write_ = &ClientHandler::upstream_write;
|
2012-11-18 13:23:13 +01:00
|
|
|
} else {
|
2013-08-03 11:51:01 +02:00
|
|
|
// For non-TLS version, first create HttpsUpstream. It may be
|
2014-03-30 12:09:21 +02:00
|
|
|
// upgraded to HTTP/2 through HTTP Upgrade or direct HTTP/2
|
2013-08-03 11:51:01 +02:00
|
|
|
// connection.
|
2015-02-05 15:21:53 +01:00
|
|
|
upstream_ = make_unique<HttpsUpstream>(this);
|
2016-09-30 16:09:02 +02:00
|
|
|
alpn_ = StringRef::from_lit("http/1.1");
|
2014-12-27 18:59:06 +01:00
|
|
|
read_ = &ClientHandler::read_clear;
|
2015-10-02 15:42:46 +02:00
|
|
|
write_ = &ClientHandler::write_clear;
|
2014-12-27 18:59:06 +01:00
|
|
|
on_read_ = &ClientHandler::upstream_http1_connhd_read;
|
|
|
|
on_write_ = &ClientHandler::upstream_noop;
|
2012-11-18 13:23:13 +01:00
|
|
|
}
|
2012-06-04 16:48:31 +02:00
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
ClientHandler::~ClientHandler() {
|
|
|
|
if (LOG_ENABLED(INFO)) {
|
2012-12-09 11:15:14 +01:00
|
|
|
CLOG(INFO, this) << "Deleting";
|
2012-06-04 16:48:31 +02:00
|
|
|
}
|
2014-06-10 17:07:51 +02:00
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (upstream_) {
|
2014-11-18 17:59:09 +01:00
|
|
|
upstream_->on_handler_delete();
|
|
|
|
}
|
|
|
|
|
2015-02-11 11:18:41 +01:00
|
|
|
auto worker_stat = worker_->get_worker_stat();
|
|
|
|
--worker_stat->num_connections;
|
2014-06-26 15:55:22 +02:00
|
|
|
|
2015-04-07 15:13:01 +02:00
|
|
|
if (worker_stat->num_connections == 0) {
|
2015-04-08 06:43:57 +02:00
|
|
|
worker_->schedule_clear_mcpool();
|
2015-04-07 15:13:01 +02:00
|
|
|
}
|
|
|
|
|
2015-02-04 13:15:58 +01:00
|
|
|
ev_timer_stop(conn_.loop, &reneg_shutdown_timer_);
|
2014-12-27 18:59:06 +01:00
|
|
|
|
2014-08-12 15:22:02 +02:00
|
|
|
// TODO If backend is http/2, and it is in CONNECTED state, signal
|
|
|
|
// it and make it loopbreak when output is zero.
|
2015-02-25 14:53:23 +01:00
|
|
|
if (worker_->get_graceful_shutdown() && worker_stat->num_connections == 0) {
|
2015-02-04 13:15:58 +01:00
|
|
|
ev_break(conn_.loop);
|
2014-06-10 18:16:49 +02:00
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (LOG_ENABLED(INFO)) {
|
2012-12-09 11:15:14 +01:00
|
|
|
CLOG(INFO, this) << "Deleted";
|
2012-06-04 16:48:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
Upstream *ClientHandler::get_upstream() { return upstream_.get(); }
|
2012-06-04 16:48:31 +02:00
|
|
|
|
2014-12-27 18:59:06 +01:00
|
|
|
struct ev_loop *ClientHandler::get_loop() const {
|
2015-02-04 13:15:58 +01:00
|
|
|
return conn_.loop;
|
2012-06-04 16:48:31 +02:00
|
|
|
}
|
|
|
|
|
2014-12-27 18:59:06 +01:00
|
|
|
void ClientHandler::reset_upstream_read_timeout(ev_tstamp t) {
|
2015-02-04 13:15:58 +01:00
|
|
|
conn_.rt.repeat = t;
|
|
|
|
if (ev_is_active(&conn_.rt)) {
|
|
|
|
ev_timer_again(conn_.loop, &conn_.rt);
|
2014-12-27 18:59:06 +01:00
|
|
|
}
|
2012-06-04 16:48:31 +02:00
|
|
|
}
|
|
|
|
|
2014-12-27 18:59:06 +01:00
|
|
|
void ClientHandler::reset_upstream_write_timeout(ev_tstamp t) {
|
2015-02-04 13:15:58 +01:00
|
|
|
conn_.wt.repeat = t;
|
|
|
|
if (ev_is_active(&conn_.wt)) {
|
|
|
|
ev_timer_again(conn_.loop, &conn_.wt);
|
2014-12-27 18:59:06 +01:00
|
|
|
}
|
2012-06-04 16:48:31 +02:00
|
|
|
}
|
|
|
|
|
2016-06-23 17:04:39 +02:00
|
|
|
void ClientHandler::repeat_read_timer() {
|
|
|
|
ev_timer_again(conn_.loop, &conn_.rt);
|
2016-03-05 11:11:36 +01:00
|
|
|
}
|
|
|
|
|
2016-06-23 17:04:39 +02:00
|
|
|
void ClientHandler::stop_read_timer() { ev_timer_stop(conn_.loop, &conn_.rt); }
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
int ClientHandler::validate_next_proto() {
|
2013-07-26 12:33:25 +02:00
|
|
|
const unsigned char *next_proto = nullptr;
|
2016-04-08 16:03:42 +02:00
|
|
|
unsigned int next_proto_len = 0;
|
2014-06-10 17:07:51 +02:00
|
|
|
|
2013-07-26 14:35:14 +02:00
|
|
|
// First set callback for catch all cases
|
2014-12-27 18:59:06 +01:00
|
|
|
on_read_ = &ClientHandler::upstream_read;
|
|
|
|
|
2015-02-04 13:15:58 +01:00
|
|
|
SSL_get0_next_proto_negotiated(conn_.tls.ssl, &next_proto, &next_proto_len);
|
2015-08-31 16:30:40 +02:00
|
|
|
#if OPENSSL_VERSION_NUMBER >= 0x10002000L
|
|
|
|
if (next_proto == nullptr) {
|
|
|
|
SSL_get0_alpn_selected(conn_.tls.ssl, &next_proto, &next_proto_len);
|
|
|
|
}
|
|
|
|
#endif // OPENSSL_VERSION_NUMBER >= 0x10002000L
|
2014-04-26 15:51:39 +02:00
|
|
|
|
2015-08-31 16:30:40 +02:00
|
|
|
if (next_proto == nullptr) {
|
|
|
|
if (LOG_ENABLED(INFO)) {
|
|
|
|
CLOG(INFO, this) << "No protocol negotiated. Fallback to HTTP/1.1";
|
|
|
|
}
|
2014-06-10 17:07:51 +02:00
|
|
|
|
2015-08-31 16:30:40 +02:00
|
|
|
upstream_ = make_unique<HttpsUpstream>(this);
|
2016-09-30 16:09:02 +02:00
|
|
|
alpn_ = StringRef::from_lit("http/1.1");
|
2014-06-10 17:07:51 +02:00
|
|
|
|
2015-08-31 16:30:40 +02:00
|
|
|
// At this point, input buffer is already filled with some bytes.
|
|
|
|
// The read callback is not called until new data come. So consume
|
|
|
|
// input buffer here.
|
|
|
|
if (on_read() != 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-03-24 16:02:07 +01:00
|
|
|
auto proto = StringRef{next_proto, next_proto_len};
|
|
|
|
|
2015-08-31 16:30:40 +02:00
|
|
|
if (LOG_ENABLED(INFO)) {
|
|
|
|
CLOG(INFO, this) << "The negotiated next protocol: " << proto;
|
|
|
|
}
|
2015-08-19 16:33:53 +02:00
|
|
|
|
2016-03-24 16:02:07 +01:00
|
|
|
if (!ssl::in_proto_list(get_config()->tls.npn_list, proto)) {
|
2015-08-31 16:30:40 +02:00
|
|
|
if (LOG_ENABLED(INFO)) {
|
2016-03-24 16:02:07 +01:00
|
|
|
CLOG(INFO, this) << "The negotiated protocol is not supported: " << proto;
|
2015-08-31 16:30:40 +02:00
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
2014-06-10 17:07:51 +02:00
|
|
|
|
2016-03-24 16:02:07 +01:00
|
|
|
if (util::check_h2_is_selected(proto)) {
|
2015-08-31 16:30:40 +02:00
|
|
|
on_read_ = &ClientHandler::upstream_http2_connhd_read;
|
2014-04-26 15:51:39 +02:00
|
|
|
|
2015-08-31 16:30:40 +02:00
|
|
|
auto http2_upstream = make_unique<Http2Upstream>(this);
|
2014-06-10 17:07:51 +02:00
|
|
|
|
2015-08-31 16:30:40 +02:00
|
|
|
upstream_ = std::move(http2_upstream);
|
2016-09-30 16:09:02 +02:00
|
|
|
alpn_ = make_string_ref(balloc_, proto);
|
2015-08-31 16:30:40 +02:00
|
|
|
|
|
|
|
// At this point, input buffer is already filled with some bytes.
|
|
|
|
// The read callback is not called until new data come. So consume
|
|
|
|
// input buffer here.
|
|
|
|
if (on_read() != 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2014-06-19 15:40:24 +02:00
|
|
|
|
2014-01-01 15:54:28 +01:00
|
|
|
#ifdef HAVE_SPDYLAY
|
2016-03-24 16:02:07 +01:00
|
|
|
auto spdy_version = spdylay_npn_get_version(proto.byte(), proto.size());
|
2015-08-31 16:30:40 +02:00
|
|
|
if (spdy_version) {
|
|
|
|
upstream_ = make_unique<SpdyUpstream>(spdy_version, this);
|
|
|
|
|
|
|
|
switch (spdy_version) {
|
|
|
|
case SPDYLAY_PROTO_SPDY2:
|
2016-09-30 16:09:02 +02:00
|
|
|
alpn_ = StringRef::from_lit("spdy/2");
|
2015-08-31 16:30:40 +02:00
|
|
|
break;
|
|
|
|
case SPDYLAY_PROTO_SPDY3:
|
2016-09-30 16:09:02 +02:00
|
|
|
alpn_ = StringRef::from_lit("spdy/3");
|
2014-01-01 15:54:28 +01:00
|
|
|
break;
|
2015-08-31 16:30:40 +02:00
|
|
|
case SPDYLAY_PROTO_SPDY3_1:
|
2016-09-30 16:09:02 +02:00
|
|
|
alpn_ = StringRef::from_lit("spdy/3.1");
|
2015-08-31 16:30:40 +02:00
|
|
|
break;
|
|
|
|
default:
|
2016-09-30 16:09:02 +02:00
|
|
|
alpn_ = StringRef::from_lit("spdy/unknown");
|
2012-06-04 16:48:31 +02:00
|
|
|
}
|
2015-08-31 16:30:40 +02:00
|
|
|
|
|
|
|
// At this point, input buffer is already filled with some bytes.
|
|
|
|
// The read callback is not called until new data come. So consume
|
|
|
|
// input buffer here.
|
|
|
|
if (on_read() != 0) {
|
|
|
|
return -1;
|
2012-06-04 16:48:31 +02:00
|
|
|
}
|
2015-08-31 16:30:40 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif // HAVE_SPDYLAY
|
|
|
|
|
2016-03-24 16:02:07 +01:00
|
|
|
if (proto == StringRef::from_lit("http/1.1")) {
|
2015-02-05 15:21:53 +01:00
|
|
|
upstream_ = make_unique<HttpsUpstream>(this);
|
2016-09-30 16:09:02 +02:00
|
|
|
alpn_ = StringRef::from_lit("http/1.1");
|
2014-06-19 15:40:24 +02:00
|
|
|
|
|
|
|
// At this point, input buffer is already filled with some bytes.
|
|
|
|
// The read callback is not called until new data come. So consume
|
|
|
|
// input buffer here.
|
2014-12-27 18:59:06 +01:00
|
|
|
if (on_read() != 0) {
|
2014-06-19 15:40:24 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-01-01 16:53:07 +01:00
|
|
|
return 0;
|
2012-06-04 16:48:31 +02:00
|
|
|
}
|
2014-11-27 15:39:04 +01:00
|
|
|
if (LOG_ENABLED(INFO)) {
|
2014-01-01 16:53:07 +01:00
|
|
|
CLOG(INFO, this) << "The negotiated protocol is not supported";
|
2012-06-05 18:26:04 +02:00
|
|
|
}
|
2014-01-01 16:53:07 +01:00
|
|
|
return -1;
|
2012-06-04 16:48:31 +02:00
|
|
|
}
|
|
|
|
|
2014-12-27 18:59:06 +01:00
|
|
|
int ClientHandler::do_read() { return read_(*this); }
|
|
|
|
int ClientHandler::do_write() { return write_(*this); }
|
2014-10-30 13:47:38 +01:00
|
|
|
|
nghttpx: Fix bug that data buffered in SSL object are not read
This is same issue described in https://github.com/h2o/h2o/issues/268.
That is if SSL object has decrypted data buffered inside it, and
application does not read it for some reason (e.g., rate limit), we
have to check the existence of data using SSL_pending. This is
because buffered data inside SSL is not notified by io watcher. It is
obvious, but we totally missed it.
nghttpx code normally reads everything until SSL_read returns error
(want-read). But if rate limit is involved, we stop reading early.
Also in HTTP/1 code, while processing one request, we just read until
buffer is filled up. In these cases, we may suffer from this problem.
This commit fixes this problem, by performing SSL_pending() and if it
has buffered data and read io watcher is enabled, we feed event using
ev_feed_event().
2015-04-06 15:31:36 +02:00
|
|
|
int ClientHandler::on_read() {
|
2017-01-08 08:41:02 +01:00
|
|
|
if (rb_.chunk_avail()) {
|
|
|
|
auto rv = on_read_(*this);
|
|
|
|
if (rv != 0) {
|
|
|
|
return rv;
|
|
|
|
}
|
nghttpx: Fix bug that data buffered in SSL object are not read
This is same issue described in https://github.com/h2o/h2o/issues/268.
That is if SSL object has decrypted data buffered inside it, and
application does not read it for some reason (e.g., rate limit), we
have to check the existence of data using SSL_pending. This is
because buffered data inside SSL is not notified by io watcher. It is
obvious, but we totally missed it.
nghttpx code normally reads everything until SSL_read returns error
(want-read). But if rate limit is involved, we stop reading early.
Also in HTTP/1 code, while processing one request, we just read until
buffer is filled up. In these cases, we may suffer from this problem.
This commit fixes this problem, by performing SSL_pending() and if it
has buffered data and read io watcher is enabled, we feed event using
ev_feed_event().
2015-04-06 15:31:36 +02:00
|
|
|
}
|
|
|
|
conn_.handle_tls_pending_read();
|
|
|
|
return 0;
|
|
|
|
}
|
2014-12-27 18:59:06 +01:00
|
|
|
int ClientHandler::on_write() { return on_write_(*this); }
|
2014-10-30 13:47:38 +01:00
|
|
|
|
2016-09-30 16:09:02 +02:00
|
|
|
const StringRef &ClientHandler::get_ipaddr() const { return ipaddr_; }
|
2012-06-04 16:48:31 +02:00
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
bool ClientHandler::get_should_close_after_write() const {
|
2012-06-04 16:48:31 +02:00
|
|
|
return should_close_after_write_;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
void ClientHandler::set_should_close_after_write(bool f) {
|
2012-06-04 16:48:31 +02:00
|
|
|
should_close_after_write_ = f;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
void ClientHandler::pool_downstream_connection(
|
|
|
|
std::unique_ptr<DownstreamConnection> dconn) {
|
2015-03-10 15:11:22 +01:00
|
|
|
if (!dconn->poolable()) {
|
|
|
|
return;
|
|
|
|
}
|
2016-02-27 15:24:14 +01:00
|
|
|
|
|
|
|
dconn->set_client_handler(nullptr);
|
|
|
|
|
2016-08-04 17:04:47 +02:00
|
|
|
auto &group = dconn->get_downstream_addr_group();
|
2016-02-27 15:24:14 +01:00
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (LOG_ENABLED(INFO)) {
|
2015-07-09 19:52:11 +02:00
|
|
|
CLOG(INFO, this) << "Pooling downstream connection DCONN:" << dconn.get()
|
2016-02-27 15:24:14 +01:00
|
|
|
<< " in group " << group;
|
2012-06-09 16:14:00 +02:00
|
|
|
}
|
2016-02-27 15:24:14 +01:00
|
|
|
|
2016-06-09 16:17:41 +02:00
|
|
|
auto &shared_addr = group->shared_addr;
|
|
|
|
|
|
|
|
if (shared_addr->affinity == AFFINITY_NONE) {
|
|
|
|
auto &dconn_pool = group->shared_addr->dconn_pool;
|
|
|
|
dconn_pool.add_downstream_connection(std::move(dconn));
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto addr = dconn->get_addr();
|
|
|
|
auto &dconn_pool = addr->dconn_pool;
|
|
|
|
dconn_pool->add_downstream_connection(std::move(dconn));
|
2012-06-09 16:14:00 +02:00
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
void ClientHandler::remove_downstream_connection(DownstreamConnection *dconn) {
|
|
|
|
if (LOG_ENABLED(INFO)) {
|
2012-12-09 11:15:14 +01:00
|
|
|
CLOG(INFO, this) << "Removing downstream connection DCONN:" << dconn
|
|
|
|
<< " from pool";
|
2012-06-09 16:14:00 +02:00
|
|
|
}
|
2016-03-22 15:51:00 +01:00
|
|
|
auto &dconn_pool =
|
|
|
|
dconn->get_downstream_addr_group()->shared_addr->dconn_pool;
|
2016-02-27 15:24:14 +01:00
|
|
|
dconn_pool.remove_downstream_connection(dconn);
|
2012-06-09 16:14:00 +02:00
|
|
|
}
|
|
|
|
|
2016-06-09 15:35:59 +02:00
|
|
|
namespace {
|
2016-07-06 15:31:28 +02:00
|
|
|
// Computes 32bits hash for session affinity for IP address |ip|.
|
|
|
|
uint32_t compute_affinity_from_ip(const StringRef &ip) {
|
|
|
|
int rv;
|
|
|
|
std::array<uint8_t, 32> buf;
|
2016-06-09 15:35:59 +02:00
|
|
|
|
2016-07-06 15:31:28 +02:00
|
|
|
rv = util::sha256(buf.data(), ip);
|
|
|
|
if (rv != 0) {
|
|
|
|
// Not sure when sha256 failed. Just fall back to another
|
|
|
|
// function.
|
|
|
|
return util::hash32(ip);
|
2016-06-09 15:35:59 +02:00
|
|
|
}
|
|
|
|
|
2016-07-06 16:58:53 +02:00
|
|
|
return (static_cast<uint32_t>(buf[0]) << 24) |
|
|
|
|
(static_cast<uint32_t>(buf[1]) << 16) |
|
|
|
|
(static_cast<uint32_t>(buf[2]) << 8) | static_cast<uint32_t>(buf[3]);
|
2016-06-09 15:35:59 +02:00
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
Http2Session *ClientHandler::select_http2_session_with_affinity(
|
|
|
|
const std::shared_ptr<DownstreamAddrGroup> &group, DownstreamAddr *addr) {
|
|
|
|
auto &shared_addr = group->shared_addr;
|
|
|
|
|
|
|
|
if (LOG_ENABLED(INFO)) {
|
|
|
|
CLOG(INFO, this) << "Selected DownstreamAddr=" << addr
|
|
|
|
<< ", index=" << (addr - shared_addr->addrs.data());
|
|
|
|
}
|
|
|
|
|
2016-09-22 16:17:49 +02:00
|
|
|
for (auto session = addr->http2_extra_freelist.head; session;) {
|
|
|
|
auto next = session->dlnext;
|
|
|
|
|
|
|
|
if (session->max_concurrency_reached(0)) {
|
|
|
|
if (LOG_ENABLED(INFO)) {
|
|
|
|
CLOG(INFO, this)
|
|
|
|
<< "Maximum streams have been reached for Http2Session(" << session
|
|
|
|
<< "). Skip it";
|
|
|
|
}
|
|
|
|
|
|
|
|
session->remove_from_freelist();
|
|
|
|
session = next;
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
2016-06-09 15:35:59 +02:00
|
|
|
|
|
|
|
if (LOG_ENABLED(INFO)) {
|
|
|
|
CLOG(INFO, this) << "Use Http2Session " << session
|
|
|
|
<< " from http2_extra_freelist";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (session->max_concurrency_reached(1)) {
|
|
|
|
if (LOG_ENABLED(INFO)) {
|
|
|
|
CLOG(INFO, this) << "Maximum streams are reached for Http2Session("
|
|
|
|
<< session << ").";
|
|
|
|
}
|
2016-06-09 16:17:41 +02:00
|
|
|
|
|
|
|
session->remove_from_freelist();
|
2016-06-09 15:35:59 +02:00
|
|
|
}
|
|
|
|
return session;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto session = new Http2Session(conn_.loop, worker_->get_cl_ssl_ctx(),
|
|
|
|
worker_, group, addr);
|
|
|
|
|
|
|
|
if (LOG_ENABLED(INFO)) {
|
|
|
|
CLOG(INFO, this) << "Create new Http2Session " << session;
|
|
|
|
}
|
|
|
|
|
2016-06-09 16:17:41 +02:00
|
|
|
session->add_to_extra_freelist();
|
2016-06-09 15:35:59 +02:00
|
|
|
|
|
|
|
return session;
|
|
|
|
}
|
|
|
|
|
2016-04-02 16:11:03 +02:00
|
|
|
namespace {
|
|
|
|
// Returns true if load of |lhs| is lighter than that of |rhs|.
|
|
|
|
// Currently, we assume that lesser streams means lesser load.
|
|
|
|
bool load_lighter(const DownstreamAddr *lhs, const DownstreamAddr *rhs) {
|
|
|
|
return lhs->num_dconn < rhs->num_dconn;
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2016-06-02 18:20:49 +02:00
|
|
|
Http2Session *ClientHandler::select_http2_session(
|
|
|
|
const std::shared_ptr<DownstreamAddrGroup> &group) {
|
|
|
|
auto &shared_addr = group->shared_addr;
|
2016-04-02 16:11:03 +02:00
|
|
|
|
|
|
|
// First count the working backend addresses.
|
|
|
|
size_t min = 0;
|
|
|
|
for (const auto &addr : shared_addr->addrs) {
|
2016-05-24 16:36:43 +02:00
|
|
|
if (addr.proto != PROTO_HTTP2 || addr.connect_blocker->blocked()) {
|
2016-04-02 16:11:03 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
++min;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (min == 0) {
|
|
|
|
if (LOG_ENABLED(INFO)) {
|
|
|
|
CLOG(INFO, this) << "No working backend address found";
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto &http2_avail_freelist = shared_addr->http2_avail_freelist;
|
|
|
|
|
|
|
|
if (http2_avail_freelist.size() >= min) {
|
2016-09-14 17:25:41 +02:00
|
|
|
for (auto session = http2_avail_freelist.head; session;) {
|
|
|
|
auto next = session->dlnext;
|
2016-04-02 16:11:03 +02:00
|
|
|
|
2016-09-14 17:25:41 +02:00
|
|
|
session->remove_from_freelist();
|
|
|
|
|
|
|
|
// session may be in graceful shutdown period now.
|
|
|
|
if (session->max_concurrency_reached(0)) {
|
|
|
|
if (LOG_ENABLED(INFO)) {
|
|
|
|
CLOG(INFO, this)
|
|
|
|
<< "Maximum streams have been reached for Http2Session("
|
|
|
|
<< session << "). Skip it";
|
|
|
|
}
|
|
|
|
|
|
|
|
session = next;
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
2016-04-02 16:11:03 +02:00
|
|
|
|
|
|
|
if (LOG_ENABLED(INFO)) {
|
2016-09-14 17:25:41 +02:00
|
|
|
CLOG(INFO, this) << "Use Http2Session " << session
|
|
|
|
<< " from http2_avail_freelist";
|
2016-04-02 16:11:03 +02:00
|
|
|
}
|
2016-09-14 17:25:41 +02:00
|
|
|
|
|
|
|
if (session->max_concurrency_reached(1)) {
|
|
|
|
if (LOG_ENABLED(INFO)) {
|
|
|
|
CLOG(INFO, this) << "Maximum streams are reached for Http2Session("
|
|
|
|
<< session << ").";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
session->add_to_avail_freelist();
|
|
|
|
}
|
|
|
|
return session;
|
2016-04-02 16:11:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DownstreamAddr *selected_addr = nullptr;
|
|
|
|
|
|
|
|
for (auto &addr : shared_addr->addrs) {
|
2016-09-14 17:25:41 +02:00
|
|
|
if (addr.in_avail || addr.proto != PROTO_HTTP2 ||
|
|
|
|
(addr.http2_extra_freelist.size() == 0 &&
|
|
|
|
addr.connect_blocker->blocked())) {
|
2016-04-02 16:11:03 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-09-14 17:25:41 +02:00
|
|
|
for (auto session = addr.http2_extra_freelist.head; session;) {
|
|
|
|
auto next = session->dlnext;
|
|
|
|
|
|
|
|
// session may be in graceful shutdown period now.
|
|
|
|
if (session->max_concurrency_reached(0)) {
|
|
|
|
if (LOG_ENABLED(INFO)) {
|
|
|
|
CLOG(INFO, this)
|
|
|
|
<< "Maximum streams have been reached for Http2Session("
|
|
|
|
<< session << "). Skip it";
|
|
|
|
}
|
|
|
|
|
|
|
|
session->remove_from_freelist();
|
|
|
|
|
|
|
|
session = next;
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (addr.http2_extra_freelist.size() == 0 &&
|
|
|
|
addr.connect_blocker->blocked()) {
|
2016-04-02 16:11:03 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (selected_addr == nullptr || load_lighter(&addr, selected_addr)) {
|
|
|
|
selected_addr = &addr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(selected_addr);
|
|
|
|
|
|
|
|
if (LOG_ENABLED(INFO)) {
|
|
|
|
CLOG(INFO, this) << "Selected DownstreamAddr=" << selected_addr
|
|
|
|
<< ", index="
|
2016-04-24 10:42:24 +02:00
|
|
|
<< (selected_addr - shared_addr->addrs.data());
|
2016-04-02 16:11:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (selected_addr->http2_extra_freelist.size()) {
|
|
|
|
auto session = selected_addr->http2_extra_freelist.head;
|
|
|
|
session->remove_from_freelist();
|
|
|
|
|
|
|
|
if (LOG_ENABLED(INFO)) {
|
|
|
|
CLOG(INFO, this) << "Use Http2Session " << session
|
|
|
|
<< " from http2_extra_freelist";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (session->max_concurrency_reached(1)) {
|
|
|
|
if (LOG_ENABLED(INFO)) {
|
|
|
|
CLOG(INFO, this) << "Maximum streams are reached for Http2Session("
|
|
|
|
<< session << ").";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
session->add_to_avail_freelist();
|
|
|
|
}
|
|
|
|
return session;
|
|
|
|
}
|
|
|
|
|
2016-05-24 16:36:43 +02:00
|
|
|
auto session = new Http2Session(conn_.loop, worker_->get_cl_ssl_ctx(),
|
2016-06-02 18:20:49 +02:00
|
|
|
worker_, group, selected_addr);
|
2016-04-02 16:11:03 +02:00
|
|
|
|
|
|
|
if (LOG_ENABLED(INFO)) {
|
|
|
|
CLOG(INFO, this) << "Create new Http2Session " << session;
|
|
|
|
}
|
|
|
|
|
|
|
|
session->add_to_avail_freelist();
|
|
|
|
|
|
|
|
return session;
|
|
|
|
}
|
|
|
|
|
2016-05-24 16:36:43 +02:00
|
|
|
namespace {
|
2016-05-25 16:07:04 +02:00
|
|
|
// The chosen value is small enough for uint32_t, and large enough for
|
|
|
|
// the number of backend.
|
|
|
|
constexpr uint32_t WEIGHT_MAX = 65536;
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
bool pri_less(const WeightedPri &lhs, const WeightedPri &rhs) {
|
2016-05-24 16:36:43 +02:00
|
|
|
if (lhs.cycle < rhs.cycle) {
|
2016-05-25 16:07:04 +02:00
|
|
|
return rhs.cycle - lhs.cycle <= WEIGHT_MAX;
|
2016-05-24 16:36:43 +02:00
|
|
|
}
|
|
|
|
|
2016-05-25 16:07:04 +02:00
|
|
|
return lhs.cycle - rhs.cycle > WEIGHT_MAX;
|
2016-05-24 16:36:43 +02:00
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
namespace {
|
2016-05-25 16:07:04 +02:00
|
|
|
uint32_t next_cycle(const WeightedPri &pri) {
|
|
|
|
return pri.cycle + WEIGHT_MAX / std::min(WEIGHT_MAX, pri.weight);
|
|
|
|
}
|
2016-05-24 16:36:43 +02:00
|
|
|
} // namespace
|
|
|
|
|
2014-08-18 17:16:51 +02:00
|
|
|
std::unique_ptr<DownstreamConnection>
|
2015-07-09 19:52:11 +02:00
|
|
|
ClientHandler::get_downstream_connection(Downstream *downstream) {
|
2016-02-27 15:24:14 +01:00
|
|
|
size_t group_idx;
|
2016-06-03 12:13:02 +02:00
|
|
|
auto &downstreamconf = *worker_->get_downstream_config();
|
2016-06-11 11:21:37 +02:00
|
|
|
auto &routerconf = downstreamconf.router;
|
2016-06-03 12:13:02 +02:00
|
|
|
|
|
|
|
auto catch_all = downstreamconf.addr_group_catch_all;
|
2016-02-21 06:53:06 +01:00
|
|
|
auto &groups = worker_->get_downstream_addr_groups();
|
2015-07-09 19:52:11 +02:00
|
|
|
|
2016-01-13 14:45:52 +01:00
|
|
|
const auto &req = downstream->request();
|
|
|
|
|
2016-06-16 16:30:35 +02:00
|
|
|
switch (faddr_->alt_mode) {
|
|
|
|
case ALTMODE_API:
|
2016-06-02 16:47:41 +02:00
|
|
|
return make_unique<APIDownstreamConnection>(worker_);
|
2016-06-16 17:00:37 +02:00
|
|
|
case ALTMODE_HEALTHMON:
|
|
|
|
return make_unique<HealthMonitorDownstreamConnection>();
|
2016-06-02 16:47:41 +02:00
|
|
|
}
|
|
|
|
|
2015-07-09 19:52:11 +02:00
|
|
|
// Fast path. If we have one group, it must be catch-all group.
|
2016-03-12 16:59:25 +01:00
|
|
|
// proxy mode falls in this case.
|
2015-07-12 15:16:20 +02:00
|
|
|
if (groups.size() == 1) {
|
2016-02-27 15:24:14 +01:00
|
|
|
group_idx = 0;
|
2016-01-13 14:45:52 +01:00
|
|
|
} else if (req.method == HTTP_CONNECT) {
|
2015-07-09 19:52:11 +02:00
|
|
|
// We don't know how to treat CONNECT request in host-path
|
|
|
|
// mapping. It most likely appears in proxy scenario. Since we
|
|
|
|
// have dealt with proxy case already, just use catch-all group.
|
2016-02-27 15:24:14 +01:00
|
|
|
group_idx = catch_all;
|
2015-07-09 19:52:11 +02:00
|
|
|
} else {
|
2016-06-11 11:41:43 +02:00
|
|
|
auto &balloc = downstream->get_block_allocator();
|
|
|
|
|
2016-01-13 14:45:52 +01:00
|
|
|
if (!req.authority.empty()) {
|
2016-06-11 11:41:43 +02:00
|
|
|
group_idx = match_downstream_addr_group(
|
|
|
|
routerconf, req.authority, req.path, groups, catch_all, balloc);
|
2015-07-09 19:52:11 +02:00
|
|
|
} else {
|
2016-01-13 14:45:52 +01:00
|
|
|
auto h = req.fs.header(http2::HD_HOST);
|
2015-07-09 19:52:11 +02:00
|
|
|
if (h) {
|
2016-06-11 11:21:37 +02:00
|
|
|
group_idx = match_downstream_addr_group(routerconf, h->value, req.path,
|
2016-06-11 11:41:43 +02:00
|
|
|
groups, catch_all, balloc);
|
2015-09-25 19:38:45 +02:00
|
|
|
} else {
|
2016-06-11 11:41:43 +02:00
|
|
|
group_idx = match_downstream_addr_group(
|
|
|
|
routerconf, StringRef{}, req.path, groups, catch_all, balloc);
|
2015-07-09 19:52:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (LOG_ENABLED(INFO)) {
|
2016-02-27 15:24:14 +01:00
|
|
|
CLOG(INFO, this) << "Downstream address group_idx: " << group_idx;
|
2015-07-09 19:52:11 +02:00
|
|
|
}
|
|
|
|
|
2016-06-03 12:13:02 +02:00
|
|
|
auto &group = groups[group_idx];
|
2016-06-02 18:20:49 +02:00
|
|
|
auto &shared_addr = group->shared_addr;
|
2016-03-22 15:51:00 +01:00
|
|
|
|
2016-06-09 15:35:59 +02:00
|
|
|
if (shared_addr->affinity == AFFINITY_IP) {
|
2016-07-06 15:31:28 +02:00
|
|
|
if (!affinity_hash_computed_) {
|
2016-09-30 16:09:02 +02:00
|
|
|
affinity_hash_ = compute_affinity_from_ip(ipaddr_);
|
2016-07-06 15:31:28 +02:00
|
|
|
affinity_hash_computed_ = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto &affinity_hash = shared_addr->affinity_hash;
|
|
|
|
|
|
|
|
auto it = std::lower_bound(
|
|
|
|
std::begin(affinity_hash), std::end(affinity_hash), affinity_hash_,
|
|
|
|
[](const AffinityHash &lhs, uint32_t rhs) { return lhs.hash < rhs; });
|
|
|
|
|
|
|
|
if (it == std::end(affinity_hash)) {
|
|
|
|
it = std::begin(affinity_hash);
|
2016-06-09 15:35:59 +02:00
|
|
|
}
|
|
|
|
|
2016-07-06 15:31:28 +02:00
|
|
|
auto idx = (*it).idx;
|
2016-06-09 15:35:59 +02:00
|
|
|
|
|
|
|
auto &addr = shared_addr->addrs[idx];
|
|
|
|
if (addr.proto == PROTO_HTTP2) {
|
|
|
|
auto http2session = select_http2_session_with_affinity(group, &addr);
|
|
|
|
|
|
|
|
auto dconn = make_unique<Http2DownstreamConnection>(http2session);
|
|
|
|
|
|
|
|
dconn->set_client_handler(this);
|
|
|
|
|
|
|
|
return std::move(dconn);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto &dconn_pool = addr.dconn_pool;
|
|
|
|
auto dconn = dconn_pool->pop_downstream_connection();
|
|
|
|
|
|
|
|
if (!dconn) {
|
|
|
|
dconn = make_unique<HttpDownstreamConnection>(group, idx, conn_.loop,
|
|
|
|
worker_);
|
|
|
|
}
|
|
|
|
|
|
|
|
dconn->set_client_handler(this);
|
|
|
|
|
|
|
|
return dconn;
|
|
|
|
}
|
2014-10-13 14:09:00 +02:00
|
|
|
|
2016-05-25 16:07:04 +02:00
|
|
|
auto http1_weight = shared_addr->http1_pri.weight;
|
|
|
|
auto http2_weight = shared_addr->http2_pri.weight;
|
|
|
|
|
2016-06-09 15:35:59 +02:00
|
|
|
auto proto = PROTO_NONE;
|
|
|
|
|
2016-05-25 16:07:04 +02:00
|
|
|
if (http1_weight > 0 && http2_weight > 0) {
|
|
|
|
// We only advance cycle if both weight has nonzero to keep its
|
|
|
|
// distance under WEIGHT_MAX.
|
|
|
|
if (pri_less(shared_addr->http1_pri, shared_addr->http2_pri)) {
|
2016-05-24 16:36:43 +02:00
|
|
|
proto = PROTO_HTTP1;
|
2016-05-25 16:07:04 +02:00
|
|
|
shared_addr->http1_pri.cycle = next_cycle(shared_addr->http1_pri);
|
2016-05-24 16:36:43 +02:00
|
|
|
} else {
|
|
|
|
proto = PROTO_HTTP2;
|
2016-05-25 16:07:04 +02:00
|
|
|
shared_addr->http2_pri.cycle = next_cycle(shared_addr->http2_pri);
|
2016-05-24 16:36:43 +02:00
|
|
|
}
|
2016-05-25 16:07:04 +02:00
|
|
|
} else if (http1_weight > 0) {
|
|
|
|
proto = PROTO_HTTP1;
|
2016-05-25 17:14:11 +02:00
|
|
|
} else if (http2_weight > 0) {
|
2016-05-25 16:07:04 +02:00
|
|
|
proto = PROTO_HTTP2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (proto == PROTO_NONE) {
|
|
|
|
if (LOG_ENABLED(INFO)) {
|
|
|
|
CLOG(INFO, this) << "No working downstream address found";
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
2016-05-24 16:36:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (proto == PROTO_HTTP2) {
|
2014-11-27 15:39:04 +01:00
|
|
|
if (LOG_ENABLED(INFO)) {
|
2012-12-09 11:15:14 +01:00
|
|
|
CLOG(INFO, this) << "Downstream connection pool is empty."
|
|
|
|
<< " Create new one";
|
2012-06-09 16:14:00 +02:00
|
|
|
}
|
2014-10-13 14:09:00 +02:00
|
|
|
|
2016-05-24 16:36:43 +02:00
|
|
|
auto http2session = select_http2_session(group);
|
2016-02-27 11:39:03 +01:00
|
|
|
|
2016-05-24 16:36:43 +02:00
|
|
|
if (http2session == nullptr) {
|
|
|
|
return nullptr;
|
2012-11-18 13:23:13 +01:00
|
|
|
}
|
2016-05-24 16:36:43 +02:00
|
|
|
|
|
|
|
auto dconn = make_unique<Http2DownstreamConnection>(http2session);
|
|
|
|
|
2014-10-13 14:09:00 +02:00
|
|
|
dconn->set_client_handler(this);
|
2016-05-24 16:36:43 +02:00
|
|
|
|
|
|
|
return std::move(dconn);
|
2012-06-09 16:14:00 +02:00
|
|
|
}
|
2014-08-18 17:16:51 +02:00
|
|
|
|
2016-05-24 16:36:43 +02:00
|
|
|
auto &dconn_pool = shared_addr->dconn_pool;
|
2014-10-13 14:09:00 +02:00
|
|
|
|
2016-05-24 16:36:43 +02:00
|
|
|
// pool connection must be HTTP/1.1 connection
|
|
|
|
auto dconn = dconn_pool.pop_downstream_connection();
|
|
|
|
|
|
|
|
if (dconn) {
|
|
|
|
if (LOG_ENABLED(INFO)) {
|
|
|
|
CLOG(INFO, this) << "Reuse downstream connection DCONN:" << dconn.get()
|
|
|
|
<< " from pool";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (LOG_ENABLED(INFO)) {
|
|
|
|
CLOG(INFO, this) << "Downstream connection pool is empty."
|
|
|
|
<< " Create new one";
|
|
|
|
}
|
|
|
|
|
2016-06-09 15:35:59 +02:00
|
|
|
dconn =
|
|
|
|
make_unique<HttpDownstreamConnection>(group, -1, conn_.loop, worker_);
|
2014-08-18 17:16:51 +02:00
|
|
|
}
|
|
|
|
|
2016-05-24 16:36:43 +02:00
|
|
|
dconn->set_client_handler(this);
|
|
|
|
|
2014-08-18 17:16:51 +02:00
|
|
|
return dconn;
|
2012-06-09 16:14:00 +02:00
|
|
|
}
|
|
|
|
|
2015-04-07 15:13:01 +02:00
|
|
|
MemchunkPool *ClientHandler::get_mcpool() { return worker_->get_mcpool(); }
|
|
|
|
|
2015-02-04 13:15:58 +01:00
|
|
|
SSL *ClientHandler::get_ssl() const { return conn_.tls.ssl; }
|
2012-07-14 16:24:03 +02:00
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
void ClientHandler::direct_http2_upgrade() {
|
2015-02-05 15:21:53 +01:00
|
|
|
upstream_ = make_unique<Http2Upstream>(this);
|
2016-09-30 16:09:02 +02:00
|
|
|
alpn_ = StringRef::from_lit(NGHTTP2_CLEARTEXT_PROTO_VERSION_ID);
|
2014-12-27 18:59:06 +01:00
|
|
|
on_read_ = &ClientHandler::upstream_read;
|
2015-10-01 16:10:53 +02:00
|
|
|
write_ = &ClientHandler::write_clear;
|
2013-08-03 11:51:01 +02:00
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
int ClientHandler::perform_http2_upgrade(HttpsUpstream *http) {
|
2015-02-05 15:21:53 +01:00
|
|
|
auto upstream = make_unique<Http2Upstream>(this);
|
2015-12-15 16:38:30 +01:00
|
|
|
|
|
|
|
auto output = upstream->get_response_buf();
|
|
|
|
|
|
|
|
// We might have written non-final header in response_buf, in this
|
|
|
|
// case, response_state is still INITIAL. If this non-final header
|
|
|
|
// and upgrade header fit in output buffer, do upgrade. Otherwise,
|
|
|
|
// to avoid to send this non-final header as response body in HTTP/2
|
|
|
|
// upstream, fail upgrade.
|
|
|
|
auto downstream = http->get_downstream();
|
|
|
|
auto input = downstream->get_response_buf();
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (upstream->upgrade_upstream(http) != 0) {
|
2013-08-03 11:51:01 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2013-09-26 14:39:19 +02:00
|
|
|
// http pointer is now owned by upstream.
|
|
|
|
upstream_.release();
|
2014-11-24 07:22:10 +01:00
|
|
|
// TODO We might get other version id in HTTP2-settings, if we
|
|
|
|
// support aliasing for h2, but we just use library default for now.
|
2016-09-30 16:09:02 +02:00
|
|
|
alpn_ = StringRef::from_lit(NGHTTP2_CLEARTEXT_PROTO_VERSION_ID);
|
2014-12-27 18:59:06 +01:00
|
|
|
on_read_ = &ClientHandler::upstream_http2_connhd_read;
|
2015-10-01 16:10:53 +02:00
|
|
|
write_ = &ClientHandler::write_clear;
|
2014-12-27 18:59:06 +01:00
|
|
|
|
2016-01-26 15:04:53 +01:00
|
|
|
input->remove(*output, input->rleft());
|
2016-03-24 17:10:58 +01:00
|
|
|
|
|
|
|
constexpr auto res =
|
|
|
|
StringRef::from_lit("HTTP/1.1 101 Switching Protocols\r\n"
|
|
|
|
"Connection: Upgrade\r\n"
|
|
|
|
"Upgrade: " NGHTTP2_CLEARTEXT_PROTO_VERSION_ID "\r\n"
|
|
|
|
"\r\n");
|
|
|
|
|
|
|
|
output->append(res);
|
2015-10-02 15:42:46 +02:00
|
|
|
upstream_ = std::move(upstream);
|
|
|
|
|
2015-03-01 02:11:45 +01:00
|
|
|
signal_write();
|
2013-08-03 11:51:01 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-02-04 13:15:58 +01:00
|
|
|
bool ClientHandler::get_http2_upgrade_allowed() const { return !conn_.tls.ssl; }
|
2013-08-03 11:51:01 +02:00
|
|
|
|
2016-03-10 14:42:07 +01:00
|
|
|
StringRef ClientHandler::get_upstream_scheme() const {
|
2015-02-04 13:15:58 +01:00
|
|
|
if (conn_.tls.ssl) {
|
2016-03-10 14:42:07 +01:00
|
|
|
return StringRef::from_lit("https");
|
2013-12-21 09:49:31 +01:00
|
|
|
} else {
|
2016-03-10 14:42:07 +01:00
|
|
|
return StringRef::from_lit("http");
|
2013-12-21 09:49:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-04 13:15:58 +01:00
|
|
|
void ClientHandler::start_immediate_shutdown() {
|
|
|
|
ev_timer_start(conn_.loop, &reneg_shutdown_timer_);
|
2014-11-05 16:56:07 +01:00
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
void ClientHandler::write_accesslog(Downstream *downstream) {
|
2015-06-28 09:37:17 +02:00
|
|
|
nghttp2::ssl::TLSSessionInfo tls_info;
|
2017-01-11 12:22:55 +01:00
|
|
|
auto &req = downstream->request();
|
2015-06-28 09:37:17 +02:00
|
|
|
|
2016-10-08 04:34:23 +02:00
|
|
|
auto config = get_config();
|
2016-03-10 14:42:07 +01:00
|
|
|
|
2017-01-11 12:22:55 +01:00
|
|
|
if (!req.tstamp) {
|
|
|
|
auto lgconf = log_config();
|
|
|
|
lgconf->update_tstamp(std::chrono::system_clock::now());
|
|
|
|
req.tstamp = lgconf->tstamp;
|
|
|
|
}
|
|
|
|
|
2015-05-04 15:45:34 +02:00
|
|
|
upstream_accesslog(
|
2016-10-08 04:34:23 +02:00
|
|
|
config->logging.access.format,
|
2015-05-04 15:45:34 +02:00
|
|
|
LogSpec{
|
2017-01-11 14:30:12 +01:00
|
|
|
downstream, ipaddr_, alpn_,
|
|
|
|
nghttp2::ssl::get_tls_session_info(&tls_info, conn_.tls.ssl),
|
2015-05-04 15:45:34 +02:00
|
|
|
std::chrono::high_resolution_clock::now(), // request_end_time
|
2017-01-11 14:30:12 +01:00
|
|
|
port_, faddr_->port, config->pid,
|
2015-05-04 15:45:34 +02:00
|
|
|
});
|
2014-11-18 16:56:44 +01:00
|
|
|
}
|
|
|
|
|
2015-01-08 13:28:52 +01:00
|
|
|
ClientHandler::ReadBuf *ClientHandler::get_rb() { return &rb_; }
|
2014-12-27 18:59:06 +01:00
|
|
|
|
2015-02-04 13:15:58 +01:00
|
|
|
void ClientHandler::signal_write() { conn_.wlimit.startw(); }
|
2014-12-27 18:59:06 +01:00
|
|
|
|
2016-11-29 12:42:27 +01:00
|
|
|
void ClientHandler::signal_write_no_wait() {
|
2016-12-21 15:05:29 +01:00
|
|
|
// ev_feed_event works without starting watcher. But rate limiter
|
|
|
|
// requires active watcher. Without that, we might not send pending
|
|
|
|
// data. Also ClientHandler::write_tls requires it.
|
|
|
|
conn_.wlimit.startw();
|
2016-11-29 12:42:27 +01:00
|
|
|
ev_feed_event(conn_.loop, &conn_.wev, EV_WRITE);
|
|
|
|
}
|
|
|
|
|
2015-02-04 13:15:58 +01:00
|
|
|
RateLimit *ClientHandler::get_rlimit() { return &conn_.rlimit; }
|
|
|
|
RateLimit *ClientHandler::get_wlimit() { return &conn_.wlimit; }
|
2014-12-27 18:59:06 +01:00
|
|
|
|
2015-02-10 16:44:30 +01:00
|
|
|
ev_io *ClientHandler::get_wev() { return &conn_.wev; }
|
|
|
|
|
2015-02-11 11:18:41 +01:00
|
|
|
Worker *ClientHandler::get_worker() const { return worker_; }
|
|
|
|
|
2015-09-06 11:39:32 +02:00
|
|
|
namespace {
|
|
|
|
ssize_t parse_proxy_line_port(const uint8_t *first, const uint8_t *last) {
|
|
|
|
auto p = first;
|
|
|
|
int32_t port = 0;
|
|
|
|
|
2015-09-07 15:35:02 +02:00
|
|
|
if (p == last) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*p == '0') {
|
2015-11-27 16:41:39 +01:00
|
|
|
if (p + 1 != last && util::is_digit(*(p + 1))) {
|
2015-09-07 15:35:02 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-11-27 16:41:39 +01:00
|
|
|
for (; p != last && util::is_digit(*p); ++p) {
|
2015-09-06 11:39:32 +02:00
|
|
|
port *= 10;
|
|
|
|
port += *p - '0';
|
|
|
|
|
|
|
|
if (port > 65535) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return p - first;
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2015-09-06 16:11:07 +02:00
|
|
|
int ClientHandler::on_proxy_protocol_finish() {
|
2015-09-17 15:26:49 +02:00
|
|
|
if (conn_.tls.ssl) {
|
2017-01-08 08:41:02 +01:00
|
|
|
conn_.tls.rbuf.append(rb_.pos(), rb_.rleft());
|
2015-09-17 15:26:49 +02:00
|
|
|
rb_.reset();
|
|
|
|
}
|
|
|
|
|
2015-09-06 16:11:07 +02:00
|
|
|
setup_upstream_io_callback();
|
|
|
|
|
|
|
|
// Run on_read to process data left in buffer since they are not
|
|
|
|
// notified further
|
|
|
|
if (on_read() != 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-09-07 15:35:02 +02:00
|
|
|
// http://www.haproxy.org/download/1.5/doc/proxy-protocol.txt
|
2015-09-06 11:39:32 +02:00
|
|
|
int ClientHandler::proxy_protocol_read() {
|
|
|
|
if (LOG_ENABLED(INFO)) {
|
|
|
|
CLOG(INFO, this) << "PROXY-protocol: Started";
|
|
|
|
}
|
|
|
|
|
2017-01-08 08:41:02 +01:00
|
|
|
auto first = rb_.pos();
|
2015-09-06 11:39:32 +02:00
|
|
|
|
2015-09-07 15:35:02 +02:00
|
|
|
// NULL character really destroys functions which expects NULL
|
|
|
|
// terminated string. We won't expect it in PROXY protocol line, so
|
|
|
|
// find it here.
|
|
|
|
auto chrs = std::array<char, 2>{{'\n', '\0'}};
|
|
|
|
|
|
|
|
constexpr size_t MAX_PROXY_LINELEN = 107;
|
|
|
|
|
2017-01-08 08:41:02 +01:00
|
|
|
auto bufend = rb_.pos() + std::min(MAX_PROXY_LINELEN, rb_.rleft());
|
2015-09-07 15:35:02 +02:00
|
|
|
|
|
|
|
auto end =
|
2017-01-08 08:41:02 +01:00
|
|
|
std::find_first_of(rb_.pos(), bufend, std::begin(chrs), std::end(chrs));
|
2015-09-07 15:35:02 +02:00
|
|
|
|
2017-01-08 08:41:02 +01:00
|
|
|
if (end == bufend || *end == '\0' || end == rb_.pos() || *(end - 1) != '\r') {
|
2015-09-06 14:44:45 +02:00
|
|
|
if (LOG_ENABLED(INFO)) {
|
|
|
|
CLOG(INFO, this) << "PROXY-protocol-v1: No ending CR LF sequence found";
|
|
|
|
}
|
2015-09-06 11:39:32 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-09-07 15:35:02 +02:00
|
|
|
--end;
|
|
|
|
|
2016-03-24 17:10:58 +01:00
|
|
|
constexpr auto HEADER = StringRef::from_lit("PROXY ");
|
2015-09-06 11:39:32 +02:00
|
|
|
|
2017-01-08 08:41:02 +01:00
|
|
|
if (static_cast<size_t>(end - rb_.pos()) < HEADER.size()) {
|
2015-09-06 11:39:32 +02:00
|
|
|
if (LOG_ENABLED(INFO)) {
|
|
|
|
CLOG(INFO, this) << "PROXY-protocol-v1: PROXY version 1 ID not found";
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-01-08 08:41:02 +01:00
|
|
|
if (!util::streq(HEADER, StringRef{rb_.pos(), HEADER.size()})) {
|
2015-09-06 11:39:32 +02:00
|
|
|
if (LOG_ENABLED(INFO)) {
|
|
|
|
CLOG(INFO, this) << "PROXY-protocol-v1: Bad PROXY protocol version 1 ID";
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-03-24 17:10:58 +01:00
|
|
|
rb_.drain(HEADER.size());
|
2015-09-06 11:39:32 +02:00
|
|
|
|
|
|
|
int family;
|
|
|
|
|
2017-01-08 08:41:02 +01:00
|
|
|
if (rb_.pos()[0] == 'T') {
|
|
|
|
if (end - rb_.pos() < 5) {
|
2015-09-06 11:39:32 +02:00
|
|
|
if (LOG_ENABLED(INFO)) {
|
|
|
|
CLOG(INFO, this) << "PROXY-protocol-v1: INET protocol family not found";
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-01-08 08:41:02 +01:00
|
|
|
if (rb_.pos()[1] != 'C' || rb_.pos()[2] != 'P') {
|
2015-09-07 15:35:02 +02:00
|
|
|
if (LOG_ENABLED(INFO)) {
|
|
|
|
CLOG(INFO, this) << "PROXY-protocol-v1: Unknown INET protocol family";
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-01-08 08:41:02 +01:00
|
|
|
switch (rb_.pos()[3]) {
|
2015-09-07 15:35:02 +02:00
|
|
|
case '4':
|
2015-09-06 11:39:32 +02:00
|
|
|
family = AF_INET;
|
2015-09-07 15:35:02 +02:00
|
|
|
break;
|
|
|
|
case '6':
|
2015-09-06 11:39:32 +02:00
|
|
|
family = AF_INET6;
|
2015-09-07 15:35:02 +02:00
|
|
|
break;
|
|
|
|
default:
|
2015-09-06 11:39:32 +02:00
|
|
|
if (LOG_ENABLED(INFO)) {
|
|
|
|
CLOG(INFO, this) << "PROXY-protocol-v1: Unknown INET protocol family";
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
rb_.drain(5);
|
|
|
|
} else {
|
2017-01-08 08:41:02 +01:00
|
|
|
if (end - rb_.pos() < 7) {
|
2015-09-06 11:39:32 +02:00
|
|
|
if (LOG_ENABLED(INFO)) {
|
|
|
|
CLOG(INFO, this) << "PROXY-protocol-v1: INET protocol family not found";
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
2017-01-08 08:41:02 +01:00
|
|
|
if (!util::streq_l("UNKNOWN", rb_.pos(), 7)) {
|
2015-09-06 11:39:32 +02:00
|
|
|
if (LOG_ENABLED(INFO)) {
|
|
|
|
CLOG(INFO, this) << "PROXY-protocol-v1: Unknown INET protocol family";
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-01-08 08:41:02 +01:00
|
|
|
rb_.drain(end + 2 - rb_.pos());
|
2015-09-06 16:11:07 +02:00
|
|
|
|
|
|
|
return on_proxy_protocol_finish();
|
2015-09-06 11:39:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// source address
|
2017-01-08 08:41:02 +01:00
|
|
|
auto token_end = std::find(rb_.pos(), end, ' ');
|
2015-09-06 11:39:32 +02:00
|
|
|
if (token_end == end) {
|
|
|
|
if (LOG_ENABLED(INFO)) {
|
|
|
|
CLOG(INFO, this) << "PROXY-protocol-v1: Source address not found";
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
*token_end = '\0';
|
2017-01-08 08:41:02 +01:00
|
|
|
if (!util::numeric_host(reinterpret_cast<const char *>(rb_.pos()), family)) {
|
2015-09-06 11:39:32 +02:00
|
|
|
if (LOG_ENABLED(INFO)) {
|
|
|
|
CLOG(INFO, this) << "PROXY-protocol-v1: Invalid source address";
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-01-08 08:41:02 +01:00
|
|
|
auto src_addr = rb_.pos();
|
|
|
|
auto src_addrlen = token_end - rb_.pos();
|
2015-09-06 11:39:32 +02:00
|
|
|
|
2017-01-08 08:41:02 +01:00
|
|
|
rb_.drain(token_end - rb_.pos() + 1);
|
2015-09-06 11:39:32 +02:00
|
|
|
|
|
|
|
// destination address
|
2017-01-08 08:41:02 +01:00
|
|
|
token_end = std::find(rb_.pos(), end, ' ');
|
2015-09-06 11:39:32 +02:00
|
|
|
if (token_end == end) {
|
|
|
|
if (LOG_ENABLED(INFO)) {
|
|
|
|
CLOG(INFO, this) << "PROXY-protocol-v1: Destination address not found";
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
*token_end = '\0';
|
2017-01-08 08:41:02 +01:00
|
|
|
if (!util::numeric_host(reinterpret_cast<const char *>(rb_.pos()), family)) {
|
2015-09-06 11:39:32 +02:00
|
|
|
if (LOG_ENABLED(INFO)) {
|
|
|
|
CLOG(INFO, this) << "PROXY-protocol-v1: Invalid destination address";
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Currently we don't use destination address
|
|
|
|
|
2017-01-08 08:41:02 +01:00
|
|
|
rb_.drain(token_end - rb_.pos() + 1);
|
2015-09-06 11:39:32 +02:00
|
|
|
|
|
|
|
// source port
|
2017-01-08 08:41:02 +01:00
|
|
|
auto n = parse_proxy_line_port(rb_.pos(), end);
|
|
|
|
if (n <= 0 || *(rb_.pos() + n) != ' ') {
|
2015-09-06 11:39:32 +02:00
|
|
|
if (LOG_ENABLED(INFO)) {
|
|
|
|
CLOG(INFO, this) << "PROXY-protocol-v1: Invalid source port";
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-01-08 08:41:02 +01:00
|
|
|
rb_.pos()[n] = '\0';
|
|
|
|
auto src_port = rb_.pos();
|
2015-09-06 11:39:32 +02:00
|
|
|
auto src_portlen = n;
|
|
|
|
|
|
|
|
rb_.drain(n + 1);
|
|
|
|
|
|
|
|
// destination port
|
2017-01-08 08:41:02 +01:00
|
|
|
n = parse_proxy_line_port(rb_.pos(), end);
|
|
|
|
if (n <= 0 || rb_.pos() + n != end) {
|
2015-09-06 11:39:32 +02:00
|
|
|
if (LOG_ENABLED(INFO)) {
|
|
|
|
CLOG(INFO, this) << "PROXY-protocol-v1: Invalid destination port";
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Currently we don't use destination port
|
|
|
|
|
2017-01-08 08:41:02 +01:00
|
|
|
rb_.drain(end + 2 - rb_.pos());
|
2015-09-06 11:39:32 +02:00
|
|
|
|
2016-09-30 16:09:02 +02:00
|
|
|
ipaddr_ =
|
|
|
|
make_string_ref(balloc_, StringRef{src_addr, src_addr + src_addrlen});
|
|
|
|
port_ = make_string_ref(balloc_, StringRef{src_port, src_port + src_portlen});
|
2015-09-06 11:39:32 +02:00
|
|
|
|
|
|
|
if (LOG_ENABLED(INFO)) {
|
2017-01-08 08:41:02 +01:00
|
|
|
CLOG(INFO, this) << "PROXY-protocol-v1: Finished, " << (rb_.pos() - first)
|
2015-09-06 11:39:32 +02:00
|
|
|
<< " bytes read";
|
|
|
|
}
|
|
|
|
|
2015-09-06 16:11:07 +02:00
|
|
|
return on_proxy_protocol_finish();
|
2015-09-06 11:39:32 +02:00
|
|
|
}
|
|
|
|
|
2016-02-28 15:54:02 +01:00
|
|
|
StringRef ClientHandler::get_forwarded_by() const {
|
2016-01-18 09:00:20 +01:00
|
|
|
auto &fwdconf = get_config()->http.forwarded;
|
|
|
|
|
|
|
|
if (fwdconf.by_node_type == FORWARDED_NODE_OBFUSCATED) {
|
2016-10-02 14:22:02 +02:00
|
|
|
return fwdconf.by_obfuscated;
|
2016-01-15 15:04:58 +01:00
|
|
|
}
|
|
|
|
|
2016-10-02 14:22:02 +02:00
|
|
|
return faddr_->hostport;
|
2016-01-15 15:04:58 +01:00
|
|
|
}
|
|
|
|
|
2016-09-30 16:09:02 +02:00
|
|
|
StringRef ClientHandler::get_forwarded_for() const { return forwarded_for_; }
|
2016-01-15 15:04:58 +01:00
|
|
|
|
2016-04-27 17:19:30 +02:00
|
|
|
const UpstreamAddr *ClientHandler::get_upstream_addr() const { return faddr_; }
|
|
|
|
|
2016-09-08 15:49:36 +02:00
|
|
|
Connection *ClientHandler::get_connection() { return &conn_; };
|
|
|
|
|
2016-09-30 16:09:02 +02:00
|
|
|
void ClientHandler::set_tls_sni(const StringRef &sni) {
|
|
|
|
sni_ = make_string_ref(balloc_, sni);
|
|
|
|
}
|
2016-09-10 15:02:46 +02:00
|
|
|
|
2016-09-30 16:09:02 +02:00
|
|
|
StringRef ClientHandler::get_tls_sni() const { return sni_; }
|
2016-09-10 15:02:46 +02:00
|
|
|
|
2016-10-01 17:19:50 +02:00
|
|
|
BlockAllocator &ClientHandler::get_block_allocator() { return balloc_; }
|
|
|
|
|
2012-06-04 16:48:31 +02:00
|
|
|
} // namespace shrpx
|