20 : transid_(transid), iface_(
""), ifindex_(-1), 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) {
36 memcpy(&
data_[0], buf, len);
42 options_.insert(std::pair<int, OptionPtr>(opt->getType(), opt));
59 OptionPtr option_copy = x->second->clone();
60 x->second = option_copy;
90 if (!classes.
contains(client_class)) {
91 classes.
insert(client_class);
97 timestamp_ = boost::posix_time::microsec_clock::universal_time();
101 if (!
data_.empty()) {
108 const std::vector<uint8_t>& hw_addr) {
122 Pkt::setHWAddrMember(
const uint8_t htype,
const uint8_t,
123 const std::vector<uint8_t>& hw_addr,
125 storage.reset(
new HWAddr(hw_addr, htype));
140 }
else if (hw_addr_src == HWAddr::HWADDR_SOURCE_RAW) {
152 }
else if (hw_addr_src == HWAddr::HWADDR_SOURCE_CLIENT_ADDR_RELAY_OPTION) {
164 }
else if (hw_addr_src == HWAddr::HWADDR_SOURCE_DUID) {
176 }
else if (hw_addr_src == HWAddr::HWADDR_SOURCE_IPV6_LINK_LOCAL) {
188 }
else if (hw_addr_src == HWAddr::HWADDR_SOURCE_REMOTE_ID) {
202 }
else if (hw_addr_src == HWAddr::HWADDR_SOURCE_DOCSIS_CMTS) {
214 }
else if (hw_addr_src == HWAddr::HWADDR_SOURCE_DOCSIS_MODEM) {
230 std::vector<uint8_t> bin = addr.
toBytes();
233 if ((bin.size() == isc::asiolink::V6ADDRESS_LEN) &&
235 (bin[0] == 0xfe) && (bin[1] == 0x80) &&
238 ((bin[8] & 3) == 2) &&
240 (bin[11] == 0xff) && (bin[12] == 0xfe)) {
243 bin.erase(bin.begin(), bin.begin() + 8);
246 bin.erase(bin.begin() + 3, bin.begin() + 5);
257 hwtype = iface->getHWType();
260 mac.reset(
new HWAddr(bin, hwtype));
virtual HWAddrPtr getMACFromRemoteIdRelayOption()=0
Attempts to obtain MAC address from remote-id relay option.
IfacePtr getIface(int ifindex)
Returns interface specified interface index.
isc::asiolink::IOAddress local_addr_
Local IP (v4 or v6) address.
HWAddrPtr getMACFromIPv6(const isc::asiolink::IOAddress &addr)
Attempts to convert IPv6 address into MAC.
int64_t ifindex_
Interface index.
OptionBuffer data_
Unparsed data (in received packets).
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.
std::string iface_
Name of the network interface the packet was received/to be sent over.
bool inClass(const isc::dhcp::ClientClass &client_class)
Checks whether a client belongs to a given class.
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...
A generic exception that is thrown if a parameter given to a method or function is considered invalid...
boost::shared_ptr< HWAddr > HWAddrPtr
Shared pointer to a hardware address structure.
bool contains(const ClientClass &x) const
returns if class x belongs to the defined classes
virtual size_t len()=0
Returns packet size in binary format.
uint32_t transid_
Transaction-id (32 bits for v4, 24 bits for v6)
boost::shared_ptr< Iface > IfacePtr
Type definition for the pointer to an Iface object.
boost::shared_ptr< Option > OptionPtr
virtual HWAddrPtr getMACFromDocsisModem()=0
Attempts to extract MAC/Hardware address from DOCSIS options inserted by the modem itself...
virtual void addOption(const OptionPtr &opt)
Adds an option to this packet.
static const uint32_t HWADDR_SOURCE_REMOTE_ID
A relay can insert remote-id.
bool isV6LinkLocal() const
checks whether and address is IPv6 and is link-local
static const uint32_t HWADDR_SOURCE_CLIENT_ADDR_RELAY_OPTION
Get it from RFC6939 option.
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.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
ClientClasses classes_
Classes this packet belongs to.
virtual HWAddrPtr getMACFromDocsisCMTS()=0
Attempts to extract MAC/Hardware address from DOCSIS options inserted by the CMTS (the relay agent) ...
std::vector< uint8_t > toBytes() const
Return address as set of bytes.
bool delOption(uint16_t type)
Attempts to delete first suboption of requested type.
bool empty() const
Check if classes is empty.
bool copy_retrieved_options_
Indicates if a copy of the retrieved option should be returned when Pkt::getOption is called...
uint16_t remote_port_
remote TCP or UDP port
static const uint32_t HWADDR_SOURCE_IPV6_LINK_LOCAL
Extracted from IPv6 link-local address.
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...
void setRemoteHWAddr(const HWAddrPtr &hw_addr)
Sets remote hardware address.
Defines the logger used by the top-level component of kea-lfc.
void updateTimestamp()
Update packet timestamp.
uint16_t local_port_
local TDP or UDP port
virtual HWAddrPtr getMACFromIPv6RelayOpt()=0
Attempts to obtain MAC address from relay option client-linklayer-addr.
void addClass(const isc::dhcp::ClientClass &client_class, bool required=false)
Adds packet to a specified class.
virtual HWAddrPtr getMACFromDUID()=0
Attempts to obtain MAC address from DUID-LL or DUID-LLT.
static const uint32_t HWADDR_SOURCE_RAW
Obtained first hand from raw socket (100% reliable).
isc::asiolink::IOAddress remote_addr_
Remote IP address.
OptionPtr getNonCopiedOption(const uint16_t type) const
Returns the first option of specified type without copying.
OptionPtr getOption(const uint16_t type)
Returns the first option of specified type.
void repack()
Copies content of input buffer to output buffer.
static IfaceMgr & instance()
IfaceMgr is a singleton class.
Hardware type that represents information from DHCPv4 packet.
void insert(const ClientClass &class_name)
Insert an element.
isc::util::OutputBuffer buffer_out_
Output buffer (used during message transmission)
virtual HWAddrPtr getMACFromSrcLinkLocalAddr()=0
Attempts to obtain MAC address from source link-local IPv6 address.
The IOAddress class represents an IP addresses (version agnostic)
HWAddrPtr getRemoteHWAddr() const
Returns the remote HW address obtained from raw sockets.
ClientClasses required_classes_
Classes which are required to be evaluated.
isc::dhcp::OptionCollection options_
Collection of options present in this message.
Container for storing client class names.
static const uint32_t HWADDR_SOURCE_DUID
Extracted from DUID-LL or DUID-LLT (not 100% reliable as the client can send fake DUID)...
boost::posix_time::ptime timestamp_
packet timestamp
HWAddrPtr getMAC(uint32_t hw_addr_src)
Returns MAC address.