]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#2038] add hwtype,hwaddr_source to v6 memfile
authorAndrei Pavel <andrei@isc.org>
Mon, 15 Nov 2021 15:49:33 +0000 (17:49 +0200)
committerAndrei Pavel <andrei@isc.org>
Mon, 15 Nov 2021 15:51:46 +0000 (17:51 +0200)
src/lib/dhcpsrv/csv_lease_file6.cc
src/lib/dhcpsrv/csv_lease_file6.h

index 1164043cc6ccaf3bea4b969ca488a7dba11c17f4..cee9647d4a8c42a7eda8cdcb6d3261b12933ad71 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,6 +150,8 @@ CSVLeaseFile6::initColumns() {
     addColumn("fqdn_rev", "1.0");
     addColumn("hostname", "1.0");
     addColumn("hwaddr", "2.0");
+    addColumn("hwtype", "4.0", "1" /* == HTYPE_ETHER */);
+    addColumn("hwaddr_source", "4.0", "0" /* == HWADDR_SOURCE_UNKNOWN */);
     addColumn("state", "3.0", "0");
     addColumn("user_context", "3.1");
     // Any file with less than hostname is invalid
@@ -235,11 +239,14 @@ HWAddrPtr
 CSVLeaseFile6::readHWAddr(const CSVRow& row) {
 
     try {
-        const HWAddr& hwaddr = HWAddr::fromText(row.readAt(getColumnIndex("hwaddr")));
+        uint16_t hwtype(readHWType(row));
+        HWAddr hwaddr(HWAddr::fromText(row.readAt(getColumnIndex("hwaddr")), hwtype));
         if (hwaddr.hwaddr_.empty()) {
             return (HWAddrPtr());
         }
 
+        hwaddr.source_ = readHWAddrSource(row);
+
         /// @todo: HWAddr returns an object, not a pointer. Without HWAddr
         /// refactoring, at least one copy is unavoidable.
 
@@ -256,6 +263,16 @@ CSVLeaseFile6::readHWAddr(const CSVRow& row) {
     }
 }
 
+uint16_t
+CSVLeaseFile6::readHWType(const CSVRow& row) {
+    return row.readAndConvertAt<uint16_t>(getColumnIndex("hwtype"));
+}
+
+uint32_t
+CSVLeaseFile6::readHWAddrSource(const CSVRow& row) {
+    return row.readAndConvertAt<uint32_t>(getColumnIndex("hwaddr_source"));
+}
+
 uint32_t
 CSVLeaseFile6::readState(const util::CSVRow& row) {
     uint32_t state = row.readAndConvertAt<uint32_t>(getColumnIndex("state"));
index 1dec282c58b4696746562ef82166dee1497fb5b7..b4b6e36581995ec82b203e2349bff88f95e7bbba 100644 (file)
@@ -99,6 +99,8 @@ private:
     /// - fqdn_rev
     /// - hostname
     /// - hwaddr
+    /// - hwtype
+    /// - hwaddr_source
     /// - state
     /// - user_context
     void initColumns();
@@ -174,6 +176,18 @@ private:
     /// @return pointer to the HWAddr structure that was read
     HWAddrPtr readHWAddr(const util::CSVRow& row);
 
+    /// @brief Reads hardware address type from the CSV file row.
+    ///
+    /// @param row CSV file row holding lease information.
+    /// @return pointer to the HWAddr structure that was read
+    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 pointer to the HWAddr structure that was read
+    uint32_t readHWAddrSource(const util::CSVRow& row);
+
     /// @brief Reads lease state from the CSV file row.
     ///
     /// @param row CSV file row holding lease information.