1 /*
2 * daemon/stats.c - collect runtime performance indicators.
3 *
4 * Copyright (c) 2007, NLnet Labs. All rights reserved.
5 *
6 * This software is open source.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
14 *
15 * Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
18 *
19 * Neither the name of the NLNET LABS nor the names of its contributors may
20 * be used to endorse or promote products derived from this software without
21 * specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
29 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 */
35
36 /**
37 * \file
38 *
39 * This file describes the data structure used to collect runtime performance
40 * numbers. These 'statistics' may be of interest to the operator.
41 */
42 #include "config.h"
43 #ifdef HAVE_TIME_H
44 #include <time.h>
45 #endif
46 #include <sys/time.h>
47 #include <sys/types.h>
48 #include "daemon/stats.h"
49 #include "daemon/worker.h"
50 #include "daemon/daemon.h"
51 #include "services/mesh.h"
52 #include "services/outside_network.h"
53 #include "services/listen_dnsport.h"
54 #include "util/config_file.h"
55 #include "util/tube.h"
56 #include "util/timehist.h"
57 #include "util/net_help.h"
58 #include "validator/validator.h"
59 #include "iterator/iterator.h"
60 #include "sldns/sbuffer.h"
61 #include "services/cache/rrset.h"
62 #include "services/cache/infra.h"
63 #include "services/authzone.h"
64 #include "validator/val_kcache.h"
65 #include "validator/val_neg.h"
66 #ifdef CLIENT_SUBNET
67 #include "edns-subnet/subnetmod.h"
68 #endif
69 #ifdef HAVE_SSL
70 #include <openssl/ssl.h>
71 #endif
72
73 /** add timers and the values do not overflow or become negative */
74 static void
stats_timeval_add(long long * d_sec,long long * d_usec,long long add_sec,long long add_usec)75 stats_timeval_add(long long* d_sec, long long* d_usec, long long add_sec, long long add_usec)
76 {
77 #ifndef S_SPLINT_S
78 (*d_sec) += add_sec;
79 (*d_usec) += add_usec;
80 if((*d_usec) >= 1000000) {
81 (*d_usec) -= 1000000;
82 (*d_sec)++;
83 }
84 #endif
85 }
86
server_stats_init(struct ub_server_stats * stats,struct config_file * cfg)87 void server_stats_init(struct ub_server_stats* stats, struct config_file* cfg)
88 {
89 memset(stats, 0, sizeof(*stats));
90 stats->extended = cfg->stat_extended;
91 }
92
server_stats_querymiss(struct ub_server_stats * stats,struct worker * worker)93 void server_stats_querymiss(struct ub_server_stats* stats, struct worker* worker)
94 {
95 stats->num_queries_missed_cache++;
96 stats->sum_query_list_size += worker->env.mesh->all.count;
97 if((long long)worker->env.mesh->all.count > stats->max_query_list_size)
98 stats->max_query_list_size = (long long)worker->env.mesh->all.count;
99 }
100
server_stats_prefetch(struct ub_server_stats * stats,struct worker * worker)101 void server_stats_prefetch(struct ub_server_stats* stats, struct worker* worker)
102 {
103 stats->num_queries_prefetch++;
104 /* changes the query list size so account that, like a querymiss */
105 stats->sum_query_list_size += worker->env.mesh->all.count;
106 if((long long)worker->env.mesh->all.count > stats->max_query_list_size)
107 stats->max_query_list_size = (long long)worker->env.mesh->all.count;
108 }
109
server_stats_log(struct ub_server_stats * stats,struct worker * worker,int threadnum)110 void server_stats_log(struct ub_server_stats* stats, struct worker* worker,
111 int threadnum)
112 {
113 log_info("server stats for thread %d: %u queries, "
114 "%u answers from cache, %u recursions, %u prefetch, %u rejected by "
115 "ip ratelimiting",
116 threadnum, (unsigned)stats->num_queries,
117 (unsigned)(stats->num_queries -
118 stats->num_queries_missed_cache),
119 (unsigned)stats->num_queries_missed_cache,
120 (unsigned)stats->num_queries_prefetch,
121 (unsigned)stats->num_queries_ip_ratelimited);
122 log_info("server stats for thread %d: requestlist max %u avg %g "
123 "exceeded %u jostled %u", threadnum,
124 (unsigned)stats->max_query_list_size,
125 (stats->num_queries_missed_cache+stats->num_queries_prefetch)?
126 (double)stats->sum_query_list_size/
127 (double)(stats->num_queries_missed_cache+
128 stats->num_queries_prefetch) : 0.0,
129 (unsigned)worker->env.mesh->stats_dropped,
130 (unsigned)worker->env.mesh->stats_jostled);
131 }
132
133
134 #ifdef CLIENT_SUBNET
135 /** Set the EDNS Subnet stats. */
136 static void
set_subnet_stats(struct worker * worker,struct ub_server_stats * svr,int reset)137 set_subnet_stats(struct worker* worker, struct ub_server_stats* svr,
138 int reset)
139 {
140 int m = modstack_find(&worker->env.mesh->mods, "subnet");
141 struct subnet_env* sne;
142 if(m == -1)
143 return;
144 sne = (struct subnet_env*)worker->env.modinfo[m];
145 if(reset && !worker->env.cfg->stat_cumulative) {
146 lock_rw_wrlock(&sne->biglock);
147 } else {
148 lock_rw_rdlock(&sne->biglock);
149 }
150 svr->num_query_subnet = (long long)(sne->num_msg_nocache + sne->num_msg_cache);
151 svr->num_query_subnet_cache = (long long)sne->num_msg_cache;
152 if(reset && !worker->env.cfg->stat_cumulative) {
153 sne->num_msg_cache = 0;
154 sne->num_msg_nocache = 0;
155 }
156 lock_rw_unlock(&sne->biglock);
157 }
158 #endif /* CLIENT_SUBNET */
159
160 /** Set the neg cache stats. */
161 static void
set_neg_cache_stats(struct worker * worker,struct ub_server_stats * svr,int reset)162 set_neg_cache_stats(struct worker* worker, struct ub_server_stats* svr,
163 int reset)
164 {
165 int m = modstack_find(&worker->env.mesh->mods, "validator");
166 struct val_env* ve;
167 struct val_neg_cache* neg;
168 if(m == -1)
169 return;
170 ve = (struct val_env*)worker->env.modinfo[m];
171 if(!ve->neg_cache)
172 return;
173 neg = ve->neg_cache;
174 lock_basic_lock(&neg->lock);
175 svr->num_neg_cache_noerror = (long long)neg->num_neg_cache_noerror;
176 svr->num_neg_cache_nxdomain = (long long)neg->num_neg_cache_nxdomain;
177 if(reset && !worker->env.cfg->stat_cumulative) {
178 neg->num_neg_cache_noerror = 0;
179 neg->num_neg_cache_nxdomain = 0;
180 }
181 lock_basic_unlock(&neg->lock);
182 }
183
184 /** get rrsets bogus number from validator */
185 static size_t
get_rrset_bogus(struct worker * worker,int reset)186 get_rrset_bogus(struct worker* worker, int reset)
187 {
188 int m = modstack_find(&worker->env.mesh->mods, "validator");
189 struct val_env* ve;
190 size_t r;
191 if(m == -1)
192 return 0;
193 ve = (struct val_env*)worker->env.modinfo[m];
194 lock_basic_lock(&ve->bogus_lock);
195 r = ve->num_rrset_bogus;
196 if(reset && !worker->env.cfg->stat_cumulative)
197 ve->num_rrset_bogus = 0;
198 lock_basic_unlock(&ve->bogus_lock);
199 return r;
200 }
201
202 /** get number of ratelimited queries from iterator */
203 static size_t
get_queries_ratelimit(struct worker * worker,int reset)204 get_queries_ratelimit(struct worker* worker, int reset)
205 {
206 int m = modstack_find(&worker->env.mesh->mods, "iterator");
207 struct iter_env* ie;
208 size_t r;
209 if(m == -1)
210 return 0;
211 ie = (struct iter_env*)worker->env.modinfo[m];
212 lock_basic_lock(&ie->queries_ratelimit_lock);
213 r = ie->num_queries_ratelimited;
214 if(reset && !worker->env.cfg->stat_cumulative)
215 ie->num_queries_ratelimited = 0;
216 lock_basic_unlock(&ie->queries_ratelimit_lock);
217 return r;
218 }
219
220 #ifdef USE_DNSCRYPT
221 /** get the number of shared secret cache miss */
222 static size_t
get_dnscrypt_cache_miss(struct worker * worker,int reset)223 get_dnscrypt_cache_miss(struct worker* worker, int reset)
224 {
225 size_t r;
226 struct dnsc_env* de = worker->daemon->dnscenv;
227 if(!de) return 0;
228
229 lock_basic_lock(&de->shared_secrets_cache_lock);
230 r = de->num_query_dnscrypt_secret_missed_cache;
231 if(reset && !worker->env.cfg->stat_cumulative)
232 de->num_query_dnscrypt_secret_missed_cache = 0;
233 lock_basic_unlock(&de->shared_secrets_cache_lock);
234 return r;
235 }
236
237 /** get the number of replayed queries */
238 static size_t
get_dnscrypt_replay(struct worker * worker,int reset)239 get_dnscrypt_replay(struct worker* worker, int reset)
240 {
241 size_t r;
242 struct dnsc_env* de = worker->daemon->dnscenv;
243
244 lock_basic_lock(&de->nonces_cache_lock);
245 r = de->num_query_dnscrypt_replay;
246 if(reset && !worker->env.cfg->stat_cumulative)
247 de->num_query_dnscrypt_replay = 0;
248 lock_basic_unlock(&de->nonces_cache_lock);
249 return r;
250 }
251 #endif /* USE_DNSCRYPT */
252
253 void
server_stats_compile(struct worker * worker,struct ub_stats_info * s,int reset)254 server_stats_compile(struct worker* worker, struct ub_stats_info* s, int reset)
255 {
256 int i;
257 struct listen_list* lp;
258
259 s->svr = worker->stats;
260 s->mesh_num_states = (long long)worker->env.mesh->all.count;
261 s->mesh_num_reply_states = (long long)worker->env.mesh->num_reply_states;
262 s->mesh_jostled = (long long)worker->env.mesh->stats_jostled;
263 s->mesh_dropped = (long long)worker->env.mesh->stats_dropped;
264 s->mesh_replies_sent = (long long)worker->env.mesh->replies_sent;
265 s->mesh_replies_sum_wait_sec = (long long)worker->env.mesh->replies_sum_wait.tv_sec;
266 s->mesh_replies_sum_wait_usec = (long long)worker->env.mesh->replies_sum_wait.tv_usec;
267 s->mesh_time_median = timehist_quartile(worker->env.mesh->histogram,
268 0.50);
269
270 /* add in the values from the mesh */
271 s->svr.ans_secure += (long long)worker->env.mesh->ans_secure;
272 s->svr.ans_bogus += (long long)worker->env.mesh->ans_bogus;
273 s->svr.ans_rcode_nodata += (long long)worker->env.mesh->ans_nodata;
274 for(i=0; i<UB_STATS_RCODE_NUM; i++)
275 s->svr.ans_rcode[i] += (long long)worker->env.mesh->ans_rcode[i];
276 for(i=0; i<UB_STATS_RPZ_ACTION_NUM; i++)
277 s->svr.rpz_action[i] += (long long)worker->env.mesh->rpz_action[i];
278 timehist_export(worker->env.mesh->histogram, s->svr.hist,
279 NUM_BUCKETS_HIST);
280 /* values from outside network */
281 s->svr.unwanted_replies = (long long)worker->back->unwanted_replies;
282 s->svr.qtcp_outgoing = (long long)worker->back->num_tcp_outgoing;
283
284 /* get and reset validator rrset bogus number */
285 s->svr.rrset_bogus = (long long)get_rrset_bogus(worker, reset);
286
287 /* get and reset iterator query ratelimit number */
288 s->svr.queries_ratelimited = (long long)get_queries_ratelimit(worker, reset);
289
290 /* get cache sizes */
291 s->svr.msg_cache_count = (long long)count_slabhash_entries(worker->env.msg_cache);
292 s->svr.rrset_cache_count = (long long)count_slabhash_entries(&worker->env.rrset_cache->table);
293 s->svr.infra_cache_count = (long long)count_slabhash_entries(worker->env.infra_cache->hosts);
294 if(worker->env.key_cache)
295 s->svr.key_cache_count = (long long)count_slabhash_entries(worker->env.key_cache->slab);
296 else s->svr.key_cache_count = 0;
297
298 #ifdef USE_DNSCRYPT
299 if(worker->daemon->dnscenv) {
300 s->svr.num_query_dnscrypt_secret_missed_cache =
301 (long long)get_dnscrypt_cache_miss(worker, reset);
302 s->svr.shared_secret_cache_count = (long long)count_slabhash_entries(
303 worker->daemon->dnscenv->shared_secrets_cache);
304 s->svr.nonce_cache_count = (long long)count_slabhash_entries(
305 worker->daemon->dnscenv->nonces_cache);
306 s->svr.num_query_dnscrypt_replay =
307 (long long)get_dnscrypt_replay(worker, reset);
308 } else {
309 s->svr.num_query_dnscrypt_secret_missed_cache = 0;
310 s->svr.shared_secret_cache_count = 0;
311 s->svr.nonce_cache_count = 0;
312 s->svr.num_query_dnscrypt_replay = 0;
313 }
314 #else
315 s->svr.num_query_dnscrypt_secret_missed_cache = 0;
316 s->svr.shared_secret_cache_count = 0;
317 s->svr.nonce_cache_count = 0;
318 s->svr.num_query_dnscrypt_replay = 0;
319 #endif /* USE_DNSCRYPT */
320 if(worker->env.auth_zones) {
321 if(reset && !worker->env.cfg->stat_cumulative) {
322 lock_rw_wrlock(&worker->env.auth_zones->lock);
323 } else {
324 lock_rw_rdlock(&worker->env.auth_zones->lock);
325 }
326 s->svr.num_query_authzone_up = (long long)worker->env.
327 auth_zones->num_query_up;
328 s->svr.num_query_authzone_down = (long long)worker->env.
329 auth_zones->num_query_down;
330 if(reset && !worker->env.cfg->stat_cumulative) {
331 worker->env.auth_zones->num_query_up = 0;
332 worker->env.auth_zones->num_query_down = 0;
333 }
334 lock_rw_unlock(&worker->env.auth_zones->lock);
335 }
336 s->svr.mem_stream_wait =
337 (long long)tcp_req_info_get_stream_buffer_size();
338
339 /* Set neg cache usage numbers */
340 set_neg_cache_stats(worker, &s->svr, reset);
341 #ifdef CLIENT_SUBNET
342 /* EDNS Subnet usage numbers */
343 set_subnet_stats(worker, &s->svr, reset);
344 #else
345 s->svr.num_query_subnet = 0;
346 s->svr.num_query_subnet_cache = 0;
347 #endif
348
349 /* get tcp accept usage */
350 s->svr.tcp_accept_usage = 0;
351 for(lp = worker->front->cps; lp; lp = lp->next) {
352 if(lp->com->type == comm_tcp_accept)
353 s->svr.tcp_accept_usage += (long long)lp->com->cur_tcp_count;
354 }
355
356 if(reset && !worker->env.cfg->stat_cumulative) {
357 worker_stats_clear(worker);
358 }
359 }
360
server_stats_obtain(struct worker * worker,struct worker * who,struct ub_stats_info * s,int reset)361 void server_stats_obtain(struct worker* worker, struct worker* who,
362 struct ub_stats_info* s, int reset)
363 {
364 uint8_t *reply = NULL;
365 uint32_t len = 0;
366 if(worker == who) {
367 /* just fill it in */
368 server_stats_compile(worker, s, reset);
369 return;
370 }
371 /* communicate over tube */
372 verbose(VERB_ALGO, "write stats cmd");
373 if(reset)
374 worker_send_cmd(who, worker_cmd_stats);
375 else worker_send_cmd(who, worker_cmd_stats_noreset);
376 verbose(VERB_ALGO, "wait for stats reply");
377 if(!tube_read_msg(worker->cmd, &reply, &len, 0))
378 fatal_exit("failed to read stats over cmd channel");
379 if(len != (uint32_t)sizeof(*s))
380 fatal_exit("stats on cmd channel wrong length %d %d",
381 (int)len, (int)sizeof(*s));
382 memcpy(s, reply, (size_t)len);
383 free(reply);
384 }
385
server_stats_reply(struct worker * worker,int reset)386 void server_stats_reply(struct worker* worker, int reset)
387 {
388 struct ub_stats_info s;
389 server_stats_compile(worker, &s, reset);
390 verbose(VERB_ALGO, "write stats replymsg");
391 if(!tube_write_msg(worker->daemon->workers[0]->cmd,
392 (uint8_t*)&s, sizeof(s), 0))
393 fatal_exit("could not write stat values over cmd channel");
394 }
395
server_stats_add(struct ub_stats_info * total,struct ub_stats_info * a)396 void server_stats_add(struct ub_stats_info* total, struct ub_stats_info* a)
397 {
398 total->svr.num_queries += a->svr.num_queries;
399 total->svr.num_queries_ip_ratelimited += a->svr.num_queries_ip_ratelimited;
400 total->svr.num_queries_missed_cache += a->svr.num_queries_missed_cache;
401 total->svr.num_queries_prefetch += a->svr.num_queries_prefetch;
402 total->svr.sum_query_list_size += a->svr.sum_query_list_size;
403 total->svr.ans_expired += a->svr.ans_expired;
404 #ifdef USE_DNSCRYPT
405 total->svr.num_query_dnscrypt_crypted += a->svr.num_query_dnscrypt_crypted;
406 total->svr.num_query_dnscrypt_cert += a->svr.num_query_dnscrypt_cert;
407 total->svr.num_query_dnscrypt_cleartext += \
408 a->svr.num_query_dnscrypt_cleartext;
409 total->svr.num_query_dnscrypt_crypted_malformed += \
410 a->svr.num_query_dnscrypt_crypted_malformed;
411 #endif /* USE_DNSCRYPT */
412 /* the max size reached is upped to higher of both */
413 if(a->svr.max_query_list_size > total->svr.max_query_list_size)
414 total->svr.max_query_list_size = a->svr.max_query_list_size;
415
416 if(a->svr.extended) {
417 int i;
418 total->svr.qtype_big += a->svr.qtype_big;
419 total->svr.qclass_big += a->svr.qclass_big;
420 total->svr.qtcp += a->svr.qtcp;
421 total->svr.qtcp_outgoing += a->svr.qtcp_outgoing;
422 total->svr.qtls += a->svr.qtls;
423 total->svr.qtls_resume += a->svr.qtls_resume;
424 total->svr.qipv6 += a->svr.qipv6;
425 total->svr.qbit_QR += a->svr.qbit_QR;
426 total->svr.qbit_AA += a->svr.qbit_AA;
427 total->svr.qbit_TC += a->svr.qbit_TC;
428 total->svr.qbit_RD += a->svr.qbit_RD;
429 total->svr.qbit_RA += a->svr.qbit_RA;
430 total->svr.qbit_Z += a->svr.qbit_Z;
431 total->svr.qbit_AD += a->svr.qbit_AD;
432 total->svr.qbit_CD += a->svr.qbit_CD;
433 total->svr.qEDNS += a->svr.qEDNS;
434 total->svr.qEDNS_DO += a->svr.qEDNS_DO;
435 total->svr.ans_rcode_nodata += a->svr.ans_rcode_nodata;
436 total->svr.ans_secure += a->svr.ans_secure;
437 total->svr.ans_bogus += a->svr.ans_bogus;
438 total->svr.unwanted_replies += a->svr.unwanted_replies;
439 total->svr.unwanted_queries += a->svr.unwanted_queries;
440 total->svr.tcp_accept_usage += a->svr.tcp_accept_usage;
441 for(i=0; i<UB_STATS_QTYPE_NUM; i++)
442 total->svr.qtype[i] += a->svr.qtype[i];
443 for(i=0; i<UB_STATS_QCLASS_NUM; i++)
444 total->svr.qclass[i] += a->svr.qclass[i];
445 for(i=0; i<UB_STATS_OPCODE_NUM; i++)
446 total->svr.qopcode[i] += a->svr.qopcode[i];
447 for(i=0; i<UB_STATS_RCODE_NUM; i++)
448 total->svr.ans_rcode[i] += a->svr.ans_rcode[i];
449 for(i=0; i<NUM_BUCKETS_HIST; i++)
450 total->svr.hist[i] += a->svr.hist[i];
451 for(i=0; i<UB_STATS_RPZ_ACTION_NUM; i++)
452 total->svr.rpz_action[i] += a->svr.rpz_action[i];
453 }
454
455 total->mesh_num_states += a->mesh_num_states;
456 total->mesh_num_reply_states += a->mesh_num_reply_states;
457 total->mesh_jostled += a->mesh_jostled;
458 total->mesh_dropped += a->mesh_dropped;
459 total->mesh_replies_sent += a->mesh_replies_sent;
460 stats_timeval_add(&total->mesh_replies_sum_wait_sec, &total->mesh_replies_sum_wait_usec, a->mesh_replies_sum_wait_sec, a->mesh_replies_sum_wait_usec);
461 /* the medians are averaged together, this is not as accurate as
462 * taking the median over all of the data, but is good and fast
463 * added up here, division later*/
464 total->mesh_time_median += a->mesh_time_median;
465 }
466
server_stats_insquery(struct ub_server_stats * stats,struct comm_point * c,uint16_t qtype,uint16_t qclass,struct edns_data * edns,struct comm_reply * repinfo)467 void server_stats_insquery(struct ub_server_stats* stats, struct comm_point* c,
468 uint16_t qtype, uint16_t qclass, struct edns_data* edns,
469 struct comm_reply* repinfo)
470 {
471 uint16_t flags = sldns_buffer_read_u16_at(c->buffer, 2);
472 if(qtype < UB_STATS_QTYPE_NUM)
473 stats->qtype[qtype]++;
474 else stats->qtype_big++;
475 if(qclass < UB_STATS_QCLASS_NUM)
476 stats->qclass[qclass]++;
477 else stats->qclass_big++;
478 stats->qopcode[ LDNS_OPCODE_WIRE(sldns_buffer_begin(c->buffer)) ]++;
479 if(c->type != comm_udp) {
480 stats->qtcp++;
481 if(c->ssl != NULL) {
482 stats->qtls++;
483 #ifdef HAVE_SSL
484 if(SSL_session_reused(c->ssl))
485 stats->qtls_resume++;
486 #endif
487 }
488 }
489 if(repinfo && addr_is_ip6(&repinfo->addr, repinfo->addrlen))
490 stats->qipv6++;
491 if( (flags&BIT_QR) )
492 stats->qbit_QR++;
493 if( (flags&BIT_AA) )
494 stats->qbit_AA++;
495 if( (flags&BIT_TC) )
496 stats->qbit_TC++;
497 if( (flags&BIT_RD) )
498 stats->qbit_RD++;
499 if( (flags&BIT_RA) )
500 stats->qbit_RA++;
501 if( (flags&BIT_Z) )
502 stats->qbit_Z++;
503 if( (flags&BIT_AD) )
504 stats->qbit_AD++;
505 if( (flags&BIT_CD) )
506 stats->qbit_CD++;
507 if(edns->edns_present) {
508 stats->qEDNS++;
509 if( (edns->bits & EDNS_DO) )
510 stats->qEDNS_DO++;
511 }
512 }
513
server_stats_insrcode(struct ub_server_stats * stats,sldns_buffer * buf)514 void server_stats_insrcode(struct ub_server_stats* stats, sldns_buffer* buf)
515 {
516 if(stats->extended && sldns_buffer_limit(buf) != 0) {
517 int r = (int)LDNS_RCODE_WIRE( sldns_buffer_begin(buf) );
518 stats->ans_rcode[r] ++;
519 if(r == 0 && LDNS_ANCOUNT( sldns_buffer_begin(buf) ) == 0)
520 stats->ans_rcode_nodata ++;
521 }
522 }
523