Skip to content

Commit

Permalink
Merge pull request #2076 from nghttp2/h2load-add-sni
Browse files Browse the repository at this point in the history
h2load: Add --sni option
  • Loading branch information
tatsuhiro-t committed Feb 18, 2024
2 parents d2ca281 + ed0b786 commit 5327912
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/h2load.cc
Original file line number Diff line number Diff line change
Expand Up @@ -582,8 +582,12 @@ int Client::make_socket(addrinfo *addr) {
}
}

if (ssl && !util::numeric_host(config.host.c_str())) {
SSL_set_tlsext_host_name(ssl, config.host.c_str());
if (ssl) {
if (!config.sni.empty()) {
SSL_set_tlsext_host_name(ssl, config.sni.c_str());
} else if (!util::numeric_host(config.host.c_str())) {
SSL_set_tlsext_host_name(ssl, config.host.c_str());
}
}

if (config.is_quic()) {
Expand Down Expand Up @@ -2301,6 +2305,9 @@ void print_help(std::ostream &out) {
--max-udp-payload-size=<SIZE>
Specify the maximum outgoing UDP datagram payload size.
--ktls Enable ktls.
--sni=<DNSNAME>
Send <DNSNAME> in TLS SNI, overriding the host name
specified in URI.
-v, --verbose
Output debug information.
--version Display version information and exit.
Expand Down Expand Up @@ -2363,6 +2370,7 @@ int main(int argc, char **argv) {
{"max-udp-payload-size", required_argument, &flag, 17},
{"ktls", no_argument, &flag, 18},
{"alpn-list", required_argument, &flag, 19},
{"sni", required_argument, &flag, 20},
{nullptr, 0, nullptr, 0}};
int option_index = 0;
auto c = getopt_long(argc, argv,
Expand Down Expand Up @@ -2699,6 +2707,10 @@ int main(int argc, char **argv) {
// alpn-list option
config.alpn_list = util::parse_config_str_list(StringRef{optarg});
break;
case 20:
// --sni
config.sni = optarg;
break;
}
break;
default:
Expand Down
3 changes: 3 additions & 0 deletions src/h2load.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ struct Config {
size_t max_udp_payload_size;
// Enable ktls.
bool ktls;
// sni is the value sent in TLS SNI, overriding DNS name of the
// remote host.
std::string sni;

Config();
~Config();
Expand Down

0 comments on commit 5327912

Please sign in to comment.