Kea 2.7.5
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
14namespace isc {
15namespace perfdhcp {
16
38public:
39
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
71 uint16_t type,
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
133private:
134 size_t offset_;
135 bool option_valid_;
136};
137
138
139} // namespace isc::perfdhcp
140} // namespace isc
141
142#endif // LOCALIZED_OPTION_H
This is a base class for exceptions thrown from the DNS library module.
uint16_t type_
option type (0-255 for DHCPv4, 0-65535 for DHCPv6)
Definition option.h:597
Universe
defines option universe DHCPv4 or DHCPv6
Definition option.h:90
Universe universe_
option universe (V4 or V6)
Definition option.h:594
OptionBuffer data_
contains content of this data
Definition option.h:600
Option(Universe u, uint16_t type)
ctor, used for options constructed, usually during transmission
Definition option.cc:39
DHCP option at specific offset.
LocalizedOption(const boost::shared_ptr< dhcp::Option6IA > &opt_ia, const size_t offset)
Copy constructor, creates LocalizedOption from Option6IA.
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.
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.
virtual bool valid() const
Checks if option is valid.
size_t getOffset() const
Returns offset of an option in a DHCP packet.
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
Definition buffer.h:343
OptionBuffer::const_iterator OptionBufferConstIter
const_iterator for walking over OptionBuffer
Definition option.h:30
std::vector< uint8_t > OptionBuffer
buffer types used in DHCP code.
Definition option.h:24
Defines the logger used by the top-level component of kea-lfc.