Commit 11db6c2a authored by wtc@chromium.org's avatar wtc@chromium.org

Replace setsockopt(IP_PKTINFO) and setsockopt(IPV6_RECVPKTINFO) calls by

gfe_quic::QuicSocketUtils::SetGetAddressInfo() calls. Update
gfe_quic::QuicSocketUtils::SetGetAddressInfo() to the best-known
implementation.

Merge internal CL: 70966702

R=rtenneti@chromium.org
BUG=none

Review URL: https://codereview.chromium.org/397793004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@283482 0039d316-1c4b-4281-b951-d872f2087c98
parent 899bbef8
......@@ -124,15 +124,7 @@ bool QuicClient::CreateUDPSocket() {
return false;
}
int get_local_ip = 1;
if (address_family == AF_INET) {
rc = setsockopt(fd_, IPPROTO_IP, IP_PKTINFO,
&get_local_ip, sizeof(get_local_ip));
} else {
rc = setsockopt(fd_, IPPROTO_IPV6, IPV6_RECVPKTINFO,
&get_local_ip, sizeof(get_local_ip));
}
rc = QuicSocketUtils::SetGetAddressInfo(fd_, address_family);
if (rc < 0) {
LOG(ERROR) << "IP detection not supported" << strerror(errno);
return false;
......
......@@ -28,12 +28,16 @@
#define SO_RXQ_OVFL 40
#endif
namespace net {
namespace tools {
namespace {
const int kEpollFlags = EPOLLIN | EPOLLOUT | EPOLLET;
static const char kSourceAddressTokenSecret[] = "secret";
const char kSourceAddressTokenSecret[] = "secret";
const uint32 kServerInitialFlowControlWindow = 100 * net::kMaxPacketSize;
namespace net {
namespace tools {
} // namespace
QuicServer::QuicServer()
: port_(0),
......@@ -92,6 +96,8 @@ bool QuicServer::Listen(const IPEndPoint& address) {
return false;
}
// Enable the socket option that allows the local address to be
// returned if the socket is bound to more than one address.
int rc = QuicSocketUtils::SetGetAddressInfo(fd_, address_family);
if (rc < 0) {
......@@ -122,20 +128,6 @@ bool QuicServer::Listen(const IPEndPoint& address) {
return false;
}
// Enable the socket option that allows the local address to be
// returned if the socket is bound to more than on address.
int get_local_ip = 1;
rc = setsockopt(fd_, IPPROTO_IP, IP_PKTINFO,
&get_local_ip, sizeof(get_local_ip));
if (rc == 0 && address_family == AF_INET6) {
rc = setsockopt(fd_, IPPROTO_IPV6, IPV6_RECVPKTINFO,
&get_local_ip, sizeof(get_local_ip));
}
if (rc != 0) {
LOG(ERROR) << "Failed to set required socket options";
return false;
}
sockaddr_storage raw_addr;
socklen_t raw_addr_len = sizeof(raw_addr);
CHECK(address.ToSockAddr(reinterpret_cast<sockaddr*>(&raw_addr),
......
......@@ -70,13 +70,13 @@ bool QuicSocketUtils::GetOverflowFromMsghdr(struct msghdr *hdr,
// static
int QuicSocketUtils::SetGetAddressInfo(int fd, int address_family) {
int get_local_ip = 1;
if (address_family == AF_INET) {
return setsockopt(fd, IPPROTO_IP, IP_PKTINFO,
&get_local_ip, sizeof(get_local_ip));
} else {
return setsockopt(fd, IPPROTO_IPV6, IPV6_RECVPKTINFO,
int rc = setsockopt(fd, IPPROTO_IP, IP_PKTINFO,
&get_local_ip, sizeof(get_local_ip));
if (rc == 0 && address_family == AF_INET6) {
rc = setsockopt(fd, IPPROTO_IPV6, IPV6_RECVPKTINFO,
&get_local_ip, sizeof(get_local_ip));
}
return rc;
}
// static
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment