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 /***************************************************************************** 00025 * 00026 * P_SplitDNSProcessor.h - Interface to DNS server selection 00027 * 00028 * 00029 ****************************************************************************/ 00030 00031 #ifndef _P_SPLIT_DNSProcessor_H_ 00032 #define _P_SPLIT_DNSProcessor_H_ 00033 00034 /* 00035 #include "P_DNS.h" 00036 #include "I_SplitDNS.h" 00037 #include "I_Lock.h" 00038 #include "ControlBase.h" 00039 #include "ControlMatcher.h" 00040 */ 00041 #include "ProxyConfig.h" 00042 00043 /* --------------------------- 00044 forward declarations ... 00045 --------------------------- */ 00046 void ink_split_dns_init(ModuleVersion version); 00047 00048 struct RequestData; 00049 00050 struct matcher_line; 00051 00052 class SplitDNSRecord; 00053 struct SplitDNSResult; 00054 00055 struct DNSServer; 00056 00057 enum DNSResultType 00058 { DNS_SRVR_UNDEFINED = 0, 00059 DNS_SRVR_SPECIFIED, 00060 DNS_SRVR_FAIL 00061 }; 00062 00063 typedef ControlMatcher<SplitDNSRecord, SplitDNSResult> DNS_table; 00064 00065 00066 /* -------------------------------------------------------------- 00067 ** struct SplitDNSResult 00068 -------------------------------------------------------------- */ 00069 struct SplitDNSResult 00070 { 00071 SplitDNSResult(); 00072 00073 /* ------------ 00074 public 00075 ------------ */ 00076 DNSResultType r; 00077 00078 DNSServer *get_dns_record(); 00079 int get_dns_srvr_count(); 00080 00081 /* ------------ 00082 private 00083 ------------ */ 00084 int m_line_number; 00085 00086 SplitDNSRecord *m_rec; 00087 bool m_wrap_around; 00088 }; 00089 00090 00091 /* -------------------------------------------------------------- 00092 ** struct SplitDNS 00093 -------------------------------------------------------------- */ 00094 struct SplitDNS:public ConfigInfo 00095 { 00096 SplitDNS(); 00097 ~SplitDNS(); 00098 00099 void *getDNSRecord(const char *hostname); 00100 void findServer(RequestData * rdata, SplitDNSResult * result); 00101 00102 00103 DNS_table *m_DNSSrvrTable; 00104 00105 int32_t m_SplitDNSlEnable; 00106 00107 /* ---------------------------- 00108 required by the alleged fast 00109 path 00110 ---------------------------- */ 00111 bool m_bEnableFastPath; 00112 void *m_pxLeafArray; 00113 int m_numEle; 00114 }; 00115 00116 00117 /* -------------------------------------------------------------- 00118 SplitDNSConfig::isSplitDNSEnabled() 00119 -------------------------------------------------------------- */ 00120 TS_INLINE bool SplitDNSConfig::isSplitDNSEnabled() 00121 { 00122 return (gsplit_dns_enabled ? true : false); 00123 } 00124 00125 00126 // 00127 // End API to outside world 00128 // 00129 00130 00131 /* -------------------------------------------------------------- 00132 ** class DNSRequestData 00133 00134 A record for an single server 00135 -------------------------------------------------------------- */ 00136 class DNSRequestData: public RequestData 00137 { 00138 public: 00139 00140 DNSRequestData(); 00141 00142 char *get_string(); 00143 00144 const char *get_host(); 00145 00146 sockaddr const* get_ip(); // unused required virtual method. 00147 sockaddr const* get_client_ip(); // unused required virtual method. 00148 00149 const char *m_pHost; 00150 }; 00151 00152 00153 /* -------------------------------------------------------------- 00154 DNSRequestData::get_string() 00155 -------------------------------------------------------------- */ 00156 TS_INLINE DNSRequestData::DNSRequestData() 00157 : m_pHost(0) 00158 { 00159 } 00160 00161 00162 /* -------------------------------------------------------------- 00163 DNSRequestData::get_string() 00164 -------------------------------------------------------------- */ 00165 TS_INLINE char * 00166 DNSRequestData::get_string() 00167 { 00168 return ats_strdup((char *) m_pHost); 00169 } 00170 00171 00172 /* -------------------------------------------------------------- 00173 DNSRequestData::get_host() 00174 -------------------------------------------------------------- */ 00175 TS_INLINE const char * 00176 DNSRequestData::get_host() 00177 { 00178 return m_pHost; 00179 } 00180 00181 00182 /* -------------------------------------------------------------- 00183 DNSRequestData::get_ip() 00184 -------------------------------------------------------------- */ 00185 TS_INLINE sockaddr const* DNSRequestData::get_ip() 00186 { 00187 return NULL; 00188 } 00189 00190 00191 /* -------------------------------------------------------------- 00192 DNSRequestData::get_client_ip() 00193 -------------------------------------------------------------- */ 00194 TS_INLINE sockaddr const* DNSRequestData::get_client_ip() 00195 { 00196 return NULL; 00197 } 00198 00199 /* -------------------------------------------------------------- 00200 * class SplitDNSRecord 00201 00202 A record for a configuration line in the splitdns.config file 00203 -------------------------------------------------------------- */ 00204 class SplitDNSRecord: public ControlBase 00205 { 00206 public: 00207 00208 SplitDNSRecord(); 00209 ~SplitDNSRecord(); 00210 00211 char *Init(matcher_line * line_info); 00212 00213 const char *ProcessDNSHosts(char *val); 00214 const char *ProcessDomainSrchList(char *val); 00215 const char *ProcessDefDomain(char *val); 00216 00217 void UpdateMatch(SplitDNSResult * result, RequestData * rdata); 00218 void Print(); 00219 00220 DNSServer m_servers; 00221 int m_dnsSrvr_cnt; 00222 int m_domain_srch_list; 00223 }; 00224 00225 00226 /* -------------------------------------------------------------- 00227 SplitDNSRecord::SplitDNSRecord() 00228 -------------------------------------------------------------- */ 00229 TS_INLINE SplitDNSRecord::SplitDNSRecord() 00230 : m_dnsSrvr_cnt(0), m_domain_srch_list(0) 00231 { } 00232 00233 00234 /* -------------------------------------------------------------- 00235 SplitDNSRecord::~SplitDNSRecord() 00236 -------------------------------------------------------------- */ 00237 TS_INLINE SplitDNSRecord::~SplitDNSRecord() 00238 { } 00239 00240 00241 /* ------------------ 00242 Helper Functions 00243 ------------------ */ 00244 00245 SplitDNSRecord *createDefaultServer(); 00246 void reloadDefaultParent(char *val); 00247 void reloadParentFile(); 00248 00249 #endif