Skip to content

Commit

Permalink
Include network UDPSocket is bound to in NetLog.
Browse files Browse the repository at this point in the history
This helps debug QUIC connection migration.

R=xunjieli

Review-Url: https://codereview.chromium.org/2051993004
Cr-Commit-Position: refs/heads/master@{#399254}
  • Loading branch information
JensenPaul authored and Commit bot committed Jun 10, 2016
1 parent 31d694f commit f0d9535
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 10 deletions.
6 changes: 6 additions & 0 deletions net/log/net_log_event_type_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,9 @@ EVENT_TYPE(EV_CERT_CT_COMPLIANCE_CHECKED)
//
// {
// "address": <Remote address being connected to>,
// "bound_to_network": <optional; network handle for the network that this
// socket is bound to. Only present when this socket
// is bound to a network.>
// }
//
// And the END event will contain the following parameter:
Expand All @@ -690,6 +693,9 @@ EVENT_TYPE(UDP_CONNECT)
// The following parameters are attached:
// {
// "address": <Local address bound to the socket>,
// "bound_to_network": <optional; network handle for the network that this
// socket is bound to. Only present when this socket
// is bound to a network.>
// }
EVENT_TYPE(UDP_LOCAL_ADDRESS)

Expand Down
8 changes: 6 additions & 2 deletions net/udp/udp_net_log_parameters.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@ std::unique_ptr<base::Value> NetLogUDPDataTranferCallback(

std::unique_ptr<base::Value> NetLogUDPConnectCallback(
const IPEndPoint* address,
NetworkChangeNotifier::NetworkHandle network,
NetLogCaptureMode /* capture_mode */) {
std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
dict->SetString("address", address->ToString());
if (network != NetworkChangeNotifier::kInvalidNetworkHandle)
dict->SetInteger("bound_to_network", network);
return std::move(dict);
}

Expand All @@ -48,9 +51,10 @@ NetLog::ParametersCallback CreateNetLogUDPDataTranferCallback(
}

NetLog::ParametersCallback CreateNetLogUDPConnectCallback(
const IPEndPoint* address) {
const IPEndPoint* address,
NetworkChangeNotifier::NetworkHandle network) {
DCHECK(address);
return base::Bind(&NetLogUDPConnectCallback, address);
return base::Bind(&NetLogUDPConnectCallback, address, network);
}

} // namespace net
4 changes: 3 additions & 1 deletion net/udp/udp_net_log_parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#ifndef NET_UDP_UDP_NET_LOG_PARAMETERS_H_
#define NET_UDP_UDP_NET_LOG_PARAMETERS_H_

#include "net/base/network_change_notifier.h"
#include "net/log/net_log.h"

namespace net {
Expand All @@ -24,7 +25,8 @@ NetLog::ParametersCallback CreateNetLogUDPDataTranferCallback(
// connect event. |address| cannot be NULL, and must remain valid for
// the lifetime of the callback.
NetLog::ParametersCallback CreateNetLogUDPConnectCallback(
const IPEndPoint* address);
const IPEndPoint* address,
NetworkChangeNotifier::NetworkHandle network);

} // namespace net

Expand Down
12 changes: 8 additions & 4 deletions net/udp/udp_socket_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ UDPSocketPosix::UDPSocketPosix(DatagramSocket::BindType bind_type,
read_buf_len_(0),
recv_from_address_(NULL),
write_buf_len_(0),
net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_UDP_SOCKET)) {
net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_UDP_SOCKET)),
bound_network_(NetworkChangeNotifier::kInvalidNetworkHandle) {
net_log_.BeginEvent(NetLog::TYPE_SOCKET_ALIVE,
source.ToEventParametersCallback());
if (bind_type == DatagramSocket::RANDOM_BIND)
Expand Down Expand Up @@ -175,8 +176,9 @@ int UDPSocketPosix::GetLocalAddress(IPEndPoint* address) const {
if (!address->FromSockAddr(storage.addr, storage.addr_len))
return ERR_ADDRESS_INVALID;
local_address_.reset(address.release());
net_log_.AddEvent(NetLog::TYPE_UDP_LOCAL_ADDRESS,
CreateNetLogUDPConnectCallback(local_address_.get()));
net_log_.AddEvent(
NetLog::TYPE_UDP_LOCAL_ADDRESS,
CreateNetLogUDPConnectCallback(local_address_.get(), bound_network_));
}

*address = *local_address_;
Expand Down Expand Up @@ -269,7 +271,7 @@ int UDPSocketPosix::SendToOrWrite(IOBuffer* buf,
int UDPSocketPosix::Connect(const IPEndPoint& address) {
DCHECK_NE(socket_, kInvalidSocket);
net_log_.BeginEvent(NetLog::TYPE_UDP_CONNECT,
CreateNetLogUDPConnectCallback(&address));
CreateNetLogUDPConnectCallback(&address, bound_network_));
int rv = InternalConnect(address);
net_log_.EndEventWithNetErrorCode(NetLog::TYPE_UDP_CONNECT, rv);
is_connected_ = (rv == OK);
Expand Down Expand Up @@ -364,6 +366,8 @@ int UDPSocketPosix::BindToNetwork(
// the less descriptive ERR_FAILED.
if (rv == ENONET)
return ERR_NETWORK_CHANGED;
if (rv == 0)
bound_network_ = network;
return MapSystemError(rv);
#else
NOTIMPLEMENTED();
Expand Down
3 changes: 3 additions & 0 deletions net/udp/udp_socket_posix.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,9 @@ class NET_EXPORT UDPSocketPosix : public base::NonThreadSafe {

BoundNetLog net_log_;

// Network that this socket is bound to via BindToNetwork().
NetworkChangeNotifier::NetworkHandle bound_network_;

DISALLOW_COPY_AND_ASSIGN(UDPSocketPosix);
};

Expand Down
11 changes: 8 additions & 3 deletions net/udp/udp_socket_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "net/base/ip_endpoint.h"
#include "net/base/net_errors.h"
#include "net/base/network_activity_monitor.h"
#include "net/base/network_change_notifier.h"
#include "net/base/sockaddr_storage.h"
#include "net/base/winsock_init.h"
#include "net/base/winsock_util.h"
Expand Down Expand Up @@ -355,7 +356,9 @@ int UDPSocketWin::GetLocalAddress(IPEndPoint* address) const {
return ERR_ADDRESS_INVALID;
local_address_.reset(local_address.release());
net_log_.AddEvent(NetLog::TYPE_UDP_LOCAL_ADDRESS,
CreateNetLogUDPConnectCallback(local_address_.get()));
CreateNetLogUDPConnectCallback(
local_address_.get(),
NetworkChangeNotifier::kInvalidNetworkHandle));
}

*address = *local_address_;
Expand Down Expand Up @@ -426,8 +429,10 @@ int UDPSocketWin::SendToOrWrite(IOBuffer* buf,

int UDPSocketWin::Connect(const IPEndPoint& address) {
DCHECK_NE(socket_, INVALID_SOCKET);
net_log_.BeginEvent(NetLog::TYPE_UDP_CONNECT,
CreateNetLogUDPConnectCallback(&address));
net_log_.BeginEvent(
NetLog::TYPE_UDP_CONNECT,
CreateNetLogUDPConnectCallback(
&address, NetworkChangeNotifier::kInvalidNetworkHandle));
int rv = InternalConnect(address);
net_log_.EndEventWithNetErrorCode(NetLog::TYPE_UDP_CONNECT, rv);
is_connected_ = (rv == OK);
Expand Down

0 comments on commit f0d9535

Please sign in to comment.