Branch: Tag:

1999-07-25

1999-07-25 18:58:36 by Henrik Grubbström (Grubba) <grubba@grubba.org>

do_sync_query() now uses udp->wait(), so syncronous calls now time out.
Also added retransmission, and fallback DNS server support to the sync calls.

Rev: lib/modules/Protocols.pmod/DNS.pmod:1.33

208:   };       + #define RETRIES 12 + #define RETRY_DELAY 5 +    class client {    inherit protocol;   
364:    }       -  // Warning: NO TIMEOUT +     mapping do_sync_query(string s)    { -  object udp=Stdio.UDP(); +  object udp = Stdio.UDP();    udp->bind(0); -  udp->send(nameservers[0],53,s); +     mapping m; -  do { -  m=udp->read(); -  } while (m->port != 53 || -  m->ip != nameservers[0] || -  m->data[0..1]!=s[0..1]); +  int i; +  for (i=0; i < RETRIES; i++) { +  udp->send(nameservers[i % sizeof(nameservers)], 53, s); +  +  while (udp->wait(RETRY_DELAY)) { +  m = udp->read(); +  if ((m->port == 53) && +  (m->data[0..1] == s[0..1]) && +  (search(nameservers, m->ip) != -1)) { +  // Success.    return decode_res(m->data);    } -  +  } +  } +  // Failure. +  return 0; +  }       -  // Warning: NO TIMEOUT +     mixed *gethostbyname(string s)    {    mapping m;    if(sizeof(domains) && s[-1] != '.' && sizeof(s/".") < 3) { -  m=do_sync_query(mkquery(s, C_IN, T_A)); +  m = do_sync_query(mkquery(s, C_IN, T_A));    if(!m || !m->an || !sizeof(m->an))    foreach(domains, string domain)    { -  m=do_sync_query(mkquery(s+"."+domain, C_IN, T_A)); +  m = do_sync_query(mkquery(s+"."+domain, C_IN, T_A));    if(m && m->an && sizeof(m->an))    break;    }    } else { -  m=do_sync_query(mkquery(s, C_IN, T_A)); +  m = do_sync_query(mkquery(s, C_IN, T_A));    }    -  +  if (!m) { +  return ({ 0, ({}), ({}) }); +  } +     string *names=({});    string *ips=({});    foreach(m->an, mapping x)
423:    return reverse(arpa/".")[2..]*".";    }    -  // Warning: NO TIMEOUT +     mixed *gethostbyaddr(string s)    {    mapping m=do_sync_query(mkquery(arpa_from_ip(s), C_IN, T_PTR)); -  +  if (m) {    string *names=({});    string *ips=({}); -  +     foreach(m->an, mapping x)    {    if(x->ptr)    names+=({x->ptr});    if(x->name) -  +     {    ips+=({ip_from_arpa(x->name)});    }
444:    ips,    names,    }); +  } else { +  // Lookup failed. +  return({ 0, ({}), ({}) });    } -  +  }       string get_primary_mx(string host)    {
461:    } else {    m=do_sync_query(mkquery(host, C_IN, T_MX));    } +  if (!m) { +  return 0; +  }    int minpref=29372974;    string ret;    foreach(m->an, mapping m2)
475:    }   }    - #define RETRIES 12 - #define RETRY_DELAY 5 +    #define REMOVE_DELAY 120   #define GIVE_UP_DELAY (RETRIES * RETRY_DELAY + REMOVE_DELAY)*2