From f9d75a163a50a5593687407b4a9e0821885d676c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Vladim=C3=ADr=20=C4=8Cun=C3=A1t?= Date: Tue, 24 May 2022 10:36:50 +0200 Subject: [PATCH] lib/selection debug logs: print one more line And that made the "NO6: is KO" line extraneous. Example in context: [select][14162.01] => id: '15271' choosing from addresses: 0 v4 + 1 v6; names to resolve: 6 v4 + 5 v6; force_resolve: 0; NO6: IPv6 is OK [select][14162.01] => id: '15271' choosing: 'ns1.p31.dynect.net.'@'2600:2000:2210::31#00053' with timeout 774 ms zone cut: 'amazon.com.' [select][14162.01] => id: '15271' updating: 'ns1.p31.dynect.net.'@'2600:2000:2210::31#00053' zone cut: 'amazon.com.' with rtt 316 to srtt: 311 and variance: 89 --- lib/selection.c | 4 +--- lib/selection.h | 4 ++++ lib/selection_iter.c | 23 +++++++++++++++++++++-- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/lib/selection.c b/lib/selection.c index a418fc045..0a112884c 100644 --- a/lib/selection.c +++ b/lib/selection.c @@ -76,7 +76,7 @@ static struct { uint8_t addr_prefixes[NO6_PREFIX_COUNT][NO6_PREFIX_BYTES]; } no6_est = { .len_used = 0 }; -static inline bool no6_is_bad(void) +bool no6_is_bad(void) { return no6_est.len_used == NO6_PREFIX_COUNT; } @@ -459,8 +459,6 @@ struct kr_transport *select_transport(const struct choice choices[], int choices /* "EXPLOIT": * choose a resolved address which seems best right now. */ chosen = best; - if (no6_is_bad()) - VERBOSE_MSG(NULL, "NO6: is KO [exploit]\n"); } /* Don't try the same server again when there are other choices to be explored */ diff --git a/lib/selection.h b/lib/selection.h index 81e111845..468638bf3 100644 --- a/lib/selection.h +++ b/lib/selection.h @@ -263,3 +263,7 @@ uint8_t *ip_to_bytes(const union kr_sockaddr *src, size_t len); */ void update_address_state(struct address_state *state, union kr_sockaddr *address, size_t address_len, struct kr_query *qry); + +/** @internal Return whether IPv6 is considered to be broken. */ +bool no6_is_bad(void); + diff --git a/lib/selection_iter.c b/lib/selection_iter.c index eff4c0b9c..c59a88c60 100644 --- a/lib/selection_iter.c +++ b/lib/selection_iter.c @@ -249,10 +249,29 @@ void iter_choose_transport(struct kr_query *qry, struct kr_transport **transport // Filter valid addresses and names from the tries int choices_len = get_valid_addresses(local_state, choices); int resolvable_len = get_resolvable_names(local_state, resolvable, qry); + bool * const force_resolve_p = &qry->server_selection.local_state->force_resolve; + + // Print some stats into debug logs. + if (kr_log_is_debug_qry(SELECTION, qry)) { + int v4_choices = 0; + for (int i = 0; i < choices_len; ++i) + if (choices[i].address.ip.sa_family == AF_INET) + ++v4_choices; + int v4_resolvable = 0; + for (int i = 0; i < resolvable_len; ++i) + if (resolvable[i].type == KR_TRANSPORT_RESOLVE_A) + ++v4_resolvable; + VERBOSE_MSG(qry, "=> id: '%05u' choosing from addresses: %d v4 + %d v6; " + "names to resolve: %d v4 + %d v6; " + "force_resolve: %d; NO6: IPv6 is %s\n", + qry->id, v4_choices, choices_len - v4_choices, + v4_resolvable, resolvable_len - v4_resolvable, + (int)*force_resolve_p, no6_is_bad() ? "KO" : "OK"); + } - if (qry->server_selection.local_state->force_resolve && resolvable_len) { + if (*force_resolve_p && resolvable_len) { choices_len = 0; - qry->server_selection.local_state->force_resolve = false; + *force_resolve_p = false; } bool tcp = qry->flags.TCP || qry->server_selection.local_state->truncated; -- 2.47.2