mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-25 17:12:03 +00:00
Merge pull request #24319 from azat/ipv6-fix
Fix IPv6 addresses resolving
This commit is contained in:
commit
13398ad233
@ -87,9 +87,20 @@ static DNSResolver::IPAddresses resolveIPAddressImpl(const std::string & host)
|
||||
{
|
||||
Poco::Net::IPAddress ip;
|
||||
|
||||
/// NOTE: Poco::Net::DNS::resolveOne(host) doesn't work for IP addresses like 127.0.0.2
|
||||
/// NOTE:
|
||||
/// - Poco::Net::DNS::resolveOne(host) doesn't work for IP addresses like 127.0.0.2
|
||||
/// - Poco::Net::IPAddress::tryParse() expect hex string for IPv6 (w/o brackets)
|
||||
if (host.starts_with('['))
|
||||
{
|
||||
assert(host.ends_with(']'));
|
||||
if (Poco::Net::IPAddress::tryParse(host.substr(1, host.size() - 2), ip))
|
||||
return DNSResolver::IPAddresses(1, ip);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Poco::Net::IPAddress::tryParse(host, ip))
|
||||
return DNSResolver::IPAddresses(1, ip);
|
||||
}
|
||||
|
||||
/// Family: AF_UNSPEC
|
||||
/// AI_ALL is required for checking if client is allowed to connect from an address
|
||||
|
@ -28,15 +28,27 @@ std::pair<std::string, UInt16> parseAddress(const std::string & str, UInt16 defa
|
||||
throw Exception("Illegal address passed to function parseAddress: "
|
||||
"the address begins with opening square bracket, but no closing square bracket found", ErrorCodes::BAD_ARGUMENTS);
|
||||
|
||||
port = find_first_symbols<':'>(closing_square_bracket + 1, end);
|
||||
port = closing_square_bracket + 1;
|
||||
}
|
||||
else
|
||||
port = find_first_symbols<':'>(begin, end);
|
||||
|
||||
if (port != end)
|
||||
{
|
||||
UInt16 port_number = parse<UInt16>(port + 1);
|
||||
return { std::string(begin, port), port_number };
|
||||
if (*port != ':')
|
||||
throw Exception(ErrorCodes::BAD_ARGUMENTS,
|
||||
"Illegal port prefix passed to function parseAddress: {}", port);
|
||||
|
||||
++port;
|
||||
|
||||
UInt16 port_number;
|
||||
ReadBufferFromMemory port_buf(port, end - port);
|
||||
if (!tryReadText<UInt16>(port_number, port_buf) || !port_buf.eof())
|
||||
{
|
||||
throw Exception(ErrorCodes::BAD_ARGUMENTS,
|
||||
"Illegal port passed to function parseAddress: {}", port);
|
||||
}
|
||||
return { std::string(begin, port - 1), port_number };
|
||||
}
|
||||
else if (default_port)
|
||||
{
|
||||
|
12
tests/queries/0_stateless/01880_remote_ipv6.sql
Normal file
12
tests/queries/0_stateless/01880_remote_ipv6.sql
Normal file
@ -0,0 +1,12 @@
|
||||
SET connections_with_failover_max_tries=0;
|
||||
|
||||
SELECT * FROM remote('[::1]', system.one) FORMAT Null;
|
||||
SELECT * FROM remote('[::1]:9000', system.one) FORMAT Null;
|
||||
|
||||
SELECT * FROM remote('[::1', system.one) FORMAT Null; -- { serverError 36 }
|
||||
SELECT * FROM remote('::1]', system.one) FORMAT Null; -- { serverError 36 }
|
||||
SELECT * FROM remote('::1', system.one) FORMAT Null; -- { serverError 36 }
|
||||
|
||||
SELECT * FROM remote('[::1][::1]', system.one) FORMAT Null; -- { serverError 36 }
|
||||
SELECT * FROM remote('[::1][::1', system.one) FORMAT Null; -- { serverError 36 }
|
||||
SELECT * FROM remote('[::1]::1]', system.one) FORMAT Null; -- { serverError 36 }
|
@ -236,3 +236,4 @@
|
||||
01801_s3_distributed
|
||||
01833_test_collation_alvarotuso
|
||||
01850_dist_INSERT_preserve_error
|
||||
01880_remote_ipv6
|
||||
|
Loading…
Reference in New Issue
Block a user