]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
- Fix testbound test program to accurately output packets from hex. master
authorW.C.A. Wijngaards <wouter@nlnetlabs.nl>
Fri, 1 Aug 2025 08:34:12 +0000 (10:34 +0200)
committerW.C.A. Wijngaards <wouter@nlnetlabs.nl>
Fri, 1 Aug 2025 08:34:12 +0000 (10:34 +0200)
doc/Changelog
testcode/fake_event.c

index 10b5d95d84bba43e9eabde90506b69304139d005..883920b77b22beacf02d24be0f5854057ed95c43 100644 (file)
@@ -1,3 +1,6 @@
+1 August 2025: Wouter
+       - Fix testbound test program to accurately output packets from hex.
+
 28 July 2025: Wouter
        - Fix redis cachedb module gettimeofday init failure.
 
index ea05ea1edd08bc5ff516d2b11887086f1731965f..ce439edd1294a1fb998a1aefbcfff1ffb471db75 100644 (file)
@@ -188,6 +188,22 @@ delete_replay_answer(struct replay_answer* a)
        free(a);
 }
 
+/** Log the packet for a reply_packet from testpkts. */
+static void
+log_testpkt_reply_pkt(const char* txt, struct reply_packet* reppkt)
+{
+       if(!reppkt) {
+               log_info("%s <null>", txt);
+               return;
+       }
+       if(reppkt->reply_from_hex) {
+               log_pkt(txt, sldns_buffer_begin(reppkt->reply_from_hex),
+                       sldns_buffer_limit(reppkt->reply_from_hex));
+               return;
+       }
+       log_pkt(txt, reppkt->reply_pkt, reppkt->reply_len);
+}
+
 /**
  * return: true if pending query matches the now event.
  */
@@ -240,9 +256,8 @@ pending_find_match(struct replay_runtime* runtime, struct entry** entry,
                                p->start_step, p->end_step, (*entry)->lineno);
                        if(p->addrlen != 0)
                                log_addr(0, "matched ip", &p->addr, p->addrlen);
-                       log_pkt("matched pkt: ",
-                               (*entry)->reply_list->reply_pkt,
-                               (*entry)->reply_list->reply_len);
+                       log_testpkt_reply_pkt("matched pkt: ",
+                               (*entry)->reply_list);
                        return 1;
                }
                p = p->next_range;
@@ -330,7 +345,7 @@ fill_buffer_with_reply(sldns_buffer* buffer, struct entry* entry, uint8_t* q,
                while(reppkt && i--)
                        reppkt = reppkt->next;
                if(!reppkt) fatal_exit("extra packet read from TCP stream but none is available");
-               log_pkt("extra_packet ", reppkt->reply_pkt, reppkt->reply_len);
+               log_testpkt_reply_pkt("extra packet ", reppkt);
        }
        if(reppkt->reply_from_hex) {
                c = sldns_buffer_begin(reppkt->reply_from_hex);
@@ -462,8 +477,7 @@ fake_front_query(struct replay_runtime* runtime, struct replay_moment *todo)
                repinfo.c->type = comm_udp;
        fill_buffer_with_reply(repinfo.c->buffer, todo->match, NULL, 0, 0);
        log_info("testbound: incoming QUERY");
-       log_pkt("query pkt", todo->match->reply_list->reply_pkt,
-               todo->match->reply_list->reply_len);
+       log_testpkt_reply_pkt("query pkt ", todo->match->reply_list);
        /* call the callback for incoming queries */
        if((*runtime->callback_query)(repinfo.c, runtime->cb_arg,
                NETEVENT_NOERROR, &repinfo)) {