This is an automated email from the ASF dual-hosted git repository.

masaori pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new fea8566ac6 Add port in HostDBRecord (#12856)
fea8566ac6 is described below

commit fea8566ac6839ba856af10b9a7370c00a5dc1275
Author: Masaori Koshiba <[email protected]>
AuthorDate: Thu Feb 5 13:21:34 2026 +0900

    Add port in HostDBRecord (#12856)
    
    * Add port in HostDBRecord
    
    * Address comments from Copiot
    
    * Fix typo
---
 include/iocore/hostdb/HostDBProcessor.h | 20 +++++++++++++++++++-
 src/iocore/hostdb/HostDB.cc             |  7 ++++---
 src/iocore/hostdb/test_HostFile.cc      |  3 ++-
 src/mgmt/rpc/handlers/hostdb/HostDB.cc  |  8 +++++++-
 4 files changed, 32 insertions(+), 6 deletions(-)

diff --git a/include/iocore/hostdb/HostDBProcessor.h 
b/include/iocore/hostdb/HostDBProcessor.h
index fded833c50..df5a5519bd 100644
--- a/include/iocore/hostdb/HostDBProcessor.h
+++ b/include/iocore/hostdb/HostDBProcessor.h
@@ -25,6 +25,7 @@
 
 #include <chrono>
 #include <atomic>
+#include <cstdint>
 #include <utility>
 
 #include "tscore/HashFNV.h"
@@ -312,11 +313,13 @@ public:
    * @param query_name Name of the query for the record.
    * @param rr_count Number of info instances.
    * @param srv_name_size Storage for SRV names, if any.
+   * @param port Port Number, if any.
+   *
    * @return An instance sufficient to hold the specified data.
    *
    * The query name will stored and initialized, and the info instances 
initialized.
    */
-  static self_type *alloc(swoc::TextView query_name, unsigned rr_count, size_t 
srv_name_size = 0);
+  static self_type *alloc(swoc::TextView query_name, unsigned rr_count, size_t 
srv_name_size = 0, in_port_t port = 0);
 
   /// Type of data stored in this record.
   HostDBType record_type = HostDBType::UNSPEC;
@@ -390,6 +393,11 @@ public:
    */
   swoc::TextView name_view() const;
 
+  /**
+    @return Port Number
+   */
+  in_port_t port() const;
+
   /// Get the array of info instances.
   swoc::MemSpan<HostDBInfo> rr_info();
 
@@ -519,6 +527,10 @@ protected:
       unsigned failed_p : 1; ///< DNS error.
     } f;
   } flags{0};
+
+private:
+  /// Port Number if hash key includes it.
+  in_port_t _port = 0;
 };
 
 struct HostDBCache;
@@ -733,6 +745,12 @@ HostDBRecord::name_view() const
   return {this->name(), swoc::TextView::npos};
 }
 
