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
 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
 

Functions

static void usage (char *argv[])
 usage information for streamtcp
 
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_sockettap_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_sockettap_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_sockettap_socket_new_tlsaccept (char *ip, void(*ev_cb)(int, short, void *), void *data, char *server_key, char *server_cert, char *verifypem)
 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 void tap_data_free (struct tap_data *data)
 delete the tap structure
 
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)
 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)
 setup and run the server to listen to DNSTAP messages
 
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_entryworker_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))
 
void worker_alloc_cleanup (void *ATTR_UNUSED(arg))
 
struct outbound_entrylibworker_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 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))
 
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. More...
 
int codeline_cmp (const void *a, const void *b)
 compare two codeline structs for rbtree from memstats test app More...
 
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))
 

Variables

static int longformat = 0
 long format option, for multiline printout per message
 
static struct ub_event_basesig_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.

Function Documentation

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