Skip to content

Commit

Permalink
Use different client port if the reserved UDP port is in use.
Browse files Browse the repository at this point in the history
In case the reserved client port is in use, use different port
instead of assert.

Change-Id: Ie99e3e4a29bd4a809086ae4505ce8498bf40f79a
closes-bug: #1573316
  • Loading branch information
haripk committed May 9, 2016
1 parent 39ac2fe commit 2686166
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 2686166

Please sign in to comment.