From: Francis Dupont Date: Wed, 25 Jan 2017 14:00:15 +0000 (+0100) Subject: [master] Finishing merge of trac5096 (migrate database config) X-Git-Tag: trac5119_base~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a959b5548b2511e2ec5b73a4c41fdbcd83cb38ea;p=thirdparty%2Fkea.git [master] Finishing merge of trac5096 (migrate database config) --- a959b5548b2511e2ec5b73a4c41fdbcd83cb38ea diff --cc src/bin/dhcp4/dhcp4_parser.yy index b00bc7f579,e94e63d7b9..3d62023423 --- a/src/bin/dhcp4/dhcp4_parser.yy +++ b/src/bin/dhcp4/dhcp4_parser.yy @@@ -122,19 -125,7 +127,13 @@@ using namespace std PARAMETERS "parameters" EXPIRED_LEASES_PROCESSING "expired-leases-processing" + RECLAIM_TIMER_WAIT_TIME "reclaim-timer-wait-time" + FLUSH_RECLAIMED_TIMER_WAIT_TIME "flush-reclaimed-timer-wait-time" + HOLD_RECLAIMED_TIME "hold-reclaimed-time" + MAX_RECLAIM_LEASES "max-reclaim-leases" + MAX_RECLAIM_TIME "max-reclaim-time" + UNWARNED_RECLAIM_CYCLES "unwarned-reclaim-cycles" - SERVER_ID "server-id" - IDENTIFIER "identifier" - HTYPE "htype" - TIME "time" - ENTERPRISE_ID "enterprise-id" - DHCP4O6_PORT "dhcp4o6-port" CONTROL_SOCKET "control-socket" @@@ -195,9 -184,7 +194,10 @@@ %token BOOLEAN "boolean" %type value +%type socket_type + %type db_type +%type ncr_protocol_value +%type replace_client_name_value %printer { yyoutput << $$; } <*>; diff --cc src/bin/dhcp4/json_config_parser.cc index 814df9aa4d,cd8c1767d6..c9178fc79f --- a/src/bin/dhcp4/json_config_parser.cc +++ b/src/bin/dhcp4/json_config_parser.cc @@@ -425,14 -426,13 +425,11 @@@ DhcpConfigParser* createGlobalDhcp4Conf } else if ((config_id.compare("next-server") == 0)) { parser = new StringParser(config_id, globalContext()->string_values_); - } else if (config_id.compare("lease-database") == 0) { - parser = new DbAccessParser(config_id, DbAccessParser::LEASE_DB); - } else if (config_id.compare("hosts-database") == 0) { - parser = new DbAccessParser(config_id, DbAccessParser::HOSTS_DB); - // hooks-libraries are now migrated to SimpleParser. - // lease-database and hosts-database have been converted to SimpleParser already. - } else if (config_id.compare("hooks-libraries") == 0) { - parser = new HooksLibrariesParser(config_id); -- } else if (config_id.compare("echo-client-id") == 0) { ++ // hooks-libraries are now migrated to SimpleParser. ++ // lease-database and hosts-database have been converted to SimpleParser already. ++ } else if (config_id.compare("echo-client-id") == 0) { parser = new BooleanParser(config_id, globalContext()->boolean_values_); - } else if (config_id.compare("dhcp-ddns") == 0) { - parser = new D2ClientConfigParser(config_id); + // dhcp-ddns has been converted to SimpleParser. } else if (config_id.compare("match-client-id") == 0) { parser = new BooleanParser(config_id, globalContext()->boolean_values_); // control-socket has been converted to SimpleParser already. @@@ -566,7 -568,8 +563,6 @@@ configureDhcp4Server(Dhcpv4Srv&, isc::d // Please do not change this order! ParserCollection independent_parsers; ParserPtr subnet_parser; - ParserPtr leases_parser; - ParserPtr iface_parser; - ParserPtr client_classes_parser; // Some of the parsers alter the state of the system in a way that can't // easily be undone. (Or alter it in a way such that undoing the change has @@@ -593,6 -596,6 +589,8 @@@ ConfigPair config_pair; try { ++ SrvConfigPtr srv_cfg = CfgMgr::instance().getStagingCfg(); ++ // This is a way to convert ConstElementPtr to ElementPtr. // We need a config that can be edited, because we will insert // default values and will insert derived values as well. @@@ -605,7 -608,7 +603,7 @@@ ConstElementPtr option_defs = mutable_cfg->get("option-def"); if (option_defs) { OptionDefListParser parser; -- CfgOptionDefPtr cfg_option_def = CfgMgr::instance().getStagingCfg()->getCfgOptionDef(); ++ CfgOptionDefPtr cfg_option_def = srv_cfg->getCfgOptionDef(); parser.parse(cfg_option_def, option_defs); } @@@ -613,12 -616,8 +611,11 @@@ const std::map& values_map = mutable_cfg->mapValue(); BOOST_FOREACH(config_pair, values_map) { - SrvConfigPtr srv_cfg = CfgMgr::instance().getStagingCfg(); - + // In principle we could have the following code structured as a series + // of long if else if clauses. That would give a marginal performance + // boost, but would make the code less readable. We had serious issues + // with the parser code debugability, so I decided to keep it as a + // series of independent ifs. - if (config_pair.first == "option-def") { // This is converted to SimpleParser and is handled already above. continue; @@@ -644,42 -642,18 +640,57 @@@ continue; } + if (config_pair.first == "interfaces-config") { + IfacesConfigParser parser(AF_INET); - CfgIfacePtr cfg_iface = CfgMgr::instance().getStagingCfg()->getCfgIface(); ++ CfgIfacePtr cfg_iface = srv_cfg->getCfgIface(); + parser.parse(cfg_iface, config_pair.second); + continue; + } + + if (config_pair.first == "expired-leases-processing") { + ExpirationConfigParser parser; + parser.parse(config_pair.second); + continue; + } + + if (config_pair.first == "hooks-libraries") { + hooks_parser.parse(config_pair.second); + hooks_parser.verifyLibraries(); + continue; + } + + // Legacy DhcpConfigParser stuff below + if (config_pair.first == "dhcp-ddns") { + // Apply defaults if not in short cut + if (!D2ClientConfigParser::isShortCutDisabled(config_pair.second)) { + D2ClientConfigParser::setAllDefaults(config_pair.second); + } + D2ClientConfigParser parser; + D2ClientConfigPtr cfg = parser.parse(config_pair.second); - CfgMgr::instance().getStagingCfg()->setD2ClientConfig(cfg); ++ srv_cfg->setD2ClientConfig(cfg); + continue; + } + + if (config_pair.first == "client-classes") { + ClientClassDefListParser parser; + ClientClassDictionaryPtr dictionary = + parser.parse(config_pair.second, AF_INET); - CfgMgr::instance().getStagingCfg()->setClientClassDictionary(dictionary); ++ srv_cfg->setClientClassDictionary(dictionary); ++ continue; ++ } ++ + // Please move at the end when migration will be finished. + if (config_pair.first == "lease-database") { + DbAccessParser parser(DbAccessParser::LEASE_DB); + CfgDbAccessPtr cfg_db_access = srv_cfg->getCfgDbAccess(); + parser.parse(cfg_db_access, config_pair.second); + continue; + } + + if (config_pair.first == "host-database") { + DbAccessParser parser(DbAccessParser::HOSTS_DB); + CfgDbAccessPtr cfg_db_access = srv_cfg->getCfgDbAccess(); + parser.parse(cfg_db_access, config_pair.second); continue; } @@@ -689,8 -663,19 +700,6 @@@ .arg(config_pair.first); if (config_pair.first == "subnet4") { subnet_parser = parser; - } else if (config_pair.first == "lease-database") { - leases_parser = parser; - } else if (config_pair.first == "interfaces-config") { - // The interface parser is independent from any other - // parser and can be run here before any other parsers. - iface_parser = parser; - parser->build(config_pair.second); - } else if (config_pair.first == "hooks-libraries") { - // Executing commit will alter currently-loaded hooks - // libraries. Check if the supplied libraries are valid, - // but defer the commit until everything else has committed. - hooks_parser = parser; - parser->build(config_pair.second); - } else if (config_pair.first == "client-classes") { - client_classes_parser = parser; } else { // Those parsers should be started before other // parsers so we can call build straight away. diff --cc src/bin/dhcp6/dhcp6_parser.yy index 98ee268dda,4536e41e93..fa13b1c60c --- a/src/bin/dhcp6/dhcp6_parser.yy +++ b/src/bin/dhcp6/dhcp6_parser.yy @@@ -197,9 -193,8 +202,10 @@@ using namespace std %token BOOLEAN "boolean" %type value + %type db_type %type duid_type +%type ncr_protocol_value +%type replace_client_name_value %printer { yyoutput << $$; } <*>; diff --cc src/bin/dhcp6/json_config_parser.cc index f3ed466e70,2a8994bc39..87a7ec35b6 --- a/src/bin/dhcp6/json_config_parser.cc +++ b/src/bin/dhcp6/json_config_parser.cc @@@ -702,16 -702,18 +702,13 @@@ DhcpConfigParser* createGlobal6DhcpConf } else if (config_id.compare("subnet6") == 0) { parser = new Subnets6ListConfigParser(config_id); // option-data and option-def are no longer needed here. They're now - // converted to SimpleParser and are handled in configureDhcp6Server - } else if (config_id.compare("version") == 0) { - parser = new StringParser(config_id, - globalContext()->string_values_); + // converted to SimpleParser and are handled in configureDhcp6Server. + // interfaces-config has been converted to SimpleParser. + // version was removed - it was a leftover from bindctrl. - } else if (config_id.compare("lease-database") == 0) { - parser = new DbAccessParser(config_id, DbAccessParser::LEASE_DB); - } else if (config_id.compare("hosts-database") == 0) { - parser = new DbAccessParser(config_id, DbAccessParser::HOSTS_DB); + // hooks-libraries is now converted to SimpleParser. + // lease-database and hosts-database have been converted to SimpleParser already. - } else if (config_id.compare("hooks-libraries") == 0) { - parser = new HooksLibrariesParser(config_id); - } else if (config_id.compare("dhcp-ddns") == 0) { - parser = new D2ClientConfigParser(config_id); // mac-source has been converted to SimpleParser. + // dhcp-ddns has been converted to SimpleParser } else if (config_id.compare("relay-supplied-options") == 0) { parser = new RSOOListConfigParser(config_id); // control-socket has been converted to SimpleParser. @@@ -835,7 -839,8 +832,6 @@@ configureDhcp6Server(Dhcpv6Srv&, isc::d // Please do not change this order! ParserCollection independent_parsers; ParserPtr subnet_parser; - ParserPtr leases_parser; - ParserPtr iface_parser; - ParserPtr client_classes_parser; // Some of the parsers alter state of the system that can't easily // be undone. (Or alter it in a way such that undoing the change @@@ -862,6 -867,6 +858,8 @@@ ConfigPair config_pair; try { ++ SrvConfigPtr srv_config = CfgMgr::instance().getStagingCfg(); ++ // This is a way to convert ConstElementPtr to ElementPtr. // We need a config that can be edited, because we will insert // default values and will insert derived values as well. @@@ -877,7 -882,7 +875,7 @@@ ConstElementPtr option_defs = mutable_cfg->get("option-def"); if (option_defs) { OptionDefListParser parser; -- CfgOptionDefPtr cfg_option_def = CfgMgr::instance().getStagingCfg()->getCfgOptionDef(); ++ CfgOptionDefPtr cfg_option_def = srv_config->getCfgOptionDef(); parser.parse(cfg_option_def, option_defs); } @@@ -927,41 -927,18 +924,56 @@@ continue; } + if (config_pair.first == "interfaces-config") { + IfacesConfigParser parser(AF_INET6); - CfgIfacePtr cfg_iface = CfgMgr::instance().getStagingCfg()->getCfgIface(); ++ CfgIfacePtr cfg_iface = srv_config->getCfgIface(); + parser.parse(cfg_iface, config_pair.second); + continue; + } + + if (config_pair.first == "expired-leases-processing") { + ExpirationConfigParser parser; + parser.parse(config_pair.second); + continue; + } + + if (config_pair.first == "hooks-libraries") { + hooks_parser.parse(config_pair.second); + hooks_parser.verifyLibraries(); + continue; + } + + if (config_pair.first == "dhcp-ddns") { + // Apply defaults if not in short cut + if (!D2ClientConfigParser::isShortCutDisabled(config_pair.second)) { + D2ClientConfigParser::setAllDefaults(config_pair.second); + } + D2ClientConfigParser parser; + D2ClientConfigPtr cfg = parser.parse(config_pair.second); - CfgMgr::instance().getStagingCfg()->setD2ClientConfig(cfg); ++ srv_config->setD2ClientConfig(cfg); + continue; + } + + if (config_pair.first =="client-classes") { + ClientClassDefListParser parser; + ClientClassDictionaryPtr dictionary = + parser.parse(config_pair.second, AF_INET6); - CfgMgr::instance().getStagingCfg()->setClientClassDictionary(dictionary); ++ srv_config->setClientClassDictionary(dictionary); ++ continue; ++ } ++ + // Please move at the end when migration will be finished. + if (config_pair.first == "lease-database") { + DbAccessParser parser(DbAccessParser::LEASE_DB); + CfgDbAccessPtr cfg_db_access = srv_config->getCfgDbAccess(); + parser.parse(cfg_db_access, config_pair.second); + continue; + } + + if (config_pair.first == "host-database") { + DbAccessParser parser(DbAccessParser::HOSTS_DB); + CfgDbAccessPtr cfg_db_access = srv_config->getCfgDbAccess(); + parser.parse(cfg_db_access, config_pair.second); continue; } @@@ -971,8 -948,20 +983,6 @@@ .arg(config_pair.first); if (config_pair.first == "subnet6") { subnet_parser = parser; - } else if (config_pair.first == "lease-database") { - leases_parser = parser; - } else if (config_pair.first == "hooks-libraries") { - // Executing the commit will alter currently loaded hooks - // libraries. Check if the supplied libraries are valid, - // but defer the commit until after everything else has - // committed. - hooks_parser = parser; - hooks_parser->build(config_pair.second); - } else if (config_pair.first == "interfaces-config") { - // The interface parser is independent from any other parser and - // can be run here before other parsers. - parser->build(config_pair.second); - iface_parser = parser; - } else if (config_pair.first == "client-classes") { - client_classes_parser = parser; } else { // Those parsers should be started before other // parsers so we can call build straight away.