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 *ports, size_t bufsize, int tcp_accept_count, void *sslctx, comm_point_callback_t *cb, void *cb_arg)
 Create commpoints with for this thread for the shared ports.
void listen_delete (struct listen_dnsport *listen)
 delete the listening structure
struct comm_basecomm_base_create (int sigs)
 Create a new comm base.
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 *comsig, int sig)
 Bind signal struct to catch a signal.
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 num_ports, char **ifs, int num_ifs, int do_ip4, int do_ip6, size_t num_tcp, struct infra_cache *infra, struct ub_randstate *rnd, int use_caps_for_id, int *availports, int numavailports, size_t unwanted_threshold, void(*unwanted_action)(void *), void *unwanted_param, int do_udp, void *sslctx)
 Create outside_network structure with N udp ports.
void outside_network_delete (struct outside_network *outnet)
 Delete outside_network structure.
void outside_network_quit_prepare (struct outside_network *outnet)
 Prepare for quit.
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 ssl_upstream)
 Send TCP query.
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 want_dnssec, int tcp_upstream, int ssl_upstream, struct sockaddr_storage *addr, socklen_t addrlen, uint8_t *zone, size_t zonelen, comm_point_callback_t *callback, void *callback_arg, ldns_buffer *buff, int(*arg_compare)(void *, void *))
 Perform a serviced query to the authoritative servers.
void outnet_serviced_query_stop (struct serviced_query *sq, void *cb_arg)
 Remove service query callback.
struct listen_portlistening_ports_open (struct config_file *cfg)
 Create shared listening ports Getaddrinfo, create socket, bind and listen to zero or more interfaces for IP4 and/or IP6, for UDP and/or TCP.
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 *base, int fd, size_t bufsize, comm_point_callback_t *callback, void *callback_arg)
 Create commpoint to listen to a local domain file descriptor.
struct comm_pointcomm_point_create_raw (struct comm_base *base, int fd, int writing, comm_point_callback_t *callback, void *callback_arg)
 Create commpoint to listen to a local domain pipe descriptor.
void comm_point_start_listening (struct comm_point *c, int newfd, int sec)
 Start listening again for input on the comm point.
void comm_point_stop_listening (struct comm_point *c)
 Stop listening for input on the commpoint.
void comm_point_delete (struct comm_point *c)
 Close and deallocate (free) the comm point.
size_t listen_get_mem (struct listen_dnsport *listen)
 get memory size used by the listening structs
size_t outnet_get_mem (struct outside_network *outnet)
 Get memory size in use by outside network.
size_t comm_point_get_mem (struct comm_point *c)
 Get size of memory used by comm point.
size_t serviced_get_mem (struct serviced_query *c)
 Get memory size in use by serviced query while it is servicing callbacks.
int outnet_udp_cb (struct comm_point *c, void *arg, int error, struct comm_reply *reply_info)
 callback for incoming udp answers from the network
int outnet_tcp_cb (struct comm_point *c, void *arg, int error, struct comm_reply *reply_info)
 callback for pending tcp connections
void pending_udp_timer_cb (void *arg)
 callback for udp timeout
void outnet_tcptimer (void *arg)
 callback for outgoing TCP timer event
void comm_point_udp_callback (int fd, short event, void *arg)
 This routine is published for checks and tests, and is only used internally.
void comm_point_udp_ancil_callback (int fd, short event, void *arg)
 This routine is published for checks and tests, and is only used internally.
void comm_point_tcp_accept_callback (int fd, short event, void *arg)
 This routine is published for checks and tests, and is only used internally.
void comm_point_tcp_handle_callback (int fd, short event, void *arg)
 This routine is published for checks and tests, and is only used internally.
void comm_timer_callback (int fd, short event, void *arg)
 This routine is published for checks and tests, and is only used internally.
void comm_signal_callback (int fd, short event, void *arg)
 This routine is published for checks and tests, and is only used internally.
void comm_point_local_handle_callback (int fd, short event, void *arg)
 This routine is published for checks and tests, and is only used internally.
