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