Skip to content

Commit 34e88d7

Browse files
committed
[#2736] Warn on additional and lifetime params
Updated the ARM: /doc/sphinx/arm/dhcp4-srv.rst /doc/sphinx/arm/dhcp6-srv.rst Added ChangeLog /src/lib/dhcpsrv/dhcpsrv_messages.* DHCPSRV_CLASS_WITH_ADDTIONAL_AND_LIFETIMES - new message /src/lib/dhcpsrv/parsers/client_class_def_parser.cc ClientClassDefParser::parse() - now emits WARN log /src/lib/dhcpsrv/tests/client_class_def_parser_unittest.cc TEST_F(ClientClassDefParserTest, addtionalWithLifetimes4) TEST_F(ClientClassDefParserTest, addtionalWithLifetimes6) - new tests
1 parent 9af00a7 commit 34e88d7

File tree

8 files changed

+193
-2
lines changed

8 files changed

+193
-2
lines changed

ChangeLog

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
2304. [func] tmark
2+
Both kea-dhcp4 and kea-dhcp6 will now emit a warning
3+
log message when classes are configured with both
4+
``only-in-additional-list`` true and parameter(s)
5+
that normally impact lease lifetimes (e.g. 'valid-
6+
lifetime', 'preferred-lifetime`).
7+
(Gitlab #2736)
8+
19
2303. [bug] tmark
210
Modified both kea-dhcp4 and kea-dhcp6 to avoid
311
generating DDNS update requests when leases are

doc/sphinx/arm/dhcp4-srv.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3483,6 +3483,12 @@ Since Kea version 2.7.4 additional classes configured without
34833483
a test expression are unconditionally added, i.e. they are considered
34843484
to always be evaluated to ``true``.
34853485

3486+
.. note::
3487+
Because additional evaluation occurs after lease assignment, parameters
3488+
that would otherwise impact lease life times (e.g. ``valid-lifetime``,
3489+
``offer-lifetime``) will have no effect when specified in a class that
3490+
also sets ``only-in-additional-list`` true.
3491+
34863492
.. note::
34873493

34883494
As of Kea version 2.7.4, ``only-if-required`` and ``require-client-classes``
@@ -8021,7 +8027,7 @@ The following standards are currently supported in Kea:
80218027
Client Configuration (CCC) Option*, `RFC 3594
80228028
<https://tools.ietf.org/html/rfc3594>`__: The Security Ticket Control
80238029
sub-option is supported.
8024-
8030+
80258031
- *Key Distribution Center (KDC) Server Address Sub-option for the
80268032
Dynamic Host Configuration Protocol (DHCP) CableLabs Client
80278033
Configuration (CCC) Option*, `RFC 3634

doc/sphinx/arm/dhcp6-srv.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3219,6 +3219,12 @@ Since Kea version 2.7.4 additional classes configured without
32193219
a test expression are unconditionally added, i.e. they are considered
32203220
to always be evaluated to ``true``.
32213221

3222+
.. note::
3223+
Because additional evaluation occurs after lease assignment, parameters
3224+
that would otherwise impact lease life times (e.g. ``valid-lifetime``,
3225+
``preferred-lifetime``) will have no effect when specified in a class that
3226+
also sets ``only-in-additional-list`` true.
3227+
32223228
.. note::
32233229

32243230
As of Kea version 2.7.4, ``only-if-required`` and ``require-client-classes``

src/lib/dhcpsrv/dhcpsrv_messages.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ extern const isc::log::MessageID DHCPSRV_CFGMGR_UPDATE_SUBNET6 = "DHCPSRV_CFGMGR
4646
extern const isc::log::MessageID DHCPSRV_CFGMGR_USE_ADDRESS = "DHCPSRV_CFGMGR_USE_ADDRESS";
4747
extern const isc::log::MessageID DHCPSRV_CFGMGR_USE_ALLOCATOR = "DHCPSRV_CFGMGR_USE_ALLOCATOR";
4848
extern const isc::log::MessageID DHCPSRV_CFGMGR_USE_UNICAST = "DHCPSRV_CFGMGR_USE_UNICAST";
49+
extern const isc::log::MessageID DHCPSRV_CLASS_WITH_ADDTIONAL_AND_LIFETIMES = "DHCPSRV_CLASS_WITH_ADDTIONAL_AND_LIFETIMES";
4950
extern const isc::log::MessageID DHCPSRV_CLOSE_DB = "DHCPSRV_CLOSE_DB";
5051
extern const isc::log::MessageID DHCPSRV_DDNS_TTL_PERCENT_TOO_SMALL = "DHCPSRV_DDNS_TTL_PERCENT_TOO_SMALL";
5152
extern const isc::log::MessageID DHCPSRV_DHCP4O6_RECEIVED_BAD_PACKET = "DHCPSRV_DHCP4O6_RECEIVED_BAD_PACKET";
@@ -215,6 +216,7 @@ const char* values[] = {
215216
"DHCPSRV_CFGMGR_USE_ADDRESS", "listening on address %1, on interface %2",
216217
"DHCPSRV_CFGMGR_USE_ALLOCATOR", "using the %1 allocator for %2 leases in subnet %3",
217218
"DHCPSRV_CFGMGR_USE_UNICAST", "listening on unicast address %1, on interface %2",
219+
"DHCPSRV_CLASS_WITH_ADDTIONAL_AND_LIFETIMES", "class: %1 has 'only-in-additional-list' true while specifying one or more lease life time values. Life time values will be ignored.",
218220
"DHCPSRV_CLOSE_DB", "closing currently open %1 database",
219221
"DHCPSRV_DDNS_TTL_PERCENT_TOO_SMALL", "ddns-ttl-percent %1 of lease lifetime %2 is too small, ignoring it",
220222
"DHCPSRV_DHCP4O6_RECEIVED_BAD_PACKET", "received bad DHCPv4o6 packet: %1",

src/lib/dhcpsrv/dhcpsrv_messages.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ extern const isc::log::MessageID DHCPSRV_CFGMGR_UPDATE_SUBNET6;
4747
extern const isc::log::MessageID DHCPSRV_CFGMGR_USE_ADDRESS;
4848
extern const isc::log::MessageID DHCPSRV_CFGMGR_USE_ALLOCATOR;
4949
extern const isc::log::MessageID DHCPSRV_CFGMGR_USE_UNICAST;
50+
extern const isc::log::MessageID DHCPSRV_CLASS_WITH_ADDTIONAL_AND_LIFETIMES;
5051
extern const isc::log::MessageID DHCPSRV_CLOSE_DB;
5152
extern const isc::log::MessageID DHCPSRV_DDNS_TTL_PERCENT_TOO_SMALL;
5253
extern const isc::log::MessageID DHCPSRV_DHCP4O6_RECEIVED_BAD_PACKET;

src/lib/dhcpsrv/dhcpsrv_messages.mes

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -957,3 +957,12 @@ included in the message.
957957
% DHCPSRV_UNKNOWN_DB unknown database type: %1
958958
The database access string specified a database type (given in the
959959
message) that is unknown to the software. This is a configuration error.
960+
961+
% DHCPSRV_CLASS_WITH_ADDTIONAL_AND_LIFETIMES class: %1 has 'only-in-additional-list' true while specifying one or more lease life time values. Life time values will be ignored.
962+
This warning is emitted whenever a class is configured with
963+
'only-in-addition-list' true as well as specifying one or
964+
more lease life time parameters (e.g. 'valid-lifetime',
965+
'preferred-lifetime', or 'offer-lifetime'). Additional list classes
966+
are evaluated after lease assignment, thus parameters that would otherwise
967+
impact lease life times will have no affect.
968+

src/lib/dhcpsrv/parsers/client_class_def_parser.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,14 @@ ClientClassDefParser::parse(ClientClassDictionaryPtr& class_dictionary,
292292
// depend_on_known is now allowed
293293
}
294294

295+
if (additional &&
296+
(!valid_lft.unspecified() ||
297+
!preferred_lft.unspecified() ||
298+
!offer_lft.unspecified())) {
299+
LOG_WARN(dhcpsrv_logger, DHCPSRV_CLASS_WITH_ADDTIONAL_AND_LIFETIMES)
300+
.arg(name);
301+
}
302+
295303
// Add the client class definition
296304
try {
297305
class_dictionary->addClass(name, match_expr, test, additional,

src/lib/dhcpsrv/tests/client_class_def_parser_unittest.cc

Lines changed: 152 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <asiolink/io_address.h>
1717
#include <eval/evaluate.h>
1818
#include <testutils/gtest_utils.h>
19+
#include <testutils/log_utils.h>
1920
#include <gtest/gtest.h>
2021
#include <sstream>
2122
#include <stdint.h>
@@ -28,6 +29,7 @@ using namespace isc::data;
2829
using namespace isc::dhcp;
2930
using namespace isc::asiolink;
3031
using namespace isc::util;
32+
using namespace isc::dhcp::test;
3133

3234
namespace {
3335

@@ -101,7 +103,8 @@ class ExpressionParserTest : public ::testing::Test {
101103
};
102104

103105
/// @brief Test fixture class for @c ClientClassDefParser.
104-
class ClientClassDefParserTest : public ::testing::Test {
106+
//class ClientClassDefParserTest : public ::testing::Test {
107+
class ClientClassDefParserTest : public LogContentTest {
105108
protected:
106109

107110
/// @brief Convenience method for parsing a configuration
@@ -2192,4 +2195,152 @@ TEST_F(ClientClassDefParserTest, deprecatedOnlyIfRequired) {
21922195
"'only-in-additional-list'. Use only the latter.");
21932196
}
21942197

2198+
// Verifies that the parser detects use of life time parameters
2199+
// in classes that also set `only-in-additinal-list' true.
2200+
TEST_F(ClientClassDefParserTest, addtionalWithLifetimes4) {
2201+
CfgMgr::instance().setFamily(AF_INET);
2202+
boost::scoped_ptr<ClientClassDef> cclass;
2203+
2204+
struct Scenario {
2205+
size_t line_no_;
2206+
std::string cfg_;
2207+
bool should_log_;
2208+
};
2209+
2210+
std::list<Scenario> scenarios = {
2211+
{
2212+
__LINE__,
2213+
R"({
2214+
"name": "boo",
2215+
"only-in-additional-list": true
2216+
})",
2217+
},{
2218+
__LINE__,
2219+
R"({
2220+
"name": "boo",
2221+
"only-in-additional-list": true,
2222+
"valid-lifetime": 100
2223+
})",
2224+
true
2225+
},{
2226+
__LINE__,
2227+
R"({
2228+
"name": "boo",
2229+
"only-in-additional-list": true,
2230+
"offer-lifetime": 100
2231+
})",
2232+
true
2233+
},{
2234+
__LINE__,
2235+
R"({
2236+
"name": "boo",
2237+
"only-in-additional-list": false,
2238+
"valid-lifetime": 100
2239+
})",
2240+
false
2241+
},{
2242+
__LINE__,
2243+
R"({
2244+
"name": "boo",
2245+
"only-in-additional-list": false,
2246+
"offer-lifetime": 100
2247+
})",
2248+
false
2249+
}
2250+
};
2251+
2252+
size_t exp_log_count = 0;
2253+
for (auto& scenario : scenarios) {
2254+
std::stringstream oss;
2255+
oss << "scenario at: " << scenario.line_no_;
2256+
SCOPED_TRACE(oss.str());
2257+
// Parse the class definition.
2258+
auto class_def = parseClientClassDef(scenario.cfg_, AF_INET);
2259+
ASSERT_TRUE(class_def);
2260+
2261+
// If we expect the warning log to be emitted the occurrences
2262+
// in the log file should bump by 1.
2263+
if (scenario.should_log_) {
2264+
// Veriy we emitted another instance of the log message.
2265+
++exp_log_count;
2266+
ASSERT_EQ(countFile("DHCPSRV_CLASS_WITH_ADDTIONAL_AND_LIFETIMES"),
2267+
exp_log_count);
2268+
}
2269+
}
2270+
}
2271+
2272+
// Verifies that the parser detects use of life time parameters
2273+
// in classes that also set `only-in-additinal-list' true.
2274+
TEST_F(ClientClassDefParserTest, addtionalWithLifetimes6) {
2275+
CfgMgr::instance().setFamily(AF_INET6);
2276+
boost::scoped_ptr<ClientClassDef> cclass;
2277+
2278+
struct Scenario {
2279+
size_t line_no_;
2280+
std::string cfg_;
2281+
bool should_log_;
2282+
};
2283+
2284+
std::list<Scenario> scenarios = {
2285+
{
2286+
__LINE__,
2287+
R"({
2288+
"name": "boo",
2289+
"only-in-additional-list": true
2290+
})",
2291+
},{
2292+
__LINE__,
2293+
R"({
2294+
"name": "boo",
2295+
"only-in-additional-list": true,
2296+
"valid-lifetime": 100
2297+
})",
2298+
true
2299+
},{
2300+
__LINE__,
2301+
R"({
2302+
"name": "boo",
2303+
"only-in-additional-list": true,
2304+
"preferred-lifetime": 100
2305+
})",
2306+
true
2307+
},{
2308+
__LINE__,
2309+
R"({
2310+
"name": "boo",
2311+
"only-in-additional-list": false,
2312+
"valid-lifetime": 100
2313+
})",
2314+
false
2315+
},{
2316+
__LINE__,
2317+
R"({
2318+
"name": "boo",
2319+
"only-in-additional-list": false,
2320+
"preferred-lifetime": 100
2321+
})",
2322+
false
2323+
}
2324+
};
2325+
2326+
size_t exp_log_count = 0;
2327+
for (auto& scenario : scenarios) {
2328+
std::stringstream oss;
2329+
oss << "scenario at: " << scenario.line_no_;
2330+
SCOPED_TRACE(oss.str());
2331+
// Parse the class definition.
2332+
auto class_def = parseClientClassDef(scenario.cfg_, AF_INET6);
2333+
ASSERT_TRUE(class_def);
2334+
2335+
// If we expect the warning log to be emitted the occurrences
2336+
// in the log file should bump by 1.
2337+
if (scenario.should_log_) {
2338+
// Veriy we emitted another instance of the log message.
2339+
++exp_log_count;
2340+
ASSERT_EQ(countFile("DHCPSRV_CLASS_WITH_ADDTIONAL_AND_LIFETIMES"),
2341+
exp_log_count);
2342+
}
2343+
}
2344+
}
2345+
21952346
} // end of anonymous namespace

0 commit comments

Comments
 (0)