]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
resolved: tests for dns_query_go() using a bypass query
authorJames Coglan <james@neighbourhood.ie>
Fri, 21 Jun 2024 16:01:01 +0000 (17:01 +0100)
committerJames Coglan <james@neighbourhood.ie>
Tue, 23 Jul 2024 13:17:23 +0000 (14:17 +0100)
src/resolve/test-dns-query.c

index 4f6d70f1c1f642f76ca0140c3853a0144f7c0b17..6d5e3a760abfd3a380804d34c3edf31618f36f80 100644 (file)
@@ -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);