Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion source/common/network/utility.cc
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,14 @@ Address::InstanceConstSharedPtr Utility::getOriginalDst(Socket& sock) {
return nullptr;
}

return Address::addressFromSockAddrOrDie(orig_addr, 0, -1, true /* default for v6 constructor */);
auto address_or_status =
Address::addressFromSockAddr(orig_addr, 0, true /* default for v6 constructor */);
Comment thread
yanavlasov marked this conversation as resolved.
if (!address_or_status.ok()) {
ENVOY_LOG_MISC(debug, "Failed to get address from sockaddr for getOriginalDst: {}",
address_or_status.status().message());
return nullptr;
}
return *address_or_status;

#else
// TODO(zuercher): determine if connection redirection is possible under macOS (c.f. pfctl and
Expand Down
9 changes: 9 additions & 0 deletions test/common/network/utility_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,15 @@ TEST(NetworkUtility, GetOriginalDst) {
EXPECT_CALL(socket, getSocketOption(Eq(SOL_IP), Eq(SO_ORIGINAL_DST), _, _))
.WillOnce(DoAll(SetArg2Sockaddr(storage), Return(Api::SysCallIntResult{0, 0})));
EXPECT_EQ("12.34.56.78:9527", Utility::getOriginalDst(socket)->asString());

// Invalid family returned by SO_ORIGINAL_DST should cause addressFromSockAddr to fail and
// getOriginalDst to return nullptr
sin.sin_family = AF_UNSPEC;
EXPECT_CALL(socket, getSocketOption(Eq(SOL_IP), Eq(SO_ORIGINAL_DST), _, _))
.WillOnce(DoAll(SetArg2Sockaddr(storage), Return(Api::SysCallIntResult{0, 0})));
EXPECT_EQ(nullptr, Utility::getOriginalDst(socket));

sin.sin_family = AF_INET;
#ifndef WIN32
// Transparent socket gets original dst from local address while connection tracking disabled
EXPECT_CALL(socket, getSocketOption(Eq(SOL_IP), Eq(SO_ORIGINAL_DST), _, _))
Expand Down
Loading