| Kea 3.0.2-git

localized_option.h
Go to the documentation of this file.
1// Copyright (C) 2012-2024 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 LOCALIZED_OPTION_H
8#define LOCALIZED_OPTION_H
9
10#include <dhcp/pkt6.h>
11#include <dhcp/option6_ia.h>
12#include <util/buffer.h>
13
14 namespace isc {
15 namespace perfdhcp {
16
37 class LocalizedOption : public dhcp::Option {
38 public:
39
51 LocalizedOption(dhcp::Option::Universe u,
52 uint16_t type,
53 const dhcp::OptionBuffer& data,
54 const size_t offset = 0) :
55 dhcp::Option(u, type, data),
56 offset_(offset), option_valid_(true) {
57 }
58
70 LocalizedOption(dhcp::Option::Universe u,
71 uint16_t type,
72 dhcp::OptionBufferConstIter first,
73 dhcp::OptionBufferConstIter last,
74 const size_t offset = 0) :
75 dhcp::Option(u, type, first, last),
76 offset_(offset), option_valid_(true) {
77 }
78
87 LocalizedOption(const boost::shared_ptr<dhcp::Option6IA>& opt_ia,
88 const size_t offset) :
89 dhcp::Option(Option::V6, 0, dhcp::OptionBuffer()),
90 offset_(offset), option_valid_(false) {
91 // If given option is NULL we will mark this new option
92 // as invalid. User may query if option is valid when
93 // object is created.
94 if (opt_ia) {
95 // Set universe and type.
96 universe_ = opt_ia->getUniverse();
97 type_ = opt_ia->getType();
98 util::OutputBuffer buf(opt_ia->len() - opt_ia->getHeaderLen());
99 try {
100 // Try to pack option data into the temporary buffer.
101 opt_ia->pack(buf);
102 if (buf.getLength() > 0) {
103 const uint8_t* buf_data = buf.getData();
104 // Option has been packed along with option type flag
105 // and transaction id so we have to skip first 4 bytes
106 // when copying temporary buffer option buffer.
107 data_.assign(buf_data + 4, buf_data + buf.getLength());
108 }
109 option_valid_ = true;
110 } catch (const Exception&) {
111 // If there was an exception somewhere when packing
112 // the data into the buffer we assume that option is
113 // not valid and should not be used.
114 option_valid_ = false;
115 }
116 } else {
117 option_valid_ = false;
118 }
119 }
120
124 size_t getOffset() const { return offset_; };
125
129 virtual bool valid() const {
130 return (Option::valid() && option_valid_);
131 }
132
133 private:
134 size_t offset_;
135 bool option_valid_;
136};
137
138
139} // namespace isc::perfdhcp
140} // namespace isc
141
142#endif // LOCALIZED_OPTION_H
buffer.h
isc::Exception
This is a base class for exceptions thrown from the DNS library module.
Definition exceptions/exceptions.h:23
isc::dhcp::Option
Definition option.h:81
isc::dhcp::Option::type_
uint16_t type_
option type (0-255 for DHCPv4, 0-65535 for DHCPv6)
Definition option.h:597
isc::dhcp::Option::Universe
Universe
defines option universe DHCPv4 or DHCPv6
Definition option.h:90
isc::dhcp::Option::V6
@ V6
Definition option.h:90
isc::dhcp::Option::universe_
Universe universe_
option universe (V4 or V6)
Definition option.h:594
isc::dhcp::Option::data_
OptionBuffer data_
contains content of this data
Definition option.h:600
isc::dhcp::Option::Option
Option(Universe u, uint16_t type)
ctor, used for options constructed, usually during transmission
Definition option.cc:39
isc::perfdhcp::LocalizedOption::LocalizedOption
LocalizedOption(const boost::shared_ptr< dhcp::Option6IA > &opt_ia, const size_t offset)
Copy constructor, creates LocalizedOption from Option6IA.
Definition localized_option.h:87
isc::perfdhcp::LocalizedOption::LocalizedOption
LocalizedOption(dhcp::Option::Universe u, uint16_t type, const dhcp::OptionBuffer &data, const size_t offset=0)
Constructor, used to create localized option from buffer.
Definition localized_option.h:51
isc::perfdhcp::LocalizedOption::LocalizedOption
LocalizedOption(dhcp::Option::Universe u, uint16_t type, dhcp::OptionBufferConstIter first, dhcp::OptionBufferConstIter last, const size_t offset=0)
Constructor, used to create option from buffer iterators.
Definition localized_option.h:70
isc::perfdhcp::LocalizedOption::valid
virtual bool valid() const
Checks if option is valid.
Definition localized_option.h:129
isc::perfdhcp::LocalizedOption::getOffset
size_t getOffset() const
Returns offset of an option in a DHCP packet.
Definition localized_option.h:124
isc::util::OutputBuffer
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
Definition buffer.h:346
isc::util::OutputBuffer::getData
const uint8_t * getData() const
Return a pointer to the head of the data stored in the buffer.
Definition buffer.h:398
isc::util::OutputBuffer::getLength
size_t getLength() const
Return the length of data written in the buffer.
Definition buffer.h:412
isc::data
Definition base_stamped_element.cc:12
isc::dhcp
Definition dhcp4/client_handler.cc:20
isc::dhcp::OptionBufferConstIter
OptionBuffer::const_iterator OptionBufferConstIter
const_iterator for walking over OptionBuffer
Definition option.h:30
isc::dhcp::OptionBuffer
std::vector< uint8_t > OptionBuffer
buffer types used in DHCP code.
Definition option.h:24
isc::perfdhcp
Definition abstract_scen.h:15
isc
Defines the logger used by the top-level component of kea-lfc.
Definition agent_parser.cc:148
option6_ia.h
pkt6.h