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_config.h"
|
|
|
|
|
2015-05-13 15:30:35 +02:00
|
|
|
#ifdef HAVE_PWD_H
|
2012-08-01 17:06:41 +02:00
|
|
|
#include <pwd.h>
|
2015-05-13 15:30:35 +02:00
|
|
|
#endif // HAVE_PWD_H
|
|
|
|
#ifdef HAVE_NETDB_H
|
2012-08-01 17:06:41 +02:00
|
|
|
#include <netdb.h>
|
2015-05-13 15:30:35 +02:00
|
|
|
#endif // HAVE_NETDB_H
|
|
|
|
#ifdef HAVE_SYSLOG_H
|
2012-08-01 18:20:18 +02:00
|
|
|
#include <syslog.h>
|
2015-05-13 15:30:35 +02:00
|
|
|
#endif // HAVE_SYSLOG_H
|
2012-12-03 07:33:04 +01:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
2015-05-13 15:30:35 +02:00
|
|
|
#ifdef HAVE_FCNTL_H
|
2015-01-06 16:25:10 +01:00
|
|
|
#include <fcntl.h>
|
2015-05-13 15:30:35 +02:00
|
|
|
#endif // HAVE_FCNTL_H
|
|
|
|
#ifdef HAVE_UNISTD_H
|
2012-12-03 07:33:04 +01:00
|
|
|
#include <unistd.h>
|
2015-05-13 15:30:35 +02:00
|
|
|
#endif // HAVE_UNISTD_H
|
2012-08-01 17:06:41 +02:00
|
|
|
|
|
|
|
#include <cstring>
|
|
|
|
#include <cerrno>
|
|
|
|
#include <limits>
|
|
|
|
#include <fstream>
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
#include <nghttp2/nghttp2.h>
|
2013-02-22 13:54:07 +01:00
|
|
|
|
2013-08-27 19:47:22 +02:00
|
|
|
#include "http-parser/http_parser.h"
|
|
|
|
|
2012-08-01 17:26:24 +02:00
|
|
|
#include "shrpx_log.h"
|
2013-02-06 15:27:05 +01:00
|
|
|
#include "shrpx_ssl.h"
|
2013-02-09 08:42:01 +01:00
|
|
|
#include "shrpx_http.h"
|
2012-08-01 17:06:41 +02:00
|
|
|
#include "util.h"
|
2015-07-09 19:52:11 +02:00
|
|
|
#include "base64.h"
|
2012-08-01 17:06:41 +02:00
|
|
|
|
2012-06-04 16:48:31 +02:00
|
|
|
namespace shrpx {
|
|
|
|
|
|
|
|
namespace {
|
2016-07-31 12:01:29 +02:00
|
|
|
std::unique_ptr<Config> config;
|
2012-06-04 16:48:31 +02:00
|
|
|
} // namespace
|
|
|
|
|
2016-03-24 17:10:25 +01:00
|
|
|
constexpr auto SHRPX_UNIX_PATH_PREFIX = StringRef::from_lit("unix:");
|
2016-03-24 17:00:04 +01:00
|
|
|
|
2016-07-31 12:01:29 +02:00
|
|
|
const Config *get_config() { return config.get(); }
|
2012-06-04 16:48:31 +02:00
|
|
|
|
2016-07-31 12:01:29 +02:00
|
|
|
Config *mod_config() { return config.get(); }
|
2012-06-04 16:48:31 +02:00
|
|
|
|
2016-07-31 12:01:29 +02:00
|
|
|
std::unique_ptr<Config> replace_config(std::unique_ptr<Config> another) {
|
|
|
|
config.swap(another);
|
|
|
|
return another;
|
2016-07-31 08:57:41 +02:00
|
|
|
}
|
|
|
|
|
2016-07-31 12:01:29 +02:00
|
|
|
void create_config() { config = make_unique<Config>(); }
|
2012-06-04 16:48:31 +02:00
|
|
|
|
2016-07-31 12:01:29 +02:00
|
|
|
Config::~Config() {
|
|
|
|
auto &upstreamconf = http2.upstream;
|
2016-07-31 08:57:41 +02:00
|
|
|
|
|
|
|
nghttp2_option_del(upstreamconf.option);
|
|
|
|
nghttp2_option_del(upstreamconf.alt_mode_option);
|
|
|
|
nghttp2_session_callbacks_del(upstreamconf.callbacks);
|
|
|
|
|
2016-07-31 12:01:29 +02:00
|
|
|
auto &downstreamconf = http2.downstream;
|
2016-07-31 08:57:41 +02:00
|
|
|
|
|
|
|
nghttp2_option_del(downstreamconf.option);
|
|
|
|
nghttp2_session_callbacks_del(downstreamconf.callbacks);
|
|
|
|
|
2016-07-31 12:01:29 +02:00
|
|
|
auto &dumpconf = http2.upstream.debug.dump;
|
2016-07-31 08:57:41 +02:00
|
|
|
|
|
|
|
if (dumpconf.request_header) {
|
|
|
|
fclose(dumpconf.request_header);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dumpconf.response_header) {
|
|
|
|
fclose(dumpconf.response_header);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-07 16:01:09 +01:00
|
|
|
TicketKeys::~TicketKeys() {
|
|
|
|
/* Erase keys from memory */
|
|
|
|
for (auto &key : keys) {
|
|
|
|
memset(&key, 0, sizeof(key));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-01 17:06:41 +02:00
|
|
|
namespace {
|
|
|
|
int split_host_port(char *host, size_t hostlen, uint16_t *port_ptr,
|
2016-03-24 13:05:02 +01:00
|
|
|
const StringRef &hostport, const StringRef &opt) {
|
2012-08-01 17:06:41 +02:00
|
|
|
// host and port in |hostport| is separated by single ','.
|
2016-03-23 16:35:13 +01:00
|
|
|
auto sep = std::find(std::begin(hostport), std::end(hostport), ',');
|
|
|
|
if (sep == std::end(hostport)) {
|
|
|
|
LOG(ERROR) << opt << ": Invalid host, port: " << hostport;
|
2012-08-01 17:06:41 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2016-03-23 16:35:13 +01:00
|
|
|
size_t len = sep - std::begin(hostport);
|
2014-11-27 15:39:04 +01:00
|
|
|
if (hostlen < len + 1) {
|
2016-03-23 16:35:13 +01:00
|
|
|
LOG(ERROR) << opt << ": Hostname too long: " << hostport;
|
2012-08-01 17:06:41 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2016-03-23 16:35:13 +01:00
|
|
|
std::copy(std::begin(hostport), sep, host);
|
2012-08-01 17:06:41 +02:00
|
|
|
host[len] = '\0';
|
|
|
|
|
2016-03-23 16:35:13 +01:00
|
|
|
auto portstr = StringRef{sep + 1, std::end(hostport)};
|
|
|
|
auto d = util::parse_uint(portstr);
|
2015-07-09 19:52:11 +02:00
|
|
|
if (1 <= d && d <= std::numeric_limits<uint16_t>::max()) {
|
2012-08-01 17:06:41 +02:00
|
|
|
*port_ptr = d;
|
|
|
|
return 0;
|
|
|
|
}
|
2016-03-23 16:35:13 +01:00
|
|
|
|
|
|
|
LOG(ERROR) << opt << ": Port is invalid: " << portstr;
|
|
|
|
return -1;
|
2012-08-01 17:06:41 +02:00
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2012-12-07 15:14:20 +01:00
|
|
|
namespace {
|
2016-03-24 13:05:02 +01:00
|
|
|
bool is_secure(const StringRef &filename) {
|
2012-12-03 07:33:04 +01:00
|
|
|
struct stat buf;
|
2016-03-24 13:05:02 +01:00
|
|
|
int rv = stat(filename.c_str(), &buf);
|
2012-12-03 07:33:04 +01:00
|
|
|
if (rv == 0) {
|
2014-11-27 15:39:04 +01:00
|
|
|
if ((buf.st_mode & S_IRWXU) && !(buf.st_mode & S_IRWXG) &&
|
2012-12-03 07:33:04 +01:00
|
|
|
!(buf.st_mode & S_IRWXO)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2012-12-07 15:14:20 +01:00
|
|
|
} // namespace
|
2012-12-03 07:33:04 +01:00
|
|
|
|
2015-01-07 17:26:30 +01:00
|
|
|
std::unique_ptr<TicketKeys>
|
2015-07-17 18:49:20 +02:00
|
|
|
read_tls_ticket_key_file(const std::vector<std::string> &files,
|
|
|
|
const EVP_CIPHER *cipher, const EVP_MD *hmac) {
|
2015-02-05 15:21:53 +01:00
|
|
|
auto ticket_keys = make_unique<TicketKeys>();
|
2015-01-07 17:26:30 +01:00
|
|
|
auto &keys = ticket_keys->keys;
|
|
|
|
keys.resize(files.size());
|
2015-07-17 18:49:20 +02:00
|
|
|
auto enc_keylen = EVP_CIPHER_key_length(cipher);
|
|
|
|
auto hmac_keylen = EVP_MD_size(hmac);
|
|
|
|
if (cipher == EVP_aes_128_cbc()) {
|
|
|
|
// backward compatibility, as a legacy of using same file format
|
|
|
|
// with nginx and apache.
|
|
|
|
hmac_keylen = 16;
|
|
|
|
}
|
2015-07-26 19:12:07 +02:00
|
|
|
auto expectedlen = keys[0].data.name.size() + enc_keylen + hmac_keylen;
|
2015-07-17 18:49:20 +02:00
|
|
|
char buf[256];
|
|
|
|
assert(sizeof(buf) >= expectedlen);
|
|
|
|
|
2015-01-07 17:26:30 +01:00
|
|
|
size_t i = 0;
|
|
|
|
for (auto &file : files) {
|
2015-07-17 18:49:20 +02:00
|
|
|
struct stat fst {};
|
|
|
|
|
|
|
|
if (stat(file.c_str(), &fst) == -1) {
|
|
|
|
auto error = errno;
|
|
|
|
LOG(ERROR) << "tls-ticket-key-file: could not stat file " << file
|
|
|
|
<< ", errno=" << error;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-07-19 13:50:14 +02:00
|
|
|
if (static_cast<size_t>(fst.st_size) != expectedlen) {
|
2015-07-17 18:49:20 +02:00
|
|
|
LOG(ERROR) << "tls-ticket-key-file: the expected file size is "
|
|
|
|
<< expectedlen << ", the actual file size is " << fst.st_size;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-01-07 17:26:30 +01:00
|
|
|
std::ifstream f(file.c_str());
|
|
|
|
if (!f) {
|
|
|
|
LOG(ERROR) << "tls-ticket-key-file: could not open file " << file;
|
|
|
|
return nullptr;
|
|
|
|
}
|
2015-07-17 18:49:20 +02:00
|
|
|
|
|
|
|
f.read(buf, expectedlen);
|
2015-07-19 13:50:14 +02:00
|
|
|
if (static_cast<size_t>(f.gcount()) != expectedlen) {
|
2015-07-17 18:49:20 +02:00
|
|
|
LOG(ERROR) << "tls-ticket-key-file: want to read " << expectedlen
|
|
|
|
<< " bytes but only read " << f.gcount() << " bytes from "
|
|
|
|
<< file;
|
2015-01-07 17:26:30 +01:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto &key = keys[i++];
|
2015-07-17 18:49:20 +02:00
|
|
|
key.cipher = cipher;
|
|
|
|
key.hmac = hmac;
|
|
|
|
key.hmac_keylen = hmac_keylen;
|
|
|
|
|
|
|
|
if (LOG_ENABLED(INFO)) {
|
|
|
|
LOG(INFO) << "enc_keylen=" << enc_keylen
|
|
|
|
<< ", hmac_keylen=" << key.hmac_keylen;
|
|
|
|
}
|
|
|
|
|
2015-01-07 17:26:30 +01:00
|
|
|
auto p = buf;
|
2015-07-26 19:12:07 +02:00
|
|
|
std::copy_n(p, key.data.name.size(), std::begin(key.data.name));
|
|
|
|
p += key.data.name.size();
|
|
|
|
std::copy_n(p, enc_keylen, std::begin(key.data.enc_key));
|
2015-07-17 18:49:20 +02:00
|
|
|
p += enc_keylen;
|
2015-07-26 19:12:07 +02:00
|
|
|
std::copy_n(p, hmac_keylen, std::begin(key.data.hmac_key));
|
2015-01-07 17:26:30 +01:00
|
|
|
|
|
|
|
if (LOG_ENABLED(INFO)) {
|
2015-07-17 18:49:20 +02:00
|
|
|
LOG(INFO) << "session ticket key: " << util::format_hex(key.data.name);
|
2015-01-07 17:26:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return ticket_keys;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
FILE *open_file_for_write(const char *filename) {
|
2015-01-22 15:20:16 +01:00
|
|
|
#if defined O_CLOEXEC
|
2015-01-06 16:25:10 +01:00
|
|
|
auto fd = open(filename, O_WRONLY | O_CLOEXEC | O_CREAT | O_TRUNC,
|
|
|
|
S_IRUSR | S_IWUSR);
|
2015-01-22 15:20:16 +01:00
|
|
|
#else
|
|
|
|
auto fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
|
|
|
|
|
|
|
|
// We get race condition if execve is called at the same time.
|
|
|
|
if (fd != -1) {
|
2015-03-02 21:14:09 +01:00
|
|
|
util::make_socket_closeonexec(fd);
|
2015-01-22 15:20:16 +01:00
|
|
|
}
|
|
|
|
#endif
|
2015-01-06 16:25:10 +01:00
|
|
|
if (fd == -1) {
|
|
|
|
LOG(ERROR) << "Failed to open " << filename
|
|
|
|
<< " for writing. Cause: " << strerror(errno);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
auto f = fdopen(fd, "wb");
|
2014-11-27 15:39:04 +01:00
|
|
|
if (f == nullptr) {
|
|
|
|
LOG(ERROR) << "Failed to open " << filename
|
|
|
|
<< " for writing. Cause: " << strerror(errno);
|
2014-08-19 17:17:50 +02:00
|
|
|
return nullptr;
|
2013-11-17 15:52:19 +01:00
|
|
|
}
|
2014-08-12 15:22:02 +02:00
|
|
|
|
2013-11-17 15:52:19 +01:00
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
2016-03-24 13:05:02 +01:00
|
|
|
namespace {
|
|
|
|
// Read passwd from |filename|
|
|
|
|
std::string read_passwd_from_file(const StringRef &opt,
|
|
|
|
const StringRef &filename) {
|
2012-12-03 07:33:04 +01:00
|
|
|
std::string line;
|
|
|
|
|
|
|
|
if (!is_secure(filename)) {
|
2016-03-24 13:05:02 +01:00
|
|
|
LOG(ERROR) << opt << ": Private key passwd file " << filename
|
2012-12-03 07:33:04 +01:00
|
|
|
<< " has insecure mode.";
|
|
|
|
return line;
|
|
|
|
}
|
|
|
|
|
2016-03-24 13:05:02 +01:00
|
|
|
std::ifstream in(filename.c_str(), std::ios::binary);
|
2014-11-27 15:39:04 +01:00
|
|
|
if (!in) {
|
2016-03-24 13:05:02 +01:00
|
|
|
LOG(ERROR) << opt << ": Could not open key passwd file " << filename;
|
2012-12-03 07:33:04 +01:00
|
|
|
return line;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::getline(in, line);
|
|
|
|
return line;
|
|
|
|
}
|
2016-03-24 13:05:02 +01:00
|
|
|
} // namespace
|
2012-12-03 07:33:04 +01:00
|
|
|
|
2016-03-24 13:05:02 +01:00
|
|
|
Headers::value_type parse_header(const StringRef &optarg) {
|
|
|
|
auto colon = std::find(std::begin(optarg), std::end(optarg), ':');
|
2014-04-26 07:56:08 +02:00
|
|
|
|
2016-03-24 13:05:02 +01:00
|
|
|
if (colon == std::end(optarg) || colon == std::begin(optarg)) {
|
2014-04-26 07:56:08 +02:00
|
|
|
return {"", ""};
|
|
|
|
}
|
|
|
|
|
|
|
|
auto value = colon + 1;
|
2014-11-27 15:39:04 +01:00
|
|
|
for (; *value == '\t' || *value == ' '; ++value)
|
|
|
|
;
|
2014-04-26 07:56:08 +02:00
|
|
|
|
2016-03-24 13:05:02 +01:00
|
|
|
auto p = Header(std::string{std::begin(optarg), colon},
|
|
|
|
std::string{value, std::end(optarg)});
|
2016-02-13 14:19:05 +01:00
|
|
|
util::inp_strlower(p.name);
|
2015-11-05 14:48:54 +01:00
|
|
|
|
2015-12-25 12:57:24 +01:00
|
|
|
if (!nghttp2_check_header_name(
|
2016-02-13 14:19:05 +01:00
|
|
|
reinterpret_cast<const uint8_t *>(p.name.c_str()), p.name.size()) ||
|
2015-12-25 12:57:24 +01:00
|
|
|
!nghttp2_check_header_value(
|
2016-02-13 14:19:05 +01:00
|
|
|
reinterpret_cast<const uint8_t *>(p.value.c_str()), p.value.size())) {
|
2016-03-24 13:05:02 +01:00
|
|
|
return Header{};
|
2015-12-25 12:57:24 +01:00
|
|
|
}
|
|
|
|
|
2015-11-05 14:48:54 +01:00
|
|
|
return p;
|
2014-04-26 07:56:08 +02:00
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
template <typename T>
|
2016-03-24 13:05:02 +01:00
|
|
|
int parse_uint(T *dest, const StringRef &opt, const StringRef &optarg) {
|
|
|
|
auto val = util::parse_uint(optarg);
|
|
|
|
if (val == -1) {
|
2014-08-27 16:36:36 +02:00
|
|
|
LOG(ERROR) << opt << ": bad value. Specify an integer >= 0.";
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
*dest = val;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-01-13 13:54:53 +01:00
|
|
|
namespace {
|
|
|
|
template <typename T>
|
2016-03-24 13:05:02 +01:00
|
|
|
int parse_uint_with_unit(T *dest, const StringRef &opt,
|
|
|
|
const StringRef &optarg) {
|
2015-01-13 13:54:53 +01:00
|
|
|
auto n = util::parse_uint_with_unit(optarg);
|
|
|
|
if (n == -1) {
|
|
|
|
LOG(ERROR) << opt << ": bad value: '" << optarg << "'";
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-09-10 09:51:35 +02:00
|
|
|
if (static_cast<uint64_t>(std::numeric_limits<T>::max()) <
|
|
|
|
static_cast<uint64_t>(n)) {
|
2016-09-09 14:05:37 +02:00
|
|
|
LOG(ERROR) << opt
|
|
|
|
<< ": too large. The value should be less than or equal to "
|
|
|
|
<< std::numeric_limits<T>::max();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-01-13 13:54:53 +01:00
|
|
|
*dest = n;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2016-03-24 13:05:02 +01:00
|
|
|
// Parses |optarg| as signed integer. This requires |optarg| to be
|
|
|
|
// NULL-terminated string.
|
2014-11-27 15:39:04 +01:00
|
|
|
template <typename T>
|
2016-03-24 13:05:02 +01:00
|
|
|
int parse_int(T *dest, const StringRef &opt, const char *optarg) {
|
2014-08-27 16:36:36 +02:00
|
|
|
char *end = nullptr;
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
|
|
|
|
auto val = strtol(optarg, &end, 10);
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (!optarg[0] || errno != 0 || *end) {
|
2014-08-27 16:36:36 +02:00
|
|
|
LOG(ERROR) << opt << ": bad value. Specify an integer.";
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
*dest = val;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-07-14 16:36:44 +02:00
|
|
|
namespace {
|
2015-07-14 16:45:50 +02:00
|
|
|
// generated by gennghttpxfun.py
|
2015-07-14 16:36:44 +02:00
|
|
|
LogFragmentType log_var_lookup_token(const char *name, size_t namelen) {
|
|
|
|
switch (namelen) {
|
|
|
|
case 3:
|
|
|
|
switch (name[2]) {
|
|
|
|
case 'd':
|
|
|
|
if (util::strieq_l("pi", name, 2)) {
|
|
|
|
return SHRPX_LOGF_PID;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
switch (name[3]) {
|
|
|
|
case 'n':
|
|
|
|
if (util::strieq_l("alp", name, 3)) {
|
|
|
|
return SHRPX_LOGF_ALPN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
switch (name[5]) {
|
|
|
|
case 's':
|
|
|
|
if (util::strieq_l("statu", name, 5)) {
|
|
|
|
return SHRPX_LOGF_STATUS;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
switch (name[6]) {
|
|
|
|
case 't':
|
|
|
|
if (util::strieq_l("reques", name, 6)) {
|
|
|
|
return SHRPX_LOGF_REQUEST;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 10:
|
|
|
|
switch (name[9]) {
|
|
|
|
case 'l':
|
|
|
|
if (util::strieq_l("time_loca", name, 9)) {
|
|
|
|
return SHRPX_LOGF_TIME_LOCAL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
if (util::strieq_l("ssl_ciphe", name, 9)) {
|
|
|
|
return SHRPX_LOGF_SSL_CIPHER;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 11:
|
|
|
|
switch (name[10]) {
|
|
|
|
case 'r':
|
|
|
|
if (util::strieq_l("remote_add", name, 10)) {
|
|
|
|
return SHRPX_LOGF_REMOTE_ADDR;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
if (util::strieq_l("remote_por", name, 10)) {
|
|
|
|
return SHRPX_LOGF_REMOTE_PORT;
|
|
|
|
}
|
|
|
|
if (util::strieq_l("server_por", name, 10)) {
|
|
|
|
return SHRPX_LOGF_SERVER_PORT;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 12:
|
|
|
|
switch (name[11]) {
|
|
|
|
case '1':
|
|
|
|
if (util::strieq_l("time_iso860", name, 11)) {
|
|
|
|
return SHRPX_LOGF_TIME_ISO8601;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'e':
|
|
|
|
if (util::strieq_l("request_tim", name, 11)) {
|
|
|
|
return SHRPX_LOGF_REQUEST_TIME;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'l':
|
|
|
|
if (util::strieq_l("ssl_protoco", name, 11)) {
|
|
|
|
return SHRPX_LOGF_SSL_PROTOCOL;
|
|
|
|
}
|
|
|
|
break;
|
2016-08-04 17:04:47 +02:00
|
|
|
case 't':
|
|
|
|
if (util::strieq_l("backend_hos", name, 11)) {
|
|
|
|
return SHRPX_LOGF_BACKEND_HOST;
|
|
|
|
}
|
|
|
|
if (util::strieq_l("backend_por", name, 11)) {
|
|
|
|
return SHRPX_LOGF_BACKEND_PORT;
|
|
|
|
}
|
|
|
|
break;
|
2015-07-14 16:36:44 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 14:
|
|
|
|
switch (name[13]) {
|
|
|
|
case 'd':
|
|
|
|
if (util::strieq_l("ssl_session_i", name, 13)) {
|
|
|
|
return SHRPX_LOGF_SSL_SESSION_ID;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 15:
|
|
|
|
switch (name[14]) {
|
|
|
|
case 't':
|
|
|
|
if (util::strieq_l("body_bytes_sen", name, 14)) {
|
|
|
|
return SHRPX_LOGF_BODY_BYTES_SENT;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 18:
|
|
|
|
switch (name[17]) {
|
|
|
|
case 'd':
|
|
|
|
if (util::strieq_l("ssl_session_reuse", name, 17)) {
|
|
|
|
return SHRPX_LOGF_SSL_SESSION_REUSED;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return SHRPX_LOGF_NONE;
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2014-11-18 16:56:44 +01:00
|
|
|
namespace {
|
2014-11-27 15:39:04 +01:00
|
|
|
bool var_token(char c) {
|
2015-11-27 16:41:39 +01:00
|
|
|
return util::is_alpha(c) || util::is_digit(c) || c == '_';
|
2014-11-18 16:56:44 +01:00
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2016-03-24 13:05:02 +01:00
|
|
|
std::vector<LogFragment> parse_log_format(const StringRef &optarg) {
|
|
|
|
auto literal_start = std::begin(optarg);
|
|
|
|
auto p = literal_start;
|
|
|
|
auto eop = std::end(optarg);
|
2014-11-18 16:56:44 +01:00
|
|
|
|
|
|
|
auto res = std::vector<LogFragment>();
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
for (; p != eop;) {
|
|
|
|
if (*p != '$') {
|
2014-11-18 16:56:44 +01:00
|
|
|
++p;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto var_start = p;
|
|
|
|
|
|
|
|
++p;
|
|
|
|
|
2015-07-14 15:25:52 +02:00
|
|
|
const char *var_name;
|
|
|
|
size_t var_namelen;
|
|
|
|
if (p != eop && *p == '{') {
|
|
|
|
var_name = ++p;
|
|
|
|
for (; p != eop && var_token(*p); ++p)
|
|
|
|
;
|
|
|
|
|
|
|
|
if (p == eop || *p != '}') {
|
2016-03-24 13:05:02 +01:00
|
|
|
LOG(WARN) << "Missing '}' after " << StringRef{var_start, p};
|
2015-07-14 15:25:52 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
var_namelen = p - var_name;
|
|
|
|
++p;
|
|
|
|
} else {
|
|
|
|
var_name = p;
|
|
|
|
for (; p != eop && var_token(*p); ++p)
|
|
|
|
;
|
2014-11-18 16:56:44 +01:00
|
|
|
|
2015-07-14 15:25:52 +02:00
|
|
|
var_namelen = p - var_name;
|
|
|
|
}
|
2014-11-18 16:56:44 +01:00
|
|
|
|
|
|
|
const char *value = nullptr;
|
|
|
|
|
2015-07-14 16:36:44 +02:00
|
|
|
auto type = log_var_lookup_token(var_name, var_namelen);
|
|
|
|
|
|
|
|
if (type == SHRPX_LOGF_NONE) {
|
2016-03-24 16:14:12 +01:00
|
|
|
if (util::istarts_with_l(StringRef{var_name, var_namelen}, "http_")) {
|
2016-03-24 16:02:07 +01:00
|
|
|
if (util::streq_l("host", StringRef{var_name + str_size("http_"),
|
|
|
|
var_namelen - str_size("http_")})) {
|
2015-10-28 15:12:16 +01:00
|
|
|
// Special handling of host header field. We will use
|
|
|
|
// :authority header field if host header is missing. This
|
|
|
|
// is a typical case in HTTP/2.
|
|
|
|
type = SHRPX_LOGF_AUTHORITY;
|
|
|
|
} else {
|
|
|
|
type = SHRPX_LOGF_HTTP;
|
|
|
|
value = var_name + str_size("http_");
|
|
|
|
}
|
2015-07-14 16:36:44 +02:00
|
|
|
} else {
|
|
|
|
LOG(WARN) << "Unrecognized log format variable: "
|
2016-03-24 13:05:02 +01:00
|
|
|
<< StringRef{var_name, var_namelen};
|
2015-07-14 16:36:44 +02:00
|
|
|
continue;
|
|
|
|
}
|
2014-11-18 16:56:44 +01:00
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (literal_start < var_start) {
|
2016-01-17 07:04:09 +01:00
|
|
|
res.emplace_back(SHRPX_LOGF_LITERAL,
|
|
|
|
ImmutableString(literal_start, var_start));
|
2014-11-18 16:56:44 +01:00
|
|
|
}
|
|
|
|
|
2015-07-14 15:25:52 +02:00
|
|
|
literal_start = p;
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (value == nullptr) {
|
2015-07-14 15:43:02 +02:00
|
|
|
res.emplace_back(type);
|
2015-07-14 15:25:52 +02:00
|
|
|
continue;
|
2014-11-18 16:56:44 +01:00
|
|
|
}
|
|
|
|
|
2016-01-17 07:04:09 +01:00
|
|
|
auto name = std::string(value, var_name + var_namelen);
|
|
|
|
for (auto &c : name) {
|
|
|
|
if (c == '_') {
|
|
|
|
c = '-';
|
2015-07-14 15:25:52 +02:00
|
|
|
}
|
|
|
|
}
|
2016-01-17 07:04:09 +01:00
|
|
|
|
|
|
|
res.emplace_back(type, ImmutableString(name));
|
2014-11-18 16:56:44 +01:00
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (literal_start != eop) {
|
2016-01-17 07:04:09 +01:00
|
|
|
res.emplace_back(SHRPX_LOGF_LITERAL, ImmutableString(literal_start, eop));
|
2014-11-18 16:56:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2016-02-13 10:45:23 +01:00
|
|
|
namespace {
|
2016-03-24 13:05:02 +01:00
|
|
|
int parse_address_family(int *dest, const StringRef &opt,
|
|
|
|
const StringRef &optarg) {
|
|
|
|
if (util::strieq_l("auto", optarg)) {
|
2016-02-13 10:45:23 +01:00
|
|
|
*dest = AF_UNSPEC;
|
|
|
|
return 0;
|
|
|
|
}
|
2016-03-24 13:05:02 +01:00
|
|
|
if (util::strieq_l("IPv4", optarg)) {
|
2016-02-13 10:45:23 +01:00
|
|
|
*dest = AF_INET;
|
|
|
|
return 0;
|
|
|
|
}
|
2016-03-24 13:05:02 +01:00
|
|
|
if (util::strieq_l("IPv6", optarg)) {
|
2016-02-13 10:45:23 +01:00
|
|
|
*dest = AF_INET6;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG(ERROR) << opt << ": bad value: '" << optarg << "'";
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2014-08-27 16:36:36 +02:00
|
|
|
namespace {
|
2016-03-24 13:05:02 +01:00
|
|
|
int parse_duration(ev_tstamp *dest, const StringRef &opt,
|
|
|
|
const StringRef &optarg) {
|
2015-01-29 15:28:47 +01:00
|
|
|
auto t = util::parse_duration_with_unit(optarg);
|
2015-01-27 16:36:44 +01:00
|
|
|
if (t == std::numeric_limits<double>::infinity()) {
|
|
|
|
LOG(ERROR) << opt << ": bad value: '" << optarg << "'";
|
2014-08-27 16:36:36 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-01-27 16:36:44 +01:00
|
|
|
*dest = t;
|
2014-08-27 16:36:36 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2016-03-23 16:22:13 +01:00
|
|
|
struct MemcachedConnectionParams {
|
|
|
|
bool tls;
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
// Parses memcached connection configuration parameter |src_params|,
|
|
|
|
// and stores parsed results into |out|. This function returns 0 if
|
|
|
|
// it succeeds, or -1.
|
|
|
|
int parse_memcached_connection_params(MemcachedConnectionParams &out,
|
|
|
|
const StringRef &src_params,
|
|
|
|
const StringRef &opt) {
|
|
|
|
auto last = std::end(src_params);
|
|
|
|
for (auto first = std::begin(src_params); first != last;) {
|
|
|
|
auto end = std::find(first, last, ';');
|
|
|
|
auto param = StringRef{first, end};
|
|
|
|
|
|
|
|
if (util::strieq_l("tls", param)) {
|
|
|
|
out.tls = true;
|
|
|
|
} else if (util::strieq_l("no-tls", param)) {
|
|
|
|
out.tls = false;
|
|
|
|
} else if (!param.empty()) {
|
|
|
|
LOG(ERROR) << opt << ": " << param << ": unknown keyword";
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (end == last) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
first = end + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2016-03-23 15:56:09 +01:00
|
|
|
struct UpstreamParams {
|
2016-06-16 16:30:35 +02:00
|
|
|
int alt_mode;
|
2016-03-23 15:56:09 +01:00
|
|
|
bool tls;
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
// Parses upstream configuration parameter |src_params|, and stores
|
|
|
|
// parsed results into |out|. This function returns 0 if it succeeds,
|
|
|
|
// or -1.
|
|
|
|
int parse_upstream_params(UpstreamParams &out, const StringRef &src_params) {
|
|
|
|
auto last = std::end(src_params);
|
|
|
|
for (auto first = std::begin(src_params); first != last;) {
|
|
|
|
auto end = std::find(first, last, ';');
|
|
|
|
auto param = StringRef{first, end};
|
|
|
|
|
|
|
|
if (util::strieq_l("tls", param)) {
|
|
|
|
out.tls = true;
|
|
|
|
} else if (util::strieq_l("no-tls", param)) {
|
|
|
|
out.tls = false;
|
2016-06-02 15:39:04 +02:00
|
|
|
} else if (util::strieq_l("api", param)) {
|
2016-06-21 15:44:26 +02:00
|
|
|
if (out.alt_mode && out.alt_mode != ALTMODE_API) {
|
|
|
|
LOG(ERROR) << "frontend: api and healthmon are mutually exclusive";
|
|
|
|
return -1;
|
|
|
|
}
|
2016-06-16 16:30:35 +02:00
|
|
|
out.alt_mode = ALTMODE_API;
|
2016-06-16 17:00:37 +02:00
|
|
|
} else if (util::strieq_l("healthmon", param)) {
|
2016-06-21 15:44:26 +02:00
|
|
|
if (out.alt_mode && out.alt_mode != ALTMODE_HEALTHMON) {
|
|
|
|
LOG(ERROR) << "frontend: api and healthmon are mutually exclusive";
|
|
|
|
return -1;
|
|
|
|
}
|
2016-06-16 17:00:37 +02:00
|
|
|
out.alt_mode = ALTMODE_HEALTHMON;
|
2016-03-23 15:56:09 +01:00
|
|
|
} else if (!param.empty()) {
|
|
|
|
LOG(ERROR) << "frontend: " << param << ": unknown keyword";
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (end == last) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
first = end + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2016-03-23 14:56:18 +01:00
|
|
|
struct DownstreamParams {
|
2016-04-29 07:42:18 +02:00
|
|
|
StringRef sni;
|
2016-04-09 14:58:08 +02:00
|
|
|
size_t fall;
|
|
|
|
size_t rise;
|
2016-03-23 14:56:18 +01:00
|
|
|
shrpx_proto proto;
|
2016-06-09 15:35:59 +02:00
|
|
|
shrpx_session_affinity affinity;
|
2016-03-23 14:56:18 +01:00
|
|
|
bool tls;
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
// Parses downstream configuration parameter |src_params|, and stores
|
|
|
|
// parsed results into |out|. This function returns 0 if it succeeds,
|
|
|
|
// or -1.
|
|
|
|
int parse_downstream_params(DownstreamParams &out,
|
|
|
|
const StringRef &src_params) {
|
|
|
|
auto last = std::end(src_params);
|
|
|
|
for (auto first = std::begin(src_params); first != last;) {
|
|
|
|
auto end = std::find(first, last, ';');
|
|
|
|
auto param = StringRef{first, end};
|
|
|
|
|
|
|
|
if (util::istarts_with_l(param, "proto=")) {
|
|
|
|
auto protostr = StringRef{first + str_size("proto="), end};
|
|
|
|
if (protostr.empty()) {
|
|
|
|
LOG(ERROR) << "backend: proto: protocol is empty";
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (util::streq_l("h2", std::begin(protostr), protostr.size())) {
|
|
|
|
out.proto = PROTO_HTTP2;
|
|
|
|
} else if (util::streq_l("http/1.1", std::begin(protostr),
|
|
|
|
protostr.size())) {
|
|
|
|
out.proto = PROTO_HTTP1;
|
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "backend: proto: unknown protocol " << protostr;
|
|
|
|
return -1;
|
|
|
|
}
|
2016-04-09 14:58:08 +02:00
|
|
|
} else if (util::istarts_with_l(param, "fall=")) {
|
|
|
|
auto valstr = StringRef{first + str_size("fall="), end};
|
|
|
|
if (valstr.empty()) {
|
|
|
|
LOG(ERROR) << "backend: fall: non-negative integer is expected";
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto n = util::parse_uint(valstr);
|
|
|
|
if (n == -1) {
|
|
|
|
LOG(ERROR) << "backend: fall: non-negative integer is expected";
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
out.fall = n;
|
|
|
|
} else if (util::istarts_with_l(param, "rise=")) {
|
|
|
|
auto valstr = StringRef{first + str_size("rise="), end};
|
|
|
|
if (valstr.empty()) {
|
|
|
|
LOG(ERROR) << "backend: rise: non-negative integer is expected";
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto n = util::parse_uint(valstr);
|
|
|
|
if (n == -1) {
|
|
|
|
LOG(ERROR) << "backend: rise: non-negative integer is expected";
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
out.rise = n;
|
2016-03-23 14:56:18 +01:00
|
|
|
} else if (util::strieq_l("tls", param)) {
|
|
|
|
out.tls = true;
|
|
|
|
} else if (util::strieq_l("no-tls", param)) {
|
|
|
|
out.tls = false;
|
2016-04-29 07:42:18 +02:00
|
|
|
} else if (util::istarts_with_l(param, "sni=")) {
|
|
|
|
out.sni = StringRef{first + str_size("sni="), end};
|
2016-06-09 15:35:59 +02:00
|
|
|
} else if (util::istarts_with_l(param, "affinity=")) {
|
|
|
|
auto valstr = StringRef{first + str_size("affinity="), end};
|
|
|
|
if (util::strieq_l("none", valstr)) {
|
|
|
|
out.affinity = AFFINITY_NONE;
|
|
|
|
} else if (util::strieq_l("ip", valstr)) {
|
|
|
|
out.affinity = AFFINITY_IP;
|
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "backend: affinity: value must be either none or ip";
|
|
|
|
return -1;
|
|
|
|
}
|
2016-03-23 14:56:18 +01:00
|
|
|
} else if (!param.empty()) {
|
|
|
|
LOG(ERROR) << "backend: " << param << ": unknown keyword";
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (end == last) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
first = end + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2015-07-09 19:52:11 +02:00
|
|
|
namespace {
|
2016-02-28 13:35:26 +01:00
|
|
|
// Parses host-path mapping patterns in |src_pattern|, and stores
|
|
|
|
// mappings in config. We will store each host-path pattern found in
|
|
|
|
// |src| with |addr|. |addr| will be copied accordingly. Also we
|
|
|
|
// make a group based on the pattern. The "/" pattern is considered
|
|
|
|
// as catch-all. We also parse protocol specified in |src_proto|.
|
|
|
|
//
|
|
|
|
// This function returns 0 if it succeeds, or -1.
|
2016-06-02 16:59:59 +02:00
|
|
|
int parse_mapping(Config *config, DownstreamAddrConfig addr,
|
|
|
|
const StringRef &src_pattern, const StringRef &src_params) {
|
2015-07-09 19:52:11 +02:00
|
|
|
// This returns at least 1 element (it could be empty string). We
|
|
|
|
// will append '/' to all patterns, so it becomes catch-all pattern.
|
2016-02-28 13:35:26 +01:00
|
|
|
auto mapping = util::split_str(src_pattern, ':');
|
2015-07-09 19:52:11 +02:00
|
|
|
assert(!mapping.empty());
|
2016-06-03 12:13:02 +02:00
|
|
|
auto &downstreamconf = *config->conn.downstream;
|
|
|
|
auto &addr_groups = downstreamconf.addr_groups;
|
2016-01-19 08:56:12 +01:00
|
|
|
|
2016-03-23 14:56:18 +01:00
|
|
|
DownstreamParams params{};
|
|
|
|
params.proto = PROTO_HTTP1;
|
2016-02-28 13:35:26 +01:00
|
|
|
|
2016-03-23 14:56:18 +01:00
|
|
|
if (parse_downstream_params(params, src_params) != 0) {
|
|
|
|
return -1;
|
2016-02-28 13:35:26 +01:00
|
|
|
}
|
|
|
|
|
2016-04-09 14:58:08 +02:00
|
|
|
addr.fall = params.fall;
|
|
|
|
addr.rise = params.rise;
|
2016-05-24 16:36:43 +02:00
|
|
|
addr.proto = params.proto;
|
|
|
|
addr.tls = params.tls;
|
2016-04-29 07:42:18 +02:00
|
|
|
addr.sni = ImmutableString{std::begin(params.sni), std::end(params.sni)};
|
2016-04-09 14:58:08 +02:00
|
|
|
|
2016-06-11 11:21:37 +02:00
|
|
|
auto &routerconf = downstreamconf.router;
|
|
|
|
auto &router = routerconf.router;
|
|
|
|
auto &rw_router = routerconf.rev_wildcard_router;
|
|
|
|
auto &wildcard_patterns = routerconf.wildcard_patterns;
|
|
|
|
|
2015-07-20 14:37:23 +02:00
|
|
|
for (const auto &raw_pattern : mapping) {
|
2015-07-09 19:52:11 +02:00
|
|
|
auto done = false;
|
|
|
|
std::string pattern;
|
2016-02-28 13:35:26 +01:00
|
|
|
auto slash = std::find(std::begin(raw_pattern), std::end(raw_pattern), '/');
|
|
|
|
if (slash == std::end(raw_pattern)) {
|
2015-07-09 19:52:11 +02:00
|
|
|
// This effectively makes empty pattern to "/".
|
2016-02-28 13:35:26 +01:00
|
|
|
pattern.assign(std::begin(raw_pattern), std::end(raw_pattern));
|
2015-07-09 19:52:11 +02:00
|
|
|
util::inp_strlower(pattern);
|
2015-11-27 16:03:16 +01:00
|
|
|
pattern += '/';
|
2015-07-09 19:52:11 +02:00
|
|
|
} else {
|
2016-02-28 13:35:26 +01:00
|
|
|
pattern.assign(std::begin(raw_pattern), slash);
|
2015-07-09 19:52:11 +02:00
|
|
|
util::inp_strlower(pattern);
|
2016-03-10 15:50:04 +01:00
|
|
|
pattern += http2::normalize_path(StringRef{slash, std::end(raw_pattern)},
|
|
|
|
StringRef{});
|
2015-07-09 19:52:11 +02:00
|
|
|
}
|
2016-01-19 08:56:12 +01:00
|
|
|
for (auto &g : addr_groups) {
|
2016-02-14 10:47:24 +01:00
|
|
|
if (g.pattern == pattern) {
|
2016-06-09 15:35:59 +02:00
|
|
|
// Last value wins if we have multiple different affinity
|
|
|
|
// value under one group.
|
|
|
|
if (params.affinity != AFFINITY_NONE) {
|
|
|
|
g.affinity = params.affinity;
|
|
|
|
}
|
2015-07-09 19:52:11 +02:00
|
|
|
g.addrs.push_back(addr);
|
|
|
|
done = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (done) {
|
|
|
|
continue;
|
|
|
|
}
|
2016-06-03 16:52:44 +02:00
|
|
|
|
|
|
|
auto idx = addr_groups.size();
|
|
|
|
addr_groups.emplace_back(StringRef{pattern});
|
|
|
|
auto &g = addr_groups.back();
|
2015-07-09 19:52:11 +02:00
|
|
|
g.addrs.push_back(addr);
|
2016-06-09 15:35:59 +02:00
|
|
|
g.affinity = params.affinity;
|
2015-09-25 19:38:45 +02:00
|
|
|
|
2016-03-12 16:59:25 +01:00
|
|
|
if (pattern[0] == '*') {
|
|
|
|
// wildcard pattern
|
|
|
|
auto path_first =
|
|
|
|
std::find(std::begin(g.pattern), std::end(g.pattern), '/');
|
|
|
|
|
|
|
|
auto host = StringRef{std::begin(g.pattern) + 1, path_first};
|
|
|
|
auto path = StringRef{path_first, std::end(g.pattern)};
|
|
|
|
|
|
|
|
auto it = std::find_if(
|
|
|
|
std::begin(wildcard_patterns), std::end(wildcard_patterns),
|
|
|
|
[&host](const WildcardPattern &wp) { return wp.host == host; });
|
|
|
|
|
|
|
|
if (it == std::end(wildcard_patterns)) {
|
2016-06-03 16:52:44 +02:00
|
|
|
wildcard_patterns.emplace_back(host);
|
2016-03-12 16:59:25 +01:00
|
|
|
|
2016-06-02 18:20:49 +02:00
|
|
|
auto &router = wildcard_patterns.back().router;
|
2016-06-03 16:52:44 +02:00
|
|
|
router.add_route(path, idx);
|
2016-06-10 16:13:40 +02:00
|
|
|
|
|
|
|
auto rev_host = host.str();
|
|
|
|
std::reverse(std::begin(rev_host), std::end(rev_host));
|
|
|
|
|
2016-06-11 11:21:37 +02:00
|
|
|
rw_router.add_route(StringRef{rev_host}, wildcard_patterns.size() - 1);
|
2016-03-12 16:59:25 +01:00
|
|
|
} else {
|
2016-06-03 16:52:44 +02:00
|
|
|
(*it).router.add_route(path, idx);
|
2016-03-12 16:59:25 +01:00
|
|
|
}
|
2016-06-11 11:21:37 +02:00
|
|
|
|
|
|
|
continue;
|
2016-03-12 16:59:25 +01:00
|
|
|
}
|
2016-06-11 11:21:37 +02:00
|
|
|
|
|
|
|
router.add_route(StringRef{g.pattern}, idx);
|
2015-07-09 19:52:11 +02:00
|
|
|
}
|
2016-02-28 13:35:26 +01:00
|
|
|
return 0;
|
2015-07-09 19:52:11 +02:00
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2016-01-15 15:04:58 +01:00
|
|
|
namespace {
|
2016-03-24 13:05:02 +01:00
|
|
|
int parse_forwarded_node_type(const StringRef &optarg) {
|
|
|
|
if (util::strieq_l("obfuscated", optarg)) {
|
2016-01-15 15:04:58 +01:00
|
|
|
return FORWARDED_NODE_OBFUSCATED;
|
|
|
|
}
|
|
|
|
|
2016-03-24 13:05:02 +01:00
|
|
|
if (util::strieq_l("ip", optarg)) {
|
2016-01-15 15:04:58 +01:00
|
|
|
return FORWARDED_NODE_IP;
|
|
|
|
}
|
|
|
|
|
2016-01-15 15:18:27 +01:00
|
|
|
if (optarg.size() < 2 || optarg[0] != '_') {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (std::find_if_not(std::begin(optarg), std::end(optarg), [](char c) {
|
|
|
|
return util::is_alpha(c) || util::is_digit(c) || c == '.' || c == '_' ||
|
|
|
|
c == '-';
|
|
|
|
}) != std::end(optarg)) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FORWARDED_NODE_OBFUSCATED;
|
2016-01-15 15:04:58 +01:00
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2016-03-19 15:41:21 +01:00
|
|
|
namespace {
|
2016-03-24 13:05:02 +01:00
|
|
|
int parse_error_page(std::vector<ErrorPage> &error_pages, const StringRef &opt,
|
|
|
|
const StringRef &optarg) {
|
|
|
|
auto eq = std::find(std::begin(optarg), std::end(optarg), '=');
|
|
|
|
if (eq == std::end(optarg) || eq + 1 == std::end(optarg)) {
|
|
|
|
LOG(ERROR) << opt << ": bad value: '" << optarg << "'";
|
2016-03-19 15:41:21 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-03-24 13:05:02 +01:00
|
|
|
auto codestr = StringRef{std::begin(optarg), eq};
|
2016-03-19 15:49:15 +01:00
|
|
|
unsigned int code;
|
2016-03-19 15:41:21 +01:00
|
|
|
|
2016-03-24 16:07:21 +01:00
|
|
|
if (codestr == StringRef::from_lit("*")) {
|
2016-03-19 15:49:15 +01:00
|
|
|
code = 0;
|
|
|
|
} else {
|
|
|
|
auto n = util::parse_uint(codestr);
|
|
|
|
|
|
|
|
if (n == -1 || n < 400 || n > 599) {
|
|
|
|
LOG(ERROR) << opt << ": bad code: '" << codestr << "'";
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
code = static_cast<unsigned int>(n);
|
2016-03-19 15:41:21 +01:00
|
|
|
}
|
|
|
|
|
2016-03-24 13:05:02 +01:00
|
|
|
auto path = StringRef{eq + 1, std::end(optarg)};
|
2016-03-19 15:41:21 +01:00
|
|
|
|
|
|
|
std::vector<uint8_t> content;
|
|
|
|
auto fd = open(path.c_str(), O_RDONLY);
|
|
|
|
if (fd == -1) {
|
|
|
|
auto error = errno;
|
|
|
|
LOG(ERROR) << opt << ": " << optarg << ": " << strerror(error);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto fd_closer = defer(close, fd);
|
|
|
|
|
|
|
|
std::array<uint8_t, 4096> buf;
|
|
|
|
for (;;) {
|
|
|
|
auto n = read(fd, buf.data(), buf.size());
|
|
|
|
if (n == -1) {
|
|
|
|
auto error = errno;
|
|
|
|
LOG(ERROR) << opt << ": " << optarg << ": " << strerror(error);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (n == 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
content.insert(std::end(content), std::begin(buf), std::begin(buf) + n);
|
|
|
|
}
|
|
|
|
|
2016-03-19 15:49:15 +01:00
|
|
|
error_pages.push_back(ErrorPage{std::move(content), code});
|
2016-03-19 15:41:21 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2015-07-14 16:45:50 +02:00
|
|
|
// generated by gennghttpxfun.py
|
2015-07-14 16:21:38 +02:00
|
|
|
int option_lookup_token(const char *name, size_t namelen) {
|
|
|
|
switch (namelen) {
|
|
|
|
case 4:
|
|
|
|
switch (name[3]) {
|
|
|
|
case 'f':
|
|
|
|
if (util::strieq_l("con", name, 3)) {
|
|
|
|
return SHRPX_OPTID_CONF;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
if (util::strieq_l("use", name, 3)) {
|
|
|
|
return SHRPX_OPTID_USER;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
switch (name[5]) {
|
|
|
|
case 'a':
|
|
|
|
if (util::strieq_l("no-vi", name, 5)) {
|
|
|
|
return SHRPX_OPTID_NO_VIA;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
if (util::strieq_l("altsv", name, 5)) {
|
|
|
|
return SHRPX_OPTID_ALTSVC;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
if (util::strieq_l("daemo", name, 5)) {
|
|
|
|
return SHRPX_OPTID_DAEMON;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
if (util::strieq_l("cacer", name, 5)) {
|
|
|
|
return SHRPX_OPTID_CACERT;
|
|
|
|
}
|
|
|
|
if (util::strieq_l("clien", name, 5)) {
|
|
|
|
return SHRPX_OPTID_CLIENT;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
switch (name[6]) {
|
|
|
|
case 'd':
|
|
|
|
if (util::strieq_l("backen", name, 6)) {
|
|
|
|
return SHRPX_OPTID_BACKEND;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'e':
|
|
|
|
if (util::strieq_l("includ", name, 6)) {
|
|
|
|
return SHRPX_OPTID_INCLUDE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'g':
|
|
|
|
if (util::strieq_l("backlo", name, 6)) {
|
|
|
|
return SHRPX_OPTID_BACKLOG;
|
|
|
|
}
|
|
|
|
if (util::strieq_l("paddin", name, 6)) {
|
|
|
|
return SHRPX_OPTID_PADDING;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'p':
|
|
|
|
if (util::strieq_l("no-ocs", name, 6)) {
|
|
|
|
return SHRPX_OPTID_NO_OCSP;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
if (util::strieq_l("cipher", name, 6)) {
|
|
|
|
return SHRPX_OPTID_CIPHERS;
|
|
|
|
}
|
|
|
|
if (util::strieq_l("worker", name, 6)) {
|
|
|
|
return SHRPX_OPTID_WORKERS;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
if (util::strieq_l("subcer", name, 6)) {
|
|
|
|
return SHRPX_OPTID_SUBCERT;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
switch (name[7]) {
|
|
|
|
case 'd':
|
|
|
|
if (util::strieq_l("fronten", name, 7)) {
|
|
|
|
return SHRPX_OPTID_FRONTEND;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'e':
|
|
|
|
if (util::strieq_l("insecur", name, 7)) {
|
|
|
|
return SHRPX_OPTID_INSECURE;
|
|
|
|
}
|
|
|
|
if (util::strieq_l("pid-fil", name, 7)) {
|
|
|
|
return SHRPX_OPTID_PID_FILE;
|
|
|
|
}
|
|
|
|
break;
|
2015-10-03 00:32:58 +02:00
|
|
|
case 'n':
|
|
|
|
if (util::strieq_l("fastope", name, 7)) {
|
|
|
|
return SHRPX_OPTID_FASTOPEN;
|
|
|
|
}
|
|
|
|
break;
|
2015-07-14 16:21:38 +02:00
|
|
|
case 't':
|
|
|
|
if (util::strieq_l("npn-lis", name, 7)) {
|
|
|
|
return SHRPX_OPTID_NPN_LIST;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 9:
|
|
|
|
switch (name[8]) {
|
|
|
|
case 'e':
|
2016-05-06 16:10:09 +02:00
|
|
|
if (util::strieq_l("no-kqueu", name, 8)) {
|
|
|
|
return SHRPX_OPTID_NO_KQUEUE;
|
|
|
|
}
|
2015-07-14 16:21:38 +02:00
|
|
|
if (util::strieq_l("read-rat", name, 8)) {
|
|
|
|
return SHRPX_OPTID_READ_RATE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'l':
|
|
|
|
if (util::strieq_l("log-leve", name, 8)) {
|
|
|
|
return SHRPX_OPTID_LOG_LEVEL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 10:
|
|
|
|
switch (name[9]) {
|
|
|
|
case 'e':
|
2016-03-19 15:41:21 +01:00
|
|
|
if (util::strieq_l("error-pag", name, 9)) {
|
|
|
|
return SHRPX_OPTID_ERROR_PAGE;
|
|
|
|
}
|
2015-10-05 17:10:42 +02:00
|
|
|
if (util::strieq_l("mruby-fil", name, 9)) {
|
|
|
|
return SHRPX_OPTID_MRUBY_FILE;
|
|
|
|
}
|
2015-07-14 16:21:38 +02:00
|
|
|
if (util::strieq_l("write-rat", name, 9)) {
|
|
|
|
return SHRPX_OPTID_WRITE_RATE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
if (util::strieq_l("read-burs", name, 9)) {
|
|
|
|
return SHRPX_OPTID_READ_BURST;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 11:
|
|
|
|
switch (name[10]) {
|
2016-08-26 15:28:09 +02:00
|
|
|
case 'e':
|
|
|
|
if (util::strieq_l("server-nam", name, 10)) {
|
|
|
|
return SHRPX_OPTID_SERVER_NAME;
|
|
|
|
}
|
|
|
|
break;
|
2016-02-28 13:35:26 +01:00
|
|
|
case 's':
|
|
|
|
if (util::strieq_l("backend-tl", name, 10)) {
|
|
|
|
return SHRPX_OPTID_BACKEND_TLS;
|
|
|
|
}
|
|
|
|
break;
|
2015-07-14 16:21:38 +02:00
|
|
|
case 't':
|
|
|
|
if (util::strieq_l("write-burs", name, 10)) {
|
|
|
|
return SHRPX_OPTID_WRITE_BURST;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'y':
|
|
|
|
if (util::strieq_l("http2-prox", name, 10)) {
|
|
|
|
return SHRPX_OPTID_HTTP2_PROXY;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 12:
|
|
|
|
switch (name[11]) {
|
|
|
|
case '4':
|
|
|
|
if (util::strieq_l("backend-ipv", name, 11)) {
|
|
|
|
return SHRPX_OPTID_BACKEND_IPV4;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '6':
|
|
|
|
if (util::strieq_l("backend-ipv", name, 11)) {
|
|
|
|
return SHRPX_OPTID_BACKEND_IPV6;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'e':
|
2015-07-23 16:54:56 +02:00
|
|
|
if (util::strieq_l("host-rewrit", name, 11)) {
|
|
|
|
return SHRPX_OPTID_HOST_REWRITE;
|
|
|
|
}
|
2015-07-14 16:21:38 +02:00
|
|
|
if (util::strieq_l("http2-bridg", name, 11)) {
|
|
|
|
return SHRPX_OPTID_HTTP2_BRIDGE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'y':
|
|
|
|
if (util::strieq_l("client-prox", name, 11)) {
|
|
|
|
return SHRPX_OPTID_CLIENT_PROXY;
|
|
|
|
}
|
2016-01-15 15:04:58 +01:00
|
|
|
if (util::strieq_l("forwarded-b", name, 11)) {
|
|
|
|
return SHRPX_OPTID_FORWARDED_BY;
|
|
|
|
}
|
2015-07-14 16:21:38 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 13:
|
|
|
|
switch (name[12]) {
|
2016-01-15 15:04:58 +01:00
|
|
|
case 'd':
|
|
|
|
if (util::strieq_l("add-forwarde", name, 12)) {
|
|
|
|
return SHRPX_OPTID_ADD_FORWARDED;
|
|
|
|
}
|
|
|
|
break;
|
2015-07-14 16:21:38 +02:00
|
|
|
case 'e':
|
|
|
|
if (util::strieq_l("dh-param-fil", name, 12)) {
|
|
|
|
return SHRPX_OPTID_DH_PARAM_FILE;
|
|
|
|
}
|
|
|
|
if (util::strieq_l("errorlog-fil", name, 12)) {
|
|
|
|
return SHRPX_OPTID_ERRORLOG_FILE;
|
|
|
|
}
|
|
|
|
if (util::strieq_l("rlimit-nofil", name, 12)) {
|
|
|
|
return SHRPX_OPTID_RLIMIT_NOFILE;
|
|
|
|
}
|
|
|
|
break;
|
2016-01-15 15:04:58 +01:00
|
|
|
case 'r':
|
|
|
|
if (util::strieq_l("forwarded-fo", name, 12)) {
|
|
|
|
return SHRPX_OPTID_FORWARDED_FOR;
|
|
|
|
}
|
|
|
|
break;
|
2015-07-14 16:21:38 +02:00
|
|
|
case 't':
|
|
|
|
if (util::strieq_l("verify-clien", name, 12)) {
|
|
|
|
return SHRPX_OPTID_VERIFY_CLIENT;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 14:
|
|
|
|
switch (name[13]) {
|
|
|
|
case 'e':
|
|
|
|
if (util::strieq_l("accesslog-fil", name, 13)) {
|
|
|
|
return SHRPX_OPTID_ACCESSLOG_FILE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
if (util::strieq_l("no-server-pus", name, 13)) {
|
|
|
|
return SHRPX_OPTID_NO_SERVER_PUSH;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
if (util::strieq_l("backend-no-tl", name, 13)) {
|
|
|
|
return SHRPX_OPTID_BACKEND_NO_TLS;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
if (util::strieq_l("tls-proto-lis", name, 13)) {
|
|
|
|
return SHRPX_OPTID_TLS_PROTO_LIST;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 15:
|
|
|
|
switch (name[14]) {
|
|
|
|
case 'e':
|
|
|
|
if (util::strieq_l("no-host-rewrit", name, 14)) {
|
|
|
|
return SHRPX_OPTID_NO_HOST_REWRITE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'g':
|
|
|
|
if (util::strieq_l("errorlog-syslo", name, 14)) {
|
|
|
|
return SHRPX_OPTID_ERRORLOG_SYSLOG;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
if (util::strieq_l("frontend-no-tl", name, 14)) {
|
|
|
|
return SHRPX_OPTID_FRONTEND_NO_TLS;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'y':
|
|
|
|
if (util::strieq_l("syslog-facilit", name, 14)) {
|
|
|
|
return SHRPX_OPTID_SYSLOG_FACILITY;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 16:
|
|
|
|
switch (name[15]) {
|
|
|
|
case 'e':
|
|
|
|
if (util::strieq_l("certificate-fil", name, 15)) {
|
|
|
|
return SHRPX_OPTID_CERTIFICATE_FILE;
|
|
|
|
}
|
|
|
|
if (util::strieq_l("client-cert-fil", name, 15)) {
|
|
|
|
return SHRPX_OPTID_CLIENT_CERT_FILE;
|
|
|
|
}
|
|
|
|
if (util::strieq_l("private-key-fil", name, 15)) {
|
|
|
|
return SHRPX_OPTID_PRIVATE_KEY_FILE;
|
|
|
|
}
|
|
|
|
if (util::strieq_l("worker-read-rat", name, 15)) {
|
|
|
|
return SHRPX_OPTID_WORKER_READ_RATE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'g':
|
|
|
|
if (util::strieq_l("accesslog-syslo", name, 15)) {
|
|
|
|
return SHRPX_OPTID_ACCESSLOG_SYSLOG;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
if (util::strieq_l("accesslog-forma", name, 15)) {
|
|
|
|
return SHRPX_OPTID_ACCESSLOG_FORMAT;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 17:
|
|
|
|
switch (name[16]) {
|
|
|
|
case 'e':
|
2016-08-31 16:47:15 +02:00
|
|
|
if (util::strieq_l("no-server-rewrit", name, 16)) {
|
|
|
|
return SHRPX_OPTID_NO_SERVER_REWRITE;
|
|
|
|
}
|
2015-07-14 16:21:38 +02:00
|
|
|
if (util::strieq_l("worker-write-rat", name, 16)) {
|
|
|
|
return SHRPX_OPTID_WORKER_WRITE_RATE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 's':
|
2016-02-06 11:50:21 +01:00
|
|
|
if (util::strieq_l("backend-http1-tl", name, 16)) {
|
|
|
|
return SHRPX_OPTID_BACKEND_HTTP1_TLS;
|
|
|
|
}
|
2015-07-14 16:21:38 +02:00
|
|
|
if (util::strieq_l("max-header-field", name, 16)) {
|
|
|
|
return SHRPX_OPTID_MAX_HEADER_FIELDS;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
if (util::strieq_l("worker-read-burs", name, 16)) {
|
|
|
|
return SHRPX_OPTID_WORKER_READ_BURST;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 18:
|
|
|
|
switch (name[17]) {
|
|
|
|
case 'r':
|
|
|
|
if (util::strieq_l("add-request-heade", name, 17)) {
|
|
|
|
return SHRPX_OPTID_ADD_REQUEST_HEADER;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
if (util::strieq_l("worker-write-burs", name, 17)) {
|
|
|
|
return SHRPX_OPTID_WORKER_WRITE_BURST;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 19:
|
|
|
|
switch (name[18]) {
|
|
|
|
case 'e':
|
|
|
|
if (util::strieq_l("no-location-rewrit", name, 18)) {
|
|
|
|
return SHRPX_OPTID_NO_LOCATION_REWRITE;
|
|
|
|
}
|
|
|
|
if (util::strieq_l("tls-ticket-key-fil", name, 18)) {
|
|
|
|
return SHRPX_OPTID_TLS_TICKET_KEY_FILE;
|
|
|
|
}
|
|
|
|
break;
|
2016-06-21 17:13:43 +02:00
|
|
|
case 'f':
|
|
|
|
if (util::strieq_l("backend-max-backof", name, 18)) {
|
|
|
|
return SHRPX_OPTID_BACKEND_MAX_BACKOFF;
|
|
|
|
}
|
|
|
|
break;
|
2015-07-14 16:21:38 +02:00
|
|
|
case 'r':
|
|
|
|
if (util::strieq_l("add-response-heade", name, 18)) {
|
|
|
|
return SHRPX_OPTID_ADD_RESPONSE_HEADER;
|
|
|
|
}
|
|
|
|
if (util::strieq_l("add-x-forwarded-fo", name, 18)) {
|
|
|
|
return SHRPX_OPTID_ADD_X_FORWARDED_FOR;
|
|
|
|
}
|
|
|
|
if (util::strieq_l("header-field-buffe", name, 18)) {
|
|
|
|
return SHRPX_OPTID_HEADER_FIELD_BUFFER;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
if (util::strieq_l("stream-read-timeou", name, 18)) {
|
|
|
|
return SHRPX_OPTID_STREAM_READ_TIMEOUT;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 20:
|
|
|
|
switch (name[19]) {
|
|
|
|
case 'g':
|
|
|
|
if (util::strieq_l("frontend-frame-debu", name, 19)) {
|
|
|
|
return SHRPX_OPTID_FRONTEND_FRAME_DEBUG;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'l':
|
|
|
|
if (util::strieq_l("ocsp-update-interva", name, 19)) {
|
|
|
|
return SHRPX_OPTID_OCSP_UPDATE_INTERVAL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
if (util::strieq_l("backend-read-timeou", name, 19)) {
|
|
|
|
return SHRPX_OPTID_BACKEND_READ_TIMEOUT;
|
|
|
|
}
|
|
|
|
if (util::strieq_l("stream-write-timeou", name, 19)) {
|
|
|
|
return SHRPX_OPTID_STREAM_WRITE_TIMEOUT;
|
|
|
|
}
|
|
|
|
if (util::strieq_l("verify-client-cacer", name, 19)) {
|
|
|
|
return SHRPX_OPTID_VERIFY_CLIENT_CACERT;
|
|
|
|
}
|
|
|
|
break;
|
2016-06-04 10:24:54 +02:00
|
|
|
case 'y':
|
|
|
|
if (util::strieq_l("api-max-request-bod", name, 19)) {
|
|
|
|
return SHRPX_OPTID_API_MAX_REQUEST_BODY;
|
|
|
|
}
|
|
|
|
break;
|
2015-07-14 16:21:38 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 21:
|
|
|
|
switch (name[20]) {
|
|
|
|
case 'd':
|
|
|
|
if (util::strieq_l("backend-tls-sni-fiel", name, 20)) {
|
|
|
|
return SHRPX_OPTID_BACKEND_TLS_SNI_FIELD;
|
|
|
|
}
|
|
|
|
break;
|
2015-09-06 11:39:32 +02:00
|
|
|
case 'l':
|
|
|
|
if (util::strieq_l("accept-proxy-protoco", name, 20)) {
|
|
|
|
return SHRPX_OPTID_ACCEPT_PROXY_PROTOCOL;
|
|
|
|
}
|
|
|
|
break;
|
2015-07-28 16:49:37 +02:00
|
|
|
case 'r':
|
|
|
|
if (util::strieq_l("tls-ticket-key-ciphe", name, 20)) {
|
|
|
|
return SHRPX_OPTID_TLS_TICKET_KEY_CIPHER;
|
|
|
|
}
|
|
|
|
break;
|
2015-07-14 16:21:38 +02:00
|
|
|
case 't':
|
|
|
|
if (util::strieq_l("backend-write-timeou", name, 20)) {
|
|
|
|
return SHRPX_OPTID_BACKEND_WRITE_TIMEOUT;
|
|
|
|
}
|
|
|
|
if (util::strieq_l("frontend-read-timeou", name, 20)) {
|
|
|
|
return SHRPX_OPTID_FRONTEND_READ_TIMEOUT;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 22:
|
|
|
|
switch (name[21]) {
|
|
|
|
case 'i':
|
|
|
|
if (util::strieq_l("backend-http-proxy-ur", name, 21)) {
|
|
|
|
return SHRPX_OPTID_BACKEND_HTTP_PROXY_URI;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
if (util::strieq_l("backend-request-buffe", name, 21)) {
|
|
|
|
return SHRPX_OPTID_BACKEND_REQUEST_BUFFER;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
if (util::strieq_l("frontend-write-timeou", name, 21)) {
|
|
|
|
return SHRPX_OPTID_FRONTEND_WRITE_TIMEOUT;
|
|
|
|
}
|
|
|
|
break;
|
2016-02-13 11:09:39 +01:00
|
|
|
case 'y':
|
|
|
|
if (util::strieq_l("backend-address-famil", name, 21)) {
|
|
|
|
return SHRPX_OPTID_BACKEND_ADDRESS_FAMILY;
|
|
|
|
}
|
|
|
|
break;
|
2015-07-14 16:21:38 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 23:
|
|
|
|
switch (name[22]) {
|
|
|
|
case 'e':
|
|
|
|
if (util::strieq_l("client-private-key-fil", name, 22)) {
|
|
|
|
return SHRPX_OPTID_CLIENT_PRIVATE_KEY_FILE;
|
|
|
|
}
|
|
|
|
if (util::strieq_l("private-key-passwd-fil", name, 22)) {
|
|
|
|
return SHRPX_OPTID_PRIVATE_KEY_PASSWD_FILE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
if (util::strieq_l("backend-response-buffe", name, 22)) {
|
|
|
|
return SHRPX_OPTID_BACKEND_RESPONSE_BUFFER;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 24:
|
|
|
|
switch (name[23]) {
|
2015-07-27 17:54:44 +02:00
|
|
|
case 'd':
|
2016-01-15 15:04:58 +01:00
|
|
|
if (util::strieq_l("strip-incoming-forwarde", name, 23)) {
|
|
|
|
return SHRPX_OPTID_STRIP_INCOMING_FORWARDED;
|
|
|
|
}
|
2015-07-27 17:54:44 +02:00
|
|
|
if (util::strieq_l("tls-ticket-key-memcache", name, 23)) {
|
|
|
|
return SHRPX_OPTID_TLS_TICKET_KEY_MEMCACHED;
|
|
|
|
}
|
|
|
|
break;
|
2015-07-14 16:21:38 +02:00
|
|
|
case 'e':
|
|
|
|
if (util::strieq_l("fetch-ocsp-response-fil", name, 23)) {
|
|
|
|
return SHRPX_OPTID_FETCH_OCSP_RESPONSE_FILE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
if (util::strieq_l("listener-disable-timeou", name, 23)) {
|
|
|
|
return SHRPX_OPTID_LISTENER_DISABLE_TIMEOUT;
|
|
|
|
}
|
2015-10-21 12:22:46 +02:00
|
|
|
if (util::strieq_l("tls-dyn-rec-idle-timeou", name, 23)) {
|
|
|
|
return SHRPX_OPTID_TLS_DYN_REC_IDLE_TIMEOUT;
|
|
|
|
}
|
2015-07-14 16:21:38 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 25:
|
|
|
|
switch (name[24]) {
|
2016-09-09 14:05:37 +02:00
|
|
|
case 'e':
|
|
|
|
if (util::strieq_l("backend-http2-window-siz", name, 24)) {
|
|
|
|
return SHRPX_OPTID_BACKEND_HTTP2_WINDOW_SIZE;
|
|
|
|
}
|
|
|
|
break;
|
2015-07-14 16:21:38 +02:00
|
|
|
case 'g':
|
|
|
|
if (util::strieq_l("http2-no-cookie-crumblin", name, 24)) {
|
|
|
|
return SHRPX_OPTID_HTTP2_NO_COOKIE_CRUMBLING;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
if (util::strieq_l("backend-http2-window-bit", name, 24)) {
|
|
|
|
return SHRPX_OPTID_BACKEND_HTTP2_WINDOW_BITS;
|
|
|
|
}
|
2016-02-06 09:22:23 +01:00
|
|
|
if (util::strieq_l("max-request-header-field", name, 24)) {
|
|
|
|
return SHRPX_OPTID_MAX_REQUEST_HEADER_FIELDS;
|
|
|
|
}
|
2015-07-14 16:21:38 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 26:
|
|
|
|
switch (name[25]) {
|
2016-09-09 14:05:37 +02:00
|
|
|
case 'e':
|
|
|
|
if (util::strieq_l("frontend-http2-window-siz", name, 25)) {
|
|
|
|
return SHRPX_OPTID_FRONTEND_HTTP2_WINDOW_SIZE;
|
|
|
|
}
|
|
|
|
break;
|
2015-07-14 16:21:38 +02:00
|
|
|
case 's':
|
|
|
|
if (util::strieq_l("frontend-http2-window-bit", name, 25)) {
|
|
|
|
return SHRPX_OPTID_FRONTEND_HTTP2_WINDOW_BITS;
|
|
|
|
}
|
2016-02-06 04:25:34 +01:00
|
|
|
if (util::strieq_l("max-response-header-field", name, 25)) {
|
|
|
|
return SHRPX_OPTID_MAX_RESPONSE_HEADER_FIELDS;
|
|
|
|
}
|
2015-07-14 16:21:38 +02:00
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
if (util::strieq_l("backend-keep-alive-timeou", name, 25)) {
|
|
|
|
return SHRPX_OPTID_BACKEND_KEEP_ALIVE_TIMEOUT;
|
|
|
|
}
|
2016-02-06 09:05:14 +01:00
|
|
|
if (util::strieq_l("no-http2-cipher-black-lis", name, 25)) {
|
|
|
|
return SHRPX_OPTID_NO_HTTP2_CIPHER_BLACK_LIST;
|
|
|
|
}
|
2015-07-14 16:21:38 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 27:
|
|
|
|
switch (name[26]) {
|
2015-07-25 15:22:17 +02:00
|
|
|
case 'd':
|
|
|
|
if (util::strieq_l("tls-session-cache-memcache", name, 26)) {
|
|
|
|
return SHRPX_OPTID_TLS_SESSION_CACHE_MEMCACHED;
|
|
|
|
}
|
|
|
|
break;
|
2016-02-06 09:22:23 +01:00
|
|
|
case 'r':
|
|
|
|
if (util::strieq_l("request-header-field-buffe", name, 26)) {
|
|
|
|
return SHRPX_OPTID_REQUEST_HEADER_FIELD_BUFFER;
|
|
|
|
}
|
|
|
|
break;
|
2015-07-14 16:21:38 +02:00
|
|
|
case 's':
|
|
|
|
if (util::strieq_l("worker-frontend-connection", name, 26)) {
|
|
|
|
return SHRPX_OPTID_WORKER_FRONTEND_CONNECTIONS;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
if (util::strieq_l("frontend-http2-read-timeou", name, 26)) {
|
|
|
|
return SHRPX_OPTID_FRONTEND_HTTP2_READ_TIMEOUT;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 28:
|
|
|
|
switch (name[27]) {
|
2015-10-21 12:22:46 +02:00
|
|
|
case 'd':
|
|
|
|
if (util::strieq_l("tls-dyn-rec-warmup-threshol", name, 27)) {
|
|
|
|
return SHRPX_OPTID_TLS_DYN_REC_WARMUP_THRESHOLD;
|
|
|
|
}
|
|
|
|
break;
|
2016-02-06 04:25:34 +01:00
|
|
|
case 'r':
|
|
|
|
if (util::strieq_l("response-header-field-buffe", name, 27)) {
|
|
|
|
return SHRPX_OPTID_RESPONSE_HEADER_FIELD_BUFFER;
|
|
|
|
}
|
|
|
|
break;
|
2015-07-14 16:21:38 +02:00
|
|
|
case 's':
|
|
|
|
if (util::strieq_l("http2-max-concurrent-stream", name, 27)) {
|
|
|
|
return SHRPX_OPTID_HTTP2_MAX_CONCURRENT_STREAMS;
|
|
|
|
}
|
2016-02-13 10:17:11 +01:00
|
|
|
if (util::strieq_l("tls-ticket-key-memcached-tl", name, 27)) {
|
|
|
|
return SHRPX_OPTID_TLS_TICKET_KEY_MEMCACHED_TLS;
|
|
|
|
}
|
2015-07-14 16:21:38 +02:00
|
|
|
break;
|
2016-02-28 14:15:49 +01:00
|
|
|
case 't':
|
|
|
|
if (util::strieq_l("backend-connections-per-hos", name, 27)) {
|
|
|
|
return SHRPX_OPTID_BACKEND_CONNECTIONS_PER_HOST;
|
|
|
|
}
|
|
|
|
break;
|
2015-07-14 16:21:38 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 30:
|
|
|
|
switch (name[29]) {
|
|
|
|
case 'r':
|
|
|
|
if (util::strieq_l("strip-incoming-x-forwarded-fo", name, 29)) {
|
|
|
|
return SHRPX_OPTID_STRIP_INCOMING_X_FORWARDED_FOR;
|
|
|
|
}
|
|
|
|
break;
|
2016-05-21 07:13:57 +02:00
|
|
|
case 't':
|
|
|
|
if (util::strieq_l("backend-http2-settings-timeou", name, 29)) {
|
|
|
|
return SHRPX_OPTID_BACKEND_HTTP2_SETTINGS_TIMEOUT;
|
|
|
|
}
|
|
|
|
break;
|
2015-07-14 16:21:38 +02:00
|
|
|
}
|
|
|
|
break;
|
2016-02-11 14:56:45 +01:00
|
|
|
case 31:
|
|
|
|
switch (name[30]) {
|
|
|
|
case 's':
|
|
|
|
if (util::strieq_l("tls-session-cache-memcached-tl", name, 30)) {
|
|
|
|
return SHRPX_OPTID_TLS_SESSION_CACHE_MEMCACHED_TLS;
|
|
|
|
}
|
|
|
|
break;
|
2016-05-21 07:13:57 +02:00
|
|
|
case 't':
|
|
|
|
if (util::strieq_l("frontend-http2-settings-timeou", name, 30)) {
|
|
|
|
return SHRPX_OPTID_FRONTEND_HTTP2_SETTINGS_TIMEOUT;
|
|
|
|
}
|
|
|
|
break;
|
2016-02-11 14:56:45 +01:00
|
|
|
}
|
|
|
|
break;
|
2016-02-28 09:11:12 +01:00
|
|
|
case 32:
|
|
|
|
switch (name[31]) {
|
|
|
|
case 'd':
|
|
|
|
if (util::strieq_l("backend-connections-per-fronten", name, 31)) {
|
|
|
|
return SHRPX_OPTID_BACKEND_CONNECTIONS_PER_FRONTEND;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2015-07-27 18:02:33 +02:00
|
|
|
case 33:
|
|
|
|
switch (name[32]) {
|
|
|
|
case 'l':
|
|
|
|
if (util::strieq_l("tls-ticket-key-memcached-interva", name, 32)) {
|
|
|
|
return SHRPX_OPTID_TLS_TICKET_KEY_MEMCACHED_INTERVAL;
|
|
|
|
}
|
2015-07-27 18:17:29 +02:00
|
|
|
if (util::strieq_l("tls-ticket-key-memcached-max-fai", name, 32)) {
|
|
|
|
return SHRPX_OPTID_TLS_TICKET_KEY_MEMCACHED_MAX_FAIL;
|
|
|
|
}
|
2015-07-27 18:02:33 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2015-07-14 16:21:38 +02:00
|
|
|
case 34:
|
|
|
|
switch (name[33]) {
|
2016-02-13 10:17:11 +01:00
|
|
|
case 'e':
|
|
|
|
if (util::strieq_l("tls-ticket-key-memcached-cert-fil", name, 33)) {
|
|
|
|
return SHRPX_OPTID_TLS_TICKET_KEY_MEMCACHED_CERT_FILE;
|
|
|
|
}
|
|
|
|
break;
|
2015-07-14 16:21:38 +02:00
|
|
|
case 'r':
|
|
|
|
if (util::strieq_l("frontend-http2-dump-request-heade", name, 33)) {
|
|
|
|
return SHRPX_OPTID_FRONTEND_HTTP2_DUMP_REQUEST_HEADER;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
if (util::strieq_l("backend-http1-connections-per-hos", name, 33)) {
|
|
|
|
return SHRPX_OPTID_BACKEND_HTTP1_CONNECTIONS_PER_HOST;
|
|
|
|
}
|
|
|
|
break;
|
2015-07-27 18:17:29 +02:00
|
|
|
case 'y':
|
|
|
|
if (util::strieq_l("tls-ticket-key-memcached-max-retr", name, 33)) {
|
|
|
|
return SHRPX_OPTID_TLS_TICKET_KEY_MEMCACHED_MAX_RETRY;
|
|
|
|
}
|
|
|
|
break;
|
2015-07-14 16:21:38 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 35:
|
|
|
|
switch (name[34]) {
|
2016-09-08 15:49:36 +02:00
|
|
|
case 'e':
|
|
|
|
if (util::strieq_l("frontend-http2-optimize-window-siz", name, 34)) {
|
|
|
|
return SHRPX_OPTID_FRONTEND_HTTP2_OPTIMIZE_WINDOW_SIZE;
|
|
|
|
}
|
|
|
|
break;
|
2015-07-14 16:21:38 +02:00
|
|
|
case 'r':
|
|
|
|
if (util::strieq_l("frontend-http2-dump-response-heade", name, 34)) {
|
|
|
|
return SHRPX_OPTID_FRONTEND_HTTP2_DUMP_RESPONSE_HEADER;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 36:
|
|
|
|
switch (name[35]) {
|
2016-09-09 14:05:37 +02:00
|
|
|
case 'e':
|
|
|
|
if (util::strieq_l("backend-http2-connection-window-siz", name, 35)) {
|
|
|
|
return SHRPX_OPTID_BACKEND_HTTP2_CONNECTION_WINDOW_SIZE;
|
|
|
|
}
|
|
|
|
break;
|
2015-07-14 16:21:38 +02:00
|
|
|
case 'r':
|
|
|
|
if (util::strieq_l("backend-http2-connections-per-worke", name, 35)) {
|
|
|
|
return SHRPX_OPTID_BACKEND_HTTP2_CONNECTIONS_PER_WORKER;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
if (util::strieq_l("backend-http2-connection-window-bit", name, 35)) {
|
|
|
|
return SHRPX_OPTID_BACKEND_HTTP2_CONNECTION_WINDOW_BITS;
|
|
|
|
}
|
2016-02-27 16:06:40 +01:00
|
|
|
if (util::strieq_l("backend-http2-max-concurrent-stream", name, 35)) {
|
|
|
|
return SHRPX_OPTID_BACKEND_HTTP2_MAX_CONCURRENT_STREAMS;
|
|
|
|
}
|
2015-07-14 16:21:38 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 37:
|
|
|
|
switch (name[36]) {
|
2016-02-12 16:20:38 +01:00
|
|
|
case 'e':
|
2016-09-09 14:05:37 +02:00
|
|
|
if (util::strieq_l("frontend-http2-connection-window-siz", name, 36)) {
|
|
|
|
return SHRPX_OPTID_FRONTEND_HTTP2_CONNECTION_WINDOW_SIZE;
|
|
|
|
}
|
2016-02-12 16:20:38 +01:00
|
|
|
if (util::strieq_l("tls-session-cache-memcached-cert-fil", name, 36)) {
|
|
|
|
return SHRPX_OPTID_TLS_SESSION_CACHE_MEMCACHED_CERT_FILE;
|
|
|
|
}
|
|
|
|
break;
|
2015-07-14 16:21:38 +02:00
|
|
|
case 's':
|
|
|
|
if (util::strieq_l("frontend-http2-connection-window-bit", name, 36)) {
|
|
|
|
return SHRPX_OPTID_FRONTEND_HTTP2_CONNECTION_WINDOW_BITS;
|
|
|
|
}
|
2016-02-27 16:06:40 +01:00
|
|
|
if (util::strieq_l("frontend-http2-max-concurrent-stream", name, 36)) {
|
|
|
|
return SHRPX_OPTID_FRONTEND_HTTP2_MAX_CONCURRENT_STREAMS;
|
|
|
|
}
|
2015-07-14 16:21:38 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 38:
|
|
|
|
switch (name[37]) {
|
|
|
|
case 'd':
|
|
|
|
if (util::strieq_l("backend-http1-connections-per-fronten", name, 37)) {
|
|
|
|
return SHRPX_OPTID_BACKEND_HTTP1_CONNECTIONS_PER_FRONTEND;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2016-02-13 10:45:23 +01:00
|
|
|
case 39:
|
|
|
|
switch (name[38]) {
|
|
|
|
case 'y':
|
|
|
|
if (util::strieq_l("tls-ticket-key-memcached-address-famil", name, 38)) {
|
|
|
|
return SHRPX_OPTID_TLS_TICKET_KEY_MEMCACHED_ADDRESS_FAMILY;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2016-09-12 15:53:02 +02:00
|
|
|
case 40:
|
|
|
|
switch (name[39]) {
|
|
|
|
case 'e':
|
|
|
|
if (util::strieq_l("backend-http2-decoder-dynamic-table-siz", name, 39)) {
|
|
|
|
return SHRPX_OPTID_BACKEND_HTTP2_DECODER_DYNAMIC_TABLE_SIZE;
|
|
|
|
}
|
|
|
|
if (util::strieq_l("backend-http2-encoder-dynamic-table-siz", name, 39)) {
|
|
|
|
return SHRPX_OPTID_BACKEND_HTTP2_ENCODER_DYNAMIC_TABLE_SIZE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2016-02-13 10:17:11 +01:00
|
|
|
case 41:
|
|
|
|
switch (name[40]) {
|
|
|
|
case 'e':
|
2016-09-12 15:53:02 +02:00
|
|
|
if (util::strieq_l("frontend-http2-decoder-dynamic-table-siz", name,
|
|
|
|
40)) {
|
|
|
|
return SHRPX_OPTID_FRONTEND_HTTP2_DECODER_DYNAMIC_TABLE_SIZE;
|
|
|
|
}
|
|
|
|
if (util::strieq_l("frontend-http2-encoder-dynamic-table-siz", name,
|
|
|
|
40)) {
|
|
|
|
return SHRPX_OPTID_FRONTEND_HTTP2_ENCODER_DYNAMIC_TABLE_SIZE;
|
|
|
|
}
|
2016-09-08 15:49:36 +02:00
|
|
|
if (util::strieq_l("frontend-http2-optimize-write-buffer-siz", name,
|
|
|
|
40)) {
|
|
|
|
return SHRPX_OPTID_FRONTEND_HTTP2_OPTIMIZE_WRITE_BUFFER_SIZE;
|
|
|
|
}
|
2016-02-13 10:17:11 +01:00
|
|
|
if (util::strieq_l("tls-ticket-key-memcached-private-key-fil", name,
|
|
|
|
40)) {
|
|
|
|
return SHRPX_OPTID_TLS_TICKET_KEY_MEMCACHED_PRIVATE_KEY_FILE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2016-02-13 10:45:23 +01:00
|
|
|
case 42:
|
|
|
|
switch (name[41]) {
|
|
|
|
case 'y':
|
|
|
|
if (util::strieq_l("tls-session-cache-memcached-address-famil", name,
|
|
|
|
41)) {
|
|
|
|
return SHRPX_OPTID_TLS_SESSION_CACHE_MEMCACHED_ADDRESS_FAMILY;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2016-02-12 16:20:38 +01:00
|
|
|
case 44:
|
|
|
|
switch (name[43]) {
|
|
|
|
case 'e':
|
|
|
|
if (util::strieq_l("tls-session-cache-memcached-private-key-fil", name,
|
|
|
|
43)) {
|
|
|
|
return SHRPX_OPTID_TLS_SESSION_CACHE_MEMCACHED_PRIVATE_KEY_FILE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2015-07-14 16:21:38 +02:00
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-06-02 16:59:59 +02:00
|
|
|
int parse_config(Config *config, const StringRef &opt, const StringRef &optarg,
|
2016-03-24 13:05:02 +01:00
|
|
|
std::set<StringRef> &included_set) {
|
2016-06-04 10:41:06 +02:00
|
|
|
auto optid = option_lookup_token(opt.c_str(), opt.size());
|
|
|
|
return parse_config(config, optid, opt, optarg, included_set);
|
|
|
|
}
|
|
|
|
|
|
|
|
int parse_config(Config *config, int optid, const StringRef &opt,
|
|
|
|
const StringRef &optarg, std::set<StringRef> &included_set) {
|
2012-08-01 17:06:41 +02:00
|
|
|
char host[NI_MAXHOST];
|
|
|
|
uint16_t port;
|
2015-07-09 19:52:11 +02:00
|
|
|
|
2015-07-14 16:21:38 +02:00
|
|
|
switch (optid) {
|
|
|
|
case SHRPX_OPTID_BACKEND: {
|
2016-03-24 13:05:02 +01:00
|
|
|
auto addr_end = std::find(std::begin(optarg), std::end(optarg), ';');
|
2016-02-28 13:35:26 +01:00
|
|
|
|
2016-02-27 15:24:14 +01:00
|
|
|
DownstreamAddrConfig addr{};
|
2016-03-24 17:00:04 +01:00
|
|
|
if (util::istarts_with(optarg, SHRPX_UNIX_PATH_PREFIX)) {
|
|
|
|
auto path = std::begin(optarg) + SHRPX_UNIX_PATH_PREFIX.size();
|
2016-02-28 13:35:26 +01:00
|
|
|
addr.host = ImmutableString(path, addr_end);
|
2015-02-22 09:12:00 +01:00
|
|
|
addr.host_unix = true;
|
2015-07-09 19:52:11 +02:00
|
|
|
} else {
|
2016-03-23 16:35:13 +01:00
|
|
|
if (split_host_port(host, sizeof(host), &port,
|
2016-03-24 13:05:02 +01:00
|
|
|
StringRef{std::begin(optarg), addr_end}, opt) == -1) {
|
2015-07-09 19:52:11 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2015-02-22 04:27:51 +01:00
|
|
|
|
2016-01-17 03:33:45 +01:00
|
|
|
addr.host = ImmutableString(host);
|
2015-07-09 19:52:11 +02:00
|
|
|
addr.port = port;
|
2015-02-22 04:27:51 +01:00
|
|
|
}
|
|
|
|
|
2016-03-24 13:05:02 +01:00
|
|
|
auto mapping = addr_end == std::end(optarg) ? addr_end : addr_end + 1;
|
|
|
|
auto mapping_end = std::find(mapping, std::end(optarg), ';');
|
2016-02-28 13:35:26 +01:00
|
|
|
|
2016-03-24 13:05:02 +01:00
|
|
|
auto params =
|
|
|
|
mapping_end == std::end(optarg) ? mapping_end : mapping_end + 1;
|
2016-02-28 13:35:26 +01:00
|
|
|
|
2016-06-02 16:59:59 +02:00
|
|
|
if (parse_mapping(config, addr, StringRef{mapping, mapping_end},
|
2016-03-24 13:05:02 +01:00
|
|
|
StringRef{params, std::end(optarg)}) != 0) {
|
2012-08-01 17:06:41 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_FRONTEND: {
|
2016-06-02 16:59:59 +02:00
|
|
|
auto &listenerconf = config->conn.listener;
|
2016-06-16 17:09:15 +02:00
|
|
|
auto &apiconf = config->api;
|
2016-01-19 08:56:12 +01:00
|
|
|
|
2016-03-24 13:05:02 +01:00
|
|
|
auto addr_end = std::find(std::begin(optarg), std::end(optarg), ';');
|
|
|
|
auto src_params = StringRef{addr_end, std::end(optarg)};
|
2016-03-23 15:56:09 +01:00
|
|
|
|
|
|
|
UpstreamParams params{};
|
|
|
|
params.tls = true;
|
|
|
|
|
|
|
|
if (parse_upstream_params(params, src_params) != 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-02-07 09:51:53 +01:00
|
|
|
UpstreamAddr addr{};
|
2016-01-31 11:41:56 +01:00
|
|
|
addr.fd = -1;
|
2016-03-23 15:56:09 +01:00
|
|
|
addr.tls = params.tls;
|
2016-06-16 16:30:35 +02:00
|
|
|
addr.alt_mode = params.alt_mode;
|
2016-01-31 11:41:56 +01:00
|
|
|
|
2016-06-16 16:30:35 +02:00
|
|
|
if (addr.alt_mode == ALTMODE_API) {
|
2016-06-16 17:09:15 +02:00
|
|
|
apiconf.enabled = true;
|
2016-06-16 14:22:36 +02:00
|
|
|
}
|
|
|
|
|
2016-03-24 17:00:04 +01:00
|
|
|
if (util::istarts_with(optarg, SHRPX_UNIX_PATH_PREFIX)) {
|
|
|
|
auto path = std::begin(optarg) + SHRPX_UNIX_PATH_PREFIX.size();
|
2016-03-23 15:56:09 +01:00
|
|
|
addr.host = ImmutableString{path, addr_end};
|
2016-01-31 11:41:56 +01:00
|
|
|
addr.host_unix = true;
|
|
|
|
|
|
|
|
listenerconf.addrs.push_back(std::move(addr));
|
2015-02-22 09:01:19 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-03-23 16:35:13 +01:00
|
|
|
if (split_host_port(host, sizeof(host), &port,
|
2016-03-24 13:05:02 +01:00
|
|
|
StringRef{std::begin(optarg), addr_end}, opt) == -1) {
|
2012-08-01 17:06:41 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2014-06-08 14:02:40 +02:00
|
|
|
|
2016-01-31 11:41:56 +01:00
|
|
|
addr.host = ImmutableString(host);
|
|
|
|
addr.port = port;
|
|
|
|
|
|
|
|
if (util::numeric_host(host, AF_INET)) {
|
|
|
|
addr.family = AF_INET;
|
|
|
|
listenerconf.addrs.push_back(std::move(addr));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (util::numeric_host(host, AF_INET6)) {
|
|
|
|
addr.family = AF_INET6;
|
|
|
|
listenerconf.addrs.push_back(std::move(addr));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
addr.family = AF_INET;
|
|
|
|
listenerconf.addrs.push_back(addr);
|
|
|
|
|
|
|
|
addr.family = AF_INET6;
|
|
|
|
listenerconf.addrs.push_back(std::move(addr));
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_WORKERS:
|
2015-09-06 09:59:57 +02:00
|
|
|
#ifdef NOTHREADS
|
|
|
|
LOG(WARN) << "Threading disabled at build time, no threads created.";
|
|
|
|
return 0;
|
2016-06-02 16:59:59 +02:00
|
|
|
#else // !NOTHREADS
|
|
|
|
return parse_uint(&config->num_worker, opt, optarg);
|
2015-09-06 09:59:57 +02:00
|
|
|
#endif // !NOTHREADS
|
2016-02-27 16:06:40 +01:00
|
|
|
case SHRPX_OPTID_HTTP2_MAX_CONCURRENT_STREAMS: {
|
|
|
|
LOG(WARN) << opt << ": deprecated. Use "
|
|
|
|
<< SHRPX_OPT_FRONTEND_HTTP2_MAX_CONCURRENT_STREAMS << " and "
|
|
|
|
<< SHRPX_OPT_BACKEND_HTTP2_MAX_CONCURRENT_STREAMS << " instead.";
|
|
|
|
size_t n;
|
|
|
|
if (parse_uint(&n, opt, optarg) != 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
2016-06-02 16:59:59 +02:00
|
|
|
auto &http2conf = config->http2;
|
2016-02-27 16:06:40 +01:00
|
|
|
http2conf.upstream.max_concurrent_streams = n;
|
|
|
|
http2conf.downstream.max_concurrent_streams = n;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_LOG_LEVEL:
|
2014-11-27 15:39:04 +01:00
|
|
|
if (Log::set_severity_level_by_name(optarg) == -1) {
|
2014-08-27 16:36:36 +02:00
|
|
|
LOG(ERROR) << opt << ": Invalid severity level: " << optarg;
|
2012-08-01 17:06:41 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_DAEMON:
|
2016-06-02 16:59:59 +02:00
|
|
|
config->daemon = util::strieq_l("yes", optarg);
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_HTTP2_PROXY:
|
2016-06-02 16:59:59 +02:00
|
|
|
config->http2_proxy = util::strieq_l("yes", optarg);
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_HTTP2_BRIDGE:
|
2016-03-29 15:11:42 +02:00
|
|
|
LOG(ERROR) << opt
|
|
|
|
<< ": deprecated. Use backend=<addr>,<port>;;proto=h2;tls";
|
2016-02-28 13:35:26 +01:00
|
|
|
return -1;
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_CLIENT_PROXY:
|
2016-03-29 15:11:42 +02:00
|
|
|
LOG(ERROR)
|
|
|
|
<< opt
|
|
|
|
<< ": deprecated. Use http2-proxy, frontend=<addr>,<port>;no-tls "
|
|
|
|
"and backend=<addr>,<port>;;proto=h2;tls";
|
2016-02-28 13:35:26 +01:00
|
|
|
return -1;
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_ADD_X_FORWARDED_FOR:
|
2016-06-02 16:59:59 +02:00
|
|
|
config->http.xff.add = util::strieq_l("yes", optarg);
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_STRIP_INCOMING_X_FORWARDED_FOR:
|
2016-06-02 16:59:59 +02:00
|
|
|
config->http.xff.strip_incoming = util::strieq_l("yes", optarg);
|
2014-10-24 15:24:17 +02:00
|
|
|
|
|
|
|
return 0;
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_NO_VIA:
|
2016-06-02 16:59:59 +02:00
|
|
|
config->http.no_via = util::strieq_l("yes", optarg);
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_FRONTEND_HTTP2_READ_TIMEOUT:
|
2016-06-02 16:59:59 +02:00
|
|
|
return parse_duration(&config->conn.upstream.timeout.http2_read, opt,
|
2015-01-27 16:36:44 +01:00
|
|
|
optarg);
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_FRONTEND_READ_TIMEOUT:
|
2016-06-02 16:59:59 +02:00
|
|
|
return parse_duration(&config->conn.upstream.timeout.read, opt, optarg);
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_FRONTEND_WRITE_TIMEOUT:
|
2016-06-02 16:59:59 +02:00
|
|
|
return parse_duration(&config->conn.upstream.timeout.write, opt, optarg);
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_BACKEND_READ_TIMEOUT:
|
2016-06-03 12:13:02 +02:00
|
|
|
return parse_duration(&config->conn.downstream->timeout.read, opt, optarg);
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_BACKEND_WRITE_TIMEOUT:
|
2016-06-03 12:13:02 +02:00
|
|
|
return parse_duration(&config->conn.downstream->timeout.write, opt, optarg);
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_STREAM_READ_TIMEOUT:
|
2016-06-02 16:59:59 +02:00
|
|
|
return parse_duration(&config->http2.timeout.stream_read, opt, optarg);
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_STREAM_WRITE_TIMEOUT:
|
2016-06-02 16:59:59 +02:00
|
|
|
return parse_duration(&config->http2.timeout.stream_write, opt, optarg);
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_ACCESSLOG_FILE:
|
2016-06-02 16:59:59 +02:00
|
|
|
config->logging.access.file =
|
2016-03-24 13:05:02 +01:00
|
|
|
ImmutableString{std::begin(optarg), std::end(optarg)};
|
2014-07-05 11:22:40 +02:00
|
|
|
|
|
|
|
return 0;
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_ACCESSLOG_SYSLOG:
|
2016-06-02 16:59:59 +02:00
|
|
|
config->logging.access.syslog = util::strieq_l("yes", optarg);
|
2014-07-05 11:22:40 +02:00
|
|
|
|
|
|
|
return 0;
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_ACCESSLOG_FORMAT:
|
2016-06-02 16:59:59 +02:00
|
|
|
config->logging.access.format = parse_log_format(optarg);
|
2014-11-18 16:56:44 +01:00
|
|
|
|
|
|
|
return 0;
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_ERRORLOG_FILE:
|
2016-06-02 16:59:59 +02:00
|
|
|
config->logging.error.file =
|
2016-03-24 13:05:02 +01:00
|
|
|
ImmutableString{std::begin(optarg), std::end(optarg)};
|
2014-07-05 11:22:40 +02:00
|
|
|
|
|
|
|
return 0;
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_ERRORLOG_SYSLOG:
|
2016-06-02 16:59:59 +02:00
|
|
|
config->logging.error.syslog = util::strieq_l("yes", optarg);
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
2015-10-03 00:32:58 +02:00
|
|
|
case SHRPX_OPTID_FASTOPEN: {
|
|
|
|
int n;
|
2016-03-24 13:05:02 +01:00
|
|
|
if (parse_int(&n, opt, optarg.c_str()) != 0) {
|
2015-10-03 00:32:58 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n < 0) {
|
|
|
|
LOG(ERROR) << opt << ": " << optarg << " is not allowed";
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-06-02 16:59:59 +02:00
|
|
|
config->conn.listener.fastopen = n;
|
2015-10-03 00:32:58 +02:00
|
|
|
|
|
|
|
return 0;
|
2015-10-15 14:42:11 +02:00
|
|
|
}
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_BACKEND_KEEP_ALIVE_TIMEOUT:
|
2016-06-03 12:13:02 +02:00
|
|
|
return parse_duration(&config->conn.downstream->timeout.idle_read, opt,
|
2015-01-27 16:36:44 +01:00
|
|
|
optarg);
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_FRONTEND_HTTP2_WINDOW_BITS:
|
|
|
|
case SHRPX_OPTID_BACKEND_HTTP2_WINDOW_BITS: {
|
2016-09-09 14:05:37 +02:00
|
|
|
LOG(WARN) << opt << ": deprecated. Use "
|
|
|
|
<< (optid == SHRPX_OPTID_FRONTEND_HTTP2_WINDOW_BITS
|
|
|
|
? SHRPX_OPT_FRONTEND_HTTP2_WINDOW_SIZE
|
|
|
|
: SHRPX_OPT_BACKEND_HTTP2_WINDOW_SIZE);
|
|
|
|
int32_t *resp;
|
2014-08-27 16:36:36 +02:00
|
|
|
|
2015-07-14 16:21:38 +02:00
|
|
|
if (optid == SHRPX_OPTID_FRONTEND_HTTP2_WINDOW_BITS) {
|
2016-09-09 14:05:37 +02:00
|
|
|
resp = &config->http2.upstream.window_size;
|
2012-11-21 15:47:48 +01:00
|
|
|
} else {
|
2016-09-09 14:05:37 +02:00
|
|
|
resp = &config->http2.downstream.window_size;
|
2012-11-21 15:47:48 +01:00
|
|
|
}
|
2014-08-27 16:36:36 +02:00
|
|
|
|
2012-08-01 17:06:41 +02:00
|
|
|
errno = 0;
|
2014-08-27 16:36:36 +02:00
|
|
|
|
|
|
|
int n;
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (parse_uint(&n, opt, optarg) != 0) {
|
2014-08-27 16:36:36 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (n >= 31) {
|
2014-08-27 16:36:36 +02:00
|
|
|
LOG(ERROR) << opt
|
|
|
|
<< ": specify the integer in the range [0, 30], inclusive";
|
2012-08-01 17:06:41 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2014-06-08 16:01:48 +02:00
|
|
|
|
2016-09-09 14:05:37 +02:00
|
|
|
// Make 16 bits to the HTTP/2 default 64KiB - 1. This is the same
|
|
|
|
// behaviour of previous code. For SPDY, we adjust this value in
|
|
|
|
// SpdyUpstream to look like the SPDY default.
|
|
|
|
*resp = (1 << n) - 1;
|
2014-08-27 16:36:36 +02:00
|
|
|
|
2014-06-08 16:01:48 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_FRONTEND_HTTP2_CONNECTION_WINDOW_BITS:
|
|
|
|
case SHRPX_OPTID_BACKEND_HTTP2_CONNECTION_WINDOW_BITS: {
|
2016-09-09 14:05:37 +02:00
|
|
|
LOG(WARN) << opt << ": deprecated. Use "
|
|
|
|
<< (optid == SHRPX_OPTID_FRONTEND_HTTP2_CONNECTION_WINDOW_BITS
|
|
|
|
? SHRPX_OPT_FRONTEND_HTTP2_CONNECTION_WINDOW_SIZE
|
|
|
|
: SHRPX_OPT_BACKEND_HTTP2_CONNECTION_WINDOW_SIZE);
|
|
|
|
int32_t *resp;
|
2014-08-27 16:36:36 +02:00
|
|
|
|
2015-07-14 16:21:38 +02:00
|
|
|
if (optid == SHRPX_OPTID_FRONTEND_HTTP2_CONNECTION_WINDOW_BITS) {
|
2016-09-09 14:05:37 +02:00
|
|
|
resp = &config->http2.upstream.connection_window_size;
|
2013-11-20 16:15:17 +01:00
|
|
|
} else {
|
2016-09-09 14:05:37 +02:00
|
|
|
resp = &config->http2.downstream.connection_window_size;
|
2013-11-20 16:15:17 +01:00
|
|
|
}
|
2014-08-27 16:36:36 +02:00
|
|
|
|
2013-11-20 16:15:17 +01:00
|
|
|
errno = 0;
|
2014-08-27 16:36:36 +02:00
|
|
|
|
|
|
|
int n;
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (parse_uint(&n, opt, optarg) != 0) {
|
2014-08-27 16:36:36 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (n < 16 || n >= 31) {
|
2014-08-27 16:36:36 +02:00
|
|
|
LOG(ERROR) << opt
|
|
|
|
<< ": specify the integer in the range [16, 30], inclusive";
|
2013-11-20 16:15:17 +01:00
|
|
|
return -1;
|
|
|
|
}
|
2014-06-08 16:01:48 +02:00
|
|
|
|
2016-09-09 14:05:37 +02:00
|
|
|
*resp = (1 << n) - 1;
|
2014-08-27 16:36:36 +02:00
|
|
|
|
2014-06-08 16:01:48 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_FRONTEND_NO_TLS:
|
2016-03-23 15:56:09 +01:00
|
|
|
LOG(WARN) << opt << ": deprecated. Use no-tls keyword in "
|
|
|
|
<< SHRPX_OPT_FRONTEND;
|
2014-06-08 16:01:48 +02:00
|
|
|
return 0;
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_BACKEND_NO_TLS:
|
2016-02-28 13:35:26 +01:00
|
|
|
LOG(WARN) << opt << ": deprecated. backend connection is not encrypted by "
|
|
|
|
"default. See also " << SHRPX_OPT_BACKEND_TLS;
|
2014-06-08 16:01:48 +02:00
|
|
|
return 0;
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_BACKEND_TLS_SNI_FIELD:
|
2016-04-29 07:42:18 +02:00
|
|
|
LOG(WARN) << opt << ": deprecated. Use sni keyword in --backend option. "
|
|
|
|
"For now, all sni values of all backends are "
|
|
|
|
"overridden by the given value " << optarg;
|
2016-06-02 16:59:59 +02:00
|
|
|
config->tls.backend_sni_name = optarg.str();
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_PID_FILE:
|
2016-06-02 16:59:59 +02:00
|
|
|
config->pid_file = ImmutableString{std::begin(optarg), std::end(optarg)};
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_USER: {
|
2016-03-24 13:05:02 +01:00
|
|
|
auto pwd = getpwnam(optarg.c_str());
|
2014-11-27 15:39:04 +01:00
|
|
|
if (!pwd) {
|
|
|
|
LOG(ERROR) << opt << ": failed to get uid from " << optarg << ": "
|
|
|
|
<< strerror(errno);
|
2012-08-01 17:06:41 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2016-08-26 15:40:59 +02:00
|
|
|
config->user = ImmutableString{pwd->pw_name};
|
2016-06-02 16:59:59 +02:00
|
|
|
config->uid = pwd->pw_uid;
|
|
|
|
config->gid = pwd->pw_gid;
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_PRIVATE_KEY_FILE:
|
2016-06-02 16:59:59 +02:00
|
|
|
config->tls.private_key_file =
|
2016-03-24 13:05:02 +01:00
|
|
|
ImmutableString{std::begin(optarg), std::end(optarg)};
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_PRIVATE_KEY_PASSWD_FILE: {
|
2016-03-24 13:05:02 +01:00
|
|
|
auto passwd = read_passwd_from_file(opt, optarg);
|
2012-12-03 07:33:04 +01:00
|
|
|
if (passwd.empty()) {
|
2014-08-27 16:36:36 +02:00
|
|
|
LOG(ERROR) << opt << ": Couldn't read key file's passwd from " << optarg;
|
2012-12-03 07:33:04 +01:00
|
|
|
return -1;
|
|
|
|
}
|
2016-08-26 15:52:08 +02:00
|
|
|
config->tls.private_key_passwd = ImmutableString{passwd};
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_CERTIFICATE_FILE:
|
2016-06-02 16:59:59 +02:00
|
|
|
config->tls.cert_file =
|
2016-03-24 13:05:02 +01:00
|
|
|
ImmutableString{std::begin(optarg), std::end(optarg)};
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_DH_PARAM_FILE:
|
2016-06-02 16:59:59 +02:00
|
|
|
config->tls.dh_param_file =
|
2016-03-24 13:05:02 +01:00
|
|
|
ImmutableString{std::begin(optarg), std::end(optarg)};
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_SUBCERT: {
|
2013-02-06 15:27:05 +01:00
|
|
|
// Private Key file and certificate file separated by ':'.
|
2016-03-24 13:05:02 +01:00
|
|
|
auto sp = std::find(std::begin(optarg), std::end(optarg), ':');
|
|
|
|
if (sp == std::end(optarg)) {
|
|
|
|
LOG(ERROR) << opt << ": missing ':' in " << optarg;
|
|
|
|
return -1;
|
2013-02-06 15:27:05 +01:00
|
|
|
}
|
2014-06-08 16:01:48 +02:00
|
|
|
|
2016-03-24 13:05:02 +01:00
|
|
|
auto private_key_file = StringRef{std::begin(optarg), sp};
|
|
|
|
|
|
|
|
if (private_key_file.empty()) {
|
|
|
|
LOG(ERROR) << opt << ": missing private key file: " << optarg;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto cert_file = StringRef{sp + 1, std::end(optarg)};
|
|
|
|
|
|
|
|
if (cert_file.empty()) {
|
|
|
|
LOG(ERROR) << opt << ": missing certificate file: " << optarg;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-06-02 16:59:59 +02:00
|
|
|
config->tls.subcerts.emplace_back(private_key_file.str(), cert_file.str());
|
2016-03-24 13:05:02 +01:00
|
|
|
|
2014-06-08 16:01:48 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_SYSLOG_FACILITY: {
|
2012-08-01 18:20:18 +02:00
|
|
|
int facility = int_syslog_facility(optarg);
|
2014-11-27 15:39:04 +01:00
|
|
|
if (facility == -1) {
|
2014-08-27 16:36:36 +02:00
|
|
|
LOG(ERROR) << opt << ": Unknown syslog facility: " << optarg;
|
2012-08-01 18:20:18 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2016-06-02 16:59:59 +02:00
|
|
|
config->logging.syslog_facility = facility;
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_BACKLOG: {
|
2014-08-27 16:36:36 +02:00
|
|
|
int n;
|
2016-03-24 13:05:02 +01:00
|
|
|
if (parse_int(&n, opt, optarg.c_str()) != 0) {
|
2014-08-27 16:36:36 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (n < -1) {
|
2014-08-27 16:36:36 +02:00
|
|
|
LOG(ERROR) << opt << ": " << optarg << " is not allowed";
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-06-02 16:59:59 +02:00
|
|
|
config->conn.listener.backlog = n;
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_CIPHERS:
|
2016-06-02 16:59:59 +02:00
|
|
|
config->tls.ciphers = ImmutableString{std::begin(optarg), std::end(optarg)};
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_CLIENT:
|
2016-03-29 06:09:52 +02:00
|
|
|
LOG(ERROR) << opt << ": deprecated. Use frontend=<addr>,<port>;no-tls, "
|
2016-03-29 15:10:30 +02:00
|
|
|
"backend=<addr>,<port>;;proto=h2;tls";
|
2016-02-28 13:35:26 +01:00
|
|
|
return -1;
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_INSECURE:
|
2016-06-02 16:59:59 +02:00
|
|
|
config->tls.insecure = util::strieq_l("yes", optarg);
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_CACERT:
|
2016-06-02 16:59:59 +02:00
|
|
|
config->tls.cacert = ImmutableString{std::begin(optarg), std::end(optarg)};
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_BACKEND_IPV4:
|
2016-02-13 11:09:39 +01:00
|
|
|
LOG(WARN) << opt
|
|
|
|
<< ": deprecated. Use backend-address-family=IPv4 instead.";
|
|
|
|
|
2016-06-03 12:13:02 +02:00
|
|
|
config->conn.downstream->family = AF_INET;
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_BACKEND_IPV6:
|
2016-02-13 11:09:39 +01:00
|
|
|
LOG(WARN) << opt
|
|
|
|
<< ": deprecated. Use backend-address-family=IPv6 instead.";
|
|
|
|
|
2016-06-03 12:13:02 +02:00
|
|
|
config->conn.downstream->family = AF_INET6;
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_BACKEND_HTTP_PROXY_URI: {
|
2016-06-02 16:59:59 +02:00
|
|
|
auto &proxy = config->downstream_http_proxy;
|
2016-01-17 14:51:40 +01:00
|
|
|
// Reset here so that multiple option occurrence does not merge
|
|
|
|
// the results.
|
|
|
|
proxy = {};
|
2013-02-09 08:42:01 +01:00
|
|
|
// parse URI and get hostname, port and optionally userinfo.
|
2015-07-19 10:55:37 +02:00
|
|
|
http_parser_url u{};
|
2016-03-24 13:05:02 +01:00
|
|
|
int rv = http_parser_parse_url(optarg.c_str(), optarg.size(), 0, &u);
|
2014-11-27 15:39:04 +01:00
|
|
|
if (rv == 0) {
|
|
|
|
if (u.field_set & UF_USERINFO) {
|
2016-03-24 13:05:02 +01:00
|
|
|
auto uf = util::get_uri_field(optarg.c_str(), u, UF_USERINFO);
|
2013-02-22 13:23:59 +01:00
|
|
|
// Surprisingly, u.field_set & UF_USERINFO is nonzero even if
|
|
|
|
// userinfo component is empty string.
|
2016-03-24 13:05:02 +01:00
|
|
|
if (!uf.empty()) {
|
|
|
|
proxy.userinfo = util::percent_decode(std::begin(uf), std::end(uf));
|
2013-02-22 13:23:59 +01:00
|
|
|
}
|
2013-02-09 08:42:01 +01:00
|
|
|
}
|
2014-11-27 15:39:04 +01:00
|
|
|
if (u.field_set & UF_HOST) {
|
2016-03-24 13:05:02 +01:00
|
|
|
http2::copy_url_component(proxy.host, &u, UF_HOST, optarg.c_str());
|
2013-02-09 08:42:01 +01:00
|
|
|
} else {
|
2014-08-27 16:36:36 +02:00
|
|
|
LOG(ERROR) << opt << ": no hostname specified";
|
2013-02-09 08:42:01 +01:00
|
|
|
return -1;
|
|
|
|
}
|
2014-11-27 15:39:04 +01:00
|
|
|
if (u.field_set & UF_PORT) {
|
2016-01-17 14:51:40 +01:00
|
|
|
proxy.port = u.port;
|
2013-02-09 08:42:01 +01:00
|
|
|
} else {
|
2014-08-27 16:36:36 +02:00
|
|
|
LOG(ERROR) << opt << ": no port specified";
|
2013-02-09 08:42:01 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
} else {
|
2014-08-27 16:36:36 +02:00
|
|
|
LOG(ERROR) << opt << ": parse error";
|
|
|
|
return -1;
|
2013-02-09 08:42:01 +01:00
|
|
|
}
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_READ_RATE:
|
2016-06-02 16:59:59 +02:00
|
|
|
return parse_uint_with_unit(&config->conn.upstream.ratelimit.read.rate, opt,
|
|
|
|
optarg);
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_READ_BURST:
|
2016-06-02 16:59:59 +02:00
|
|
|
return parse_uint_with_unit(&config->conn.upstream.ratelimit.read.burst,
|
|
|
|
opt, optarg);
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_WRITE_RATE:
|
2016-06-02 16:59:59 +02:00
|
|
|
return parse_uint_with_unit(&config->conn.upstream.ratelimit.write.rate,
|
|
|
|
opt, optarg);
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_WRITE_BURST:
|
2016-06-02 16:59:59 +02:00
|
|
|
return parse_uint_with_unit(&config->conn.upstream.ratelimit.write.burst,
|
|
|
|
opt, optarg);
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_WORKER_READ_RATE:
|
2015-01-02 03:22:39 +01:00
|
|
|
LOG(WARN) << opt << ": not implemented yet";
|
2016-01-19 08:56:12 +01:00
|
|
|
return 0;
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_WORKER_READ_BURST:
|
2015-01-02 03:22:39 +01:00
|
|
|
LOG(WARN) << opt << ": not implemented yet";
|
2016-01-19 08:56:12 +01:00
|
|
|
return 0;
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_WORKER_WRITE_RATE:
|
2015-01-02 03:22:39 +01:00
|
|
|
LOG(WARN) << opt << ": not implemented yet";
|
2016-01-19 08:56:12 +01:00
|
|
|
return 0;
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_WORKER_WRITE_BURST:
|
2015-01-02 03:22:39 +01:00
|
|
|
LOG(WARN) << opt << ": not implemented yet";
|
2016-01-19 08:56:12 +01:00
|
|
|
return 0;
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_NPN_LIST:
|
2016-06-02 16:59:59 +02:00
|
|
|
config->tls.npn_list = util::parse_config_str_list(optarg);
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_TLS_PROTO_LIST:
|
2016-06-02 16:59:59 +02:00
|
|
|
config->tls.tls_proto_list = util::parse_config_str_list(optarg);
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_VERIFY_CLIENT:
|
2016-06-02 16:59:59 +02:00
|
|
|
config->tls.client_verify.enabled = util::strieq_l("yes", optarg);
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_VERIFY_CLIENT_CACERT:
|
2016-06-02 16:59:59 +02:00
|
|
|
config->tls.client_verify.cacert =
|
2016-03-24 13:05:02 +01:00
|
|
|
ImmutableString{std::begin(optarg), std::end(optarg)};
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_CLIENT_PRIVATE_KEY_FILE:
|
2016-06-02 16:59:59 +02:00
|
|
|
config->tls.client.private_key_file =
|
2016-03-24 13:05:02 +01:00
|
|
|
ImmutableString{std::begin(optarg), std::end(optarg)};
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_CLIENT_CERT_FILE:
|
2016-06-02 16:59:59 +02:00
|
|
|
config->tls.client.cert_file =
|
2016-03-24 13:05:02 +01:00
|
|
|
ImmutableString{std::begin(optarg), std::end(optarg)};
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_FRONTEND_HTTP2_DUMP_REQUEST_HEADER:
|
2016-06-02 16:59:59 +02:00
|
|
|
config->http2.upstream.debug.dump.request_header_file =
|
2016-03-24 13:05:02 +01:00
|
|
|
ImmutableString{std::begin(optarg), std::end(optarg)};
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_FRONTEND_HTTP2_DUMP_RESPONSE_HEADER:
|
2016-06-02 16:59:59 +02:00
|
|
|
config->http2.upstream.debug.dump.response_header_file =
|
2016-03-24 13:05:02 +01:00
|
|
|
ImmutableString{std::begin(optarg), std::end(optarg)};
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_HTTP2_NO_COOKIE_CRUMBLING:
|
2016-06-02 16:59:59 +02:00
|
|
|
config->http2.no_cookie_crumbling = util::strieq_l("yes", optarg);
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_FRONTEND_FRAME_DEBUG:
|
2016-06-02 16:59:59 +02:00
|
|
|
config->http2.upstream.debug.frame_debug = util::strieq_l("yes", optarg);
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_PADDING:
|
2016-06-02 16:59:59 +02:00
|
|
|
return parse_uint(&config->padding, opt, optarg);
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_ALTSVC: {
|
2016-03-24 13:05:02 +01:00
|
|
|
auto tokens = util::split_str(optarg, ',');
|
2014-04-03 06:20:50 +02:00
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (tokens.size() < 2) {
|
2014-04-08 15:28:50 +02:00
|
|
|
// Requires at least protocol_id and port
|
2014-08-27 16:36:36 +02:00
|
|
|
LOG(ERROR) << opt << ": too few parameters: " << optarg;
|
2014-04-08 15:28:50 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2014-04-03 06:20:50 +02:00
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (tokens.size() > 4) {
|
2014-04-08 15:28:50 +02:00
|
|
|
// We only need protocol_id, port, host and origin
|
2014-08-27 16:36:36 +02:00
|
|
|
LOG(ERROR) << opt << ": too many parameters: " << optarg;
|
2014-04-03 06:20:50 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-08-27 16:36:36 +02:00
|
|
|
int port;
|
2014-04-08 15:28:50 +02:00
|
|
|
|
2016-03-24 13:05:02 +01:00
|
|
|
if (parse_uint(&port, opt, tokens[1]) != 0) {
|
2014-08-27 16:36:36 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (port < 1 ||
|
|
|
|
port > static_cast<int>(std::numeric_limits<uint16_t>::max())) {
|
2015-07-20 15:37:26 +02:00
|
|
|
LOG(ERROR) << opt << ": port is invalid: " << tokens[1];
|
2014-04-08 15:28:50 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-03-13 06:01:59 +01:00
|
|
|
AltSvc altsvc{};
|
2014-04-08 15:28:50 +02:00
|
|
|
|
2016-03-24 13:05:02 +01:00
|
|
|
altsvc.protocol_id = tokens[0].str();
|
2015-07-20 15:37:26 +02:00
|
|
|
|
|
|
|
altsvc.port = port;
|
2016-03-24 13:05:02 +01:00
|
|
|
altsvc.service = tokens[1].str();
|
2014-04-08 15:28:50 +02:00
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (tokens.size() > 2) {
|
2016-03-24 13:05:02 +01:00
|
|
|
altsvc.host = tokens[2].str();
|
2014-04-08 15:28:50 +02:00
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (tokens.size() > 3) {
|
2016-03-24 13:05:02 +01:00
|
|
|
altsvc.origin = tokens[3].str();
|
2014-04-08 15:28:50 +02:00
|
|
|
}
|
|
|
|
}
|
2014-04-03 06:20:50 +02:00
|
|
|
|
2016-06-02 16:59:59 +02:00
|
|
|
config->http.altsvcs.push_back(std::move(altsvc));
|
2014-04-03 06:20:50 +02:00
|
|
|
|
2014-06-08 16:01:48 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_ADD_REQUEST_HEADER:
|
|
|
|
case SHRPX_OPTID_ADD_RESPONSE_HEADER: {
|
2014-04-26 07:56:08 +02:00
|
|
|
auto p = parse_header(optarg);
|
2016-02-13 14:19:05 +01:00
|
|
|
if (p.name.empty()) {
|
2015-12-25 12:57:24 +01:00
|
|
|
LOG(ERROR) << opt << ": invalid header field: " << optarg;
|
2014-04-26 07:56:08 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2015-07-14 16:21:38 +02:00
|
|
|
if (optid == SHRPX_OPTID_ADD_REQUEST_HEADER) {
|
2016-06-02 16:59:59 +02:00
|
|
|
config->http.add_request_headers.push_back(std::move(p));
|
2015-06-05 16:04:20 +02:00
|
|
|
} else {
|
2016-06-02 16:59:59 +02:00
|
|
|
config->http.add_response_headers.push_back(std::move(p));
|
2015-06-05 16:04:20 +02:00
|
|
|
}
|
2014-06-08 16:01:48 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_WORKER_FRONTEND_CONNECTIONS:
|
2016-06-02 16:59:59 +02:00
|
|
|
return parse_uint(&config->conn.upstream.worker_connections, opt, optarg);
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_NO_LOCATION_REWRITE:
|
2016-06-02 16:59:59 +02:00
|
|
|
config->http.no_location_rewrite = util::strieq_l("yes", optarg);
|
2014-08-10 05:39:27 +02:00
|
|
|
|
|
|
|
return 0;
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_NO_HOST_REWRITE:
|
2015-07-23 16:54:56 +02:00
|
|
|
LOG(WARN) << SHRPX_OPT_NO_HOST_REWRITE
|
|
|
|
<< ": deprecated. :authority and host header fields are NOT "
|
|
|
|
"altered by default. To rewrite these headers, use "
|
|
|
|
"--host-rewrite option.";
|
2015-02-03 17:41:20 +01:00
|
|
|
|
|
|
|
return 0;
|
2016-02-28 14:15:49 +01:00
|
|
|
case SHRPX_OPTID_BACKEND_HTTP1_CONNECTIONS_PER_HOST:
|
|
|
|
LOG(WARN) << opt
|
|
|
|
<< ": deprecated. Use backend-connections-per-host instead.";
|
|
|
|
// fall through
|
|
|
|
case SHRPX_OPTID_BACKEND_CONNECTIONS_PER_HOST: {
|
2014-08-27 16:36:36 +02:00
|
|
|
int n;
|
2014-08-16 14:29:20 +02:00
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (parse_uint(&n, opt, optarg) != 0) {
|
2014-08-27 16:36:36 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-01-13 15:23:35 +01:00
|
|
|
if (n == 0) {
|
|
|
|
LOG(ERROR) << opt << ": specify an integer strictly more than 0";
|
2014-08-16 14:29:20 +02:00
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-06-03 12:13:02 +02:00
|
|
|
config->conn.downstream->connections_per_host = n;
|
2014-08-16 14:29:20 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_BACKEND_HTTP1_CONNECTIONS_PER_FRONTEND:
|
2016-02-28 09:11:12 +01:00
|
|
|
LOG(WARN) << opt << ": deprecated. Use "
|
|
|
|
<< SHRPX_OPT_BACKEND_CONNECTIONS_PER_FRONTEND << " instead.";
|
|
|
|
// fall through
|
|
|
|
case SHRPX_OPTID_BACKEND_CONNECTIONS_PER_FRONTEND:
|
2016-06-03 12:13:02 +02:00
|
|
|
return parse_uint(&config->conn.downstream->connections_per_frontend, opt,
|
2016-06-02 16:59:59 +02:00
|
|
|
optarg);
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_LISTENER_DISABLE_TIMEOUT:
|
2016-06-02 16:59:59 +02:00
|
|
|
return parse_duration(&config->conn.listener.timeout.sleep, opt, optarg);
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_TLS_TICKET_KEY_FILE:
|
2016-06-02 16:59:59 +02:00
|
|
|
config->tls.ticket.files.push_back(optarg.str());
|
2015-01-07 17:26:30 +01:00
|
|
|
return 0;
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_RLIMIT_NOFILE: {
|
2015-01-10 15:17:48 +01:00
|
|
|
int n;
|
|
|
|
|
|
|
|
if (parse_uint(&n, opt, optarg) != 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n < 0) {
|
|
|
|
LOG(ERROR) << opt << ": specify the integer more than or equal to 0";
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-06-02 16:59:59 +02:00
|
|
|
config->rlimit_nofile = n;
|
2015-01-10 15:17:48 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_BACKEND_REQUEST_BUFFER:
|
|
|
|
case SHRPX_OPTID_BACKEND_RESPONSE_BUFFER: {
|
2015-01-13 15:20:06 +01:00
|
|
|
size_t n;
|
|
|
|
if (parse_uint_with_unit(&n, opt, optarg) != 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n == 0) {
|
|
|
|
LOG(ERROR) << opt << ": specify an integer strictly more than 0";
|
2015-01-13 15:23:35 +01:00
|
|
|
|
2015-01-13 15:20:06 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-07-14 16:21:38 +02:00
|
|
|
if (optid == SHRPX_OPTID_BACKEND_REQUEST_BUFFER) {
|
2016-06-03 12:13:02 +02:00
|
|
|
config->conn.downstream->request_buffer_size = n;
|
2015-01-13 15:30:28 +01:00
|
|
|
} else {
|
2016-06-03 12:13:02 +02:00
|
|
|
config->conn.downstream->response_buffer_size = n;
|
2015-01-13 15:30:28 +01:00
|
|
|
}
|
2015-01-13 15:20:06 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_NO_SERVER_PUSH:
|
2016-06-02 16:59:59 +02:00
|
|
|
config->http2.no_server_push = util::strieq_l("yes", optarg);
|
2015-02-08 08:19:12 +01:00
|
|
|
|
|
|
|
return 0;
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_BACKEND_HTTP2_CONNECTIONS_PER_WORKER:
|
2016-02-27 15:44:35 +01:00
|
|
|
LOG(WARN) << opt << ": deprecated.";
|
|
|
|
return 0;
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_FETCH_OCSP_RESPONSE_FILE:
|
2016-06-02 16:59:59 +02:00
|
|
|
config->tls.ocsp.fetch_ocsp_response_file =
|
2016-03-24 13:05:02 +01:00
|
|
|
ImmutableString{std::begin(optarg), std::end(optarg)};
|
2015-03-30 16:20:40 +02:00
|
|
|
|
|
|
|
return 0;
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_OCSP_UPDATE_INTERVAL:
|
2016-06-02 16:59:59 +02:00
|
|
|
return parse_duration(&config->tls.ocsp.update_interval, opt, optarg);
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_NO_OCSP:
|
2016-06-02 16:59:59 +02:00
|
|
|
config->tls.ocsp.disabled = util::strieq_l("yes", optarg);
|
2015-03-30 16:20:40 +02:00
|
|
|
|
|
|
|
return 0;
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_HEADER_FIELD_BUFFER:
|
2016-02-06 09:22:23 +01:00
|
|
|
LOG(WARN) << opt
|
|
|
|
<< ": deprecated. Use request-header-field-buffer instead.";
|
|
|
|
// fall through
|
|
|
|
case SHRPX_OPTID_REQUEST_HEADER_FIELD_BUFFER:
|
2016-06-02 16:59:59 +02:00
|
|
|
return parse_uint_with_unit(&config->http.request_header_field_buffer, opt,
|
|
|
|
optarg);
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_MAX_HEADER_FIELDS:
|
2016-02-06 09:22:23 +01:00
|
|
|
LOG(WARN) << opt << ": deprecated. Use max-request-header-fields instead.";
|
|
|
|
// fall through
|
|
|
|
case SHRPX_OPTID_MAX_REQUEST_HEADER_FIELDS:
|
2016-06-02 16:59:59 +02:00
|
|
|
return parse_uint(&config->http.max_request_header_fields, opt, optarg);
|
2016-02-06 04:25:34 +01:00
|
|
|
case SHRPX_OPTID_RESPONSE_HEADER_FIELD_BUFFER:
|
2016-06-02 16:59:59 +02:00
|
|
|
return parse_uint_with_unit(&config->http.response_header_field_buffer, opt,
|
|
|
|
optarg);
|
2016-02-06 04:25:34 +01:00
|
|
|
case SHRPX_OPTID_MAX_RESPONSE_HEADER_FIELDS:
|
2016-06-02 16:59:59 +02:00
|
|
|
return parse_uint(&config->http.max_response_header_fields, opt, optarg);
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_INCLUDE: {
|
2015-07-13 14:44:06 +02:00
|
|
|
if (included_set.count(optarg)) {
|
|
|
|
LOG(ERROR) << opt << ": " << optarg << " has already been included";
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-07-19 13:50:14 +02:00
|
|
|
included_set.insert(optarg);
|
2016-07-31 08:57:41 +02:00
|
|
|
auto rv = load_config(config, optarg.c_str(), included_set);
|
2015-07-13 14:44:06 +02:00
|
|
|
included_set.erase(optarg);
|
|
|
|
|
|
|
|
if (rv != 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2015-07-12 16:18:36 +02:00
|
|
|
}
|
2015-07-28 16:49:37 +02:00
|
|
|
case SHRPX_OPTID_TLS_TICKET_KEY_CIPHER:
|
2016-03-24 13:05:02 +01:00
|
|
|
if (util::strieq_l("aes-128-cbc", optarg)) {
|
2016-06-02 16:59:59 +02:00
|
|
|
config->tls.ticket.cipher = EVP_aes_128_cbc();
|
2016-03-24 13:05:02 +01:00
|
|
|
} else if (util::strieq_l("aes-256-cbc", optarg)) {
|
2016-06-02 16:59:59 +02:00
|
|
|
config->tls.ticket.cipher = EVP_aes_256_cbc();
|
2015-07-17 18:49:20 +02:00
|
|
|
} else {
|
|
|
|
LOG(ERROR) << opt
|
|
|
|
<< ": unsupported cipher for ticket encryption: " << optarg;
|
|
|
|
return -1;
|
|
|
|
}
|
2016-06-02 16:59:59 +02:00
|
|
|
config->tls.ticket.cipher_given = true;
|
2015-07-17 18:49:20 +02:00
|
|
|
|
2015-07-23 16:54:56 +02:00
|
|
|
return 0;
|
|
|
|
case SHRPX_OPTID_HOST_REWRITE:
|
2016-06-02 16:59:59 +02:00
|
|
|
config->http.no_host_rewrite = !util::strieq_l("yes", optarg);
|
2015-07-23 16:54:56 +02:00
|
|
|
|
2015-07-17 18:49:20 +02:00
|
|
|
return 0;
|
2016-03-23 16:22:13 +01:00
|
|
|
case SHRPX_OPTID_TLS_SESSION_CACHE_MEMCACHED:
|
|
|
|
case SHRPX_OPTID_TLS_TICKET_KEY_MEMCACHED: {
|
2016-03-24 13:05:02 +01:00
|
|
|
auto addr_end = std::find(std::begin(optarg), std::end(optarg), ';');
|
|
|
|
auto src_params = StringRef{addr_end, std::end(optarg)};
|
2016-03-23 16:22:13 +01:00
|
|
|
|
|
|
|
MemcachedConnectionParams params{};
|
|
|
|
if (parse_memcached_connection_params(params, src_params, StringRef{opt}) !=
|
|
|
|
0) {
|
2015-07-25 15:22:17 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-03-23 16:35:13 +01:00
|
|
|
if (split_host_port(host, sizeof(host), &port,
|
2016-03-24 13:05:02 +01:00
|
|
|
StringRef{std::begin(optarg), addr_end}, opt) == -1) {
|
2015-07-27 17:54:44 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-03-23 16:22:13 +01:00
|
|
|
switch (optid) {
|
|
|
|
case SHRPX_OPTID_TLS_SESSION_CACHE_MEMCACHED: {
|
2016-06-02 16:59:59 +02:00
|
|
|
auto &memcachedconf = config->tls.session_cache.memcached;
|
2016-08-26 15:40:59 +02:00
|
|
|
memcachedconf.host = ImmutableString{host};
|
2016-03-23 16:22:13 +01:00
|
|
|
memcachedconf.port = port;
|
|
|
|
memcachedconf.tls = params.tls;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SHRPX_OPTID_TLS_TICKET_KEY_MEMCACHED: {
|
2016-06-02 16:59:59 +02:00
|
|
|
auto &memcachedconf = config->tls.ticket.memcached;
|
2016-08-26 15:40:59 +02:00
|
|
|
memcachedconf.host = ImmutableString{host};
|
2016-03-23 16:22:13 +01:00
|
|
|
memcachedconf.port = port;
|
|
|
|
memcachedconf.tls = params.tls;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
2015-07-27 17:54:44 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2015-07-27 18:02:33 +02:00
|
|
|
case SHRPX_OPTID_TLS_TICKET_KEY_MEMCACHED_INTERVAL:
|
2016-06-02 16:59:59 +02:00
|
|
|
return parse_duration(&config->tls.ticket.memcached.interval, opt, optarg);
|
2015-07-27 18:17:29 +02:00
|
|
|
case SHRPX_OPTID_TLS_TICKET_KEY_MEMCACHED_MAX_RETRY: {
|
|
|
|
int n;
|
|
|
|
if (parse_uint(&n, opt, optarg) != 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n > 30) {
|
|
|
|
LOG(ERROR) << opt << ": must be smaller than or equal to 30";
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-06-02 16:59:59 +02:00
|
|
|
config->tls.ticket.memcached.max_retry = n;
|
2015-07-27 18:17:29 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
case SHRPX_OPTID_TLS_TICKET_KEY_MEMCACHED_MAX_FAIL:
|
2016-06-02 16:59:59 +02:00
|
|
|
return parse_uint(&config->tls.ticket.memcached.max_fail, opt, optarg);
|
2015-10-21 12:22:46 +02:00
|
|
|
case SHRPX_OPTID_TLS_DYN_REC_WARMUP_THRESHOLD: {
|
|
|
|
size_t n;
|
|
|
|
if (parse_uint_with_unit(&n, opt, optarg) != 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-06-02 16:59:59 +02:00
|
|
|
config->tls.dyn_rec.warmup_threshold = n;
|
2015-10-21 12:22:46 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SHRPX_OPTID_TLS_DYN_REC_IDLE_TIMEOUT:
|
2016-06-02 16:59:59 +02:00
|
|
|
return parse_duration(&config->tls.dyn_rec.idle_timeout, opt, optarg);
|
2015-10-21 12:22:46 +02:00
|
|
|
|
2015-10-05 17:10:42 +02:00
|
|
|
case SHRPX_OPTID_MRUBY_FILE:
|
2015-09-06 09:59:57 +02:00
|
|
|
#ifdef HAVE_MRUBY
|
2016-06-02 16:59:59 +02:00
|
|
|
config->mruby_file = ImmutableString{std::begin(optarg), std::end(optarg)};
|
2015-09-06 09:59:57 +02:00
|
|
|
#else // !HAVE_MRUBY
|
|
|
|
LOG(WARN) << opt
|
|
|
|
<< ": ignored because mruby support is disabled at build time.";
|
|
|
|
#endif // !HAVE_MRUBY
|
2015-09-06 11:39:32 +02:00
|
|
|
return 0;
|
|
|
|
case SHRPX_OPTID_ACCEPT_PROXY_PROTOCOL:
|
2016-06-02 16:59:59 +02:00
|
|
|
config->conn.upstream.accept_proxy_protocol = util::strieq_l("yes", optarg);
|
2015-09-06 11:39:32 +02:00
|
|
|
|
2015-09-01 17:19:32 +02:00
|
|
|
return 0;
|
2016-01-18 09:00:20 +01:00
|
|
|
case SHRPX_OPTID_ADD_FORWARDED: {
|
2016-06-02 16:59:59 +02:00
|
|
|
auto &fwdconf = config->http.forwarded;
|
2016-01-18 09:00:20 +01:00
|
|
|
fwdconf.params = FORWARDED_NONE;
|
2016-03-24 13:05:02 +01:00
|
|
|
for (const auto ¶m : util::split_str(optarg, ',')) {
|
|
|
|
if (util::strieq_l("by", param)) {
|
2016-01-18 09:00:20 +01:00
|
|
|
fwdconf.params |= FORWARDED_BY;
|
2016-01-15 15:04:58 +01:00
|
|
|
continue;
|
|
|
|
}
|
2016-03-24 13:05:02 +01:00
|
|
|
if (util::strieq_l("for", param)) {
|
2016-01-18 09:00:20 +01:00
|
|
|
fwdconf.params |= FORWARDED_FOR;
|
2016-01-15 15:04:58 +01:00
|
|
|
continue;
|
|
|
|
}
|
2016-03-24 13:05:02 +01:00
|
|
|
if (util::strieq_l("host", param)) {
|
2016-01-18 09:00:20 +01:00
|
|
|
fwdconf.params |= FORWARDED_HOST;
|
2016-01-15 15:04:58 +01:00
|
|
|
continue;
|
|
|
|
}
|
2016-03-24 13:05:02 +01:00
|
|
|
if (util::strieq_l("proto", param)) {
|
2016-01-18 09:00:20 +01:00
|
|
|
fwdconf.params |= FORWARDED_PROTO;
|
2016-01-15 15:04:58 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG(ERROR) << opt << ": unknown parameter " << optarg;
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2016-01-18 09:00:20 +01:00
|
|
|
}
|
2016-01-15 15:04:58 +01:00
|
|
|
case SHRPX_OPTID_STRIP_INCOMING_FORWARDED:
|
2016-06-02 16:59:59 +02:00
|
|
|
config->http.forwarded.strip_incoming = util::strieq_l("yes", optarg);
|
2016-01-15 15:04:58 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
case SHRPX_OPTID_FORWARDED_BY:
|
|
|
|
case SHRPX_OPTID_FORWARDED_FOR: {
|
|
|
|
auto type = parse_forwarded_node_type(optarg);
|
|
|
|
|
2016-01-21 13:05:07 +01:00
|
|
|
if (type == -1 ||
|
|
|
|
(optid == SHRPX_OPTID_FORWARDED_FOR && optarg[0] == '_')) {
|
2016-01-15 15:18:27 +01:00
|
|
|
LOG(ERROR) << opt << ": unknown node type or illegal obfuscated string "
|
|
|
|
<< optarg;
|
2016-01-15 15:04:58 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-06-02 16:59:59 +02:00
|
|
|
auto &fwdconf = config->http.forwarded;
|
2016-01-18 09:00:20 +01:00
|
|
|
|
2016-01-15 15:04:58 +01:00
|
|
|
switch (optid) {
|
|
|
|
case SHRPX_OPTID_FORWARDED_BY:
|
2016-01-18 09:00:20 +01:00
|
|
|
fwdconf.by_node_type = static_cast<shrpx_forwarded_node_type>(type);
|
2016-01-15 15:18:27 +01:00
|
|
|
if (optarg[0] == '_') {
|
2016-03-24 13:05:02 +01:00
|
|
|
fwdconf.by_obfuscated = optarg.str();
|
2016-01-16 03:53:18 +01:00
|
|
|
} else {
|
2016-01-18 09:00:20 +01:00
|
|
|
fwdconf.by_obfuscated = "";
|
2016-01-15 15:18:27 +01:00
|
|
|
}
|
2016-01-15 15:04:58 +01:00
|
|
|
break;
|
|
|
|
case SHRPX_OPTID_FORWARDED_FOR:
|
2016-01-18 09:00:20 +01:00
|
|
|
fwdconf.for_node_type = static_cast<shrpx_forwarded_node_type>(type);
|
2016-01-15 15:04:58 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2016-02-06 09:05:14 +01:00
|
|
|
case SHRPX_OPTID_NO_HTTP2_CIPHER_BLACK_LIST:
|
2016-06-02 16:59:59 +02:00
|
|
|
config->tls.no_http2_cipher_black_list = util::strieq_l("yes", optarg);
|
2016-02-06 09:05:14 +01:00
|
|
|
|
2016-02-06 11:50:21 +01:00
|
|
|
return 0;
|
|
|
|
case SHRPX_OPTID_BACKEND_HTTP1_TLS:
|
2016-02-28 13:35:26 +01:00
|
|
|
case SHRPX_OPTID_BACKEND_TLS:
|
2016-03-23 14:56:18 +01:00
|
|
|
LOG(WARN) << opt << ": deprecated. Use tls keyword in "
|
|
|
|
<< SHRPX_OPT_BACKEND << " instead.";
|
2016-02-06 09:05:14 +01:00
|
|
|
return 0;
|
2016-02-11 14:56:45 +01:00
|
|
|
case SHRPX_OPTID_TLS_SESSION_CACHE_MEMCACHED_TLS:
|
2016-03-23 16:22:13 +01:00
|
|
|
LOG(WARN) << opt << ": deprecated. Use tls keyword in "
|
|
|
|
<< SHRPX_OPT_TLS_SESSION_CACHE_MEMCACHED;
|
2016-02-12 16:20:38 +01:00
|
|
|
return 0;
|
|
|
|
case SHRPX_OPTID_TLS_SESSION_CACHE_MEMCACHED_CERT_FILE:
|
2016-06-02 16:59:59 +02:00
|
|
|
config->tls.session_cache.memcached.cert_file =
|
2016-03-24 13:05:02 +01:00
|
|
|
ImmutableString{std::begin(optarg), std::end(optarg)};
|
2016-02-12 16:20:38 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
case SHRPX_OPTID_TLS_SESSION_CACHE_MEMCACHED_PRIVATE_KEY_FILE:
|
2016-06-02 16:59:59 +02:00
|
|
|
config->tls.session_cache.memcached.private_key_file =
|
2016-03-24 13:05:02 +01:00
|
|
|
ImmutableString{std::begin(optarg), std::end(optarg)};
|
2016-02-12 16:20:38 +01:00
|
|
|
|
2016-02-13 10:17:11 +01:00
|
|
|
return 0;
|
|
|
|
case SHRPX_OPTID_TLS_TICKET_KEY_MEMCACHED_TLS:
|
2016-03-23 16:22:13 +01:00
|
|
|
LOG(WARN) << opt << ": deprecated. Use tls keyword in "
|
|
|
|
<< SHRPX_OPT_TLS_TICKET_KEY_MEMCACHED;
|
2016-02-13 10:17:11 +01:00
|
|
|
return 0;
|
|
|
|
case SHRPX_OPTID_TLS_TICKET_KEY_MEMCACHED_CERT_FILE:
|
2016-06-02 16:59:59 +02:00
|
|
|
config->tls.ticket.memcached.cert_file =
|
2016-03-24 13:05:02 +01:00
|
|
|
ImmutableString{std::begin(optarg), std::end(optarg)};
|
2016-02-13 10:17:11 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
case SHRPX_OPTID_TLS_TICKET_KEY_MEMCACHED_PRIVATE_KEY_FILE:
|
2016-06-02 16:59:59 +02:00
|
|
|
config->tls.ticket.memcached.private_key_file =
|
2016-03-24 13:05:02 +01:00
|
|
|
ImmutableString{std::begin(optarg), std::end(optarg)};
|
2016-02-13 10:17:11 +01:00
|
|
|
|
2016-02-11 14:56:45 +01:00
|
|
|
return 0;
|
2016-02-13 10:45:23 +01:00
|
|
|
case SHRPX_OPTID_TLS_TICKET_KEY_MEMCACHED_ADDRESS_FAMILY:
|
2016-06-02 16:59:59 +02:00
|
|
|
return parse_address_family(&config->tls.ticket.memcached.family, opt,
|
2016-02-13 10:45:23 +01:00
|
|
|
optarg);
|
|
|
|
case SHRPX_OPTID_TLS_SESSION_CACHE_MEMCACHED_ADDRESS_FAMILY:
|
2016-06-02 16:59:59 +02:00
|
|
|
return parse_address_family(&config->tls.session_cache.memcached.family,
|
|
|
|
opt, optarg);
|
2016-02-13 11:09:39 +01:00
|
|
|
case SHRPX_OPTID_BACKEND_ADDRESS_FAMILY:
|
2016-06-03 12:13:02 +02:00
|
|
|
return parse_address_family(&config->conn.downstream->family, opt, optarg);
|
2016-02-27 16:06:40 +01:00
|
|
|
case SHRPX_OPTID_FRONTEND_HTTP2_MAX_CONCURRENT_STREAMS:
|
2016-06-02 16:59:59 +02:00
|
|
|
return parse_uint(&config->http2.upstream.max_concurrent_streams, opt,
|
2016-02-27 16:06:40 +01:00
|
|
|
optarg);
|
|
|
|
case SHRPX_OPTID_BACKEND_HTTP2_MAX_CONCURRENT_STREAMS:
|
2016-06-02 16:59:59 +02:00
|
|
|
return parse_uint(&config->http2.downstream.max_concurrent_streams, opt,
|
|
|
|
optarg);
|
2016-03-19 15:41:21 +01:00
|
|
|
case SHRPX_OPTID_ERROR_PAGE:
|
2016-06-02 16:59:59 +02:00
|
|
|
return parse_error_page(config->http.error_pages, opt, optarg);
|
2016-05-06 16:10:09 +02:00
|
|
|
case SHRPX_OPTID_NO_KQUEUE:
|
|
|
|
if ((ev_supported_backends() & EVBACKEND_KQUEUE) == 0) {
|
|
|
|
LOG(WARN) << opt << ": kqueue is not supported on this platform";
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-06-02 16:59:59 +02:00
|
|
|
config->ev_loop_flags = ev_recommended_backends() & ~EVBACKEND_KQUEUE;
|
2016-05-06 16:10:09 +02:00
|
|
|
|
|
|
|
return 0;
|
2016-05-21 07:13:57 +02:00
|
|
|
case SHRPX_OPTID_FRONTEND_HTTP2_SETTINGS_TIMEOUT:
|
2016-06-02 16:59:59 +02:00
|
|
|
return parse_duration(&config->http2.upstream.timeout.settings, opt,
|
2016-05-21 07:13:57 +02:00
|
|
|
optarg);
|
|
|
|
case SHRPX_OPTID_BACKEND_HTTP2_SETTINGS_TIMEOUT:
|
2016-06-02 16:59:59 +02:00
|
|
|
return parse_duration(&config->http2.downstream.timeout.settings, opt,
|
2016-05-21 07:13:57 +02:00
|
|
|
optarg);
|
2016-06-04 10:24:54 +02:00
|
|
|
case SHRPX_OPTID_API_MAX_REQUEST_BODY:
|
|
|
|
return parse_uint_with_unit(&config->api.max_request_body, opt, optarg);
|
2016-06-21 17:13:43 +02:00
|
|
|
case SHRPX_OPTID_BACKEND_MAX_BACKOFF:
|
|
|
|
return parse_duration(&config->conn.downstream->timeout.max_backoff, opt,
|
|
|
|
optarg);
|
2016-08-26 15:28:09 +02:00
|
|
|
case SHRPX_OPTID_SERVER_NAME:
|
|
|
|
config->http.server_name =
|
|
|
|
ImmutableString{std::begin(optarg), std::end(optarg)};
|
|
|
|
|
2016-08-31 16:47:15 +02:00
|
|
|
return 0;
|
|
|
|
case SHRPX_OPTID_NO_SERVER_REWRITE:
|
|
|
|
config->http.no_server_rewrite = util::strieq_l("yes", optarg);
|
|
|
|
|
2016-09-08 15:49:36 +02:00
|
|
|
return 0;
|
|
|
|
case SHRPX_OPTID_FRONTEND_HTTP2_OPTIMIZE_WRITE_BUFFER_SIZE:
|
|
|
|
config->http2.upstream.optimize_write_buffer_size =
|
|
|
|
util::strieq_l("yes", optarg);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
case SHRPX_OPTID_FRONTEND_HTTP2_OPTIMIZE_WINDOW_SIZE:
|
|
|
|
config->http2.upstream.optimize_window_size = util::strieq_l("yes", optarg);
|
|
|
|
|
2016-09-09 14:05:37 +02:00
|
|
|
return 0;
|
|
|
|
case SHRPX_OPTID_FRONTEND_HTTP2_WINDOW_SIZE:
|
|
|
|
if (parse_uint_with_unit(&config->http2.upstream.window_size, opt,
|
|
|
|
optarg) != 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
case SHRPX_OPTID_FRONTEND_HTTP2_CONNECTION_WINDOW_SIZE:
|
|
|
|
if (parse_uint_with_unit(&config->http2.upstream.connection_window_size,
|
|
|
|
opt, optarg) != 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
case SHRPX_OPTID_BACKEND_HTTP2_WINDOW_SIZE:
|
|
|
|
if (parse_uint_with_unit(&config->http2.downstream.window_size, opt,
|
|
|
|
optarg) != 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
case SHRPX_OPTID_BACKEND_HTTP2_CONNECTION_WINDOW_SIZE:
|
|
|
|
if (parse_uint_with_unit(&config->http2.downstream.connection_window_size,
|
|
|
|
opt, optarg) != 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-08-26 15:28:09 +02:00
|
|
|
return 0;
|
2016-09-12 15:53:02 +02:00
|
|
|
case SHRPX_OPTID_FRONTEND_HTTP2_ENCODER_DYNAMIC_TABLE_SIZE:
|
|
|
|
if (parse_uint_with_unit(&config->http2.upstream.encoder_dynamic_table_size,
|
|
|
|
opt, optarg) != 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
nghttp2_option_set_max_deflate_dynamic_table_size(
|
|
|
|
config->http2.upstream.option,
|
|
|
|
config->http2.upstream.encoder_dynamic_table_size);
|
|
|
|
nghttp2_option_set_max_deflate_dynamic_table_size(
|
|
|
|
config->http2.upstream.alt_mode_option,
|
|
|
|
config->http2.upstream.encoder_dynamic_table_size);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
case SHRPX_OPTID_FRONTEND_HTTP2_DECODER_DYNAMIC_TABLE_SIZE:
|
|
|
|
return parse_uint_with_unit(
|
|
|
|
&config->http2.upstream.decoder_dynamic_table_size, opt, optarg);
|
|
|
|
case SHRPX_OPTID_BACKEND_HTTP2_ENCODER_DYNAMIC_TABLE_SIZE:
|
|
|
|
if (parse_uint_with_unit(
|
|
|
|
&config->http2.downstream.encoder_dynamic_table_size, opt,
|
|
|
|
optarg) != 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
nghttp2_option_set_max_deflate_dynamic_table_size(
|
|
|
|
config->http2.downstream.option,
|
|
|
|
config->http2.downstream.encoder_dynamic_table_size);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
case SHRPX_OPTID_BACKEND_HTTP2_DECODER_DYNAMIC_TABLE_SIZE:
|
|
|
|
return parse_uint_with_unit(
|
|
|
|
&config->http2.downstream.decoder_dynamic_table_size, opt, optarg);
|
2015-07-14 16:21:38 +02:00
|
|
|
case SHRPX_OPTID_CONF:
|
2014-11-08 02:51:56 +01:00
|
|
|
LOG(WARN) << "conf: ignored";
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
2012-08-01 17:06:41 +02:00
|
|
|
}
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
LOG(ERROR) << "Unknown option: " << opt;
|
|
|
|
|
|
|
|
return -1;
|
2012-08-01 17:06:41 +02:00
|
|
|
}
|
|
|
|
|
2016-07-31 08:57:41 +02:00
|
|
|
int load_config(Config *config, const char *filename,
|
|
|
|
std::set<StringRef> &include_set) {
|
2012-08-01 17:06:41 +02:00
|
|
|
std::ifstream in(filename, std::ios::binary);
|
2014-11-27 15:39:04 +01:00
|
|
|
if (!in) {
|
2012-08-01 17:26:24 +02:00
|
|
|
LOG(ERROR) << "Could not open config file " << filename;
|
2012-08-01 17:06:41 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
std::string line;
|
|
|
|
int linenum = 0;
|
2014-11-27 15:39:04 +01:00
|
|
|
while (std::getline(in, line)) {
|
2012-08-01 17:06:41 +02:00
|
|
|
++linenum;
|
2014-11-27 15:39:04 +01:00
|
|
|
if (line.empty() || line[0] == '#') {
|
2012-08-01 17:06:41 +02:00
|
|
|
continue;
|
|
|
|
}
|
2016-03-24 13:05:02 +01:00
|
|
|
auto eq = std::find(std::begin(line), std::end(line), '=');
|
|
|
|
if (eq == std::end(line)) {
|
2015-07-12 16:18:36 +02:00
|
|
|
LOG(ERROR) << "Bad configuration format in " << filename << " at line "
|
|
|
|
<< linenum;
|
2012-08-01 17:06:41 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2016-03-24 13:05:02 +01:00
|
|
|
*eq = '\0';
|
|
|
|
|
2016-07-31 08:57:41 +02:00
|
|
|
if (parse_config(config, StringRef{std::begin(line), eq},
|
2016-03-24 13:05:02 +01:00
|
|
|
StringRef{eq + 1, std::end(line)}, include_set) != 0) {
|
2012-08-01 17:06:41 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-03-24 13:05:02 +01:00
|
|
|
StringRef str_syslog_facility(int facility) {
|
2014-11-27 15:39:04 +01:00
|
|
|
switch (facility) {
|
|
|
|
case (LOG_AUTH):
|
2016-03-24 13:05:02 +01:00
|
|
|
return StringRef::from_lit("auth");
|
2015-06-27 10:51:07 +02:00
|
|
|
#ifdef LOG_AUTHPRIV
|
2014-11-27 15:39:04 +01:00
|
|
|
case (LOG_AUTHPRIV):
|
2016-03-24 13:05:02 +01:00
|
|
|
return StringRef::from_lit("authpriv");
|
2015-06-27 10:51:07 +02:00
|
|
|
#endif // LOG_AUTHPRIV
|
2014-11-27 15:39:04 +01:00
|
|
|
case (LOG_CRON):
|
2016-03-24 13:05:02 +01:00
|
|
|
return StringRef::from_lit("cron");
|
2014-11-27 15:39:04 +01:00
|
|
|
case (LOG_DAEMON):
|
2016-03-24 13:05:02 +01:00
|
|
|
return StringRef::from_lit("daemon");
|
2015-06-27 10:51:07 +02:00
|
|
|
#ifdef LOG_FTP
|
2014-11-27 15:39:04 +01:00
|
|
|
case (LOG_FTP):
|
2016-03-24 13:05:02 +01:00
|
|
|
return StringRef::from_lit("ftp");
|
2015-06-27 10:51:07 +02:00
|
|
|
#endif // LOG_FTP
|
2014-11-27 15:39:04 +01:00
|
|
|
case (LOG_KERN):
|
2016-03-24 13:05:02 +01:00
|
|
|
return StringRef::from_lit("kern");
|
2014-11-27 15:39:04 +01:00
|
|
|
case (LOG_LOCAL0):
|
2016-03-24 13:05:02 +01:00
|
|
|
return StringRef::from_lit("local0");
|
2014-11-27 15:39:04 +01:00
|
|
|
case (LOG_LOCAL1):
|
2016-03-24 13:05:02 +01:00
|
|
|
return StringRef::from_lit("local1");
|
2014-11-27 15:39:04 +01:00
|
|
|
case (LOG_LOCAL2):
|
2016-03-24 13:05:02 +01:00
|
|
|
return StringRef::from_lit("local2");
|
2014-11-27 15:39:04 +01:00
|
|
|
case (LOG_LOCAL3):
|
2016-03-24 13:05:02 +01:00
|
|
|
return StringRef::from_lit("local3");
|
2014-11-27 15:39:04 +01:00
|
|
|
case (LOG_LOCAL4):
|
2016-03-24 13:05:02 +01:00
|
|
|
return StringRef::from_lit("local4");
|
2014-11-27 15:39:04 +01:00
|
|
|
case (LOG_LOCAL5):
|
2016-03-24 13:05:02 +01:00
|
|
|
return StringRef::from_lit("local5");
|
2014-11-27 15:39:04 +01:00
|
|
|
case (LOG_LOCAL6):
|
2016-03-24 13:05:02 +01:00
|
|
|
return StringRef::from_lit("local6");
|
2014-11-27 15:39:04 +01:00
|
|
|
case (LOG_LOCAL7):
|
2016-03-24 13:05:02 +01:00
|
|
|
return StringRef::from_lit("local7");
|
2014-11-27 15:39:04 +01:00
|
|
|
case (LOG_LPR):
|
2016-03-24 13:05:02 +01:00
|
|
|
return StringRef::from_lit("lpr");
|
2014-11-27 15:39:04 +01:00
|
|
|
case (LOG_MAIL):
|
2016-03-24 13:05:02 +01:00
|
|
|
return StringRef::from_lit("mail");
|
2014-11-27 15:39:04 +01:00
|
|
|
case (LOG_SYSLOG):
|
2016-03-24 13:05:02 +01:00
|
|
|
return StringRef::from_lit("syslog");
|
2014-11-27 15:39:04 +01:00
|
|
|
case (LOG_USER):
|
2016-03-24 13:05:02 +01:00
|
|
|
return StringRef::from_lit("user");
|
2014-11-27 15:39:04 +01:00
|
|
|
case (LOG_UUCP):
|
2016-03-24 13:05:02 +01:00
|
|
|
return StringRef::from_lit("uucp");
|
2012-08-01 18:20:18 +02:00
|
|
|
default:
|
2016-03-24 13:05:02 +01:00
|
|
|
return StringRef::from_lit("(unknown)");
|
2012-08-01 18:20:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-24 13:05:02 +01:00
|
|
|
int int_syslog_facility(const StringRef &strfacility) {
|
|
|
|
if (util::strieq_l("auth", strfacility)) {
|
2012-08-01 18:20:18 +02:00
|
|
|
return LOG_AUTH;
|
2014-06-08 16:03:26 +02:00
|
|
|
}
|
|
|
|
|
2015-06-27 10:51:07 +02:00
|
|
|
#ifdef LOG_AUTHPRIV
|
2016-03-24 13:05:02 +01:00
|
|
|
if (util::strieq_l("authpriv", strfacility)) {
|
2012-08-01 18:20:18 +02:00
|
|
|
return LOG_AUTHPRIV;
|
2014-06-08 16:03:26 +02:00
|
|
|
}
|
2015-06-27 10:51:07 +02:00
|
|
|
#endif // LOG_AUTHPRIV
|
2014-06-08 16:03:26 +02:00
|
|
|
|
2016-03-24 13:05:02 +01:00
|
|
|
if (util::strieq_l("cron", strfacility)) {
|
2012-08-01 18:20:18 +02:00
|
|
|
return LOG_CRON;
|
2014-06-08 16:03:26 +02:00
|
|
|
}
|
|
|
|
|
2016-03-24 13:05:02 +01:00
|
|
|
if (util::strieq_l("daemon", strfacility)) {
|
2012-08-01 18:20:18 +02:00
|
|
|
return LOG_DAEMON;
|
2014-06-08 16:03:26 +02:00
|
|
|
}
|
|
|
|
|
2015-06-27 10:51:07 +02:00
|
|
|
#ifdef LOG_FTP
|
2016-03-24 13:05:02 +01:00
|
|
|
if (util::strieq_l("ftp", strfacility)) {
|
2012-08-01 18:20:18 +02:00
|
|
|
return LOG_FTP;
|
2014-06-08 16:03:26 +02:00
|
|
|
}
|
2015-06-27 10:51:07 +02:00
|
|
|
#endif // LOG_FTP
|
2014-06-08 16:03:26 +02:00
|
|
|
|
2016-03-24 13:05:02 +01:00
|
|
|
if (util::strieq_l("kern", strfacility)) {
|
2012-08-01 18:20:18 +02:00
|
|
|
return LOG_KERN;
|
2014-06-08 16:03:26 +02:00
|
|
|
}
|
|
|
|
|
2016-03-24 13:05:02 +01:00
|
|
|
if (util::strieq_l("local0", strfacility)) {
|
2012-08-01 18:20:18 +02:00
|
|
|
return LOG_LOCAL0;
|
2014-06-08 16:03:26 +02:00
|
|
|
}
|
|
|
|
|
2016-03-24 13:05:02 +01:00
|
|
|
if (util::strieq_l("local1", strfacility)) {
|
2012-08-01 18:20:18 +02:00
|
|
|
return LOG_LOCAL1;
|
2014-06-08 16:03:26 +02:00
|
|
|
}
|
|
|
|
|
2016-03-24 13:05:02 +01:00
|
|
|
if (util::strieq_l("local2", strfacility)) {
|
2012-08-01 18:20:18 +02:00
|
|
|
return LOG_LOCAL2;
|
2014-06-08 16:03:26 +02:00
|
|
|
}
|
|
|
|
|
2016-03-24 13:05:02 +01:00
|
|
|
if (util::strieq_l("local3", strfacility)) {
|
2012-08-01 18:20:18 +02:00
|
|
|
return LOG_LOCAL3;
|
2014-06-08 16:03:26 +02:00
|
|
|
}
|
|
|
|
|
2016-03-24 13:05:02 +01:00
|
|
|
if (util::strieq_l("local4", strfacility)) {
|
2012-08-01 18:20:18 +02:00
|
|
|
return LOG_LOCAL4;
|
2014-06-08 16:03:26 +02:00
|
|
|
}
|
|
|
|
|
2016-03-24 13:05:02 +01:00
|
|
|
if (util::strieq_l("local5", strfacility)) {
|
2012-08-01 18:20:18 +02:00
|
|
|
return LOG_LOCAL5;
|
2014-06-08 16:03:26 +02:00
|
|
|
}
|
|
|
|
|
2016-03-24 13:05:02 +01:00
|
|
|
if (util::strieq_l("local6", strfacility)) {
|
2012-08-01 18:20:18 +02:00
|
|
|
return LOG_LOCAL6;
|
2014-06-08 16:03:26 +02:00
|
|
|
}
|
|
|
|
|
2016-03-24 13:05:02 +01:00
|
|
|
if (util::strieq_l("local7", strfacility)) {
|
2012-08-01 18:20:18 +02:00
|
|
|
return LOG_LOCAL7;
|
2014-06-08 16:03:26 +02:00
|
|
|
}
|
|
|
|
|
2016-03-24 13:05:02 +01:00
|
|
|
if (util::strieq_l("lpr", strfacility)) {
|
2012-08-01 18:20:18 +02:00
|
|
|
return LOG_LPR;
|
2014-06-08 16:03:26 +02:00
|
|
|
}
|
|
|
|
|
2016-03-24 13:05:02 +01:00
|
|
|
if (util::strieq_l("mail", strfacility)) {
|
2012-08-01 18:20:18 +02:00
|
|
|
return LOG_MAIL;
|
2014-06-08 16:03:26 +02:00
|
|
|
}
|
|
|
|
|
2016-03-24 13:05:02 +01:00
|
|
|
if (util::strieq_l("news", strfacility)) {
|
2012-08-01 18:20:18 +02:00
|
|
|
return LOG_NEWS;
|
2014-06-08 16:03:26 +02:00
|
|
|
}
|
|
|
|
|
2016-03-24 13:05:02 +01:00
|
|
|
if (util::strieq_l("syslog", strfacility)) {
|
2012-08-01 18:20:18 +02:00
|
|
|
return LOG_SYSLOG;
|
2014-06-08 16:03:26 +02:00
|
|
|
}
|
|
|
|
|
2016-03-24 13:05:02 +01:00
|
|
|
if (util::strieq_l("user", strfacility)) {
|
2012-08-01 18:20:18 +02:00
|
|
|
return LOG_USER;
|
2014-06-08 16:03:26 +02:00
|
|
|
}
|
|
|
|
|
2016-03-24 13:05:02 +01:00
|
|
|
if (util::strieq_l("uucp", strfacility)) {
|
2012-08-01 18:20:18 +02:00
|
|
|
return LOG_UUCP;
|
|
|
|
}
|
2014-06-08 16:03:26 +02:00
|
|
|
|
|
|
|
return -1;
|
2012-08-01 18:20:18 +02:00
|
|
|
}
|
|
|
|
|
2016-02-28 13:35:26 +01:00
|
|
|
StringRef strproto(shrpx_proto proto) {
|
|
|
|
switch (proto) {
|
|
|
|
case PROTO_NONE:
|
|
|
|
return StringRef::from_lit("none");
|
|
|
|
case PROTO_HTTP1:
|
|
|
|
return StringRef::from_lit("http/1.1");
|
|
|
|
case PROTO_HTTP2:
|
|
|
|
return StringRef::from_lit("h2");
|
|
|
|
case PROTO_MEMCACHED:
|
|
|
|
return StringRef::from_lit("memcached");
|
|
|
|
}
|
2016-02-28 17:16:45 +01:00
|
|
|
|
|
|
|
// gcc needs this.
|
|
|
|
assert(0);
|
2016-02-28 13:35:26 +01:00
|
|
|
}
|
|
|
|
|
2016-07-06 15:31:28 +02:00
|
|
|
namespace {
|
|
|
|
// Consistent hashing method described in
|
|
|
|
// https://github.com/RJ/ketama. Generate 160 32-bit hashes per |s|,
|
|
|
|
// which is usually backend address. The each hash is associated to
|
|
|
|
// index of backend address. When all hashes for every backend
|
|
|
|
// address are calculated, sort it in ascending order of hash. To
|
|
|
|
// choose the index, compute 32-bit hash based on client IP address,
|
|
|
|
// and do lower bound search in the array. The returned index is the
|
|
|
|
// backend to use.
|
|
|
|
int compute_affinity_hash(std::vector<AffinityHash> &res, size_t idx,
|
|
|
|
const StringRef &s) {
|
|
|
|
int rv;
|
|
|
|
std::array<uint8_t, 32> buf;
|
|
|
|
|
|
|
|
for (auto i = 0; i < 20; ++i) {
|
|
|
|
auto t = s.str();
|
|
|
|
t += i;
|
|
|
|
|
|
|
|
rv = util::sha256(buf.data(), StringRef{t});
|
|
|
|
if (rv != 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < 8; ++i) {
|
2016-07-06 16:58:53 +02:00
|
|
|
auto h = (static_cast<uint32_t>(buf[4 * i]) << 24) |
|
|
|
|
(static_cast<uint32_t>(buf[4 * i + 1]) << 16) |
|
|
|
|
(static_cast<uint32_t>(buf[4 * i + 2]) << 8) |
|
|
|
|
static_cast<uint32_t>(buf[4 * i + 3]);
|
2016-07-06 15:31:28 +02:00
|
|
|
|
|
|
|
res.emplace_back(idx, h);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2016-06-02 18:20:49 +02:00
|
|
|
// Configures the following member in |config|:
|
|
|
|
// conn.downstream_router, conn.downstream.addr_groups,
|
|
|
|
// conn.downstream.addr_group_catch_all.
|
2016-06-02 17:22:55 +02:00
|
|
|
int configure_downstream_group(Config *config, bool http2_proxy,
|
|
|
|
bool numeric_addr_only,
|
|
|
|
const TLSConfig &tlsconf) {
|
2016-07-06 15:31:28 +02:00
|
|
|
int rv;
|
|
|
|
|
2016-06-03 12:13:02 +02:00
|
|
|
auto &downstreamconf = *config->conn.downstream;
|
2016-06-02 17:22:55 +02:00
|
|
|
auto &addr_groups = downstreamconf.addr_groups;
|
2016-06-11 11:21:37 +02:00
|
|
|
auto &routerconf = downstreamconf.router;
|
|
|
|
auto &router = routerconf.router;
|
2016-06-02 17:22:55 +02:00
|
|
|
|
|
|
|
if (addr_groups.empty()) {
|
|
|
|
DownstreamAddrConfig addr{};
|
|
|
|
addr.host = ImmutableString::from_lit(DEFAULT_DOWNSTREAM_HOST);
|
|
|
|
addr.port = DEFAULT_DOWNSTREAM_PORT;
|
|
|
|
addr.proto = PROTO_HTTP1;
|
|
|
|
|
|
|
|
DownstreamAddrGroupConfig g(StringRef::from_lit("/"));
|
|
|
|
g.addrs.push_back(std::move(addr));
|
2016-06-03 12:13:02 +02:00
|
|
|
router.add_route(StringRef{g.pattern}, addr_groups.size());
|
2016-06-02 17:22:55 +02:00
|
|
|
addr_groups.push_back(std::move(g));
|
|
|
|
} else if (http2_proxy) {
|
|
|
|
// We don't support host mapping in these cases. Move all
|
|
|
|
// non-catch-all patterns to catch-all pattern.
|
|
|
|
DownstreamAddrGroupConfig catch_all(StringRef::from_lit("/"));
|
|
|
|
for (auto &g : addr_groups) {
|
|
|
|
std::move(std::begin(g.addrs), std::end(g.addrs),
|
|
|
|
std::back_inserter(catch_all.addrs));
|
|
|
|
}
|
|
|
|
std::vector<DownstreamAddrGroupConfig>().swap(addr_groups);
|
|
|
|
// maybe not necessary?
|
2016-06-11 11:21:37 +02:00
|
|
|
routerconf = RouterConfig{};
|
2016-06-03 12:13:02 +02:00
|
|
|
router.add_route(StringRef{catch_all.pattern}, addr_groups.size());
|
2016-06-02 17:22:55 +02:00
|
|
|
addr_groups.push_back(std::move(catch_all));
|
|
|
|
}
|
|
|
|
|
|
|
|
// backward compatibility: override all SNI fields with the option
|
|
|
|
// value --backend-tls-sni-field
|
|
|
|
if (!tlsconf.backend_sni_name.empty()) {
|
|
|
|
auto &sni = tlsconf.backend_sni_name;
|
|
|
|
for (auto &addr_group : addr_groups) {
|
|
|
|
for (auto &addr : addr_group.addrs) {
|
2016-08-26 15:52:08 +02:00
|
|
|
addr.sni = ImmutableString{sni};
|
2016-06-02 17:22:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (LOG_ENABLED(INFO)) {
|
|
|
|
LOG(INFO) << "Resolving backend address";
|
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t catch_all_group = -1;
|
|
|
|
for (size_t i = 0; i < addr_groups.size(); ++i) {
|
|
|
|
auto &g = addr_groups[i];
|
|
|
|
if (g.pattern == StringRef::from_lit("/")) {
|
|
|
|
catch_all_group = i;
|
|
|
|
}
|
|
|
|
if (LOG_ENABLED(INFO)) {
|
|
|
|
LOG(INFO) << "Host-path pattern: group " << i << ": '" << g.pattern
|
|
|
|
<< "'";
|
|
|
|
for (auto &addr : g.addrs) {
|
|
|
|
LOG(INFO) << "group " << i << " -> " << addr.host.c_str()
|
|
|
|
<< (addr.host_unix ? "" : ":" + util::utos(addr.port))
|
|
|
|
<< ", proto=" << strproto(addr.proto)
|
|
|
|
<< (addr.tls ? ", tls" : "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (catch_all_group == -1) {
|
|
|
|
LOG(FATAL) << "backend: No catch-all backend address is configured";
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
downstreamconf.addr_group_catch_all = catch_all_group;
|
|
|
|
|
|
|
|
if (LOG_ENABLED(INFO)) {
|
|
|
|
LOG(INFO) << "Catch-all pattern is group " << catch_all_group;
|
|
|
|
}
|
|
|
|
|
2016-06-16 16:06:17 +02:00
|
|
|
auto resolve_flags = numeric_addr_only ? AI_NUMERICHOST | AI_NUMERICSERV : 0;
|
2016-06-02 17:22:55 +02:00
|
|
|
|
|
|
|
for (auto &g : addr_groups) {
|
|
|
|
for (auto &addr : g.addrs) {
|
|
|
|
|
|
|
|
if (addr.host_unix) {
|
|
|
|
// for AF_UNIX socket, we use "localhost" as host for backend
|
|
|
|
// hostport. This is used as Host header field to backend and
|
|
|
|
// not going to be passed to any syscalls.
|
2016-08-26 15:40:59 +02:00
|
|
|
addr.hostport = ImmutableString::from_lit("localhost");
|
2016-06-02 17:22:55 +02:00
|
|
|
|
|
|
|
auto path = addr.host.c_str();
|
|
|
|
auto pathlen = addr.host.size();
|
|
|
|
|
|
|
|
if (pathlen + 1 > sizeof(addr.addr.su.un.sun_path)) {
|
|
|
|
LOG(FATAL) << "UNIX domain socket path " << path << " is too long > "
|
|
|
|
<< sizeof(addr.addr.su.un.sun_path);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (LOG_ENABLED(INFO)) {
|
|
|
|
LOG(INFO) << "Use UNIX domain socket path " << path
|
|
|
|
<< " for backend connection";
|
|
|
|
}
|
|
|
|
|
|
|
|
addr.addr.su.un.sun_family = AF_UNIX;
|
|
|
|
// copy path including terminal NULL
|
|
|
|
std::copy_n(path, pathlen + 1, addr.addr.su.un.sun_path);
|
|
|
|
addr.addr.len = sizeof(addr.addr.su.un);
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
addr.hostport = ImmutableString(
|
|
|
|
util::make_http_hostport(StringRef(addr.host), addr.port));
|
|
|
|
|
|
|
|
auto hostport = util::make_hostport(StringRef{addr.host}, addr.port);
|
|
|
|
|
|
|
|
if (resolve_hostname(&addr.addr, addr.host.c_str(), addr.port,
|
|
|
|
downstreamconf.family, resolve_flags) == -1) {
|
|
|
|
LOG(FATAL) << "Resolving backend address failed: " << hostport;
|
|
|
|
return -1;
|
|
|
|
}
|
2016-06-16 15:12:42 +02:00
|
|
|
|
|
|
|
if (LOG_ENABLED(INFO)) {
|
|
|
|
LOG(INFO) << "Resolved backend address: " << hostport << " -> "
|
2016-06-02 17:22:55 +02:00
|
|
|
<< util::to_numeric_addr(&addr.addr);
|
2016-06-16 15:12:42 +02:00
|
|
|
}
|
2016-06-02 17:22:55 +02:00
|
|
|
}
|
2016-07-06 15:31:28 +02:00
|
|
|
|
|
|
|
if (g.affinity == AFFINITY_IP) {
|
|
|
|
size_t idx = 0;
|
|
|
|
for (auto &addr : g.addrs) {
|
|
|
|
auto p = reinterpret_cast<uint8_t *>(&addr.addr.su);
|
|
|
|
rv = compute_affinity_hash(g.affinity_hash, idx,
|
|
|
|
StringRef{p, addr.addr.len});
|
|
|
|
if (rv != 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
++idx;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::sort(std::begin(g.affinity_hash), std::end(g.affinity_hash),
|
|
|
|
[](const AffinityHash &lhs, const AffinityHash &rhs) {
|
|
|
|
return lhs.hash < rhs.hash;
|
|
|
|
});
|
|
|
|
}
|
2016-06-02 17:22:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int resolve_hostname(Address *addr, const char *hostname, uint16_t port,
|
|
|
|
int family, int additional_flags) {
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
auto service = util::utos(port);
|
|
|
|
|
|
|
|
addrinfo hints{};
|
|
|
|
hints.ai_family = family;
|
|
|
|
hints.ai_socktype = SOCK_STREAM;
|
|
|
|
hints.ai_flags |= additional_flags;
|
|
|
|
#ifdef AI_ADDRCONFIG
|
|
|
|
hints.ai_flags |= AI_ADDRCONFIG;
|
|
|
|
#endif // AI_ADDRCONFIG
|
|
|
|
addrinfo *res;
|
|
|
|
|
|
|
|
rv = getaddrinfo(hostname, service.c_str(), &hints, &res);
|
|
|
|
if (rv != 0) {
|
|
|
|
LOG(FATAL) << "Unable to resolve address for " << hostname << ": "
|
|
|
|
<< gai_strerror(rv);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto res_d = defer(freeaddrinfo, res);
|
|
|
|
|
|
|
|
char host[NI_MAXHOST];
|
|
|
|
rv = getnameinfo(res->ai_addr, res->ai_addrlen, host, sizeof(host), nullptr,
|
|
|
|
0, NI_NUMERICHOST);
|
|
|
|
if (rv != 0) {
|
|
|
|
LOG(FATAL) << "Address resolution for " << hostname
|
|
|
|
<< " failed: " << gai_strerror(rv);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (LOG_ENABLED(INFO)) {
|
|
|
|
LOG(INFO) << "Address resolution for " << hostname
|
|
|
|
<< " succeeded: " << host;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(&addr->su, res->ai_addr, res->ai_addrlen);
|
|
|
|
addr->len = res->ai_addrlen;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-06-04 16:48:31 +02:00
|
|
|
} // namespace shrpx
|