Merge pull request #24319 from azat/ipv6-fix

Fix IPv6 addresses resolving
This commit is contained in:
alexey-milovidov 2021-05-22 15:23:18 +03:00 committed by GitHub
commit 13398ad233
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 42 additions and 6 deletions

View File

@ -87,9 +87,20 @@ static DNSResolver::IPAddresses resolveIPAddressImpl(const std::string & host)
{ {
Poco::Net::IPAddress ip; Poco::Net::IPAddress ip;
/// NOTE: Poco::Net::DNS::resolveOne(host) doesn't work for IP addresses like 127.0.0.2 /// NOTE:
if (Poco::Net::IPAddress::tryParse(host, ip)) /// - Poco::Net::DNS::resolveOne(host) doesn't work for IP addresses like 127.0.0.2
return DNSResolver::IPAddresses(1, ip); /// - 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 /// Family: AF_UNSPEC
/// AI_ALL is required for checking if client is allowed to connect from an address /// AI_ALL is required for checking if client is allowed to connect from an address

View File

@ -28,15 +28,27 @@ std::pair<std::string, UInt16> parseAddress(const std::string & str, UInt16 defa
throw Exception("Illegal address passed to function parseAddress: " throw Exception("Illegal address passed to function parseAddress: "
"the address begins with opening square bracket, but no closing square bracket found", ErrorCodes::BAD_ARGUMENTS); "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 else
port = find_first_symbols<':'>(begin, end); port = find_first_symbols<':'>(begin, end);
if (port != end) if (port != end)
{ {
UInt16 port_number = parse<UInt16>(port + 1); if (*port != ':')
return { std::string(begin, port), port_number }; 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) else if (default_port)
{ {

View 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 }

View File

@ -236,3 +236,4 @@
01801_s3_distributed 01801_s3_distributed
01833_test_collation_alvarotuso 01833_test_collation_alvarotuso
01850_dist_INSERT_preserve_error 01850_dist_INSERT_preserve_error
01880_remote_ipv6