20 : transid_(transid), iface_(
""), ifindex_(
UNSET_IFINDEX), local_addr_(local_addr),
21 remote_addr_(remote_addr), local_port_(local_port),
22 remote_port_(remote_port), buffer_out_(0), copy_retrieved_options_(false) {
28 : transid_(0), iface_(
""), ifindex_(
UNSET_IFINDEX), local_addr_(local_addr),
29 remote_addr_(remote_addr), local_port_(local_port),
30 remote_port_(remote_port), buffer_out_(0), copy_retrieved_options_(false) {
42 options_.insert(std::pair<int, OptionPtr>(opt->getType(), opt));
59 OptionPtr option_copy = x->second->clone();
60 x->second = option_copy;
69 std::pair<OptionCollection::const_iterator,
70 OptionCollection::const_iterator> range =
options_.equal_range(opt_type);
78 std::pair<OptionCollection::iterator,
79 OptionCollection::iterator> range =
options_.equal_range(opt_type);
84 for (OptionCollection::iterator opt_it = range.first;
85 opt_it != range.second; ++opt_it) {
86 OptionPtr option_copy = opt_it->second->clone();
87 opt_it->second = option_copy;
113 if (!classes.
contains(client_class)) {
114 classes.
insert(client_class);
133 timestamp_ = boost::posix_time::microsec_clock::universal_time();
137 if (!
data_.empty()) {
144 const std::vector<uint8_t>& hw_addr) {
158 Pkt::setHWAddrMember(
const uint8_t htype,
const uint8_t,
159 const std::vector<uint8_t>& hw_addr,
161 storage.reset(
new HWAddr(hw_addr, htype));
266 std::vector<uint8_t> bin = addr.
toBytes();
269 if ((bin.size() == isc::asiolink::V6ADDRESS_LEN) &&
271 (bin[0] == 0xfe) && (bin[1] == 0x80) &&
274 ((bin[8] & 3) == 2) &&
276 (bin[11] == 0xff) && (bin[12] == 0xfe)) {
279 bin.erase(bin.begin(), bin.begin() + 8);
282 bin.erase(bin.begin() + 3, bin.begin() + 5);
293 hwtype = iface->getHWType();
296 mac.reset(
new HWAddr(bin, hwtype));
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
A generic exception that is thrown if a parameter given to a method or function is considered invalid...
The IOAddress class represents an IP addresses (version agnostic)
std::vector< uint8_t > toBytes() const
Return address as set of bytes.
bool isV6LinkLocal() const
checks whether and address is IPv6 and is link-local
Container for storing client class names.
bool contains(const ClientClass &x) const
returns if class x belongs to the defined classes
void insert(const ClientClass &class_name)
Insert an element.
IfacePtr getIface(const unsigned int ifindex)
Returns interface specified interface index.
static IfaceMgr & instance()
IfaceMgr is a singleton class.
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.
isc::dhcp::OptionCollection getOptions(const uint16_t type)
Returns all instances of specified type.
virtual HWAddrPtr getMACFromDocsisCMTS()=0
Attempts to extract MAC/Hardware address from DOCSIS options inserted by the CMTS (the relay agent)
ClientClasses required_classes_
Classes which are required to be evaluated.
void repack()
Copies content of input buffer to output buffer.
virtual HWAddrPtr getMACFromRemoteIdRelayOption()=0
Attempts to obtain MAC address from remote-id relay option.
OptionBuffer data_
Unparsed data (in received packets).
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.
ClientClasses classes_
Classes this packet belongs to.
virtual size_t len()=0
Returns packet size in binary format.
isc::dhcp::OptionCollection options_
Collection of options present in this message.
isc::util::OutputBuffer buffer_out_
Output buffer (used during message transmission)
virtual HWAddrPtr getMACFromDUID()=0
Attempts to obtain MAC address from DUID-LL or DUID-LLT.
SubClassRelationContainer subclasses_
SubClasses this packet belongs to.
OptionCollection getNonCopiedOptions(const uint16_t opt_type) const
Returns all option instances of specified type without copying.
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.
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.
boost::posix_time::ptime timestamp_
packet timestamp
HWAddrPtr getMAC(uint32_t hw_addr_src)
Returns MAC address.
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.
void addClass(const isc::dhcp::ClientClass &client_class, bool required=false)
Adds a specified class to the packet.
OptionPtr getNonCopiedOption(const uint16_t type) const
Returns the first option of specified type without copying.
HWAddrPtr getMACFromIPv6(const isc::asiolink::IOAddress &addr)
Attempts to convert IPv6 address into MAC.
virtual void addOption(const OptionPtr &opt)
Adds an option to this packet.
void writeData(const void *data, size_t len)
Copy an arbitrary length of data into the buffer.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
static const uint32_t HWADDR_SOURCE_RAW
Obtained first hand from raw socket (100% reliable).
static const uint32_t HWADDR_SOURCE_REMOTE_ID
A relay can insert remote-id.
static const uint32_t HWADDR_SOURCE_CLIENT_ADDR_RELAY_OPTION
Get it from RFC6939 option.
static const uint32_t HWADDR_SOURCE_IPV6_LINK_LOCAL
Extracted from IPv6 link-local address.
static const uint32_t HWADDR_SOURCE_DOCSIS_MODEM
A cable modem (acting as DHCP client) that supports DOCSIS standard can insert DOCSIS options that co...
static const uint32_t HWADDR_SOURCE_DUID
Extracted from DUID-LL or DUID-LLT (not 100% reliable as the client can send fake DUID).
static const uint32_t HWADDR_SOURCE_DOCSIS_CMTS
A CMTS (acting as DHCP relay agent) that supports DOCSIS standard can insert DOCSIS options that cont...
std::string ClientClass
Defines a single class name.
boost::shared_ptr< Iface > IfacePtr
Type definition for the pointer to an Iface object.
std::multimap< unsigned int, OptionPtr > OptionCollection
A collection of DHCP (v4 or v6) options.
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.
boost::shared_ptr< Option > OptionPtr
Defines the logger used by the top-level component of kea-lfc.
Hardware type that represents information from DHCPv4 packet.
Defines a subclass to template class relation.