1 /** 2 * Copyright (c) 2016, The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.net.metrics; 18 19 /** 20 * Logs netd events. 21 * 22 * {@hide} 23 */ 24 oneway interface INetdEventListener { 25 const int EVENT_GETADDRINFO = 1; 26 const int EVENT_GETHOSTBYNAME = 2; 27 28 const int REPORTING_LEVEL_NONE = 0; 29 const int REPORTING_LEVEL_METRICS = 1; 30 const int REPORTING_LEVEL_FULL = 2; 31 32 // Maximum number of IP addresses logged for DNS lookups before we truncate the full list. 33 const int DNS_REPORTED_IP_ADDRESSES_LIMIT = 10; 34 35 /** 36 * Logs a DNS lookup function call (getaddrinfo and gethostbyname). 37 * 38 * @param netId the ID of the network the lookup was performed on. 39 * @param eventType one of the EVENT_* constants in this interface. 40 * @param returnCode the return value of the function call. 41 * @param latencyMs the latency of the function call. 42 * @param hostname the name that was looked up. 43 * @param ipAddresses (possibly a subset of) the IP addresses returned. 44 * At most {@link #DNS_REPORTED_IP_ADDRESSES_LIMIT} addresses are logged. 45 * @param ipAddressesCount the number of IP addresses returned. May be different from the length 46 * of ipAddresses if there were too many addresses to log. 47 * @param uid the UID of the application that performed the query. 48 */ onDnsEvent(int netId, int eventType, int returnCode, int latencyMs, String hostname, in String[] ipAddresses, int ipAddressesCount, int uid)49 void onDnsEvent(int netId, int eventType, int returnCode, int latencyMs, String hostname, 50 in String[] ipAddresses, int ipAddressesCount, int uid); 51 52 /** 53 * Represents a private DNS validation success or failure. 54 * 55 * @param netId the ID of the network the validation was performed on. 56 * @param ipAddress the IP address for which validation was performed. 57 * @param hostname the hostname for which validation was performed. 58 * @param validated whether or not validation was successful. 59 */ onPrivateDnsValidationEvent(int netId, String ipAddress, String hostname, boolean validated)60 void onPrivateDnsValidationEvent(int netId, String ipAddress, String hostname, 61 boolean validated); 62 63 /** 64 * Logs a single connect library call. 65 * 66 * @param netId the ID of the network the connect was performed on. 67 * @param error 0 if the connect call succeeded, otherwise errno if it failed. 68 * @param latencyMs the latency of the connect call. 69 * @param ipAddr destination IP address. 70 * @param port destination port number. 71 * @param uid the UID of the application that performed the connection. 72 */ onConnectEvent(int netId, int error, int latencyMs, String ipAddr, int port, int uid)73 void onConnectEvent(int netId, int error, int latencyMs, String ipAddr, int port, int uid); 74 75 /** 76 * Logs a single RX packet which caused the main CPU to exit sleep state. 77 * @param prefix arbitrary string provided via wakeupAddInterface() 78 * @param uid UID of the destination process or -1 if no UID is available. 79 * @param ethertype of the RX packet encoded in an int in native order, or -1 if not available. 80 * @param ipNextHeader ip protocol of the RX packet as IPPROTO_* number, 81 or -1 if the packet was not IPv4 or IPv6. 82 * @param dstHw destination hardware address, or 0 if not available. 83 * @param srcIp source IP address, or null if not available. 84 * @param dstIp destination IP address, or null if not available. 85 * @param srcPort src port of RX packet in native order, or -1 if the packet was not UDP or TCP. 86 * @param dstPort dst port of RX packet in native order, or -1 if the packet was not UDP or TCP. 87 * @param timestampNs receive timestamp for the offending packet. In units of nanoseconds and 88 * synchronized to CLOCK_MONOTONIC. 89 */ onWakeupEvent(String prefix, int uid, int ethertype, int ipNextHeader, in byte[] dstHw, String srcIp, String dstIp, int srcPort, int dstPort, long timestampNs)90 void onWakeupEvent(String prefix, int uid, int ethertype, int ipNextHeader, in byte[] dstHw, 91 String srcIp, String dstIp, int srcPort, int dstPort, long timestampNs); 92 93 /** 94 * An event sent after every Netlink sock_diag poll performed by Netd. This reported batch 95 * groups TCP socket stats aggregated by network id. Per-network data are stored in a 96 * structure-of-arrays style where networkIds, sentPackets, lostPackets, rttUs, and 97 * sentAckDiffMs have the same length. Stats for the i-th network is spread across all these 98 * arrays at index i. 99 * @param networkIds an array of network ids for which there was tcp socket stats to collect in 100 * the last sock_diag poll. 101 * @param sentPackets an array of packet sent across all TCP sockets still alive and new 102 TCP sockets since the last sock_diag poll, summed per network id. 103 * @param lostPackets, an array of packet lost across all TCP sockets still alive and new 104 TCP sockets since the last sock_diag poll, summed per network id. 105 * @param rttUs an array of smoothed round trip times in microseconds, averaged across all TCP 106 sockets since the last sock_diag poll for a given network id. 107 * @param sentAckDiffMs an array of milliseconds duration between the last packet sent and the 108 last ack received for a socket, averaged across all TCP sockets for a network id. 109 */ onTcpSocketStatsEvent(in int[] networkIds, in int[] sentPackets, in int[] lostPackets, in int[] rttUs, in int[] sentAckDiffMs)110 void onTcpSocketStatsEvent(in int[] networkIds, in int[] sentPackets, 111 in int[] lostPackets, in int[] rttUs, in int[] sentAckDiffMs); 112 } 113