OSDN Git Service

DO NOT MERGE onConnectEvent does not report udp connects
authorHugo Benichi <hugobenichi@google.com>
Thu, 8 Dec 2016 06:37:05 +0000 (15:37 +0900)
committerHugo Benichi <hugobenichi@google.com>
Fri, 9 Dec 2016 03:43:55 +0000 (12:43 +0900)
Test: manual test + $ runtest -x system/netd/test/netd_integration_test.cpp
Bug: 32198976
Bug: 29748723
Change-Id: I476ada792092db80c8fb27cb40d5d7ea0f26de46

server/FwmarkServer.cpp

index de129ab..b08f9f9 100644 (file)
@@ -22,6 +22,7 @@
 #include "NetworkController.h"
 #include "resolv_netid.h"
 
+#include <netinet/in.h>
 #include <sys/socket.h>
 #include <unistd.h>
 #include <utils/String16.h>
@@ -165,6 +166,15 @@ int FwmarkServer::processClient(SocketClient* client, int* socketFd) {
             // Called after a socket connect() completes.
             // This reports connect event including netId, destination IP address, destination port,
             // uid and connect latency
+
+            // Skip reporting if connect() happened on a UDP socket.
+            int socketProto;
+            socklen_t intSize = sizeof(socketProto);
+            const int ret = getsockopt(*socketFd, SOL_SOCKET, SO_PROTOCOL, &socketProto, &intSize);
+            if ((ret != 0) || (socketProto == IPPROTO_UDP)) {
+                break;
+            }
+
             android::sp<android::net::metrics::INetdEventListener> netdEventListener =
                     mEventReporter->getNetdEventListener();