void comm_point_raw_handle_callback (int fd, short event, void *arg)
 This routine is published for checks and tests, and is only used internally.
int serviced_udp_callback (struct comm_point *c, void *arg, int error, struct comm_reply *reply_info)
 callback for serviced query UDP answers
int serviced_tcp_callback (struct comm_point *c, void *arg, int error, struct comm_reply *reply_info)
 TCP reply or error callback for serviced queries.
int pending_cmp (const void *a, const void *b)
 compare function of pending rbtree
int serviced_cmp (const void *a, const void *b)
 compare function of serviced query rbtree
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 *b)
 Access internal data structure (for util/tube.c on windows)
void daemon_remote_exec (struct worker *worker)
 Handle nonthreaded remote cmd execution.

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(), spool_auto_file(), and setup_config().

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_runtime::now, replay_moment::time_step, replay_runtime::scenario, replay_scenario::range_list, replay_range::start_step, replay_range::end_step, replay_range::addrlen, sockaddr_cmp(), replay_range::addr, fake_pending::addr, fake_pending::addrlen, find_match(), replay_range::match, fake_pending::pkt, fake_pending::transport, log_info(), log_addr(), log_pkt(), and replay_range::next_range.

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 replay_runtime::pending_list, log_info(), pending_find_match(), and fake_pending::next.

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 fake_pending::cb_arg, fake_pending::callback, comm_point::fd, comm_point::buffer, replay_runtime::bufsize, comm_point::type, fake_pending::transport, fill_buffer_with_reply(), fake_pending::pkt, comm_reply::c, comm_reply::addrlen, fake_pending::addrlen, comm_reply::addr, fake_pending::addr, fake_pending::serviced, pending_list_delete(), NETEVENT_NOERROR, and fatal_exit().

Referenced by run_scenario().

static void do_moment_and_advance ( struct replay_runtime runtime) [static]
struct listen_dnsport* listen_create ( struct comm_base base,
struct listen_port ports,
size_t  bufsize,
int  tcp_accept_count,
void *  sslctx,
comm_point_callback_t cb,
void *  cb_arg 
) [read]

Create commpoints with for this thread for the shared ports.

Parameters:
base,:the comm_base that provides event functionality. for default all ifs.
ports,:the list of shared ports.
bufsize,:size of datagram buffer.
tcp_accept_count,:max number of simultaneous TCP connections from clients.
sslctx,:nonNULL if ssl context.
cb,:callback function when a request arrives. It is passed the packet and user argument. Return true to send a reply.
cb_arg,:user data argument for callback function.
Returns:
: the malloced listening structure, ready for use. NULL on error.

References listen_dnsport::cps, listen_dnsport::udp_buff, listen_port::ftype, listen_type_udp, comm_point_create_udp(), listen_port::fd, listen_type_tcp, comm_point_create_tcp(), listen_type_ssl, comm_point::ssl, listen_type_udpancil, comm_point_create_udp_ancil(), log_err(), listen_delete(), comm_point::do_not_close, listen_cp_insert(), comm_point_delete(), listen_port::next, listen_dnsport::base, replay_runtime::callback_query, replay_runtime::cb_arg, and replay_runtime::bufsize.

void listen_delete ( struct listen_dnsport listen)

delete the listening structure

Parameters:
listen,:listening structure.

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

struct comm_base* comm_base_create ( int  sigs) [read]

Create a new comm base.

Parameters:
sigs,:if true it attempts to create a default loop for signal handling.
Returns:
: the new comm base. NULL on error.

Referenced by worker_init(), and libworker_setup().

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 worker_delete(), and libworker_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 worker_init(), libworker_setup(), and outside_network_create().

void comm_base_dispatch ( struct comm_base b)

Dispatch the comm base events.

Parameters:
b,:the communication to perform.

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

void comm_base_exit ( struct comm_base b)

Exit from dispatch loop.

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

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

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().

int comm_signal_bind ( struct comm_signal comsig,
int  sig 
)

Bind signal struct to catch a signal.

A signle comm_signal can be bound to multiple signals, calling comm_signal_bind multiple times.

