blob: 7bfe845ae65f403c5b4b2a5bc21964f7152cab5e [file] [log] [blame]
Bernie Innocenti318ed2d2018-08-30 04:05:20 +09001/*
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 Innocentiac18b122018-10-01 23:10:18 +090017#ifndef NETD_RES_STATS_H
18#define NETD_RES_STATS_H
Bernie Innocenti318ed2d2018-08-30 04:05:20 +090019
Bernie Innocenti318ed2d2018-08-30 04:05:20 +090020#include <stdbool.h>
21#include <stdint.h>
Bernie Innocenti8ad893f2018-08-31 14:09:46 +090022#include <sys/socket.h>
Bernie Innocenti318ed2d2018-08-30 04:05:20 +090023#include <time.h>
24
Bernie Innocentiac18b122018-10-01 23:10:18 +090025#include "params.h"
Bernie Innocenti318ed2d2018-08-30 04:05:20 +090026
Bernie Innocenti8ad893f2018-08-31 14:09:46 +090027#define RCODE_INTERNAL_ERROR 254
28#define RCODE_TIMEOUT 255
Bernie Innocenti318ed2d2018-08-30 04:05:20 +090029
Bernie Innocentiac18b122018-10-01 23:10:18 +090030struct res_sample {
Bernie Innocenti8ad893f2018-08-31 14:09:46 +090031 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 Innocenti318ed2d2018-08-30 04:05:20 +090034};
35
Bernie Innocentiac18b122018-10-01 23:10:18 +090036// Resolver reachability statistics and run-time parameters.
37struct res_stats {
Bernie Innocenti318ed2d2018-08-30 04:05:20 +090038 // Stats of the last <sample_count> queries.
Bernie Innocentiac18b122018-10-01 23:10:18 +090039 res_sample samples[MAXNSSAMPLES];
Bernie Innocenti318ed2d2018-08-30 04:05:20 +090040 // The number of samples stored.
Bernie Innocenti8ad893f2018-08-31 14:09:46 +090041 uint8_t sample_count;
Bernie Innocenti318ed2d2018-08-30 04:05:20 +090042 // The next sample to modify.
Bernie Innocenti8ad893f2018-08-31 14:09:46 +090043 uint8_t sample_next;
Bernie Innocenti318ed2d2018-08-30 04:05:20 +090044};
45
Bernie Innocenti8fca66a2018-09-25 14:23:19 +090046// Aggregates the reachability statistics for the given server based on on the stored samples.
Bernie Innocentiac18b122018-10-01 23:10:18 +090047LIBNETD_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 Innocenti318ed2d2018-08-30 04:05:20 +090051
Bernie Innocenti8fca66a2018-09-25 14:23:19 +090052LIBNETD_RESOLV_PUBLIC int android_net_res_stats_get_info_for_net(
53 unsigned netid, int* nscount, sockaddr_storage servers[MAXNS], int* dcount,
Bernie Innocenti758005f2019-02-19 18:08:36 +090054 char domains[MAXDNSRCH][MAXDNSRCHPATH], res_params* params, res_stats stats[MAXNS],
Ken Chen92bed612018-12-22 21:46:55 +080055 int* wait_for_pending_req_timeout_count);
Bernie Innocenti318ed2d2018-08-30 04:05:20 +090056
Bernie Innocenti8fca66a2018-09-25 14:23:19 +090057// Returns an array of bools indicating which servers are considered good
Luke Huang70931aa2019-01-31 11:57:41 +080058LIBNETD_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 Innocenti318ed2d2018-08-30 04:05:20 +090061
Bernie Innocentiac18b122018-10-01 23:10:18 +090062#endif // NETD_RES_STATS_H