|
@@ -17,7 +17,7 @@
|
|
|
|
|
|
#include <asiolink/io_address.h>
|
|
#include <asiolink/io_address.h>
|
|
#include <dhcp/option.h>
|
|
#include <dhcp/option.h>
|
|
-#include <dhcp/classify.h>
|
|
+#include <dhcp/pkt.h>
|
|
|
|
|
|
#include <boost/date_time/posix_time/posix_time.hpp>
|
|
#include <boost/date_time/posix_time/posix_time.hpp>
|
|
#include <boost/shared_array.hpp>
|
|
#include <boost/shared_array.hpp>
|
|
@@ -35,7 +35,7 @@ namespace dhcp {
|
|
class Pkt6;
|
|
class Pkt6;
|
|
typedef boost::shared_ptr<Pkt6> Pkt6Ptr;
|
|
typedef boost::shared_ptr<Pkt6> Pkt6Ptr;
|
|
|
|
|
|
-class Pkt6 {
|
|
+class Pkt6 : public Pkt {
|
|
public:
|
|
public:
|
|
/// specifies non-relayed DHCPv6 packet header length (over UDP)
|
|
/// specifies non-relayed DHCPv6 packet header length (over UDP)
|
|
const static size_t DHCPV6_PKT_HDR_LEN = 4;
|
|
const static size_t DHCPV6_PKT_HDR_LEN = 4;
|
|
@@ -122,7 +122,7 @@ public:
|
|
/// @throw BadValue if packet protocol is invalid, InvalidOperation
|
|
/// @throw BadValue if packet protocol is invalid, InvalidOperation
|
|
/// if packing fails, or NotImplemented if protocol is TCP (IPv6 over TCP is
|
|
/// if packing fails, or NotImplemented if protocol is TCP (IPv6 over TCP is
|
|
/// not yet supported).
|
|
/// not yet supported).
|
|
- void pack();
|
|
+ virtual void pack();
|
|
|
|
|
|
/// @brief Dispatch method that handles binary packet parsing.
|
|
/// @brief Dispatch method that handles binary packet parsing.
|
|
///
|
|
///
|
|
@@ -130,19 +130,7 @@ public:
|
|
/// unpackTCP).
|
|
/// unpackTCP).
|
|
///
|
|
///
|
|
/// @return true if parsing was successful
|
|
/// @return true if parsing was successful
|
|
- bool unpack();
|
|
+ virtual bool unpack();
|
|
-
|
|
|
|
- /// @brief Returns reference to output buffer.
|
|
|
|
- ///
|
|
|
|
- /// Returned buffer will contain reasonable data only for
|
|
|
|
- /// output (TX) packet and after pack() was called. This buffer
|
|
|
|
- /// is only valid till Pkt6 object is valid.
|
|
|
|
- ///
|
|
|
|
- /// RX packet or TX packet before pack() will return buffer with
|
|
|
|
- /// zero length
|
|
|
|
- ///
|
|
|
|
- /// @return reference to output buffer
|
|
|
|
- const isc::util::OutputBuffer& getBuffer() const { return (buffer_out_); };
|
|
|
|
|
|
|
|
/// @brief Returns protocol of this packet (UDP or TCP).
|
|
/// @brief Returns protocol of this packet (UDP or TCP).
|
|
///
|
|
///
|
|
@@ -159,7 +147,7 @@ public:
|
|
/// This function is useful mainly for debugging.
|
|
/// This function is useful mainly for debugging.
|
|
///
|
|
///
|
|
/// @return string with text representation
|
|
/// @return string with text representation
|
|
- std::string toText();
|
|
+ virtual std::string toText();
|
|
|
|
|
|
/// @brief Returns length of the packet.
|
|
/// @brief Returns length of the packet.
|
|
///
|
|
///
|
|
@@ -171,33 +159,18 @@ public:
|
|
/// before they are unpacked.
|
|
/// before they are unpacked.
|
|
///
|
|
///
|
|
/// @return number of bytes required to assemble this packet
|
|
/// @return number of bytes required to assemble this packet
|
|
- uint16_t len();
|
|
+ virtual size_t len();
|
|
|
|
|
|
/// Returns message type (e.g. 1 = SOLICIT)
|
|
/// Returns message type (e.g. 1 = SOLICIT)
|
|
///
|
|
///
|
|
/// @return message type
|
|
/// @return message type
|
|
- uint8_t getType() const { return (msg_type_); }
|
|
+ virtual uint8_t getType() const { return (msg_type_); }
|
|
|
|
|
|
/// Sets message type (e.g. 1 = SOLICIT)
|
|
/// Sets message type (e.g. 1 = SOLICIT)
|
|
///
|
|
///
|
|
/// @param type message type to be set
|
|
/// @param type message type to be set
|
|
void setType(uint8_t type) { msg_type_=type; };
|
|
void setType(uint8_t type) { msg_type_=type; };
|
|
|
|
|
|
- /// @brief Sets transaction-id value
|
|
|
|
- ///
|
|
|
|
- /// @param transid transaction-id to be set.
|
|
|
|
- void setTransid(uint32_t transid) { transid_ = transid; }
|
|
|
|
-
|
|
|
|
- /// Returns value of transaction-id field
|
|
|
|
- ///
|
|
|
|
- /// @return transaction-id
|
|
|
|
- uint32_t getTransid() const { return (transid_); };
|
|
|
|
-
|
|
|
|
- /// Adds an option to this packet.
|
|
|
|
- ///
|
|
|
|
- /// @param opt option to be added.
|
|
|
|
- void addOption(const OptionPtr& opt);
|
|
|
|
-
|
|
|
|
/// @brief Returns the first option of specified type.
|
|
/// @brief Returns the first option of specified type.
|
|
///
|
|
///
|
|
/// Returns the first option of specified type. Note that in DHCPv6 several
|
|
/// Returns the first option of specified type. Note that in DHCPv6 several
|
|
@@ -247,13 +220,6 @@ public:
|
|
/// @return instance of option collection with requested options
|
|
/// @return instance of option collection with requested options
|
|
isc::dhcp::OptionCollection getOptions(uint16_t type);
|
|
isc::dhcp::OptionCollection getOptions(uint16_t type);
|
|
|
|
|
|
- /// Attempts to delete first suboption of requested type
|
|
|
|
- ///
|
|
|
|
- /// @param type Type of option to be deleted.
|
|
|
|
- ///
|
|
|
|
- /// @return true if option was deleted, false if no such option existed
|
|
|
|
- bool delOption(uint16_t type);
|
|
|
|
-
|
|
|
|
/// @brief This method copies data from output buffer to input buffer
|
|
/// @brief This method copies data from output buffer to input buffer
|
|
///
|
|
///
|
|
/// This is useful only in testing
|
|
/// This is useful only in testing
|
|
@@ -345,16 +311,6 @@ public:
|
|
/// @param relay structure with necessary relay information
|
|
/// @param relay structure with necessary relay information
|
|
void addRelayInfo(const RelayInfo& relay);
|
|
void addRelayInfo(const RelayInfo& relay);
|
|
|
|
|
|
- /// collection of options present in this message
|
|
|
|
- ///
|
|
|
|
- /// @warning This public member is accessed by derived
|
|
|
|
- /// classes directly. One of such derived classes is
|
|
|
|
- /// @ref perfdhcp::PerfPkt6. The impact on derived clasess'
|
|
|
|
- /// behavior must be taken into consideration before making
|
|
|
|
- /// changes to this member such as access scope restriction or
|
|
|
|
- /// data format change etc.
|
|
|
|
- isc::dhcp::OptionCollection options_;
|
|
|
|
-
|
|
|
|
/// @brief Update packet timestamp.
|
|
/// @brief Update packet timestamp.
|
|
///
|
|
///
|
|
/// Updates packet timestamp. This method is invoked
|
|
/// Updates packet timestamp. This method is invoked
|
|
@@ -417,46 +373,6 @@ public:
|
|
/// (or least bad) solution.
|
|
/// (or least bad) solution.
|
|
std::vector<RelayInfo> relay_info_;
|
|
std::vector<RelayInfo> relay_info_;
|
|
|
|
|
|
-
|
|
|
|
- /// unparsed data (in received packets)
|
|
|
|
- ///
|
|
|
|
- /// @warning This public member is accessed by derived
|
|
|
|
- /// classes directly. One of such derived classes is
|
|
|
|
- /// @ref perfdhcp::PerfPkt6. The impact on derived clasess'
|
|
|
|
- /// behavior must be taken into consideration before making
|
|
|
|
- /// changes to this member such as access scope restriction or
|
|
|
|
- /// data format change etc.
|
|
|
|
- OptionBuffer data_;
|
|
|
|
-
|
|
|
|
- /// @brief Checks whether a client belongs to a given class
|
|
|
|
- ///
|
|
|
|
- /// @param client_class name of the class
|
|
|
|
- /// @return true if belongs
|
|
|
|
- bool inClass(const std::string& client_class);
|
|
|
|
-
|
|
|
|
- /// @brief Adds packet to a specified class
|
|
|
|
- ///
|
|
|
|
- /// A packet can be added to the same class repeatedly. Any additional
|
|
|
|
- /// attempts to add to a class the packet already belongs to, will be
|
|
|
|
- /// ignored silently.
|
|
|
|
- ///
|
|
|
|
- /// @note It is a matter of naming convention. Conceptually, the server
|
|
|
|
- /// processes a stream of packets, with some packets belonging to given
|
|
|
|
- /// classes. From that perspective, this method adds a packet to specifed
|
|
|
|
- /// class. Implementation wise, it looks the opposite - the class name
|
|
|
|
- /// is added to the packet. Perhaps the most appropriate name for this
|
|
|
|
- /// method would be associateWithClass()? But that seems overly long,
|
|
|
|
- /// so I decided to stick with addClass().
|
|
|
|
- ///
|
|
|
|
- /// @param client_class name of the class to be added
|
|
|
|
- void addClass(const std::string& client_class);
|
|
|
|
-
|
|
|
|
- /// @brief Classes this packet belongs to.
|
|
|
|
- ///
|
|
|
|
- /// This field is public, so code can iterate over existing classes.
|
|
|
|
- /// Having it public also solves the problem of returned reference lifetime.
|
|
|
|
- ClientClasses classes_;
|
|
|
|
-
|
|
|
|
protected:
|
|
protected:
|
|
/// Builds on wire packet for TCP transmission.
|
|
/// Builds on wire packet for TCP transmission.
|
|
///
|
|
///
|
|
@@ -536,48 +452,6 @@ protected:
|
|
/// DHCPv6 message type
|
|
/// DHCPv6 message type
|
|
uint8_t msg_type_;
|
|
uint8_t msg_type_;
|
|
|
|
|
|
- /// DHCPv6 transaction-id
|
|
|
|
- uint32_t transid_;
|
|
|
|
-
|
|
|
|
- /// name of the network interface the packet was received/to be sent over
|
|
|
|
- std::string iface_;
|
|
|
|
-
|
|
|
|
- /// @brief interface index
|
|
|
|
- ///
|
|
|
|
- /// interface index (each network interface has assigned unique ifindex
|
|
|
|
- /// it is functional equivalent of name, but sometimes more useful, e.g.
|
|
|
|
- /// when using crazy systems that allow spaces in interface names
|
|
|
|
- /// e.g. windows
|
|
|
|
- int ifindex_;
|
|
|
|
-
|
|
|
|
- /// local address (dst if receiving packet, src if sending packet)
|
|
|
|
- isc::asiolink::IOAddress local_addr_;
|
|
|
|
-
|
|
|
|
- /// remote address (src if receiving packet, dst if sending packet)
|
|
|
|
- isc::asiolink::IOAddress remote_addr_;
|
|
|
|
-
|
|
|
|
- /// local TDP or UDP port
|
|
|
|
- uint16_t local_port_;
|
|
|
|
-
|
|
|
|
- /// remote TCP or UDP port
|
|
|
|
- uint16_t remote_port_;
|
|
|
|
-
|
|
|
|
- /// Output buffer (used during message transmission)
|
|
|
|
- ///
|
|
|
|
- /// @warning This protected member is accessed by derived
|
|
|
|
- /// classes directly. One of such derived classes is
|
|
|
|
- /// @ref perfdhcp::PerfPkt6. The impact on derived clasess'
|
|
|
|
- /// behavior must be taken into consideration before making
|
|
|
|
- /// changes to this member such as access scope restriction or
|
|
|
|
- /// data format change etc.
|
|
|
|
- isc::util::OutputBuffer buffer_out_;
|
|
|
|
-
|
|
|
|
- /// packet timestamp
|
|
|
|
- boost::posix_time::ptime timestamp_;
|
|
|
|
-
|
|
|
|
- /// A callback to be called to unpack options from the packet.
|
|
|
|
- UnpackOptionsCallback callback_;
|
|
|
|
-
|
|
|
|
}; // Pkt6 class
|
|
}; // Pkt6 class
|
|
|
|
|
|
} // isc::dhcp namespace
|
|
} // isc::dhcp namespace
|