Kea  1.9.9-git
pkt4o6.cc
Go to the documentation of this file.
1 // Copyright (C) 2015-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 #include <config.h>
8 
9 #include <dhcp/dhcp6.h>
10 #include <dhcp/option.h>
11 #include <dhcp/pkt4o6.h>
12 #include <exceptions/exceptions.h>
13 #include <util/buffer.h>
14 
15 using namespace isc::asiolink;
16 using namespace isc::dhcp;
17 using namespace isc::util;
18 using namespace std;
19 
20 namespace isc {
21 namespace dhcp {
22 
23 Pkt4o6::Pkt4o6(const OptionBuffer& pkt4, const Pkt6Ptr& pkt6)
24  :Pkt4(&pkt4[0], pkt4.size()), pkt6_(pkt6)
25 {
26  static_cast<void>(pkt6->delOption(D6O_DHCPV4_MSG));
27  setIface(pkt6->getIface());
28  setIndex(pkt6->getIndex());
29  setRemoteAddr(pkt6->getRemoteAddr());
30 }
31 
32 Pkt4o6::Pkt4o6(const Pkt4Ptr& pkt4, const Pkt6Ptr& pkt6)
33  :Pkt4(*pkt4), pkt6_(pkt6) {
34 }
35 
36 void Pkt4o6::pack() {
37  // Convert wire-format Pkt4 data in the form of OptionBuffer.
38  Pkt4::pack();
39  OutputBuffer& buf = getBuffer();
40  const uint8_t* ptr = static_cast<const uint8_t*>(buf.getData());
41  OptionBuffer msg(ptr, ptr + buf.getLength());
42 
43  // Build the DHCPv4 Message option for the DHCPv6 message, and pack the
44  // entire stuff.
45  OptionPtr dhcp4_msg(new Option(Option::V6, D6O_DHCPV4_MSG, msg));
46  pkt6_->addOption(dhcp4_msg);
47  pkt6_->pack();
48 }
49 
50 void
53  // Copy the new setting to the encapsulated instance of Pkt6.
54  pkt6_->setCopyRetrievedOptions(copy);
55 }
56 
57 
58 } // end of namespace isc::dhcp
59 
60 } // end of namespace isc
const void * getData() const
Return a pointer to the head of the data stored in the buffer.
Definition: buffer.h:401
boost::shared_ptr< Option > OptionPtr
Definition: option.h:36
Pkt4o6(const OptionBuffer &pkt4, const Pkt6Ptr &pkt6)
Constructor, used in message reception.
Definition: pkt4o6.cc:23
STL namespace.
virtual void setCopyRetrievedOptions(const bool copy)
Controls whether the option retrieved by the Pkt::getOption should be copied before being returned...
Definition: pkt.h:368
void setIface(const std::string &iface)
Sets interface name.
Definition: pkt.h:520
std::vector< uint8_t > OptionBuffer
buffer types used in DHCP code.
Definition: option.h:24
void setRemoteAddr(const isc::asiolink::IOAddress &remote)
Sets remote IP address.
Definition: pkt.h:418
boost::shared_ptr< Pkt6 > Pkt6Ptr
A pointer to Pkt6 packet.
Definition: pkt6.h:28
Definition: edns.h:19
ElementPtr copy(ConstElementPtr from, int level)
Copy the data up to a nesting level.
Definition: data.cc:1097
virtual void pack()
Prepares on-wire format of DHCPv4-over-DHCPv6 packet.
Definition: pkt4o6.cc:36
boost::shared_ptr< Pkt4 > Pkt4Ptr
A pointer to Pkt4 object.
Definition: pkt4.h:544
isc::util::OutputBuffer & getBuffer()
Returns reference to output buffer.
Definition: pkt.h:174
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
Definition: buffer.h:294
Defines the logger used by the top-level component of kea-dhcp-ddns.
Represents DHCPv4 packet.
Definition: pkt4.h:37
void setIndex(uint32_t ifindex)
Sets interface index.
Definition: pkt.h:483
virtual void pack()
Prepares on-wire format of DHCPv4 packet.
Definition: pkt4.cc:89
size_t getLength() const
Return the length of data written in the buffer.
Definition: buffer.h:403
virtual void setCopyRetrievedOptions(const bool copy)
Overrides the Pkt::setCopyRetrievedOptions to also set the flag for encapsulated Pkt6 instance...
Definition: pkt4o6.cc:51