Parameters:
comsig,:the communication point, with callback information.
sig,:signal number.
Returns:
: true on success. false 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 reply_and_prefetch(), mesh_new_client(), mesh_send_reply(), and fake_front_query().

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 worker_handle_request(), mesh_new_client(), and mesh_state_cleanup().

struct outside_network* outside_network_create ( struct comm_base base,
size_t  bufsize,
size_t  num_ports,
char **  ifs,
int  num_ifs,
int  do_ip4,
int  do_ip6,
size_t  num_tcp,
struct infra_cache infra,
struct ub_randstate rnd,
int  use_caps_for_id,
int *  availports,
int  numavailports,
size_t  unwanted_threshold,
void(*)(void *)  unwanted_action,
void *  unwanted_param,
int  do_udp,
void *  sslctx 
) [read]

Create outside_network structure with N udp ports.

Parameters:
base,:the communication base to use for event handling.
bufsize,:size for network buffers.
num_ports,:number of udp ports to open per interface.
ifs,:interface names (or NULL for default interface). These interfaces must be able to access all authoritative servers.
num_ifs,:number of names in array ifs.
do_ip4,:service IP4.
do_ip6,:service IP6.
num_tcp,:number of outgoing tcp buffers to preallocate.
infra,:pointer to infra cached used for serviced queries.
rnd,:stored to create random numbers for serviced queries.
use_caps_for_id,:enable to use 0x20 bits to encode id randomness.
availports,:array of available ports.
numavailports,:number of available ports in array.
unwanted_threshold,:when to take defensive action.
unwanted_action,:the action to take.
unwanted_param,:user parameter to action.
do_udp,:if udp is done.
sslctx,:context to create outgoing connections with (if enabled).
Returns:
: the new structure (with no pending answers) or NULL on error.

References log_err(), comm_base_timept(), outside_network::now_secs, outside_network::now_tv, outside_network::base, outside_network::num_tcp, outside_network::infra, outside_network::rnd, outside_network::sslctx, outside_network::svcd_overhead, outside_network::want_to_quit, outside_network::unwanted_threshold, outside_network::unwanted_action, outside_network::unwanted_param, outside_network::use_caps_for_id, outside_network::do_udp, outside_network_delete(), calc_num46(), outside_network::num_ip4, outside_network::num_ip6, outside_network::ip4_ifs, outside_network::ip6_ifs, outside_network::udp_buff, outside_network::pending, rbtree_create(), pending_cmp(), outside_network::serviced, serviced_cmp(), create_pending_tcp(), port_comm::cp, comm_point_create_udp(), outnet_udp_cb(), port_comm::next, outside_network::unused_fds, setup_if(), str_is_ip6(), and replay_runtime::infra.

void outside_network_delete ( struct outside_network outnet)
void outside_network_quit_prepare ( struct outside_network outnet)

Prepare for quit.

Sends no more queries, even if queued up.

Parameters:
outnet,:object to prepare for removal

References outside_network::want_to_quit.

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

struct waiting_tcp* pending_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  ssl_upstream 
) [read]

Send TCP query.

May wait for TCP buffer. Selects ID to be random, and checks id.

Parameters:
outnet,:provides the event handling.
packet,:wireformat query to send to destination. copied from.
addr,:address to send to.
addrlen,:length of addr.
timeout,:in seconds from now. Timer starts running now. Timer may expire if all buffers are used, without any query been sent to the server yet.
callback,:function to call on error, timeout or reply.
callback_arg,:user argument for callback function.
ssl_upstream,:if the tcp connection must use SSL.
Returns:
: false on error for malloc or socket. Else the pending TCP object.

