Tighten link-local routing exclusion check
Also add a unit test for this behavior. BUG=https://code.google.com/p/webrtc/issues/detail?id=4823 R=pthatcher@webrtc.org Review URL: https://codereview.webrtc.org/1218293016 . Cr-Commit-Position: refs/heads/master@{#9550}
This commit is contained in:
parent
6e89b25143
commit
b8b0143a11
@ -472,7 +472,8 @@ bool Port::IsCompatibleAddress(const rtc::SocketAddress& addr) {
|
||||
return false;
|
||||
}
|
||||
// Link-local IPv6 ports can only connect to other link-local IPv6 ports.
|
||||
if (family == AF_INET6 && (IPIsPrivate(ip()) != IPIsPrivate(addr.ipaddr()))) {
|
||||
if (family == AF_INET6 &&
|
||||
(IPIsLinkLocal(ip()) != IPIsLinkLocal(addr.ipaddr()))) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
@ -538,6 +538,8 @@ class PortTest : public testing::Test, public sigslot::has_slots<> {
|
||||
|
||||
void TestCrossFamilyPorts(int type);
|
||||
|
||||
void ExpectPortsCanConnect(bool can_connect, Port* p1, Port* p2);
|
||||
|
||||
// This does all the work and then deletes |port1| and |port2|.
|
||||
void TestConnectivity(const char* name1, Port* port1,
|
||||
const char* name2, Port* port2,
|
||||
@ -1394,6 +1396,49 @@ TEST_F(PortTest, TestSkipCrossFamilyUdp) {
|
||||
TestCrossFamilyPorts(SOCK_DGRAM);
|
||||
}
|
||||
|
||||
void PortTest::ExpectPortsCanConnect(bool can_connect, Port* p1, Port* p2) {
|
||||
Connection* c = p1->CreateConnection(GetCandidate(p2),
|
||||
Port::ORIGIN_MESSAGE);
|
||||
if (can_connect) {
|
||||
EXPECT_FALSE(NULL == c);
|
||||
EXPECT_EQ(1U, p1->connections().size());
|
||||
} else {
|
||||
EXPECT_TRUE(NULL == c);
|
||||
EXPECT_EQ(0U, p1->connections().size());
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(PortTest, TestUdpV6CrossTypePorts) {
|
||||
FakePacketSocketFactory factory;
|
||||
scoped_ptr<Port> ports[4];
|
||||
SocketAddress addresses[4] = {SocketAddress("2001:db8::1", 0),
|
||||
SocketAddress("fe80::1", 0),
|
||||
SocketAddress("fe80::2", 0),
|
||||
SocketAddress("::1", 0)};
|
||||
for (int i = 0; i < 4; i++) {
|
||||
FakeAsyncPacketSocket *socket = new FakeAsyncPacketSocket();
|
||||
factory.set_next_udp_socket(socket);
|
||||
ports[i].reset(CreateUdpPort(addresses[i], &factory));
|
||||
socket->set_state(AsyncPacketSocket::STATE_BINDING);
|
||||
socket->SignalAddressReady(socket, addresses[i]);
|
||||
ports[i]->PrepareAddress();
|
||||
}
|
||||
|
||||
Port* standard = ports[0].get();
|
||||
Port* link_local1 = ports[1].get();
|
||||
Port* link_local2 = ports[2].get();
|
||||
Port* localhost = ports[3].get();
|
||||
|
||||
ExpectPortsCanConnect(false, link_local1, standard);
|
||||
ExpectPortsCanConnect(false, standard, link_local1);
|
||||
ExpectPortsCanConnect(false, link_local1, localhost);
|
||||
ExpectPortsCanConnect(false, localhost, link_local1);
|
||||
|
||||
ExpectPortsCanConnect(true, link_local1, link_local2);
|
||||
ExpectPortsCanConnect(true, localhost, standard);
|
||||
ExpectPortsCanConnect(true, standard, localhost);
|
||||
}
|
||||
|
||||
// This test verifies DSCP value set through SetOption interface can be
|
||||
// get through DefaultDscpValue.
|
||||
TEST_F(PortTest, TestDefaultDscpValue) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user