OSDN Git Service

DO NOT MERGE Add success/errno to connect() event reporting
authorHugo Benichi <hugobenichi@google.com>
Mon, 31 Oct 2016 06:07:23 +0000 (15:07 +0900)
committerHugo Benichi <hugobenichi@google.com>
Thu, 15 Dec 2016 11:50:42 +0000 (20:50 +0900)
Test: $ runtest -x system/netd/tests/netd_integration_test.cpp
Bug: 32198976

(cherry picked from commit 794c5c714a4d4cf169769ec956845a6fb24e7ebc)

Change-Id: I0a7990d7211d5355a48d941ee9659c16e38817ca

client/NetdClient.cpp
include/FwmarkCommand.h
server/FwmarkServer.cpp
server/binder/android/net/metrics/INetdEventListener.aidl

index f025228..948b617 100644 (file)
@@ -87,13 +87,13 @@ int netdClientConnect(int sockfd, const sockaddr* addr, socklen_t addrlen) {
     }
     // Latency measurement does not include time of sending commands to Fwmark
     Stopwatch s;
-    int ret = libcConnect(sockfd, addr, addrlen);
+    const int ret = libcConnect(sockfd, addr, addrlen);
     // Save errno so it isn't clobbered by sending ON_CONNECT_COMPLETE
     const int connectErrno = errno;
     const unsigned latencyMs = lround(s.timeTaken());
     // Send an ON_CONNECT_COMPLETE command that includes sockaddr and connect latency for reporting
     if (shouldSetFwmark && FwmarkClient::shouldReportConnectComplete(addr->sa_family)) {
-        FwmarkConnectInfo connectInfo(latencyMs, addr);
+        FwmarkConnectInfo connectInfo(ret == 0 ? 0 : connectErrno, latencyMs, addr);
         // TODO: get the netId from the socket mark once we have continuous benchmark runs
         FwmarkCommand command = {FwmarkCommand::ON_CONNECT_COMPLETE, /* netId (ignored) */ 0,
                 /* uid (filled in by the server) */ 0};
index a31b320..39ff233 100644 (file)
@@ -23,6 +23,7 @@
 
 // Additional information sent with ON_CONNECT_COMPLETE command
 struct FwmarkConnectInfo {
+    int error;
     unsigned latencyMs;
     union {
         sockaddr s;
@@ -32,7 +33,8 @@ struct FwmarkConnectInfo {
 
     FwmarkConnectInfo() {}
 
-    FwmarkConnectInfo(const unsigned latency, const sockaddr* saddr) {
+    FwmarkConnectInfo(const int connectErrno, const unsigned latency, const sockaddr* saddr) {
+        error = connectErrno;
         latencyMs = latency;
         if (saddr->sa_family == AF_INET) {
             addr.sin = *((struct sockaddr_in*) saddr);
index b08f9f9..80df03f 100644 (file)
@@ -165,7 +165,7 @@ int FwmarkServer::processClient(SocketClient* client, int* socketFd) {
         case FwmarkCommand::ON_CONNECT_COMPLETE: {
             // Called after a socket connect() completes.
             // This reports connect event including netId, destination IP address, destination port,
-            // uid and connect latency
+            // uid, connect latency, and connect errno if any.
 
             // Skip reporting if connect() happened on a UDP socket.
             int socketProto;
@@ -185,7 +185,8 @@ int FwmarkServer::processClient(SocketClient* client, int* socketFd) {
                         addrstr, sizeof(addrstr), portstr, sizeof(portstr),
                         NI_NUMERICHOST | NI_NUMERICSERV);
 
-                netdEventListener->onConnectEvent(fwmark.netId, connectInfo.latencyMs,
+                netdEventListener->onConnectEvent(fwmark.netId, connectInfo.error,
+                        connectInfo.latencyMs,
                         (ret == 0) ? String16(addrstr) : String16(""),
                         (ret == 0) ? strtoul(portstr, NULL, 10) : 0, client->getUid());
             }
index 49a20f2..e966537 100644 (file)
@@ -52,11 +52,12 @@ oneway interface INetdEventListener {
     /**
      * Logs a single connect library call.
      *
-     * @param netId the ID of the network the lookup was performed on.
-     * @param latencyMs the latency of the function call.
+     * @param netId the ID of the network the connect was performed on.
+     * @param error 0 if the connect call succeeded, otherwise errno if it failed.
+     * @param latencyMs the latency of the connect call.
      * @param ipAddr destination IP address.
      * @param port destination port number.
      * @param uid the UID of the application that performed the connection.
      */
-    void onConnectEvent(int netId, int latencyMs, String ipAddr, int port, int uid);
+    void onConnectEvent(int netId, int error, int latencyMs, String ipAddr, int port, int uid);
 }