Changeset 16e8c85a9d0e6b2e2bf74a7d159f6352253c50a9 for src/modules
- Timestamp:
- 09/13/10 15:28:40 (3 years ago)
- git-parent:
- Files:
-
- src/modules/dns.c (modified) (9 diffs)
- src/modules/dns.xml (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
src/modules/dns.c
rafe029d r16e8c85 47 47 #include "udns/udns.h" 48 48 49 #define MAX_RR 256 50 49 51 static void eventer_dns_utm_fn(struct dns_ctx *, int, void *); 50 52 static int dns_eventer_callback(eventer_t, int, void *, struct timeval *); … … 65 67 eventer_t timeout; /* the timeout managed by libudns */ 66 68 } dns_ctx_handle_t; 69 70 static int cstring_cmp(const void *a, const void *b) { 71 return strcmp(*((const char **)a), *((const char **)b)); 72 } 67 73 68 74 static dns_ctx_handle_t *default_ctx_handle = NULL; … … 151 157 char *error; 152 158 int nrr; 159 int sort; 153 160 154 161 /* These make up the query itself */ … … 459 466 static void dns_cb(struct dns_ctx *ctx, void *result, void *data) { 460 467 int r = dns_status(ctx); 468 int len, i; 461 469 struct dns_check_info *ci = data; 462 470 struct dns_parse p; … … 465 473 unsigned char dn[DNS_MAXDN]; 466 474 const unsigned char *pkt, *cur, *end; 467 char *result_str = NULL; 475 char *result_str[MAX_RR] = { NULL }; 476 char *result_combined = NULL; 468 477 469 478 /* If out ci isn't active, we must have timed out already */ … … 515 524 p.dnsp_qtyp = ci->query_rtype == DNS_T_ANY ? 0 : ci->query_rtype; 516 525 p.dnsp_qcls = ci->query_ctype == DNS_C_ANY ? 0 : ci->query_ctype; 517 while(dns_nextrr(&p, &rr)) 518 decode_rr(ci, &p, &rr, &result_str); 519 noit_stats_set_metric(&ci->current, "answer", METRIC_STRING, result_str); 526 while(dns_nextrr(&p, &rr) && ci->nrr < MAX_RR) 527 decode_rr(ci, &p, &rr, &result_str[ci->nrr]); 528 if(ci->sort) 529 qsort(result_str, ci->nrr, sizeof(*result_str), cstring_cmp); 530 /* calculate the length and allocate on the stack */ 531 len = 0; 532 for(i=0; i<ci->nrr; i++) len += strlen(result_str[i]) + 2; 533 result_combined = alloca(len); 534 /* string it together */ 535 len = 0; 536 for(i=0; i<ci->nrr; i++) { 537 int slen; 538 if(i) { memcpy(result_combined + len, ", ", 2); len += 2; } 539 slen = strlen(result_str[i]); 540 memcpy(result_combined + len, result_str[i], slen); 541 len += slen; 542 result_combined[len] = '\0'; 543 free(result_str[i]); /* free as we go */ 544 } 545 noit_stats_set_metric(&ci->current, "answer", METRIC_STRING, result_combined); 520 546 521 547 cleanup: … … 540 566 const char *rtype = NULL; 541 567 const char *nameserver = NULL; 568 const char *want_sort = NULL; 542 569 const char *ctype = "IN"; 543 570 const char *query = NULL; … … 552 579 ci->timed_out = 1; 553 580 ci->nrr = 0; 581 ci->sort = 1; 554 582 555 583 if(!strcmp(check->name, "in-addr.arpa") || … … 580 608 CONFIG_OVERRIDE(rtype); 581 609 CONFIG_OVERRIDE(query); 610 CONFIG_OVERRIDE(want_sort); 611 if(want_sort && strcasecmp(want_sort, "on") && strcasecmp(want_sort, "true")) 612 ci->sort = 0; 582 613 583 614 noit_check_make_attrs(check, &check_attrs_hash); src/modules/dns.xml
r9f36fc2 r16e8c85 24 24 default="%[name]|%[:inaddrarpa:target].in-addr.arpa" 25 25 allowed=".+">The query to send. If the name of the check is in-addr.arpa, the reverse IP octet notation of in-addr.arpa syntax is synthesized by default. Otherwise the default query is the name of the check itself.</parameter> 26 <parameter name="want_sort" 27 required="optional" 28 default="true" 29 allowed="(true|false|on|off)">Sorts (strcmp) the answers if multiple RRs are returned in the result set.</parameter> 26 30 </checkconfig> 27 31 <examples>
