17#include <boost/date_time/posix_time/posix_time.hpp>
18#include <boost/shared_ptr.hpp>
30constexpr unsigned int UNSET_IFINDEX = std::numeric_limits<unsigned int>::max();
45template<
typename PktType>
62 pkt1->setCopyRetrievedOptions(
true);
65 pkt2->setCopyRetrievedOptions(
true);
74 pkts_.first->setCopyRetrievedOptions(
false);
77 pkts_.second->setCopyRetrievedOptions(
false);
84 std::pair<PktTypePtr, PktTypePtr> pkts_;
107 PktEvent(
const std::string& label, boost::posix_time::ptime timestamp)
117 static boost::posix_time::ptime
now() {
118 return (boost::posix_time::microsec_clock::universal_time());
125 static boost::posix_time::ptime empty_time;
133 static auto min_time = boost::posix_time::ptime(boost::posix_time::min_date_time);
141 static auto max_time = boost::posix_time::ptime(boost::posix_time::max_date_time);
178 uint16_t remote_port);
193 Pkt(
const uint8_t* buf, uint32_t
len,
196 uint16_t remote_port);
541 const boost::posix_time::ptime& timestamp =
PktEvent::now());
549 void addPktEvent(
const std::string& label,
const struct timeval& timestamp);
561 const boost::posix_time::ptime& timestamp =
PktEvent::now());
572 boost::posix_time::ptime
getPktEventTime(
const std::string& label)
const;
738 const std::vector<uint8_t>& hw_addr);
989 virtual void setHWAddrMember(
const uint8_t htype,
const uint8_t hlen,
990 const std::vector<uint8_t>& hw_addr,
994 std::list<PktEvent> events_;
998typedef boost::shared_ptr<isc::dhcp::Pkt>
PktPtr;
1022 options_ = opt->getMutableOptions();
1031 option_->getMutableOptions() = options_;
1056template<
typename PktType>
1066 pkt_.options_ = pkt_.cloneOptions();
1073 pkt_.options_ = options_;
Defines elements for storing the names of client classes.
A generic exception that is thrown when a function is not implemented.
The IOAddress class represents an IP addresses (version agnostic)
Container for storing client class names.
Describes an event during the life cycle of a packet.
~PktEvent()=default
Destructor.
static boost::posix_time::ptime now()
Fetch the current UTC system time, microsecond precision.
std::string label_
Label identifying this event.
PktEvent(const std::string &label, boost::posix_time::ptime timestamp)
Constructor.
static boost::posix_time::ptime & MAX_TIME()
Fetches the maximum timestamp.
static const std::string BUFFER_READ
Event that marks when a packet is read from the socket buffer by application.
boost::posix_time::ptime timestamp_
Timestamp at which the event occurred.
static const std::string SOCKET_RECEIVED
Event that marks when a packet is placed in the socket buffer by the kernel.
static const std::string RESPONSE_SENT
Event that marks when a packet is been written to the socket by application.
static boost::posix_time::ptime & MIN_TIME()
Fetches the minimum timestamp.
static boost::posix_time::ptime & EMPTY_TIME()
Fetch an empty timestamp, used for logic comparisons.
Base class for classes representing DHCP messages.
bool delOption(uint16_t type)
Attempts to delete first suboption of requested type.
virtual HWAddrPtr getMACFromDocsisModem()=0
Attempts to extract MAC/Hardware address from DOCSIS options inserted by the modem itself.
virtual uint8_t getType() const =0
Returns message type (e.g.
isc::dhcp::OptionCollection getOptions(const uint16_t type)
Returns all instances of specified type.
isc::asiolink::IOAddress remote_addr_
Remote IP address.
virtual HWAddrPtr getMACFromDocsisCMTS()=0
Attempts to extract MAC/Hardware address from DOCSIS options inserted by the CMTS (the relay agent)
virtual const char * getName() const =0
Returns name of the DHCP message.
virtual void setType(uint8_t type)=0
Sets message type (e.g.
bool isCopyRetrievedOptions() const
Returns whether the copying of retrieved options is enabled.
void addClass(const isc::dhcp::ClientClass &client_class)
Adds a specified class to the packet.
uint16_t local_port_
local TDP or UDP port
int getIndex() const
Returns interface index.
const SubClassRelationContainer & getSubClassesRelations() const
Returns the class set including template classes associated with subclasses.
void resetIndex()
Resets interface index to negative value.
uint32_t transid_
Transaction-id (32 bits for v4, 24 bits for v6)
void addAdditionalClass(const isc::dhcp::ClientClass &client_class)
Adds a specified class to the packet's additional class list.
void repack()
Copies content of input buffer to output buffer.
isc::asiolink::IOAddress local_addr_
Local IP (v4 or v6) address.
virtual void pack()=0
Prepares on-wire format of DHCP (either v4 or v6) packet.
virtual HWAddrPtr getMACFromRemoteIdRelayOption()=0
Attempts to obtain MAC address from remote-id relay option.
const ClientClasses & getClasses() const
Returns the class set.
virtual void unpack()=0
Parses on-wire form of DHCP (either v4 or v6) packet.
OptionBuffer data_
Unparsed data (in received packets).
const isc::asiolink::IOAddress & getLocalAddr() const
Returns local IP address.
HWAddrPtr getRemoteHWAddr() const
Returns the remote HW address obtained from raw sockets.
virtual HWAddrPtr getMACFromSrcLinkLocalAddr()=0
Attempts to obtain MAC address from source link-local IPv6 address.
const std::list< PktEvent > & getPktEvents()
Fetches the current event stack contents.
const isc::asiolink::IOAddress & getRemoteAddr() const
Returns remote IP address.
ClientClasses classes_
Classes this packet belongs to.
void setPktEvent(const std::string &label, const boost::posix_time::ptime ×tamp=PktEvent::now())
Updates (or adds) an event in the event stack.
virtual size_t len()=0
Returns packet size in binary format.
void setIface(const std::string &iface)
Sets interface name.
bool indexSet() const
Checks if interface index has been set.
isc::util::OutputBuffer & getBuffer()
Returns reference to output buffer.
uint16_t getLocalPort() const
Returns local UDP (and soon TCP) port.
void setLocalPort(uint16_t local)
Sets local UDP (and soon TCP) port.
const ClientClasses & getAdditionalClasses() const
Returns the additional class list.
uint16_t remote_port_
remote TCP or UDP port
void setIndex(const unsigned int ifindex)
Sets interface index.
uint32_t getTransid() const
Returns value of transaction-id field.
isc::dhcp::OptionCollection options_
Collection of options present in this message.
isc::util::OutputBuffer buffer_out_
Output buffer (used during message transmission)
std::string getIface() const
Returns interface name.
virtual HWAddrPtr getMACFromDUID()=0
Attempts to obtain MAC address from DUID-LL or DUID-LLT.
virtual void setCopyRetrievedOptions(const bool copy)
Controls whether the option retrieved by the Pkt::getOption should be copied before being returned.
const boost::posix_time::ptime & getTimestamp() const
Returns packet timestamp.
SubClassRelationContainer subclasses_
SubClasses this packet belongs to.
void addPktEvent(const std::string &label, const boost::posix_time::ptime ×tamp=PktEvent::now())
Adds an event to the end of the event stack.
void clearPktEvents()
Discards contents of the packet event stack.
OptionCollection getNonCopiedOptions(const uint16_t opt_type) const
Returns all option instances of specified type without copying.
void setTimestamp(boost::posix_time::ptime ×tamp)
Set socket receive timestamp.
Pkt(uint32_t transid, const isc::asiolink::IOAddress &local_addr, const isc::asiolink::IOAddress &remote_addr, uint16_t local_port, uint16_t remote_port)
Constructor.
boost::posix_time::ptime getPktEventTime(const std::string &label) const
Fetches the timestamp for a given event in the stack.
OptionCollection cloneOptions()
Clones all options so that they can be safely modified.
uint16_t getRemotePort() const
Returns remote port.
OptionPtr getOption(const uint16_t type)
Returns the first option of specified type.
void setRemoteHWAddr(const HWAddrPtr &hw_addr)
Sets remote hardware address.
void addSubClass(const isc::dhcp::ClientClass &class_def, const isc::dhcp::ClientClass &subclass)
Adds a specified subclass to the packet.
bool inClass(const isc::dhcp::ClientClass &client_class)
Checks whether a client belongs to a given class.
virtual HWAddrPtr getMACFromIPv6RelayOpt()=0
Attempts to obtain MAC address from relay option client-linklayer-addr.
unsigned int ifindex_
Interface index.
boost::posix_time::ptime timestamp_
packet timestamp
void setTransid(uint32_t transid)
Sets transaction-id value.
HWAddrPtr getMAC(uint32_t hw_addr_src)
Returns MAC address.
ClientClasses additional_classes_
Classes to be evaluated during additional class evaluation.
virtual std::string toText() const =0
Returns text representation of the packet.
void updateTimestamp()
Update packet timestamp.
bool copy_retrieved_options_
Indicates if a copy of the retrieved option should be returned when Pkt::getOption is called.
std::string iface_
Name of the network interface the packet was received/to be sent over.
std::string dumpPktEvents(bool verbose=false) const
Creates a dump of the stack contents to a string for logging.
OptionPtr getNonCopiedOption(const uint16_t type) const
Returns the first option of specified type without copying.
void setRemoteAddr(const isc::asiolink::IOAddress &remote)
Sets remote IP address.
HWAddrPtr getMACFromIPv6(const isc::asiolink::IOAddress &addr)
Attempts to convert IPv6 address into MAC.
void setLocalAddr(const isc::asiolink::IOAddress &local)
Sets local IP address.
void setRemotePort(uint16_t remote)
Sets remote UDP (and soon TCP) port.
virtual std::string getLabel() const
Returns text representation primary packet identifiers.
virtual void addOption(const OptionPtr &opt)
Adds an option to this packet.
virtual ~Pkt()
Virtual destructor.
RAII object enabling copying options retrieved from the packet.
ScopedEnableOptionsCopy(const PktTypePtr &pkt1, const PktTypePtr &pkt2=PktTypePtr())
Constructor.
boost::shared_ptr< PktType > PktTypePtr
Pointer to an encapsulated packet.
~ScopedEnableOptionsCopy()
Destructor.
RAII object enabling duplication of the stored options and restoring the original options on destruct...
~ScopedPktOptionsCopy()
Destructor.
ScopedPktOptionsCopy(PktType &pkt)
Constructor.
RAII object enabling duplication of the stored options and restoring the original options on destruct...
ScopedSubOptionsCopy(const OptionPtr &opt)
Constructor.
~ScopedSubOptionsCopy()
Destructor.
Base class for classes which need to be associated with a CalloutHandle object.
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
ElementPtr copy(ConstElementPtr from, int level)
Copy the data up to a nesting level.
boost::shared_ptr< isc::dhcp::Pkt > PktPtr
A pointer to either Pkt4 or Pkt6 packet.
std::string ClientClass
Defines a single class name.
std::multimap< unsigned int, OptionPtr > OptionCollection
A collection of DHCP (v4 or v6) options.
boost::multi_index_container< SubClassRelation, boost::multi_index::indexed_by< boost::multi_index::sequenced< boost::multi_index::tag< TemplateClassSequenceTag > >, boost::multi_index::hashed_unique< boost::multi_index::tag< TemplateClassNameTag >, boost::multi_index::member< SubClassRelation, ClientClass, &SubClassRelation::class_def_ > > > > SubClassRelationContainer
the subclass multi-index.
boost::shared_ptr< HWAddr > HWAddrPtr
Shared pointer to a hardware address structure.
constexpr unsigned int UNSET_IFINDEX
A value used to signal that the interface index was not set.
std::vector< uint8_t > OptionBuffer
buffer types used in DHCP code.
boost::shared_ptr< Option > OptionPtr
Defines the logger used by the top-level component of kea-lfc.