Kea 3.1.1
host_data_parser.h
Go to the documentation of this file.
1// Copyright (C) 2017-2025 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#ifndef HOST_DATA_PARSER_H
8#define HOST_DATA_PARSER_H
9
12#include <boost/pointer_cast.hpp>
13#include <boost/shared_ptr.hpp>
14
15namespace isc {
16namespace host_cmds {
17
29template<typename ParserBase>
30class HostDataParser : public ParserBase {
31public:
32
49 bool required = true) {
50 uint32_t subnet_id = dhcp::SUBNET_ID_UNUSED;
51 boost::shared_ptr<isc::data::MapElement> new_map = boost::dynamic_pointer_cast<
53
54 for (auto const& el : host_data->mapValue()) {
55 if (el.first == "subnet-id") {
56 if (el.second->getType() != isc::data::Element::integer) {
58 "'subnet-id' parameter is not integer.");
59 }
60
61 if (el.second->intValue() < 0 ||
62 el.second->intValue() > dhcp::SUBNET_ID_MAX) {
64 "subnet-id: " << el.second->intValue()
65 << " is invalid," << " must be between 0 and "
66 << dhcp::SUBNET_ID_MAX << " (inclusive).");
67 }
68
69 subnet_id = static_cast<uint32_t>(el.second->intValue());
70 } else {
71 new_map->set(el.first, el.second);
72 }
73 }
74
75 if (required && (subnet_id == dhcp::SUBNET_ID_UNUSED)) {
77 "Mandatory 'subnet-id' parameter missing."
78 << " Use `reservation-get-by-id' or"
79 << " 'reservation-get-by-address' to get the list of"
80 << " reservations with given identifier or address.");
81 }
82
83 // Parse host reservations without encapsulating options with suboptions.
84 return (ParserBase::parse(subnet_id,
85 boost::dynamic_pointer_cast<const isc::data::Element>(new_map),
86 false));
87 }
88};
89
92
95
96} // namespace host_cmds
97} // namespace isc
98
99#endif
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
Definition data.cc:304
A class for parsing extended host reservation data.
isc::dhcp::HostPtr parseWithSubnet(isc::data::ConstElementPtr host_data, bool required=true)
Parser specified parameter as host reservation data.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:29
boost::shared_ptr< Host > HostPtr
Pointer to the Host object.
Definition host.h:837
HostDataParser< isc::dhcp::HostReservationParser6 > HostDataParser6
Parser for DHCPv4 host reservation.
HostDataParser< isc::dhcp::HostReservationParser4 > HostDataParser4
Parser for DHCPv4 host reservation.
Defines the logger used by the top-level component of kea-lfc.