References outside_network::tcp_free, waiting_tcp::timer, comm_timer_create(), outside_network::base, outnet_tcptimer(), waiting_tcp::pkt, waiting_tcp::pkt_len, ub_random(), outside_network::rnd, waiting_tcp::addr, waiting_tcp::addrlen, waiting_tcp::outnet, waiting_tcp::cb, waiting_tcp::cb_arg, waiting_tcp::ssl_upstream, comm_timer_set(), outnet_tcp_take_into_use(), waiting_tcp_delete(), waiting_tcp::next_waiting, outside_network::tcp_wait_last, outside_network::tcp_wait_first, log_assert, log_err(), fatal_exit(), log_pkt(), replay_runtime::now, replay_moment::evt_type, replay_moment::addrlen, sockaddr_cmp(), replay_moment::addr, find_match(), replay_moment::match, log_info(), replay_moment::time_step, repevt_string(), advance_moment(), and replay_runtime::pending_list.

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,
int  want_dnssec,
int  tcp_upstream,
int  ssl_upstream,
struct sockaddr_storage *  addr,
socklen_t  addrlen,
uint8_t *  zone,
size_t  zonelen,
comm_point_callback_t callback,
void *  callback_arg,
ldns_buffer *  buff,
int(*)(void *, void *)  arg_compare 
) [read]

Perform a serviced query to the authoritative servers.

Duplicate efforts are detected, and EDNS, TCP and UDP retry is performed.

Parameters:
outnet,:outside network, with rbtree of serviced queries.
qname,:what qname to query.
qnamelen,:length of qname in octets including 0 root label.
qtype,:rrset type to query (host format)
qclass,:query class. (host format)
flags,:flags u16 (host format), includes opcode, CD bit.
dnssec,:if set, DO bit is set in EDNS queries. If the value includes BIT_CD, CD bit is set when in EDNS queries. If the value includes BIT_DO, DO bit is set when in EDNS queries.
want_dnssec,:signatures are needed, without EDNS the answer is likely to be useless.
tcp_upstream,:use TCP for upstream queries.
ssl_upstream,:use SSL for upstream queries.
callback,:callback function.
callback_arg,:user argument to callback function.
addr,:to which server to send the query.
addrlen,:length of addr.
zone,:name of the zone of the delegation point. wireformat dname. This is the delegation point name for which the server is deemed authoritative.
zonelen,:length of zone.
buff,:scratch buffer to create query contents in. Empty on exit.
arg_compare,:function to compare callback args, return true if identical. It is given the callback_arg and args that are listed.
Returns:
0 on error, or pointer to serviced query that is used to answer this serviced query may be shared with other callbacks as well.

References service_callback::cb, serviced_gen_query(), lookup_serviced(), callback_list_find(), serviced_create(), outside_network::do_udp, serviced_udp_send(), rbtree_delete(), outside_network::serviced, serviced_query::qbuf, serviced_query::zone, serviced_tcp_send(), service_callback::cb_arg, service_callback::next, serviced_query::cblist, outside_network::base, log_assert, log_nametypeclass(), VERB_OPS, dname_str(), verbose(), BIT_RD, BIT_CD, edns_data::edns_present, edns_data::ext_rcode, edns_data::edns_version, EDNS_ADVERTISED_VERSION, edns_data::udp_size, EDNS_ADVERTISED_SIZE, edns_data::bits, EDNS_DO, attach_edns_record(), UDP_AUTH_QUERY_TIMEOUT, log_err(), fatal_exit(), replay_runtime::now, replay_moment::evt_type, replay_moment::addrlen, sockaddr_cmp(), replay_moment::addr, find_match(), replay_moment::match, log_info(), replay_moment::time_step, repevt_string(), advance_moment(), and replay_runtime::pending_list.

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 callback_list_remove(), serviced_query::cblist, serviced_query::to_be_deleted, rbtree_delete(), serviced_query::outnet, outside_network::serviced, log_assert, serviced_delete(), fake_pending::runtime, replay_runtime::pending_list, fake_pending::cb_arg, log_info(), fake_pending::next, fake_pending::buffer, and fake_pending::pkt.

struct listen_port* listening_ports_open ( struct config_file cfg) [read]

Create shared listening ports Getaddrinfo, create socket, bind and listen to zero or more interfaces for IP4 and/or IP6, for UDP and/or TCP.

On the given port number. It creates the sockets.

Parameters:
cfg,:settings on what ports to open.
Returns:
: linked list of ports or NULL on error.

