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 #ifndef NETD_RES_STATS_H 18 #define NETD_RES_STATS_H 19 20 #include <stdbool.h> 21 #include <stdint.h> 22 #include <sys/socket.h> 23 #include <time.h> 24 25 #include "params.h" 26 27 #define RCODE_INTERNAL_ERROR 254 28 #define RCODE_TIMEOUT 255 29 30 struct res_sample { 31 time_t at; // time in s at which the sample was recorded 32 uint16_t rtt; // round-trip time in ms 33 uint8_t rcode; // the DNS rcode or RCODE_XXX defined above 34 }; 35 36 // Resolver reachability statistics and run-time parameters. 37 struct res_stats { 38 // Stats of the last <sample_count> queries. 39 res_sample samples[MAXNSSAMPLES]; 40 // The number of samples stored. 41 uint8_t sample_count; 42 // The next sample to modify. 43 uint8_t sample_next; 44 }; 45 46 // Aggregates the reachability statistics for the given server based on on the stored samples. 47 LIBNETD_RESOLV_PUBLIC void android_net_res_stats_aggregate(res_stats* stats, int* successes, 48 int* errors, int* timeouts, 49 int* internal_errors, int* rtt_avg, 50 time_t* last_sample_time); 51 52 LIBNETD_RESOLV_PUBLIC int android_net_res_stats_get_info_for_net( 53 unsigned netid, int* nscount, sockaddr_storage servers[MAXNS], int* dcount, 54 char domains[MAXDNSRCH][MAXDNSRCHPATH], res_params* params, res_stats stats[MAXNS], 55 int* wait_for_pending_req_timeout_count); 56 57 // Returns an array of bools indicating which servers are considered good 58 LIBNETD_RESOLV_PUBLIC int android_net_res_stats_get_usable_servers(const res_params* params, 59 res_stats stats[], int nscount, 60 bool valid_servers[]); 61 62 #endif // NETD_RES_STATS_H 63