Kea 1.5.0
pkt4.h
Go to the documentation of this file.
1// Copyright (C) 2011-2017 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#ifndef PKT4_H
8#define PKT4_H
9
10#include <asiolink/io_address.h>
11#include <dhcp/option.h>
12#include <dhcp/duid.h>
13#include <util/buffer.h>
14#include <dhcp/option.h>
15#include <dhcp/classify.h>
16#include <dhcp/pkt.h>
17
18#include <boost/shared_ptr.hpp>
19
20#include <iostream>
21#include <vector>
22#include <set>
23#include <list>
24
25#include <time.h>
26
27namespace isc {
28
29namespace dhcp {
30
38class Pkt4 : public Pkt {
39public:
40
42 const static size_t MAX_CHADDR_LEN = 16;
43
45 const static size_t MAX_SNAME_LEN = 64;
46
48 const static size_t MAX_FILE_LEN = 128;
49
51 const static size_t DHCPV4_PKT_HDR_LEN = 236;
52
55 const static uint16_t FLAG_BROADCAST_MASK = 0x8000;
56
61 Pkt4(uint8_t msg_type, uint32_t transid);
62
70 Pkt4(const uint8_t* data, size_t len);
71
80 virtual void pack();
81
90 virtual void unpack();
91
102 std::string getLabel() const;
103
113 static std::string makeLabel(const HWAddrPtr& hwaddr,
114 const ClientIdPtr& client_id,
115 const uint32_t transid);
116
124 static std::string makeLabel(const HWAddrPtr& hwaddr, const ClientIdPtr& client_id);
125
131 std::string toText() const;
132
139 size_t len();
140
144 void setHops(uint8_t hops) { hops_ = hops; };
145
149 uint8_t getHops() const { return (hops_); };
150
151 // Note: There's no need to manipulate OP field directly,
152 // thus no setOp() method. See op_ comment.
153
157 uint8_t getOp() const { return (op_); };
158
162 void setSecs(uint16_t secs) { secs_ = secs; };
163
167 uint16_t getSecs() const { return (secs_); };
168
172 void setFlags(uint16_t flags) { flags_ = flags; };
173
177 uint16_t getFlags() const { return (flags_); };
178
183 getCiaddr() const { return (ciaddr_); };
184
188 void
189 setCiaddr(const isc::asiolink::IOAddress& ciaddr) { ciaddr_ = ciaddr; };
190
191
196 getSiaddr() const { return (siaddr_); };
197
201 void
202 setSiaddr(const isc::asiolink::IOAddress& siaddr) { siaddr_ = siaddr; };
203
208 getYiaddr() const { return (yiaddr_); };
209
213 void
214 setYiaddr(const isc::asiolink::IOAddress& yiaddr) { yiaddr_ = yiaddr; };
215
220 getGiaddr() const { return (giaddr_); };
221
225 void
226 setGiaddr(const isc::asiolink::IOAddress& giaddr) { giaddr_ = giaddr; };
227
234 uint8_t getType() const;
235
239 void setType(uint8_t type);
240
251 static const char* getName(const uint8_t type);
252
258 const char* getName() const;
259
266 const OptionBuffer
267 getSname() const { return (std::vector<uint8_t>(sname_, &sname_[MAX_SNAME_LEN])); };
268
273 void setSname(const uint8_t* sname, size_t sname_len);
274
281 const OptionBuffer
282 getFile() const { return (std::vector<uint8_t>(file_, &file_[MAX_FILE_LEN])); };
283
288 void
289 setFile(const uint8_t* file, size_t file_len);
290
302 void setHWAddr(uint8_t htype, uint8_t hlen,
303 const std::vector<uint8_t>& mac_addr);
304
310 void setHWAddr(const HWAddrPtr& addr);
311
315 uint8_t
316 getHtype() const;
317
321 uint8_t
322 getHlen() const;
323
326 HWAddrPtr getHWAddr() const { return (hwaddr_); }
327
333 virtual void
334 addOption(const OptionPtr& opt);
335
346 void setLocalHWAddr(const uint8_t htype, const uint8_t hlen,
347 const std::vector<uint8_t>& mac_addr);
348
358 void setLocalHWAddr(const HWAddrPtr& addr);
359
364 return (local_hwaddr_);
365 }
366
376 std::list<uint16_t>& getDeferredOptions() {
377 return (deferred_options_);
378 }
379
390 bool isRelayed() const;
391
396 virtual bool isDhcp4o6() const {
397 return (false);
398 }
399
400private:
401
413 virtual void setHWAddrMember(const uint8_t htype, const uint8_t hlen,
414 const std::vector<uint8_t>& mac_addr,
415 HWAddrPtr& hw_addr);
416
417protected:
418
424 uint8_t
425 DHCPTypeToBootpType(uint8_t dhcpType);
426
436 return (HWAddrPtr());
437 }
438
448 return (HWAddrPtr());
449 }
450
459 return (HWAddrPtr());
460 }
461
470 return (HWAddrPtr());
471 }
472
481 return (HWAddrPtr());
482 }
483
491 return(HWAddrPtr());
492 }
493
496
497 // @brief List of deferred option codes
498 std::list<uint16_t> deferred_options_;
499
507 uint8_t op_;
508
514
516 uint8_t hops_;
517
519 uint16_t secs_;
520
522 uint16_t flags_;
523
526
529
532
535
538
541
542 // end of real DHCPv4 fields
543}; // Pkt4 class
544
546typedef boost::shared_ptr<Pkt4> Pkt4Ptr;
547
548} // isc::dhcp namespace
549
550} // isc namespace
551
552#endif
Defines elements for storing the names of client classes.
Represents DHCPv4 packet.
Definition: pkt4.h:38
virtual void addOption(const OptionPtr &opt)
Add an option.
Definition: pkt4.cc:550
std::string toText() const
Returns text representation of the packet.
Definition: pkt4.cc:383
void setCiaddr(const isc::asiolink::IOAddress &ciaddr)
Sets ciaddr field.
Definition: pkt4.h:189
virtual void unpack()
Parses on-wire form of DHCPv4 packet.
Definition: pkt4.cc:150
const isc::asiolink::IOAddress & getSiaddr() const
Returns siaddr field.
Definition: pkt4.h:196
const isc::asiolink::IOAddress & getYiaddr() const
Returns yiaddr field.
Definition: pkt4.h:208
uint8_t getHops() const
Returns hops field.
Definition: pkt4.h:149
std::list< uint16_t > deferred_options_
Definition: pkt4.h:498
virtual HWAddrPtr getMACFromSrcLinkLocalAddr()
No-op.
Definition: pkt4.h:435
HWAddrPtr hwaddr_
link-layer address and hardware information represents 3 fields: htype (hardware type,...
Definition: pkt4.h:513
void setHops(uint8_t hops)
Sets hops field.
Definition: pkt4.h:144
const char * getName() const
Returns name of the DHCP message.
Definition: pkt4.cc:321
HWAddrPtr local_hwaddr_
local HW address (dst if receiving packet, src if sending packet)
Definition: pkt4.h:495
void setSecs(uint16_t secs)
Sets secs field.
Definition: pkt4.h:162
static const size_t MAX_CHADDR_LEN
length of the CHADDR field in DHCPv4 message
Definition: pkt4.h:42
void setLocalHWAddr(const uint8_t htype, const uint8_t hlen, const std::vector< uint8_t > &mac_addr)
Sets local HW address.
Definition: pkt4.cc:454
virtual HWAddrPtr getMACFromDUID()
No-op.
Definition: pkt4.h:469
uint8_t DHCPTypeToBootpType(uint8_t dhcpType)
converts DHCP message type to BOOTP op type
Definition: pkt4.cc:506
const isc::asiolink::IOAddress & getGiaddr() const
Returns giaddr field.
Definition: pkt4.h:220
std::string getLabel() const
Returns text representation of the primary packet identifiers.
Definition: pkt4.cc:329
virtual void pack()
Prepares on-wire format of DHCPv4 packet.
Definition: pkt4.cc:89
isc::asiolink::IOAddress giaddr_
giaddr field (32 bits): Gateway IP address
Definition: pkt4.h:534
uint8_t file_[MAX_FILE_LEN]
file field (128 bytes)
Definition: pkt4.h:540
const isc::asiolink::IOAddress & getCiaddr() const
Returns ciaddr field.
Definition: pkt4.h:183
uint8_t op_
message operation code
Definition: pkt4.h:507
uint16_t getSecs() const
Returns secs field.
Definition: pkt4.h:167
uint8_t hops_
Number of relay agents traversed.
Definition: pkt4.h:516
const OptionBuffer getFile() const
Returns file field.
Definition: pkt4.h:282
const OptionBuffer getSname() const
Returns sname field.
Definition: pkt4.h:267
std::list< uint16_t > & getDeferredOptions()
Returns a reference to option codes which unpacking will be deferred.
Definition: pkt4.h:376
HWAddrPtr getHWAddr() const
returns hardware address information
Definition: pkt4.h:326
virtual HWAddrPtr getMACFromDocsisCMTS()
No-op.
Definition: pkt4.h:480
void setSname(const uint8_t *sname, size_t sname_len)
Sets sname field.
Definition: pkt4.cc:469
uint8_t getHlen() const
Returns hlen field.
Definition: pkt4.cc:541
void setYiaddr(const isc::asiolink::IOAddress &yiaddr)
Sets yiaddr field.
Definition: pkt4.h:214
static const size_t DHCPV4_PKT_HDR_LEN
specifies DHCPv4 packet header length (fixed part)
Definition: pkt4.h:51
bool isRelayed() const
Checks if a DHCPv4 message has been relayed.
Definition: pkt4.cc:561
void setFile(const uint8_t *file, size_t file_len)
Sets file field.
Definition: pkt4.cc:487
static const size_t MAX_SNAME_LEN
length of the SNAME field in DHCPv4 message
Definition: pkt4.h:45
static std::string makeLabel(const HWAddrPtr &hwaddr, const ClientIdPtr &client_id, const uint32_t transid)
Returns text representation of the given packet identifiers.
Definition: pkt4.cc:360
void setSiaddr(const isc::asiolink::IOAddress &siaddr)
Sets siaddr field.
Definition: pkt4.h:202
uint8_t getType() const
Returns DHCP message type (e.g.
Definition: pkt4.cc:230
uint16_t getFlags() const
Returns flags field.
Definition: pkt4.h:177
void setType(uint8_t type)
Sets DHCP message type (e.g.
Definition: pkt4.cc:247
HWAddrPtr getLocalHWAddr() const
Returns local HW address.
Definition: pkt4.h:363
isc::asiolink::IOAddress siaddr_
siaddr field (32 bits): next server IP address in boot process(e.g.TFTP)
Definition: pkt4.h:531
size_t len()
Returns the size of the required buffer to build the packet.
Definition: pkt4.cc:75
uint16_t secs_
elapsed (number of seconds since beginning of transmission)
Definition: pkt4.h:519
isc::asiolink::IOAddress ciaddr_
ciaddr field (32 bits): Client's IP address
Definition: pkt4.h:525
static const uint16_t FLAG_BROADCAST_MASK
Mask for the value of flags field in the DHCPv4 message to check whether client requested broadcast r...
Definition: pkt4.h:55
isc::asiolink::IOAddress yiaddr_
yiaddr field (32 bits): Client's IP address ("your"), set by server
Definition: pkt4.h:528
uint8_t sname_[MAX_SNAME_LEN]
sname field (64 bytes)
Definition: pkt4.h:537
virtual HWAddrPtr getMACFromDocsisModem()
No-op.
Definition: pkt4.h:458
virtual HWAddrPtr getMACFromRemoteIdRelayOption()
No-op.
Definition: pkt4.h:490
virtual bool isDhcp4o6() const
Checks if a DHCPv4 message has been transported over DHCPv6.
Definition: pkt4.h:396
uint8_t getOp() const
Returns op field.
Definition: pkt4.h:157
void setHWAddr(uint8_t htype, uint8_t hlen, const std::vector< uint8_t > &mac_addr)
Sets hardware address.
Definition: pkt4.cc:419
uint8_t getHtype() const
Returns htype field.
Definition: pkt4.cc:533
void setFlags(uint16_t flags)
Sets flags field.
Definition: pkt4.h:172
virtual HWAddrPtr getMACFromIPv6RelayOpt()
No-op.
Definition: pkt4.h:447
uint16_t flags_
flags
Definition: pkt4.h:522
static const size_t MAX_FILE_LEN
length of the FILE field in DHCPv4 message
Definition: pkt4.h:48
void setGiaddr(const isc::asiolink::IOAddress &giaddr)
Sets giaddr field.
Definition: pkt4.h:226
Base class for classes representing DHCP messages.
Definition: pkt.h:90
boost::shared_ptr< Pkt4 > Pkt4Ptr
A pointer to Pkt4 object.
Definition: pkt4.h:546
boost::shared_ptr< HWAddr > HWAddrPtr
Shared pointer to a hardware address structure.
Definition: hwaddr.h:154
boost::shared_ptr< ClientId > ClientIdPtr
Shared pointer to a Client ID.
Definition: duid.h:105
std::vector< uint8_t > OptionBuffer
buffer types used in DHCP code.
Definition: option.h:25
boost::shared_ptr< Option > OptionPtr
Definition: option.h:38
Defines the logger used by the top-level component of kea-dhcp-ddns.