Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 #ifndef _I_DNSProcessor_h_
00025 #define _I_DNSProcessor_h_
00026 
00027 #include "SRV.h"
00028 
00029 #define  MAX_DNS_PACKET_LEN         8192
00030 #define  DNS_MAX_ALIASES              35
00031 #define  DNS_MAX_ADDRS                35
00032 #define  DNS_HOSTBUF_SIZE           8192
00033 #define  DOMAIN_SERVICE_PORT          53
00034 #define  DEFAULT_DOMAIN_NAME_SERVER    0        // use the default server
00035 
00036 
00037 
00038 
00039 
00040 
00041 
00042 
00043 struct HostEnt : RefCountObj {
00044   struct hostent ent;
00045   uint32_t ttl;
00046   int packet_size;
00047   char buf[MAX_DNS_PACKET_LEN];
00048   u_char *host_aliases[DNS_MAX_ALIASES];
00049   u_char *h_addr_ptrs[DNS_MAX_ADDRS + 1];
00050   u_char hostbuf[DNS_HOSTBUF_SIZE];
00051 
00052   SRVHosts srv_hosts;
00053 
00054   virtual void free();
00055 
00056   HostEnt() { 
00057     size_t base = sizeof(force_VFPT_to_top);  
00058     memset(((char*)this) + base, 0, sizeof(*this) - base); 
00059   }
00060 };
00061 
00062 extern EventType ET_DNS;
00063 
00064 struct DNSHandler;
00065 
00066 struct DNSProcessor: public Processor
00067 {
00068   
00069   
00070 
00071 
00072   struct Options {
00073     typedef Options self; 
00074 
00075 
00076 
00077     DNSHandler* handler;
00078 
00079 
00080     int timeout; 
00081 
00082 
00083     HostResStyle host_res_style;
00084 
00085 
00086     Options();
00087 
00088 
00089 
00090     self& setHandler(DNSHandler* handler);
00091 
00092 
00093 
00094     self& setTimeout(int timeout);
00095 
00096 
00097 
00098     self& setHostResStyle(HostResStyle style);
00099 
00100 
00101 
00102     self& reset();
00103   };
00104 
00105   
00106   
00107   
00108   
00109   
00110 
00111   Action *gethostbyname(Continuation *cont, const char *name, Options const& opt);
00112   Action *getSRVbyname(Continuation *cont, const char *name, Options const& opt);
00113   Action *gethostbyname(Continuation *cont, const char *name, int len, Options const& opt);
00114   Action *gethostbyaddr(Continuation *cont, IpAddr const* ip, Options const& opt);
00115 
00116 
00117   
00118   
00119   
00120 
00121   int start(int no_of_extra_dns_threads=0, size_t stacksize=DEFAULT_STACKSIZE);
00122 
00123   
00124   
00125   void open(sockaddr const* ns = 0, int options = _res.options);
00126 
00127   DNSProcessor();
00128 
00129   
00130   
00131   EThread *thread;
00132   DNSHandler *handler;
00133   ts_imp_res_state l_res;
00134   IpEndpoint local_ipv6;
00135   IpEndpoint local_ipv4;
00136 
00137 
00138 
00139 
00140 
00141 
00142 
00143 
00144   Action *getby(const char *x, int len, int type, Continuation *cont, Options const& opt);
00145 
00146   void dns_init();
00147 };
00148 
00149 
00150 
00151 
00152 
00153 extern DNSProcessor dnsProcessor;
00154 
00155 
00156 
00157 
00158 
00159 inline Action *
00160 DNSProcessor::getSRVbyname(Continuation *cont, const char *name, Options const& opt)
00161 {
00162   return getby(name, 0, T_SRV, cont, opt);
00163 }
00164 
00165 inline Action *
00166 DNSProcessor::gethostbyname(Continuation *cont, const char *name, Options const& opt)
00167 {
00168   return getby(name, 0, T_A, cont, opt);
00169 }
00170 
00171 inline Action *
00172 DNSProcessor::gethostbyname(Continuation *cont, const char *name, int len, Options const& opt)
00173 {
00174   return getby(name, len, T_A, cont, opt);
00175 }
00176 
00177 inline Action *
00178 DNSProcessor::gethostbyaddr(Continuation *cont, IpAddr const* addr, Options const& opt)
00179 {
00180   return getby(reinterpret_cast<char const*>(addr), 0, T_PTR, cont, opt);
00181 }
00182 
00183 inline DNSProcessor::Options::Options()
00184                     : handler(0)
00185                     , timeout(0)
00186                     , host_res_style(HOST_RES_IPV4)
00187 {
00188 }
00189 
00190 inline DNSProcessor::Options&
00191 DNSProcessor::Options::setHandler(DNSHandler* h)
00192 {
00193   handler = h;
00194   return *this;
00195 }
00196 
00197 inline DNSProcessor::Options&
00198 DNSProcessor::Options::setTimeout(int t)
00199 {
00200   timeout = t;
00201   return *this;
00202 }
00203 
00204 inline DNSProcessor::Options&
00205 DNSProcessor::Options::setHostResStyle(HostResStyle style)
00206 {
00207   host_res_style = style;
00208   return *this;
00209 }
00210 
00211 inline DNSProcessor::Options&
00212 DNSProcessor::Options::reset()
00213 {
00214   *this = Options();
00215   return *this;
00216 }
00217 
00218 void ink_dns_init(ModuleVersion version);
00219 
00220 #endif