Changeset 212da6e4b6f6b0af9ea0a9ceba106f42a1ea04df

Show
Ignore:
Timestamp:
09/14/11 15:59:49 (3 years ago)
Author:
gdusbabek <gdusbabek@gmail.com>
git-committer:
gdusbabek <gdusbabek@gmail.com> 1316015989 -0500
git-parent:

[a33aa52dc08eb296a042f396243bde78cf840b99]

git-author:
gdusbabek <gdusbabek@gmail.com> 1315949729 -0500
Message:

apply resolve_rtype to check flags

Files:

Legend:

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

    rbb10f44 r212da6e  
    9696noit_check_t * 
    9797noit_fire_check(xmlNodePtr attr, xmlNodePtr config, const char **error) { 
    98   char *target = NULL, *name = NULL, *module = NULL, *filterset = NULL
     98  char *target = NULL, *name = NULL, *module = NULL, *filterset = NULL, *resolve_rtype = NULL
    9999  int timeout = 0; 
    100100  noit_module_t *m; 
     
    116116      timeout = atoi(timeout_str); 
    117117      free(timeout_str); 
    118     } 
     118    } else if(!strcmp((char *)a->name, "resolve_rtype"))  
     119      resolve_rtype = (char *)xmlNodeGetContent(a); 
    119120  } 
    120121  m = noit_module_lookup(module); 
     
    137138    goto error; 
    138139  } 
     140  int flags = NP_TRANSIENT; 
     141  flags |= strcmp(resolve_rtype, PREFER_IPV6) == 0 || strcmp(resolve_rtype, FORCE_IPV6) == 0 ? NP_PREFER_IPV6 : 0; 
     142  flags |= strcmp(resolve_rtype, FORCE_IPV4) == 0 || strcmp(resolve_rtype, FORCE_IPV6) == 0 ? NP_SINGLE_RESOLVE : 0; 
    139143  c = calloc(1, sizeof(*c)); 
    140144  noit_check_update(c, target, name, filterset, 
    141                     conf_hash, 0, timeout, NULL, NP_TRANSIENT); 
     145                    conf_hash, 0, timeout, NULL, flags); 
    142146  c->module = strdup(module); 
    143147  uuid_generate(c->checkid); 
     
    155159  if(module) xmlFree(module); 
    156160  if(filterset) xmlFree(filterset); 
     161  if (resolve_rtype) xmlFree(resolve_rtype); 
    157162  return c; 
    158163} 
  • src/noit_check.c

    rf207009 r212da6e  
    150150    char filterset[256] = ""; 
    151151    char oncheck[1024] = ""; 
     152    char resolve_rtype[16] = ""; 
    152153    int no_period = 0; 
    153154    int no_oncheck = 0; 
     
    183184    if(!INHERIT(stringbuf, filterset, filterset, sizeof(filterset))) 
    184185      filterset[0] = '\0'; 
     186     
     187    if (!INHERIT(stringbuf, resolve_rtype, resolve_rtype, sizeof(resolve_rtype))) 
     188      strlcpy(resolve_rtype, PREFER_IPV4, sizeof(resolve_rtype)); 
    185189 
    186190    if(!MYATTR(stringbuf, name, name, sizeof(name))) 
     
    217221    if(busted) flags |= (NP_UNCONFIG|NP_DISABLED); 
    218222    else if(disabled) flags |= NP_DISABLED; 
     223 
     224    flags |= strcmp(resolve_rtype, PREFER_IPV6) == 0 || strcmp(resolve_rtype, FORCE_IPV6) == 0 ? NP_PREFER_IPV6 : 0; 
     225    flags |= strcmp(resolve_rtype, FORCE_IPV4) == 0 || strcmp(resolve_rtype, FORCE_IPV6) == 0 ? NP_SINGLE_RESOLVE : 0; 
    219226 
    220227    if(noit_hash_retrieve(&polls, (char *)uuid, UUID_SIZE, 
     
    569576  } a; 
    570577 
    571  
    572   family = AF_INET; 
     578  family = NOIT_CHECK_PREFER_V6(new_check) ? AF_INET6 : AF_INET; 
    573579  rv = inet_pton(family, ip_str, &a); 
    574   if(rv != 1) { 
    575     family = AF_INET6
     580  if(rv != 1 && !NOIT_CHECK_SINGLE_RESOLVE(new_check)) { 
     581    family = family == AF_INET ? AF_INET6 : AF_INET
    576582    rv = inet_pton(family, ip_str, &a); 
    577583    if(rv != 1) { 
     
    624630  if(new_check->target) free(new_check->target); 
    625631  new_check->target = strdup(target); 
     632 
     633  // apply resolution flags to check. 
     634  if (flags & NP_PREFER_IPV6) 
     635    new_check->flags |= NP_PREFER_IPV6; 
     636  else 
     637    new_check->flags &= ~NP_PREFER_IPV6; 
     638  if (flags & NP_SINGLE_RESOLVE) 
     639    new_check->flags |= NP_SINGLE_RESOLVE; 
     640  else 
     641    new_check->flags &= ~NP_SINGLE_RESOLVE; 
    626642 
    627643  if(noit_check_set_ip(new_check, target)) { 
  • src/noit_check.h

    ra33aa52 r212da6e  
    7373#define NP_SUPPRESS_METRICS 0x00002000 
    7474 
    75 #define NP_PREFER_IP         0x00004000 
    76 #define NP_TRY_OTHER_RESOLVE 0x00008000 
    77  
    78 #define NP_PREFER_IPV4 "prefer-ipv4" 
    79 #define NP_PREFER_IPV6 "prefer-ipv6" 
    80 #define NP_FORCE_IPV4  "force-ipv4" 
    81 #define NP_FORCE_IPV6  "force-ipv6" 
     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" 
    8282 
    8383#define NP_UNKNOWN '0'             /* stats_t.{available,state} */ 
     
    164164/* It is resolved if it is resolved or never needed to be resolved */ 
    165165#define NOIT_CHECK_RESOLVED(a) (((a)->flags & NP_RESOLVED) || (((a)->flags & NP_RESOLVE) == 0)) 
    166 #define NOIT_CHECK_PREFER_V4(a) (((a)->flags & NP_PREFER_IP) == 0
    167 #define NOIT_CHECK_TRY_OTHER_RESOLVE(a) ((a)->flags & NP_TRY_OTHER_RESOLVE) 
     166#define NOIT_CHECK_PREFER_V6(a) (((a)->flags & NP_PREFER_IPV6) == NP_PREFER_IPV6
     167#define NOIT_CHECK_SINGLE_RESOLVE(a) (((a)->flags & NP_SINGLE_RESOLVE) == NP_SINGLE_RESOLVE) 
    168168 
    169169API_EXPORT(void) noit_poller_init(); 
  • src/noit_check_rest.c

    ra33aa52 r212da6e  
    289289          noit_boolean invalid; 
    290290          tmp = xmlNodeGetContent(an); 
    291           invalid = strcmp((char *)tmp, NP_PREFER_IPV4) && strcmp((char *)tmp, NP_PREFER_IPV6) && strcmp((char *)tmp, NP_FORCE_IPV4) && strcmp((char *)tmp, NP_FORCE_IPV6); 
     291          invalid = strcmp((char *)tmp, PREFER_IPV4) && strcmp((char *)tmp,PREFER_IPV6) && strcmp((char *)tmp, FORCE_IPV4) && strcmp((char *)tmp, FORCE_IPV6); 
    292292          xmlFree(tmp); 
    293293          if(invalid) {