+inline in_port_t
+HostDBRecord::port() const
+{
+  return _port;
+}
+
 inline ts_time
 HostDBRecord::expiry_time() const
 {
diff --git a/src/iocore/hostdb/HostDB.cc b/src/iocore/hostdb/HostDB.cc
index dbcf25d87c..f30246b8c7 100644
--- a/src/iocore/hostdb/HostDB.cc
+++ b/src/iocore/hostdb/HostDB.cc
@@ -434,7 +434,7 @@ probe_ip(HostDBHash const &hash)
     Dbg(dbg_ctl_hostdb, "DNS %.*s", int(hash.host_name.size()), 
hash.host_name.data());
     IpAddr tip;
     if (0 == tip.load(hash.host_name)) {
-      result            = 
HostDBRecord::Handle{HostDBRecord::alloc(hash.host_name, 1)};
+      result            = 
HostDBRecord::Handle{HostDBRecord::alloc(hash.host_name, 1, 0, hash.port)};
       result->af_family = tip.family();
       auto &info        = result->rr_info()[0];
       info.assign(tip);
@@ -919,7 +919,7 @@ HostDBContinuation::dnsEvent(int event, HostEnt *e)
 
     // In the event that the lookup failed (SOA response-- for example) we 
want to use hash.host_name, since it'll be ""
     TextView query_name = (failed || !hash.host_name.empty()) ? hash.host_name 
: TextView{e->ent.h_name, strlen(e->ent.h_name)};
-    HostDBRecord::Handle r{HostDBRecord::alloc(query_name, valid_records, 
failed ? 0 : e->srv_hosts.srv_hosts_length)};
+    HostDBRecord::Handle r{HostDBRecord::alloc(query_name, valid_records, 
failed ? 0 : e->srv_hosts.srv_hosts_length, hash.port)};
     r->key              = hash.hash.fold(); // always set the key
     r->af_family        = af;
     r->flags.f.failed_p = failed;
@@ -1542,7 +1542,7 @@ HostDBRecord::free()
 }
 
 HostDBRecord *
-HostDBRecord::alloc(TextView query_name, unsigned int rr_count, size_t 
srv_name_size)
+HostDBRecord::alloc(TextView query_name, unsigned int rr_count, size_t 
srv_name_size, in_port_t port)
 {
   const swoc::Scalar<8, ssize_t> qn_size = round_up(query_name.size() + 1);
   const swoc::Scalar<8, ssize_t> r_size  = round_up(sizeof(self_type) + 
qn_size + rr_count * sizeof(HostDBInfo) + srv_name_size);
@@ -1554,6 +1554,7 @@ HostDBRecord::alloc(TextView query_name, unsigned int 
rr_count, size_t srv_name_
   new (self) self_type();
   self->_iobuffer_index = iobuffer_index;
   self->_record_size    = r_size;
+  self->_port           = port;
 
   Dbg(dbg_ctl_hostdb, "allocating %ld bytes for %.*s with %d RR records at 
[%p]", r_size.value(), int(query_name.size()),
       query_name.data(), rr_count, self);
diff --git a/src/iocore/hostdb/test_HostFile.cc 
b/src/iocore/hostdb/test_HostFile.cc
index 9bbe5e70bc..1fa7140c24 100644
--- a/src/iocore/hostdb/test_HostFile.cc
+++ b/src/iocore/hostdb/test_HostFile.cc
@@ -168,7 +168,7 @@ HostDBHash::~HostDBHash() {}
 #include "swoc/Scalar.h"
 
 HostDBRecord *
-HostDBRecord::alloc(swoc::TextView query_name, unsigned int rr_count, size_t 
srv_name_size)
+HostDBRecord::alloc(swoc::TextView query_name, unsigned int rr_count, size_t 
srv_name_size, in_port_t port)
 {
   const swoc::Scalar<8, ssize_t> qn_size = swoc::round_up(query_name.size() + 
1);
   const swoc::Scalar<8, ssize_t> r_size =
@@ -179,6 +179,7 @@ HostDBRecord::alloc(swoc::TextView query_name, unsigned int 
rr_count, size_t srv
   new (self) self_type();
   self->_iobuffer_index = 0;
   self->_record_size    = r_size;
+  self->_port           = port;
 
   Dbg(dbg_ctl_hostdb, "allocating %ld bytes for %.*s with %d RR records at 
[%p]", r_size.value(), int(query_name.size()),
       query_name.data(), rr_count, self);
diff --git a/src/mgmt/rpc/handlers/hostdb/HostDB.cc 
b/src/mgmt/rpc/handlers/hostdb/HostDB.cc
index 1c720299a1..a279c8968b 100644
--- a/src/mgmt/rpc/handlers/hostdb/HostDB.cc
+++ b/src/mgmt/rpc/handlers/hostdb/HostDB.cc
@@ -87,6 +87,10 @@ template <> struct convert<HostDBCache> {
         partition.copy(partition_entries);
       }
 
+      if (partition_entries.empty()) {
+        continue;
+      }
+
       Node partition_node;
       partition_node["id"] = i;
 
@@ -116,10 +120,12 @@ template <> struct convert<HostDBRecord> {
   {
     Node metadata;
     metadata["name"]         = record.name();
+    metadata["port"]         = record.port();
     metadata["type"]         = str(record.record_type);
-    metadata["af_familiy"]   = str(record.af_family);
+    metadata["af_family"]    = str(record.af_family);
     metadata["failed"]       = record.is_failed();
     metadata["ip_timestamp"] = record.ip_timestamp.time_since_epoch().count();
+    metadata["hash_key"]     = record.key;
 
     Node node;
     node["metadata"] = metadata;

Reply via email to