Skip to content

Commit

Permalink
Merge "Use different client port if the reserved UDP port is in use."…
Browse files Browse the repository at this point in the history
… into R3.0
  • Loading branch information
Zuul authored and opencontrail-ci-admin committed May 9, 2016
2 parents 70c7f5e + 2686166 commit 60c72cf
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/dns/bind/bind_resolver.cc
Expand Up @@ -46,7 +46,11 @@ BindResolver::BindResolver(boost::asio::io_service &io,
sock_.open(boost::asio::ip::udp::v4(), ec);
assert(ec.value() == 0);
sock_.bind(local_ep, ec);
assert(ec.value() == 0);
if (ec.value() != 0) {
local_ep.port(0);
sock_.bind(local_ep, ec);
assert(ec.value() == 0);
}
AsyncRead();
}

Expand Down
11 changes: 11 additions & 0 deletions src/dns/test/dns_bind_test.cc
Expand Up @@ -1061,6 +1061,17 @@ TEST_F(DnsBindTest, DnsUpdateErrorParse) {

int main(int argc, char **argv) {
Dns::Init();

// Bind to the client port first so that a new client port is used
boost::system::error_code ec;
boost::asio::ip::udp::socket sock(*Dns::GetEventManager()->io_service());
boost::asio::ip::udp::endpoint ep(boost::asio::ip::address::
from_string("0.0.0.0", ec),
ContrailPorts::ContrailDnsClientUdpPort());
sock.open(boost::asio::ip::udp::v4(), ec);
assert(ec.value() == 0);
sock.bind(ep, ec);

::testing::InitGoogleTest(&argc, argv);
int error = RUN_ALL_TESTS();
TaskScheduler::GetInstance()->Terminate();
Expand Down
6 changes: 5 additions & 1 deletion src/vnsw/agent/oper/mirror_table.cc
Expand Up @@ -303,7 +303,11 @@ void MirrorTable::MirrorSockInit(void) {
assert(ec.value() == 0);

udp_sock_->bind(ep, ec);
assert(ec.value() == 0);
if (ec.value() != 0) {
ep.port(0);
udp_sock_->bind(ep, ec);
assert(ec.value() == 0);
}

ip::udp::endpoint sock_ep = udp_sock_->local_endpoint(ec);
assert(ec.value() == 0);
Expand Down

0 comments on commit 60c72cf

Please sign in to comment.