Changeset de645be52b417be48be0d95ec39f045439782fb6

Show
Ignore:
Timestamp:
09/16/11 20:32:07 (3 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1316205127 -0400
git-parent:

[9eca23b16e66b798a03d5fbbd442b9f8c639c63e], [16b1bdd1a6ac2cff3a9d3145c7d31de06255c661]

git-author:
Theo Schlossnagle <jesus@omniti.com> 1316205127 -0400
Message:

Merge branch 'dns_resolve_rtype' of https://github.com/gdusbabek/reconnoiter into dns_resolve_rtype

Files:

Legend:

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

    rf0c65b7 rde645be  
    9797noit_fire_check(xmlNodePtr attr, xmlNodePtr config, const char **error) { 
    9898  char *target = NULL, *name = NULL, *module = NULL, *filterset = NULL; 
    99   int timeout = 0; 
     99  char *resolve_rtype = NULL; 
     100  int timeout = 0, flags = NP_TRANSIENT; 
    100101  noit_module_t *m; 
    101102  noit_check_t *c = NULL; 
     
    116117      timeout = atoi(timeout_str); 
    117118      free(timeout_str); 
    118     } 
     119    } else if(!strcmp((char *)a->name, "resolve_rtype"))  
     120      resolve_rtype = (char *)xmlNodeGetContent(a); 
    119121  } 
    120122  m = noit_module_lookup(module); 
     
    139141    goto error; 
    140142  } 
     143  flags |= noit_calc_rtype_flag(resolve_rtype); 
    141144  c = calloc(1, sizeof(*c)); 
    142145  noit_check_update(c, target, name, filterset, 
    143                     conf_hash, 0, timeout, NULL, NP_TRANSIENT); 
     146                    conf_hash, 0, timeout, NULL, flags); 
    144147  c->module = strdup(module); 
    145148  uuid_generate(c->checkid); 
     
    157160  if(module) xmlFree(module); 
    158161  if(filterset) xmlFree(filterset); 
     162  if (resolve_rtype) xmlFree(resolve_rtype); 
    159163  return c; 
    160164} 
  • src/noit_check.c

    rf207009 r16b1bdd  
    107107} 
    108108int 
     109noit_calc_rtype_flag(char *resolve_rtype) { 
     110  int flags = 0; 
     111  flags |= strcmp(resolve_rtype, PREFER_IPV6) == 0 || 
     112           strcmp(resolve_rtype, FORCE_IPV6) == 0 ? NP_PREFER_IPV6 : 0; 
     113  flags |= strcmp(resolve_rtype, FORCE_IPV4) == 0 || 
     114           strcmp(resolve_rtype, FORCE_IPV6) == 0 ? NP_SINGLE_RESOLVE : 0; 
     115  return flags; 
     116} 
     117int 
    109118noit_check_max_initial_stutter() { 
    110119  int stutter; 
     
    150159    char filterset[256] = ""; 
    151160    char oncheck[1024] = ""; 
     161    char resolve_rtype[16] = ""; 
    152162    int no_period = 0; 
    153163    int no_oncheck = 0; 
     
    183193    if(!INHERIT(stringbuf, filterset, filterset, sizeof(filterset))) 
    184194      filterset[0] = '\0'; 
     195     
     196    if (!INHERIT(stringbuf, resolve_rtype, resolve_rtype, sizeof(resolve_rtype))) 
     197      strlcpy(resolve_rtype, PREFER_IPV4, sizeof(resolve_rtype)); 
    185198 
    186199    if(!MYATTR(stringbuf, name, name, sizeof(name))) 
     
    217230    if(busted) flags |= (NP_UNCONFIG|NP_DISABLED); 
    218231    else if(disabled) flags |= NP_DISABLED; 
     232 
     233    flags |= noit_calc_rtype_flag(resolve_rtype); 
    219234 
    220235    if(noit_hash_retrieve(&polls, (char *)uuid, UUID_SIZE, 
     
    569584  } a; 
    570585 
    571  
    572   family = AF_INET; 
     586  family = NOIT_CHECK_PREFER_V6(new_check) ? AF_INET6 : AF_INET; 
    573587  rv = inet_pton(family, ip_str, &a); 
    574   if(rv != 1) { 
    575     family = AF_INET6
     588  if(rv != 1 && !NOIT_CHECK_SINGLE_RESOLVE(new_check)) { 
     589    family = family == AF_INET ? AF_INET6 : AF_INET
    576590    rv = inet_pton(family, ip_str, &a); 
    577591    if(rv != 1) { 
     
    624638  if(new_check->target) free(new_check->target); 
    625639  new_check->target = strdup(target); 
     640 
     641  // apply resolution flags to check. 
     642  if (flags & NP_PREFER_IPV6) 
     643    new_check->flags |= NP_PREFER_IPV6; 
     644  else 
     645    new_check->flags &= ~NP_PREFER_IPV6; 
     646  if (flags & NP_SINGLE_RESOLVE) 
     647    new_check->flags |= NP_SINGLE_RESOLVE; 
     648  else 
     649    new_check->flags &= ~NP_SINGLE_RESOLVE; 
    626650 
    627651  if(noit_check_set_ip(new_check, target)) { 
  • src/noit_check.h

    r3081176 r16b1bdd  
    7373#define NP_SUPPRESS_METRICS 0x00002000 
    7474 
     75#define NP_PREFER_IPV6   0x00004000 
     76#define NP_SINGLE_RESOLVE 0x00008000 
     77 
     78#define PREFER_IPV4 "prefer-ipv4" 
     79#define PREFER_IPV6 "prefer-ipv6" 
     80#define FORCE_IPV4  "force-ipv4" 
     81#define FORCE_IPV6  "force-ipv6" 
     82 
    7583#define NP_UNKNOWN '0'             /* stats_t.{available,state} */ 
    7684#define NP_AVAILABLE 'A'           /* stats_t.available */ 
     
    156164/* It is resolved if it is resolved or never needed to be resolved */ 
    157165#define NOIT_CHECK_RESOLVED(a) (((a)->flags & NP_RESOLVED) || (((a)->flags & NP_RESOLVE) == 0)) 
     166#define NOIT_CHECK_PREFER_V6(a) ((a)->flags & NP_PREFER_IPV6) 
     167#define NOIT_CHECK_SINGLE_RESOLVE(a) ((a)->flags & NP_SINGLE_RESOLVE) 
    158168 
    159169API_EXPORT(void) noit_poller_init(); 
     
    245255API_EXPORT(const char *) 
    246256  noit_check_state_string(int16_t state); 
     257API_EXPORT(int) 
     258  noit_calc_rtype_flag(char *resolve_rtype); 
    247259API_EXPORT(int) 
    248260  noit_stats_snprint_metric_value(char *b, int l, metric_t *m); 
  • src/noit_check_rest.c

    r09ecd28 r6033f87  
    197197  SHOW_ATTR(attr,node,module); 
    198198  SHOW_ATTR(attr,node,target); 
     199  SHOW_ATTR(attr,node,resolve_rtype); 
    199200  SHOW_ATTR(attr,node,period); 
    200201  SHOW_ATTR(attr,node,timeout); 
     
    283284          } 
    284285          target = 1; 
     286        } 
     287        else CHECK_N_SET(resolve_rtype) { 
     288          xmlChar *tmp; 
     289          noit_boolean invalid; 
     290          tmp = xmlNodeGetContent(an); 
     291          invalid = strcmp((char *)tmp, PREFER_IPV4) && 
     292                    strcmp((char *)tmp, PREFER_IPV6) && 
     293                    strcmp((char *)tmp, FORCE_IPV4) && 
     294                    strcmp((char *)tmp, FORCE_IPV6); 
     295          xmlFree(tmp); 
     296          if(invalid) { 
     297            *error = "invalid reslove_rtype"; 
     298            return 0; 
     299          } 
    285300        } 
    286301        else CHECK_N_SET(period) { 
     
    356371    ATTR2PROP(name); 
    357372    ATTR2PROP(target); 
     373    ATTR2PROP(resolve_rtype); 
    358374    ATTR2PROP(module); 
    359375    ATTR2PROP(period);