From: Andrei Pavel Date: Fri, 10 Dec 2021 18:15:47 +0000 (+0200) Subject: [#2236] add hwtype,hwaddr_source to v6 memfile X-Git-Tag: Kea-2.1.2~119 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d132beba0e6741d389f727e8871ecb976726ae60;p=thirdparty%2Fkea.git [#2236] add hwtype,hwaddr_source to v6 memfile --- diff --git a/src/lib/dhcpsrv/csv_lease_file6.cc b/src/lib/dhcpsrv/csv_lease_file6.cc index ca45af5281..b9dc91b770 100644 --- a/src/lib/dhcpsrv/csv_lease_file6.cc +++ b/src/lib/dhcpsrv/csv_lease_file6.cc @@ -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 +CSVLeaseFile6::readHWType(const CSVRow& row) { + size_t const index(getColumnIndex("hwtype")); + if (row.readAt(index).empty()) { + return std::nullopt; + } + return row.readAndConvertAt(index); +} + +std::optional +CSVLeaseFile6::readHWAddrSource(const CSVRow& row) { + size_t const index(getColumnIndex("hwaddr_source")); + if (row.readAt(index).empty()) { + return std::nullopt; + } + return row.readAndConvertAt(index); +} + } // end of namespace isc::dhcp } // end of namespace isc diff --git a/src/lib/dhcpsrv/csv_lease_file6.h b/src/lib/dhcpsrv/csv_lease_file6.h index 1dec282c58..0e0b6b2e6f 100644 --- a/src/lib/dhcpsrv/csv_lease_file6.h +++ b/src/lib/dhcpsrv/csv_lease_file6.h @@ -13,7 +13,10 @@ #include #include #include + #include + +#include #include 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 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 readHWAddrSource(const util::CSVRow& row); + //@} }; } // namespace isc::dhcp