Data Structures | Macros | Functions
netevent.c File Reference

This file contains event notification functions. More...

#include "config.h"
#include "util/netevent.h"
#include "util/log.h"
#include "util/net_help.h"
#include "util/fptr_wlist.h"
#include "ldns/pkthdr.h"
#include "ldns/sbuffer.h"
#include "dnstap/dnstap.h"
#include "event2/event.h"
#include "event2/event_struct.h"
#include "event2/event_compat.h"

Data Structures

struct  internal_event
 The internal event structure for keeping libevent info for the event. More...
 
struct  internal_base
 Internal base structure, so that every thread has its own events. More...
 
struct  internal_timer
 Internal timer structure, to store timer event in. More...
 
struct  internal_signal
 Internal signal structure, to store signal event in. More...
 

Macros

#define CMSG_ALIGN(len)   (((len)+sizeof(long)-1) & ~(sizeof(long)-1))
 if CMSG_ALIGN is not defined on this platform, a workaround
 
#define CMSG_LEN(len)   (CMSG_ALIGN(sizeof(struct cmsghdr))+(len))
 if CMSG_LEN is not defined on this platform, a workaround
 
#define CMSG_SPACE(l)   (CMSG_ALIGN(l)+CMSG_ALIGN(sizeof(struct cmsghdr)))
 if CMSG_SPACE is not defined on this platform, a workaround
 
#define TCP_QUERY_TIMEOUT   120
 The TCP reading or writing query timeout in seconds.
 
#define NUM_UDP_PER_SELECT   100
 number of UDP reads to perform per read indication from select
 

Functions

static struct comm_pointcomm_point_create_tcp_handler (struct comm_base *base, struct comm_point *parent, size_t bufsize, comm_point_callback_t *callback, void *callback_arg)
 create a tcp handler with a parent
 
static void comm_base_now (struct comm_base *b)
 fillup the time values in the event base
 
struct comm_basecomm_base_create (int sigs)
 Create a new comm base. More...
 
struct comm_basecomm_base_create_event (struct event_base *base)
 Create comm base that uses the given event_base (underlying event mechanism pointer). More...
 
void comm_base_delete (struct comm_base *b)
 Destroy a comm base. More...
 
void comm_base_delete_no_base (struct comm_base *b)
 Delete comm base structure but not the underlying lib event base. More...
 
void comm_base_timept (struct comm_base *b, time_t **tt, struct timeval **tv)
 Obtain two pointers. More...
 
void comm_base_dispatch (struct comm_base *b)
 Dispatch the comm base events. More...
 
void comm_base_exit (struct comm_base *b)
 Exit from dispatch loop. More...
 
void comm_base_set_slow_accept_handlers (struct comm_base *b, void(*stop_acc)(void *), void(*start_acc)(void *), void *arg)
 Set the slow_accept mode handlers. More...
 
struct event_base * comm_base_internal (struct comm_base *b)
 Access internal data structure (for util/tube.c on windows) More...
 
static int udp_send_errno_needs_log (struct sockaddr *addr, socklen_t addrlen)
 see if errno for udp has to be logged or not uses globals
 
int tcp_connect_errno_needs_log (struct sockaddr *addr, socklen_t addrlen)
 see if errno for tcp connect has to be logged or not. More...
 
int comm_point_send_udp_msg (struct comm_point *c, sldns_buffer *packet, struct sockaddr *addr, socklen_t addrlen)
 Send an udp message over a commpoint. More...
 
static int comm_point_send_udp_msg_if (struct comm_point *c, sldns_buffer *packet, struct sockaddr *addr, socklen_t addrlen, struct comm_reply *r)
 send a UDP reply over specified interface
 
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. More...
 
void comm_point_udp_callback (int fd, short event, void *arg)
 This routine is published for checks and tests, and is only used internally. More...
 
static void setup_tcp_handler (struct comm_point *c, int fd)
 Use a new tcp handler for new query fd, set to read query.
 
