Bernie Innocenti | 318ed2d | 2018-08-30 04:05:20 +0900 | [diff] [blame] | 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 | |
Bernie Innocenti | ac18b12 | 2018-10-01 23:10:18 +0900 | [diff] [blame] | 17 | #ifndef NETD_RES_STATS_H |
| 18 | #define NETD_RES_STATS_H |
Bernie Innocenti | 318ed2d | 2018-08-30 04:05:20 +0900 | [diff] [blame] | 19 | |
Bernie Innocenti | 318ed2d | 2018-08-30 04:05:20 +0900 | [diff] [blame] | 20 | #include <stdbool.h> |
| 21 | #include <stdint.h> |
Bernie Innocenti | 8ad893f | 2018-08-31 14:09:46 +0900 | [diff] [blame] | 22 | #include <sys/socket.h> |
Bernie Innocenti | 318ed2d | 2018-08-30 04:05:20 +0900 | [diff] [blame] | 23 | #include <time.h> |
| 24 | |
Bernie Innocenti | ac18b12 | 2018-10-01 23:10:18 +0900 | [diff] [blame] | 25 | #include "params.h" |
Bernie Innocenti | 318ed2d | 2018-08-30 04:05:20 +0900 | [diff] [blame] | 26 | |
Bernie Innocenti | 8ad893f | 2018-08-31 14:09:46 +0900 | [diff] [blame] | 27 | #define RCODE_INTERNAL_ERROR 254 |
| 28 | #define RCODE_TIMEOUT 255 |
Bernie Innocenti | 318ed2d | 2018-08-30 04:05:20 +0900 | [diff] [blame] | 29 | |
Bernie Innocenti | ac18b12 | 2018-10-01 23:10:18 +0900 | [diff] [blame] | 30 | struct res_sample { |
Bernie Innocenti | 8ad893f | 2018-08-31 14:09:46 +0900 | [diff] [blame] | 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 |
Bernie Innocenti | 318ed2d | 2018-08-30 04:05:20 +0900 | [diff] [blame] | 34 | }; |
| 35 | |
Bernie Innocenti | ac18b12 | 2018-10-01 23:10:18 +0900 | [diff] [blame] | 36 | // Resolver reachability statistics and run-time parameters. |
| 37 | struct res_stats { |
Bernie Innocenti | 318ed2d | 2018-08-30 04:05:20 +0900 | [diff] [blame] | 38 | // Stats of the last <sample_count> queries. |
Bernie Innocenti | ac18b12 | 2018-10-01 23:10:18 +0900 | [diff] [blame] | 39 | res_sample samples[MAXNSSAMPLES]; |
Bernie Innocenti | 318ed2d | 2018-08-30 04:05:20 +0900 | [diff] [blame] | 40 | // The number of samples stored. |
Bernie Innocenti | 8ad893f | 2018-08-31 14:09:46 +0900 | [diff] [blame] | 41 | uint8_t sample_count; |
Bernie Innocenti | 318ed2d | 2018-08-30 04:05:20 +0900 | [diff] [blame] | 42 | // The next sample to modify. |
Bernie Innocenti | 8ad893f | 2018-08-31 14:09:46 +0900 | [diff] [blame] | 43 | uint8_t sample_next; |
Bernie Innocenti | 318ed2d | 2018-08-30 04:05:20 +0900 | [diff] [blame] | 44 | }; |
| 45 | |
Bernie Innocenti | 8fca66a | 2018-09-25 14:23:19 +0900 | [diff] [blame] | 46 | // Aggregates the reachability statistics for the given server based on on the stored samples. |
Bernie Innocenti | ac18b12 | 2018-10-01 23:10:18 +0900 | [diff] [blame] | 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); |
Bernie Innocenti | 318ed2d | 2018-08-30 04:05:20 +0900 | [diff] [blame] | 51 | |
Bernie Innocenti | 8fca66a | 2018-09-25 14:23:19 +0900 | [diff] [blame] | 52 | LIBNETD_RESOLV_PUBLIC int android_net_res_stats_get_info_for_net( |
| 53 | unsigned netid, int* nscount, sockaddr_storage servers[MAXNS], int* dcount, |
Bernie Innocenti | 758005f | 2019-02-19 18:08:36 +0900 | [diff] [blame] | 54 | char domains[MAXDNSRCH][MAXDNSRCHPATH], res_params* params, res_stats stats[MAXNS], |
Ken Chen | 92bed61 | 2018-12-22 21:46:55 +0800 | [diff] [blame] | 55 | int* wait_for_pending_req_timeout_count); |
Bernie Innocenti | 318ed2d | 2018-08-30 04:05:20 +0900 | [diff] [blame] | 56 | |
Bernie Innocenti | 8fca66a | 2018-09-25 14:23:19 +0900 | [diff] [blame] | 57 | // Returns an array of bools indicating which servers are considered good |
Luke Huang | 70931aa | 2019-01-31 11:57:41 +0800 | [diff] [blame] | 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[]); |
Bernie Innocenti | 318ed2d | 2018-08-30 04:05:20 +0900 | [diff] [blame] | 61 | |
Bernie Innocenti | ac18b12 | 2018-10-01 23:10:18 +0900 | [diff] [blame] | 62 | #endif // NETD_RES_STATS_H |