You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by cm...@apache.org on 2024/03/26 16:36:24 UTC
(trafficserver) 01/02: Fixes for SRV records handling in hostdb rewrite (#11180)
This is an automated email from the ASF dual-hosted git repository.
cmcfarlen pushed a commit to branch 10.0.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
commit b338d98f4c604e075d19cb0313cc2422a7e1291c
Author: Chris McFarlen <ch...@mcfarlen.us>
AuthorDate: Tue Mar 26 11:28:24 2024 -0500
Fixes for SRV records handling in hostdb rewrite (#11180)
* Fixes for SRV records handling in hostdb rewrite
* Add comment to clarify arguments to HostDBInfo::assign
---------
Co-authored-by: Chris McFarlen <cm...@apple.com>
(cherry picked from commit e2fb50b6aa5e45c366115245b8d79111eb5bdad5)
---
src/iocore/hostdb/HostDB.cc | 6 +++---
src/iocore/hostdb/HostDBInfo.cc | 15 ++++++++++++++-
src/proxy/http/HttpSM.cc | 2 +-
3 files changed, 18 insertions(+), 5 deletions(-)
diff --git a/src/iocore/hostdb/HostDB.cc b/src/iocore/hostdb/HostDB.cc
index 351dc70343..d78b4c7460 100644
--- a/src/iocore/hostdb/HostDB.cc
+++ b/src/iocore/hostdb/HostDB.cc
@@ -1017,7 +1017,7 @@ HostDBContinuation::dnsEvent(int event, HostEnt *e)
}
}
// Archetypical example - "%zd" doesn't work on FreeBSD, "%ld" doesn't work on Ubuntu, "%lld" doesn't work on Fedora.
- Dbg_bw(dbg_ctl_dns_srv, "inserted SRV RR record [{}] into HostDB with TTL: {} seconds", t->host, ttl);
+ Dbg_bw(dbg_ctl_dns_srv, "inserted SRV RR record [{}] into HostDB with TTL: {} seconds", item.srvname(), ttl);
}
} else { // Otherwise this is a regular dns response
unsigned idx = 0;
@@ -1761,7 +1761,7 @@ HostDBRecord::serve_stale_but_revalidate() const
HostDBInfo *
HostDBRecord::select_best_srv(char *target, InkRand *rand, ts_time now, ts_seconds fail_window)
{
- ink_assert(rr_count <= 0 || static_cast<unsigned int>(rr_count) > hostdb_round_robin_max_count);
+ ink_assert(rr_count <= 0 || static_cast<unsigned int>(rr_count) < hostdb_round_robin_max_count);
int i = 0;
int live_n = 0;
@@ -1796,7 +1796,7 @@ HostDBRecord::select_best_srv(char *target, InkRand *rand, ts_time now, ts_secon
}
if (result) {
- ink_strlcpy(target, this->name(), MAXDNAME);
+ ink_strlcpy(target, result->srvname(), MAXDNAME);
return result;
}
return nullptr;
diff --git a/src/iocore/hostdb/HostDBInfo.cc b/src/iocore/hostdb/HostDBInfo.cc
index 0b8bd5c492..1ad87fb9c2 100644
--- a/src/iocore/hostdb/HostDBInfo.cc
+++ b/src/iocore/hostdb/HostDBInfo.cc
@@ -65,6 +65,17 @@ HostDBInfo::assign(IpAddr const &addr) -> self_type &
return *this;
}
+/** Assign SRV record and name
+ *
+ * @param[in] srv Pointer to SRV from which to assign.
+ * @param[in] name Pointer to hostname for the record
+ *
+ * @note This function assumes that name is stored near to the this pointer of
+ * the assigned instance within a uint16_t worth of bytes. This invariant must
+ * be adhered to by the caller.
+ *
+ * @todo Refactor handling of SRV records
+ */
auto
HostDBInfo::assign(SRV const *srv, char const *name) -> self_type &
{
@@ -73,7 +84,9 @@ HostDBInfo::assign(SRV const *srv, char const *name) -> self_type &
data.srv.srv_priority = srv->priority;
data.srv.srv_port = srv->port;
data.srv.key = srv->key;
- data.srv.srv_offset = reinterpret_cast<char const *>(this) - name;
+ // Danger! This offset calculation assumes that name and this are with 16-bits of each
+ // other. This invariant must be upheld for every caller of this function.
+ data.srv.srv_offset = name - reinterpret_cast<char const *>(this);
return *this;
}
diff --git a/src/proxy/http/HttpSM.cc b/src/proxy/http/HttpSM.cc
index ede21bfde4..84a92ffd93 100644
--- a/src/proxy/http/HttpSM.cc
+++ b/src/proxy/http/HttpSM.cc
@@ -2309,7 +2309,7 @@ HttpSM::state_hostdb_lookup(int event, void *data)
pending_action = nullptr;
process_srv_info(static_cast<HostDBRecord *>(data));
- char const *host_name = t_state.dns_info.is_srv() ? t_state.dns_info.record->name() : t_state.dns_info.lookup_name;
+ char const *host_name = t_state.dns_info.is_srv() ? t_state.dns_info.srv_hostname : t_state.dns_info.lookup_name;
HostDBProcessor::Options opt;
opt.port = t_state.dns_info.is_srv() ? t_state.dns_info.srv_port : t_state.server_info.dst_addr.host_order_port();
opt.flags = (t_state.cache_info.directives.does_client_permit_dns_storing) ? HostDBProcessor::HOSTDB_DO_NOT_FORCE_DNS :