void comm_base_handle_slow_accept (int ATTR_UNUSED(fd), short ATTR_UNUSED(event), void *arg)
 
int comm_point_perform_accept (struct comm_point *c, struct sockaddr_storage *addr, socklen_t *addrlen)
 perform accept(2) with error checking. More...
 
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. More...
 
static void reclaim_tcp_handler (struct comm_point *c)
 Make tcp handler free for next assignment.
 
static void tcp_callback_writer (struct comm_point *c)
 do the callback when writing is done
 
static void tcp_callback_reader (struct comm_point *c)
 do the callback when reading is done
 
static int ssl_handle_read (struct comm_point *c)
 continue ssl handshake More...
 
static int ssl_handle_write (struct comm_point *c)
 ssl write callback on TCP
 
static int ssl_handle_it (struct comm_point *c)
 handle ssl tcp connection with dns contents
 
static int comm_point_tcp_handle_read (int fd, struct comm_point *c, int short_ok)
 Handle tcp reading callback. More...
 
static int comm_point_tcp_handle_write (int fd, struct comm_point *c)
 Handle tcp writing callback. More...
 
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. More...
 
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. More...
 
void comm_point_raw_handle_callback (int ATTR_UNUSED(fd), short event, void *arg)
 
struct comm_pointcomm_point_create_udp (struct comm_base *base, int fd, sldns_buffer *buffer, comm_point_callback_t *callback, void *callback_arg)
 Create an UDP comm point. More...
 
struct comm_pointcomm_point_create_udp_ancil (struct comm_base *base, int fd, sldns_buffer *buffer, comm_point_callback_t *callback, void *callback_arg)
 Create an UDP with ancillary data comm point. More...
 
struct comm_pointcomm_point_create_tcp (struct comm_base *base, int fd, int num, size_t bufsize, comm_point_callback_t *callback, void *callback_arg)
 Create a TCP listener comm point. More...
 
struct comm_pointcomm_point_create_tcp_out (struct comm_base *base, size_t bufsize, comm_point_callback_t *callback, void *callback_arg)
 Create an outgoing TCP commpoint. More...
 
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. More...
 
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. More...
 
void comm_point_close (struct comm_point *c)
 Close a comm point fd. More...
 
void comm_point_delete (struct comm_point *c)
 Close and deallocate (free) the comm point. More...
 
void comm_point_send_reply (struct comm_reply *repinfo)
 Send reply. More...
 
void comm_point_drop_reply (struct comm_reply *repinfo)
 Drop reply. More...
 
void comm_point_stop_listening (struct comm_point *c)
 Stop listening for input on the commpoint. More...
 
void comm_point_start_listening (struct comm_point *c, int newfd, int sec)
 Start listening again for input on the comm point. More...
 
void comm_point_listen_for_rw (struct comm_point *c, int rd, int wr)
 Stop listening and start listening again for reading or writing. More...
 
size_t comm_point_get_mem (struct comm_point *c)
 Get size of memory used by comm point. More...
 
struct comm_timercomm_timer_create (struct comm_base *base, void(*cb)(void *), void *cb_arg)
 create timer. More...
 
void comm_timer_disable (struct comm_timer *timer)
 disable timer. More...
 
void comm_timer_set (struct comm_timer *timer, struct timeval *tv)
 reset timevalue for timer. More...
 
void comm_timer_delete (struct comm_timer *timer)
 delete timer. More...
 
void comm_timer_callback (int ATTR_UNUSED(fd), short event, void *arg)
 
int comm_timer_is_set (struct comm_timer *timer)
 see if timeout has been set to a value. More...
 
size_t comm_timer_get_mem (struct comm_timer *timer)
 Get size of memory used by comm timer. More...
 
struct comm_signalcomm_signal_create (struct comm_base *base, void(*callback)(int, void *), void *cb_arg)
 Create a signal handler. More...
 
void comm_signal_callback (int sig, short event, void *arg)
 This routine is published for checks and tests, and is only used internally. More...
 
int comm_signal_bind (struct comm_signal *comsig, int sig)
 Bind signal struct to catch a signal. More...
 
