unbound 0.1
unbound-dnstap-socket.c File Reference

This program listens on a DNSTAP socket for logged messages. More...

#include "config.h"
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
#include <ctype.h>
#include <openssl/ssl.h>
#include <openssl/rand.h>
#include <openssl/err.h>
#include "dnstap/dtstream.h"
#include "dnstap/dnstap_fstrm.h"
#include "util/log.h"
#include "util/ub_event.h"
#include "util/net_help.h"
#include "services/listen_dnsport.h"
#include "sldns/sbuffer.h"
#include "sldns/wire2str.h"
#include "sldns/pkthdr.h"
#include "util/config_file.h"
#include "util/data/packed_rrset.h"
#include "daemon/worker.h"
#include "daemon/remote.h"
#include "util/fptr_wlist.h"
#include "libunbound/context.h"

Data Structures

struct  main_tap_data
 main tap callback data More...
struct  tap_data_list
struct  tap_data
 tap callback variables More...
struct  tap_socket_list
 list of sockets More...
struct  tap_socket
 tap socket More...
struct  order_id
 keep track of lock id in lock-verify application More...

Macros

#define LISTEN_BACKLOG   16
 listen backlog on TCP connections for dnstap logs
#define unit_tap_datas_max   5

Functions

static void usage (char *argv[])
 usage information for streamtcp
static void tap_data_list_try_to_free_tail (struct tap_data_list *list)
 try to delete tail entries from the list if all of them have no data
static void tap_data_free (struct tap_data *data, int free_tail)
 delete the tap structure
static int tap_data_list_insert (struct tap_data_list **liststart, struct tap_data *d)
 insert tap_data in the tap_data_list
static void tap_data_list_delete (struct tap_data_list *list)
 delete the tap_data_list and free any remaining tap_data
static void tap_socket_delev (struct tap_socket *s)
 del the tap event
static void tap_socket_close (struct tap_socket *s)
 close the tap socket
static void tap_socket_delete (struct tap_socket *s)
 delete tap socket
static struct tap_socket * tap_socket_new_local (char *socketpath, void(*ev_cb)(int, short, void *), void *data)
 create new socket (unconnected, not base-added), or NULL malloc fail
static struct tap_socket * tap_socket_new_tcpaccept (char *ip, void(*ev_cb)(int, short, void *), void *data)
 create new socket (unconnected, not base-added), or NULL malloc fail
static struct tap_socket * tap_socket_new_tlsaccept (char *ip, void(*ev_cb)(int, short, void *), void *data, char *server_key, char *server_cert, char *verifypem, char *tls_protocols)
 create new socket (unconnected, not base-added), or NULL malloc fail
static int make_tcp_accept (char *ip)
 setup tcp accept socket on IP string
static int tap_socket_setup (struct tap_socket *s, struct ub_event_base *base)
 setup socket on event base
static int tap_socket_list_insert (struct tap_socket_list **liststart, struct tap_socket *s)
 add tap socket to list
static void tap_socket_list_delete (struct tap_socket_list *list)
 delete the list
static int tap_socket_list_addevs (struct tap_socket_list *list, struct ub_event_base *base)
 setup accept events
static ssize_t receive_bytes (struct tap_data *data, int fd, void *buf, size_t len)
 receive bytes from fd, prints errors if bad, returns 0: closed/error, -1: continue, >0 number of bytes
static ssize_t tap_receive (struct tap_data *data, void *buf, size_t len)
 receive bytes on the tap connection, prints errors if bad, returns 0: closed/error, -1: continue, >0 number of bytes
static int reply_with_accept (struct tap_data *data)
 reply with ACCEPT control frame to bidirectional client, returns 0 on error
static int reply_with_finish (struct tap_data *data)
 reply with FINISH control frame to bidirectional client, returns 0 on error
void dtio_tap_callback (int ATTR_UNUSED(fd), short ATTR_UNUSED(bits), void *arg)
 callback for dnstap listener
void dtio_mainfdcallback (int fd, short ATTR_UNUSED(bits), void *arg)
 callback for main listening file descriptor
static void setup_local_list (struct main_tap_data *maindata, struct config_strlist_head *local_list)
 setup local accept sockets
static void setup_tcp_list (struct main_tap_data *maindata, struct config_strlist_head *tcp_list)
 setup tcp accept sockets
