// Get the HW address. It should never be empty and the readHWAddr checks
// that.
HWAddr hwaddr = readHWAddr(row);
+ uint32_t state = readState(row);
+ if (hwaddr.hwaddr_.empty() && state != Lease::STATE_DECLINED) {
+ isc_throw(isc::BadValue, "A blank hardware address is only"
+ " valid for declined leases");
+ }
+
lease.reset(new Lease4(readAddress(row),
HWAddrPtr(new HWAddr(hwaddr)),
client_id_vec.empty() ? NULL : &client_id_vec[0],
readFqdnFwd(row),
readFqdnRev(row),
readHostname(row)));
- lease->state_ = readState(row);
+ lease->state_ = state;
} catch (std::exception& ex) {
// bump the read error count
HWAddr
CSVLeaseFile4::readHWAddr(const CSVRow& row) {
HWAddr hwaddr = HWAddr::fromText(row.readAt(getColumnIndex("hwaddr")));
- if (hwaddr.hwaddr_.empty()) {
- isc_throw(isc::BadValue, "hardware address in the lease file"
- " must not be empty");
- }
return (hwaddr);
}
"fqdn_fwd,fqdn_rev,hostname,state\n"
"192.0.2.1,06:07:08:09:0a:bc,,200,200,8,1,1,"
"host.example.com,0\n"
- "192.0.2.1,,a:11:01:04,200,200,8,1,1,host.example.com,1\n"
+ "192.0.2.1,,a:11:01:04,200,200,8,1,1,host.example.com,0\n"
"192.0.3.15,dd:de:ba:0d:1b:2e:3e:4f,0a:00:01:04,100,100,7,"
"0,0,,1\n");
}
EXPECT_EQ(Lease::STATE_DEFAULT, lease->state_);
}
- // Second lease is malformed - HW address is empty.
+ // Second lease is malformed - HW address is empty when state
+ // is not delcined.
{
SCOPED_TRACE("Second lease malformed");
EXPECT_FALSE(lf.next(lease));
"100,135,7,0,0,,1\n";
std::string c_1 = "192.0.2.3,,a:11:01:04,"
- "200,200,8,1,1,host.example.com,1\n";
+ "200,200,8,1,1,host.example.com,0\n";
// Create lease file with leases for 192.0.2.1, 192.0.3.15. The lease
// entry for the 192.0.2.3 is invalid (lacks HW address) and should
std::string a_2 = "192.0.2.1,06:07:08:09:0a:bc,,"
"200,500,8,1,1,host.example.com,1\n";
- std::string b_1 = "192.0.2.3,,a:11:01:04,200,200,8,1,1,host.example.com,1\n";
+ std::string b_1 = "192.0.2.3,,a:11:01:04,200,200,8,1,1,host.example.com,0\n";
std::string c_1 = "192.0.2.10,01:02:03:04:05:06,,200,300,8,1,1,,1\n";