Commit bf773a09 authored by Tomek Mrugalski's avatar Tomek Mrugalski 🛰
Browse files

[3191] Subnet4 now stores siaddr

parent 5eede0e0
...@@ -144,13 +144,29 @@ Subnet4::Subnet4(const isc::asiolink::IOAddress& prefix, uint8_t length, ...@@ -144,13 +144,29 @@ Subnet4::Subnet4(const isc::asiolink::IOAddress& prefix, uint8_t length,
const Triplet<uint32_t>& t1, const Triplet<uint32_t>& t1,
const Triplet<uint32_t>& t2, const Triplet<uint32_t>& t2,
const Triplet<uint32_t>& valid_lifetime) const Triplet<uint32_t>& valid_lifetime)
:Subnet(prefix, length, t1, t2, valid_lifetime) { :Subnet(prefix, length, t1, t2, valid_lifetime),
siaddr_(IOAddress("0.0.0.0")) {
if (!prefix.isV4()) { if (!prefix.isV4()) {
isc_throw(BadValue, "Non IPv4 prefix " << prefix.toText() isc_throw(BadValue, "Non IPv4 prefix " << prefix.toText()
<< " specified in subnet4"); << " specified in subnet4");
} }
} }
void Subnet4::setSiaddr(const isc::asiolink::IOAddress& siaddr) {
if (!siaddr.isV4()) {
isc_throw(BadValue, "Can't set siaddr to non-IPv4 addr "
<< siaddr.toText());
}
siaddr_ = siaddr;
}
/// @brief returns siaddr for this subnet
/// @return siaddr value
isc::asiolink::IOAddress Subnet4::getSiaddr() const {
return (siaddr_);
}
const PoolCollection& Subnet::getPools(Lease::Type type) const { const PoolCollection& Subnet::getPools(Lease::Type type) const {
// check if the type is valid (and throw if it isn't) // check if the type is valid (and throw if it isn't)
checkType(type); checkType(type);
......
...@@ -466,6 +466,17 @@ public: ...@@ -466,6 +466,17 @@ public:
const Triplet<uint32_t>& t2, const Triplet<uint32_t>& t2,
const Triplet<uint32_t>& valid_lifetime); const Triplet<uint32_t>& valid_lifetime);
/// @brief sets siaddr for the Subnet4
///
/// Will be used for siaddr field (the next server) that typically is used
/// as TFTP server. If not specified, the default value of 0.0.0.0 is
/// used.
void setSiaddr(const isc::asiolink::IOAddress& siaddr);
/// @brief returns siaddr for this subnet
/// @return siaddr value
isc::asiolink::IOAddress getSiaddr() const;
protected: protected:
/// @brief Check if option is valid and can be added to a subnet. /// @brief Check if option is valid and can be added to a subnet.
...@@ -488,6 +499,9 @@ protected: ...@@ -488,6 +499,9 @@ protected:
/// @param type type to be checked /// @param type type to be checked
/// @throw BadValue if invalid value is used /// @throw BadValue if invalid value is used
virtual void checkType(Lease::Type type) const; virtual void checkType(Lease::Type type) const;
/// @brief siaddr value for this subnet
isc::asiolink::IOAddress siaddr_;
}; };
/// @brief A pointer to a Subnet4 object /// @brief A pointer to a Subnet4 object
......
...@@ -58,6 +58,24 @@ TEST(Subnet4Test, in_range) { ...@@ -58,6 +58,24 @@ TEST(Subnet4Test, in_range) {
EXPECT_FALSE(subnet.inRange(IOAddress("255.255.255.255"))); EXPECT_FALSE(subnet.inRange(IOAddress("255.255.255.255")));
} }
// Checks whether siaddr field is handle correctly
TEST(Subnet4Test, siaddr) {
Subnet4 subnet(IOAddress("192.0.2.1"), 24, 1000, 2000, 3000);
// Check if the default is 0.0.0.0
EXPECT_EQ("0.0.0.0", subnet.getSiaddr().toText());
// Check that we can set it up
EXPECT_NO_THROW(subnet.setSiaddr(IOAddress("1.2.3.4")));
// Check that we can get it back
EXPECT_EQ("1.2.3.4", subnet.getSiaddr().toText());
// Check that only v4 addresses are supported
EXPECT_THROW(subnet.setSiaddr(IOAddress("2001:db8::1")),
BadValue);
}
TEST(Subnet4Test, Pool4InSubnet4) { TEST(Subnet4Test, Pool4InSubnet4) {
Subnet4Ptr subnet(new Subnet4(IOAddress("192.1.2.0"), 24, 1, 2, 3)); Subnet4Ptr subnet(new Subnet4(IOAddress("192.1.2.0"), 24, 1, 2, 3));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment