unbound  0.1
Functions | Variables
fake_event.c File Reference

Event service that replays a scenario. More...

#include "config.h"
#include "testcode/fake_event.h"
#include "util/netevent.h"
#include "util/net_help.h"
#include "util/data/msgparse.h"
#include "util/data/msgreply.h"
#include "util/data/msgencode.h"
#include "util/data/dname.h"
#include "util/config_file.h"
#include "services/listen_dnsport.h"
#include "services/outside_network.h"
#include "services/cache/infra.h"
#include "testcode/replay.h"
#include "testcode/ldns-testpkts.h"
#include "util/log.h"
#include "util/fptr_wlist.h"
#include <signal.h>

Functions

static void timeval_add (struct timeval *d, const struct timeval *add)
 add timers and the values do not overflow or become negative
void fake_temp_file (const char *adj, const char *id, char *buf, size_t len)
 Get filename to store temporary config stuff.
void fake_event_init (struct replay_scenario *scen)
 Initialise fake event services.
void fake_event_cleanup (void)
 Deinit fake event services.
static void log_pkt (const char *desc, ldns_pkt *pkt)
 helper function that logs a ldns_pkt packet to logfile
static const char * repevt_string (enum replay_event_type t)
 Returns a string describing the event type.
static void delete_fake_pending (struct fake_pending *pend)
 delete a fake pending
static void delete_replay_answer (struct replay_answer *a)
 delete a replay answer
static int pending_matches_current (struct replay_runtime *runtime, struct entry **entry, struct fake_pending **pend)
 return: true if pending query matches the now event.
static int pending_find_match (struct replay_runtime *runtime, struct entry **entry, struct fake_pending *pend)
 Find the range that matches this pending message.
static int pending_matches_range (struct replay_runtime *runtime, struct entry **entry, struct fake_pending **pend)
 See if outgoing pending query matches an entry.
static void pending_list_delete (struct replay_runtime *runtime, struct fake_pending *pend)
 Remove the item from the pending list.
static void fill_buffer_with_reply (ldns_buffer *buffer, struct entry *entry, ldns_pkt *q)
 Fill buffer with reply from the entry.
static void answer_callback_from_entry (struct replay_runtime *runtime, struct entry *entry, struct fake_pending *pend)
 Perform range entry on pending message.
static void answer_check_it (struct replay_runtime *runtime)
 Check the now moment answer check event.
static void fake_front_query (struct replay_runtime *runtime, struct replay_moment *todo)
 Create commpoint (as return address) for a fake incoming query.
static void fake_pending_callback (struct replay_runtime *runtime, struct replay_moment *todo, int error)
 Perform callback for fake pending message.
static void moment_assign (struct replay_runtime *runtime, struct replay_moment *mom)
 pass time
static void time_passes (struct replay_runtime *runtime, struct replay_moment *mom)
 pass time
static void autotrust_check (struct replay_runtime *runtime, struct replay_moment *mom)
 check autotrust file contents
static void do_infra_rtt (struct replay_runtime *runtime)
 Store RTT in infra cache.
static void advance_moment (struct replay_runtime *runtime)
 Advance to the next moment.
static void do_moment_and_advance (struct replay_runtime *runtime)
 Perform actions or checks determined by the moment.
static void run_scenario (struct replay_runtime *runtime)
 run the scenario in event callbacks
struct listen_dnsportlisten_create (struct comm_base *base, struct listen_port *ATTR_UNUSED(ports), size_t bufsize, int ATTR_UNUSED(tcp_accept_count), void *ATTR_UNUSED(sslctx), comm_point_callback_t *cb, void *cb_arg)
void listen_delete (struct listen_dnsport *listen)
 delete the listening structure
struct comm_basecomm_base_create (int ATTR_UNUSED(sigs))
void comm_base_delete (struct comm_base *b)
 Destroy a comm base.
void comm_base_timept (struct comm_base *b, uint32_t **tt, struct timeval **tv)
 Obtain two pointers.
