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 "services/listen_dnsport.h"
#include "services/outside_network.h"
#include "testcode/replay.h"
#include "testcode/ldns-testpkts.h"
#include "util/log.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_event_init (struct replay_scenario *scen)
 Initialise fake event services.
void fake_event_cleanup ()
 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 time_passes (struct replay_runtime *runtime, struct replay_moment *mom)
 pass time
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, 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)
 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)
 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, struct sockaddr_storage *addr, socklen_t addrlen, 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.
void listen_pushback (struct listen_dnsport *listen)
 Stop listening to the dnsports.
void listen_resume (struct listen_dnsport *listen)
 Start listening again to the dnsports.
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_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 fake_pending::addr, replay_range::addr, fake_pending::addrlen, replay_range::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. return: 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]

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,
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.
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::base, replay_runtime::bufsize, replay_runtime::callback_query, replay_runtime::cb_arg, comm_point_create_tcp(), comm_point_create_udp(), comm_point_create_udp_ancil(), comm_point_delete(), listen_dnsport::cps, comm_point::do_not_close, listen_port::fd, listen_port::ftype, listen_cp_insert(), listen_delete(), listen_type_tcp, listen_type_udp, listen_type_udpancil, log_err(), listen_port::next, and listen_dnsport::udp_buff.

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.

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

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(), worker_handle_control_cmd(), worker_sighandler(), 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 fake_front_query(), mesh_new_client(), and mesh_send_reply().

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

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 
) [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.
Returns:
: the new structure (with no pending answers) or NULL on error.

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

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 replay_moment::addr, pending::addr, replay_moment::addrlen, pending::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().

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 
) [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.
Returns:
: false on error for malloc or socket. Else the pending TCP object.

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

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,
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.
callback,: callback function.
callback_arg,: user argument to callback function.
addr,: to which server to send the query.
addrlen,: length of addr.
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 replay_moment::addr, replay_moment::addrlen, advance_moment(), attach_edns_record(), outside_network::base, BIT_CD, BIT_RD, edns_data::bits, callback_list_find(), service_callback::cb, service_callback::cb_arg, serviced_query::cblist, EDNS_ADVERTISED_SIZE, EDNS_ADVERTISED_VERSION, EDNS_DO, edns_data::edns_present, edns_data::edns_version, replay_moment::evt_type, edns_data::ext_rcode, fatal_exit(), find_match(), log_assert, log_err(), log_info(), log_nametypeclass(), lookup_serviced(), replay_moment::match, service_callback::next, replay_runtime::now, replay_runtime::pending_list, serviced_query::qbuf, rbtree_delete(), repevt_string(), outside_network::serviced, serviced_create(), serviced_gen_query(), serviced_udp_send(), sockaddr_cmp(), replay_moment::time_step, UDP_AUTH_QUERY_TIMEOUT, edns_data::udp_size, VERB_OPS, 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.

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::do_ip4, config_file::do_ip6, config_file::do_tcp, config_file::do_udp, config_file::if_automatic, config_file::ifs, config_file::incoming_num_tcp, listening_ports_free(), log_warn(), config_file::num_ifs, config_file::port, ports_create_if(), and str_is_ip6().

void listen_pushback ( struct listen_dnsport listen  ) 

Stop listening to the dnsports.

Ports are still open but not checked for readability - performs pushback of the load.

Parameters:
listen,: the listening structs to stop listening on. Note that udp and tcp-accept handlers stop, but ongoing tcp-handlers are kept going, since its rude to 'reset connection by peer' them, instead, we keep them and the callback will be called when its ready. It can be dropped at that time. New tcp and udp queries can be served by other threads.

References listen_list::com, comm_point_stop_listening(), listen_dnsport::cps, log_assert, listen_list::next, and comm_point::type.

void listen_resume ( struct listen_dnsport listen  ) 

Start listening again to the dnsports.

Call after the listen_pushback has been called.

Parameters:
listen,: the listening structs to stop listening on.

References listen_list::com, comm_point_start_listening(), listen_dnsport::cps, log_assert, listen_list::next, and comm_point::type.

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 comm_point_send_reply(), listen_resume(), outnet_tcp_take_into_use(), reclaim_tcp_handler(), remote_accept_callback(), select_ifport(), setup_tcp_handler(), tcp_callback_reader(), tcp_callback_writer(), 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 comm_point_tcp_accept_callback(), listen_pushback(), remote_accept_callback(), tcp_callback_reader(), tcp_callback_writer(), 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 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().

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_list::com, comm_point_get_mem(), listen_dnsport::cps, listen_list::next, and listen_dnsport::udp_buff.

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 comm_point_get_mem(), if_get_mem(), listen_get_mem(), outnet_get_mem(), and worker_mem_report().

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::cblist, comm_timer_get_mem(), service_callback::next, serviced_query::qbuflen, and serviced_query::status.

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 comm_point_create_udp(), and fptr_whitelist_event().

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 comm_point_create_udp_ancil(), and fptr_whitelist_event().

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 comm_point_create_tcp(), and fptr_whitelist_event().

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 comm_point_create_tcp_handler(), comm_point_create_tcp_out(), and fptr_whitelist_event().

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 comm_timer_create(), comm_timer_set(), and fptr_whitelist_event().

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 comm_signal_bind(), and fptr_whitelist_event().

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 comm_point_create_local(), and fptr_whitelist_event().

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 comm_point_create_raw(), and fptr_whitelist_event().

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(), set_cron_timer(), 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(), worker_delete(), 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 worker::cmd, execute_cmd(), log_err(), tube_read_msg(), VERB_ALGO, and verbose().


Variable Documentation

struct replay_scenario* saved_scenario = NULL [static]

Global variable: the scenario.

Saved here for when event_init is done.


Generated on Tue Oct 13 06:46:31 2009 for unbound by  doxygen 1.5.9