References config_file::port, config_file::do_ip4, config_file::do_ip6, config_file::do_tcp, config_file::if_automatic, config_file::do_udp, config_file::incoming_num_tcp, config_file::num_ifs, ports_create_if(), config_file::so_rcvbuf, config_file::so_sndbuf, config_file::ssl_port, listening_ports_free(), str_is_ip6(), and config_file::ifs.

struct comm_point* comm_point_create_local ( struct comm_base base,
int  fd,
size_t  bufsize,
comm_point_callback_t callback,
void *  callback_arg 
) [read]

Create commpoint to listen to a local domain file descriptor.

Parameters:
base,:in which base to alloc the commpoint.
fd,:file descriptor of open AF_UNIX socket set to listen nonblocking.
bufsize,:size of buffer to create for handlers.
callback,:callback function pointer for the handler.
callback_arg,:will be passed to your callback function.
Returns:
: the commpoint or NULL on error.
struct comm_point* comm_point_create_raw ( struct comm_base base,
int  fd,
int  writing,
comm_point_callback_t callback,
void *  callback_arg 
) [read]

Create commpoint to listen to a local domain pipe descriptor.

Parameters:
base,:in which base to alloc the commpoint.
fd,:file descriptor.
writing,:true if you want to listen to writes, false for reads.
callback,:callback function pointer for the handler.
callback_arg,:will be passed to your callback function.
Returns:
: the commpoint or NULL on error.

Referenced by accept_open(), remote_accept_callback(), tube_setup_bg_listen(), and tube_setup_bg_write().

void comm_point_start_listening ( struct comm_point c,
int  newfd,
int  sec 
)

Start listening again for input on the comm point.

Parameters:
c,:commpoint to enable again.
newfd,:new fd, or -1 to leave fd be.
sec,:timeout in seconds, or -1 for no (change to the) timeout.

Referenced by remote_accept_callback(), outnet_tcp_take_into_use(), select_ifport(), setup_tcp_handler(), reclaim_tcp_handler(), tcp_callback_writer(), tcp_callback_reader(), comm_point_send_reply(), and tube_queue_item().

void comm_point_stop_listening ( struct comm_point c)

Stop listening for input on the commpoint.

No callbacks will happen.

Parameters:
c,:commpoint to disable. The fd is not closed.

Referenced by remote_accept_callback(), comm_point_tcp_accept_callback(), tcp_callback_writer(), tcp_callback_reader(), and tube_handle_write().

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 daemon_remote_clear(), remote_accept_callback(), clean_point(), listen_create(), listen_list_delete(), outside_network_delete(), comm_point_create_udp(), comm_point_create_udp_ancil(), comm_point_create_tcp(), comm_point_delete(), tube_remove_bg_listen(), and tube_remove_bg_write().

size_t listen_get_mem ( struct listen_dnsport listen)

get memory size used by the listening structs

Parameters:
listen,:listening structure.
Returns:
: size in bytes.

References listen_dnsport::base, listen_dnsport::udp_buff, listen_dnsport::cps, listen_list::next, comm_point_get_mem(), and listen_list::com.

size_t outnet_get_mem ( struct outside_network outnet)
size_t comm_point_get_mem ( struct comm_point c)

Get size of memory used by comm point.

For TCP handlers this includes subhandlers. For UDP handlers, this does not include the (shared) UDP buffer.

Parameters:
c,:commpoint.
Returns:
size in bytes.

Referenced by worker_mem_report(), listen_get_mem(), if_get_mem(), outnet_get_mem(), and comm_point_get_mem().

size_t serviced_get_mem ( struct serviced_query sq)

Get memory size in use by serviced query while it is servicing callbacks.

This takes into account the pre-deleted status of it; it will be deleted when the callbacks are done.

Parameters:
sq,:serviced query.
Returns:
size in bytes.

References serviced_query::qbuflen, serviced_query::cblist, service_callback::next, serviced_query::status, and comm_timer_get_mem().

void comm_point_udp_callback ( int  fd,
short  event,
void *  arg 
)

This routine is published for checks and tests, and is only used internally.

handle libevent callback for udp comm point.