void comm_signal_delete (struct comm_signal *comsig)
 Delete the signal communication point. More...
 

Detailed Description

This file contains event notification functions.

Function Documentation

struct comm_base* comm_base_create ( int  sigs)

Create a new comm base.

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

References internal_base::base, comm_base_now(), comm_base::eb, internal_base::now, internal_base::secs, VERB_ALGO, and verbose().

struct comm_base* comm_base_create_event ( struct event_base *  base)

Create comm base that uses the given event_base (underlying event mechanism pointer).

Parameters
baseunderlying lib event base.
Returns
: the new comm base. NULL on error.

References internal_base::base, comm_base_now(), and comm_base::eb.

Referenced by libworker_setup().

void comm_base_delete ( struct comm_base b)
void comm_base_delete_no_base ( struct comm_base b)

Delete comm base structure but not the underlying lib event base.

All comm points must have been deleted.

Parameters
bthe base to delete.

References internal_base::base, comm_base::eb, log_err(), internal_base::slow_accept, and internal_base::slow_accept_enabled.

Referenced by libworker_delete_event().

void comm_base_timept ( struct comm_base b,
time_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
bthe communication base that will update the time values.
ttpointer to time in seconds is returned.
tvpointer to time in microseconds is returned.

References comm_base::eb, internal_base::now, replay_runtime::now_secs, replay_runtime::now_tv, and internal_base::secs.

void comm_base_dispatch ( struct comm_base b)

Dispatch the comm base events.

Parameters
bthe communication to perform.

References internal_base::base, comm_base::eb, fatal_exit(), run_scenario(), replay_runtime::sig_cb, and replay_runtime::sig_cb_arg.

void comm_base_exit ( struct comm_base b)

Exit from dispatch loop.

Parameters
bthe communication base that is in dispatch().

References internal_base::base, comm_base::eb, replay_runtime::exit_cleanly, fatal_exit(), and log_err().

void comm_base_set_slow_accept_handlers ( struct comm_base b,
void(*)(void *)  stop_accept,
void(*)(void *)  start_accept,
void *  arg 
)

Set the slow_accept mode handlers.

You can not provide these if you do not perform accept() calls.

Parameters
bcomm base
stop_acceptfunction that stops listening to accept fds.
start_acceptfunction that resumes listening to accept fds.
argcallback arg to pass to the functions.

References comm_base::cb_arg, comm_base::start_accept, and comm_base::stop_accept.

struct event_base* comm_base_internal ( struct comm_base b)

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

Parameters
bcomm base
Returns
event_base. Could be libevent, or internal event handler.

References internal_base::base, and comm_base::eb.

int tcp_connect_errno_needs_log ( struct sockaddr *  addr,
socklen_t  addrlen 
)

see if errno for tcp connect has to be logged or not.

This uses errno

References udp_send_errno_needs_log().

Referenced by outnet_tcp_take_into_use().

int comm_point_send_udp_msg ( struct comm_point c,
struct sldns_buffer packet,
struct sockaddr *  addr,
socklen_t  addrlen 
)

Send an udp message over a commpoint.

Parameters
ccommpoint to send it from.
packetwhat to send.
addrwhere to send it to.
addrlenlength of addr.
Returns
: false on a failure.

References comm_point::fd, log_addr(), log_assert, log_err(), sldns_buffer_begin(), sldns_buffer_remaining(), udp_send_errno_needs_log(), VERB_OPS, and verbose().

Referenced by comm_point_send_reply(), comm_point_udp_callback(), and randomize_and_send_udp().

void comm_point_udp_ancil_callback ( int  fd,
short  event,
void *  arg 
)
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
fdfile descriptor.
eventevent bits from libevent: EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT.
argthe comm_point structure.

References comm_reply::addr, comm_reply::addrlen, internal_event::base, comm_point::buffer, comm_reply::c, comm_point::callback, comm_point::cb_arg, comm_base_now(), comm_point_send_udp_msg(), comm_point::comm_udp, comm_point::ev, comm_point::fd, fptr_ok, fptr_whitelist_comm_point(), log_assert, log_err(), NETEVENT_NOERROR, NUM_UDP_PER_SELECT, sldns_buffer_begin(), sldns_buffer_clear(), sldns_buffer_flip(), sldns_buffer_remaining(), sldns_buffer_skip(), comm_reply::srctype, and comm_point::type.

Referenced by comm_point_create_udp().

int comm_point_perform_accept ( struct comm_point c,
struct sockaddr_storage *  addr,
socklen_t *  addrlen 
)

perform accept(2) with error checking.

Parameters
ccommpoint with accept fd.
addrremote end returned here.
addrlenlength of remote end returned here.
Returns
new fd, or -1 on error. if -1, error message has been printed if necessary, simply drop out of the reading handler.

References internal_event::base, internal_base::base, comm_base::cb_arg, comm_base_handle_slow_accept(), comm_base::eb, internal_event::ev, comm_point::ev, comm_point::fd, fd_set_nonblock(), fptr_ok, fptr_whitelist_stop_accept(), log_err_addr(), NETEVENT_SLOW_ACCEPT_TIME, internal_base::slow_accept, internal_base::slow_accept_enabled, comm_base::stop_accept, VERB_ALGO, and verbose().

Referenced by comm_point_tcp_accept_callback().

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
fdfile descriptor.
eventevent bits from libevent: EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT.
argthe comm_point structure.

References comm_reply::addr, internal_event::base, comm_base_now(), comm_point_close(), comm_point_perform_accept(), comm_point_stop_listening(), comm_point::comm_ssl_shake_read, comm_point::comm_tcp_accept, comm_point::ev, incoming_ssl_fd(), log_assert, log_info(), log_warn(), comm_point::repinfo, setup_tcp_handler(), comm_point::ssl, comm_point::tcp_free, and comm_point::type.

Referenced by comm_point_create_tcp().

static int ssl_handle_read ( struct comm_point c)
static
static int comm_point_tcp_handle_read ( int  fd,
struct comm_point c,
int  short_ok 
)
static
static int comm_point_tcp_handle_write ( int  fd,
struct comm_point c 
)
static
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
fdfile descriptor.
eventevent bits from libevent: EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT.
argthe comm_point structure.

References internal_event::base, comm_point::callback, comm_point::cb_arg, comm_base_now(), comm_point_tcp_handle_read(), comm_point_tcp_handle_write(), comm_point::comm_tcp, comm_point::ev, fptr_ok, fptr_whitelist_comm_point(), log_assert, log_err(), NETEVENT_CLOSED, NETEVENT_TIMEOUT, reclaim_tcp_handler(), comm_point::tcp_do_close, comm_point::type, VERB_QUERY, and verbose().

Referenced by comm_point_create_tcp_handler(), and comm_point_create_tcp_out().

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
fdfile descriptor.
eventevent bits from libevent: EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT.
argthe comm_point structure.

References internal_event::base, comm_point::callback, comm_point::cb_arg, comm_base_now(), comm_point::comm_local, comm_point_tcp_handle_read(), comm_point::ev, fptr_ok, fptr_whitelist_comm_point(), log_assert, log_err(), NETEVENT_CLOSED, and comm_point::type.

Referenced by comm_point_create_local().

struct comm_point* comm_point_create_udp ( struct comm_base base,
int  fd,
struct sldns_buffer buffer,
comm_point_callback_t callback,
void *  callback_arg 
)

Create an UDP comm point.

Calls malloc. setups the structure with the parameters you provide.

Parameters
basein which base to alloc the commpoint.
fd: file descriptor of open UDP socket.
buffershared buffer by UDP sockets from this thread.
callbackcallback function pointer.
callback_argwill be passed to your callback function.
Returns
: returns the allocated communication point. NULL on error. Sets timeout to NULL. Turns off TCP options.

References internal_event::base, internal_base::base, comm_point::buffer, comm_point::callback, comm_point::cb_arg, comm_point_delete(), comm_point_udp_callback(), comm_point::do_not_close, comm_base::eb, internal_event::ev, comm_point::ev, comm_point::fd, comm_point::inuse, log_err(), comm_point::max_tcp_count, comm_point::tcp_byte_count, comm_point::tcp_check_nb_connect, comm_point::tcp_do_close, comm_point::tcp_do_toggle_rw, comm_point::tcp_free, comm_point::tcp_handlers, comm_point::tcp_is_reading, comm_point::tcp_parent, comm_point::timeout, and comm_point::type.

Referenced by listen_create(), and outside_network_create().

struct comm_point* comm_point_create_udp_ancil ( struct comm_base base,
int  fd,
struct sldns_buffer buffer,
comm_point_callback_t callback,
void *  callback_arg 
)

Create an UDP with ancillary data comm point.

Calls malloc. Uses recvmsg instead of recv to get udp message. setups the structure with the parameters you provide.

Parameters
basein which base to alloc the commpoint.
fd: file descriptor of open UDP socket.
buffershared buffer by UDP sockets from this thread.
callbackcallback function pointer.
callback_argwill be passed to your callback function.
Returns
: returns the allocated communication point. NULL on error. Sets timeout to NULL. Turns off TCP options.

References internal_event::base, internal_base::base, comm_point::buffer, comm_point::callback, comm_point::cb_arg, comm_point_delete(), comm_point_udp_ancil_callback(), comm_point::do_not_close, comm_base::eb, internal_event::ev, comm_point::ev, comm_point::fd, comm_point::inuse, log_err(), comm_point::max_tcp_count, comm_point::tcp_byte_count, comm_point::tcp_check_nb_connect, comm_point::tcp_do_close, comm_point::tcp_do_toggle_rw, comm_point::tcp_free, comm_point::tcp_handlers, comm_point::tcp_is_reading, comm_point::tcp_parent, comm_point::timeout, and comm_point::type.

Referenced by listen_create().

struct comm_point* comm_point_create_tcp ( struct comm_base base,
int  fd,
int  num,
size_t  bufsize,
comm_point_callback_t callback,
void *  callback_arg 
)

Create a TCP listener comm point.

Calls malloc. Setups the structure with the parameters you provide. Also Creates TCP Handlers, pre allocated for you. Uses the parameters you provide.

Parameters
basein which base to alloc the commpoint.
fdfile descriptor of open TCP socket set to listen nonblocking.
numbecomes max_tcp_count, the routine allocates that many tcp handler commpoints.
bufsizesize of buffer to create for handlers.
callbackcallback function pointer for TCP handlers.
callback_argwill be passed to your callback function.
Returns
: returns the TCP listener commpoint. You can find the TCP handlers in the array inside the listener commpoint. returns NULL on error. Inits timeout to NULL. All handlers are on the free list.

References internal_event::base, internal_base::base, comm_point::buffer, comm_point::callback, comm_point::cb_arg, comm_point_create_tcp_handler(), comm_point_delete(), comm_point_tcp_accept_callback(), comm_point::comm_tcp_accept, comm_point::do_not_close, comm_base::eb, internal_event::ev, comm_point::ev, comm_point::fd, log_err(), comm_point::max_tcp_count, comm_point::tcp_byte_count, comm_point::tcp_check_nb_connect, comm_point::tcp_do_close, comm_point::tcp_do_toggle_rw, comm_point::tcp_free, comm_point::tcp_handlers, comm_point::tcp_is_reading, comm_point::tcp_parent, comm_point::timeout, and comm_point::type.

Referenced by listen_create().

struct comm_point* comm_point_create_tcp_out ( struct comm_base base,
size_t  bufsize,
comm_point_callback_t callback,
void *  callback_arg 
)

Create an outgoing TCP commpoint.

No file descriptor is opened, left at -1.

Parameters
basein which base to alloc the commpoint.
bufsizesize of buffer to create for handlers.
callbackcallback function pointer for the handler.
callback_argwill be passed to your callback function.
Returns
: the commpoint or NULL on error.

References internal_event::base, internal_base::base, comm_point::buffer, comm_reply::c, comm_point::callback, comm_point::cb_arg, comm_point_tcp_handle_callback(), comm_point::do_not_close, comm_base::eb, internal_event::ev, comm_point::ev, comm_point::fd, log_err(), comm_point::max_tcp_count, comm_point::repinfo, sldns_buffer_free(), sldns_buffer_new(), comm_point::tcp_byte_count, comm_point::tcp_check_nb_connect, comm_point::tcp_do_close, comm_point::tcp_do_toggle_rw, comm_point::tcp_free, comm_point::tcp_handlers, comm_point::tcp_is_reading, comm_point::tcp_parent, comm_point::timeout, and comm_point::type.

Referenced by create_pending_tcp().

struct comm_point* comm_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.

Parameters
basein which base to alloc the commpoint.
fdfile descriptor of open AF_UNIX socket set to listen nonblocking.
bufsizesize of buffer to create for handlers.
callbackcallback function pointer for the handler.
callback_argwill be passed to your callback function.
Returns
: the commpoint or NULL on error.

References internal_event::base, internal_base::base, comm_point::buffer, comm_point::callback, comm_point::cb_arg, comm_point_local_handle_callback(), comm_point::do_not_close, comm_base::eb, internal_event::ev, comm_point::ev, comm_point::fd, log_err(), comm_point::max_tcp_count, sldns_buffer_new(), comm_point::tcp_byte_count, comm_point::tcp_check_nb_connect, comm_point::tcp_do_close, comm_point::tcp_do_toggle_rw, comm_point::tcp_free, comm_point::tcp_handlers, comm_point::tcp_is_reading, comm_point::tcp_parent, comm_point::timeout, and comm_point::type.

struct comm_point* comm_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.

Parameters
basein which base to alloc the commpoint.
fdfile descriptor.
writingtrue if you want to listen to writes, false for reads.
callbackcallback function pointer for the handler.
callback_argwill be passed to your callback function.
Returns
: the commpoint or NULL on error.

References internal_event::base, internal_base::base, comm_point::buffer, comm_point::callback, comm_point::cb_arg, comm_point_raw_handle_callback(), comm_point::do_not_close, comm_base::eb, internal_event::ev, comm_point::ev, comm_point::fd, log_err(), comm_point::max_tcp_count, comm_point::tcp_byte_count, comm_point::tcp_check_nb_connect, comm_point::tcp_do_close, comm_point::tcp_do_toggle_rw, comm_point::tcp_free, comm_point::tcp_handlers, comm_point::tcp_is_reading, comm_point::tcp_parent, comm_point::timeout, and comm_point::type.

void comm_point_close ( struct comm_point c)
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
ccomm point to delete.

References comm_point::buffer, comm_point_close(), comm_point::ev, comm_point::max_tcp_count, sldns_buffer_free(), comm_point::ssl, comm_point::tcp_handlers, comm_point::timeout, and comm_point::type.

Referenced by comm_point_create_tcp(), comm_point_create_udp(), and comm_point_create_udp_ancil().

void comm_point_send_reply ( struct comm_reply repinfo)
void comm_point_drop_reply ( struct comm_reply repinfo)

Drop reply.

Cleans up.

Parameters
repinfoThe reply info copied from a commpoint callback call.

References comm_point::buffer, comm_reply::c, log_assert, log_info(), reclaim_tcp_handler(), sldns_buffer_free(), and comm_point::type.

void comm_point_stop_listening ( struct comm_point c)

Stop listening for input on the commpoint.

No callbacks will happen.

Parameters
ccommpoint to disable. The fd is not closed.

References internal_event::ev, comm_point::ev, comm_point::fd, log_err(), VERB_ALGO, and verbose().

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

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

Start listening again for input on the comm point.

Parameters
ccommpoint to enable again.
newfdnew fd, or -1 to leave fd be.
sectimeout in seconds, or -1 for no (change to the) timeout.

References internal_event::ev, comm_point::ev, comm_point::fd, log_err(), comm_point::tcp_free, comm_point::tcp_is_reading, comm_point::timeout, comm_point::type, VERB_ALGO, and verbose().

Referenced by comm_point_send_reply(), reclaim_tcp_handler(), setup_tcp_handler(), tcp_callback_reader(), and tcp_callback_writer().

void comm_point_listen_for_rw ( struct comm_point c,
int  rd,
int  wr 
)

Stop listening and start listening again for reading or writing.

Parameters
ccommpoint
rdif true, listens for reading.
wrif true, listens for writing.

References internal_event::ev, comm_point::ev, comm_point::fd, log_err(), comm_point::timeout, VERB_ALGO, and verbose().

Referenced by ssl_handle_read(), and ssl_handle_write().

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
ccommpoint.
Returns
size in bytes.

References comm_point::buffer, comm_point_get_mem(), comm_point::ev, comm_point::max_tcp_count, sldns_buffer_capacity(), comm_point::tcp_handlers, comm_point::timeout, and comm_point::type.

Referenced by comm_point_get_mem().

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

create timer.

Not active upon creation.

Parameters
baseevent handling base.
cbcallback function: void myfunc(void* myarg);
cb_arguser callback argument.
Returns
: the new timer or NULL on error.

References internal_base::base, internal_timer::base, comm_timer::callback, fake_timer::cb, comm_timer::cb_arg, fake_timer::cb_arg, comm_timer_callback(), comm_base::eb, internal_timer::ev, comm_timer::ev_timer, fptr_ok, fptr_whitelist_comm_timer(), log_err(), fake_timer::next, fake_timer::runtime, and replay_runtime::timer_list.

void comm_timer_disable ( struct comm_timer timer)

disable timer.

Stops callbacks from happening.

Parameters
timerto disable.

References internal_timer::enabled, fake_timer::enabled, internal_timer::ev, comm_timer::ev_timer, and log_info().

Referenced by comm_timer_delete(), and comm_timer_set().

void comm_timer_set ( struct comm_timer timer,
struct timeval *  tv 
)
void comm_timer_delete ( struct comm_timer timer)
int comm_timer_is_set ( struct comm_timer timer)

see if timeout has been set to a value.

Parameters
timerthe timer to examine.
Returns
: false if disabled or not set.

References internal_timer::enabled, and comm_timer::ev_timer.

size_t comm_timer_get_mem ( struct comm_timer timer)

Get size of memory used by comm timer.

Parameters
timerthe timer to examine.
Returns
size in bytes.

Referenced by serviced_get_mem(), waiting_tcp_get_mem(), and waiting_udp_get_mem().

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

Create a signal handler.

Call signal_bind() later to bind to a signal.

Parameters
basecommunication base to use.
callbackcalled when signal is caught.
cb_arguser argument to callback
Returns
: the signal struct or NULL on error.

References comm_signal::base, comm_signal::callback, replay_runtime::cb_arg, comm_signal::cb_arg, comm_signal::ev_signal, log_err(), replay_runtime::sig_cb, and replay_runtime::sig_cb_arg.

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
fdfile descriptor (used for the signal number).
eventevent bits from libevent: EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT.
argthe internal commsignal structure.

References comm_signal::base, comm_signal::callback, comm_signal::cb_arg, comm_base_now(), fptr_ok, and fptr_whitelist_comm_signal().

Referenced by comm_signal_bind().

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
comsigthe communication point, with callback information.
sigsignal number.
Returns
: true on success. false on error.

References internal_base::base, comm_signal::base, comm_signal_callback(), comm_base::eb, internal_signal::ev, comm_signal::ev_signal, log_assert, log_err(), and internal_signal::next.

void comm_signal_delete ( struct comm_signal comsig)

Delete the signal communication point.

Parameters
comsigto delete.

References internal_signal::ev, comm_signal::ev_signal, and internal_signal::next.