Commit e8f8dc46 authored by Tomek Mrugalski's avatar Tomek Mrugalski 🛰
Browse files

[3546] Missing pkt.cc added, several more methods moved.

parent d7f6665f
// Copyright (C) 2014 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 <utility>
#include <dhcp/pkt.h>
namespace isc {
namespace dhcp {
void
Pkt::addOption(const OptionPtr& opt) {
options_.insert(std::pair<int, boost::shared_ptr<Option> >(opt->getType(), opt));
}
OptionPtr
Pkt::getOption(uint16_t type) const {
OptionCollection::const_iterator x = options_.find(type);
if (x != options_.end()) {
return (*x).second;
}
return boost::shared_ptr<isc::dhcp::Option>(); // NULL
}
bool
Pkt::delOption(uint16_t type) {
isc::dhcp::OptionCollection::iterator x = options_.find(type);
if (x!=options_.end()) {
options_.erase(x);
return (true); // delete successful
}
return (false); // can't find option to be deleted
}
bool
Pkt::inClass(const std::string& client_class) {
return (classes_.find(client_class) != classes_.end());
}
void
Pkt::addClass(const std::string& client_class) {
if (classes_.find(client_class) == classes_.end()) {
classes_.insert(client_class);
}
}
void
Pkt::updateTimestamp() {
timestamp_ = boost::posix_time::microsec_clock::universal_time();
}
void Pkt::repack() {
buffer_out_.writeData(&data_[0], data_.size());
}
};
};
......@@ -167,7 +167,40 @@ public:
/// data format change etc.
OptionBuffer data_;
virtual ~Pkt() { }
/// @brief Returns the first option of specified type.
///
/// Returns the first option of specified type. Note that in DHCPv6 several
/// instances of the same option are allowed (and frequently used).
/// Also see \ref getOptions().
///
/// @param type option type we are looking for
///
/// @return pointer to found option (or NULL)
OptionPtr getOption(uint16_t type) const;
/// @brief Update packet timestamp.
///
/// Updates packet timestamp. This method is invoked
/// by interface manager just before sending or
/// just after receiving it.
/// @throw isc::Unexpected if timestamp update failed
void updateTimestamp();
/// @brief Copies content of input buffer to output buffer.
///
/// This is mostly a diagnostic function. It is being used for sending
/// received packet. Received packet is stored in bufferIn_, but
/// transmitted data is stored in buffer_out_. If we want to send packet
/// that we just received, a copy between those two buffers is necessary.
void repack();
/// @brief virtual desctructor
///
/// There is nothing to clean up here, but since there are virtual methods,
/// we define virtual destructor to ensure that derived classes will have
/// a virtual one, too.
virtual ~Pkt() {
}
protected:
......
......@@ -264,10 +264,6 @@ void Pkt4::setType(uint8_t dhcp_type) {
}
}
void Pkt4::repack() {
buffer_out_.writeData(&data_[0], data_.size());
}
std::string
Pkt4::toText() {
stringstream tmp;
......@@ -434,30 +430,6 @@ Pkt4::addOption(const OptionPtr& opt) {
options_.insert(pair<int, boost::shared_ptr<Option> >(opt->getType(), opt));
}
boost::shared_ptr<isc::dhcp::Option>
Pkt4::getOption(uint8_t type) const {
OptionCollection::const_iterator x = options_.find(type);
if (x != options_.end()) {
return (*x).second;
}
return boost::shared_ptr<isc::dhcp::Option>(); // NULL
}
bool
Pkt4::delOption(uint8_t type) {
isc::dhcp::OptionCollection::iterator x = options_.find(type);
if (x != options_.end()) {
options_.erase(x);
return (true); // delete successful
}
return (false); // can't find option to be deleted
}
void
Pkt4::updateTimestamp() {
timestamp_ = boost::posix_time::microsec_clock::universal_time();
}
bool
Pkt4::isRelayed() const {
static const IOAddress zero_addr("0.0.0.0");
......
......@@ -104,14 +104,6 @@ public:
/// Method will throw exception if anomaly is found.
void check();
/// @brief Copies content of input buffer to output buffer.
///
/// This is mostly a diagnostic function. It is being used for sending
/// received packet. Received packet is stored in bufferIn_, but
/// transmitted data is stored in buffer_out_. If we want to send packet
/// that we just received, a copy between those two buffers is necessary.
void repack();
/// @brief Returns text representation of the packet.
///
/// This function is useful mainly for debugging.
......@@ -303,18 +295,6 @@ public:
virtual void
addOption(const OptionPtr& opt);
/// @brief Returns an option of specified type.
///
/// @return returns option of requested type (or NULL)
/// if no such option is present
OptionPtr
getOption(uint8_t opt_type) const;
/// @brief Deletes specified option
/// @param type option type to be deleted
/// @return true if anything was deleted, false otherwise
bool delOption(uint8_t type);
/// @brief Returns interface name.
///
/// Returns interface name over which packet was received or is
......@@ -489,14 +469,6 @@ public:
callback_ = callback;
}
/// @brief Update packet timestamp.
///
/// Updates packet timestamp. This method is invoked
/// by interface manager just before sending or
/// just after receiving it.
/// @throw isc::Unexpected if timestamp update failed
void updateTimestamp();
/// @brief That's the data of input buffer used in RX packet.
///
/// @note Note that InputBuffer does not store the data itself, but just
......@@ -592,13 +564,6 @@ protected:
uint8_t file_[MAX_FILE_LEN];
// end of real DHCPv4 fields
/// packet timestamp
boost::posix_time::ptime timestamp_;
/// A callback to be called to unpack options from the packet.
UnpackOptionsCallback callback_;
}; // Pkt4 class
typedef boost::shared_ptr<Pkt4> Pkt4Ptr;
......
......@@ -451,15 +451,6 @@ Pkt6::toText() {
return tmp.str();
}
OptionPtr
Pkt6::getOption(uint16_t opt_type) {
isc::dhcp::OptionCollection::const_iterator x = options_.find(opt_type);
if (x!=options_.end()) {
return (*x).second;
}
return OptionPtr(); // NULL
}
isc::dhcp::OptionCollection
Pkt6::getOptions(uint16_t opt_type) {
isc::dhcp::OptionCollection found;
......@@ -473,15 +464,6 @@ Pkt6::getOptions(uint16_t opt_type) {
return (found);
}
void Pkt6::repack() {
buffer_out_.writeData(&data_[0], data_.size());
}
void
Pkt6::updateTimestamp() {
timestamp_ = boost::posix_time::microsec_clock::universal_time();
}
const char*
Pkt6::getName(uint8_t type) {
static const char* CONFIRM = "CONFIRM";
......
......@@ -169,18 +169,7 @@ public:
/// Sets message type (e.g. 1 = SOLICIT)
///
/// @param type message type to be set
void setType(uint8_t type) { msg_type_=type; };
/// @brief Returns the first option of specified type.
///
/// Returns the first option of specified type. Note that in DHCPv6 several
/// instances of the same option are allowed (and frequently used).
/// Also see \ref getOptions().
///
/// @param type option type we are looking for
///
/// @return pointer to found option (or NULL)
OptionPtr getOption(uint16_t type);
virtual void setType(uint8_t type) { msg_type_=type; };
/// @brief returns option inserted by relay
///
......@@ -220,11 +209,6 @@ public:
/// @return instance of option collection with requested options
isc::dhcp::OptionCollection getOptions(uint16_t type);
/// @brief This method copies data from output buffer to input buffer
///
/// This is useful only in testing
void repack();
/// @brief Sets remote address.
///
/// @param remote specifies remote address
......@@ -311,14 +295,6 @@ public:
/// @param relay structure with necessary relay information
void addRelayInfo(const RelayInfo& relay);
/// @brief Update packet timestamp.
///
/// Updates packet timestamp. This method is invoked
/// by interface manager just before sending or
/// just after receiving it.
/// @throw isc::Unexpected if timestamp update failed
void updateTimestamp();
/// @brief Return textual type of packet.
///
/// Returns the name of valid packet received by the server (e.g. SOLICIT).
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment