aboutsummaryrefslogtreecommitdiff
path: root/contrib/unbound/testcode/fake_event.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/unbound/testcode/fake_event.c')
-rw-r--r--contrib/unbound/testcode/fake_event.c46
1 files changed, 34 insertions, 12 deletions
diff --git a/contrib/unbound/testcode/fake_event.c b/contrib/unbound/testcode/fake_event.c
index f7f3210790eb..ce439edd1294 100644
--- a/contrib/unbound/testcode/fake_event.c
+++ b/contrib/unbound/testcode/fake_event.c
@@ -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)) {
@@ -900,8 +914,10 @@ run_scenario(struct replay_runtime* runtime)
runtime->now->evt_type == repevt_front_reply) {
answer_check_it(runtime);
advance_moment(runtime);
- } else if(pending_matches_range(runtime, &entry, &pending)) {
- answer_callback_from_entry(runtime, entry, pending);
+ } else if(runtime->now && pending_matches_range(runtime,
+ &entry, &pending)) {
+ if(entry)
+ answer_callback_from_entry(runtime, entry, pending);
} else {
do_moment_and_advance(runtime);
}
@@ -1254,7 +1270,7 @@ struct serviced_query* outnet_serviced_query(struct outside_network* outnet,
struct query_info* qinfo, uint16_t flags, int dnssec,
int ATTR_UNUSED(want_dnssec), int ATTR_UNUSED(nocaps),
int ATTR_UNUSED(check_ratelimit),
- int ATTR_UNUSED(tcp_upstream), int ATTR_UNUSED(ssl_upstream),
+ int tcp_upstream, int ATTR_UNUSED(ssl_upstream),
char* ATTR_UNUSED(tls_auth_name), struct sockaddr_storage* addr,
socklen_t addrlen, uint8_t* zone, size_t zonelen,
struct module_qstate* qstate, comm_point_callback_type* callback,
@@ -1274,7 +1290,7 @@ struct serviced_query* outnet_serviced_query(struct outside_network* outnet,
(flags&~(BIT_RD|BIT_CD))?" MORE":"", (dnssec)?" DO":"");
/* create packet with EDNS */
- pend->buffer = sldns_buffer_new(512);
+ pend->buffer = sldns_buffer_new(4096);
log_assert(pend->buffer);
sldns_buffer_write_u16(pend->buffer, 0); /* id */
sldns_buffer_write_u16(pend->buffer, flags);
@@ -1334,7 +1350,13 @@ struct serviced_query* outnet_serviced_query(struct outside_network* outnet,
edns.opt_list_in = NULL;
edns.opt_list_out = per_upstream_opt_list;
edns.opt_list_inplace_cb_out = NULL;
- attach_edns_record(pend->buffer, &edns);
+ if(sldns_buffer_capacity(pend->buffer) >=
+ sldns_buffer_limit(pend->buffer)
+ +calc_edns_field_size(&edns)) {
+ attach_edns_record(pend->buffer, &edns);
+ } else {
+ verbose(VERB_ALGO, "edns field too large to fit");
+ }
}
memcpy(&pend->addr, addr, addrlen);
pend->addrlen = addrlen;
@@ -1345,7 +1367,7 @@ struct serviced_query* outnet_serviced_query(struct outside_network* outnet,
pend->callback = callback;
pend->cb_arg = callback_arg;
pend->timeout = UDP_AUTH_QUERY_TIMEOUT/1000;
- pend->transport = transport_udp; /* pretend UDP */
+ pend->transport = tcp_upstream?transport_tcp:transport_udp;
pend->pkt = NULL;
pend->runtime = runtime;
pend->serviced = 1;