Changeset 9761c2f27f1d8476cd82892ad939edc6df00ab20

Show
Ignore:
Timestamp:
01/07/11 15:55:57 (3 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1294415757 +0000
git-parent:

[ae6a9eb3d143c05a62c9a1bd8044e92029015036]

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

fixes #339

Files:

Legend:

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

    rae6a9eb r9761c2f  
    220220static int dns_interpolate_inaddr_arpa(char *buff, int len, const char *ip) { 
    221221  const char *b, *e; 
    222   char *o = buff; 
     222  char *o; 
     223  unsigned char dn[DNS_MAXDN]; 
    223224  int il; 
     225  struct { 
     226    struct in_addr addr; 
     227    struct in6_addr addr6; 
     228  } a; 
    224229  /* This function takes a dot delimited string as input and 
    225230   * reverses the parts split on dot. 
    226231   */ 
     232  if (dns_pton(AF_INET, ip, &a.addr) > 0) { 
     233    dns_a4todn(&a.addr, 0, dn, sizeof(dn)); 
     234    dns_dntop(dn,buff,len); 
     235    return strlen(buff); 
     236  } 
     237  else if (dns_pton(AF_INET6, ip, &a.addr6) > 0) { 
     238    dns_a6todn(&a.addr6, 0, dn, sizeof(dn)); 
     239    dns_dntop(dn,buff,len); 
     240    return strlen(buff); 
     241  } 
     242 
     243  o = buff; 
    227244  il = strlen(ip); 
    228245  if(len <= il) { 
     
    246263  assert((o - buff) == il); 
    247264  return o - buff; 
     265} 
     266static int dns_interpolate_reverse_ip(char *buff, int len, const char *ip) { 
     267#define IN4ADDRARPA_LEN 13 // strlen(".in-addr.arpa"); 
     268#define IN6ADDRARPA_LEN 9 // strlen(".ip6.arpa"); 
     269  dns_interpolate_inaddr_arpa(buff,len,ip); 
     270  if(len > IN4ADDRARPA_LEN && 
     271     !strcmp(buff+len-IN4ADDRARPA_LEN, ".in-addr.arpa")) 
     272    buff[len-IN4ADDRARPA_LEN] = '\0'; 
     273  else if((len > IN6ADDRARPA_LEN) && 
     274          !strcmp(buff+len-IN6ADDRARPA_LEN, ".ip6.arpa")) 
     275    buff[len-IN6ADDRARPA_LEN] = '\0'; 
     276  return strlen(buff); 
    248277} 
    249278 
     
    267296  noit_check_interpolate_register_oper_fn("inaddrarpa", 
    268297                                          dns_interpolate_inaddr_arpa); 
     298  noit_check_interpolate_register_oper_fn("reverseip", 
     299                                          dns_interpolate_reverse_ip); 
    269300 
    270301  if (dns_init(NULL, 0) < 0 || (pctx = dns_new(NULL)) == NULL) { 
     
    595626     *   nameserver to NULL 
    596627     *   rtype to PTR 
    597      *   query to %[:inaddrarpa:target].in-addr.arpa 
     628     *   query to %[:inaddrarpa:target] 
    598629     */ 
    599630    nameserver = NULL; 
    600631    rtype = "PTR"; 
    601     query = "%[:inaddrarpa:target].in-addr.arpa"; 
     632    query = "%[:inaddrarpa:target]"; 
    602633  } 
    603634  else { 
  • src/modules/dns.xml

    r1da40d5 r9761c2f  
    2222    <parameter name="query" 
    2323               required="required" 
    24                default="%[name]|%[:inaddrarpa:target].in-addr.arpa
     24               default="%[name]|%[:inaddrarpa:target]
    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> 
    2626    <parameter name="want_sort"