2007-02-08 16:03:26 +00:00
|
|
|
/*
|
|
|
|
* testcode/fake_event.c - fake event handling that replays existing scenario.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2007, NLnet Labs. All rights reserved.
|
|
|
|
*
|
|
|
|
* This software is open source.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* Redistributions of source code must retain the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* Neither the name of the NLNET LABS nor the names of its contributors may
|
|
|
|
* be used to endorse or promote products derived from this software without
|
|
|
|
* specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
|
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \file
|
|
|
|
* Event service that replays a scenario.
|
|
|
|
* This implements the same exported symbols as the files:
|
|
|
|
* util/netevent.c
|
|
|
|
* services/listen_dnsport.c
|
|
|
|
* services/outside_network.c
|
|
|
|
* But these do not actually access the network or events, instead
|
|
|
|
* the scenario is played.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "testcode/fake_event.h"
|
|
|
|
#include "util/netevent.h"
|
2007-04-17 14:03:33 +00:00
|
|
|
#include "util/net_help.h"
|
2007-05-22 12:36:02 +00:00
|
|
|
#include "util/data/msgparse.h"
|
|
|
|
#include "util/data/msgreply.h"
|
2007-06-01 12:25:38 +00:00
|
|
|
#include "util/data/msgencode.h"
|
2007-02-08 16:03:26 +00:00
|
|
|
#include "services/listen_dnsport.h"
|
|
|
|
#include "services/outside_network.h"
|
|
|
|
#include "testcode/replay.h"
|
2007-02-09 16:39:47 +00:00
|
|
|
#include "testcode/ldns-testpkts.h"
|
2007-02-12 16:04:11 +00:00
|
|
|
#include "util/log.h"
|
2007-11-12 13:58:34 +00:00
|
|
|
#include <signal.h>
|
2008-12-03 15:20:56 +00:00
|
|
|
struct worker;
|
2007-02-08 16:03:26 +00:00
|
|
|
|
2007-02-09 16:39:47 +00:00
|
|
|
/** Global variable: the scenario. Saved here for when event_init is done. */
|
|
|
|
static struct replay_scenario* saved_scenario = NULL;
|
2007-02-08 16:03:26 +00:00
|
|
|
|
2008-09-02 13:04:47 +00:00
|
|
|
/** add timers and the values do not overflow or become negative */
|
|
|
|
static void
|
2008-09-18 07:55:01 +00:00
|
|
|
timeval_add(struct timeval* d, const struct timeval* add)
|
2008-09-02 13:04:47 +00:00
|
|
|
{
|
|
|
|
#ifndef S_SPLINT_S
|
|
|
|
d->tv_sec += add->tv_sec;
|
|
|
|
d->tv_usec += add->tv_usec;
|
|
|
|
while(d->tv_usec > 1000000 ) {
|
|
|
|
d->tv_usec -= 1000000;
|
|
|
|
d->tv_sec++;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2007-02-08 16:03:26 +00:00
|
|
|
void
|
|
|
|
fake_event_init(struct replay_scenario* scen)
|
|
|
|
{
|
2007-02-09 16:39:47 +00:00
|
|
|
saved_scenario = scen;
|
2007-02-08 16:03:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
fake_event_cleanup()
|
|
|
|
{
|
2007-02-09 16:39:47 +00:00
|
|
|
replay_scenario_delete(saved_scenario);
|
|
|
|
saved_scenario = NULL;
|
|
|
|
}
|
|
|
|
|
2007-06-12 14:51:49 +00:00
|
|
|
/** helper function that logs a ldns_pkt packet to logfile */
|
2007-02-15 12:59:26 +00:00
|
|
|
static void
|
|
|
|
log_pkt(const char* desc, ldns_pkt* pkt)
|
|
|
|
{
|
|
|
|
char* str = ldns_pkt2str(pkt);
|
|
|
|
if(!str)
|
|
|
|
log_info("%s: (failed)", desc);
|
|
|
|
else {
|
|
|
|
log_info("%s%s", desc, str);
|
|
|
|
free(str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-13 14:00:58 +00:00
|
|
|
/**
|
|
|
|
* Returns a string describing the event type.
|
|
|
|
*/
|
|
|
|
static const char*
|
|
|
|
repevt_string(enum replay_event_type t)
|
|
|
|
{
|
|
|
|
switch(t) {
|
2007-02-14 14:02:50 +00:00
|
|
|
case repevt_nothing: return "NOTHING";
|
|
|
|
case repevt_front_query: return "QUERY";
|
|
|
|
case repevt_front_reply: return "CHECK_ANSWER";
|
|
|
|
case repevt_timeout: return "TIMEOUT";
|
2008-09-02 13:04:47 +00:00
|
|
|
case repevt_time_passes: return "TIME_PASSES";
|
2007-02-14 14:02:50 +00:00
|
|
|
case repevt_back_reply: return "REPLY";
|
|
|
|
case repevt_back_query: return "CHECK_OUT_QUERY";
|
|
|
|
case repevt_error: return "ERROR";
|
|
|
|
default: return "UNKNOWN";
|
2009-01-15 10:49:19 +00:00
|
|
|
}
|
2007-02-13 14:00:58 +00:00
|
|
|
}
|
|
|
|
|
2007-02-12 16:04:11 +00:00
|
|
|
/** delete a fake pending */
|
|
|
|
static void
|
|
|
|
delete_fake_pending(struct fake_pending* pend)
|
|
|
|
{
|
|
|
|
if(!pend)
|
|
|
|
return;
|
|
|
|
ldns_buffer_free(pend->buffer);
|
|
|
|
ldns_pkt_free(pend->pkt);
|
|
|
|
free(pend);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** delete a replay answer */
|
|
|
|
static void
|
|
|
|
delete_replay_answer(struct replay_answer* a)
|
|
|
|
{
|
|
|
|
if(!a)
|
|
|
|
return;
|
2007-02-13 14:00:58 +00:00
|
|
|
if(a->repinfo.c) {
|
|
|
|
ldns_buffer_free(a->repinfo.c->buffer);
|
|
|
|
free(a->repinfo.c);
|
|
|
|
}
|
|
|
|
ldns_pkt_free(a->pkt);
|
2007-02-12 16:04:11 +00:00
|
|
|
free(a);
|
|
|
|
}
|
|
|
|
|
2007-02-09 16:39:47 +00:00
|
|
|
/**
|
|
|
|
* return: true if pending query matches the now event.
|
|
|
|
*/
|
|
|
|
static int
|
2007-02-13 14:00:58 +00:00
|
|
|
pending_matches_current(struct replay_runtime* runtime,
|
|
|
|
struct entry** entry, struct fake_pending **pend)
|
2007-02-09 16:39:47 +00:00
|
|
|
{
|
|
|
|
struct fake_pending* p;
|
2007-02-13 14:00:58 +00:00
|
|
|
struct entry* e;
|
2007-02-09 16:39:47 +00:00
|
|
|
if(!runtime->now || runtime->now->evt_type != repevt_back_query
|
|
|
|
|| !runtime->pending_list)
|
|
|
|
return 0;
|
|
|
|
/* see if any of the pending queries matches */
|
|
|
|
for(p = runtime->pending_list; p; p = p->next) {
|
2007-07-25 12:31:04 +00:00
|
|
|
if(runtime->now->addrlen != 0 &&
|
|
|
|
sockaddr_cmp(&p->addr, p->addrlen, &runtime->now->addr,
|
|
|
|
runtime->now->addrlen) != 0)
|
|
|
|
continue;
|
2007-02-13 14:00:58 +00:00
|
|
|
if((e=find_match(runtime->now->match, p->pkt, p->transport))) {
|
|
|
|
*entry = e;
|
|
|
|
*pend = p;
|
2007-02-09 16:39:47 +00:00
|
|
|
return 1;
|
2007-02-13 14:00:58 +00:00
|
|
|
}
|
2007-02-09 16:39:47 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-02-12 16:04:11 +00:00
|
|
|
/**
|
|
|
|
* Find the range that matches this pending message.
|
|
|
|
* @param runtime: runtime with current moment, and range list.
|
|
|
|
* @param entry: returns the pointer to entry that matches.
|
|
|
|
* @param pend: the pending that the entry must match.
|
|
|
|
* @return: true if a match is found.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
pending_find_match(struct replay_runtime* runtime, struct entry** entry,
|
|
|
|
struct fake_pending* pend)
|
|
|
|
{
|
|
|
|
int timenow = runtime->now->time_step;
|
|
|
|
struct replay_range* p = runtime->scenario->range_list;
|
|
|
|
while(p) {
|
|
|
|
if(p->start_step <= timenow && timenow <= p->end_step &&
|
2007-07-25 12:31:04 +00:00
|
|
|
(p->addrlen == 0 || sockaddr_cmp(&p->addr, p->addrlen,
|
|
|
|
&pend->addr, pend->addrlen) == 0) &&
|
2007-02-12 16:04:11 +00:00
|
|
|
(*entry = find_match(p->match, pend->pkt, pend->transport))) {
|
2007-02-13 14:00:58 +00:00
|
|
|
log_info("matched query time %d in range [%d, %d] "
|
|
|
|
"with entry line %d", timenow,
|
|
|
|
p->start_step, p->end_step, (*entry)->lineno);
|
2007-07-25 12:31:04 +00:00
|
|
|
if(p->addrlen != 0)
|
2007-10-18 09:04:55 +00:00
|
|
|
log_addr(0, "matched ip", &p->addr, p->addrlen);
|
2007-09-17 14:03:35 +00:00
|
|
|
log_pkt("matched pkt: ", (*entry)->reply_list->reply);
|
2007-02-12 16:04:11 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
p = p->next_range;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-02-09 16:39:47 +00:00
|
|
|
/**
|
|
|
|
* See if outgoing pending query matches an entry.
|
|
|
|
* @param runtime: runtime.
|
|
|
|
* @param entry: if true, the entry that matches is returned.
|
|
|
|
* @param pend: if true, the outgoing message that matches is returned.
|
|
|
|
* return: true if pending query matches the now event.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
pending_matches_range(struct replay_runtime* runtime,
|
|
|
|
struct entry** entry, struct fake_pending** pend)
|
|
|
|
{
|
2007-02-12 16:04:11 +00:00
|
|
|
struct fake_pending* p = runtime->pending_list;
|
|
|
|
/* slow, O(N*N), but it works as advertised with weird matching */
|
|
|
|
while(p) {
|
2007-07-25 12:31:04 +00:00
|
|
|
log_info("check of pending");
|
2007-02-12 16:04:11 +00:00
|
|
|
if(pending_find_match(runtime, entry, p)) {
|
|
|
|
*pend = p;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
p = p->next;
|
|
|
|
}
|
|
|
|
return 0;
|
2007-02-09 16:39:47 +00:00
|
|
|
}
|
|
|
|
|
2007-02-13 14:00:58 +00:00
|
|
|
/**
|
|
|
|
* Remove the item from the pending list.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
pending_list_delete(struct replay_runtime* runtime, struct fake_pending* pend)
|
|
|
|
{
|
|
|
|
struct fake_pending** prev = &runtime->pending_list;
|
|
|
|
struct fake_pending* p = runtime->pending_list;
|
|
|
|
|
|
|
|
while(p) {
|
|
|
|
if(p == pend) {
|
|
|
|
*prev = p->next;
|
|
|
|
delete_fake_pending(pend);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
prev = &p->next;
|
|
|
|
p = p->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-09 16:39:47 +00:00
|
|
|
/**
|
2007-02-13 15:35:26 +00:00
|
|
|
* Fill buffer with reply from the entry.
|
2007-02-09 16:39:47 +00:00
|
|
|
*/
|
|
|
|
static void
|
2007-02-13 15:35:26 +00:00
|
|
|
fill_buffer_with_reply(ldns_buffer* buffer, struct entry* entry, ldns_pkt* q)
|
2007-02-09 16:39:47 +00:00
|
|
|
{
|
2007-02-13 14:00:58 +00:00
|
|
|
ldns_status status;
|
|
|
|
ldns_pkt* answer_pkt = NULL;
|
2007-02-14 14:02:50 +00:00
|
|
|
log_assert(entry && entry->reply_list);
|
2007-02-13 15:35:26 +00:00
|
|
|
ldns_buffer_clear(buffer);
|
2007-02-13 14:00:58 +00:00
|
|
|
if(entry->reply_list->reply_from_hex) {
|
|
|
|
status = ldns_buffer2pkt_wire(&answer_pkt,
|
|
|
|
entry->reply_list->reply_from_hex);
|
|
|
|
if(status != LDNS_STATUS_OK) {
|
2007-02-13 15:35:26 +00:00
|
|
|
log_err("testbound: hex packet unparsable, used asis.");
|
|
|
|
ldns_buffer_write(buffer,
|
2007-02-13 14:00:58 +00:00
|
|
|
ldns_buffer_begin(entry->reply_list->reply_from_hex),
|
|
|
|
ldns_buffer_limit(entry->reply_list->reply_from_hex));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
answer_pkt = ldns_pkt_clone(entry->reply_list->reply);
|
|
|
|
}
|
|
|
|
if(answer_pkt) {
|
2007-02-14 14:02:50 +00:00
|
|
|
if(q) adjust_packet(entry, answer_pkt, q);
|
2007-02-13 15:35:26 +00:00
|
|
|
status = ldns_pkt2buffer_wire(buffer, answer_pkt);
|
2007-02-13 14:00:58 +00:00
|
|
|
if(status != LDNS_STATUS_OK)
|
|
|
|
fatal_exit("ldns: cannot pkt2buffer_wire parsed pkt");
|
|
|
|
}
|
2007-02-13 15:35:26 +00:00
|
|
|
ldns_pkt_free(answer_pkt);
|
|
|
|
ldns_buffer_flip(buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Perform range entry on pending message.
|
2007-02-14 14:02:50 +00:00
|
|
|
* @param runtime: runtime buffer size preference.
|
2007-02-13 15:35:26 +00:00
|
|
|
* @param entry: entry that codes for the reply to do.
|
|
|
|
* @param pend: pending query that is answered, callback called.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
answer_callback_from_entry(struct replay_runtime* runtime,
|
|
|
|
struct entry* entry, struct fake_pending* pend)
|
|
|
|
{
|
|
|
|
struct comm_point c;
|
2007-05-11 14:33:38 +00:00
|
|
|
struct comm_reply repinfo;
|
2007-07-25 12:31:04 +00:00
|
|
|
void* cb_arg = pend->cb_arg;
|
|
|
|
comm_point_callback_t* cb = pend->callback;
|
|
|
|
|
2007-02-13 15:35:26 +00:00
|
|
|
memset(&c, 0, sizeof(c));
|
|
|
|
c.fd = -1;
|
|
|
|
c.buffer = ldns_buffer_new(runtime->bufsize);
|
|
|
|
c.type = comm_udp;
|
|
|
|
if(pend->transport == transport_tcp)
|
|
|
|
c.type = comm_tcp;
|
|
|
|
fill_buffer_with_reply(c.buffer, entry, pend->pkt);
|
2007-05-11 14:33:38 +00:00
|
|
|
repinfo.c = &c;
|
|
|
|
repinfo.addrlen = pend->addrlen;
|
|
|
|
memcpy(&repinfo.addr, &pend->addr, pend->addrlen);
|
2007-07-25 12:31:04 +00:00
|
|
|
if(!pend->serviced)
|
|
|
|
pending_list_delete(runtime, pend);
|
|
|
|
if((*cb)(&c, cb_arg, NETEVENT_NOERROR, &repinfo)) {
|
2007-02-13 14:00:58 +00:00
|
|
|
fatal_exit("testbound: unexpected: callback returned 1");
|
|
|
|
}
|
|
|
|
ldns_buffer_free(c.buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Check the now moment answer check event */
|
|
|
|
static void
|
|
|
|
answer_check_it(struct replay_runtime* runtime)
|
|
|
|
{
|
|
|
|
struct replay_answer* ans = runtime->answer_list,
|
2007-03-26 15:01:11 +00:00
|
|
|
*prev = NULL;
|
2007-02-13 14:00:58 +00:00
|
|
|
log_assert(runtime && runtime->now &&
|
|
|
|
runtime->now->evt_type == repevt_front_reply);
|
|
|
|
while(ans) {
|
|
|
|
enum transport_type tr = transport_tcp;
|
|
|
|
if(ans->repinfo.c->type == comm_udp)
|
|
|
|
tr = transport_udp;
|
2007-07-25 12:31:04 +00:00
|
|
|
if((runtime->now->addrlen == 0 || sockaddr_cmp(
|
|
|
|
&runtime->now->addr, runtime->now->addrlen,
|
|
|
|
&ans->repinfo.addr, ans->repinfo.addrlen) == 0) &&
|
|
|
|
find_match(runtime->now->match, ans->pkt, tr)) {
|
2007-02-13 14:00:58 +00:00
|
|
|
struct replay_answer *n = ans->next;
|
2007-02-14 14:02:50 +00:00
|
|
|
log_info("testbound matched event entry from line %d",
|
2007-02-13 14:00:58 +00:00
|
|
|
runtime->now->match->lineno);
|
2007-02-13 15:35:26 +00:00
|
|
|
log_info("testbound: do STEP %d %s",
|
|
|
|
runtime->now->time_step,
|
|
|
|
repevt_string(runtime->now->evt_type));
|
2007-03-26 15:01:11 +00:00
|
|
|
if(prev)
|
|
|
|
prev->next = ans->next;
|
|
|
|
else runtime->answer_list = ans->next;
|
|
|
|
if(!ans->next)
|
|
|
|
runtime->answer_last = prev;
|
2007-02-13 14:00:58 +00:00
|
|
|
delete_replay_answer(ans);
|
|
|
|
ans = n;
|
2007-02-14 14:02:50 +00:00
|
|
|
return;
|
2007-02-13 14:00:58 +00:00
|
|
|
} else {
|
2007-03-26 15:01:11 +00:00
|
|
|
prev = ans;
|
2007-02-13 14:00:58 +00:00
|
|
|
ans = ans->next;
|
|
|
|
}
|
|
|
|
}
|
2007-02-14 14:02:50 +00:00
|
|
|
log_info("testbound: do STEP %d %s", runtime->now->time_step,
|
|
|
|
repevt_string(runtime->now->evt_type));
|
|
|
|
fatal_exit("testbound: not matched");
|
2007-02-09 16:39:47 +00:00
|
|
|
}
|
|
|
|
|
2007-02-12 16:04:11 +00:00
|
|
|
/**
|
|
|
|
* Create commpoint (as return address) for a fake incoming query.
|
|
|
|
*/
|
|
|
|
static void
|
2007-02-13 14:00:58 +00:00
|
|
|
fake_front_query(struct replay_runtime* runtime, struct replay_moment *todo)
|
2007-02-12 16:04:11 +00:00
|
|
|
{
|
|
|
|
struct comm_reply repinfo;
|
|
|
|
memset(&repinfo, 0, sizeof(repinfo));
|
|
|
|
repinfo.c = (struct comm_point*)calloc(1, sizeof(struct comm_point));
|
|
|
|
repinfo.addrlen = (socklen_t)sizeof(struct sockaddr_in);
|
2007-07-25 12:31:04 +00:00
|
|
|
if(todo->addrlen != 0) {
|
|
|
|
repinfo.addrlen = todo->addrlen;
|
|
|
|
memcpy(&repinfo.addr, &todo->addr, todo->addrlen);
|
|
|
|
}
|
2007-02-14 14:02:50 +00:00
|
|
|
repinfo.c->fd = -1;
|
2007-02-13 14:00:58 +00:00
|
|
|
repinfo.c->ev = (struct internal_event*)runtime;
|
2007-02-12 16:04:11 +00:00
|
|
|
repinfo.c->buffer = ldns_buffer_new(runtime->bufsize);
|
2007-09-05 09:50:02 +00:00
|
|
|
if(todo->match->match_transport == transport_tcp)
|
|
|
|
repinfo.c->type = comm_tcp;
|
|
|
|
else repinfo.c->type = comm_udp;
|
2007-02-13 15:35:26 +00:00
|
|
|
fill_buffer_with_reply(repinfo.c->buffer, todo->match, NULL);
|
2007-02-14 14:02:50 +00:00
|
|
|
log_info("testbound: incoming QUERY");
|
2007-10-09 15:33:40 +00:00
|
|
|
log_pkt("query pkt", todo->match->reply_list->reply);
|
2007-02-12 16:04:11 +00:00
|
|
|
/* call the callback for incoming queries */
|
|
|
|
if((*runtime->callback_query)(repinfo.c, runtime->cb_arg,
|
|
|
|
NETEVENT_NOERROR, &repinfo)) {
|
|
|
|
/* send immediate reply */
|
|
|
|
comm_point_send_reply(&repinfo);
|
|
|
|
}
|
|
|
|
/* clear it again, in case copy not done properly */
|
|
|
|
memset(&repinfo, 0, sizeof(repinfo));
|
|
|
|
}
|
|
|
|
|
2007-02-13 15:35:26 +00:00
|
|
|
/**
|
|
|
|
* Perform callback for fake pending message.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
fake_pending_callback(struct replay_runtime* runtime,
|
|
|
|
struct replay_moment* todo, int error)
|
|
|
|
{
|
|
|
|
struct fake_pending* p = runtime->pending_list;
|
2007-05-11 14:33:38 +00:00
|
|
|
struct comm_reply repinfo;
|
2007-02-13 15:35:26 +00:00
|
|
|
struct comm_point c;
|
2008-09-01 13:48:24 +00:00
|
|
|
void* cb_arg;
|
|
|
|
comm_point_callback_t* cb;
|
2007-10-18 09:24:57 +00:00
|
|
|
|
2007-02-13 15:35:26 +00:00
|
|
|
memset(&c, 0, sizeof(c));
|
|
|
|
if(!p) fatal_exit("No pending queries.");
|
2008-09-01 13:48:24 +00:00
|
|
|
cb_arg = p->cb_arg;
|
|
|
|
cb = p->callback;
|
2007-02-13 15:35:26 +00:00
|
|
|
log_assert(todo->qname == NULL); /* or find that one */
|
|
|
|
c.buffer = ldns_buffer_new(runtime->bufsize);
|
|
|
|
c.type = comm_udp;
|
|
|
|
if(p->transport == transport_tcp)
|
|
|
|
c.type = comm_tcp;
|
|
|
|
if(todo->evt_type == repevt_back_reply && todo->match) {
|
|
|
|
fill_buffer_with_reply(c.buffer, todo->match, p->pkt);
|
2007-05-11 14:33:38 +00:00
|
|
|
}
|
|
|
|
repinfo.c = &c;
|
|
|
|
repinfo.addrlen = p->addrlen;
|
|
|
|
memcpy(&repinfo.addr, &p->addr, p->addrlen);
|
2007-10-30 21:40:16 +00:00
|
|
|
if(!p->serviced)
|
|
|
|
pending_list_delete(runtime, p);
|
2007-10-18 09:24:57 +00:00
|
|
|
if((*cb)(&c, cb_arg, error, &repinfo)) {
|
2007-02-13 15:35:26 +00:00
|
|
|
fatal_exit("unexpected: pending callback returned 1");
|
|
|
|
}
|
|
|
|
/* delete the pending item. */
|
|
|
|
ldns_buffer_free(c.buffer);
|
|
|
|
}
|
|
|
|
|
2008-09-02 13:04:47 +00:00
|
|
|
/** pass time */
|
|
|
|
static void
|
|
|
|
time_passes(struct replay_runtime* runtime, struct replay_moment* mom)
|
|
|
|
{
|
|
|
|
timeval_add(&runtime->now_tv, &mom->elapse);
|
|
|
|
runtime->now_secs = (uint32_t)runtime->now_tv.tv_sec;
|
|
|
|
#ifndef S_SPLINT_S
|
|
|
|
log_info("elapsed %d.%6.6d now %d.%6.6d",
|
|
|
|
(int)mom->elapse.tv_sec, (int)mom->elapse.tv_usec,
|
|
|
|
(int)runtime->now_tv.tv_sec, (int)runtime->now_tv.tv_usec);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2007-02-09 16:39:47 +00:00
|
|
|
/**
|
2007-02-13 14:00:58 +00:00
|
|
|
* Advance to the next moment.
|
2007-02-09 16:39:47 +00:00
|
|
|
*/
|
|
|
|
static void
|
2007-02-13 14:00:58 +00:00
|
|
|
advance_moment(struct replay_runtime* runtime)
|
2007-02-09 16:39:47 +00:00
|
|
|
{
|
|
|
|
if(!runtime->now)
|
2007-02-13 14:00:58 +00:00
|
|
|
runtime->now = runtime->scenario->mom_first;
|
|
|
|
else runtime->now = runtime->now->mom_next;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Perform actions or checks determined by the moment.
|
|
|
|
* Also advances the time by one step.
|
2007-02-13 15:35:26 +00:00
|
|
|
* @param runtime: scenario runtime information.
|
2007-02-13 14:00:58 +00:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
do_moment_and_advance(struct replay_runtime* runtime)
|
|
|
|
{
|
|
|
|
struct replay_moment* mom;
|
|
|
|
if(!runtime->now) {
|
|
|
|
advance_moment(runtime);
|
2007-02-09 16:39:47 +00:00
|
|
|
return;
|
2007-02-13 14:00:58 +00:00
|
|
|
}
|
2007-02-13 15:35:26 +00:00
|
|
|
log_info("testbound: do STEP %d %s", runtime->now->time_step,
|
|
|
|
repevt_string(runtime->now->evt_type));
|
2007-02-12 16:04:11 +00:00
|
|
|
switch(runtime->now->evt_type) {
|
2007-02-14 14:02:50 +00:00
|
|
|
case repevt_nothing:
|
2007-02-13 14:00:58 +00:00
|
|
|
advance_moment(runtime);
|
2007-02-12 16:04:11 +00:00
|
|
|
break;
|
2007-02-14 14:02:50 +00:00
|
|
|
case repevt_front_query:
|
|
|
|
/* advance moment before doing the step, so that the next
|
|
|
|
moment which may check some result of the mom step
|
|
|
|
can catch those results. */
|
2007-02-13 14:00:58 +00:00
|
|
|
mom = runtime->now;
|
|
|
|
advance_moment(runtime);
|
|
|
|
fake_front_query(runtime, mom);
|
2007-02-12 16:04:11 +00:00
|
|
|
break;
|
2007-02-14 14:02:50 +00:00
|
|
|
case repevt_front_reply:
|
2007-02-13 14:00:58 +00:00
|
|
|
if(runtime->answer_list)
|
2007-02-14 14:02:50 +00:00
|
|
|
log_err("testbound: There are unmatched answers.");
|
2007-02-12 16:04:11 +00:00
|
|
|
fatal_exit("testbound: query answer not matched");
|
|
|
|
break;
|
2007-02-14 14:02:50 +00:00
|
|
|
case repevt_timeout:
|
2007-02-13 15:35:26 +00:00
|
|
|
mom = runtime->now;
|
2007-02-13 14:00:58 +00:00
|
|
|
advance_moment(runtime);
|
2007-02-13 15:35:26 +00:00
|
|
|
fake_pending_callback(runtime, mom, NETEVENT_TIMEOUT);
|
2007-02-12 16:04:11 +00:00
|
|
|
break;
|
2007-02-14 14:02:50 +00:00
|
|
|
case repevt_back_reply:
|
2007-02-13 15:35:26 +00:00
|
|
|
mom = runtime->now;
|
2007-02-13 14:00:58 +00:00
|
|
|
advance_moment(runtime);
|
2007-02-13 15:35:26 +00:00
|
|
|
fake_pending_callback(runtime, mom, NETEVENT_NOERROR);
|
2007-02-12 16:04:11 +00:00
|
|
|
break;
|
2007-02-14 14:02:50 +00:00
|
|
|
case repevt_back_query:
|
|
|
|
/* Back queries are matched when they are sent out. */
|
|
|
|
log_err("No query matching the current moment was sent.");
|
2007-02-12 16:04:11 +00:00
|
|
|
fatal_exit("testbound: back query not matched");
|
|
|
|
break;
|
2007-02-14 14:02:50 +00:00
|
|
|
case repevt_error:
|
2007-02-13 15:35:26 +00:00
|
|
|
mom = runtime->now;
|
2007-02-13 14:00:58 +00:00
|
|
|
advance_moment(runtime);
|
2007-02-13 15:35:26 +00:00
|
|
|
fake_pending_callback(runtime, mom, NETEVENT_CLOSED);
|
2007-02-12 16:04:11 +00:00
|
|
|
break;
|
2008-09-02 13:04:47 +00:00
|
|
|
case repevt_time_passes:
|
|
|
|
time_passes(runtime, runtime->now);
|
|
|
|
advance_moment(runtime);
|
|
|
|
break;
|
2007-02-12 16:04:11 +00:00
|
|
|
default:
|
|
|
|
fatal_exit("testbound: unknown event type %d",
|
|
|
|
runtime->now->evt_type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-09 16:39:47 +00:00
|
|
|
/** run the scenario in event callbacks */
|
|
|
|
static void
|
|
|
|
run_scenario(struct replay_runtime* runtime)
|
|
|
|
{
|
|
|
|
struct entry* entry = NULL;
|
|
|
|
struct fake_pending* pending = NULL;
|
2007-02-13 14:00:58 +00:00
|
|
|
int max_rounds = 50;
|
|
|
|
int rounds = 0;
|
2007-02-13 15:35:26 +00:00
|
|
|
runtime->now = runtime->scenario->mom_first;
|
2007-02-13 14:00:58 +00:00
|
|
|
log_info("testbound: entering fake runloop");
|
2007-02-09 16:39:47 +00:00
|
|
|
do {
|
|
|
|
/* if moment matches pending query do it. */
|
2007-02-13 14:00:58 +00:00
|
|
|
/* else if moment matches given answer, do it */
|
2007-02-09 16:39:47 +00:00
|
|
|
/* else if precoded_range matches pending, do it */
|
|
|
|
/* else do the current moment */
|
2007-02-13 14:00:58 +00:00
|
|
|
if(pending_matches_current(runtime, &entry, &pending)) {
|
2007-02-14 14:02:50 +00:00
|
|
|
log_info("testbound: do STEP %d CHECK_OUT_QUERY",
|
2007-02-13 15:35:26 +00:00
|
|
|
runtime->now->time_step);
|
2007-02-14 14:02:50 +00:00
|
|
|
advance_moment(runtime);
|
2007-02-13 14:00:58 +00:00
|
|
|
if(entry->copy_id)
|
|
|
|
answer_callback_from_entry(runtime, entry,
|
|
|
|
pending);
|
|
|
|
} else if(runtime->answer_list && runtime->now &&
|
|
|
|
runtime->now->evt_type == repevt_front_reply) {
|
|
|
|
answer_check_it(runtime);
|
2007-02-09 16:39:47 +00:00
|
|
|
advance_moment(runtime);
|
|
|
|
} else if(pending_matches_range(runtime, &entry, &pending)) {
|
|
|
|
answer_callback_from_entry(runtime, entry, pending);
|
|
|
|
} else {
|
2007-02-13 14:00:58 +00:00
|
|
|
do_moment_and_advance(runtime);
|
2007-02-09 16:39:47 +00:00
|
|
|
}
|
2007-02-13 14:00:58 +00:00
|
|
|
log_info("testbound: end of event stage");
|
|
|
|
rounds++;
|
|
|
|
if(rounds > max_rounds)
|
|
|
|
fatal_exit("testbound: too many rounds, it loops.");
|
2007-02-09 16:39:47 +00:00
|
|
|
} while(runtime->now);
|
2007-02-13 15:35:26 +00:00
|
|
|
|
2007-02-13 14:00:58 +00:00
|
|
|
if(runtime->pending_list) {
|
2007-07-25 12:31:04 +00:00
|
|
|
struct fake_pending* p;
|
|
|
|
log_err("testbound: there are still messages pending.");
|
2008-11-17 12:47:34 +00:00
|
|
|
for(p = runtime->pending_list; p; p=p->next) {
|
2007-07-25 12:31:04 +00:00
|
|
|
log_pkt("pending msg", p->pkt);
|
2008-11-17 12:47:34 +00:00
|
|
|
log_addr(0, "pending to", &p->addr, p->addrlen);
|
|
|
|
}
|
2007-02-13 14:00:58 +00:00
|
|
|
fatal_exit("testbound: there are still messages pending.");
|
|
|
|
}
|
|
|
|
if(runtime->answer_list) {
|
|
|
|
fatal_exit("testbound: there are unmatched answers.");
|
|
|
|
}
|
2007-02-14 14:02:50 +00:00
|
|
|
log_info("testbound: exiting fake runloop.");
|
2007-11-12 13:58:34 +00:00
|
|
|
runtime->exit_cleanly = 1;
|
2007-02-08 16:03:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********** Dummy routines ***********/
|
|
|
|
|
2007-02-08 16:47:06 +00:00
|
|
|
struct listen_dnsport*
|
2007-02-23 10:04:50 +00:00
|
|
|
listen_create(struct comm_base* base, struct listen_port* ATTR_UNUSED(ports),
|
2007-08-30 08:36:41 +00:00
|
|
|
size_t bufsize, int ATTR_UNUSED(tcp_accept_count),
|
|
|
|
comm_point_callback_t* cb, void* cb_arg)
|
2007-02-08 16:47:06 +00:00
|
|
|
{
|
2007-02-09 16:39:47 +00:00
|
|
|
struct replay_runtime* runtime = (struct replay_runtime*)base;
|
|
|
|
struct listen_dnsport* l= calloc(1, sizeof(struct listen_dnsport));
|
|
|
|
if(!l)
|
|
|
|
return NULL;
|
|
|
|
l->base = base;
|
|
|
|
l->udp_buff = ldns_buffer_new(bufsize);
|
|
|
|
if(!l->udp_buff) {
|
|
|
|
free(l);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
runtime->callback_query = cb;
|
|
|
|
runtime->cb_arg = cb_arg;
|
2007-02-12 16:04:11 +00:00
|
|
|
runtime->bufsize = bufsize;
|
2007-02-09 16:39:47 +00:00
|
|
|
return l;
|
2007-02-08 16:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
listen_delete(struct listen_dnsport* listen)
|
|
|
|
{
|
2007-02-09 16:39:47 +00:00
|
|
|
if(!listen)
|
|
|
|
return;
|
|
|
|
ldns_buffer_free(listen->udp_buff);
|
2007-02-08 16:47:06 +00:00
|
|
|
free(listen);
|
|
|
|
}
|
|
|
|
|
2007-02-13 14:00:58 +00:00
|
|
|
struct comm_base*
|
2009-01-05 15:05:33 +00:00
|
|
|
comm_base_create(int ATTR_UNUSED(sigs))
|
2007-02-08 16:47:06 +00:00
|
|
|
{
|
2007-02-09 16:39:47 +00:00
|
|
|
/* we return the runtime structure instead. */
|
|
|
|
struct replay_runtime* runtime = (struct replay_runtime*)
|
|
|
|
calloc(1, sizeof(struct replay_runtime));
|
|
|
|
runtime->scenario = saved_scenario;
|
|
|
|
return (struct comm_base*)runtime;
|
2007-02-08 16:47:06 +00:00
|
|
|
}
|
|
|
|
|
2007-02-13 14:00:58 +00:00
|
|
|
void
|
|
|
|
comm_base_delete(struct comm_base* b)
|
2007-02-08 16:47:06 +00:00
|
|
|
{
|
2007-02-09 16:39:47 +00:00
|
|
|
struct replay_runtime* runtime = (struct replay_runtime*)b;
|
2007-02-12 16:04:11 +00:00
|
|
|
struct fake_pending* p, *np;
|
|
|
|
struct replay_answer* a, *na;
|
|
|
|
if(!runtime)
|
|
|
|
return;
|
|
|
|
runtime->scenario= NULL;
|
|
|
|
p = runtime->pending_list;
|
|
|
|
while(p) {
|
|
|
|
np = p->next;
|
|
|
|
delete_fake_pending(p);
|
|
|
|
p = np;
|
|
|
|
}
|
|
|
|
a = runtime->answer_list;
|
|
|
|
while(a) {
|
|
|
|
na = a->next;
|
|
|
|
delete_replay_answer(a);
|
|
|
|
a = na;
|
|
|
|
}
|
2007-02-09 16:39:47 +00:00
|
|
|
free(runtime);
|
2007-02-08 16:47:06 +00:00
|
|
|
}
|
|
|
|
|
2008-02-19 13:12:23 +00:00
|
|
|
void
|
|
|
|
comm_base_timept(struct comm_base* b, uint32_t** tt, struct timeval** tv)
|
|
|
|
{
|
|
|
|
struct replay_runtime* runtime = (struct replay_runtime*)b;
|
|
|
|
*tt = &runtime->now_secs;
|
|
|
|
*tv = &runtime->now_tv;
|
|
|
|
}
|
|
|
|
|
2007-02-13 14:00:58 +00:00
|
|
|
void
|
|
|
|
comm_base_dispatch(struct comm_base* b)
|
2007-02-08 16:47:06 +00:00
|
|
|
{
|
2007-02-09 16:39:47 +00:00
|
|
|
struct replay_runtime* runtime = (struct replay_runtime*)b;
|
|
|
|
run_scenario(runtime);
|
2007-11-13 16:15:04 +00:00
|
|
|
if(runtime->sig_cb)
|
|
|
|
(*runtime->sig_cb)(SIGTERM, runtime->sig_cb_arg);
|
|
|
|
else exit(0); /* OK exit when LIBEVENT_SIGNAL_PROBLEM exists */
|
2007-02-08 16:47:06 +00:00
|
|
|
}
|
|
|
|
|
2007-02-13 14:00:58 +00:00
|
|
|
void
|
2007-11-12 13:58:34 +00:00
|
|
|
comm_base_exit(struct comm_base* b)
|
2007-02-08 16:47:06 +00:00
|
|
|
{
|
2007-11-12 13:58:34 +00:00
|
|
|
struct replay_runtime* runtime = (struct replay_runtime*)b;
|
|
|
|
if(!runtime->exit_cleanly) {
|
|
|
|
/* some sort of failure */
|
|
|
|
fatal_exit("testbound: comm_base_exit was called.");
|
|
|
|
}
|
2007-02-08 16:47:06 +00:00
|
|
|
}
|
|
|
|
|
2007-02-13 14:00:58 +00:00
|
|
|
struct comm_signal*
|
|
|
|
comm_signal_create(struct comm_base* base,
|
2007-02-09 16:39:47 +00:00
|
|
|
void (*callback)(int, void*), void* cb_arg)
|
2007-02-08 16:47:06 +00:00
|
|
|
{
|
2007-02-09 16:39:47 +00:00
|
|
|
struct replay_runtime* runtime = (struct replay_runtime*)base;
|
|
|
|
runtime->sig_cb = callback;
|
|
|
|
runtime->sig_cb_arg = cb_arg;
|
|
|
|
return calloc(1, sizeof(struct comm_signal));
|
2007-02-08 16:47:06 +00:00
|
|
|
}
|
|
|
|
|
2007-02-13 14:00:58 +00:00
|
|
|
int
|
|
|
|
comm_signal_bind(struct comm_signal* ATTR_UNUSED(comsig), int
|
2007-02-08 16:47:06 +00:00
|
|
|
ATTR_UNUSED(sig))
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2007-02-13 14:00:58 +00:00
|
|
|
void
|
|
|
|
comm_signal_delete(struct comm_signal* comsig)
|
2007-02-08 16:47:06 +00:00
|
|
|
{
|
|
|
|
free(comsig);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
comm_point_send_reply(struct comm_reply* repinfo)
|
|
|
|
{
|
2007-02-13 14:00:58 +00:00
|
|
|
struct replay_answer* ans = (struct replay_answer*)calloc(1,
|
|
|
|
sizeof(struct replay_answer));
|
|
|
|
ldns_status status;
|
|
|
|
struct replay_runtime* runtime = (struct replay_runtime*)repinfo->c->ev;
|
|
|
|
log_info("testbound: comm_point_send_reply fake");
|
|
|
|
/* dump it into the todo list */
|
|
|
|
log_assert(ans);
|
|
|
|
memcpy(&ans->repinfo, repinfo, sizeof(struct comm_reply));
|
|
|
|
ans->next = NULL;
|
|
|
|
if(runtime->answer_last)
|
|
|
|
runtime->answer_last->next = ans;
|
|
|
|
else runtime->answer_list = ans;
|
|
|
|
runtime->answer_last = ans;
|
|
|
|
|
|
|
|
/* try to parse packet */
|
|
|
|
status = ldns_buffer2pkt_wire(&ans->pkt, ans->repinfo.c->buffer);
|
|
|
|
if(status != LDNS_STATUS_OK) {
|
|
|
|
log_err("ldns error parsing packet: %s",
|
|
|
|
ldns_get_errorstr_by_id(status));
|
|
|
|
fatal_exit("Sending unparseable DNS replies to clients!");
|
|
|
|
}
|
2007-02-15 12:59:26 +00:00
|
|
|
log_pkt("reply pkt: ", ans->pkt);
|
2007-02-08 16:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
comm_point_drop_reply(struct comm_reply* repinfo)
|
|
|
|
{
|
2007-02-12 16:04:11 +00:00
|
|
|
log_info("comm_point_drop_reply fake");
|
2007-02-13 14:00:58 +00:00
|
|
|
if(repinfo->c) {
|
|
|
|
ldns_buffer_free(repinfo->c->buffer);
|
|
|
|
free(repinfo->c);
|
|
|
|
}
|
2007-02-08 16:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct outside_network*
|
2007-02-09 16:39:47 +00:00
|
|
|
outside_network_create(struct comm_base* base, size_t bufsize,
|
2007-02-23 11:00:55 +00:00
|
|
|
size_t ATTR_UNUSED(num_ports), char** ATTR_UNUSED(ifs),
|
2007-02-14 14:02:50 +00:00
|
|
|
int ATTR_UNUSED(num_ifs), int ATTR_UNUSED(do_ip4),
|
2008-04-11 14:10:16 +00:00
|
|
|
int ATTR_UNUSED(do_ip6), size_t ATTR_UNUSED(num_tcp),
|
|
|
|
struct infra_cache* ATTR_UNUSED(infra),
|
2008-04-11 13:24:49 +00:00
|
|
|
struct ub_randstate* ATTR_UNUSED(rnd),
|
|
|
|
int ATTR_UNUSED(use_caps_for_id), int* ATTR_UNUSED(availports),
|
2008-10-22 14:36:46 +00:00
|
|
|
int ATTR_UNUSED(numavailports), size_t ATTR_UNUSED(unwanted_threshold),
|
|
|
|
void (*unwanted_action)(void*), void* ATTR_UNUSED(unwanted_param))
|
2007-02-08 16:47:06 +00:00
|
|
|
{
|
2007-02-09 16:39:47 +00:00
|
|
|
struct outside_network* outnet = calloc(1,
|
|
|
|
sizeof(struct outside_network));
|
2008-10-22 14:36:46 +00:00
|
|
|
(void)unwanted_action;
|
2007-02-09 16:39:47 +00:00
|
|
|
if(!outnet)
|
|
|
|
return NULL;
|
|
|
|
outnet->base = base;
|
|
|
|
outnet->udp_buff = ldns_buffer_new(bufsize);
|
|
|
|
if(!outnet->udp_buff)
|
|
|
|
return NULL;
|
|
|
|
return outnet;
|
2007-02-08 16:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
outside_network_delete(struct outside_network* outnet)
|
|
|
|
{
|
2007-02-09 16:39:47 +00:00
|
|
|
if(!outnet)
|
|
|
|
return;
|
|
|
|
ldns_buffer_free(outnet->udp_buff);
|
2007-02-08 16:47:06 +00:00
|
|
|
free(outnet);
|
|
|
|
}
|
|
|
|
|
2009-05-27 08:24:19 +00:00
|
|
|
void
|
|
|
|
outside_network_quit_prepare(struct outside_network* ATTR_UNUSED(outnet))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-05-21 15:10:55 +00:00
|
|
|
struct pending*
|
2007-02-13 14:00:58 +00:00
|
|
|
pending_udp_query(struct outside_network* outnet, ldns_buffer* packet,
|
2007-02-08 16:47:06 +00:00
|
|
|
struct sockaddr_storage* addr, socklen_t addrlen, int timeout,
|
2008-04-11 13:24:49 +00:00
|
|
|
comm_point_callback_t* callback, void* callback_arg)
|
2007-02-08 16:47:06 +00:00
|
|
|
{
|
2007-02-12 16:04:11 +00:00
|
|
|
struct replay_runtime* runtime = (struct replay_runtime*)outnet->base;
|
|
|
|
struct fake_pending* pend = (struct fake_pending*)calloc(1,
|
|
|
|
sizeof(struct fake_pending));
|
|
|
|
ldns_status status;
|
|
|
|
log_assert(pend);
|
|
|
|
pend->buffer = ldns_buffer_new(ldns_buffer_capacity(packet));
|
2007-02-14 14:02:50 +00:00
|
|
|
log_assert(pend->buffer);
|
2007-02-12 16:04:11 +00:00
|
|
|
ldns_buffer_write(pend->buffer, ldns_buffer_begin(packet),
|
|
|
|
ldns_buffer_limit(packet));
|
|
|
|
ldns_buffer_flip(pend->buffer);
|
|
|
|
memcpy(&pend->addr, addr, addrlen);
|
|
|
|
pend->addrlen = addrlen;
|
|
|
|
pend->callback = callback;
|
|
|
|
pend->cb_arg = callback_arg;
|
2007-05-23 06:24:01 +00:00
|
|
|
pend->timeout = timeout/1000;
|
2007-02-12 16:04:11 +00:00
|
|
|
pend->transport = transport_udp;
|
|
|
|
pend->pkt = NULL;
|
2007-07-25 12:31:04 +00:00
|
|
|
pend->serviced = 0;
|
2007-05-22 12:36:02 +00:00
|
|
|
pend->runtime = runtime;
|
2007-02-12 16:04:11 +00:00
|
|
|
status = ldns_buffer2pkt_wire(&pend->pkt, packet);
|
|
|
|
if(status != LDNS_STATUS_OK) {
|
|
|
|
log_err("ldns error parsing udp output packet: %s",
|
|
|
|
ldns_get_errorstr_by_id(status));
|
|
|
|
fatal_exit("Sending unparseable DNS packets to servers!");
|
|
|
|
}
|
2007-02-15 12:59:26 +00:00
|
|
|
log_pkt("pending udp pkt: ", pend->pkt);
|
2007-02-12 16:04:11 +00:00
|
|
|
|
2007-05-09 07:00:10 +00:00
|
|
|
/* see if it matches the current moment */
|
|
|
|
if(runtime->now && runtime->now->evt_type == repevt_back_query &&
|
2007-07-25 12:31:04 +00:00
|
|
|
(runtime->now->addrlen == 0 || sockaddr_cmp(
|
|
|
|
&runtime->now->addr, runtime->now->addrlen,
|
|
|
|
&pend->addr, pend->addrlen) == 0) &&
|
2007-05-09 07:00:10 +00:00
|
|
|
find_match(runtime->now->match, pend->pkt, pend->transport)) {
|
|
|
|
log_info("testbound: matched pending to event. "
|
|
|
|
"advance time between events.");
|
|
|
|
log_info("testbound: do STEP %d %s", runtime->now->time_step,
|
|
|
|
repevt_string(runtime->now->evt_type));
|
|
|
|
advance_moment(runtime);
|
|
|
|
/* still create the pending, because we need it to callback */
|
|
|
|
}
|
|
|
|
log_info("testbound: created fake pending");
|
|
|
|
/* add to list */
|
|
|
|
pend->next = runtime->pending_list;
|
|
|
|
runtime->pending_list = pend;
|
2007-05-21 15:10:55 +00:00
|
|
|
return (struct pending*)pend;
|
2007-05-09 07:00:10 +00:00
|
|
|
}
|
|
|
|
|
2007-05-21 15:10:55 +00:00
|
|
|
struct waiting_tcp*
|
2007-05-09 07:00:10 +00:00
|
|
|
pending_tcp_query(struct outside_network* outnet, ldns_buffer* packet,
|
|
|
|
struct sockaddr_storage* addr, socklen_t addrlen, int timeout,
|
2008-04-11 13:24:49 +00:00
|
|
|
comm_point_callback_t* callback, void* callback_arg)
|
2007-05-09 07:00:10 +00:00
|
|
|
{
|
|
|
|
struct replay_runtime* runtime = (struct replay_runtime*)outnet->base;
|
|
|
|
struct fake_pending* pend = (struct fake_pending*)calloc(1,
|
|
|
|
sizeof(struct fake_pending));
|
|
|
|
ldns_status status;
|
|
|
|
log_assert(pend);
|
|
|
|
pend->buffer = ldns_buffer_new(ldns_buffer_capacity(packet));
|
|
|
|
log_assert(pend->buffer);
|
|
|
|
ldns_buffer_write(pend->buffer, ldns_buffer_begin(packet),
|
|
|
|
ldns_buffer_limit(packet));
|
|
|
|
ldns_buffer_flip(pend->buffer);
|
|
|
|
memcpy(&pend->addr, addr, addrlen);
|
|
|
|
pend->addrlen = addrlen;
|
|
|
|
pend->callback = callback;
|
|
|
|
pend->cb_arg = callback_arg;
|
|
|
|
pend->timeout = timeout;
|
|
|
|
pend->transport = transport_tcp;
|
|
|
|
pend->pkt = NULL;
|
2007-05-22 12:36:02 +00:00
|
|
|
pend->runtime = runtime;
|
2007-07-25 12:31:04 +00:00
|
|
|
pend->serviced = 0;
|
2007-05-09 07:00:10 +00:00
|
|
|
status = ldns_buffer2pkt_wire(&pend->pkt, packet);
|
|
|
|
if(status != LDNS_STATUS_OK) {
|
|
|
|
log_err("ldns error parsing tcp output packet: %s",
|
|
|
|
ldns_get_errorstr_by_id(status));
|
|
|
|
fatal_exit("Sending unparseable DNS packets to servers!");
|
|
|
|
}
|
|
|
|
log_pkt("pending tcp pkt: ", pend->pkt);
|
|
|
|
|
2007-02-13 14:00:58 +00:00
|
|
|
/* see if it matches the current moment */
|
|
|
|
if(runtime->now && runtime->now->evt_type == repevt_back_query &&
|
2007-07-25 12:31:04 +00:00
|
|
|
(runtime->now->addrlen == 0 || sockaddr_cmp(
|
|
|
|
&runtime->now->addr, runtime->now->addrlen,
|
|
|
|
&pend->addr, pend->addrlen) == 0) &&
|
2007-02-14 14:02:50 +00:00
|
|
|
find_match(runtime->now->match, pend->pkt, pend->transport)) {
|
2007-02-13 14:00:58 +00:00
|
|
|
log_info("testbound: matched pending to event. "
|
|
|
|
"advance time between events.");
|
2007-02-13 15:35:26 +00:00
|
|
|
log_info("testbound: do STEP %d %s", runtime->now->time_step,
|
|
|
|
repevt_string(runtime->now->evt_type));
|
2007-02-13 14:00:58 +00:00
|
|
|
advance_moment(runtime);
|
2007-02-14 14:02:50 +00:00
|
|
|
/* still create the pending, because we need it to callback */
|
2007-02-13 15:58:39 +00:00
|
|
|
}
|
|
|
|
log_info("testbound: created fake pending");
|
|
|
|
/* add to list */
|
|
|
|
pend->next = runtime->pending_list;
|
|
|
|
runtime->pending_list = pend;
|
2007-05-21 15:10:55 +00:00
|
|
|
return (struct waiting_tcp*)pend;
|
2007-02-08 16:47:06 +00:00
|
|
|
}
|
|
|
|
|
2007-05-22 12:36:02 +00:00
|
|
|
struct serviced_query* outnet_serviced_query(struct outside_network* outnet,
|
|
|
|
uint8_t* qname, size_t qnamelen, uint16_t qtype, uint16_t qclass,
|
|
|
|
uint16_t flags, int dnssec, struct sockaddr_storage* addr,
|
|
|
|
socklen_t addrlen, comm_point_callback_t* callback,
|
2007-06-18 10:27:54 +00:00
|
|
|
void* callback_arg, ldns_buffer* ATTR_UNUSED(buff),
|
|
|
|
int (*arg_compare)(void*,void*))
|
2007-05-22 12:36:02 +00:00
|
|
|
{
|
|
|
|
struct replay_runtime* runtime = (struct replay_runtime*)outnet->base;
|
|
|
|
struct fake_pending* pend = (struct fake_pending*)calloc(1,
|
|
|
|
sizeof(struct fake_pending));
|
|
|
|
ldns_status status;
|
2007-06-18 10:27:54 +00:00
|
|
|
(void)arg_compare;
|
2007-05-22 12:36:02 +00:00
|
|
|
log_assert(pend);
|
2007-09-19 12:17:42 +00:00
|
|
|
log_nametypeclass(VERB_OPS, "pending serviced query",
|
|
|
|
qname, qtype, qclass);
|
|
|
|
verbose(VERB_OPS, "pending serviced query flags%s%s%s%s",
|
|
|
|
(flags&BIT_RD)?" RD":"", (flags&BIT_CD)?" CD":"",
|
|
|
|
(flags&~(BIT_RD|BIT_CD))?" MORE":"", (dnssec)?" DO":"");
|
2007-05-22 12:36:02 +00:00
|
|
|
|
|
|
|
/* create packet with EDNS */
|
|
|
|
pend->buffer = ldns_buffer_new(512);
|
|
|
|
log_assert(pend->buffer);
|
|
|
|
ldns_buffer_write_u16(pend->buffer, 0); /* id */
|
|
|
|
ldns_buffer_write_u16(pend->buffer, flags);
|
|
|
|
ldns_buffer_write_u16(pend->buffer, 1); /* qdcount */
|
|
|
|
ldns_buffer_write_u16(pend->buffer, 0); /* ancount */
|
|
|
|
ldns_buffer_write_u16(pend->buffer, 0); /* nscount */
|
|
|
|
ldns_buffer_write_u16(pend->buffer, 0); /* arcount */
|
|
|
|
ldns_buffer_write(pend->buffer, qname, qnamelen);
|
|
|
|
ldns_buffer_write_u16(pend->buffer, qtype);
|
|
|
|
ldns_buffer_write_u16(pend->buffer, qclass);
|
|
|
|
ldns_buffer_flip(pend->buffer);
|
|
|
|
if(1) {
|
|
|
|
/* add edns */
|
|
|
|
struct edns_data edns;
|
|
|
|
edns.edns_present = 1;
|
|
|
|
edns.ext_rcode = 0;
|
|
|
|
edns.edns_version = EDNS_ADVERTISED_VERSION;
|
|
|
|
edns.udp_size = EDNS_ADVERTISED_SIZE;
|
|
|
|
edns.bits = 0;
|
|
|
|
if(dnssec)
|
|
|
|
edns.bits = EDNS_DO;
|
|
|
|
attach_edns_record(pend->buffer, &edns);
|
|
|
|
}
|
|
|
|
memcpy(&pend->addr, addr, addrlen);
|
|
|
|
pend->addrlen = addrlen;
|
|
|
|
pend->callback = callback;
|
|
|
|
pend->cb_arg = callback_arg;
|
2008-01-30 14:46:01 +00:00
|
|
|
pend->timeout = UDP_AUTH_QUERY_TIMEOUT;
|
2007-05-22 12:36:02 +00:00
|
|
|
pend->transport = transport_udp; /* pretend UDP */
|
|
|
|
pend->pkt = NULL;
|
|
|
|
pend->runtime = runtime;
|
2007-07-25 12:31:04 +00:00
|
|
|
pend->serviced = 1;
|
2007-05-22 12:36:02 +00:00
|
|
|
status = ldns_buffer2pkt_wire(&pend->pkt, pend->buffer);
|
|
|
|
if(status != LDNS_STATUS_OK) {
|
|
|
|
log_err("ldns error parsing serviced output packet: %s",
|
|
|
|
ldns_get_errorstr_by_id(status));
|
|
|
|
fatal_exit("internal error");
|
|
|
|
}
|
2007-09-19 12:17:42 +00:00
|
|
|
/*log_pkt("pending serviced query: ", pend->pkt);*/
|
2007-05-22 12:36:02 +00:00
|
|
|
|
|
|
|
/* see if it matches the current moment */
|
|
|
|
if(runtime->now && runtime->now->evt_type == repevt_back_query &&
|
2007-07-25 12:31:04 +00:00
|
|
|
(runtime->now->addrlen == 0 || sockaddr_cmp(
|
|
|
|
&runtime->now->addr, runtime->now->addrlen,
|
|
|
|
&pend->addr, pend->addrlen) == 0) &&
|
2007-05-22 12:36:02 +00:00
|
|
|
find_match(runtime->now->match, pend->pkt, pend->transport)) {
|
|
|
|
log_info("testbound: matched pending to event. "
|
|
|
|
"advance time between events.");
|
|
|
|
log_info("testbound: do STEP %d %s", runtime->now->time_step,
|
|
|
|
repevt_string(runtime->now->evt_type));
|
|
|
|
advance_moment(runtime);
|
|
|
|
/* still create the pending, because we need it to callback */
|
|
|
|
}
|
|
|
|
log_info("testbound: created fake pending");
|
|
|
|
/* add to list */
|
|
|
|
pend->next = runtime->pending_list;
|
|
|
|
runtime->pending_list = pend;
|
|
|
|
return (struct serviced_query*)pend;
|
|
|
|
}
|
|
|
|
|
|
|
|
void outnet_serviced_query_stop(struct serviced_query* sq, void* cb_arg)
|
|
|
|
{
|
|
|
|
struct fake_pending* pend = (struct fake_pending*)sq;
|
|
|
|
struct replay_runtime* runtime = pend->runtime;
|
|
|
|
/* delete from the list */
|
|
|
|
struct fake_pending* p = runtime->pending_list, *prev=NULL;
|
|
|
|
while(p) {
|
|
|
|
if(p == pend) {
|
|
|
|
log_assert(p->cb_arg == cb_arg);
|
2007-07-25 12:31:04 +00:00
|
|
|
log_info("serviced pending delete");
|
2007-05-22 12:36:02 +00:00
|
|
|
if(prev)
|
|
|
|
prev->next = p->next;
|
|
|
|
else runtime->pending_list = p->next;
|
|
|
|
ldns_buffer_free(p->buffer);
|
|
|
|
ldns_pkt_free(p->pkt);
|
|
|
|
free(p);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
prev = p;
|
|
|
|
p = p->next;
|
|
|
|
}
|
2007-07-25 12:31:04 +00:00
|
|
|
log_info("double delete of pending serviced query");
|
2007-05-22 12:36:02 +00:00
|
|
|
}
|
|
|
|
|
2007-02-22 16:22:54 +00:00
|
|
|
struct listen_port* listening_ports_open(struct config_file* ATTR_UNUSED(cfg))
|
|
|
|
{
|
|
|
|
return calloc(1, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void listening_ports_free(struct listen_port* list)
|
|
|
|
{
|
|
|
|
free(list);
|
|
|
|
}
|
|
|
|
|
2007-02-27 11:25:44 +00:00
|
|
|
void listen_pushback(struct listen_dnsport* ATTR_UNUSED(listen))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void listen_resume(struct listen_dnsport* ATTR_UNUSED(listen))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-02-26 16:11:32 +00:00
|
|
|
struct comm_point* comm_point_create_local(struct comm_base* ATTR_UNUSED(base),
|
|
|
|
int ATTR_UNUSED(fd), size_t ATTR_UNUSED(bufsize),
|
|
|
|
comm_point_callback_t* ATTR_UNUSED(callback),
|
|
|
|
void* ATTR_UNUSED(callback_arg))
|
|
|
|
{
|
|
|
|
return calloc(1, 1);
|
|
|
|
}
|
|
|
|
|
2008-07-23 09:23:03 +00:00
|
|
|
struct comm_point* comm_point_create_raw(struct comm_base* ATTR_UNUSED(base),
|
|
|
|
int ATTR_UNUSED(fd), int ATTR_UNUSED(writing),
|
|
|
|
comm_point_callback_t* ATTR_UNUSED(callback),
|
|
|
|
void* ATTR_UNUSED(callback_arg))
|
|
|
|
{
|
|
|
|
/* no pipe comm possible */
|
|
|
|
return calloc(1, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void comm_point_start_listening(struct comm_point* ATTR_UNUSED(c),
|
|
|
|
int ATTR_UNUSED(newfd), int ATTR_UNUSED(sec))
|
|
|
|
{
|
|
|
|
/* no bg write pipe comm possible */
|
|
|
|
}
|
|
|
|
|
|
|
|
void comm_point_stop_listening(struct comm_point* ATTR_UNUSED(c))
|
|
|
|
{
|
|
|
|
/* no bg write pipe comm possible */
|
|
|
|
}
|
|
|
|
|
2007-02-26 16:11:32 +00:00
|
|
|
/* only cmd com _local gets deleted */
|
|
|
|
void comm_point_delete(struct comm_point* c)
|
|
|
|
{
|
|
|
|
free(c);
|
|
|
|
}
|
2007-02-22 16:22:54 +00:00
|
|
|
|
2007-07-20 15:51:06 +00:00
|
|
|
size_t listen_get_mem(struct listen_dnsport* ATTR_UNUSED(listen))
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t outnet_get_mem(struct outside_network* ATTR_UNUSED(outnet))
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t comm_point_get_mem(struct comm_point* ATTR_UNUSED(c))
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-08-14 13:15:36 +00:00
|
|
|
size_t serviced_get_mem(struct serviced_query* ATTR_UNUSED(c))
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-10-04 15:10:11 +00:00
|
|
|
/* fake for fptr wlist */
|
|
|
|
int outnet_udp_cb(struct comm_point* ATTR_UNUSED(c),
|
|
|
|
void* ATTR_UNUSED(arg), int ATTR_UNUSED(error),
|
|
|
|
struct comm_reply *ATTR_UNUSED(reply_info))
|
|
|
|
{
|
|
|
|
log_assert(0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-10-05 08:05:06 +00:00
|
|
|
int outnet_tcp_cb(struct comm_point* ATTR_UNUSED(c),
|
|
|
|
void* ATTR_UNUSED(arg), int ATTR_UNUSED(error),
|
|
|
|
struct comm_reply *ATTR_UNUSED(reply_info))
|
|
|
|
{
|
|
|
|
log_assert(0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-10-04 15:10:11 +00:00
|
|
|
void pending_udp_timer_cb(void *ATTR_UNUSED(arg))
|
|
|
|
{
|
|
|
|
log_assert(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void outnet_tcptimer(void* ATTR_UNUSED(arg))
|
|
|
|
{
|
|
|
|
log_assert(0);
|
|
|
|
}
|
|
|
|
|
2007-10-05 08:05:06 +00:00
|
|
|
void comm_point_udp_callback(int ATTR_UNUSED(fd), short ATTR_UNUSED(event),
|
|
|
|
void* ATTR_UNUSED(arg))
|
|
|
|
{
|
|
|
|
log_assert(0);
|
|
|
|
}
|
|
|
|
|
2008-01-15 09:45:30 +00:00
|
|
|
void comm_point_udp_ancil_callback(int ATTR_UNUSED(fd),
|
|
|
|
short ATTR_UNUSED(event), void* ATTR_UNUSED(arg))
|
|
|
|
{
|
|
|
|
log_assert(0);
|
|
|
|
}
|
|
|
|
|
2007-10-05 08:05:06 +00:00
|
|
|
void comm_point_tcp_accept_callback(int ATTR_UNUSED(fd),
|
|
|
|
short ATTR_UNUSED(event), void* ATTR_UNUSED(arg))
|
|
|
|
{
|
|
|
|
log_assert(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void comm_point_tcp_handle_callback(int ATTR_UNUSED(fd),
|
|
|
|
short ATTR_UNUSED(event), void* ATTR_UNUSED(arg))
|
|
|
|
{
|
|
|
|
log_assert(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void comm_timer_callback(int ATTR_UNUSED(fd),
|
|
|
|
short ATTR_UNUSED(event), void* ATTR_UNUSED(arg))
|
|
|
|
{
|
|
|
|
log_assert(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void comm_signal_callback(int ATTR_UNUSED(fd),
|
|
|
|
short ATTR_UNUSED(event), void* ATTR_UNUSED(arg))
|
|
|
|
{
|
|
|
|
log_assert(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void comm_point_local_handle_callback(int ATTR_UNUSED(fd),
|
|
|
|
short ATTR_UNUSED(event), void* ATTR_UNUSED(arg))
|
|
|
|
{
|
|
|
|
log_assert(0);
|
|
|
|
}
|
|
|
|
|
2008-01-22 11:28:07 +00:00
|
|
|
void comm_point_raw_handle_callback(int ATTR_UNUSED(fd),
|
|
|
|
short ATTR_UNUSED(event), void* ATTR_UNUSED(arg))
|
|
|
|
{
|
|
|
|
log_assert(0);
|
|
|
|
}
|
|
|
|
|
2007-10-05 08:05:06 +00:00
|
|
|
int serviced_udp_callback(struct comm_point* ATTR_UNUSED(c),
|
|
|
|
void* ATTR_UNUSED(arg), int ATTR_UNUSED(error),
|
|
|
|
struct comm_reply* ATTR_UNUSED(reply_info))
|
|
|
|
{
|
|
|
|
log_assert(0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int serviced_tcp_callback(struct comm_point* ATTR_UNUSED(c),
|
|
|
|
void* ATTR_UNUSED(arg), int ATTR_UNUSED(error),
|
|
|
|
struct comm_reply* ATTR_UNUSED(reply_info))
|
|
|
|
{
|
|
|
|
log_assert(0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-10-05 11:41:12 +00:00
|
|
|
int pending_cmp(const void* ATTR_UNUSED(a), const void* ATTR_UNUSED(b))
|
|
|
|
{
|
|
|
|
log_assert(0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int serviced_cmp(const void* ATTR_UNUSED(a), const void* ATTR_UNUSED(b))
|
|
|
|
{
|
|
|
|
log_assert(0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-02-05 10:23:44 +00:00
|
|
|
/* no statistics timers in testbound */
|
|
|
|
struct comm_timer* comm_timer_create(struct comm_base* ATTR_UNUSED(base),
|
|
|
|
void (*cb)(void*), void* ATTR_UNUSED(cb_arg))
|
|
|
|
{
|
|
|
|
(void)cb;
|
|
|
|
return malloc(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void comm_timer_disable(struct comm_timer* ATTR_UNUSED(timer))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void comm_timer_set(struct comm_timer* ATTR_UNUSED(timer),
|
|
|
|
struct timeval* ATTR_UNUSED(tv))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void comm_timer_delete(struct comm_timer* timer)
|
|
|
|
{
|
|
|
|
free(timer);
|
|
|
|
}
|
|
|
|
|
2008-07-25 09:26:15 +00:00
|
|
|
struct event_base* comm_base_internal(struct comm_base* ATTR_UNUSED(b))
|
|
|
|
{
|
|
|
|
/* no pipe comm possible in testbound */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-12-03 15:20:56 +00:00
|
|
|
void daemon_remote_exec(struct worker* ATTR_UNUSED(worker))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-02-08 16:03:26 +00:00
|
|
|
/*********** End of Dummy routines ***********/
|