pkt4o6.cc 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. #include <config.h>
  7. #include <dhcp/dhcp6.h>
  8. #include <dhcp/option.h>
  9. #include <dhcp/pkt4o6.h>
  10. #include <exceptions/exceptions.h>
  11. #include <util/buffer.h>
  12. using namespace isc::asiolink;
  13. using namespace isc::dhcp;
  14. using namespace isc::util;
  15. using namespace std;
  16. namespace isc {
  17. namespace dhcp {
  18. Pkt4o6::Pkt4o6(const OptionBuffer& pkt4, const Pkt6Ptr& pkt6)
  19. :Pkt4(&pkt4[0], pkt4.size()), pkt6_(pkt6)
  20. {
  21. static_cast<void>(pkt6->delOption(D6O_DHCPV4_MSG));
  22. setIface(pkt6->getIface());
  23. setIndex(pkt6->getIndex());
  24. setRemoteAddr(pkt6->getRemoteAddr());
  25. }
  26. Pkt4o6::Pkt4o6(const Pkt4Ptr& pkt4, const Pkt6Ptr& pkt6)
  27. :Pkt4(*pkt4), pkt6_(pkt6) {
  28. }
  29. void Pkt4o6::pack() {
  30. // Convert wire-format Pkt4 data in the form of OptionBuffer.
  31. Pkt4::pack();
  32. OutputBuffer& buf = getBuffer();
  33. const uint8_t* ptr = static_cast<const uint8_t*>(buf.getData());
  34. OptionBuffer msg(ptr, ptr + buf.getLength());
  35. // Build the DHCPv4 Message option for the DHCPv6 message, and pack the
  36. // entire stuff.
  37. OptionPtr dhcp4_msg(new Option(Option::V6, D6O_DHCPV4_MSG, msg));
  38. pkt6_->addOption(dhcp4_msg);
  39. pkt6_->pack();
  40. }
  41. void
  42. Pkt4o6::setCopyRetrievedOptions(const bool copy) {
  43. Pkt4::setCopyRetrievedOptions(copy);
  44. // Copy the new setting to the encapsulated instance of Pkt6.
  45. pkt6_->setCopyRetrievedOptions(copy);
  46. }
  47. } // end of namespace isc::dhcp
  48. } // end of namespace isc