void comm_base_dispatch (struct comm_base *b)
 Dispatch the comm base events.
void comm_base_exit (struct comm_base *b)
 Exit from dispatch loop.
struct comm_signalcomm_signal_create (struct comm_base *base, void(*callback)(int, void *), void *cb_arg)
 Create a signal handler.
int comm_signal_bind (struct comm_signal *ATTR_UNUSED(comsig), int ATTR_UNUSED(sig))
void comm_signal_delete (struct comm_signal *comsig)
 Delete the signal communication point.
void comm_point_send_reply (struct comm_reply *repinfo)
 Send reply.
void comm_point_drop_reply (struct comm_reply *repinfo)
 Drop reply.
struct outside_networkoutside_network_create (struct comm_base *base, size_t bufsize, size_t ATTR_UNUSED(num_ports), char **ATTR_UNUSED(ifs), int ATTR_UNUSED(num_ifs), int ATTR_UNUSED(do_ip4), int ATTR_UNUSED(do_ip6), size_t ATTR_UNUSED(num_tcp), struct infra_cache *infra, struct ub_randstate *ATTR_UNUSED(rnd), int ATTR_UNUSED(use_caps_for_id), int *ATTR_UNUSED(availports), int ATTR_UNUSED(numavailports), size_t ATTR_UNUSED(unwanted_threshold), void(*unwanted_action)(void *), void *ATTR_UNUSED(unwanted_param), int ATTR_UNUSED(do_udp), void *ATTR_UNUSED(sslctx))
void outside_network_delete (struct outside_network *outnet)
 Delete outside_network structure.
void outside_network_quit_prepare (struct outside_network *ATTR_UNUSED(outnet))
struct pendingpending_udp_query (struct outside_network *outnet, ldns_buffer *packet, struct sockaddr_storage *addr, socklen_t addrlen, int timeout, comm_point_callback_t *callback, void *callback_arg)
 Send UDP query, create pending answer.
struct waiting_tcppending_tcp_query (struct outside_network *outnet, ldns_buffer *packet, struct sockaddr_storage *addr, socklen_t addrlen, int timeout, comm_point_callback_t *callback, void *callback_arg, int ATTR_UNUSED(ssl_upstream))
struct serviced_queryoutnet_serviced_query (struct outside_network *outnet, uint8_t *qname, size_t qnamelen, uint16_t qtype, uint16_t qclass, uint16_t flags, int dnssec, int ATTR_UNUSED(want_dnssec), int ATTR_UNUSED(tcp_upstream), int ATTR_UNUSED(ssl_upstream), struct sockaddr_storage *addr, socklen_t addrlen, uint8_t *zone, size_t ATTR_UNUSED(zonelen), comm_point_callback_t *callback, void *callback_arg, ldns_buffer *ATTR_UNUSED(buff), int(*arg_compare)(void *, void *))
void outnet_serviced_query_stop (struct serviced_query *sq, void *cb_arg)
 Remove service query callback.
struct listen_portlistening_ports_open (struct config_file *ATTR_UNUSED(cfg))
void listening_ports_free (struct listen_port *list)
 Close and delete the (list of) listening ports.
struct comm_pointcomm_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))
struct comm_pointcomm_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))
void comm_point_start_listening (struct comm_point *ATTR_UNUSED(c), int ATTR_UNUSED(newfd), int ATTR_UNUSED(sec))
void comm_point_stop_listening (struct comm_point *ATTR_UNUSED(c))
void comm_point_delete (struct comm_point *c)
 Close and deallocate (free) the comm point.
