Changeset 3476154bc836934aa71aaecb12a5a2443a6fc26d

Show
Ignore:
Timestamp:
08/09/12 16:34:25 (2 years ago)
Author:
Theo Schlossnagle <jesus@lethargy.org>
git-committer:
Theo Schlossnagle <jesus@lethargy.org> 1344530065 -0700
git-parent:

[a36e20f834b280d8a64b7271e670e7ccf3b39e90], [666f9c351646125cb4a68c692457e6fdf7432534]

git-author:
Theo Schlossnagle <jesus@lethargy.org> 1344530065 -0700
Message:

Merge pull request #100 from pamaddox/master

Updated to use target_ip in noit_check skiplist

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/noit_check.c

    r1eb8351 r666f9c3  
    114114  return 0; 
    115115} 
     116static int 
     117noit_check_add_to_list(noit_check_t *new_check) { 
     118  if(!(new_check->flags & NP_TRANSIENT)) { 
     119    /* This remove could fail -- no big deal */ 
     120    noit_skiplist_remove(&polls_by_name, new_check, NULL); 
     121 
     122    /* This insert could fail.. which means we have a conflict on 
     123     * target`name.  That should result in the check being disabled. */ 
     124    if(!noit_skiplist_insert(&polls_by_name, new_check)) { 
     125      noitL(noit_stderr, "Check %s`%s disabled due to naming conflict\n", 
     126            new_check->target, new_check->name); 
     127      new_check->flags |= NP_DISABLED; 
     128    } 
     129  } 
     130  return 1; 
     131} 
    116132 
    117133u_int64_t noit_check_completion_count() { 
     
    191207  if(ac->period < bc->period) return -1; 
    192208  if(ac->period == bc->period) return 0; 
     209  return 1; 
     210} 
     211static int __check_target_ip_compare(const void *a, const void *b) { 
     212  const noit_check_t *ac = a; 
     213  const noit_check_t *bc = b; 
     214  int rv; 
     215  if (ac->target_ip == NULL) return 1; 
     216  if (bc->target_ip == NULL) return -1; 
     217  if((rv = strcmp(ac->target_ip, bc->target_ip)) != 0) return rv; 
     218  if (ac->name == NULL) return 1; 
     219  if (bc->name == NULL) return -1; 
     220  if((rv = strcmp(ac->name, bc->name)) != 0) return rv; 
    193221  return 1; 
    194222} 
     
    525553  noit_skiplist_set_compare(&polls_by_name, __check_name_compare, 
    526554                            __check_name_compare); 
     555  noit_skiplist_add_index(&polls_by_name, __check_target_ip_compare, 
     556                            __check_target_ip_compare); 
    527557  noit_skiplist_init(&watchlist); 
    528558  noit_skiplist_set_compare(&watchlist, __watchlist_compare, 
     
    710740  int8_t family; 
    711741  int rv, failed = 0; 
     742  char old_target_ip[INET6_ADDRSTRLEN]; 
    712743  union { 
    713744    struct in_addr addr4; 
    714745    struct in6_addr addr6; 
    715746  } a; 
     747 
     748  memset(old_target_ip, 0, INET6_ADDRSTRLEN); 
     749  strlcpy(old_target_ip, new_check->target_ip, sizeof(old_target_ip)); 
    716750 
    717751  family = NOIT_CHECK_PREFER_V6(new_check) ? AF_INET6 : AF_INET; 
     
    741775      noitL(noit_error, "inet_ntop failed [%s] -> %d\n", ip_str, errno); 
    742776    } 
     777  if ((failed == 0) && (new_check->name != NULL) && (strcmp(old_target_ip, new_check->target_ip) != 0)) { 
     778    noit_check_add_to_list(new_check); 
     779  } 
    743780  return failed; 
    744781} 
     
    834871  new_check->flags = (new_check->flags & ~mask) | flags; 
    835872 
    836   if(!(new_check->flags & NP_TRANSIENT)) { 
    837     /* This remove could fail -- no big deal */ 
    838     noit_skiplist_remove(&polls_by_name, new_check, NULL); 
    839  
    840     /* This insert could fail.. which means we have a conflict on 
    841      * target`name.  That should result in the check being disabled. */ 
    842     if(!noit_skiplist_insert(&polls_by_name, new_check)) { 
    843       noitL(noit_stderr, "Check %s`%s disabled due to naming conflict\n", 
    844             new_check->target, new_check->name); 
    845       new_check->flags |= NP_DISABLED; 
    846     } 
    847   } 
     873  noit_check_add_to_list(new_check); 
    848874  noit_check_log_check(new_check); 
    849875  return 0; 
     
    10131039  int count = 0; 
    10141040  noit_check_t pivot; 
     1041  noit_skiplist *tlist; 
    10151042  noit_skiplist_node *next; 
     1043  noit_skiplist_node *sn; 
     1044 
     1045  sn = noit_skiplist_getlist(polls_by_name.index); 
     1046  tlist = sn->data; 
    10161047 
    10171048  memset(&pivot, 0, sizeof(pivot)); 
    1018   pivot.target = (char *)target
     1049  strlcpy(pivot.target_ip, (char*)target, sizeof(pivot.target_ip))
    10191050  pivot.name = ""; 
    1020   noit_skiplist_find_neighbors(&polls_by_name, &pivot, NULL, NULL, &next); 
     1051  pivot.target = ""; 
     1052  noit_skiplist_find_neighbors(tlist, &pivot, NULL, NULL, &next); 
    10211053  while(next && next->data) { 
    10221054    noit_check_t *check = next->data; 
    1023     if(strcmp(check->target, target)) break; 
     1055    if(strcmp(check->target_ip, target)) break; 
    10241056    count += f(check,closure); 
    10251057    noit_skiplist_next(&polls_by_name, &next);