Kea  2.3.5-git
localized_option.h
Go to the documentation of this file.
1 // Copyright (C) 2012-2016 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 
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 char* buf_data = static_cast<const char*>(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
DHCP option at specific offset.
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.
Universe
defines option universe DHCPv4 or DHCPv6
Definition: option.h:83
size_t getOffset() const
Returns offset of an option in a DHCP packet.
Option(Universe u, uint16_t type)
ctor, used for options constructed, usually during transmission
Definition: option.cc:39
LocalizedOption(const boost::shared_ptr< dhcp::Option6IA > &opt_ia, const size_t offset)
Copy constructor, creates LocalizedOption from Option6IA.
Universe universe_
option universe (V4 or V6)
Definition: option.h:587
std::vector< uint8_t > OptionBuffer
buffer types used in DHCP code.
Definition: option.h:24
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
Definition: buffer.h:294
virtual bool valid() const
Checks if option is valid.
OptionBuffer::const_iterator OptionBufferConstIter
const_iterator for walking over OptionBuffer
Definition: option.h:30
This is a base class for exceptions thrown from the DNS library module.
Defines the logger used by the top-level component of kea-lfc.
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.
OptionBuffer data_
contains content of this data
Definition: option.h:593
uint16_t type_
option type (0-255 for DHCPv4, 0-65535 for DHCPv6)
Definition: option.h:590