GetDefaultLocalAddress should return the bestIP

on an IPv6 network that contains the actual default local address. This is for preventing potential IP leaking.

BUG=webrtc:5376

Review URL: https://codereview.webrtc.org/1837823005

Cr-Commit-Position: refs/heads/master@{#12417}
This commit is contained in:
honghaiz
2016-04-18 14:50:44 -07:00
committed by Commit bot
parent b9e77097ed
commit af83fe65d9
3 changed files with 54 additions and 1 deletions

View File

@ -1006,6 +1006,35 @@ TEST_F(NetworkTest, DefaultLocalAddress) {
EXPECT_EQ(ip, GetLoopbackIP(AF_INET));
EXPECT_TRUE(manager.GetDefaultLocalAddress(AF_INET6, &ip));
EXPECT_EQ(ip, GetLoopbackIP(AF_INET6));
// More tests on GetDefaultLocalAddress with ipv6 addresses where the set
// default address may be different from the best IP address of any network.
InterfaceAddress ip1;
EXPECT_TRUE(IPFromString("abcd::1234:5678:abcd:1111",
IPV6_ADDRESS_FLAG_TEMPORARY, &ip1));
// Create a network with a prefix of ip1.
Network ipv6_network("test_eth0", "Test NetworkAdapter", TruncateIP(ip1, 64),
64);
IPAddress ip2;
EXPECT_TRUE(IPFromString("abcd::1234:5678:abcd:2222", &ip2));
ipv6_network.AddIP(ip1);
ipv6_network.AddIP(ip2);
BasicNetworkManager::NetworkList list(1, new Network(ipv6_network));
bool changed;
MergeNetworkList(manager, list, &changed);
// If the set default address is not in any network, GetDefaultLocalAddress
// should return it.
IPAddress ip3;
EXPECT_TRUE(IPFromString("abcd::1234:5678:abcd:3333", &ip3));
manager.set_default_local_addresses(GetLoopbackIP(AF_INET), ip3);
EXPECT_TRUE(manager.GetDefaultLocalAddress(AF_INET6, &ip));
EXPECT_EQ(ip3, ip);
// If the set default address is in a network, GetDefaultLocalAddress will
// return the best IP in that network.
manager.set_default_local_addresses(GetLoopbackIP(AF_INET), ip2);
EXPECT_TRUE(manager.GetDefaultLocalAddress(AF_INET6, &ip));
EXPECT_EQ(static_cast<IPAddress>(ip1), ip);
manager.StopUpdating();
}