123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- // Copyright (C) 2015 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
- // copyright notice and this permission notice appear in all copies.
- //
- // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
- // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
- // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
- // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
- // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- // PERFORMANCE OF THIS SOFTWARE.
- #include <cc/data.h>
- #include <dhcpsrv/cfgmgr.h>
- #include <dhcpsrv/parsers/ifaces_config_parser.h>
- #include <boost/foreach.hpp>
- #include <string>
- #include <sys/types.h>
- using namespace isc::data;
- namespace isc {
- namespace dhcp {
- InterfaceListConfigParser::InterfaceListConfigParser(const int protocol)
- : protocol_(protocol) {
- }
- void
- InterfaceListConfigParser::build(ConstElementPtr value) {
- CfgIface cfg_iface;
- BOOST_FOREACH(ConstElementPtr iface, value->listValue()) {
- std::string iface_name = iface->stringValue();
- try {
- cfg_iface.use(protocol_, iface_name);
- } catch (const std::exception& ex) {
- isc_throw(DhcpConfigError, "Failed to select interface: "
- << ex.what() << " (" << value->getPosition() << ")");
- }
- }
- CfgMgr::instance().getStagingCfg()->setCfgIface(cfg_iface);
- }
- void
- InterfaceListConfigParser::commit() {
- // Nothing to do.
- }
- IfacesConfigParser::IfacesConfigParser(const int protocol)
- : protocol_(protocol) {
- }
- void
- IfacesConfigParser::build(isc::data::ConstElementPtr ifaces_config) {
- BOOST_FOREACH(ConfigPair element, ifaces_config->mapValue()) {
- try {
- if (element.first == "interfaces") {
- InterfaceListConfigParser parser(protocol_);
- parser.build(element.second);
- }
- } catch (const std::exception& ex) {
- // Append line number where the error occurred.
- isc_throw(DhcpConfigError, ex.what() << " ("
- << element.second->getPosition() << ")");
- }
- }
- }
- bool
- IfacesConfigParser::isGenericParameter(const std::string& parameter) const {
- // Currently, the "interfaces" is the only common parameter for
- // DHCPv4 and DHCPv6.
- return (parameter == "interfaces");
- }
- IfacesConfigParser4::IfacesConfigParser4()
- : IfacesConfigParser(AF_INET) {
- }
- void
- IfacesConfigParser4::build(isc::data::ConstElementPtr ifaces_config) {
- IfacesConfigParser::build(ifaces_config);
- BOOST_FOREACH(ConfigPair element, ifaces_config->mapValue()) {
- try {
- if (element.first == "socket-type") {
- /// @todo set socket-type
- } else if (!isGenericParameter(element.first)) {
- isc_throw(DhcpConfigError, "usupported parameter '"
- << element.first << "'");
- }
- } catch (const std::exception& ex) {
- // Append line number where the error occurred.
- isc_throw(DhcpConfigError, ex.what() << " ("
- << element.second->getPosition() << ")");
- }
- }
- }
- IfacesConfigParser6::IfacesConfigParser6()
- : IfacesConfigParser(AF_INET6) {
- }
- void
- IfacesConfigParser6::build(isc::data::ConstElementPtr ifaces_config) {
- IfacesConfigParser::build(ifaces_config);
- BOOST_FOREACH(ConfigPair element, ifaces_config->mapValue()) {
- try {
- if (!isGenericParameter(element.first)) {
- isc_throw(DhcpConfigError, "usupported parameter '"
- << element.first << "'");
- }
- } catch (const std::exception& ex) {
- // Append line number where the error occurred.
- isc_throw(DhcpConfigError, ex.what() << " ("
- << element.second->getPosition() << ")");
- }
- }
- }
- } // end of namespace isc::dhcp
- } // end of namespace isc
|