static void setup_tls_list (struct main_tap_data *maindata, struct config_strlist_head *tls_list, char *server_key, char *server_cert, char *verifypem, char *tls_protocols)
 setup tls accept sockets
static RETSIGTYPE main_sigh (int sig)
 signal handler for user quit
static void setup_and_run (struct config_strlist_head *local_list, struct config_strlist_head *tcp_list, struct config_strlist_head *tls_list, char *server_key, char *server_cert, char *verifypem, char *tls_protocols)
 setup and run the server to listen to DNSTAP messages
static int internal_unittest ()
int main (int argc, char **argv)
 main program for streamtcp
void worker_handle_control_cmd (struct tube *ATTR_UNUSED(tube), uint8_t *ATTR_UNUSED(buffer), size_t ATTR_UNUSED(len), int ATTR_UNUSED(error), void *ATTR_UNUSED(arg))
int worker_handle_request (struct comm_point *ATTR_UNUSED(c), void *ATTR_UNUSED(arg), int ATTR_UNUSED(error), struct comm_reply *ATTR_UNUSED(repinfo))
int worker_handle_service_reply (struct comm_point *ATTR_UNUSED(c), void *ATTR_UNUSED(arg), int ATTR_UNUSED(error), struct comm_reply *ATTR_UNUSED(reply_info))
int remote_accept_callback (struct comm_point *ATTR_UNUSED(c), void *ATTR_UNUSED(arg), int ATTR_UNUSED(error), struct comm_reply *ATTR_UNUSED(repinfo))
int remote_control_callback (struct comm_point *ATTR_UNUSED(c), void *ATTR_UNUSED(arg), int ATTR_UNUSED(error), struct comm_reply *ATTR_UNUSED(repinfo))
void worker_sighandler (int ATTR_UNUSED(sig), void *ATTR_UNUSED(arg))
struct outbound_entry * worker_send_query (struct query_info *ATTR_UNUSED(qinfo), uint16_t ATTR_UNUSED(flags), int ATTR_UNUSED(dnssec), int ATTR_UNUSED(want_dnssec), int ATTR_UNUSED(nocaps), int ATTR_UNUSED(check_ratelimit), struct sockaddr_storage *ATTR_UNUSED(addr), socklen_t ATTR_UNUSED(addrlen), uint8_t *ATTR_UNUSED(zone), size_t ATTR_UNUSED(zonelen), int ATTR_UNUSED(tcp_upstream), int ATTR_UNUSED(ssl_upstream), char *ATTR_UNUSED(tls_auth_name), struct module_qstate *ATTR_UNUSED(q), int *ATTR_UNUSED(was_ratelimited), int *ATTR_UNUSED(ratelimit_incremented))
void worker_alloc_cleanup (void *ATTR_UNUSED(arg))
struct outbound_entry * libworker_send_query (struct query_info *ATTR_UNUSED(qinfo), uint16_t ATTR_UNUSED(flags), int ATTR_UNUSED(dnssec), int ATTR_UNUSED(want_dnssec), int ATTR_UNUSED(nocaps), int ATTR_UNUSED(check_ratelimit), struct sockaddr_storage *ATTR_UNUSED(addr), socklen_t ATTR_UNUSED(addrlen), uint8_t *ATTR_UNUSED(zone), size_t ATTR_UNUSED(zonelen), int ATTR_UNUSED(tcp_upstream), int ATTR_UNUSED(ssl_upstream), char *ATTR_UNUSED(tls_auth_name), struct module_qstate *ATTR_UNUSED(q), int *ATTR_UNUSED(was_ratelimited), int *ATTR_UNUSED(ratelimit_incremented))
int libworker_handle_service_reply (struct comm_point *ATTR_UNUSED(c), void *ATTR_UNUSED(arg), int ATTR_UNUSED(error), struct comm_reply *ATTR_UNUSED(reply_info))
void libworker_handle_control_cmd (struct tube *ATTR_UNUSED(tube), uint8_t *ATTR_UNUSED(buffer), size_t ATTR_UNUSED(len), int ATTR_UNUSED(error), void *ATTR_UNUSED(arg))
void libworker_fg_done_cb (void *ATTR_UNUSED(arg), int ATTR_UNUSED(rcode), struct sldns_buffer *ATTR_UNUSED(buf), enum sec_status ATTR_UNUSED(s), char *ATTR_UNUSED(why_bogus), int ATTR_UNUSED(was_ratelimited))
void libworker_bg_done_cb (void *ATTR_UNUSED(arg), int ATTR_UNUSED(rcode), struct sldns_buffer *ATTR_UNUSED(buf), enum sec_status ATTR_UNUSED(s), char *ATTR_UNUSED(why_bogus), int ATTR_UNUSED(was_ratelimited))
void libworker_event_done_cb (void *ATTR_UNUSED(arg), int ATTR_UNUSED(rcode), struct sldns_buffer *ATTR_UNUSED(buf), enum sec_status ATTR_UNUSED(s), char *ATTR_UNUSED(why_bogus), int ATTR_UNUSED(was_ratelimited))
void libworker_alloc_cleanup (void *ATTR_UNUSED(arg))
int context_query_cmp (const void *ATTR_UNUSED(a), const void *ATTR_UNUSED(b))
void worker_stat_timer_cb (void *ATTR_UNUSED(arg))
void worker_probe_timer_cb (void *ATTR_UNUSED(arg))
void worker_start_accept (void *ATTR_UNUSED(arg))
void worker_stop_accept (void *ATTR_UNUSED(arg))
int order_lock_cmp (const void *e1, const void *e2)
 Due to module breakage by fptr wlist, these test app declarations are presented here.
