From 4fa4c9a0e6b8a57513eb3f324732bbb54bc16836 Mon Sep 17 00:00:00 2001 From: Francis Dupont Date: Thu, 16 Mar 2017 17:25:58 +0100 Subject: [PATCH] [3389a] Rebased (but still many things to do) --- doc/examples/kea4/advanced.json | 6 +++++- doc/examples/kea6/advanced.json | 6 +++++- src/bin/dhcp4/dhcp4_lexer.ll | 9 ++++++++ src/bin/dhcp4/dhcp4_parser.yy | 8 +++++++ src/bin/dhcp6/dhcp6_lexer.ll | 9 ++++++++ src/bin/dhcp6/dhcp6_parser.yy | 21 ++++++++++++++++--- .../dhcpsrv/parsers/ifaces_config_parser.cc | 13 ++++++++++-- 7 files changed, 65 insertions(+), 7 deletions(-) diff --git a/doc/examples/kea4/advanced.json b/doc/examples/kea4/advanced.json index 1b0e87778a..8f972e57f1 100644 --- a/doc/examples/kea4/advanced.json +++ b/doc/examples/kea4/advanced.json @@ -29,7 +29,11 @@ // 'udp' is generally better if you have only relayed traffic. Kea // than opens up normal UDP socket and the kernel does all the // Ethernet/IP stack processing. - "dhcp-socket-type": "udp" + "dhcp-socket-type": "udp", + + // This makes interfaces to be re-detected at each (re-)configuration. + // By default it is true. + "re-detect": true }, // We need to specify the the database used to store leases. As of diff --git a/doc/examples/kea6/advanced.json b/doc/examples/kea6/advanced.json index 5468a1cad2..f5722a5387 100644 --- a/doc/examples/kea6/advanced.json +++ b/doc/examples/kea6/advanced.json @@ -16,7 +16,11 @@ { // Kea is told to listen on ethX network interface only. "interfaces-config": { - "interfaces": [ "ethX" ] + "interfaces": [ "ethX" ], + + // This makes interfaces to be re-detected at each (re-)configuration. + // By default it is true. + "re-detect": true }, // We need to specify the the database used to store leases. As of diff --git a/src/bin/dhcp4/dhcp4_lexer.ll b/src/bin/dhcp4/dhcp4_lexer.ll index a137108c6b..9fad1c58ef 100644 --- a/src/bin/dhcp4/dhcp4_lexer.ll +++ b/src/bin/dhcp4/dhcp4_lexer.ll @@ -226,6 +226,15 @@ ControlCharacterFill [^"\\]|\\{JSONEscapeSequence} } } +\"re-detect\" { + switch(driver.ctx_) { + case isc::dhcp::Parser4Context::INTERFACES_CONFIG: + return isc::dhcp::Dhcp4Parser::make_RE_DETECT(driver.loc_); + default: + return isc::dhcp::Dhcp4Parser::make_STRING("re-detect", driver.loc_); + } +} + \"lease-database\" { switch(driver.ctx_) { case isc::dhcp::Parser4Context::DHCP4: diff --git a/src/bin/dhcp4/dhcp4_parser.yy b/src/bin/dhcp4/dhcp4_parser.yy index e78331eaa3..0038032446 100644 --- a/src/bin/dhcp4/dhcp4_parser.yy +++ b/src/bin/dhcp4/dhcp4_parser.yy @@ -55,6 +55,7 @@ using namespace std; DHCP_SOCKET_TYPE "dhcp-socket-type" RAW "raw" UDP "udp" + RE_DETECT "re-detect" ECHO_CLIENT_ID "echo-client-id" MATCH_CLIENT_ID "match-client-id" @@ -456,6 +457,7 @@ interfaces_config_params: interfaces_config_param interfaces_config_param: interfaces_list | dhcp_socket_type + | re_detect ; sub_interfaces4: LCURLY_BRACKET { @@ -487,6 +489,12 @@ socket_type: RAW { $$ = ElementPtr(new StringElement("raw", ctx.loc2pos(@1))); } | UDP { $$ = ElementPtr(new StringElement("udp", ctx.loc2pos(@1))); } ; +re_detect: RE_DETECT COLON BOOLEAN { + ElementPtr b(new BoolElement($3, ctx.loc2pos(@3))); + ctx.stack_.back()->set("re-detect", b); +}; + + lease_database: LEASE_DATABASE { ElementPtr i(new MapElement(ctx.loc2pos(@1))); ctx.stack_.back()->set("lease-database", i); diff --git a/src/bin/dhcp6/dhcp6_lexer.ll b/src/bin/dhcp6/dhcp6_lexer.ll index 0677ae2189..76f340f754 100644 --- a/src/bin/dhcp6/dhcp6_lexer.ll +++ b/src/bin/dhcp6/dhcp6_lexer.ll @@ -416,6 +416,15 @@ ControlCharacterFill [^"\\]|\\{JSONEscapeSequence} } } +\"re-detect\" { + switch(driver.ctx_) { + case isc::dhcp::Parser6Context::INTERFACES_CONFIG: + return isc::dhcp::Dhcp6Parser::make_RE_DETECT(driver.loc_); + default: + return isc::dhcp::Dhcp6Parser::make_STRING("re-detect", driver.loc_); + } +} + \"lease-database\" { switch(driver.ctx_) { case isc::dhcp::Parser6Context::DHCP6: diff --git a/src/bin/dhcp6/dhcp6_parser.yy b/src/bin/dhcp6/dhcp6_parser.yy index 34cbda1a9d..d422bf3d8f 100644 --- a/src/bin/dhcp6/dhcp6_parser.yy +++ b/src/bin/dhcp6/dhcp6_parser.yy @@ -52,6 +52,7 @@ using namespace std; DHCP6 "Dhcp6" INTERFACES_CONFIG "interfaces-config" INTERFACES "interfaces" + RE_DETECT "re-detect" LEASE_DATABASE "lease-database" HOSTS_DATABASE "hosts-database" @@ -449,7 +450,7 @@ interfaces_config: INTERFACES_CONFIG { ctx.stack_.back()->set("interfaces-config", i); ctx.stack_.push_back(i); ctx.enter(ctx.INTERFACES_CONFIG); -} COLON LCURLY_BRACKET interface_config_map RCURLY_BRACKET { +} COLON LCURLY_BRACKET interfaces_config_params RCURLY_BRACKET { ctx.stack_.pop_back(); ctx.leave(); }; @@ -458,11 +459,19 @@ sub_interfaces6: LCURLY_BRACKET { // Parse the interfaces-config map ElementPtr m(new MapElement(ctx.loc2pos(@1))); ctx.stack_.push_back(m); -} interface_config_map RCURLY_BRACKET { +} interfaces_config_params RCURLY_BRACKET { // parsing completed }; -interface_config_map: INTERFACES { +interfaces_config_params: interfaces_config_param + | interfaces_config_params COMMA interfaces_config_param + ; + +interfaces_config_param: interfaces_list + | re_detect + ; + +interfaces_list: INTERFACES { ElementPtr l(new ListElement(ctx.loc2pos(@1))); ctx.stack_.back()->set("interfaces", l); ctx.stack_.push_back(l); @@ -472,6 +481,12 @@ interface_config_map: INTERFACES { ctx.leave(); }; +re_detect: RE_DETECT COLON BOOLEAN { + ElementPtr b(new BoolElement($3, ctx.loc2pos(@3))); + ctx.stack_.back()->set("re-detect", b); +}; + + lease_database: LEASE_DATABASE { ElementPtr i(new MapElement(ctx.loc2pos(@1))); ctx.stack_.back()->set("lease-database", i); diff --git a/src/lib/dhcpsrv/parsers/ifaces_config_parser.cc b/src/lib/dhcpsrv/parsers/ifaces_config_parser.cc index 3e5a4cb5c7..29fe7aabed 100644 --- a/src/lib/dhcpsrv/parsers/ifaces_config_parser.cc +++ b/src/lib/dhcpsrv/parsers/ifaces_config_parser.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2015,2017 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -20,7 +20,7 @@ namespace dhcp { void IfacesConfigParser::parseInterfacesList(const CfgIfacePtr& cfg_iface, - ConstElementPtr ifaces_list) { + ConstElementPtr ifaces_list) { BOOST_FOREACH(ConstElementPtr iface, ifaces_list->listValue()) { std::string iface_name = iface->stringValue(); try { @@ -45,6 +45,15 @@ IfacesConfigParser::parse(const CfgIfacePtr& cfg, bool socket_type_specified = false; BOOST_FOREACH(ConfigPair element, ifaces_config->mapValue()) { try { + // Check for re-detect before calling parseInterfacesList() + if (element.first == "re-detect") { + if (element.second->boolValue()) { + IfaceMgr::instance().clearIfaces(); + IfaceMgr::instance().detectIfaces(); + } + continue; + } + if (element.first == "interfaces") { parseInterfacesList(cfg, element.second); continue; -- 2.47.3