Add connect event reporting

Adds reporting of connect events including netId, destination IP address,
destination port, uid and connect latency.

Also enables the relevant tests in the connect_benchmark.

Currently ignores the new data it receives, further work will be
done in the subsequent CLs.

Test: for now just the benchmarking, in the future CTS

Bug: 29748723

(cherry picked from commit 4b9b78aa02336de9291e5085401cef44c03c3bba)

Change-Id: If8e5ddcd2d29271e2f63a3338a3daf83e7afccdc
diff --git a/client/FwmarkClient.cpp b/client/FwmarkClient.cpp
index 056dfc2..a9a11bc 100644
--- a/client/FwmarkClient.cpp
+++ b/client/FwmarkClient.cpp
@@ -25,6 +25,8 @@
 #include <sys/un.h>
 #include <unistd.h>
 
+#define ARRAY_SIZE(a) (sizeof(a) / sizeof(*(a)))
+
 namespace {
 
 const sockaddr_un FWMARK_SERVER_PATH = {AF_UNIX, "/dev/socket/fwmarkd"};
@@ -36,6 +38,8 @@
 }
 
 bool FwmarkClient::shouldReportConnectComplete(int family) {
+    // TODO: put getenv(ANDROID_FWMARK_METRICS_ONLY) behind the ro.debuggable system property
+    // or else an app can evade connect logging just by setting the env variable
     return shouldSetFwmark(family) && !getenv(ANDROID_FWMARK_METRICS_ONLY);
 }
 
@@ -48,7 +52,7 @@
     }
 }
 
-int FwmarkClient::send(FwmarkCommand* data, int fd) {
+int FwmarkClient::send(FwmarkCommand* data, int fd, FwmarkConnectInfo* connectInfo) {
     mChannel = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
     if (mChannel == -1) {
         return -errno;
@@ -61,14 +65,14 @@
         return 0;
     }
 
-    iovec iov;
-    iov.iov_base = data;
-    iov.iov_len = sizeof(*data);
-
+    iovec iov[2] = {
+        { data, sizeof(*data) },
+        { connectInfo, (connectInfo ? sizeof(*connectInfo) : 0) },
+    };
     msghdr message;
     memset(&message, 0, sizeof(message));
-    message.msg_iov = &iov;
-    message.msg_iovlen = 1;
+    message.msg_iov = iov;
+    message.msg_iovlen = ARRAY_SIZE(iov);
 
     union {
         cmsghdr cmh;