Commit dc657464 authored by wtc@chromium.org's avatar wtc@chromium.org

Treat IPv4-mapped IPv6 addresses as IPv4 addresses.

Rename the Net.QuicSession.PublicResetAddressMismatch histogram to
Net.QuicSession.PublicResetAddressMismatch2.

R=jar@chromium.org,rch@chromium.org
BUG=none

Review URL: https://codereview.chromium.org/294823002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@271759 0039d316-1c4b-4281-b951-d872f2087c98
parent 838d1474
...@@ -14,9 +14,17 @@ int GetAddressMismatch(const IPEndPoint& first_address, ...@@ -14,9 +14,17 @@ int GetAddressMismatch(const IPEndPoint& first_address,
if (first_address.address().empty() || second_address.address().empty()) { if (first_address.address().empty() || second_address.address().empty()) {
return -1; return -1;
} }
IPAddressNumber first_ip_address = first_address.address();
if (IsIPv4Mapped(first_ip_address)) {
first_ip_address = ConvertIPv4MappedToIPv4(first_ip_address);
}
IPAddressNumber second_ip_address = second_address.address();
if (IsIPv4Mapped(second_ip_address)) {
second_ip_address = ConvertIPv4MappedToIPv4(second_ip_address);
}
int sample; int sample;
if (first_address.address() != second_address.address()) { if (first_ip_address != second_ip_address) {
sample = QUIC_ADDRESS_MISMATCH_BASE; sample = QUIC_ADDRESS_MISMATCH_BASE;
} else if (first_address.port() != second_address.port()) { } else if (first_address.port() != second_address.port()) {
sample = QUIC_PORT_MISMATCH_BASE; sample = QUIC_PORT_MISMATCH_BASE;
...@@ -29,8 +37,8 @@ int GetAddressMismatch(const IPEndPoint& first_address, ...@@ -29,8 +37,8 @@ int GetAddressMismatch(const IPEndPoint& first_address,
// V6_V6: add 1 // V6_V6: add 1
// V4_V6: add 2 // V4_V6: add 2
// V6_V4: add 3 // V6_V4: add 3
bool first_ipv4 = (first_address.address().size() == kIPv4AddressSize); bool first_ipv4 = (first_ip_address.size() == kIPv4AddressSize);
bool second_ipv4 = (second_address.address().size() == kIPv4AddressSize); bool second_ipv4 = (second_ip_address.size() == kIPv4AddressSize);
if (first_ipv4 != second_ipv4) { if (first_ipv4 != second_ipv4) {
CHECK_EQ(sample, QUIC_ADDRESS_MISMATCH_BASE); CHECK_EQ(sample, QUIC_ADDRESS_MISMATCH_BASE);
sample += 2; sample += 2;
......
...@@ -17,12 +17,17 @@ TEST(QuicAddressMismatchTest, GetAddressMismatch) { ...@@ -17,12 +17,17 @@ TEST(QuicAddressMismatchTest, GetAddressMismatch) {
IPAddressNumber ip4_2; IPAddressNumber ip4_2;
IPAddressNumber ip6_1; IPAddressNumber ip6_1;
IPAddressNumber ip6_2; IPAddressNumber ip6_2;
IPAddressNumber ip4_mapped_1;
IPAddressNumber ip4_mapped_2;
ASSERT_TRUE(ParseIPLiteralToNumber("1.2.3.4", &ip4_1)); ASSERT_TRUE(ParseIPLiteralToNumber("1.2.3.4", &ip4_1));
ASSERT_TRUE(ParseIPLiteralToNumber("5.6.7.8", &ip4_2)); ASSERT_TRUE(ParseIPLiteralToNumber("5.6.7.8", &ip4_2));
ASSERT_TRUE(ParseIPLiteralToNumber("1234::1", &ip6_1)); ASSERT_TRUE(ParseIPLiteralToNumber("1234::1", &ip6_1));
ASSERT_TRUE(ParseIPLiteralToNumber("1234::2", &ip6_2)); ASSERT_TRUE(ParseIPLiteralToNumber("1234::2", &ip6_2));
ip4_mapped_1 = ConvertIPv4NumberToIPv6Number(ip4_1);
ip4_mapped_2 = ConvertIPv4NumberToIPv6Number(ip4_2);
ASSERT_NE(ip4_1, ip4_2); ASSERT_NE(ip4_1, ip4_2);
ASSERT_NE(ip6_1, ip6_2); ASSERT_NE(ip6_1, ip6_2);
ASSERT_NE(ip4_mapped_1, ip4_mapped_2);
EXPECT_EQ(-1, GetAddressMismatch(IPEndPoint(), IPEndPoint())); EXPECT_EQ(-1, GetAddressMismatch(IPEndPoint(), IPEndPoint()));
EXPECT_EQ(-1, GetAddressMismatch(IPEndPoint(), IPEndPoint(ip4_1, 443))); EXPECT_EQ(-1, GetAddressMismatch(IPEndPoint(), IPEndPoint(ip4_1, 443)));
...@@ -31,6 +36,12 @@ TEST(QuicAddressMismatchTest, GetAddressMismatch) { ...@@ -31,6 +36,12 @@ TEST(QuicAddressMismatchTest, GetAddressMismatch) {
EXPECT_EQ(QUIC_ADDRESS_AND_PORT_MATCH_V4_V4, EXPECT_EQ(QUIC_ADDRESS_AND_PORT_MATCH_V4_V4,
GetAddressMismatch(IPEndPoint(ip4_1, 443), GetAddressMismatch(IPEndPoint(ip4_1, 443),
IPEndPoint(ip4_1, 443))); IPEndPoint(ip4_1, 443)));
EXPECT_EQ(QUIC_ADDRESS_AND_PORT_MATCH_V4_V4,
GetAddressMismatch(IPEndPoint(ip4_1, 443),
IPEndPoint(ip4_mapped_1, 443)));
EXPECT_EQ(QUIC_ADDRESS_AND_PORT_MATCH_V4_V4,
GetAddressMismatch(IPEndPoint(ip4_mapped_1, 443),
IPEndPoint(ip4_mapped_1, 443)));
EXPECT_EQ(QUIC_ADDRESS_AND_PORT_MATCH_V6_V6, EXPECT_EQ(QUIC_ADDRESS_AND_PORT_MATCH_V6_V6,
GetAddressMismatch(IPEndPoint(ip6_1, 443), GetAddressMismatch(IPEndPoint(ip6_1, 443),
IPEndPoint(ip6_1, 443))); IPEndPoint(ip6_1, 443)));
...@@ -38,6 +49,12 @@ TEST(QuicAddressMismatchTest, GetAddressMismatch) { ...@@ -38,6 +49,12 @@ TEST(QuicAddressMismatchTest, GetAddressMismatch) {
EXPECT_EQ(QUIC_PORT_MISMATCH_V4_V4, EXPECT_EQ(QUIC_PORT_MISMATCH_V4_V4,
GetAddressMismatch(IPEndPoint(ip4_1, 80), GetAddressMismatch(IPEndPoint(ip4_1, 80),
IPEndPoint(ip4_1, 443))); IPEndPoint(ip4_1, 443)));
EXPECT_EQ(QUIC_PORT_MISMATCH_V4_V4,
GetAddressMismatch(IPEndPoint(ip4_1, 80),
IPEndPoint(ip4_mapped_1, 443)));
EXPECT_EQ(QUIC_PORT_MISMATCH_V4_V4,
GetAddressMismatch(IPEndPoint(ip4_mapped_1, 80),
IPEndPoint(ip4_mapped_1, 443)));
EXPECT_EQ(QUIC_PORT_MISMATCH_V6_V6, EXPECT_EQ(QUIC_PORT_MISMATCH_V6_V6,
GetAddressMismatch(IPEndPoint(ip6_1, 80), GetAddressMismatch(IPEndPoint(ip6_1, 80),
IPEndPoint(ip6_1, 443))); IPEndPoint(ip6_1, 443)));
...@@ -45,9 +62,21 @@ TEST(QuicAddressMismatchTest, GetAddressMismatch) { ...@@ -45,9 +62,21 @@ TEST(QuicAddressMismatchTest, GetAddressMismatch) {
EXPECT_EQ(QUIC_ADDRESS_MISMATCH_V4_V4, EXPECT_EQ(QUIC_ADDRESS_MISMATCH_V4_V4,
GetAddressMismatch(IPEndPoint(ip4_1, 443), GetAddressMismatch(IPEndPoint(ip4_1, 443),
IPEndPoint(ip4_2, 443))); IPEndPoint(ip4_2, 443)));
EXPECT_EQ(QUIC_ADDRESS_MISMATCH_V4_V4,
GetAddressMismatch(IPEndPoint(ip4_1, 443),
IPEndPoint(ip4_mapped_2, 443)));
EXPECT_EQ(QUIC_ADDRESS_MISMATCH_V4_V4,
GetAddressMismatch(IPEndPoint(ip4_mapped_1, 443),
IPEndPoint(ip4_mapped_2, 443)));
EXPECT_EQ(QUIC_ADDRESS_MISMATCH_V4_V4, EXPECT_EQ(QUIC_ADDRESS_MISMATCH_V4_V4,
GetAddressMismatch(IPEndPoint(ip4_1, 80), GetAddressMismatch(IPEndPoint(ip4_1, 80),
IPEndPoint(ip4_2, 443))); IPEndPoint(ip4_2, 443)));
EXPECT_EQ(QUIC_ADDRESS_MISMATCH_V4_V4,
GetAddressMismatch(IPEndPoint(ip4_1, 80),
IPEndPoint(ip4_mapped_2, 443)));
EXPECT_EQ(QUIC_ADDRESS_MISMATCH_V4_V4,
GetAddressMismatch(IPEndPoint(ip4_mapped_1, 80),
IPEndPoint(ip4_mapped_2, 443)));
EXPECT_EQ(QUIC_ADDRESS_MISMATCH_V6_V6, EXPECT_EQ(QUIC_ADDRESS_MISMATCH_V6_V6,
GetAddressMismatch(IPEndPoint(ip6_1, 443), GetAddressMismatch(IPEndPoint(ip6_1, 443),
IPEndPoint(ip6_2, 443))); IPEndPoint(ip6_2, 443)));
...@@ -57,15 +86,27 @@ TEST(QuicAddressMismatchTest, GetAddressMismatch) { ...@@ -57,15 +86,27 @@ TEST(QuicAddressMismatchTest, GetAddressMismatch) {
EXPECT_EQ(QUIC_ADDRESS_MISMATCH_V4_V6, EXPECT_EQ(QUIC_ADDRESS_MISMATCH_V4_V6,
GetAddressMismatch(IPEndPoint(ip4_1, 443), GetAddressMismatch(IPEndPoint(ip4_1, 443),
IPEndPoint(ip6_1, 443))); IPEndPoint(ip6_1, 443)));
EXPECT_EQ(QUIC_ADDRESS_MISMATCH_V4_V6,
GetAddressMismatch(IPEndPoint(ip4_mapped_1, 443),
IPEndPoint(ip6_1, 443)));
EXPECT_EQ(QUIC_ADDRESS_MISMATCH_V4_V6, EXPECT_EQ(QUIC_ADDRESS_MISMATCH_V4_V6,
GetAddressMismatch(IPEndPoint(ip4_1, 80), GetAddressMismatch(IPEndPoint(ip4_1, 80),
IPEndPoint(ip6_1, 443))); IPEndPoint(ip6_1, 443)));
EXPECT_EQ(QUIC_ADDRESS_MISMATCH_V4_V6,
GetAddressMismatch(IPEndPoint(ip4_mapped_1, 80),
IPEndPoint(ip6_1, 443)));
EXPECT_EQ(QUIC_ADDRESS_MISMATCH_V6_V4, EXPECT_EQ(QUIC_ADDRESS_MISMATCH_V6_V4,
GetAddressMismatch(IPEndPoint(ip6_1, 443), GetAddressMismatch(IPEndPoint(ip6_1, 443),
IPEndPoint(ip4_1, 443))); IPEndPoint(ip4_1, 443)));
EXPECT_EQ(QUIC_ADDRESS_MISMATCH_V6_V4,
GetAddressMismatch(IPEndPoint(ip6_1, 443),
IPEndPoint(ip4_mapped_1, 443)));
EXPECT_EQ(QUIC_ADDRESS_MISMATCH_V6_V4, EXPECT_EQ(QUIC_ADDRESS_MISMATCH_V6_V4,
GetAddressMismatch(IPEndPoint(ip6_1, 80), GetAddressMismatch(IPEndPoint(ip6_1, 80),
IPEndPoint(ip4_1, 443))); IPEndPoint(ip4_1, 443)));
EXPECT_EQ(QUIC_ADDRESS_MISMATCH_V6_V4,
GetAddressMismatch(IPEndPoint(ip6_1, 80),
IPEndPoint(ip4_mapped_1, 443)));
} }
} // namespace test } // namespace test
......
...@@ -251,7 +251,7 @@ void UpdatePublicResetAddressMismatchHistogram( ...@@ -251,7 +251,7 @@ void UpdatePublicResetAddressMismatchHistogram(
if (sample < 0) { if (sample < 0) {
return; return;
} }
UMA_HISTOGRAM_ENUMERATION("Net.QuicSession.PublicResetAddressMismatch", UMA_HISTOGRAM_ENUMERATION("Net.QuicSession.PublicResetAddressMismatch2",
sample, QUIC_ADDRESS_MISMATCH_MAX); sample, QUIC_ADDRESS_MISMATCH_MAX);
} }
...@@ -300,6 +300,12 @@ const char* GetConnectionDescriptionString() { ...@@ -300,6 +300,12 @@ const char* GetConnectionDescriptionString() {
return description; return description;
} }
// If |address| is an IPv4-mapped IPv6 address, returns ADDRESS_FAMILY_IPV4
// instead of ADDRESS_FAMILY_IPV6. Othewise, behaves like GetAddressFamily().
AddressFamily GetRealAddressFamily(const IPAddressNumber& address) {
return IsIPv4Mapped(address) ? ADDRESS_FAMILY_IPV4 :
GetAddressFamily(address);
}
} // namespace } // namespace
...@@ -431,7 +437,7 @@ void QuicConnectionLogger::OnPacketReceived(const IPEndPoint& self_address, ...@@ -431,7 +437,7 @@ void QuicConnectionLogger::OnPacketReceived(const IPEndPoint& self_address,
if (local_address_from_self_.GetFamily() == ADDRESS_FAMILY_UNSPECIFIED) { if (local_address_from_self_.GetFamily() == ADDRESS_FAMILY_UNSPECIFIED) {
local_address_from_self_ = self_address; local_address_from_self_ = self_address;
UMA_HISTOGRAM_ENUMERATION("Net.QuicSession.ConnectionTypeFromSelf", UMA_HISTOGRAM_ENUMERATION("Net.QuicSession.ConnectionTypeFromSelf",
self_address.GetFamily(), GetRealAddressFamily(self_address.address()),
ADDRESS_FAMILY_LAST); ADDRESS_FAMILY_LAST);
} }
...@@ -594,7 +600,8 @@ void QuicConnectionLogger::OnCryptoHandshakeMessageReceived( ...@@ -594,7 +600,8 @@ void QuicConnectionLogger::OnCryptoHandshakeMessageReceived(
decoder.Decode(address.data(), address.size())) { decoder.Decode(address.data(), address.size())) {
local_address_from_shlo_ = IPEndPoint(decoder.ip(), decoder.port()); local_address_from_shlo_ = IPEndPoint(decoder.ip(), decoder.port());
UMA_HISTOGRAM_ENUMERATION("Net.QuicSession.ConnectionTypeFromPeer", UMA_HISTOGRAM_ENUMERATION("Net.QuicSession.ConnectionTypeFromPeer",
local_address_from_shlo_.GetFamily(), GetRealAddressFamily(
local_address_from_shlo_.address()),
ADDRESS_FAMILY_LAST); ADDRESS_FAMILY_LAST);
} }
} }
......
...@@ -13568,7 +13568,20 @@ Therefore, the affected-histogram name has to have at least one dot in it. ...@@ -13568,7 +13568,20 @@ Therefore, the affected-histogram name has to have at least one dot in it.
<histogram name="Net.QuicSession.PublicResetAddressMismatch" <histogram name="Net.QuicSession.PublicResetAddressMismatch"
enum="QuicAddressMismatch"> enum="QuicAddressMismatch">
<owner>rch@chromium.org</owner> <owner>wtc@chromium.org</owner>
<summary>
When a public reset packet is received, whether the client IP address and
port number in it differ from the client IP address and port number in the
ServerHello handshake message. In the comparison, the first address is the
one in ServerHello and the second address is the one in public reset. Note:
this histogram is obsolete because it failed to treat IPv4-mapped IPv6
addresses as IPv4 addresses.
</summary>
</histogram>
<histogram name="Net.QuicSession.PublicResetAddressMismatch2"
enum="QuicAddressMismatch">
<owner>wtc@chromium.org</owner>
<summary> <summary>
When a public reset packet is received, whether the client IP address and When a public reset packet is received, whether the client IP address and
port number in it differ from the client IP address and port number in the port number in it differ from the client IP address and port number in the
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment