Show
Ignore:
Timestamp:
09/13/10 15:28:40 (4 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1284391720 +0000
git-parent:

[5fbae1c5f1c2705b03bebf8e1f04b9cdf1b8e7a0]

git-author:
Theo Schlossnagle <jesus@omniti.com> 1284391720 +0000
Message:

fixes #315

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/modules/dns.c

    rafe029d r16e8c85  
    4747#include "udns/udns.h" 
    4848 
     49#define MAX_RR 256 
     50 
    4951static void eventer_dns_utm_fn(struct dns_ctx *, int, void *); 
    5052static int dns_eventer_callback(eventer_t, int, void *, struct timeval *); 
     
    6567  eventer_t timeout; /* the timeout managed by libudns */ 
    6668} dns_ctx_handle_t; 
     69 
     70static int cstring_cmp(const void *a, const void *b) { 
     71  return strcmp(*((const char **)a), *((const char **)b)); 
     72} 
    6773 
    6874static dns_ctx_handle_t *default_ctx_handle = NULL; 
     
    151157  char *error; 
    152158  int nrr; 
     159  int sort; 
    153160 
    154161  /* These make up the query itself */ 
     
    459466static void dns_cb(struct dns_ctx *ctx, void *result, void *data) { 
    460467  int r = dns_status(ctx); 
     468  int len, i; 
    461469  struct dns_check_info *ci = data; 
    462470  struct dns_parse p; 
     
    465473  unsigned char dn[DNS_MAXDN]; 
    466474  const unsigned char *pkt, *cur, *end; 
    467   char *result_str = NULL; 
     475  char *result_str[MAX_RR] = { NULL }; 
     476  char *result_combined = NULL; 
    468477 
    469478  /* If out ci isn't active, we must have timed out already */ 
     
    515524  p.dnsp_qtyp = ci->query_rtype == DNS_T_ANY ? 0 : ci->query_rtype; 
    516525  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); 
    520546 
    521547 cleanup: 
     
    540566  const char *rtype = NULL; 
    541567  const char *nameserver = NULL; 
     568  const char *want_sort = NULL; 
    542569  const char *ctype = "IN"; 
    543570  const char *query = NULL; 
     
    552579  ci->timed_out = 1; 
    553580  ci->nrr = 0; 
     581  ci->sort = 1; 
    554582 
    555583  if(!strcmp(check->name, "in-addr.arpa") || 
     
    580608  CONFIG_OVERRIDE(rtype); 
    581609  CONFIG_OVERRIDE(query); 
     610  CONFIG_OVERRIDE(want_sort); 
     611  if(want_sort && strcasecmp(want_sort, "on") && strcasecmp(want_sort, "true")) 
     612    ci->sort = 0; 
    582613 
    583614  noit_check_make_attrs(check, &check_attrs_hash); 
  • src/modules/dns.xml

    r9f36fc2 r16e8c85  
    2424               default="%[name]|%[:inaddrarpa:target].in-addr.arpa" 
    2525               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> 
    2630  </checkconfig> 
    2731  <examples>