• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

I_DNSProcessor.h

Go to the documentation of this file.
00001 /** @file
00002 
00003   A brief file description
00004 
00005   @section license License
00006 
00007   Licensed to the Apache Software Foundation (ASF) under one
00008   or more contributor license agreements.  See the NOTICE file
00009   distributed with this work for additional information
00010   regarding copyright ownership.  The ASF licenses this file
00011   to you under the Apache License, Version 2.0 (the
00012   "License"); you may not use this file except in compliance
00013   with the License.  You may obtain a copy of the License at
00014 
00015       http://www.apache.org/licenses/LICENSE-2.0
00016 
00017   Unless required by applicable law or agreed to in writing, software
00018   distributed under the License is distributed on an "AS IS" BASIS,
00019   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00020   See the License for the specific language governing permissions and
00021   limitations under the License.
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   All buffering required to handle a DNS receipt. For asynchronous DNS,
00039   only one HostEntBuf will exist in the system. For synchronous DNS,
00040   one will exist per call until the user deletes them.
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);  // preserve VFPT
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   // Public Interface
00069   //
00070 
00071   /// Options for host name resolution.
00072   struct Options {
00073     typedef Options self; ///< Self reference type.
00074 
00075     /// Query handler to use.
00076     /// Default: single threaded handler.
00077     DNSHandler* handler;
00078     /// Query timeout value.
00079     /// Default: @c DEFAULT_DNS_TIMEOUT (or as set in records.config)
00080     int timeout; ///< Timeout value for request.
00081     /// Host resolution style.
00082     /// Default: IPv4, IPv6 ( @c HOST_RES_IPV4 )
00083     HostResStyle host_res_style;
00084 
00085     /// Default constructor.
00086     Options();
00087 
00088     /// Set @a handler option.
00089     /// @return This object.
00090     self& setHandler(DNSHandler* handler);
00091 
00092     /// Set @a timeout option.
00093     /// @return This object.
00094     self& setTimeout(int timeout);
00095 
00096     /// Set host query @a style option.
00097     /// @return This object.
00098     self& setHostResStyle(HostResStyle style);
00099 
00100     /// Reset to default constructed values.
00101     /// @return This object.
00102     self& reset();
00103   };
00104 
00105   // DNS lookup
00106   //   calls: cont->handleEvent( DNS_EVENT_LOOKUP, HostEnt *ent) on success
00107   //          cont->handleEvent( DNS_EVENT_LOOKUP, NULL) on failure
00108   // NOTE: the HostEnt *block is freed when the function returns
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   // Processor API
00118   //
00119   /* currently dns system uses event threads
00120    * dont pass any value to the call */
00121   int start(int no_of_extra_dns_threads=0, size_t stacksize=DEFAULT_STACKSIZE);
00122 
00123   // Open/close a link to a 'named' (done in start())
00124   //
00125   void open(sockaddr const* ns = 0, int options = _res.options);
00126 
00127   DNSProcessor();
00128 
00129   // private:
00130   //
00131   EThread *thread;
00132   DNSHandler *handler;
00133   ts_imp_res_state l_res;
00134   IpEndpoint local_ipv6;
00135   IpEndpoint local_ipv4;
00136 
00137   /** Internal implementation for all getXbyY methods.
00138       For host resolution queries pass @c T_A for @a type. It will be adjusted
00139       as needed based on @a opt.host_res_style.
00140 
00141       For address resolution ( @a type is @c T_PTR ), @a x should be a
00142       @c sockaddr cast to  @c char @c const* .
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 // Global data
00152 //
00153 extern DNSProcessor dnsProcessor;
00154 
00155 //
00156 // Inline Functions
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

Generated by  doxygen 1.7.1