From: James Coglan Date: Fri, 21 Jun 2024 16:01:01 +0000 (+0100) Subject: resolved: tests for dns_query_go() using a bypass query X-Git-Tag: v257-rc1~833^2~5 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5d5f86431ff61f7aea11418ad9d4620f4c5f0c93;p=thirdparty%2Fsystemd.git resolved: tests for dns_query_go() using a bypass query --- diff --git a/src/resolve/test-dns-query.c b/src/resolve/test-dns-query.c index 4f6d70f1c1f..6d5e3a760ab 100644 --- a/src/resolve/test-dns-query.c +++ b/src/resolve/test-dns-query.c @@ -646,11 +646,13 @@ static void dns_scope_freep(DnsScope **s) { typedef struct GoConfig { bool use_link; + bool use_bypass; } GoConfig; static GoConfig mk_go_config(void) { return (GoConfig) { - .use_link = false + .use_link = false, + .use_bypass = false }; } @@ -661,6 +663,7 @@ static void exercise_dns_query_go(GoConfig *cfg) { _cleanup_(dns_scope_freep) DnsScope *scope = NULL; _cleanup_(dns_question_unrefp) DnsQuestion *question = NULL; + _cleanup_(dns_packet_unrefp) DnsPacket *packet = NULL; _cleanup_(dns_query_freep) DnsQuery *query = NULL; DnsProtocol protocol = DNS_PROTOCOL_DNS; @@ -698,9 +701,22 @@ static void exercise_dns_query_go(GoConfig *cfg) { ASSERT_OK(dns_question_new_address(&question, AF_INET, "www.example.com", false)); ASSERT_NOT_NULL(question); - ASSERT_OK(dns_query_new(&manager, &query, question, question, NULL, ifindex, flags)); - ASSERT_NOT_NULL(query); + if (cfg->use_bypass) { + ASSERT_OK(dns_packet_new_query(&packet, protocol, 0, false)); + ASSERT_NOT_NULL(packet); + DNS_PACKET_HEADER(packet)->qdcount = htobe16(1); + packet->question = dns_question_ref(question); + ASSERT_OK(dns_packet_append_question(packet, question)); + + /* search domains must be turned off for bypass queries, otherwise dns_query_add_candidate() + * tries to extract the domain name from question_idna which cannot exist on bypasses. */ + flags |= SD_RESOLVED_NO_SEARCH; + ASSERT_OK(dns_query_new(&manager, &query, NULL, NULL, packet, ifindex, flags)); + } else { + ASSERT_OK(dns_query_new(&manager, &query, question, question, NULL, ifindex, flags)); + } + ASSERT_NOT_NULL(query); ASSERT_OK(dns_query_go(query)); dns_server_unref(server); @@ -708,12 +724,18 @@ static void exercise_dns_query_go(GoConfig *cfg) { } TEST(dns_query_go) { - GoConfig cfg1 = mk_go_config(); - exercise_dns_query_go(&cfg1); + GoConfig cfg; + + cfg = mk_go_config(); + exercise_dns_query_go(&cfg); + + cfg = mk_go_config(); + cfg.use_link = true; + exercise_dns_query_go(&cfg); - GoConfig cfg2 = mk_go_config(); - cfg2.use_link = true; - exercise_dns_query_go(&cfg2); + cfg = mk_go_config(); + cfg.use_bypass = true; + exercise_dns_query_go(&cfg); } DEFINE_TEST_MAIN(LOG_DEBUG);