int codeline_cmp (const void *a, const void *b)
 compare two codeline structs for rbtree from memstats test app
int replay_var_compare (const void *ATTR_UNUSED(a), const void *ATTR_UNUSED(b))
void remote_get_opt_ssl (char *ATTR_UNUSED(str), void *ATTR_UNUSED(arg))
void fast_reload_service_cb (int ATTR_UNUSED(fd), short ATTR_UNUSED(ev), void *ATTR_UNUSED(arg))
int fast_reload_client_callback (struct comm_point *ATTR_UNUSED(c), void *ATTR_UNUSED(arg), int ATTR_UNUSED(error), struct comm_reply *ATTR_UNUSED(repinfo))

Variables

static int longformat = 0
 long format option, for multiline printout per message
static struct ub_event_base * sig_base = NULL
 signal variable
int sig_quit = 0
 do we have to quit
int optind
 getopt global, in case header files fail to declare it.
char * optarg
 getopt global, in case header files fail to declare it.

Detailed Description

This program listens on a DNSTAP socket for logged messages.

Macro Definition Documentation

◆ LISTEN_BACKLOG

#define LISTEN_BACKLOG   16

listen backlog on TCP connections for dnstap logs

Referenced by make_tcp_accept().

Function Documentation

◆ usage()

void usage ( char * argv[])
static

usage information for streamtcp

References usage().

◆ tap_data_list_try_to_free_tail()

void tap_data_list_try_to_free_tail ( struct tap_data_list * list)
static

try to delete tail entries from the list if all of them have no data

References tap_data_list::d, log_assert, tap_data_list::next, and tap_data_list_try_to_free_tail().

Referenced by tap_data_free(), and tap_data_list_try_to_free_tail().

◆ tap_data_free()

◆ tap_data_list_insert()

int tap_data_list_insert ( struct tap_data_list ** liststart,
struct tap_data * d )
static

◆ tap_data_list_delete()

void tap_data_list_delete ( struct tap_data_list * list)
static

◆ tap_socket_delev()

void tap_socket_delev ( struct tap_socket * s)
static

◆ tap_socket_close()

void tap_socket_close ( struct tap_socket * s)
static

close the tap socket

References tap_socket::fd, sock_close(), and tap_socket_close().

Referenced by tap_socket_close(), and tap_socket_list_delete().

◆ tap_socket_delete()

◆ tap_socket_new_local()

struct tap_socket * tap_socket_new_local ( char * socketpath,
void(* ev_cb )(int, short, void *),
void * data )
static

create new socket (unconnected, not base-added), or NULL malloc fail

References tap_socket::data, tap_socket::ev_cb, tap_socket::fd, log_err(), tap_socket::socketpath, and tap_socket_new_local().

Referenced by setup_local_list(), and tap_socket_new_local().

◆ tap_socket_new_tcpaccept()

struct tap_socket * tap_socket_new_tcpaccept ( char * ip,
void(* ev_cb )(int, short, void *),
void * data )
static

