Skip to content
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

Merged
merged 10 commits into from
Jul 14, 2018
Merged

added support for new masks #2637

merged 10 commits into from
Jul 14, 2018

Conversation

VadimPlh
Copy link
Contributor

I hereby agree to the terms of the CLA available at: https://yandex.ru/legal/cla/?lang=en

@alexey-milovidov
Copy link
Member

Need to add an example in comments in users.xml file.

else
{
Poco::Net::IPAddress ip_mask(str_mask);
prefix_bits_ = ip_mask.prefixLength();
Copy link
Member

@alexey-milovidov alexey-milovidov Jul 13, 2018

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.

@@ -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_)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why need this change?

@@ -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.
Copy link
Member

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.

/// Number of bits in mask.
UInt8 prefix_bits;
/// Mask of net (ip form). Always transformed to IPv6.
Poco::Net::IPAddress ip_mask;
Copy link
Member

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.

|| (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;
Copy link
Member

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.

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(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Misleading function name.

@@ -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);
Copy link
Member

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);

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

static


Poco::Net::IPAddress netmaskToIPv6(Poco::Net::IPAddress mask)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

static

@alexey-milovidov alexey-milovidov merged commit 5bb8f7e into ClickHouse:master Jul 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants