2 * testcode/fake_event.c - fake event handling that replays existing scenario.
4 * Copyright (c) 2007, NLnet Labs. All rights reserved.
6 * This software is open source.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
15 * Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
19 * Neither the name of the NLNET LABS nor the names of its contributors may
20 * be used to endorse or promote products derived from this software without
21 * specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
29 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 * Event service that replays a scenario.
39 * This implements the same exported symbols as the files:
41 * services/listen_dnsport.c
42 * services/outside_network.c
43 * But these do not actually access the network or events, instead
44 * the scenario is played.
48 #include "testcode/fake_event.h"
49 #include "util/netevent.h"
50 #include "util/net_help.h"
51 #include "util/data/msgparse.h"
52 #include "util/data/msgreply.h"
53 #include "util/data/msgencode.h"
54 #include "util/data/dname.h"
55 #include "util/config_file.h"
56 #include "services/listen_dnsport.h"
57 #include "services/outside_network.h"
58 #include "services/cache/infra.h"
59 #include "testcode/replay.h"
60 #include "testcode/testpkts.h"
62 #include "util/fptr_wlist.h"
63 #include "sldns/sbuffer.h"
64 #include "sldns/wire2str.h"
65 #include "sldns/str2wire.h"
70 /** unique code to check that fake_commpoint is that structure */
71 #define FAKE_COMMPOINT_TYPECODE 97347923
72 /** fake commpoint, stores information */
73 struct fake_commpoint {
76 /** if this is a udp outgoing type of commpoint */
78 /** if this is a tcp outgoing type of commpoint */
80 /** if this is a http outgoing type of commpoint. */
83 /** the callback, stored for usage */
84 comm_point_callback_type* cb;
85 /** the callback userarg, stored for usage */
88 struct replay_runtime* runtime;
89 /** the pending entry for this commpoint (if any) */
90 struct fake_pending* pending;
93 /** Global variable: the scenario. Saved here for when event_init is done. */
94 static struct replay_scenario* saved_scenario = NULL;
96 /** add timers and the values do not overflow or become negative */
98 timeval_add(struct timeval* d, const struct timeval* add)
101 d->tv_sec += add->tv_sec;
102 d->tv_usec += add->tv_usec;
103 if(d->tv_usec >= 1000000) {
104 d->tv_usec -= 1000000;
111 fake_temp_file(const char* adj, const char* id, char* buf, size_t len)
114 snprintf(buf, len, "testbound_%u%s%s.tmp",
115 (unsigned)getpid(), adj, id);
117 snprintf(buf, len, "/tmp/testbound_%u%s%s.tmp",
118 (unsigned)getpid(), adj, id);
123 fake_event_init(struct replay_scenario* scen)
125 saved_scenario = scen;
129 fake_event_cleanup(void)
131 replay_scenario_delete(saved_scenario);
132 saved_scenario = NULL;
135 /** helper function that logs a sldns_pkt packet to logfile */
137 log_pkt(const char* desc, uint8_t* pkt, size_t len)
139 char* str = sldns_wire2str_pkt(pkt, len);
141 fatal_exit("%s: (failed out of memory wire2str_pkt)", desc);
143 log_info("%s%s", desc, str);
149 * Returns a string describing the event type.
152 repevt_string(enum replay_event_type t)
155 case repevt_nothing: return "NOTHING";
156 case repevt_front_query: return "QUERY";
157 case repevt_front_reply: return "CHECK_ANSWER";
158 case repevt_timeout: return "TIMEOUT";
159 case repevt_time_passes: return "TIME_PASSES";
160 case repevt_back_reply: return "REPLY";
161 case repevt_back_query: return "CHECK_OUT_QUERY";
162 case repevt_autotrust_check: return "CHECK_AUTOTRUST";
163 case repevt_tempfile_check: return "CHECK_TEMPFILE";
164 case repevt_error: return "ERROR";
165 case repevt_assign: return "ASSIGN";
166 case repevt_traffic: return "TRAFFIC";
167 case repevt_infra_rtt: return "INFRA_RTT";
168 default: return "UNKNOWN";
172 /** delete a fake pending */
174 delete_fake_pending(struct fake_pending* pend)
179 sldns_buffer_free(pend->buffer);
184 /** delete a replay answer */
186 delete_replay_answer(struct replay_answer* a)
191 sldns_buffer_free(a->repinfo.c->buffer);
199 * return: true if pending query matches the now event.
202 pending_matches_current(struct replay_runtime* runtime,
203 struct entry** entry, struct fake_pending **pend)
205 struct fake_pending* p;
207 if(!runtime->now || runtime->now->evt_type != repevt_back_query
208 || !runtime->pending_list)
210 /* see if any of the pending queries matches */
211 for(p = runtime->pending_list; p; p = p->next) {
212 if(runtime->now->addrlen != 0 &&
213 sockaddr_cmp(&p->addr, p->addrlen, &runtime->now->addr,
214 runtime->now->addrlen) != 0)
216 if((e=find_match(runtime->now->match, p->pkt, p->pkt_len,
227 * Find the range that matches this pending message.
228 * @param runtime: runtime with current moment, and range list.
229 * @param entry: returns the pointer to entry that matches.
230 * @param pend: the pending that the entry must match.
231 * @return: true if a match is found.
234 pending_find_match(struct replay_runtime* runtime, struct entry** entry,
235 struct fake_pending* pend)
237 int timenow = runtime->now->time_step;
238 struct replay_range* p = runtime->scenario->range_list;
240 if(p->start_step <= timenow && timenow <= p->end_step &&
241 (p->addrlen == 0 || sockaddr_cmp(&p->addr, p->addrlen,
242 &pend->addr, pend->addrlen) == 0) &&
243 (*entry = find_match(p->match, pend->pkt, pend->pkt_len,
245 log_info("matched query time %d in range [%d, %d] "
246 "with entry line %d", timenow,
247 p->start_step, p->end_step, (*entry)->lineno);
249 log_addr(0, "matched ip", &p->addr, p->addrlen);
250 log_pkt("matched pkt: ",
251 (*entry)->reply_list->reply_pkt,
252 (*entry)->reply_list->reply_len);
261 * See if outgoing pending query matches an entry.
262 * @param runtime: runtime.
263 * @param entry: if true, the entry that matches is returned.
264 * @param pend: if true, the outgoing message that matches is returned.
265 * @return: true if pending query matches the now event.
268 pending_matches_range(struct replay_runtime* runtime,
269 struct entry** entry, struct fake_pending** pend)
271 struct fake_pending* p = runtime->pending_list;
272 /* slow, O(N*N), but it works as advertised with weird matching */
274 if(p->tcp_pkt_counter != 0) {
275 /* continue tcp transfer */
279 if(pending_find_match(runtime, entry, p)) {
289 * Remove the item from the pending list.
292 pending_list_delete(struct replay_runtime* runtime, struct fake_pending* pend)
294 struct fake_pending** prev = &runtime->pending_list;
295 struct fake_pending* p = runtime->pending_list;
300 delete_fake_pending(pend);
309 /** number of replies in entry */
311 count_reply_packets(struct entry* entry)
314 struct reply_packet* reppkt = entry->reply_list;
317 reppkt = reppkt->next;
323 * Fill buffer with reply from the entry.
326 fill_buffer_with_reply(sldns_buffer* buffer, struct entry* entry, uint8_t* q,
327 size_t qlen, int tcp_pkt_counter)
329 struct reply_packet* reppkt;
332 log_assert(entry && entry->reply_list);
333 sldns_buffer_clear(buffer);
334 reppkt = entry->reply_list;
335 if(tcp_pkt_counter > 0) {
336 int i = tcp_pkt_counter;
338 reppkt = reppkt->next;
339 if(!reppkt) fatal_exit("extra packet read from TCP stream but none is available");
340 log_pkt("extra_packet ", reppkt->reply_pkt, reppkt->reply_len);
342 if(reppkt->reply_from_hex) {
343 c = sldns_buffer_begin(reppkt->reply_from_hex);
344 clen = sldns_buffer_limit(reppkt->reply_from_hex);
345 if(!c) fatal_exit("out of memory");
347 c = reppkt->reply_pkt;
348 clen = reppkt->reply_len;
351 if(q) adjust_packet(entry, &c, &clen, q, qlen);
352 sldns_buffer_write(buffer, c, clen);
355 sldns_buffer_flip(buffer);
359 * Perform range entry on pending message.
360 * @param runtime: runtime buffer size preference.
361 * @param entry: entry that codes for the reply to do.
362 * @param pend: pending query that is answered, callback called.
365 answer_callback_from_entry(struct replay_runtime* runtime,
366 struct entry* entry, struct fake_pending* pend)
369 struct comm_reply repinfo;
370 void* cb_arg = pend->cb_arg;
371 comm_point_callback_type* cb = pend->callback;
373 memset(&c, 0, sizeof(c));
375 c.buffer = sldns_buffer_new(runtime->bufsize);
377 if(pend->transport == transport_tcp) {
379 c.tcp_timeout_msec = 30000;
380 c.tcp_keepalive = runtime->tcp_seen_keepalive;
382 fill_buffer_with_reply(c.buffer, entry, pend->pkt, pend->pkt_len,
383 pend->tcp_pkt_counter);
385 repinfo.addrlen = pend->addrlen;
386 memcpy(&repinfo.addr, &pend->addr, pend->addrlen);
387 if(!pend->serviced) {
388 if(entry && entry->reply_list->next &&
389 pend->tcp_pkt_counter < count_reply_packets(entry)) {
390 /* go to next packet next time */
391 pend->tcp_pkt_counter++;
393 pending_list_delete(runtime, pend);
396 if((*cb)(&c, cb_arg, NETEVENT_NOERROR, &repinfo)) {
397 fatal_exit("testbound: unexpected: callback returned 1");
399 sldns_buffer_free(c.buffer);
402 /** Check the now moment answer check event */
404 answer_check_it(struct replay_runtime* runtime)
406 struct replay_answer* ans = runtime->answer_list,
408 log_assert(runtime && runtime->now &&
409 runtime->now->evt_type == repevt_front_reply);
411 enum transport_type tr = transport_tcp;
412 if(ans->repinfo.c->type == comm_udp)
414 if((runtime->now->addrlen == 0 || sockaddr_cmp(
415 &runtime->now->addr, runtime->now->addrlen,
416 &ans->repinfo.addr, ans->repinfo.addrlen) == 0) &&
417 find_match(runtime->now->match, ans->pkt,
419 log_info("testbound matched event entry from line %d",
420 runtime->now->match->lineno);
421 log_info("testbound: do STEP %d %s",
422 runtime->now->time_step,
423 repevt_string(runtime->now->evt_type));
425 prev->next = ans->next;
426 else runtime->answer_list = ans->next;
428 runtime->answer_last = prev;
429 if(ans->repinfo.c->tcp_keepalive)
430 runtime->tcp_seen_keepalive = 1;
431 delete_replay_answer(ans);
438 log_info("testbound: do STEP %d %s", runtime->now->time_step,
439 repevt_string(runtime->now->evt_type));
440 fatal_exit("testbound: not matched");
444 * Create commpoint (as return address) for a fake incoming query.
447 fake_front_query(struct replay_runtime* runtime, struct replay_moment *todo)
449 struct comm_reply repinfo;
450 memset(&repinfo, 0, sizeof(repinfo));
451 repinfo.c = (struct comm_point*)calloc(1, sizeof(struct comm_point));
452 repinfo.addrlen = (socklen_t)sizeof(struct sockaddr_in);
453 if(todo->addrlen != 0) {
454 repinfo.addrlen = todo->addrlen;
455 memcpy(&repinfo.addr, &todo->addr, todo->addrlen);
458 repinfo.c->ev = (struct internal_event*)runtime;
459 repinfo.c->buffer = sldns_buffer_new(runtime->bufsize);
460 if(todo->match->match_transport == transport_tcp) {
461 repinfo.c->type = comm_tcp;
462 repinfo.c->tcp_timeout_msec = 30000;
463 repinfo.c->tcp_keepalive = runtime->tcp_seen_keepalive;
465 repinfo.c->type = comm_udp;
466 fill_buffer_with_reply(repinfo.c->buffer, todo->match, NULL, 0, 0);
467 log_info("testbound: incoming QUERY");
468 log_pkt("query pkt", todo->match->reply_list->reply_pkt,
469 todo->match->reply_list->reply_len);
470 /* call the callback for incoming queries */
471 if((*runtime->callback_query)(repinfo.c, runtime->cb_arg,
472 NETEVENT_NOERROR, &repinfo)) {
473 /* send immediate reply */
474 comm_point_send_reply(&repinfo);
476 /* clear it again, in case copy not done properly */
477 memset(&repinfo, 0, sizeof(repinfo));
481 * Perform callback for fake pending message.
484 fake_pending_callback(struct replay_runtime* runtime,
485 struct replay_moment* todo, int error)
487 struct fake_pending* p = runtime->pending_list;
488 struct comm_reply repinfo;
491 comm_point_callback_type* cb;
493 memset(&c, 0, sizeof(c));
494 if(!p) fatal_exit("No pending queries.");
497 c.buffer = sldns_buffer_new(runtime->bufsize);
499 if(p->transport == transport_tcp) {
501 c.tcp_timeout_msec = 30000;
502 c.tcp_keepalive = runtime->tcp_seen_keepalive;
504 if(todo->evt_type == repevt_back_reply && todo->match) {
505 fill_buffer_with_reply(c.buffer, todo->match, p->pkt,
506 p->pkt_len, p->tcp_pkt_counter);
509 repinfo.addrlen = p->addrlen;
510 memcpy(&repinfo.addr, &p->addr, p->addrlen);
512 if(todo->match && todo->match->reply_list->next && !error &&
513 p->tcp_pkt_counter < count_reply_packets(todo->match)) {
514 /* go to next packet next time */
515 p->tcp_pkt_counter++;
517 pending_list_delete(runtime, p);
520 if((*cb)(&c, cb_arg, error, &repinfo)) {
521 fatal_exit("unexpected: pending callback returned 1");
523 /* delete the pending item. */
524 sldns_buffer_free(c.buffer);
529 moment_assign(struct replay_runtime* runtime, struct replay_moment* mom)
531 char* value = macro_process(runtime->vars, runtime, mom->string);
533 fatal_exit("could not process macro step %d", mom->time_step);
534 log_info("assign %s = %s", mom->variable, value);
535 if(!macro_assign(runtime->vars, mom->variable, value))
536 fatal_exit("out of memory storing macro");
538 if(verbosity >= VERB_ALGO)
539 macro_print_debug(runtime->vars);
544 time_passes(struct replay_runtime* runtime, struct replay_moment* mom)
546 struct fake_timer *t;
547 struct timeval tv = mom->elapse;
549 char* xp = macro_process(runtime->vars, runtime, mom->string);
551 if(!xp) fatal_exit("could not macro expand %s", mom->string);
552 verbose(VERB_ALGO, "EVAL %s", mom->string);
557 tv.tv_usec = (int)((sec - (double)tv.tv_sec) *1000000. + 0.5);
560 timeval_add(&runtime->now_tv, &tv);
561 runtime->now_secs = (time_t)runtime->now_tv.tv_sec;
563 log_info("elapsed %d.%6.6d now %d.%6.6d",
564 (int)tv.tv_sec, (int)tv.tv_usec,
565 (int)runtime->now_tv.tv_sec, (int)runtime->now_tv.tv_usec);
567 /* see if any timers have fired; and run them */
568 while( (t=replay_get_oldest_timer(runtime)) ) {
570 log_info("fake_timer callback");
571 fptr_ok(fptr_whitelist_comm_timer(t->cb));
576 /** check autotrust file contents */
578 autotrust_check(struct replay_runtime* runtime, struct replay_moment* mom)
580 char name[1024], line[1024];
582 int lineno = 0, oke=1;
584 struct config_strlist* p;
585 line[sizeof(line)-1] = 0;
586 log_assert(mom->autotrust_id);
587 fake_temp_file("_auto_", mom->autotrust_id, name, sizeof(name));
588 in = fopen(name, "r");
589 if(!in) fatal_exit("could not open %s: %s", name, strerror(errno));
590 for(p=mom->file_content; p; p=p->next) {
592 if(!fgets(line, (int)sizeof(line)-1, in)) {
593 log_err("autotrust check failed, could not read line");
594 log_err("file %s, line %d", name, lineno);
595 log_err("should be: %s", p->str);
596 fatal_exit("autotrust_check failed");
598 if(line[0]) line[strlen(line)-1] = 0; /* remove newline */
599 expanded = macro_process(runtime->vars, runtime, p->str);
601 fatal_exit("could not expand macro line %d", lineno);
602 if(verbosity >= 7 && strcmp(p->str, expanded) != 0)
603 log_info("expanded '%s' to '%s'", p->str, expanded);
604 if(strcmp(expanded, line) != 0) {
605 log_err("mismatch in file %s, line %d", name, lineno);
606 log_err("file has : %s", line);
607 log_err("should be: %s", expanded);
613 fprintf(stderr, "%s:%2d ok : %s\n", name, lineno, line);
615 if(fgets(line, (int)sizeof(line)-1, in)) {
616 log_err("autotrust check failed, extra lines in %s after %d",
619 fprintf(stderr, "file has: %s", line);
620 } while(fgets(line, (int)sizeof(line)-1, in));
625 fatal_exit("autotrust_check STEP %d failed", mom->time_step);
626 log_info("autotrust %s is OK", mom->autotrust_id);
629 /** check tempfile file contents */
631 tempfile_check(struct replay_runtime* runtime, struct replay_moment* mom)
633 char name[1024], line[1024];
635 int lineno = 0, oke=1;
637 struct config_strlist* p;
638 line[sizeof(line)-1] = 0;
639 log_assert(mom->autotrust_id);
640 fake_temp_file("_temp_", mom->autotrust_id, name, sizeof(name));
641 in = fopen(name, "r");
642 if(!in) fatal_exit("could not open %s: %s", name, strerror(errno));
643 for(p=mom->file_content; p; p=p->next) {
645 if(!fgets(line, (int)sizeof(line)-1, in)) {
646 log_err("tempfile check failed, could not read line");
647 log_err("file %s, line %d", name, lineno);
648 log_err("should be: %s", p->str);
649 fatal_exit("tempfile_check failed");
651 if(line[0]) line[strlen(line)-1] = 0; /* remove newline */
652 expanded = macro_process(runtime->vars, runtime, p->str);
654 fatal_exit("could not expand macro line %d", lineno);
655 if(verbosity >= 7 && strcmp(p->str, expanded) != 0)
656 log_info("expanded '%s' to '%s'", p->str, expanded);
657 if(strcmp(expanded, line) != 0) {
658 log_err("mismatch in file %s, line %d", name, lineno);
659 log_err("file has : %s", line);
660 log_err("should be: %s", expanded);
666 fprintf(stderr, "%s:%2d ok : %s\n", name, lineno, line);
668 if(fgets(line, (int)sizeof(line)-1, in)) {
669 log_err("tempfile check failed, extra lines in %s after %d",
672 fprintf(stderr, "file has: %s", line);
673 } while(fgets(line, (int)sizeof(line)-1, in));
678 fatal_exit("tempfile_check STEP %d failed", mom->time_step);
679 log_info("tempfile %s is OK", mom->autotrust_id);
682 /** Store RTT in infra cache */
684 do_infra_rtt(struct replay_runtime* runtime)
686 struct replay_moment* now = runtime->now;
689 uint8_t* dp = sldns_str2wire_dname(now->variable, &dplen);
690 if(!dp) fatal_exit("cannot parse %s", now->variable);
691 rto = infra_rtt_update(runtime->infra, &now->addr, now->addrlen,
692 dp, dplen, LDNS_RR_TYPE_A, atoi(now->string),
693 -1, runtime->now_secs);
694 log_addr(0, "INFRA_RTT for", &now->addr, now->addrlen);
695 log_info("INFRA_RTT(%s roundtrip %d): rto of %d", now->variable,
696 atoi(now->string), rto);
697 if(rto == 0) fatal_exit("infra_rtt_update failed");
701 /** perform exponential backoff on the timeout */
703 expon_timeout_backoff(struct replay_runtime* runtime)
705 struct fake_pending* p = runtime->pending_list;
707 uint8_t edns_lame_known;
709 if(!p) return; /* no pending packet to backoff */
710 if(!infra_host(runtime->infra, &p->addr, p->addrlen, p->zone,
711 p->zonelen, runtime->now_secs, &vs, &edns_lame_known, &rtt))
714 rto = infra_rtt_update(runtime->infra, &p->addr, p->addrlen, p->zone,
715 p->zonelen, p->qtype, -1, last_rtt, runtime->now_secs);
716 log_info("infra_rtt_update returned rto %d", rto);
720 * Advance to the next moment.
723 advance_moment(struct replay_runtime* runtime)
726 runtime->now = runtime->scenario->mom_first;
727 else runtime->now = runtime->now->mom_next;
731 * Perform actions or checks determined by the moment.
732 * Also advances the time by one step.
733 * @param runtime: scenario runtime information.
736 do_moment_and_advance(struct replay_runtime* runtime)
738 struct replay_moment* mom;
740 advance_moment(runtime);
743 log_info("testbound: do STEP %d %s", runtime->now->time_step,
744 repevt_string(runtime->now->evt_type));
745 switch(runtime->now->evt_type) {
747 advance_moment(runtime);
749 case repevt_front_query:
750 /* advance moment before doing the step, so that the next
751 moment which may check some result of the mom step
752 can catch those results. */
754 advance_moment(runtime);
755 fake_front_query(runtime, mom);
757 case repevt_front_reply:
758 if(runtime->answer_list)
759 log_err("testbound: There are unmatched answers.");
760 fatal_exit("testbound: query answer not matched");
764 advance_moment(runtime);
765 expon_timeout_backoff(runtime);
766 fake_pending_callback(runtime, mom, NETEVENT_TIMEOUT);
768 case repevt_back_reply:
770 advance_moment(runtime);
771 fake_pending_callback(runtime, mom, NETEVENT_NOERROR);
773 case repevt_back_query:
774 /* Back queries are matched when they are sent out. */
775 log_err("No query matching the current moment was sent.");
776 fatal_exit("testbound: back query not matched");
780 advance_moment(runtime);
781 fake_pending_callback(runtime, mom, NETEVENT_CLOSED);
783 case repevt_time_passes:
784 time_passes(runtime, runtime->now);
785 advance_moment(runtime);
787 case repevt_autotrust_check:
788 autotrust_check(runtime, runtime->now);
789 advance_moment(runtime);
791 case repevt_tempfile_check:
792 tempfile_check(runtime, runtime->now);
793 advance_moment(runtime);
796 moment_assign(runtime, runtime->now);
797 advance_moment(runtime);
800 advance_moment(runtime);
802 case repevt_infra_rtt:
803 do_infra_rtt(runtime);
804 advance_moment(runtime);
807 fatal_exit("testbound: unknown event type %d",
808 runtime->now->evt_type);
812 /** run the scenario in event callbacks */
814 run_scenario(struct replay_runtime* runtime)
816 struct entry* entry = NULL;
817 struct fake_pending* pending = NULL;
818 int max_rounds = 5000;
820 runtime->now = runtime->scenario->mom_first;
821 log_info("testbound: entering fake runloop");
823 /* if moment matches pending query do it. */
824 /* else if moment matches given answer, do it */
825 /* else if precoded_range matches pending, do it */
826 /* else do the current moment */
827 if(pending_matches_current(runtime, &entry, &pending)) {
828 log_info("testbound: do STEP %d CHECK_OUT_QUERY",
829 runtime->now->time_step);
830 advance_moment(runtime);
832 answer_callback_from_entry(runtime, entry,
834 } else if(runtime->answer_list && runtime->now &&
835 runtime->now->evt_type == repevt_front_reply) {
836 answer_check_it(runtime);
837 advance_moment(runtime);
838 } else if(pending_matches_range(runtime, &entry, &pending)) {
839 answer_callback_from_entry(runtime, entry, pending);
841 do_moment_and_advance(runtime);
843 log_info("testbound: end of event stage");
845 if(rounds > max_rounds)
846 fatal_exit("testbound: too many rounds, it loops.");
847 } while(runtime->now);
849 if(runtime->pending_list) {
850 struct fake_pending* p;
851 log_err("testbound: there are still messages pending.");
852 for(p = runtime->pending_list; p; p=p->next) {
853 log_pkt("pending msg", p->pkt, p->pkt_len);
854 log_addr(0, "pending to", &p->addr, p->addrlen);
856 fatal_exit("testbound: there are still messages pending.");
858 if(runtime->answer_list) {
859 fatal_exit("testbound: there are unmatched answers.");
861 log_info("testbound: exiting fake runloop.");
862 runtime->exit_cleanly = 1;
865 /*********** Dummy routines ***********/
867 struct listen_dnsport*
868 listen_create(struct comm_base* base, struct listen_port* ATTR_UNUSED(ports),
869 size_t bufsize, int ATTR_UNUSED(tcp_accept_count),
870 int ATTR_UNUSED(tcp_idle_timeout),
871 struct tcl_list* ATTR_UNUSED(tcp_conn_limit),
872 void* ATTR_UNUSED(sslctx), struct dt_env* ATTR_UNUSED(dtenv),
873 comm_point_callback_type* cb, void* cb_arg)
875 struct replay_runtime* runtime = (struct replay_runtime*)base;
876 struct listen_dnsport* l= calloc(1, sizeof(struct listen_dnsport));
880 l->udp_buff = sldns_buffer_new(bufsize);
885 runtime->callback_query = cb;
886 runtime->cb_arg = cb_arg;
887 runtime->bufsize = bufsize;
892 listen_delete(struct listen_dnsport* listen)
896 sldns_buffer_free(listen->udp_buff);
901 comm_base_create(int ATTR_UNUSED(sigs))
903 /* we return the runtime structure instead. */
904 struct replay_runtime* runtime = (struct replay_runtime*)
905 calloc(1, sizeof(struct replay_runtime));
906 runtime->scenario = saved_scenario;
907 runtime->vars = macro_store_create();
908 if(!runtime->vars) fatal_exit("out of memory");
909 return (struct comm_base*)runtime;
913 comm_base_delete(struct comm_base* b)
915 struct replay_runtime* runtime = (struct replay_runtime*)b;
916 struct fake_pending* p, *np;
917 struct replay_answer* a, *na;
918 struct fake_timer* t, *nt;
921 runtime->scenario= NULL;
922 p = runtime->pending_list;
925 delete_fake_pending(p);
928 a = runtime->answer_list;
931 delete_replay_answer(a);
934 t = runtime->timer_list;
940 macro_store_delete(runtime->vars);
945 comm_base_timept(struct comm_base* b, time_t** tt, struct timeval** tv)
947 struct replay_runtime* runtime = (struct replay_runtime*)b;
948 *tt = &runtime->now_secs;
949 *tv = &runtime->now_tv;
953 comm_base_dispatch(struct comm_base* b)
955 struct replay_runtime* runtime = (struct replay_runtime*)b;
956 run_scenario(runtime);
958 (*runtime->sig_cb)(SIGTERM, runtime->sig_cb_arg);
959 else exit(0); /* OK exit when LIBEVENT_SIGNAL_PROBLEM exists */
963 comm_base_exit(struct comm_base* b)
965 struct replay_runtime* runtime = (struct replay_runtime*)b;
966 if(!runtime->exit_cleanly) {
967 /* some sort of failure */
968 fatal_exit("testbound: comm_base_exit was called.");
973 comm_signal_create(struct comm_base* base,
974 void (*callback)(int, void*), void* cb_arg)
976 struct replay_runtime* runtime = (struct replay_runtime*)base;
977 runtime->sig_cb = callback;
978 runtime->sig_cb_arg = cb_arg;
979 return calloc(1, sizeof(struct comm_signal));
983 comm_signal_bind(struct comm_signal* ATTR_UNUSED(comsig), int
990 comm_signal_delete(struct comm_signal* comsig)
996 comm_point_send_reply(struct comm_reply* repinfo)
998 struct replay_answer* ans = (struct replay_answer*)calloc(1,
999 sizeof(struct replay_answer));
1000 struct replay_runtime* runtime = (struct replay_runtime*)repinfo->c->ev;
1001 log_info("testbound: comm_point_send_reply fake");
1002 /* dump it into the todo list */
1004 memcpy(&ans->repinfo, repinfo, sizeof(struct comm_reply));
1006 if(runtime->answer_last)
1007 runtime->answer_last->next = ans;
1008 else runtime->answer_list = ans;
1009 runtime->answer_last = ans;
1011 /* try to parse packet */
1012 ans->pkt = memdup(sldns_buffer_begin(ans->repinfo.c->buffer),
1013 sldns_buffer_limit(ans->repinfo.c->buffer));
1014 ans->pkt_len = sldns_buffer_limit(ans->repinfo.c->buffer);
1015 if(!ans->pkt) fatal_exit("out of memory");
1016 log_pkt("reply pkt: ", ans->pkt, ans->pkt_len);
1020 comm_point_drop_reply(struct comm_reply* repinfo)
1022 log_info("comm_point_drop_reply fake");
1024 sldns_buffer_free(repinfo->c->buffer);
1029 struct outside_network*
1030 outside_network_create(struct comm_base* base, size_t bufsize,
1031 size_t ATTR_UNUSED(num_ports), char** ATTR_UNUSED(ifs),
1032 int ATTR_UNUSED(num_ifs), int ATTR_UNUSED(do_ip4),
1033 int ATTR_UNUSED(do_ip6), size_t ATTR_UNUSED(num_tcp),
1034 int ATTR_UNUSED(dscp),
1035 struct infra_cache* infra,
1036 struct ub_randstate* ATTR_UNUSED(rnd),
1037 int ATTR_UNUSED(use_caps_for_id), int* ATTR_UNUSED(availports),
1038 int ATTR_UNUSED(numavailports), size_t ATTR_UNUSED(unwanted_threshold),
1039 int ATTR_UNUSED(outgoing_tcp_mss),
1040 void (*unwanted_action)(void*), void* ATTR_UNUSED(unwanted_param),
1041 int ATTR_UNUSED(do_udp), void* ATTR_UNUSED(sslctx),
1042 int ATTR_UNUSED(delayclose), int ATTR_UNUSED(tls_use_sni),
1043 struct dt_env* ATTR_UNUSED(dtenv))
1045 struct replay_runtime* runtime = (struct replay_runtime*)base;
1046 struct outside_network* outnet = calloc(1,
1047 sizeof(struct outside_network));
1048 (void)unwanted_action;
1051 runtime->infra = infra;
1052 outnet->base = base;
1053 outnet->udp_buff = sldns_buffer_new(bufsize);
1054 if(!outnet->udp_buff) {
1062 outside_network_delete(struct outside_network* outnet)
1066 sldns_buffer_free(outnet->udp_buff);
1071 outside_network_quit_prepare(struct outside_network* ATTR_UNUSED(outnet))
1076 pending_udp_query(struct serviced_query* sq, sldns_buffer* packet,
1077 int timeout, comm_point_callback_type* callback, void* callback_arg)
1079 struct replay_runtime* runtime = (struct replay_runtime*)
1081 struct fake_pending* pend = (struct fake_pending*)calloc(1,
1082 sizeof(struct fake_pending));
1084 pend->buffer = sldns_buffer_new(sldns_buffer_capacity(packet));
1085 log_assert(pend->buffer);
1086 sldns_buffer_write(pend->buffer, sldns_buffer_begin(packet),
1087 sldns_buffer_limit(packet));
1088 sldns_buffer_flip(pend->buffer);
1089 memcpy(&pend->addr, &sq->addr, sq->addrlen);
1090 pend->addrlen = sq->addrlen;
1091 pend->callback = callback;
1092 pend->cb_arg = callback_arg;
1093 pend->timeout = timeout/1000;
1094 pend->transport = transport_udp;
1098 pend->runtime = runtime;
1099 pend->pkt_len = sldns_buffer_limit(packet);
1100 pend->pkt = memdup(sldns_buffer_begin(packet), pend->pkt_len);
1101 if(!pend->pkt) fatal_exit("out of memory");
1102 log_pkt("pending udp pkt: ", pend->pkt, pend->pkt_len);
1104 /* see if it matches the current moment */
1105 if(runtime->now && runtime->now->evt_type == repevt_back_query &&
1106 (runtime->now->addrlen == 0 || sockaddr_cmp(
1107 &runtime->now->addr, runtime->now->addrlen,
1108 &pend->addr, pend->addrlen) == 0) &&
1109 find_match(runtime->now->match, pend->pkt, pend->pkt_len,
1111 log_info("testbound: matched pending to event. "
1112 "advance time between events.");
1113 log_info("testbound: do STEP %d %s", runtime->now->time_step,
1114 repevt_string(runtime->now->evt_type));
1115 advance_moment(runtime);
1116 /* still create the pending, because we need it to callback */
1118 log_info("testbound: created fake pending");
1120 pend->next = runtime->pending_list;
1121 runtime->pending_list = pend;
1122 return (struct pending*)pend;
1126 pending_tcp_query(struct serviced_query* sq, sldns_buffer* packet,
1127 int timeout, comm_point_callback_type* callback, void* callback_arg)
1129 struct replay_runtime* runtime = (struct replay_runtime*)
1131 struct fake_pending* pend = (struct fake_pending*)calloc(1,
1132 sizeof(struct fake_pending));
1134 pend->buffer = sldns_buffer_new(sldns_buffer_capacity(packet));
1135 log_assert(pend->buffer);
1136 sldns_buffer_write(pend->buffer, sldns_buffer_begin(packet),
1137 sldns_buffer_limit(packet));
1138 sldns_buffer_flip(pend->buffer);
1139 memcpy(&pend->addr, &sq->addr, sq->addrlen);
1140 pend->addrlen = sq->addrlen;
1141 pend->callback = callback;
1142 pend->cb_arg = callback_arg;
1143 pend->timeout = timeout/1000;
1144 pend->transport = transport_tcp;
1147 pend->runtime = runtime;
1149 pend->pkt_len = sldns_buffer_limit(packet);
1150 pend->pkt = memdup(sldns_buffer_begin(packet), pend->pkt_len);
1151 if(!pend->pkt) fatal_exit("out of memory");
1152 log_pkt("pending tcp pkt: ", pend->pkt, pend->pkt_len);
1154 /* see if it matches the current moment */
1155 if(runtime->now && runtime->now->evt_type == repevt_back_query &&
1156 (runtime->now->addrlen == 0 || sockaddr_cmp(
1157 &runtime->now->addr, runtime->now->addrlen,
1158 &pend->addr, pend->addrlen) == 0) &&
1159 find_match(runtime->now->match, pend->pkt, pend->pkt_len,
1161 log_info("testbound: matched pending to event. "
1162 "advance time between events.");
1163 log_info("testbound: do STEP %d %s", runtime->now->time_step,
1164 repevt_string(runtime->now->evt_type));
1165 advance_moment(runtime);
1166 /* still create the pending, because we need it to callback */
1168 log_info("testbound: created fake pending");
1170 pend->next = runtime->pending_list;
1171 runtime->pending_list = pend;
1172 return (struct waiting_tcp*)pend;
1175 struct serviced_query* outnet_serviced_query(struct outside_network* outnet,
1176 struct query_info* qinfo, uint16_t flags, int dnssec,
1177 int ATTR_UNUSED(want_dnssec), int ATTR_UNUSED(nocaps),
1178 int ATTR_UNUSED(tcp_upstream), int ATTR_UNUSED(ssl_upstream),
1179 char* ATTR_UNUSED(tls_auth_name), struct sockaddr_storage* addr,
1180 socklen_t addrlen, uint8_t* zone, size_t zonelen,
1181 struct module_qstate* qstate, comm_point_callback_type* callback,
1182 void* callback_arg, sldns_buffer* ATTR_UNUSED(buff),
1183 struct module_env* ATTR_UNUSED(env))
1185 struct replay_runtime* runtime = (struct replay_runtime*)outnet->base;
1186 struct fake_pending* pend = (struct fake_pending*)calloc(1,
1187 sizeof(struct fake_pending));
1190 log_nametypeclass(VERB_OPS, "pending serviced query",
1191 qinfo->qname, qinfo->qtype, qinfo->qclass);
1193 verbose(VERB_OPS, "pending serviced query zone %s flags%s%s%s%s",
1194 z, (flags&BIT_RD)?" RD":"", (flags&BIT_CD)?" CD":"",
1195 (flags&~(BIT_RD|BIT_CD))?" MORE":"", (dnssec)?" DO":"");
1197 /* create packet with EDNS */
1198 pend->buffer = sldns_buffer_new(512);
1199 log_assert(pend->buffer);
1200 sldns_buffer_write_u16(pend->buffer, 0); /* id */
1201 sldns_buffer_write_u16(pend->buffer, flags);
1202 sldns_buffer_write_u16(pend->buffer, 1); /* qdcount */
1203 sldns_buffer_write_u16(pend->buffer, 0); /* ancount */
1204 sldns_buffer_write_u16(pend->buffer, 0); /* nscount */
1205 sldns_buffer_write_u16(pend->buffer, 0); /* arcount */
1206 sldns_buffer_write(pend->buffer, qinfo->qname, qinfo->qname_len);
1207 sldns_buffer_write_u16(pend->buffer, qinfo->qtype);
1208 sldns_buffer_write_u16(pend->buffer, qinfo->qclass);
1209 sldns_buffer_flip(pend->buffer);
1211 struct edns_data edns;
1212 if(!inplace_cb_query_call(env, qinfo, flags, addr, addrlen,
1213 zone, zonelen, qstate, qstate->region)) {
1218 edns.edns_present = 1;
1220 edns.edns_version = EDNS_ADVERTISED_VERSION;
1221 edns.udp_size = EDNS_ADVERTISED_SIZE;
1223 edns.opt_list = qstate->edns_opts_back_out;
1225 edns.bits = EDNS_DO;
1226 attach_edns_record(pend->buffer, &edns);
1228 memcpy(&pend->addr, addr, addrlen);
1229 pend->addrlen = addrlen;
1230 pend->zone = memdup(zone, zonelen);
1231 pend->zonelen = zonelen;
1232 pend->qtype = (int)qinfo->qtype;
1233 log_assert(pend->zone);
1234 pend->callback = callback;
1235 pend->cb_arg = callback_arg;
1236 pend->timeout = UDP_AUTH_QUERY_TIMEOUT/1000;
1237 pend->transport = transport_udp; /* pretend UDP */
1239 pend->runtime = runtime;
1241 pend->pkt_len = sldns_buffer_limit(pend->buffer);
1242 pend->pkt = memdup(sldns_buffer_begin(pend->buffer), pend->pkt_len);
1243 if(!pend->pkt) fatal_exit("out of memory");
1244 /*log_pkt("pending serviced query: ", pend->pkt, pend->pkt_len);*/
1246 /* see if it matches the current moment */
1247 if(runtime->now && runtime->now->evt_type == repevt_back_query &&
1248 (runtime->now->addrlen == 0 || sockaddr_cmp(
1249 &runtime->now->addr, runtime->now->addrlen,
1250 &pend->addr, pend->addrlen) == 0) &&
1251 find_match(runtime->now->match, pend->pkt, pend->pkt_len,
1253 log_info("testbound: matched pending to event. "
1254 "advance time between events.");
1255 log_info("testbound: do STEP %d %s", runtime->now->time_step,
1256 repevt_string(runtime->now->evt_type));
1257 advance_moment(runtime);
1258 /* still create the pending, because we need it to callback */
1260 log_info("testbound: created fake pending");
1262 pend->next = runtime->pending_list;
1263 runtime->pending_list = pend;
1264 return (struct serviced_query*)pend;
1267 void outnet_serviced_query_stop(struct serviced_query* sq, void* cb_arg)
1269 struct fake_pending* pend = (struct fake_pending*)sq;
1270 struct replay_runtime* runtime = pend->runtime;
1271 /* delete from the list */
1272 struct fake_pending* p = runtime->pending_list, *prev=NULL;
1275 log_assert(p->cb_arg == cb_arg);
1277 log_info("serviced pending delete");
1279 prev->next = p->next;
1280 else runtime->pending_list = p->next;
1281 sldns_buffer_free(p->buffer);
1290 log_info("double delete of pending serviced query");
1293 struct listen_port* listening_ports_open(struct config_file* ATTR_UNUSED(cfg),
1294 int* ATTR_UNUSED(reuseport))
1296 return calloc(1, 1);
1299 void listening_ports_free(struct listen_port* list)
1304 struct comm_point* comm_point_create_local(struct comm_base* ATTR_UNUSED(base),
1305 int ATTR_UNUSED(fd), size_t ATTR_UNUSED(bufsize),
1306 comm_point_callback_type* ATTR_UNUSED(callback),
1307 void* ATTR_UNUSED(callback_arg))
1309 struct fake_commpoint* fc = (struct fake_commpoint*)calloc(1,
1311 if(!fc) return NULL;
1312 fc->typecode = FAKE_COMMPOINT_TYPECODE;
1313 return (struct comm_point*)fc;
1316 struct comm_point* comm_point_create_raw(struct comm_base* ATTR_UNUSED(base),
1317 int ATTR_UNUSED(fd), int ATTR_UNUSED(writing),
1318 comm_point_callback_type* ATTR_UNUSED(callback),
1319 void* ATTR_UNUSED(callback_arg))
1321 /* no pipe comm possible */
1322 struct fake_commpoint* fc = (struct fake_commpoint*)calloc(1,
1324 if(!fc) return NULL;
1325 fc->typecode = FAKE_COMMPOINT_TYPECODE;
1326 return (struct comm_point*)fc;
1329 void comm_point_start_listening(struct comm_point* ATTR_UNUSED(c),
1330 int ATTR_UNUSED(newfd), int ATTR_UNUSED(sec))
1332 /* no bg write pipe comm possible */
1335 void comm_point_stop_listening(struct comm_point* ATTR_UNUSED(c))
1337 /* no bg write pipe comm possible */
1340 /* only cmd com _local gets deleted */
1341 void comm_point_delete(struct comm_point* c)
1343 struct fake_commpoint* fc = (struct fake_commpoint*)c;
1344 if(c == NULL) return;
1345 log_assert(fc->typecode == FAKE_COMMPOINT_TYPECODE);
1346 if(fc->type_tcp_out) {
1347 /* remove tcp pending, so no more callbacks to it */
1348 pending_list_delete(fc->runtime, fc->pending);
1353 size_t listen_get_mem(struct listen_dnsport* ATTR_UNUSED(listen))
1358 size_t outnet_get_mem(struct outside_network* ATTR_UNUSED(outnet))
1363 size_t comm_point_get_mem(struct comm_point* ATTR_UNUSED(c))
1368 size_t serviced_get_mem(struct serviced_query* ATTR_UNUSED(c))
1373 /* fake for fptr wlist */
1374 int outnet_udp_cb(struct comm_point* ATTR_UNUSED(c),
1375 void* ATTR_UNUSED(arg), int ATTR_UNUSED(error),
1376 struct comm_reply *ATTR_UNUSED(reply_info))
1382 int outnet_tcp_cb(struct comm_point* ATTR_UNUSED(c),
1383 void* ATTR_UNUSED(arg), int ATTR_UNUSED(error),
1384 struct comm_reply *ATTR_UNUSED(reply_info))
1390 void pending_udp_timer_cb(void *ATTR_UNUSED(arg))
1395 void pending_udp_timer_delay_cb(void *ATTR_UNUSED(arg))
1400 void outnet_tcptimer(void* ATTR_UNUSED(arg))
1405 void comm_point_udp_callback(int ATTR_UNUSED(fd), short ATTR_UNUSED(event),
1406 void* ATTR_UNUSED(arg))
1411 void comm_point_udp_ancil_callback(int ATTR_UNUSED(fd),
1412 short ATTR_UNUSED(event), void* ATTR_UNUSED(arg))
1417 void comm_point_tcp_accept_callback(int ATTR_UNUSED(fd),
1418 short ATTR_UNUSED(event), void* ATTR_UNUSED(arg))
1423 void comm_point_tcp_handle_callback(int ATTR_UNUSED(fd),
1424 short ATTR_UNUSED(event), void* ATTR_UNUSED(arg))
1429 void comm_timer_callback(int ATTR_UNUSED(fd),
1430 short ATTR_UNUSED(event), void* ATTR_UNUSED(arg))
1435 void comm_signal_callback(int ATTR_UNUSED(fd),
1436 short ATTR_UNUSED(event), void* ATTR_UNUSED(arg))
1441 void comm_point_http_handle_callback(int ATTR_UNUSED(fd),
1442 short ATTR_UNUSED(event), void* ATTR_UNUSED(arg))
1447 void comm_point_local_handle_callback(int ATTR_UNUSED(fd),
1448 short ATTR_UNUSED(event), void* ATTR_UNUSED(arg))
1453 void comm_point_raw_handle_callback(int ATTR_UNUSED(fd),
1454 short ATTR_UNUSED(event), void* ATTR_UNUSED(arg))
1459 void comm_base_handle_slow_accept(int ATTR_UNUSED(fd),
1460 short ATTR_UNUSED(event), void* ATTR_UNUSED(arg))
1465 int serviced_udp_callback(struct comm_point* ATTR_UNUSED(c),
1466 void* ATTR_UNUSED(arg), int ATTR_UNUSED(error),
1467 struct comm_reply* ATTR_UNUSED(reply_info))
1473 int serviced_tcp_callback(struct comm_point* ATTR_UNUSED(c),
1474 void* ATTR_UNUSED(arg), int ATTR_UNUSED(error),
1475 struct comm_reply* ATTR_UNUSED(reply_info))
1481 int pending_cmp(const void* ATTR_UNUSED(a), const void* ATTR_UNUSED(b))
1487 int serviced_cmp(const void* ATTR_UNUSED(a), const void* ATTR_UNUSED(b))
1493 /* timers in testbound for autotrust. statistics tested in tdir. */
1494 struct comm_timer* comm_timer_create(struct comm_base* base,
1495 void (*cb)(void*), void* cb_arg)
1497 struct replay_runtime* runtime = (struct replay_runtime*)base;
1498 struct fake_timer* t = (struct fake_timer*)calloc(1, sizeof(*t));
1501 fptr_ok(fptr_whitelist_comm_timer(t->cb)); /* check in advance */
1502 t->runtime = runtime;
1503 t->next = runtime->timer_list;
1504 runtime->timer_list = t;
1505 return (struct comm_timer*)t;
1508 void comm_timer_disable(struct comm_timer* timer)
1510 struct fake_timer* t = (struct fake_timer*)timer;
1511 log_info("fake timer disabled");
1515 void comm_timer_set(struct comm_timer* timer, struct timeval* tv)
1517 struct fake_timer* t = (struct fake_timer*)timer;
1520 log_info("fake timer set %d.%6.6d",
1521 (int)t->tv.tv_sec, (int)t->tv.tv_usec);
1522 timeval_add(&t->tv, &t->runtime->now_tv);
1525 void comm_timer_delete(struct comm_timer* timer)
1527 struct fake_timer* t = (struct fake_timer*)timer;
1528 struct fake_timer** pp, *p;
1531 /* remove from linked list */
1532 pp = &t->runtime->timer_list;
1533 p = t->runtime->timer_list;
1536 /* snip from list */
1547 void comm_base_set_slow_accept_handlers(struct comm_base* ATTR_UNUSED(b),
1548 void (*stop_acc)(void*), void (*start_acc)(void*),
1549 void* ATTR_UNUSED(arg))
1556 struct ub_event_base* comm_base_internal(struct comm_base* ATTR_UNUSED(b))
1558 /* no pipe comm possible in testbound */
1562 void daemon_remote_exec(struct worker* ATTR_UNUSED(worker))
1566 void listen_start_accept(struct listen_dnsport* ATTR_UNUSED(listen))
1570 void listen_stop_accept(struct listen_dnsport* ATTR_UNUSED(listen))
1574 void daemon_remote_start_accept(struct daemon_remote* ATTR_UNUSED(rc))
1578 void daemon_remote_stop_accept(struct daemon_remote* ATTR_UNUSED(rc))
1582 int create_udp_sock(int ATTR_UNUSED(family), int ATTR_UNUSED(socktype),
1583 struct sockaddr* ATTR_UNUSED(addr), socklen_t ATTR_UNUSED(addrlen),
1584 int ATTR_UNUSED(v6only), int* ATTR_UNUSED(inuse),
1585 int* ATTR_UNUSED(noproto), int ATTR_UNUSED(rcv), int ATTR_UNUSED(snd),
1586 int ATTR_UNUSED(listen), int* ATTR_UNUSED(reuseport),
1587 int ATTR_UNUSED(transparent), int ATTR_UNUSED(freebind),
1588 int ATTR_UNUSED(use_systemd), int ATTR_UNUSED(dscp))
1590 /* if you actually print to this, it'll be stdout during test */
1594 struct comm_point* comm_point_create_udp(struct comm_base *ATTR_UNUSED(base),
1595 int ATTR_UNUSED(fd), sldns_buffer* ATTR_UNUSED(buffer),
1596 comm_point_callback_type* ATTR_UNUSED(callback),
1597 void* ATTR_UNUSED(callback_arg))
1603 struct comm_point* comm_point_create_tcp_out(struct comm_base*
1604 ATTR_UNUSED(base), size_t ATTR_UNUSED(bufsize),
1605 comm_point_callback_type* ATTR_UNUSED(callback),
1606 void* ATTR_UNUSED(callback_arg))
1612 struct comm_point* outnet_comm_point_for_udp(struct outside_network* outnet,
1613 comm_point_callback_type* cb, void* cb_arg,
1614 struct sockaddr_storage* ATTR_UNUSED(to_addr),
1615 socklen_t ATTR_UNUSED(to_addrlen))
1617 struct replay_runtime* runtime = (struct replay_runtime*)
1619 struct fake_commpoint* fc = (struct fake_commpoint*)calloc(1,
1621 if(!fc) return NULL;
1622 fc->typecode = FAKE_COMMPOINT_TYPECODE;
1623 fc->type_udp_out = 1;
1625 fc->cb_arg = cb_arg;
1626 fc->runtime = runtime;
1627 /* used by authzone transfers */
1628 return (struct comm_point*)fc;
1631 struct comm_point* outnet_comm_point_for_tcp(struct outside_network* outnet,
1632 comm_point_callback_type* cb, void* cb_arg,
1633 struct sockaddr_storage* to_addr, socklen_t to_addrlen,
1634 struct sldns_buffer* query, int timeout, int ATTR_UNUSED(ssl),
1635 char* ATTR_UNUSED(host))
1637 struct replay_runtime* runtime = (struct replay_runtime*)
1639 struct fake_commpoint* fc = (struct fake_commpoint*)calloc(1,
1641 struct fake_pending* pend = (struct fake_pending*)calloc(1,
1642 sizeof(struct fake_pending));
1648 fc->typecode = FAKE_COMMPOINT_TYPECODE;
1649 fc->type_tcp_out = 1;
1651 fc->cb_arg = cb_arg;
1652 fc->runtime = runtime;
1655 /* used by authzone transfers */
1656 /* create pending item */
1657 pend->buffer = sldns_buffer_new(sldns_buffer_limit(query)+10);
1663 sldns_buffer_copy(pend->buffer, query);
1664 memcpy(&pend->addr, to_addr, to_addrlen);
1665 pend->addrlen = to_addrlen;
1668 if(LDNS_QDCOUNT(sldns_buffer_begin(query)) > 0) {
1671 (void)sldns_wire2str_rrquestion_buf(sldns_buffer_at(query, LDNS_HEADER_SIZE), sldns_buffer_limit(query)-LDNS_HEADER_SIZE, buf, sizeof(buf));
1672 addr_to_str((struct sockaddr_storage*)to_addr, to_addrlen,
1673 addrbuf, sizeof(addrbuf));
1674 if(verbosity >= VERB_ALGO) {
1675 if(buf[0] != 0) buf[strlen(buf)-1] = 0; /* del newline*/
1676 log_info("tcp to %s: %s", addrbuf, buf);
1678 log_assert(sldns_buffer_limit(query)-LDNS_HEADER_SIZE >= 2);
1679 pend->qtype = (int)sldns_buffer_read_u16_at(query,
1681 dname_valid(sldns_buffer_at(query, LDNS_HEADER_SIZE),
1682 sldns_buffer_limit(query)-LDNS_HEADER_SIZE));
1684 pend->callback = cb;
1685 pend->cb_arg = cb_arg;
1686 pend->timeout = timeout;
1687 pend->transport = transport_tcp;
1689 pend->runtime = runtime;
1691 pend->pkt_len = sldns_buffer_limit(pend->buffer);
1692 pend->pkt = memdup(sldns_buffer_begin(pend->buffer), pend->pkt_len);
1693 if(!pend->pkt) fatal_exit("out of memory");
1695 log_info("testbound: created fake pending for tcp_out");
1698 pend->next = runtime->pending_list;
1699 runtime->pending_list = pend;
1701 return (struct comm_point*)fc;
1704 struct comm_point* outnet_comm_point_for_http(struct outside_network* outnet,
1705 comm_point_callback_type* cb, void* cb_arg,
1706 struct sockaddr_storage* to_addr, socklen_t to_addrlen, int timeout,
1707 int ssl, char* host, char* path)
1709 struct replay_runtime* runtime = (struct replay_runtime*)
1711 struct fake_commpoint* fc = (struct fake_commpoint*)calloc(1,
1716 fc->typecode = FAKE_COMMPOINT_TYPECODE;
1717 fc->type_http_out = 1;
1719 fc->cb_arg = cb_arg;
1720 fc->runtime = runtime;
1730 /* handle http comm point and return contents from test script */
1731 return (struct comm_point*)fc;
1734 int comm_point_send_udp_msg(struct comm_point *c, sldns_buffer* packet,
1735 struct sockaddr* addr, socklen_t addrlen)
1737 struct fake_commpoint* fc = (struct fake_commpoint*)c;
1738 struct replay_runtime* runtime = fc->runtime;
1739 struct fake_pending* pend = (struct fake_pending*)calloc(1,
1740 sizeof(struct fake_pending));
1742 log_err("malloc failure");
1746 /* used by authzone transfers */
1747 /* create pending item */
1748 pend->buffer = sldns_buffer_new(sldns_buffer_limit(packet) + 10);
1753 sldns_buffer_copy(pend->buffer, packet);
1754 memcpy(&pend->addr, addr, addrlen);
1755 pend->addrlen = addrlen;
1758 if(LDNS_QDCOUNT(sldns_buffer_begin(packet)) > 0) {
1761 (void)sldns_wire2str_rrquestion_buf(sldns_buffer_at(packet, LDNS_HEADER_SIZE), sldns_buffer_limit(packet)-LDNS_HEADER_SIZE, buf, sizeof(buf));
1762 addr_to_str((struct sockaddr_storage*)addr, addrlen,
1763 addrbuf, sizeof(addrbuf));
1764 if(verbosity >= VERB_ALGO) {
1765 if(buf[0] != 0) buf[strlen(buf)-1] = 0; /* del newline*/
1766 log_info("udp to %s: %s", addrbuf, buf);
1768 log_assert(sldns_buffer_limit(packet)-LDNS_HEADER_SIZE >= 2);
1769 pend->qtype = (int)sldns_buffer_read_u16_at(packet,
1771 dname_valid(sldns_buffer_at(packet, LDNS_HEADER_SIZE),
1772 sldns_buffer_limit(packet)-LDNS_HEADER_SIZE));
1774 pend->callback = fc->cb;
1775 pend->cb_arg = fc->cb_arg;
1776 pend->timeout = UDP_AUTH_QUERY_TIMEOUT/1000;
1777 pend->transport = transport_udp;
1779 pend->runtime = runtime;
1781 pend->pkt_len = sldns_buffer_limit(pend->buffer);
1782 pend->pkt = memdup(sldns_buffer_begin(pend->buffer), pend->pkt_len);
1783 if(!pend->pkt) fatal_exit("out of memory");
1785 log_info("testbound: created fake pending for send_udp_msg");
1788 pend->next = runtime->pending_list;
1789 runtime->pending_list = pend;
1794 int outnet_get_tcp_fd(struct sockaddr_storage* ATTR_UNUSED(addr),
1795 socklen_t ATTR_UNUSED(addrlen), int ATTR_UNUSED(tcp_mss), int ATTR_UNUSED(dscp))
1801 int outnet_tcp_connect(int ATTR_UNUSED(s), struct sockaddr_storage* ATTR_UNUSED(addr),
1802 socklen_t ATTR_UNUSED(addrlen))
1808 int tcp_req_info_add_meshstate(struct tcp_req_info* ATTR_UNUSED(req),
1809 struct mesh_area* ATTR_UNUSED(mesh), struct mesh_state* ATTR_UNUSED(m))
1816 tcp_req_info_remove_mesh_state(struct tcp_req_info* ATTR_UNUSED(req),
1817 struct mesh_state* ATTR_UNUSED(m))
1823 tcp_req_info_get_stream_buffer_size(void)
1828 /*********** End of Dummy routines ***********/