Kea  1.9.9-git
dhcp_queue_control_parser.cc
Go to the documentation of this file.
1 // Copyright (C) 2015-2020 Internet Systems Consortium, Inc. ("ISC")
2 //
3 // This Source Code Form is subject to the terms of the Mozilla Public
4 // License, v. 2.0. If a copy of the MPL was not distributed with this
5 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 
7 #include <config.h>
8 #include <cc/data.h>
9 #include <dhcpsrv/cfgmgr.h>
10 #include <dhcpsrv/dhcpsrv_log.h>
13 #include <boost/foreach.hpp>
14 #include <string>
15 #include <sys/types.h>
16 
17 using namespace isc::data;
18 using namespace isc::util;
19 
20 namespace isc {
21 namespace dhcp {
22 
24 DHCPQueueControlParser::parse(const ConstElementPtr& control_elem) {
25  // All we really do here is verify that it is a map that
26  // contains at least queue-type. All other content depends
27  // on the packet queue implementation of that type.
28  if (control_elem->getType() != Element::map) {
29  isc_throw(DhcpConfigError, "dhcp-queue-control must be a map");
30  }
31 
32  // enable-queue is mandatory.
33  bool enable_queue = getBoolean(control_elem, "enable-queue");
34 
35  if (enable_queue) {
36  ConstElementPtr elem = control_elem->get("queue-type");
37  if (!elem) {
38  isc_throw(DhcpConfigError, "when queue is enabled, queue-type is required");
39  } else {
40  if (elem->getType() != Element::string) {
41  isc_throw(DhcpConfigError, "queue-type must be a string");
42  }
43  }
44  }
45 
46  // Return a copy of it.
47  ElementPtr result = data::copy(control_elem);
48 
49  // Currently not compatible with multi-threading.
50  if (MultiThreadingMgr::instance().getMode()) {
51  // Silently disable it.
52  result->set("enable-queue", Element::create(false));
53  }
54 
55  return (result);
56 }
57 
58 } // end of namespace isc::dhcp
59 } // end of namespace isc
boost::shared_ptr< Element > ElementPtr
Definition: data.h:20
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Definition: edns.h:19
ElementPtr copy(ConstElementPtr from, int level)
Copy the data up to a nesting level.
Definition: data.cc:1097
To be removed. Please use ConfigError instead.
boost::shared_ptr< const Element > ConstElementPtr
Definition: data.h:23
Defines the logger used by the top-level component of kea-dhcp-ddns.
static ElementPtr create(const Position &pos=ZERO_POSITION())
Definition: data.cc:222