"relay": {
"ip-address": "192.168.1.1"
}
+ },
+ {
+ // This subnet is divided in two pools for unknown and
+ // known (i.e. which have a reservation) clients.
+ "pools": [
+ {
+ "pool": "192.0.8.100 - 192.0.8.200",
+ "known-clients": "never"
+ },
+ {
+ "pool": "192.0.9.100 - 192.0.9.200",
+ "known-clients": "only"
+ }
+ ],
+ "subnet": "192.0.8.0/23",
+ "reservations": [
+ { "hw-address": "00:00:00:11:22:33" },
+ { "hw-address": "00:00:00:44:55:66" },
+ { "hw-address": "00:00:00:77:88:99" },
+ { "hw-address": "00:00:00:aa:bb:cc" }
+ ]
}
]
},
// and another is when there is a shared subnet scenario.
"relay": {
"ip-address": "3000::1"
- }
+ },
+ },
+ {
+ // This subnet is divided in two pools for unknown and
+ // known (i.e. which have a reservation) clients.
+ "pools": [
+ {
+ "pool": "2001:db8:8::/64",
+ "known-clients": "never"
+ },
+ {
+ "pool": "2001:db8:9::/64",
+ "known-clients": "only"
+ }
+ ],
+ "subnet": "2001:db8:8::/46",
+ "reservations": [
+ { "hw-address": "00:00:00:11:22:33" },
+ { "hw-address": "00:00:00:44:55:66" },
+ { "hw-address": "00:00:00:77:88:99" },
+ { "hw-address": "00:00:00:aa:bb:cc" }
+ ]
}
]
},
at the pool level, see <xref linkend="classification-pools"/>.
</para>
+ <para>
+ In a similar way a pool can be constrained to serve only known clients,
+ i.e. clients which have a reservation, using
+ <command>"known-clients": "only"</command>, or only unknown clients
+ with <command>"known-clients": "never"</command>. One can assign
+ addresses to registered clients without giving a different address per
+ reservations, for instance when there is not enough available addresses.
+ </para>
+
<para>
The process of doing classification is conducted in three steps. The first step
is to assess an incoming packet and assign it to zero or more classes. The
linkend="classification-pools"/>.
</para>
+ <para>
+ In a similar way a pool can be constrained to serve only known clients,
+ i.e. clients which have a reservation, using
+ <command>"known-clients": "only"</command>, or only unknown clients
+ with <command>"known-clients": "never"</command>. One can assign
+ prefixes to registered clients without giving a different prefix per
+ reservations, forinstance when there is not enough available prefixes.
+ </para>
+
<para>
The process of doing classification is conducted in three steps. The first step
is to assess an incoming packet and assign it to zero or more classes. The
pool->allowClientClass(cclass);
}
}
+
+ // Known-clients.
+ ConstElementPtr known_clients = pool_structure->get("known-clients");
+ if (known_clients) {
+ string kc = known_clients->stringValue();
+ if (kc == "only") {
+ pool->setKnownClients(Pool::SERVE_KNOWN);
+ } else if (kc == "never") {
+ pool->setKnownClients(Pool::SERVE_UNKNOWN);
+ } else
+ isc_throw(DhcpConfigError, "invalid known-clients value: " << kc
+ << " (" << known_clients->getPosition() << ")");
+ }
}
//****************************** Pool4Parser *************************
client_class_ = client_class;
}
+ ConstElementPtr known_clients = pd_pool_->get("known-clients");
+ if (known_clients) {
+ known_clients_ = known_clients;
+ }
+
// Check the pool parameters. It will throw an exception if any
// of the required parameters are invalid.
try {
pool_->setContext(user_context_);
}
-
if (client_class_) {
string cclass = client_class_->stringValue();
if (!cclass.empty()) {
}
}
+ if (known_clients_) {
+ string kc = known_clients_->stringValue();
+ if (kc == "only") {
+ pool_->setKnownClients(Pool::SERVE_KNOWN);
+ } else if (kc == "never") {
+ pool_->setKnownClients(Pool::SERVE_UNKNOWN);
+ } else
+ isc_throw(isc::dhcp::DhcpConfigError,
+ "invalid known-clients value: " << kc
+ << " (" << known_clients_->getPosition() << ")");
+ }
+
// Add the local pool to the external storage ptr.
pools->push_back(pool_);
}
isc::data::ConstElementPtr client_class_;
+ isc::data::ConstElementPtr known_clients_;
};
/// @brief Parser for a list of prefix delegation pools.
const isc::asiolink::IOAddress& last)
:id_(getNextID()), first_(first), last_(last), type_(type),
capacity_(0), cfg_option_(new CfgOption()), white_list_(),
+ known_clients_(SERVE_BOTH),
last_allocated_(first), last_allocated_valid_(false) {
}
map->set("client-class", Element::create(*cclasses.cbegin()));
}
+ // Set known-clients
+ KnownClients kc = getKnownClients();
+ if (kc != SERVE_BOTH) {
+ map->set("known-clients",
+ Element::create(kc == SERVE_KNOWN ? "only" : "never"));
+ }
+
return (map);
}
class Pool {
public:
+ /// @brief Value of known clients
+ typedef enum {
+ SERVE_BOTH = 0, ///< the pool serves both known and unknown clients
+ SERVE_KNOWN = 1, ///< the pool serves only known clients
+ SERVE_UNKNOWN = 2 ///< the pool never serves known clients
+ } KnownClients;
+
/// @note:
/// PoolType enum was removed. Please use Lease::Type instead
return (white_list_);
}
+ /// @brief Returns the value of known clients
+ KnownClients getKnownClients() const {
+ return (known_clients_);
+ }
+
+ /// @brief Sets the value of known clients
+ void setKnownClients(KnownClients known_clients) {
+ known_clients_ = known_clients;
+ }
+
/// @brief returns the last address that was tried from this pool
///
/// @return address/prefix that was last tried from this pool
/// @ref Network::white_list_
ClientClasses white_list_;
+ /// @brief Value of known clients
+ KnownClients known_clients_;
+
/// @brief Pointer to the user context (may be NULL)
data::ConstElementPtr user_context_;
} else if (!cclasses.empty()) {
pool_map->set("client-class", Element::create(*cclasses.cbegin()));
}
+ // Set known-clients
+ Pool::KnownClients kc = (*pool)->getKnownClients();
+ if (kc != Pool::SERVE_BOTH) {
+ pool_map->set("known-clients",
+ Element::create(kc == Pool::SERVE_KNOWN ?
+ "only" : "never"));
+ }
// Push on the pool list
pool_list->add(pool_map);
}
} else if (!cclasses.empty()) {
pool_map->set("client-class", Element::create(*cclasses.cbegin()));
}
+ // Set known-clients
+ Pool::KnownClients kc = pdpool->getKnownClients();
+ if (kc != Pool::SERVE_BOTH) {
+ pool_map->set("known-clients",
+ Element::create(kc == Pool::SERVE_KNOWN ?
+ "only" : "never"));
+ }
// Push on the pool list
pdpool_list->add(pool_map);
}
Pool4Ptr pool1(new Pool4(IOAddress("192.0.2.1"), IOAddress("192.0.2.10")));
Pool4Ptr pool2(new Pool4(IOAddress("192.0.2.64"), 26));
pool2->allowClientClass("bar");
+ pool2->setKnownClients(Pool::SERVE_KNOWN);
subnet->addPool(pool1);
subnet->addPool(pool2);
" },{\n"
" \"option-data\": [ ],\n"
" \"pool\": \"192.0.2.64/26\",\n"
- " \"client-class\": \"bar\"\n"
+ " \"client-class\": \"bar\",\n"
+ " \"known-clients\": \"only\"\n"
" }\n"
" ]\n"
"} ]\n";
IOAddress("2001:db8:1::199")));
Pool6Ptr pool2(new Pool6(Lease::TYPE_NA, IOAddress("2001:db8:1:1::"), 64));
pool2->allowClientClass("bar");
+ pool2->setKnownClients(Pool::SERVE_UNKNOWN);
subnet->addPool(pool1);
subnet->addPool(pool2);
" },{\n"
" \"pool\": \"2001:db8:1:1::/64\",\n"
" \"option-data\": [ ],\n"
- " \"client-class\": \"bar\"\n"
+ " \"client-class\": \"bar\",\n"
+ " \"known-clients\": \"never\"\n"
" }\n"
" ],\n"
" \"pd-pools\": [ ],\n"
Pool6Ptr pdpool2(new Pool6(IOAddress("2001:db8:3::"), 48, 56,
IOAddress("2001:db8:3::"), 64));
pdpool2->allowClientClass("bar");
+ pdpool2->setKnownClients(Pool::SERVE_KNOWN);
subnet->addPool(pdpool1);
subnet->addPool(pdpool2);
" \"excluded-prefix\": \"2001:db8:3::\",\n"
" \"excluded-prefix-len\": 64,\n"
" \"option-data\": [ ],\n"
- " \"client-class\": \"bar\"\n"
+ " \"client-class\": \"bar\",\n"
+ " \"known-clients\": \"only\"\n"
" }\n"
" ],\n"
" \"option-data\": [ ]\n"
EXPECT_TRUE(pool->clientSupported(bar_class));
}
+// This test checks that handling for known-clients is valid.
+TEST(Pool4Test, knownClients) {
+ // Create a pool.
+ Pool4Ptr pool(new Pool4(IOAddress("192.0.2.0"),
+ IOAddress("192.0.2.255")));
+
+ // This pool serves everybody by default.
+ EXPECT_EQ(Pool::SERVE_BOTH, pool->getKnownClients());
+
+ // Set it to only known clients.
+ pool->setKnownClients(Pool::SERVE_KNOWN);
+ EXPECT_EQ(Pool::SERVE_KNOWN,pool->getKnownClients());
+}
+
// This test checks that handling for last allocated address/prefix is valid.
TEST(Pool4Test, lastAllocated) {
// Create a pool.
TEST(Pool6Test, clientClasses) {
// Create a pool.
Pool6 pool(Lease::TYPE_NA, IOAddress("2001:db8::1"),
- IOAddress("2001:db8::2"));
+ IOAddress("2001:db8::2"));
// This client does not belong to any class.
isc::dhcp::ClientClasses no_class;
EXPECT_TRUE(pool.clientSupported(bar_class));
}
+// This test checks that handling for known-clients is valid.
+TEST(Pool6Test, knownClients) {
+ // Create a pool.
+ Pool6 pool(Lease::TYPE_NA, IOAddress("2001:db8::1"),
+ IOAddress("2001:db8::2"));
+
+ // This pool serves everybody by default.
+ EXPECT_EQ(Pool::SERVE_BOTH, pool.getKnownClients());
+
+ // Set it to only known clients.
+ pool.setKnownClients(Pool::SERVE_KNOWN);
+ EXPECT_EQ(Pool::SERVE_KNOWN,pool.getKnownClients());
+}
+
// This test checks that handling for last allocated address/prefix is valid.
TEST(Pool6Test, lastAllocated) {
// Create a pool.