size_t listen_get_mem (struct listen_dnsport *ATTR_UNUSED(listen))
size_t outnet_get_mem (struct outside_network *ATTR_UNUSED(outnet))
size_t comm_point_get_mem (struct comm_point *ATTR_UNUSED(c))
size_t serviced_get_mem (struct serviced_query *ATTR_UNUSED(c))
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))
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))
void pending_udp_timer_cb (void *ATTR_UNUSED(arg))
void outnet_tcptimer (void *ATTR_UNUSED(arg))
void comm_point_udp_callback (int ATTR_UNUSED(fd), short ATTR_UNUSED(event), void *ATTR_UNUSED(arg))
void comm_point_udp_ancil_callback (int ATTR_UNUSED(fd), short ATTR_UNUSED(event), void *ATTR_UNUSED(arg))
void comm_point_tcp_accept_callback (int ATTR_UNUSED(fd), short ATTR_UNUSED(event), void *ATTR_UNUSED(arg))
void comm_point_tcp_handle_callback (int ATTR_UNUSED(fd), short ATTR_UNUSED(event), void *ATTR_UNUSED(arg))
void comm_timer_callback (int ATTR_UNUSED(fd), short ATTR_UNUSED(event), void *ATTR_UNUSED(arg))
void comm_signal_callback (int ATTR_UNUSED(fd), short ATTR_UNUSED(event), void *ATTR_UNUSED(arg))
void comm_point_local_handle_callback (int ATTR_UNUSED(fd), short ATTR_UNUSED(event), void *ATTR_UNUSED(arg))
void comm_point_raw_handle_callback (int ATTR_UNUSED(fd), short ATTR_UNUSED(event), void *ATTR_UNUSED(arg))
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))
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))
int pending_cmp (const void *ATTR_UNUSED(a), const void *ATTR_UNUSED(b))
int serviced_cmp (const void *ATTR_UNUSED(a), const void *ATTR_UNUSED(b))
struct comm_timercomm_timer_create (struct comm_base *base, void(*cb)(void *), void *cb_arg)
 create timer.
void comm_timer_disable (struct comm_timer *timer)
 disable timer.
void comm_timer_set (struct comm_timer *timer, struct timeval *tv)
 reset timevalue for timer.
void comm_timer_delete (struct comm_timer *timer)
 delete timer.
struct event_base * comm_base_internal (struct comm_base *ATTR_UNUSED(b))
void daemon_remote_exec (struct worker *ATTR_UNUSED(worker))

Variables

static struct replay_scenariosaved_scenario = NULL
 Global variable: the scenario.

Detailed Description

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.


Function Documentation

void fake_temp_file ( const char *  adj,
const char *  id,
char *  buf,
size_t  len 
)

Get filename to store temporary config stuff.

The pid is added. in /tmp.

Parameters:
adj,:adjective, like "_cfg_", "_auto_"
id,:identifier, like "example.com".
buf,:where to store.
len,:length of buf.

Referenced by autotrust_check(), setup_config(), and spool_auto_file().

void fake_event_init ( struct replay_scenario scen)

Initialise fake event services.

The fake event services will automatically start when the main program calls netevent.h functions, such as comm_base_dispatch().

Parameters:
scen,:Set the scenario to use for upcoming event handling.

Referenced by main().

static int pending_find_match ( struct replay_runtime runtime,
struct entry **  entry,
struct fake_pending pend 
) [static]

Find the range that matches this pending message.

Parameters:
runtime,:runtime with current moment, and range list.
entry,:returns the pointer to entry that matches.
pend,:the pending that the entry must match.
Returns:
: true if a match is found.

References replay_range::addr, fake_pending::addr, replay_range::addrlen, fake_pending::addrlen, replay_range::end_step, find_match(), log_addr(), log_info(), log_pkt(), replay_range::match, replay_range::next_range, replay_runtime::now, fake_pending::pkt, replay_scenario::range_list, replay_runtime::scenario, sockaddr_cmp(), replay_range::start_step, replay_moment::time_step, and fake_pending::transport.

Referenced by pending_matches_range().

static int pending_matches_range ( struct replay_runtime runtime,
struct entry **  entry,
struct fake_pending **  pend 
) [static]

See if outgoing pending query matches an entry.

