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

[master] Merge branch 'trac3274' DHCP client classification

Conflicts:
	ChangeLog
	src/bin/dhcp4/dhcp4_srv.cc
	src/bin/dhcp4/tests/dhcp4_srv_unittest.cc
	src/bin/dhcp4/tests/dhcp4_test_utils.h
	src/lib/dhcpsrv/cfgmgr.cc
	src/lib/dhcpsrv/cfgmgr.h
parents 0715531b 1791d198
749. [func] tomek
b10-dhcp4, b10-dhcp6: Simple client classification has been
implemented. Incoming packets can be assigned to zero or more
client classes. It is possible to restrict subnet usage to a given
client class. User's Guide and Developer's Guide has been updated.
(Trac #3274, git 1791d19899b92a6ee411199f664bdfc690ec08b2)
748. [bug] marcin
b10-dhcp4 server picks a subnet, to assign address for a directly
connected client, using IP address of the interface on which the
......
......@@ -39,7 +39,7 @@
servers with development managed by Internet Systems Consortium (ISC).
It includes DNS libraries, modular components for controlling
authoritative and recursive DNS servers, and experimental DHCPv4
and DHCPv6 servers.
and DHCPv6 servers (codenamed Kea).
</para>
<para>
This is the reference guide for BIND 10 version &__VERSION__;.
......@@ -3536,7 +3536,9 @@ then change those defaults with config set Resolver/forward_addresses[0]/address
clients. Even though principles of both DHCPv4 and DHCPv6 are
somewhat similar, these are two radically different
protocols. BIND 10 offers two server implementations, one for DHCPv4
and one for DHCPv6.</para>
and one for DHCPv6. The DHCP part of the BIND 10 project is codenamed
Kea. The DHCPv4 component is colloquially referred to as Kea4 and its
DHCPv6 counterpart is called Kea6.</para>
<para>This chapter covers those parts of BIND 10 that are common to
both servers. DHCPv4-specific details are covered in <xref linkend="dhcp4"/>,
while those details specific to DHCPv6 are described in <xref linkend="dhcp6"/>
......@@ -3644,6 +3646,14 @@ $</screen>
<screen>
&gt; <userinput>config remove Init/components b10-dhcp4</userinput>
&gt; <userinput>config commit</userinput>
</screen>
</para>
<para>
Note that the server was only removed from the list, so BIND10 will not
restart it, but the server itself is still running. Hence it is usually
desired to stop it:
<screen>
&gt; <userinput>Dhcp4 shutdown</userinput>
</screen>
</para>
......@@ -3816,7 +3826,7 @@ Dhcp4/subnet4 [] list (default)
</section>
<section id="dhcp4-address-config">
<title>Configuration of Address Pools</title>
<title>Configuration of IPv4 Address Pools</title>
<para>
The essential role of DHCPv4 server is address assignment. The server
has to be configured with at least one subnet and one pool of dynamic
......@@ -4410,7 +4420,87 @@ Dhcp4/subnet4 [] list (default)
e.g. "123" - would then be assigned to the uint16 field in the "container" option.
</para>
</section>
</section>
<section id="dhcp4-client-classifier">
<title>Client Classification in DHCPv4</title>
<note>
<para>
DHCPv4 server has been extended to support limited client classification.
Although the current capability is modest, it is expected to be expanded
in the future. It is envisaged that the majority of client classification
extensions will be using hooks extensions.
</para>
</note>
<para>In certain cases it is useful to differentiate between different types
of clients and treat them differently. The process of doing classification
is conducted in two steps. The first step is to assess incoming packet and
assign it to zero or more classes. This classification is currently simple,
but is expected to grow in capability soon. Currently the server checks whether
incoming packet has vendor class identifier option (60). If it has, content
of that option is interpreted as a class. For example, modern cable modems
will send this option with value &quot;docsis3.0&quot; and as a result the
packet will belong to class &quot;docsis3.0&quot;.
</para>
<para>It is envisaged that the client classification will be used for changing
behavior of almost any part of the DHCP message processing, including assigning
leases from different pools, assigning different option (or different values of
the same options) etc. For now, there are only two mechanisms that are taking
advantage of client classification: specific processing for cable modems and
subnet selection.</para>
<para>
For clients that belong to the docsis3.0 class, the siaddr field is set to
the value of next-server (if specified in a subnet). If there is
boot-file-name option specified, its value is also set in the file field
in the DHCPv4 packet. For eRouter1.0 class, the siaddr is always set to
0.0.0.0. That capability is expected to be moved to external hook
library that will be dedicated to cable modems.
</para>
<para>
Kea can be instructed to limit access to given subnets based on class information.
This is particularly useful for cases where two types of devices share the
same link and are expected to be served from two different subnets. The
primary use case for such a scenario is cable networks. There are two
classes of devices: cable modem itself, which should be handled a lease
from subnet A and all other devices behind modems that should get a lease
from subnet B. That segregation is essential to prevent overly curious
users from playing with their cable modems. For details on how to set up
class restrictions on subnets, see <xref linkend="dhcp4-subnet-class"/>.
</para>
</section>
<section id="dhcp4-subnet-class">
<title>Limiting access to IPv4 subnet to certain classes</title>
<para>
In certain cases it beneficial to restrict access to certain subnets
only to clients that belong to a given subnet. For details on client
classes, see <xref linkend="dhcp4-client-classifier"/>. This is an
extension of a previous example from <xref linkend="dhcp4-address-config"/>.
Let's assume that the server is connected to a network segment that uses
the 192.0.2.0/24 prefix. The Administrator of that network has decided
that addresses from range 192.0.2.10 to 192.0.2.20 are going to be
managed by the Dhcp4 server. Only clients belonging to client class
docsis3.0 are allowed to use this subnet. Such a configuration can be
achieved in the following way:
<screen>
&gt; <userinput>config add Dhcp4/subnet4</userinput>
&gt; <userinput>config set Dhcp4/subnet4[0]/subnet "192.0.2.0/24"</userinput>
&gt; <userinput>config set Dhcp4/subnet4[0]/pool [ "192.0.2.10 - 192.0.2.20" ]</userinput>
&gt; <userinput>config set Dhcp4/subnet4[0]/client-class "docsis3.0"</userinput>
&gt; <userinput>config commit</userinput></screen>
</para>
<para>
Care should be taken with client classification as it is easy to prevent
clients that do not meet class criteria to be denied any service altogether.
</para>
</section>
</section> <!-- end of configuring DHCPv4 server section with many subsections -->
<section id="dhcp4-serverid">
<title>Server Identifier in DHCPv4</title>
<para>
......@@ -4428,6 +4518,7 @@ Dhcp4/subnet4 [] list (default)
</para>
</section>
<section id="dhcp4-next-server">
<title>Next server (siaddr)</title>
<para>In some cases, clients want to obtain configuration from the TFTP server.
......@@ -4528,6 +4619,8 @@ Dhcp4/subnet4 [] list (default)
<listitem>
<simpara><ulink url="http://tools.ietf.org/html/rfc3046">RFC 3046</ulink>:
Relay Agent Information option is supported.</simpara>
</listitem>
<listitem>
<simpara><ulink url="http://tools.ietf.org/html/rfc6842">RFC 6842</ulink>:
Server by default sends back client-id option. That capability may be
disabled. See <xref linkend="dhcp4-echo-client-id"/> for details.
......@@ -4622,13 +4715,21 @@ Dhcp4/renew-timer 1000 integer (default)
</para>
<para>
To remove <command>b10-dhcp6</command> from the set of running services,
the <command>b10-dhcp4</command> is removed from list of Init components:
the <command>b10-dhcp6</command> is removed from list of Init components:
<screen>
&gt; <userinput>config remove Init/components b10-dhcp6</userinput>
&gt; <userinput>config commit</userinput>
</screen>
</para>
<para>
Note that the server was only removed from the list, so BIND10 will not
restart it, but the server itself is still running. Hence it is usually
desired to stop it:
<screen>
&gt; <userinput>Dhcp6 shutdown</userinput>
</screen>
</para>
<para>
During start-up the server will detect available network interfaces
......@@ -4834,7 +4935,7 @@ Dhcp6/subnet6/ list
</para>
</section>
<section>
<section id="dhcp6-address-config">
<title>Subnet and Address Pool</title>
<para>
The essential role of a DHCPv6 server is address assignment. For this,
......@@ -5353,7 +5454,7 @@ should include options from the isc option space:
</section>
<section id="dhcp6-config-subnets">
<title>Subnet Selection</title>
<title>IPv6 Subnet Selection</title>
<para>
The DHCPv6 server may receive requests from local (connected to the
same subnet as the server) and remote (connecting via relays) clients.
......@@ -5441,6 +5542,76 @@ should include options from the isc option space:
</para>
</section>
<section id="dhcp6-client-classifier">
<title>Client Classification in DHCPv6</title>
<note>
<para>
DHCPv6 server has been extended to support limited client classification.
Although the current capability is modest, it is expected to be expanded
in the future. It is envisaged that the majority of client classification
extensions will be using hooks extensions.
</para>
</note>
<para>In certain cases it is useful to differentiate between different types
of clients and treat them differently. The process of doing classification
is conducted in two steps. The first step is to assess incoming packet and
assign it to zero or more classes. This classification is currently simple,
but is expected to grow in capability soon. Currently the server checks whether
incoming packet has vendor class option (16). If it has, content
of that option is interpreted as a class. For example, modern cable modems
will send this option with value &quot;docsis3.0&quot; and as a result the
packet will belong to class &quot;docsis3.0&quot;.
</para>
<para>It is envisaged that the client classification will be used for changing
behavior of almost any part of the DHCP engine processing, including assigning
leases from different pools, assigning different option (or different values of
the same options) etc. For now, there is only one mechanism that is taking
advantage of client classification: subnet selection.</para>
<para>
Kea can be instructed to limit access to given subnets based on class information.
This is particularly useful for cases where two types of devices share the
same link and are expected to be served from two different subnets. The
primary use case for such a scenario are cable networks. There are two
classes of devices: cable modem itself, which should be handled a lease
from subnet A and all other devices behind modems that should get a lease
from subnet B. That segregation is essential to prevent overly curious
users from playing with their cable modems. For details on how to set up
class restrictions on subnets, see <xref linkend="dhcp6-subnet-class"/>.
</para>
</section>
<section id="dhcp6-subnet-class">
<title>Limiting access to IPv6 subnet to certain classes</title>
<para>
In certain cases it beneficial to restrict access to certains subnets
only to clients that belong to a given subnet. For details on client
classes, see <xref linkend="dhcp6-client-classifier"/>. This is an
extension of a previous example from <xref linkend="dhcp6-address-config"/>.
Let's assume that the server is connected to a network segment that uses
the 2001:db8:1::/64 prefix. The Administrator of that network has
decided that addresses from range 2001:db8:1::1 to 2001:db8:1::ffff are
going to be managed by the Dhcp6 server. Only clients belonging to the
eRouter1.0 client class are allowed to use that pool. Such a
configuration can be achieved in the following way:
<screen>
&gt; <userinput>config add Dhcp6/subnet6</userinput>
&gt; <userinput>config set Dhcp6/subnet6[0]/subnet "2001:db8:1::/64"</userinput>
&gt; <userinput>config set Dhcp6/subnet6[0]/pool [ "2001:db8:1::0 - 2001:db8:1::ffff" ]</userinput>
&gt; <userinput>config set Dhcp6/subnet6[0]/client-class "eRouter1.0"</userinput>
&gt; <userinput>config commit</userinput></screen>
</para>
<para>
Care should be taken with client classification as it is easy to prevent
clients that do not meet class criteria to be denied any service altogether.
</para>
</section>
</section>
<section id="dhcp6-serverid">
......
// Copyright (C) 2012-2013 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2012-2014 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
......@@ -164,7 +164,7 @@ public:
/// @param ignored first parameter
/// stores global scope parameters, options, option defintions.
Subnet4ConfigParser(const std::string&)
:SubnetConfigParser("", globalContext()) {
:SubnetConfigParser("", globalContext(), IOAddress("0.0.0.0")) {
}
/// @brief Adds the created subnet to a server's configuration.
......@@ -178,6 +178,11 @@ public:
"Invalid cast in Subnet4ConfigParser::commit");
}
// Set relay information if it was parsed
if (relay_info_) {
sub4ptr->setRelayInfo(*relay_info_);
}
isc::dhcp::CfgMgr::instance().addSubnet4(sub4ptr);
}
}
......@@ -200,10 +205,13 @@ protected:
parser = new Uint32Parser(config_id, uint32_values_);
} else if ((config_id.compare("subnet") == 0) ||
(config_id.compare("interface") == 0) ||
(config_id.compare("client-class") == 0) ||
(config_id.compare("next-server") == 0)) {
parser = new StringParser(config_id, string_values_);
} else if (config_id.compare("pool") == 0) {
parser = new Pool4Parser(config_id, pools_);
} else if (config_id.compare("relay") == 0) {
parser = new RelayInfoParser(config_id, relay_info_, Option::V4);
} else if (config_id.compare("option-data") == 0) {
parser = new OptionDataListParser(config_id, options_,
global_context_,
......@@ -292,6 +300,14 @@ protected:
} catch (const DhcpConfigError&) {
// Don't care. next_server is optional. We can live without it
}
// Try setting up client class (if specified)
try {
string client_class = string_values_->getParam("client-class");
subnet4->allowClientClass(client_class);
} catch (const DhcpConfigError&) {
// That's ok if it fails. client-class is optional.
}
}
};
......
// Copyright (C) 2012-2013 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2012-2014 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
......@@ -185,6 +185,12 @@ library. See ticket #3275. The class specific behavior is:
Aforementioned modifications are conducted in @ref isc::dhcp::Dhcpv4Srv::classSpecificProcessing.
It is possible to define class restrictions in subnet, so a given subnet is only
accessible to clients that belong to a given class. That is implemented as isc::dhcp::Pkt4::classes_
being passed in isc::dhcp::Dhcpv4Srv::selectSubnet() to isc::dhcp::CfgMgr::getSubnet4().
Currently this capability is usable, but the number of scenarios it supports is
limited.
@section dhcpv4Other Other DHCPv4 topics
For hooks API support in DHCPv4, see @ref dhcpv4Hooks.
......
......@@ -250,6 +250,28 @@
}
},
{ "item_name": "client-class",
"item_type": "string",
"item_optional": false,
"item_default": "",
"item_description" : "Restricts access to this subnet to specified client class (if defined)"
},
{ "item_name": "relay",
"item_type": "map",
"item_optional": false,
"item_default": {},
"item_description" : "Structure holding relay information.",
"map_item_spec": [
{
"item_name": "ip-address",
"item_type": "string",
"item_optional": false,
"item_default": "0.0.0.0",
"item_description" : "IPv4 address of the relay (defaults to 0.0.0.0 if not specified)."
}
]
},
{ "item_name": "option-data",
"item_type": "list",
"item_optional": false,
......
......@@ -1414,7 +1414,8 @@ Dhcpv4Srv::selectSubnet(const Pkt4Ptr& question) const {
// to be malformed anyway and the message will be dropped by the higher
// level functions.
if (question->isRelayed()) {
subnet = CfgMgr::instance().getSubnet4(question->getGiaddr());
subnet = CfgMgr::instance().getSubnet4(question->getGiaddr(),
question->classes_);
// The message is not relayed so it is sent directly by a client. But
// the client may be renewing its lease and in such case it unicasts
......@@ -1424,14 +1425,16 @@ Dhcpv4Srv::selectSubnet(const Pkt4Ptr& question) const {
// we rely on the client's address to get the subnet.
} else if ((question->getLocalAddr() != bcast) &&
(question->getCiaddr() != notset)) {
subnet = CfgMgr::instance().getSubnet4(question->getCiaddr());
subnet = CfgMgr::instance().getSubnet4(question->getCiaddr(),
question->classes_);
// The message has been received from a directly connected client
// and this client appears to have no address. The IPv4 address
// assigned to the interface on which this message has been received,
// will be used to determine the subnet suitable for the client.
} else {
subnet = CfgMgr::instance().getSubnet4(question->getIface());
subnet = CfgMgr::instance().getSubnet4(question->getIface(),
question->classes_);
}
// Let's execute all callouts registered for subnet4_select
......
......@@ -24,6 +24,7 @@
#include <dhcp/option_custom.h>
#include <dhcp/option_int.h>
#include <dhcp/docsis3_option_defs.h>
#include <dhcp/classify.h>
#include <dhcpsrv/subnet.h>
#include <dhcpsrv/cfgmgr.h>
#include <hooks/hooks_manager.h>
......@@ -231,7 +232,8 @@ public:
getOptionFromSubnet(const IOAddress& subnet_address,
const uint16_t option_code,
const uint16_t expected_options_count = 1) {
Subnet4Ptr subnet = CfgMgr::instance().getSubnet4(subnet_address);
Subnet4Ptr subnet = CfgMgr::instance().getSubnet4(subnet_address,
classify_);
if (!subnet) {
/// @todo replace toText() with the use of operator <<.
ADD_FAILURE() << "A subnet for the specified address "
......@@ -454,9 +456,10 @@ public:
}
boost::scoped_ptr<Dhcpv4Srv> srv_; // DHCP4 server under test
int rcode_; // Return code from element parsing
ConstElementPtr comment_; // Reason for parse fail
boost::scoped_ptr<Dhcpv4Srv> srv_; ///< DHCP4 server under test
int rcode_; ///< Return code from element parsing
ConstElementPtr comment_; ///< Reason for parse fail
isc::dhcp::ClientClasses classify_; ///< used in client classification
};
// Goal of this test is a verification if a very simple config update
......@@ -531,7 +534,8 @@ TEST_F(Dhcp4ParserTest, subnetGlobalDefaults) {
// Now check if the configuration was indeed handled and we have
// expected pool configured.
Subnet4Ptr subnet = CfgMgr::instance().getSubnet4(IOAddress("192.0.2.200"));
Subnet4Ptr subnet = CfgMgr::instance().getSubnet4(IOAddress("192.0.2.200"),
classify_);
ASSERT_TRUE(subnet);
EXPECT_EQ(1000, subnet->getT1());
EXPECT_EQ(2000, subnet->getT2());
......@@ -749,7 +753,8 @@ TEST_F(Dhcp4ParserTest, nextServerGlobal) {
// Now check if the configuration was indeed handled and we have
// expected pool configured.
Subnet4Ptr subnet = CfgMgr::instance().getSubnet4(IOAddress("192.0.2.200"));
Subnet4Ptr subnet = CfgMgr::instance().getSubnet4(IOAddress("192.0.2.200"),
classify_);
ASSERT_TRUE(subnet);
EXPECT_EQ("1.2.3.4", subnet->getSiaddr().toText());
}
......@@ -778,7 +783,8 @@ TEST_F(Dhcp4ParserTest, nextServerSubnet) {
// Now check if the configuration was indeed handled and we have
// expected pool configured.
Subnet4Ptr subnet = CfgMgr::instance().getSubnet4(IOAddress("192.0.2.200"));
Subnet4Ptr subnet = CfgMgr::instance().getSubnet4(IOAddress("192.0.2.200"),
classify_);
ASSERT_TRUE(subnet);
EXPECT_EQ("1.2.3.4", subnet->getSiaddr().toText());
}
......@@ -865,7 +871,8 @@ TEST_F(Dhcp4ParserTest, nextServerOverride) {
// Now check if the configuration was indeed handled and we have
// expected pool configured.
Subnet4Ptr subnet = CfgMgr::instance().getSubnet4(IOAddress("192.0.2.200"));
Subnet4Ptr subnet = CfgMgr::instance().getSubnet4(IOAddress("192.0.2.200"),
classify_);
ASSERT_TRUE(subnet);
EXPECT_EQ("1.2.3.4", subnet->getSiaddr().toText());
}
......@@ -935,7 +942,8 @@ TEST_F(Dhcp4ParserTest, subnetLocal) {
// returned value should be 0 (configuration success)
checkResult(status, 0);
Subnet4Ptr subnet = CfgMgr::instance().getSubnet4(IOAddress("192.0.2.200"));
Subnet4Ptr subnet = CfgMgr::instance().getSubnet4(IOAddress("192.0.2.200"),
classify_);
ASSERT_TRUE(subnet);
EXPECT_EQ(1, subnet->getT1());
EXPECT_EQ(2, subnet->getT2());
......@@ -987,7 +995,8 @@ TEST_F(Dhcp4ParserTest, poolPrefixLen) {
// returned value must be 0 (configuration accepted)
checkResult(status, 0);
Subnet4Ptr subnet = CfgMgr::instance().getSubnet4(IOAddress("192.0.2.200"));
Subnet4Ptr subnet = CfgMgr::instance().getSubnet4(IOAddress("192.0.2.200"),
classify_);
ASSERT_TRUE(subnet);
EXPECT_EQ(1000, subnet->getT1());
EXPECT_EQ(2000, subnet->getT2());
......@@ -1556,7 +1565,8 @@ TEST_F(Dhcp4ParserTest, optionDataDefaults) {
comment_ = parseAnswer(rcode_, x);
ASSERT_EQ(0, rcode_);
Subnet4Ptr subnet = CfgMgr::instance().getSubnet4(IOAddress("192.0.2.200"));
Subnet4Ptr subnet = CfgMgr::instance().getSubnet4(IOAddress("192.0.2.200"),
classify_);
ASSERT_TRUE(subnet);
Subnet::OptionContainerPtr options = subnet->getOptionDescriptors("dhcp4");
ASSERT_EQ(2, options->size());
......@@ -1640,7 +1650,8 @@ TEST_F(Dhcp4ParserTest, optionDataTwoSpaces) {
checkResult(status, 0);
// Options should be now available for the subnet.
Subnet4Ptr subnet = CfgMgr::instance().getSubnet4(IOAddress("192.0.2.200"));
Subnet4Ptr subnet = CfgMgr::instance().getSubnet4(IOAddress("192.0.2.200"),
classify_);
ASSERT_TRUE(subnet);
// Try to get the option from the space dhcp4.
Subnet::OptionDescriptor desc1 = subnet->getOptionDescriptor("dhcp4", 56);
......@@ -1790,7 +1801,8 @@ TEST_F(Dhcp4ParserTest, optionDataEncapsulate) {
checkResult(status, 0);
// Get the subnet.
Subnet4Ptr subnet = CfgMgr::instance().getSubnet4(IOAddress("192.0.2.5"));
Subnet4Ptr subnet = CfgMgr::instance().getSubnet4(IOAddress("192.0.2.5"),
classify_);
ASSERT_TRUE(subnet);
// We should have one option available.
......@@ -1858,7 +1870,8 @@ TEST_F(Dhcp4ParserTest, optionDataInSingleSubnet) {
comment_ = parseAnswer(rcode_, x);
ASSERT_EQ(0, rcode_);
Subnet4Ptr subnet = CfgMgr::instance().getSubnet4(IOAddress("192.0.2.24"));
Subnet4Ptr subnet = CfgMgr::instance().getSubnet4(IOAddress("192.0.2.24"),
classify_);
ASSERT_TRUE(subnet);
Subnet::OptionContainerPtr options = subnet->getOptionDescriptors("dhcp4");
ASSERT_EQ(2, options->size());
......@@ -2010,7 +2023,8 @@ TEST_F(Dhcp4ParserTest, optionDataInMultipleSubnets) {
comment_ = parseAnswer(rcode_, x);
ASSERT_EQ(0, rcode_);
Subnet4Ptr subnet1 = CfgMgr::instance().getSubnet4(IOAddress("192.0.2.100"));
Subnet4Ptr subnet1 = CfgMgr::instance().getSubnet4(IOAddress("192.0.2.100"),
classify_);
ASSERT_TRUE(subnet1);
Subnet::OptionContainerPtr options1 = subnet1->getOptionDescriptors("dhcp4");
ASSERT_EQ(1, options1->size());
......@@ -2034,7 +2048,8 @@ TEST_F(Dhcp4ParserTest, optionDataInMultipleSubnets) {
testOption(*range1.first, 56, foo_expected, sizeof(foo_expected));
// Test another subnet in the same way.
Subnet4Ptr subnet2 = CfgMgr::instance().getSubnet4(IOAddress("192.0.3.102"));
Subnet4Ptr subnet2 = CfgMgr::instance().getSubnet4(IOAddress("192.0.3.102"),
classify_);
ASSERT_TRUE(subnet2);
Subnet::OptionContainerPtr options2 = subnet2->getOptionDescriptors("dhcp4");
ASSERT_EQ(1, options2->size());
......@@ -2113,7 +2128,8 @@ TEST_F(Dhcp4ParserTest, optionDataLowerCase) {
comment_ = parseAnswer(rcode_, x);
ASSERT_EQ(0, rcode_);
Subnet4Ptr subnet = CfgMgr::instance().getSubnet4(IOAddress("192.0.2.5"));
Subnet4Ptr subnet = CfgMgr::instance().getSubnet4(IOAddress("192.0.2.5"),
classify_);
ASSERT_TRUE(subnet);
Subnet::OptionContainerPtr options = subnet->getOptionDescriptors("dhcp4");
ASSERT_EQ(1, options->size());
......@@ -2157,7 +2173,8 @@ TEST_F(Dhcp4ParserTest, stdOptionData) {
comment_ = parseAnswer(rcode_, x);
ASSERT_EQ(0, rcode_);
Subnet4Ptr subnet = CfgMgr::instance().getSubnet4(IOAddress("192.0.2.5"));
Subnet4Ptr subnet = CfgMgr::instance().getSubnet4(IOAddress("192.0.2.5"),
classify_);
ASSERT_TRUE(subnet);
Subnet::OptionContainerPtr options =
subnet->getOptionDescriptors("dhcp4");
......@@ -2359,7 +2376,8 @@ TEST_F(Dhcp4ParserTest, stdOptionDataEncapsulate) {
checkResult(status, 0);
// Get the subnet.
Subnet4Ptr subnet = CfgMgr::instance().getSubnet4(IOAddress("192.0.2.5"));
Subnet4Ptr subnet = CfgMgr::instance().getSubnet4(IOAddress("192.0.2.5"),
classify_);
ASSERT_TRUE(subnet);
// We should have one option available.
......@@ -2441,7 +2459,8 @@ TEST_F(Dhcp4ParserTest, vendorOptionsHex) {
checkResult(status, 0);
// Options should be now available for the subnet.
Subnet4Ptr subnet = CfgMgr::instance().getSubnet4(IOAddress("192.0.2.5"));
Subnet4Ptr subnet = CfgMgr::instance().getSubnet4(IOAddress("192.0.2.5"),
classify_);
ASSERT_TRUE(subnet);
// Try to get the option from the vendor space 4491
......@@ -2500,7 +2519,8 @@ TEST_F(Dhcp4ParserTest, vendorOptionsCsv) {
checkResult(status, 0);
// Options should be now available for the subnet.
Subnet4Ptr subnet = CfgMgr::instance().getSubnet4(IOAddress("192.0.2.5"));
Subnet4Ptr subnet = CfgMgr::instance().getSubnet4(IOAddress("192.0.2.5"),
classify_);
ASSERT_TRUE(subnet);
// Try to get the option from the vendor space 4491
......@@ -2829,4 +2849,124 @@ TEST_F(Dhcp4ParserTest, invalidD2ClientConfig) {
ASSERT_FALSE(CfgMgr::instance().ddnsEnabled());
}
// This test checks if it is possible to specify relay information
TEST_F(Dhcp4ParserTest, subnetRelayInfo) {
ConstElementPtr status;
// A config with relay information.
string config = "{ \"interfaces\": [ \"*\" ],"
"\"rebind-timer\": 2000, "
"\"renew-timer\": 1000, "
"\"subnet4\": [ { "
" \"pool\": [ \"192.0.2.1 - 192.0.2.100\" ],"
" \"renew-timer\": 1, "
" \"rebind-timer\": 2, "
" \"valid-lifetime\": 4,"
" \"relay\": { "