-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added support for new masks #2637
Conversation
Need to add an example in comments in |
dbms/src/Interpreters/Users.cpp
Outdated
else | ||
{ | ||
Poco::Net::IPAddress ip_mask(str_mask); | ||
prefix_bits_ = ip_mask.prefixLength(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The goal or your task is to add support for "mask with holes" like
255.255.0.255
or
ffff:ffff:ff00:0:ffff:ffff::
(as in example 2a02:6b8:c00::660:0:0/ffff:ffff:ff00:0:ffff:ffff::
)
it's not just a prefix.
dbms/src/Interpreters/Users.cpp
Outdated
@@ -87,12 +98,10 @@ class IPAddressPattern : public IAddressPattern | |||
prefix_bits = 128; | |||
} | |||
|
|||
void construct(const Poco::Net::IPAddress & mask_address_, UInt8 prefix_bits_) | |||
void construct(const Poco::Net::IPAddress & mask_address_, UInt8 & prefix_bits_) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why need this change?
dbms/src/Interpreters/Users.cpp
Outdated
@@ -48,7 +48,8 @@ static Poco::Net::IPAddress toIPv6(const Poco::Net::IPAddress addr) | |||
} | |||
|
|||
|
|||
/// IP-address or subnet mask. Example: 213.180.204.3 or 10.0.0.1/8 or 2a02:6b8::3 or 2a02:6b8::3/64. | |||
/// IP-address or subnet mask. Example: 213.180.204.3 or 10.0.0.1/8 or | |||
/// 2a02:6b8::3 or 2a02:6b8::3/64. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to add an example of new mask in comment.
dbms/src/Interpreters/Users.cpp
Outdated
/// Number of bits in mask. | ||
UInt8 prefix_bits; | ||
/// Mask of net (ip form). Always transformed to IPv6. | ||
Poco::Net::IPAddress ip_mask; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Misleading name. Probably, it's better to use subnet_mask or netmask.
dbms/src/Interpreters/Users.cpp
Outdated
|| (lhs[prefix_bytes] >> (8 - remaining_bits)) == (rhs[prefix_bytes] >> (8 - remaining_bits))); | ||
bool isDigit(const std::string & str) | ||
{ | ||
return str.find_first_not_of("0123456789") == std::string::npos; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to use isNumericASCII
from <Common/StringUtils/StringUtils.h>
. Like std::all_of(str.begin(), str.end(), isNumericASCII)
or may be to find another already implemented function.
dbms/src/Interpreters/Users.cpp
Outdated
subnet_mask = Poco::Net::IPAddress(prefix_bits, Poco::Net::IPAddress::IPv6); | ||
} | ||
|
||
static bool prefixBitsEquals(const Poco::Net::IPAddress & ip, const Poco::Net::IPAddress & address, const Poco::Net::IPAddress & mask) | ||
static bool prefixBitsEquals( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Misleading function name.
dbms/src/Interpreters/Users.cpp
Outdated
@@ -117,7 +119,7 @@ class IPAddressPattern : public IAddressPattern | |||
if (mask.family() == Poco::Net::IPAddress::IPv6) | |||
return mask; | |||
|
|||
return Poco::Net::IPAddress("ffff:ffff:ffff:ffff:" + mask.toString()); | |||
return Poco::Net::IPAddress("FFFF:FFFF:FFFF:FFFF:FFFF:FFFF::") | toIPv6(mask); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can construct it in the same way as
Poco::Net::IPAddress(prefix_bits, Poco::Net::IPAddress::IPv6);
dbms/src/Interpreters/Users.cpp
Outdated
return 0 == memcmp(lhs, rhs, prefix_bytes) | ||
&& (remaining_bits % 8 == 0 | ||
|| (lhs[prefix_bytes] >> (8 - remaining_bits)) == (rhs[prefix_bytes] >> (8 - remaining_bits))); | ||
bool isDigits(const std::string & str) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static
dbms/src/Interpreters/Users.cpp
Outdated
|
||
Poco::Net::IPAddress netmaskToIPv6(Poco::Net::IPAddress mask) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static
I hereby agree to the terms of the CLA available at: https://yandex.ru/legal/cla/?lang=en