Parameters:
runtime,:runtime.
entry,:if true, the entry that matches is returned.
pend,:if true, the outgoing message that matches is returned.
Returns:
: true if pending query matches the now event.

References log_info(), fake_pending::next, pending_find_match(), and replay_runtime::pending_list.

Referenced by run_scenario().

static void answer_callback_from_entry ( struct replay_runtime runtime,
struct entry entry,
struct fake_pending pend 
) [static]

Perform range entry on pending message.

Parameters:
runtime,:runtime buffer size preference.
entry,:entry that codes for the reply to do.
pend,:pending query that is answered, callback called.

References comm_reply::addr, fake_pending::addr, comm_reply::addrlen, fake_pending::addrlen, comm_point::buffer, replay_runtime::bufsize, comm_reply::c, fake_pending::callback, fake_pending::cb_arg, fatal_exit(), comm_point::fd, fill_buffer_with_reply(), NETEVENT_NOERROR, pending_list_delete(), fake_pending::pkt, fake_pending::serviced, fake_pending::transport, and comm_point::type.

Referenced by run_scenario().

static void do_moment_and_advance ( struct replay_runtime runtime) [static]
void listen_delete ( struct listen_dnsport listen)

delete the listening structure

Parameters:
listen,:listening structure.

References listen_dnsport::cps, listen_list_delete(), and listen_dnsport::udp_buff.

void comm_base_delete ( struct comm_base b)

Destroy a comm base.

All comm points must have been deleted.

Parameters:
b,:the base to delete.

Referenced by libworker_delete(), and worker_delete().

void comm_base_timept ( struct comm_base b,
uint32_t **  tt,
struct timeval **  tv 
)

Obtain two pointers.

The pointers never change (until base_delete()). The pointers point to time values that are updated regularly.

Parameters:
b,:the communication base that will update the time values.
tt,:pointer to time in seconds is returned.
tv,:pointer to time in microseconds is returned.

Referenced by libworker_setup(), outside_network_create(), and worker_init().

void comm_base_dispatch ( struct comm_base b)

Dispatch the comm base events.

Parameters:
b,:the communication to perform.

Referenced by libworker_dobg(), libworker_fg(), and worker_work().

void comm_base_exit ( struct comm_base b)

Exit from dispatch loop.

Parameters:
b,:the communication base that is in dispatch().

Referenced by do_reload(), do_stop(), libworker_do_cmd(), libworker_fg_done_cb(), libworker_handle_control_cmd(), and worker_sighandler().

struct comm_signal* comm_signal_create ( struct comm_base base,
void(*)(int, void *)  callback,
void *  cb_arg 
) [read]

Create a signal handler.

Call signal_bind() later to bind to a signal.

Parameters:
base,:communication base to use.
callback,:called when signal is caught.
cb_arg,:user argument to callback
Returns:
: the signal struct or NULL on error.

Referenced by worker_init().

void comm_signal_delete ( struct comm_signal comsig)

Delete the signal communication point.

Parameters:
comsig,:to delete.

Referenced by worker_delete().

void comm_point_send_reply ( struct comm_reply repinfo)

Send reply.

Put message into commpoint buffer.

Parameters:
repinfo,:The reply info copied from a commpoint callback call.

Referenced by fake_front_query(), mesh_new_client(), mesh_send_reply(), and reply_and_prefetch().

void comm_point_drop_reply ( struct comm_reply repinfo)

Drop reply.

Cleans up.

Parameters:
repinfo,:The reply info copied from a commpoint callback call.

Referenced by mesh_new_client(), mesh_state_cleanup(), and worker_handle_request().

void outside_network_delete ( struct outside_network outnet)
struct pending* pending_udp_query ( struct outside_network outnet,
ldns_buffer *  packet,
struct sockaddr_storage *  addr,
socklen_t  addrlen,
int  timeout,
comm_point_callback_t callback,
void *  callback_arg 
) [read]

