]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#2236] add hwtype,hwaddr_source to v6 memfile
authorAndrei Pavel <andrei@isc.org>
Fri, 10 Dec 2021 18:15:47 +0000 (20:15 +0200)
committerAndrei Pavel <andrei@isc.org>
Sat, 8 Jan 2022 09:05:17 +0000 (11:05 +0200)
src/lib/dhcpsrv/csv_lease_file6.cc
src/lib/dhcpsrv/csv_lease_file6.h

index ca45af52811ad8dd8552de2c02ac97ba87143a10..b9dc91b7702ccb734bce723aab6d6826f5e2162f 100644 (file)
@@ -59,6 +59,8 @@ CSVLeaseFile6::append(const Lease6& lease) {
     if (lease.hwaddr_) {
         // We may not have hardware information
         row.writeAt(getColumnIndex("hwaddr"), lease.hwaddr_->toText(false));
+        row.writeAt(getColumnIndex("hwtype"), lease.hwaddr_->htype_);
+        row.writeAt(getColumnIndex("hwaddr_source"), lease.hwaddr_->source_);
     }
     row.writeAt(getColumnIndex("state"), lease.state_);
     // User context is optional.
@@ -148,8 +150,17 @@ CSVLeaseFile6::initColumns() {
     addColumn("fqdn_rev", "1.0");
     addColumn("hostname", "1.0");
     addColumn("hwaddr", "2.0");
-    addColumn("state", "3.0", "0");
+    addColumn("state", "3.0", "0" /* == STATE_DEFAULT */);
     addColumn("user_context", "3.1");
+
+    // Default not added, because it depends on hwaddr having value, but in
+    // effect, when hwaddr is present, it is "1" /* == HTYPE_ETHER */.
+    addColumn("hwtype", "4.0");
+
+    // Default not added, because it depends on hwaddr having value, but in
+    // effect, when hwaddr is present, it is "0" /* == HWADDR_SOURCE_UNKNOWN */.
+    addColumn("hwaddr_source", "4.0");
+
     // Any file with less than hostname is invalid
     setMinimumValidColumns("hostname");
 }
@@ -235,10 +246,14 @@ HWAddrPtr
 CSVLeaseFile6::readHWAddr(const CSVRow& row) {
 
     try {
-        const HWAddr& hwaddr = HWAddr::fromText(row.readAt(getColumnIndex("hwaddr")));
+        uint16_t const hwtype(readHWType(row).value_or(HTYPE_ETHER));
+        HWAddr hwaddr(
+            HWAddr::fromText(row.readAt(getColumnIndex("hwaddr")), hwtype));
         if (hwaddr.hwaddr_.empty()) {
             return (HWAddrPtr());
         }
+        hwaddr.source_ =
+            readHWAddrSource(row).value_or(HWAddr::HWADDR_SOURCE_UNKNOWN);
 
         /// @todo: HWAddr returns an object, not a pointer. Without HWAddr
         /// refactoring, at least one copy is unavoidable.
@@ -276,5 +291,23 @@ CSVLeaseFile6::readContext(const util::CSVRow& row) {
     return (ctx);
 }
 
+std::optional<uint16_t>
+CSVLeaseFile6::readHWType(const CSVRow& row) {
+    size_t const index(getColumnIndex("hwtype"));
+    if (row.readAt(index).empty()) {
+        return std::nullopt;
+    }
+    return row.readAndConvertAt<uint16_t>(index);
+}
+
+std::optional<uint32_t>
+CSVLeaseFile6::readHWAddrSource(const CSVRow& row) {
+    size_t const index(getColumnIndex("hwaddr_source"));
+    if (row.readAt(index).empty()) {
+        return std::nullopt;
+    }
+    return row.readAndConvertAt<uint32_t>(index);
+}
+
 } // end of namespace isc::dhcp
 } // end of namespace isc
index 1dec282c58b4696746562ef82166dee1497fb5b7..0e0b6b2e6f3e01af4873c631ebe1ba615926514a 100644 (file)
 #include <dhcpsrv/subnet.h>
 #include <dhcpsrv/lease_file_stats.h>
 #include <util/versioned_csv_file.h>
+
 #include <stdint.h>
+
+#include <optional>
 #include <string>
 
 namespace isc {
@@ -101,6 +104,8 @@ private:
     /// - hwaddr
     /// - state
     /// - user_context
+    /// - hwtype
+    /// - hwaddr_source
     void initColumns();
 
     ///
@@ -183,8 +188,23 @@ private:
     ///
     /// @param row CSV file row holding lease information.
     data::ConstElementPtr readContext(const util::CSVRow& row);
-    //@}
 
+    /// @brief Reads hardware address type from the CSV file row.
+    ///
+    /// @param row CSV file row holding lease information
+    ///
+    /// @return the integer value of the hardware address type that was read
+    /// or std::nullopt if the value is empty
+    std::optional<uint16_t> readHWType(const util::CSVRow& row);
+
+    /// @brief Reads hardware address source from the CSV file row.
+    ///
+    /// @param row CSV file row holding lease information
+    ///
+    /// @return the integer value of the hardware address source that was read
+    /// or std::nullopt if the value is empty
+    std::optional<uint32_t> readHWAddrSource(const util::CSVRow& row);
+    //@}
 };
 
 } // namespace isc::dhcp