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 const int EVENT_GETHOSTBYADDR = 3; 28 const int EVENT_RES_NSEND = 4; 29 30 const int REPORTING_LEVEL_NONE = 0; 31 const int REPORTING_LEVEL_METRICS = 1; 32 const int REPORTING_LEVEL_FULL = 2; 33 34 // Maximum number of IP addresses logged for DNS lookups before we truncate the full list. 35 const int DNS_REPORTED_IP_ADDRESSES_LIMIT = 10; 36 37 /** 38 * Logs a DNS lookup function call (getaddrinfo and gethostbyname). 39 * 40 * @param netId the ID of the network the lookup was performed on. 41 * @param eventType one of the EVENT_* constants in this interface. 42 * @param returnCode the return value of the function call. 43 * @param latencyMs the latency of the function call. 44 * @param hostname the name that was looked up. 45 * @param ipAddresses (possibly a subset of) the IP addresses returned. 46 * At most {@link #DNS_REPORTED_IP_ADDRESSES_LIMIT} addresses are logged. 47 * @param ipAddressesCount the number of IP addresses returned. May be different from the length 48 * of ipAddresses if there were too many addresses to log. 49 * @param uid the UID of the application that performed the query. 50 */ onDnsEvent(int netId, int eventType, int returnCode, int latencyMs, @utf8InCpp String hostname, in @utf8InCpp String[] ipAddresses, int ipAddressesCount, int uid)51 void onDnsEvent(int netId, int eventType, int returnCode, int latencyMs, 52 @utf8InCpp String hostname, in @utf8InCpp String[] ipAddresses, 53 int ipAddressesCount, int uid); 54 55 /** 56 * Represents a private DNS validation success or failure. 57 * 58 * @param netId the ID of the network the validation was performed on. 59 * @param ipAddress the IP address for which validation was performed. 60 * @param hostname the hostname for which validation was performed. 61 * @param validated whether or not validation was successful. 62 */ onPrivateDnsValidationEvent(int netId, String ipAddress, String hostname, boolean validated)63 void onPrivateDnsValidationEvent(int netId, String ipAddress, String hostname, 64 boolean validated); 65 66 /** 67 * Logs a single connect library call. 68 * 69 * @param netId the ID of the network the connect was performed on. 70 * @param error 0 if the connect call succeeded, otherwise errno if it failed. 71 * @param latencyMs the latency of the connect call. 72 * @param ipAddr destination IP address. 73 * @param port destination port number. 74 * @param uid the UID of the application that performed the connection. 75 */ onConnectEvent(int netId, int error, int latencyMs, String ipAddr, int port, int uid)76 void onConnectEvent(int netId, int error, int latencyMs, String ipAddr, int port, int uid); 77 78 /** 79 * Logs a single RX packet which caused the main CPU to exit sleep state. 80 * @param prefix arbitrary string provided via wakeupAddInterface() 81 * @param uid UID of the destination process or -1 if no UID is available. 82 * @param ethertype of the RX packet encoded in an int in native order, or -1 if not available. 83 * @param ipNextHeader ip protocol of the RX packet as IPPROTO_* number, 84 or -1 if the packet was not IPv4 or IPv6. 85 * @param dstHw destination hardware address, or 0 if not available. 86 * @param srcIp source IP address, or null if not available. 87 * @param dstIp destination IP address, or null if not available. 88 * @param srcPort src port of RX packet in native order, or -1 if the packet was not UDP or TCP. 89 * @param dstPort dst port of RX packet in native order, or -1 if the packet was not UDP or TCP. 90 * @param timestampNs receive timestamp for the offending packet. In units of nanoseconds and 91 * synchronized to CLOCK_MONOTONIC. 92 */ onWakeupEvent(String prefix, int uid, int ethertype, int ipNextHeader, in byte[] dstHw, String srcIp, String dstIp, int srcPort, int dstPort, long timestampNs)93 void onWakeupEvent(String prefix, int uid, int ethertype, int ipNextHeader, in byte[] dstHw, 94 String srcIp, String dstIp, int srcPort, int dstPort, long timestampNs); 95 96 /** 97 * An event sent after every Netlink sock_diag poll performed by Netd. This reported batch 98 * groups TCP socket stats aggregated by network id. Per-network data are stored in a 99 * structure-of-arrays style where networkIds, sentPackets, lostPackets, rttUs, and 100 * sentAckDiffMs have the same length. Stats for the i-th network is spread across all these 101 * arrays at index i. 102 * @param networkIds an array of network ids for which there was tcp socket stats to collect in 103 * the last sock_diag poll. 104 * @param sentPackets an array of packet sent across all TCP sockets still alive and new 105 TCP sockets since the last sock_diag poll, summed per network id. 106 * @param lostPackets, an array of packet lost across all TCP sockets still alive and new 107 TCP sockets since the last sock_diag poll, summed per network id. 108 * @param rttUs an array of smoothed round trip times in microseconds, averaged across all TCP 109 sockets since the last sock_diag poll for a given network id. 110 * @param sentAckDiffMs an array of milliseconds duration between the last packet sent and the 111 last ack received for a socket, averaged across all TCP sockets for a network id. 112 */ onTcpSocketStatsEvent(in int[] networkIds, in int[] sentPackets, in int[] lostPackets, in int[] rttUs, in int[] sentAckDiffMs)113 void onTcpSocketStatsEvent(in int[] networkIds, in int[] sentPackets, 114 in int[] lostPackets, in int[] rttUs, in int[] sentAckDiffMs); 115 116 /** 117 * Represents adding or removing a NAT64 prefix. 118 * 119 * @param netId the ID of the network the prefix was discovered on. 120 * @param added true if the NAT64 prefix was added, or false if the NAT64 prefix was removed. 121 * There is only one prefix at a time for each netId. If a prefix is added, it replaces 122 * the previous-added prefix. 123 * @param prefixString the detected NAT64 prefix as a string literal. 124 * @param prefixLength the prefix length associated with this NAT64 prefix. 125 */ onNat64PrefixEvent(int netId, boolean added, @utf8InCpp String prefixString, int prefixLength)126 void onNat64PrefixEvent(int netId, boolean added, @utf8InCpp String prefixString, 127 int prefixLength); 128 } 129