Send UDP query, create pending answer.

Changes the ID for the query to be random and unique for that destination.

Parameters:
outnet,:provides the event handling
packet,:wireformat query to send to destination.
addr,:address to send to.
addrlen,:length of addr.
timeout,:in milliseconds from now.
callback,:function to call on error, timeout or reply.
callback_arg,:user argument for callback function.
Returns:
: NULL on error for malloc or socket. Else the pending query object.

References pending::addr, replay_moment::addr, pending::addrlen, replay_moment::addrlen, advance_moment(), outside_network::base, pending::cb, pending::cb_arg, comm_timer_create(), comm_timer_delete(), replay_moment::evt_type, fatal_exit(), find_match(), rbnode_t::key, log_assert, log_err(), log_info(), log_pkt(), replay_moment::match, memdup(), pending::next_waiting, pending::node, replay_runtime::now, pending::outnet, pending_delete(), replay_runtime::pending_list, pending_udp_timer_cb(), pending::pkt, pending::pkt_len, randomize_and_send_udp(), repevt_string(), sockaddr_cmp(), replay_moment::time_step, pending::timeout, pending::timer, outside_network::udp_wait_first, outside_network::udp_wait_last, outside_network::unused_fds, VERB_ALGO, and verbose().

void outnet_serviced_query_stop ( struct serviced_query sq,
void *  cb_arg 
)

Remove service query callback.

If that leads to zero callbacks, the query is completely cancelled.

Parameters:
sq,:serviced query to adjust.
cb_arg,:callback argument of callback that needs removal. same as the callback_arg to outnet_serviced_query().

References fake_pending::buffer, callback_list_remove(), fake_pending::cb_arg, serviced_query::cblist, log_assert, log_info(), fake_pending::next, serviced_query::outnet, replay_runtime::pending_list, fake_pending::pkt, rbtree_delete(), fake_pending::runtime, outside_network::serviced, serviced_delete(), and serviced_query::to_be_deleted.

void comm_point_delete ( struct comm_point c)

Close and deallocate (free) the comm point.

If the comm point is a tcp-accept point, also its tcp-handler points are deleted.

Parameters:
c,:comm point to delete.

Referenced by clean_point(), comm_point_create_tcp(), comm_point_create_udp(), comm_point_create_udp_ancil(), comm_point_delete(), daemon_remote_clear(), listen_create(), listen_list_delete(), outside_network_delete(), tube_remove_bg_listen(), and tube_remove_bg_write().

struct comm_timer* comm_timer_create ( struct comm_base base,
void(*)(void *)  cb,
void *  cb_arg 
) [read]

create timer.

Not active upon creation.

Parameters:
base,:event handling base.
cb,:callback function: void myfunc(void* myarg);
cb_arg,:user callback argument.
Returns:
: the new timer or NULL on error.

Referenced by pending_tcp_query(), pending_udp_query(), worker_init(), and wsvc_setup_worker().

void comm_timer_disable ( struct comm_timer timer)

disable timer.

Stops callbacks from happening.

Parameters:
timer,:to disable.

Referenced by comm_timer_delete(), comm_timer_set(), and outnet_udp_cb().

void comm_timer_set ( struct comm_timer timer,
struct timeval *  tv 
)

reset timevalue for timer.

Parameters:
timer,:timer to (re)set.
tv,:when the timer should activate. if NULL timer is disabled.

Referenced by pending_tcp_query(), randomize_and_send_udp(), reset_worker_timer(), set_cron_timer(), worker_init(), worker_probe_timer_cb(), and worker_restart_timer().

void comm_timer_delete ( struct comm_timer timer)

delete timer.

Parameters:
timer,:to delete.

Referenced by pending_delete(), pending_udp_query(), waiting_tcp_delete(), and worker_delete().


Variable Documentation

struct replay_scenario* saved_scenario = NULL [static]

Global variable: the scenario.

Saved here for when event_init is done.