pkt4o6.cc 2.05 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.

#include <config.h>
16
17
18

#include <dhcp/dhcp6.h>
#include <dhcp/option.h>
19
20
#include <dhcp/pkt4o6.h>
#include <exceptions/exceptions.h>
21
#include <util/buffer.h>
22
23

using namespace isc::asiolink;
24
25
26
using namespace isc::dhcp;
using namespace isc::util;
using namespace std;
27
28
29
30
31
32
33
34
35
36

namespace {

/// @brief Default address used in Pkt4 constructor
const IOAddress DEFAULT_ADDRESS("0.0.0.0");
}

namespace isc {
namespace dhcp {

37
38
Pkt4o6::Pkt4o6(const OptionBuffer& pkt4, const Pkt6Ptr& pkt6)
    :Pkt4(&pkt4[0], pkt4.size()), pkt6_(pkt6)
39
{
40
    static_cast<void>(pkt6->delOption(D6O_DHCPV4_MSG));
41
42
43
44
45
    setIface(pkt6->getIface());
    setIndex(pkt6->getIndex());
    setRemoteAddr(pkt6->getRemoteAddr());
}

46
47
48
49
50
Pkt4o6::Pkt4o6(const Pkt4Ptr& pkt4, const Pkt6Ptr& pkt6)
    :Pkt4(*pkt4), pkt6_(pkt6) {
}

void Pkt4o6::pack() {
51
    // Convert wire-format Pkt4 data in the form of OptionBuffer.
52
53
54
55
    Pkt4::pack();
    OutputBuffer& buf = getBuffer();
    const uint8_t* ptr = static_cast<const uint8_t*>(buf.getData());
    OptionBuffer msg(ptr, ptr + buf.getLength());
56
57
58

    // Build the DHCPv4 Message option for the DHCPv6 message, and pack the
    // entire stuff.
59
60
61
62
63
    OptionPtr dhcp4_msg(new Option(Option::V6, D6O_DHCPV4_MSG, msg));
    pkt6_->addOption(dhcp4_msg);
    pkt6_->pack();
}

64
65
66
} // end of namespace isc::dhcp

} // end of namespace isc