This is an automated email from the ASF dual-hosted git repository. zwoop pushed a commit to branch 9.0.x in repository https://gitbox.apache.org/repos/asf/trafficserver.git
commit 3db80ca9085ad7c236291f07a441e1e6e2dfe6c2 Author: Masaori Koshiba <[email protected]> AuthorDate: Fri Nov 27 07:57:57 2020 +0900 Fix lookup split dns rule with fast path (#7320) (cherry picked from commit 4e2ac3b2be8b535ab89d0f5762b3201647e5efba) --- iocore/dns/P_SplitDNSProcessor.h | 8 +++++--- iocore/dns/SplitDNS.cc | 22 ++++++++++------------ 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/iocore/dns/P_SplitDNSProcessor.h b/iocore/dns/P_SplitDNSProcessor.h index 316e2eb..fa9a556 100644 --- a/iocore/dns/P_SplitDNSProcessor.h +++ b/iocore/dns/P_SplitDNSProcessor.h @@ -39,6 +39,8 @@ */ #include "ProxyConfig.h" +#include "tscore/HostLookup.h" + /* --------------------------- forward declarations ... --------------------------- */ @@ -95,9 +97,9 @@ struct SplitDNS : public ConfigInfo { required by the alleged fast path ---------------------------- */ - bool m_bEnableFastPath = false; - void *m_pxLeafArray = nullptr; - int m_numEle = 0; + bool m_bEnableFastPath = false; + HostLookup::LeafArray *m_pxLeafArray = nullptr; + int m_numEle = 0; }; /* -------------------------------------------------------------- diff --git a/iocore/dns/SplitDNS.cc b/iocore/dns/SplitDNS.cc index 08a0178..a6688dd 100644 --- a/iocore/dns/SplitDNS.cc +++ b/iocore/dns/SplitDNS.cc @@ -221,7 +221,7 @@ SplitDNS::findServer(RequestData *rdata, SplitDNSResult *result) /* --------------------------- the 'alleged' fast path ... --------------------------- */ - if (m_bEnableFastPath) { + if (m_bEnableFastPath && m_pxLeafArray) { SplitDNSRecord *data_ptr = nullptr; char *pHost = const_cast<char *>(rdata->get_host()); if (nullptr == pHost) { @@ -229,30 +229,28 @@ SplitDNS::findServer(RequestData *rdata, SplitDNSResult *result) return; } - int len = strlen(pHost); - HostLeaf *pxHL = static_cast<HostLeaf *>(m_pxLeafArray); - for (int i = 0; i < m_numEle; i++) { - if (nullptr == pxHL) { - break; - } + int len = strlen(pHost); + int n = std::min(static_cast<size_t>(m_numEle), m_pxLeafArray->size()); + for (int i = 0; i < n; i++) { + const HostLeaf &pxHL = m_pxLeafArray->at(i); - if (false == pxHL[i].isNot && static_cast<int>(pxHL[i].match.size()) > len) { + if (false == pxHL.isNot && static_cast<int>(pxHL.match.size()) > len) { continue; } - int idx = len - pxHL[i].match.size(); + int idx = len - pxHL.match.size(); char *pH = &pHost[idx]; - const char *pMatch = pxHL[i].match.data(); + const char *pMatch = pxHL.match.data(); char cNot = *pMatch; if ('!' == cNot) { pMatch++; } - int res = memcmp(pH, pMatch, pxHL[i].match.size()); + int res = memcmp(pH, pMatch, pxHL.match.size()); if ((0 != res && '!' == cNot) || (0 == res && '!' != cNot)) { - data_ptr = static_cast<SplitDNSRecord *>(pxHL[i].opaque_data); + data_ptr = static_cast<SplitDNSRecord *>(pxHL.opaque_data); data_ptr->UpdateMatch(result, rdata); break; }