create new socket (unconnected, not base-added), or NULL malloc fail

References tap_socket::data, tap_socket::ev_cb, tap_socket::fd, tap_socket::ip, log_err(), and tap_socket_new_tcpaccept().

Referenced by setup_tcp_list(), and tap_socket_new_tcpaccept().

◆ tap_socket_new_tlsaccept()

struct tap_socket * tap_socket_new_tlsaccept ( char * ip,
void(* ev_cb )(int, short, void *),
void * data,
char * server_key,
char * server_cert,
char * verifypem,
char * tls_protocols )
static

create new socket (unconnected, not base-added), or NULL malloc fail

References tap_socket::data, tap_socket::ev_cb, tap_socket::fd, tap_socket::ip, listen_sslctx_create(), log_err(), tap_socket::sslctx, and tap_socket_new_tlsaccept().

Referenced by setup_tls_list(), and tap_socket_new_tlsaccept().

◆ make_tcp_accept()

int make_tcp_accept ( char * ip)
static

◆ tap_socket_setup()

◆ tap_socket_list_insert()

int tap_socket_list_insert ( struct tap_socket_list ** liststart,
struct tap_socket * s )
static

◆ tap_socket_list_delete()

void tap_socket_list_delete ( struct tap_socket_list * list)
static

◆ tap_socket_list_addevs()

int tap_socket_list_addevs ( struct tap_socket_list * list,
struct ub_event_base * base )
static

◆ receive_bytes()

ssize_t receive_bytes ( struct tap_data * data,
int fd,
void * buf,
size_t len )
static

receive bytes from fd, prints errors if bad, returns 0: closed/error, -1: continue, >0 number of bytes

References tap_data::ev, tap_data::id, log_err(), log_info(), MSG_DONTWAIT, receive_bytes(), sock_strerror(), UB_EV_READ, ub_winsock_tcp_wouldblock(), and verbosity.

◆ tap_receive()

ssize_t tap_receive ( struct tap_data * data,
void * buf,
size_t len )
static

receive bytes on the tap connection, prints errors if bad, returns 0: closed/error, -1: continue, >0 number of bytes

References tap_data::fd, receive_bytes(), tap_data::ssl, and tap_receive().

Referenced by dtio_tap_callback(), and tap_receive().

◆ reply_with_accept()

int reply_with_accept ( struct tap_data * data)
static

◆ reply_with_finish()

int reply_with_finish ( struct tap_data * data)
static

◆ dtio_tap_callback()

◆ dtio_mainfdcallback()

◆ setup_local_list()

◆ setup_tcp_list()

◆ setup_tls_list()

void setup_tls_list ( struct main_tap_data * maindata,
struct config_strlist_head * tls_list,
char * server_key,
char * server_cert,
char * verifypem,
char * tls_protocols )
static

◆ main_sigh()

RETSIGTYPE main_sigh ( int sig)
static

signal handler for user quit

References main_sigh(), sig_base, sig_quit, and ub_event_base_loopexit().

Referenced by main(), and main_sigh().

◆ setup_and_run()

void setup_and_run ( struct config_strlist_head * local_list,
struct config_strlist_head * tcp_list,
struct config_strlist_head * tls_list,
char * server_key,
char * server_cert,
char * verifypem,
char * tls_protocols )
static

◆ main()

◆ order_lock_cmp()

int order_lock_cmp ( const void * e1,
const void * e2 )

Due to module breakage by fptr wlist, these test app declarations are presented here.

compare two order_ids from lock-verify test app

Parameters
e1first order_id
e2second order_id
Returns
compare code -1, 0, +1 (like memcmp).

References order_id::instance, and order_id::thr.

◆ codeline_cmp()

int codeline_cmp ( const void * a,
const void * b )

compare two codeline structs for rbtree from memstats test app

Parameters
acodeline
bcodeline
Returns
compare code -1, 0, +1 (like memcmp).

Variable Documentation

◆ longformat

int longformat = 0
static

long format option, for multiline printout per message

Referenced by main().

◆ sig_base

struct ub_event_base* sig_base = NULL
static

signal variable

Referenced by main_sigh(), and setup_and_run().

◆ sig_quit

int sig_quit = 0

do we have to quit

Referenced by main_sigh(), and setup_and_run().