Parameters:
fd,:file descriptor.
event,:event bits from libevent: EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT.
arg,:the comm_point structure.

Referenced by fptr_whitelist_event(), and comm_point_create_udp().

void comm_point_udp_ancil_callback ( int  fd,
short  event,
void *  arg 
)

This routine is published for checks and tests, and is only used internally.

handle libevent callback for udp ancillary data comm point.

Parameters:
fd,:file descriptor.
event,:event bits from libevent: EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT.
arg,:the comm_point structure.

Referenced by fptr_whitelist_event(), and comm_point_create_udp_ancil().

void comm_point_tcp_accept_callback ( int  fd,
short  event,
void *  arg 
)

This routine is published for checks and tests, and is only used internally.

handle libevent callback for tcp accept comm point

Parameters:
fd,:file descriptor.
event,:event bits from libevent: EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT.
arg,:the comm_point structure.

Referenced by fptr_whitelist_event(), and comm_point_create_tcp().

void comm_point_tcp_handle_callback ( int  fd,
short  event,
void *  arg 
)

This routine is published for checks and tests, and is only used internally.

handle libevent callback for tcp data comm point

Parameters:
fd,:file descriptor.
event,:event bits from libevent: EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT.
arg,:the comm_point structure.

Referenced by fptr_whitelist_event(), comm_point_create_tcp_handler(), and comm_point_create_tcp_out().

void comm_timer_callback ( int  fd,
short  event,
void *  arg 
)

This routine is published for checks and tests, and is only used internally.

handle libevent callback for timer comm.

Parameters:
fd,:file descriptor (always -1).
event,:event bits from libevent: EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT.
arg,:the comm_timer structure.

Referenced by fptr_whitelist_event(), comm_timer_create(), and comm_timer_set().

void comm_signal_callback ( int  fd,
short  event,
void *  arg 
)

This routine is published for checks and tests, and is only used internally.

handle libevent callback for signal comm.

Parameters:
fd,:file descriptor (used for the signal number).
event,:event bits from libevent: EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT.
arg,:the internal commsignal structure.

Referenced by fptr_whitelist_event(), and comm_signal_bind().

void comm_point_local_handle_callback ( int  fd,
short  event,
void *  arg 
)

This routine is published for checks and tests, and is only used internally.

libevent callback for AF_UNIX fds

Parameters:
fd,:file descriptor.
event,:event bits from libevent: EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT.
arg,:the comm_point structure.

Referenced by fptr_whitelist_event(), and comm_point_create_local().

void comm_point_raw_handle_callback ( int  fd,
short  event,
void *  arg 
)

This routine is published for checks and tests, and is only used internally.

libevent callback for raw fd access.

Parameters:
fd,:file descriptor.
event,:event bits from libevent: EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT.
arg,:the comm_point structure.

Referenced by fptr_whitelist_event(), and comm_point_create_raw().

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 worker_init(), pending_udp_query(), pending_tcp_query(), and wsvc_setup_worker().

void comm_timer_disable ( struct comm_timer timer)

disable timer.

Stops callbacks from happening.

Parameters:
timer,:to disable.

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

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 worker_restart_timer(), worker_probe_timer_cb(), worker_init(), randomize_and_send_udp(), pending_tcp_query(), reset_worker_timer(), and set_cron_timer().

void comm_timer_delete ( struct comm_timer timer)

delete timer.

Parameters:
timer,:to delete.

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

struct event_base* comm_base_internal ( struct comm_base b) [read]

Access internal data structure (for util/tube.c on windows)

Parameters:
b,:comm base
Returns:
event_base. Could be libevent, or internal event handler.

Referenced by wsvc_setup_worker().

void daemon_remote_exec ( struct worker worker)

Handle nonthreaded remote cmd execution.

Parameters:
worker,:this worker (the remote worker).

References tube_read_msg(), worker::cmd, log_err(), verbose(), VERB_ALGO, and execute_cmd().


Variable Documentation

struct replay_scenario* saved_scenario = NULL [static]

Global variable: the scenario.

Saved here for when event_init is done.

Referenced by comm_base_create().