"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "dnstap/dnstap_collector.c" between
nsd-4.3.5.tar.gz and nsd-4.3.6.tar.gz

About: NSD is an authoritative only, high performance, simple name server daemon.

dnstap_collector.c  (nsd-4.3.5):dnstap_collector.c  (nsd-4.3.6)
skipping to change at line 45 skipping to change at line 45
struct dt_collector* dt_collector_create(struct nsd* nsd) struct dt_collector* dt_collector_create(struct nsd* nsd)
{ {
int i, sv[2]; int i, sv[2];
struct dt_collector* dt_col = (struct dt_collector*)xalloc_zero( struct dt_collector* dt_col = (struct dt_collector*)xalloc_zero(
sizeof(*dt_col)); sizeof(*dt_col));
dt_col->count = nsd->child_count; dt_col->count = nsd->child_count;
dt_col->dt_env = NULL; dt_col->dt_env = NULL;
dt_col->region = region_create(xalloc, free); dt_col->region = region_create(xalloc, free);
dt_col->send_buffer = buffer_create(dt_col->region, dt_col->send_buffer = buffer_create(dt_col->region,
/* msglen + is_response + addrlen + is_tcp + packetlen + packet + zonelen + zone + spare + addr */ /* msglen + is_response + addrlen + is_tcp + packetlen + packet + zonelen + zone + spare + local_addr + addr */
4+1+4+1+4+TCP_MAX_MESSAGE_LEN+4+MAXHOSTNAMELEN + 32 + 4+1+4+1+4+TCP_MAX_MESSAGE_LEN+4+MAXHOSTNAMELEN + 32 +
#ifdef INET6 #ifdef INET6
sizeof(struct sockaddr_storage) sizeof(struct sockaddr_storage) + sizeof(struct sockaddr_storage)
#else #else
sizeof(struct sockaddr_in) sizeof(struct sockaddr_in) + sizeof(struct sockaddr_in)
#endif #endif
); );
/* open pipes in struct nsd */ /* open pipes in struct nsd */
nsd->dt_collector_fd_send = (int*)xalloc_array_zero(dt_col->count, nsd->dt_collector_fd_send = (int*)xalloc_array_zero(dt_col->count,
sizeof(int)); sizeof(int));
nsd->dt_collector_fd_recv = (int*)xalloc_array_zero(dt_col->count, nsd->dt_collector_fd_recv = (int*)xalloc_array_zero(dt_col->count,
sizeof(int)); sizeof(int));
for(i=0; i<dt_col->count; i++) { for(i=0; i<dt_col->count; i++) {
int fd[2]; int fd[2];
skipping to change at line 193 skipping to change at line 193
buffer_flip(buf); buffer_flip(buf);
return 1; return 1;
} }
/* submit the content of the buffer received to dnstap */ /* submit the content of the buffer received to dnstap */
static void static void
dt_submit_content(struct dt_env* dt_env, struct buffer* buf) dt_submit_content(struct dt_env* dt_env, struct buffer* buf)
{ {
uint8_t is_response, is_tcp; uint8_t is_response, is_tcp;
#ifdef INET6 #ifdef INET6
struct sockaddr_storage addr; struct sockaddr_storage local_addr, addr;
#else #else
struct sockaddr_in addr; struct sockaddr_in local_addr, addr;
#endif #endif
socklen_t addrlen; socklen_t addrlen;
size_t pktlen; size_t pktlen;
uint8_t* data; uint8_t* data;
size_t zonelen; size_t zonelen;
uint8_t* zone; uint8_t* zone;
/* parse content from buffer */ /* parse content from buffer */
if(!buffer_available(buf, 4+1+4)) return; if(!buffer_available(buf, 4+1+4)) return;
buffer_skip(buf, 4); /* skip msglen */ buffer_skip(buf, 4); /* skip msglen */
is_response = buffer_read_u8(buf); is_response = buffer_read_u8(buf);
addrlen = buffer_read_u32(buf); addrlen = buffer_read_u32(buf);
if(addrlen > sizeof(addr)) return; if(addrlen > sizeof(local_addr) || addrlen > sizeof(addr)) return;
if(!buffer_available(buf, addrlen)) return; if(!buffer_available(buf, 2*addrlen)) return;
buffer_read(buf, &local_addr, addrlen);
buffer_read(buf, &addr, addrlen); buffer_read(buf, &addr, addrlen);
if(!buffer_available(buf, 1+4)) return; if(!buffer_available(buf, 1+4)) return;
is_tcp = buffer_read_u8(buf); is_tcp = buffer_read_u8(buf);
pktlen = buffer_read_u32(buf); pktlen = buffer_read_u32(buf);
if(!buffer_available(buf, pktlen)) return; if(!buffer_available(buf, pktlen)) return;
data = buffer_current(buf); data = buffer_current(buf);
buffer_skip(buf, pktlen); buffer_skip(buf, pktlen);
if(!buffer_available(buf, 4)) return; if(!buffer_available(buf, 4)) return;
zonelen = buffer_read_u32(buf); zonelen = buffer_read_u32(buf);
if(zonelen == 0) { if(zonelen == 0) {
zone = NULL; zone = NULL;
} else { } else {
if(zonelen > MAXDOMAINLEN) return; if(zonelen > MAXDOMAINLEN) return;
if(!buffer_available(buf, zonelen)) return; if(!buffer_available(buf, zonelen)) return;
zone = buffer_current(buf); zone = buffer_current(buf);
buffer_skip(buf, zonelen); buffer_skip(buf, zonelen);
} }
/* submit it */ /* submit it */
if(is_response) { if(is_response) {
dt_msg_send_auth_response(dt_env, &addr, is_tcp, zone, dt_msg_send_auth_response(dt_env, &local_addr, &addr, is_tcp, zon e,
zonelen, data, pktlen); zonelen, data, pktlen);
} else { } else {
dt_msg_send_auth_query(dt_env, &addr, is_tcp, zone, dt_msg_send_auth_query(dt_env, &local_addr, &addr, is_tcp, zone,
zonelen, data, pktlen); zonelen, data, pktlen);
} }
} }
/* handle input from worker for dnstap */ /* handle input from worker for dnstap */
void void
dt_handle_input(int fd, short event, void* arg) dt_handle_input(int fd, short event, void* arg)
{ {
struct dt_collector_input* dt_input = (struct dt_collector_input*)arg; struct dt_collector_input* dt_input = (struct dt_collector_input*)arg;
if((event&EV_READ) != 0) { if((event&EV_READ) != 0) {
skipping to change at line 344 skipping to change at line 345
event_set(dt_col->inputs[i].event, event_set(dt_col->inputs[i].event,
nsd->dt_collector_fd_recv[i], EV_PERSIST|EV_READ, nsd->dt_collector_fd_recv[i], EV_PERSIST|EV_READ,
dt_handle_input, &dt_col->inputs[i]); dt_handle_input, &dt_col->inputs[i]);
if(event_base_set(dt_col->event_base, if(event_base_set(dt_col->event_base,
dt_col->inputs[i].event) != 0) dt_col->inputs[i].event) != 0)
log_msg(LOG_ERR, "dnstap collector: event_base_set failed "); log_msg(LOG_ERR, "dnstap collector: event_base_set failed ");
if(event_add(dt_col->inputs[i].event, NULL) != 0) if(event_add(dt_col->inputs[i].event, NULL) != 0)
log_msg(LOG_ERR, "dnstap collector: event_add failed"); log_msg(LOG_ERR, "dnstap collector: event_add failed");
dt_col->inputs[i].buffer = buffer_create(dt_col->region, dt_col->inputs[i].buffer = buffer_create(dt_col->region,
/* msglen + is_response + addrlen + is_tcp + packetlen + packet + zonelen + zone + spare + addr */ /* msglen + is_response + addrlen + is_tcp + packetlen + packet + zonelen + zone + spare + local_addr + addr */
4+1+4+1+4+TCP_MAX_MESSAGE_LEN+4+MAXHOSTNAMELEN + 32 + 4+1+4+1+4+TCP_MAX_MESSAGE_LEN+4+MAXHOSTNAMELEN + 32 +
#ifdef INET6 #ifdef INET6
sizeof(struct sockaddr_storage) sizeof(struct sockaddr_storage) + sizeof(struct sockaddr_ storage)
#else #else
sizeof(struct sockaddr_in) sizeof(struct sockaddr_in) + sizeof(struct sockaddr_in)
#endif #endif
); );
assert(buffer_capacity(dt_col->inputs[i].buffer) == assert(buffer_capacity(dt_col->inputs[i].buffer) ==
buffer_capacity(dt_col->send_buffer)); buffer_capacity(dt_col->send_buffer));
} }
} }
/* the dnstap collector process main routine */ /* the dnstap collector process main routine */
static void dt_collector_run(struct dt_collector* dt_col, struct nsd* nsd) static void dt_collector_run(struct dt_collector* dt_col, struct nsd* nsd)
{ {
skipping to change at line 403 skipping to change at line 404
/* close the dt side of the command channel */ /* close the dt side of the command channel */
close(dt_col->cmd_socket_dt); close(dt_col->cmd_socket_dt);
dt_col->cmd_socket_dt = -1; dt_col->cmd_socket_dt = -1;
} }
} }
/* put data for sending to the collector process into the buffer */ /* put data for sending to the collector process into the buffer */
static int static int
prep_send_data(struct buffer* buf, uint8_t is_response, prep_send_data(struct buffer* buf, uint8_t is_response,
#ifdef INET6 #ifdef INET6
struct sockaddr_storage* local_addr,
struct sockaddr_storage* addr, struct sockaddr_storage* addr,
#else #else
struct sockaddr_in* local_addr,
struct sockaddr_in* addr, struct sockaddr_in* addr,
#endif #endif
socklen_t addrlen, int is_tcp, struct buffer* packet, socklen_t addrlen, int is_tcp, struct buffer* packet,
struct zone* zone) struct zone* zone)
{ {
buffer_clear(buf); buffer_clear(buf);
if(!buffer_available(buf, 4+1+4+addrlen+1+4+buffer_remaining(packet))) #ifdef INET6
if(local_addr->ss_family != addr->ss_family)
return 0; /* must be same length to send */
#else
if(local_addr->sin_family != addr->sin_family)
return 0; /* must be same length to send */
#endif
if(!buffer_available(buf, 4+1+4+2*addrlen+1+4+buffer_remaining(packet)))
return 0; /* does not fit in send_buffer, log is dropped */ return 0; /* does not fit in send_buffer, log is dropped */
buffer_skip(buf, 4); /* the length of the message goes here */ buffer_skip(buf, 4); /* the length of the message goes here */
buffer_write_u8(buf, is_response); buffer_write_u8(buf, is_response);
buffer_write_u32(buf, addrlen); buffer_write_u32(buf, addrlen);
buffer_write(buf, local_addr, (size_t)addrlen);
buffer_write(buf, addr, (size_t)addrlen); buffer_write(buf, addr, (size_t)addrlen);
buffer_write_u8(buf, (is_tcp?1:0)); buffer_write_u8(buf, (is_tcp?1:0));
buffer_write_u32(buf, buffer_remaining(packet)); buffer_write_u32(buf, buffer_remaining(packet));
buffer_write(buf, buffer_begin(packet), buffer_remaining(packet)); buffer_write(buf, buffer_begin(packet), buffer_remaining(packet));
if(zone && zone->apex && domain_dname(zone->apex)) { if(zone && zone->apex && domain_dname(zone->apex)) {
if(!buffer_available(buf, 4 + domain_dname(zone->apex)->name_size )) if(!buffer_available(buf, 4 + domain_dname(zone->apex)->name_size ))
return 0; return 0;
buffer_write_u32(buf, domain_dname(zone->apex)->name_size); buffer_write_u32(buf, domain_dname(zone->apex)->name_size);
buffer_write(buf, dname_name(domain_dname(zone->apex)), buffer_write(buf, dname_name(domain_dname(zone->apex)),
domain_dname(zone->apex)->name_size); domain_dname(zone->apex)->name_size);
skipping to change at line 473 skipping to change at line 484
* because otherwise partial messages confuse the * because otherwise partial messages confuse the
* receiver. */ * receiver. */
continue; continue;
} }
total += r; total += r;
} }
} }
void dt_collector_submit_auth_query(struct nsd* nsd, void dt_collector_submit_auth_query(struct nsd* nsd,
#ifdef INET6 #ifdef INET6
struct sockaddr_storage* local_addr,
struct sockaddr_storage* addr, struct sockaddr_storage* addr,
#else #else
struct sockaddr_in* local_addr,
struct sockaddr_in* addr, struct sockaddr_in* addr,
#endif #endif
socklen_t addrlen, int is_tcp, struct buffer* packet) socklen_t addrlen, int is_tcp, struct buffer* packet)
{ {
if(!nsd->dt_collector) return; if(!nsd->dt_collector) return;
if(!nsd->options->dnstap_log_auth_query_messages) return; if(!nsd->options->dnstap_log_auth_query_messages) return;
VERBOSITY(4, (LOG_INFO, "dnstap submit auth query")); VERBOSITY(4, (LOG_INFO, "dnstap submit auth query"));
/* marshal data into send buffer */ /* marshal data into send buffer */
if(!prep_send_data(nsd->dt_collector->send_buffer, 0, addr, addrlen, if(!prep_send_data(nsd->dt_collector->send_buffer, 0, local_addr, addr, a ddrlen,
is_tcp, packet, NULL)) is_tcp, packet, NULL))
return; /* probably did not fit in buffer */ return; /* probably did not fit in buffer */
/* attempt to send data; do not block */ /* attempt to send data; do not block */
attempt_to_write(nsd->dt_collector_fd_send[nsd->this_child->child_num], attempt_to_write(nsd->dt_collector_fd_send[nsd->this_child->child_num],
buffer_begin(nsd->dt_collector->send_buffer), buffer_begin(nsd->dt_collector->send_buffer),
buffer_remaining(nsd->dt_collector->send_buffer)); buffer_remaining(nsd->dt_collector->send_buffer));
} }
void dt_collector_submit_auth_response(struct nsd* nsd, void dt_collector_submit_auth_response(struct nsd* nsd,
#ifdef INET6 #ifdef INET6
struct sockaddr_storage* local_addr,
struct sockaddr_storage* addr, struct sockaddr_storage* addr,
#else #else
struct sockaddr_in* local_addr,
struct sockaddr_in* addr, struct sockaddr_in* addr,
#endif #endif
socklen_t addrlen, int is_tcp, struct buffer* packet, socklen_t addrlen, int is_tcp, struct buffer* packet,
struct zone* zone) struct zone* zone)
{ {
if(!nsd->dt_collector) return; if(!nsd->dt_collector) return;
if(!nsd->options->dnstap_log_auth_response_messages) return; if(!nsd->options->dnstap_log_auth_response_messages) return;
VERBOSITY(4, (LOG_INFO, "dnstap submit auth response")); VERBOSITY(4, (LOG_INFO, "dnstap submit auth response"));
/* marshal data into send buffer */ /* marshal data into send buffer */
if(!prep_send_data(nsd->dt_collector->send_buffer, 1, addr, addrlen, if(!prep_send_data(nsd->dt_collector->send_buffer, 1, local_addr, addr, a ddrlen,
is_tcp, packet, zone)) is_tcp, packet, zone))
return; /* probably did not fit in buffer */ return; /* probably did not fit in buffer */
/* attempt to send data; do not block */ /* attempt to send data; do not block */
attempt_to_write(nsd->dt_collector_fd_send[nsd->this_child->child_num], attempt_to_write(nsd->dt_collector_fd_send[nsd->this_child->child_num],
buffer_begin(nsd->dt_collector->send_buffer), buffer_begin(nsd->dt_collector->send_buffer),
buffer_remaining(nsd->dt_collector->send_buffer)); buffer_remaining(nsd->dt_collector->send_buffer));
} }
 End of changes. 21 change blocks. 
15 lines changed or deleted 30 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)