1 /*
2  * dnstap/dnstap_collector.h -- nsd collector process for dnstap information
3  *
4  * Copyright (c) 2018, NLnet Labs. All rights reserved.
5  *
6  * See LICENSE for the license.
7  *
8  */
9 
10 #ifndef DNSTAP_COLLECTOR_H
11 #define DNSTAP_COLLECTOR_H
12 struct dt_env;
13 struct nsd;
14 struct event_base;
15 struct event;
16 struct dt_collector_input;
17 struct zone;
18 struct buffer;
19 struct region;
20 
21 /* information for the dnstap collector process. It collects information
22  * for dnstap from the worker processes.  And writes them to the dnstap
23  * socket. */
24 struct dt_collector {
25 	/* dnstap env for the write to the dnstap socket */
26 	struct dt_env* dt_env;
27 	/* number of workers to collect from */
28 	int count;
29 	/* socketpair for communication between (xfrd) and the
30 	 * dnstap collector process.  If closed, the collector process
31 	 * exits.  The collector closes the other side of the socketpair, so
32 	 * that if xfrd exits, so does the dnstap collector */
33 	int cmd_socket_dt, cmd_socket_nsd;
34 	/* the pid of the dt collector process (0 on that process) */
35 	pid_t dt_pid;
36 	/* in the collector process, the event base */
37 	struct event_base* event_base;
38 	/* in the collector process, the cmd handle event */
39 	struct event* cmd_event;
40 	/* in the collector process, array size count of input per worker */
41 	struct dt_collector_input* inputs;
42 	/* region for buffers */
43 	struct region* region;
44 	/* buffer for sending data to the collector */
45 	struct buffer* send_buffer;
46 };
47 
48 /* information per worker to get input from that worker. */
49 struct dt_collector_input {
50 	/* the collector this is part of (for use in callbacks) */
51 	struct dt_collector* dt_collector;
52 	/* the event to listen to the datagrams to process for that worker*/
53 	struct event* event;
54 	/* buffer to store the datagrams while they are read in */
55 	struct buffer* buffer;
56 };
57 
58 /* create dt_collector process structure and dt_env */
59 struct dt_collector* dt_collector_create(struct nsd* nsd);
60 /* destroy the dt_collector structure */
61 void dt_collector_destroy(struct dt_collector* dt_col, struct nsd* nsd);
62 /* close file descriptors */
63 void dt_collector_close(struct dt_collector* dt_col, struct nsd* nsd);
64 /* start the collector process */
65 void dt_collector_start(struct dt_collector* dt_col, struct nsd* nsd);
66 
67 /* submit auth query from worker.  It attempts to send it to the collector,
68  * if the nonblocking fails, then it silently skips it.  So it does not block
69  * on the log.
70  */
71 void dt_collector_submit_auth_query(struct nsd* nsd,
72 #ifdef INET6
73 	struct sockaddr_storage* local_addr,
74 	struct sockaddr_storage* addr,
75 #else
76 	struct sockaddr_in* local_addr,
77 	struct sockaddr_in* addr,
78 #endif
79 	socklen_t addrlen, int is_tcp, struct buffer* packet);
80 
81 /* submit auth response from worker.  It attempts to send it to the collector,
82  * if the nonblocking fails, then it silently skips it.  So it does not block
83  * on the log.
84  */
85 void dt_collector_submit_auth_response(struct nsd* nsd,
86 #ifdef INET6
87 	struct sockaddr_storage* local_addr,
88 	struct sockaddr_storage* addr,
89 #else
90 	struct sockaddr_in* local_addr,
91 	struct sockaddr_in* addr,
92 #endif
93 	socklen_t addrlen, int is_tcp, struct buffer* packet,
94 	struct zone* zone);
95 
96 #endif /* DNSTAP_COLLECTOR_H */
97