pkt.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  1. // Copyright (C) 2014-2015 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #ifndef PKT_H
  15. #define PKT_H
  16. #include <asiolink/io_address.h>
  17. #include <util/buffer.h>
  18. #include <dhcp/option.h>
  19. #include <dhcp/hwaddr.h>
  20. #include <dhcp/classify.h>
  21. #include <boost/date_time/posix_time/posix_time.hpp>
  22. namespace isc {
  23. namespace dhcp {
  24. /// @brief Base class for classes representing DHCP messages.
  25. ///
  26. /// This is a base class that holds common information (e.g. source
  27. /// and destination ports) and operations (e.g. add, get, delete options)
  28. /// for derived classes representing both DHCPv4 and DHCPv6 messages.
  29. /// The @c Pkt4 and @c Pkt6 classes derive from it.
  30. ///
  31. /// @note This is abstract class. Please instantiate derived classes
  32. /// such as @c Pkt4 or @c Pkt6.
  33. class Pkt {
  34. protected:
  35. /// @brief Constructor.
  36. ///
  37. /// This constructor is typically used for transmitted messages as it
  38. /// creates an empty (no options) packet. The constructor is protected,
  39. /// so only derived classes can call it. Pkt class cannot be instantiated
  40. /// anyway, because it is an abstract class.
  41. ///
  42. /// @param transid transaction-id
  43. /// @param local_addr local IPv4 or IPv6 address
  44. /// @param remote_addr remote IPv4 or IPv6 address
  45. /// @param local_port local UDP (one day also TCP) port
  46. /// @param remote_port remote UDP (one day also TCP) port
  47. Pkt(uint32_t transid, const isc::asiolink::IOAddress& local_addr,
  48. const isc::asiolink::IOAddress& remote_addr, uint16_t local_port,
  49. uint16_t remote_port);
  50. /// @brief Constructor.
  51. ///
  52. /// This constructor is typically used for received messages as it takes
  53. /// a buffer that's going to be parsed as one of arguments. The constructor
  54. /// is protected, so only derived classes can call it. Pkt class cannot be
  55. /// instantiated anyway, because it is an abstract class.
  56. ///
  57. /// @param buf pointer to a buffer that contains on-wire data
  58. /// @param len length of the pointer specified in buf
  59. /// @param local_addr local IPv4 or IPv6 address
  60. /// @param remote_addr remote IPv4 or IPv6 address
  61. /// @param local_port local UDP (one day also TCP) port
  62. /// @param remote_port remote UDP (one day also TCP) port
  63. Pkt(const uint8_t* buf, uint32_t len,
  64. const isc::asiolink::IOAddress& local_addr,
  65. const isc::asiolink::IOAddress& remote_addr, uint16_t local_port,
  66. uint16_t remote_port);
  67. public:
  68. /// @brief Prepares on-wire format of DHCP (either v4 or v6) packet.
  69. ///
  70. /// Prepares on-wire format of message and all its options.
  71. /// A caller must ensure that options are stored in options_ field
  72. /// prior to calling this method.
  73. ///
  74. /// Output buffer will be stored in buffer_out_.
  75. /// The buffer_out_ should be cleared before writting to the buffer
  76. /// in the derived classes.
  77. ///
  78. /// @note This is a pure virtual method and must be implemented in
  79. /// the derived classes. The @c Pkt4 and @c Pkt6 class have respective
  80. /// implementations of this method.
  81. ///
  82. /// @throw InvalidOperation if packing fails
  83. virtual void pack() = 0;
  84. /// @brief Parses on-wire form of DHCP (either v4 or v6) packet.
  85. ///
  86. /// Parses received packet, stored in on-wire format in data_.
  87. ///
  88. /// Will create a collection of option objects that will
  89. /// be stored in options_ container.
  90. ///
  91. /// @note This is a pure virtual method and must be implemented in
  92. /// the derived classes. The @c Pkt4 and @c Pkt6 class have respective
  93. /// implementations of this method.
  94. ///
  95. /// Method will throw exception if packet parsing fails.
  96. ///
  97. /// @throw tbd
  98. virtual void unpack() = 0;
  99. /// @brief Returns reference to output buffer.
  100. ///
  101. /// Returned buffer will contain reasonable data only for
  102. /// output (TX) packet and after pack() was called.
  103. ///
  104. /// RX packet or TX packet before pack() will return buffer with
  105. /// zero length. This buffer is returned as non-const, so hooks
  106. /// framework (and user's callouts) can modify them if needed
  107. ///
  108. /// @note This buffer is only valid till object that returned it exists.
  109. ///
  110. /// @return reference to output buffer
  111. isc::util::OutputBuffer& getBuffer() { return (buffer_out_); };
  112. /// @brief Adds an option to this packet.
  113. ///
  114. /// Derived classes may provide more specialized implementations.
  115. /// In particular @c Pkt4 provides one that checks if option is
  116. /// unique.
  117. ///
  118. /// @param opt option to be added.
  119. virtual void addOption(const OptionPtr& opt);
  120. /// @brief Attempts to delete first suboption of requested type.
  121. ///
  122. /// If there are several options of the same type present, only
  123. /// the first option will be deleted.
  124. ///
  125. /// @param type Type of option to be deleted.
  126. ///
  127. /// @return true if option was deleted, false if no such option existed
  128. bool delOption(uint16_t type);
  129. /// @brief Returns text representation primary packet identifiers
  130. ///
  131. /// This method is intended to be used to provide as a consistent way to
  132. /// identify packets within log statements. Derivations should supply
  133. /// there own implementation.
  134. ///
  135. /// @return string with text representation
  136. virtual std::string getLabel() const {
  137. isc_throw(NotImplemented, "Pkt::getLabel()");
  138. }
  139. /// @brief Returns text representation of the packet.
  140. ///
  141. /// This function is useful mainly for debugging.
  142. ///
  143. /// @note This is a pure virtual method and must be implemented in
  144. /// the derived classes. The @c Pkt4 and @c Pkt6 class have respective
  145. /// implementations of this method.
  146. ///
  147. /// @return string with text representation
  148. virtual std::string toText() const = 0;
  149. /// @brief Returns packet size in binary format.
  150. ///
  151. /// Returns size of the packet in on-wire format or size needed to store
  152. /// it in on-wire format.
  153. ///
  154. /// @note This is a pure virtual method and must be implemented in
  155. /// the derived classes. The @c Pkt4 and @c Pkt6 class have respective
  156. /// implementations of this method.
  157. ///
  158. /// @return packet size in bytes
  159. virtual size_t len() = 0;
  160. /// @brief Returns message type (e.g. 1 = SOLICIT).
  161. ///
  162. /// @note This is a pure virtual method and must be implemented in
  163. /// the derived classes. The @c Pkt4 and @c Pkt6 class have respective
  164. /// implementations of this method.
  165. ///
  166. /// @return message type
  167. virtual uint8_t getType() const = 0;
  168. /// @brief Sets message type (e.g. 1 = SOLICIT).
  169. ///
  170. /// @note This is a pure virtual method and must be implemented in
  171. /// the derived classes. The @c Pkt4 and @c Pkt6 class have respective
  172. /// implementations of this method.
  173. ///
  174. /// @param type message type to be set
  175. virtual void setType(uint8_t type) = 0;
  176. /// @brief Returns name of the DHCP message.
  177. ///
  178. /// For all unsupported messages the derived classes must return
  179. /// "UNKNOWN".
  180. ///
  181. /// @return Ponter to "const" string containing DHCP message name.
  182. /// The implementations in the derived classes should statically
  183. /// allocate returned strings and the caller must not release the
  184. /// returned pointer.
  185. virtual const char* getName() const = 0;
  186. /// @brief Sets transaction-id value.
  187. ///
  188. /// @param transid transaction-id to be set.
  189. void setTransid(uint32_t transid) { transid_ = transid; }
  190. /// @brief Returns value of transaction-id field.
  191. ///
  192. /// @return transaction-id
  193. uint32_t getTransid() const { return (transid_); };
  194. /// @brief Checks whether a client belongs to a given class.
  195. ///
  196. /// @param client_class name of the class
  197. /// @return true if belongs
  198. bool inClass(const isc::dhcp::ClientClass& client_class);
  199. /// @brief Adds packet to a specified class.
  200. ///
  201. /// A packet can be added to the same class repeatedly. Any additional
  202. /// attempts to add to a class the packet already belongs to, will be
  203. /// ignored silently.
  204. ///
  205. /// @note It is a matter of naming convention. Conceptually, the server
  206. /// processes a stream of packets, with some packets belonging to given
  207. /// classes. From that perspective, this method adds a packet to specifed
  208. /// class. Implementation wise, it looks the opposite - the class name
  209. /// is added to the packet. Perhaps the most appropriate name for this
  210. /// method would be associateWithClass()? But that seems overly long,
  211. /// so I decided to stick with addClass().
  212. ///
  213. /// @param client_class name of the class to be added
  214. void addClass(const isc::dhcp::ClientClass& client_class);
  215. /// @brief Unparsed data (in received packets).
  216. ///
  217. /// @warning This public member is accessed by derived
  218. /// classes directly. One of such derived classes is
  219. /// @ref perfdhcp::PerfPkt6. The impact on derived clasess'
  220. /// behavior must be taken into consideration before making
  221. /// changes to this member such as access scope restriction or
  222. /// data format change etc.
  223. OptionBuffer data_;
  224. /// @brief Returns the first option of specified type.
  225. ///
  226. /// Returns the first option of specified type. Note that in DHCPv6 several
  227. /// instances of the same option are allowed (and frequently used).
  228. /// Also see \ref Pkt6::getOptions().
  229. ///
  230. /// The options will be only returned after unpack() is called.
  231. ///
  232. /// @param type option type we are looking for
  233. ///
  234. /// @return pointer to found option (or NULL)
  235. OptionPtr getOption(uint16_t type) const;
  236. /// @brief Update packet timestamp.
  237. ///
  238. /// Updates packet timestamp. This method is invoked
  239. /// by interface manager just before sending or
  240. /// just after receiving it.
  241. /// @throw isc::Unexpected if timestamp update failed
  242. void updateTimestamp();
  243. /// @brief Returns packet timestamp.
  244. ///
  245. /// Returns packet timestamp value updated when
  246. /// packet is received or send.
  247. ///
  248. /// @return packet timestamp.
  249. const boost::posix_time::ptime& getTimestamp() const {
  250. return timestamp_;
  251. }
  252. /// @brief Copies content of input buffer to output buffer.
  253. ///
  254. /// This is mostly a diagnostic function. It is being used for sending
  255. /// received packet. Received packet is stored in data_, but
  256. /// transmitted data is stored in buffer_out_. If we want to send packet
  257. /// that we just received, a copy between those two buffers is necessary.
  258. void repack();
  259. /// @brief Set callback function to be used to parse options.
  260. ///
  261. /// @param callback An instance of the callback function or NULL to
  262. /// uninstall callback.
  263. void setCallback(UnpackOptionsCallback callback) {
  264. callback_ = callback;
  265. }
  266. /// @brief Sets remote IP address.
  267. ///
  268. /// @param remote specifies remote address
  269. void setRemoteAddr(const isc::asiolink::IOAddress& remote) {
  270. remote_addr_ = remote;
  271. }
  272. /// @brief Returns remote IP address.
  273. ///
  274. /// @return remote address
  275. const isc::asiolink::IOAddress& getRemoteAddr() const {
  276. return (remote_addr_);
  277. }
  278. /// @brief Sets local IP address.
  279. ///
  280. /// @param local specifies local address
  281. void setLocalAddr(const isc::asiolink::IOAddress& local) {
  282. local_addr_ = local;
  283. }
  284. /// @brief Returns local IP address.
  285. ///
  286. /// @return local address
  287. const isc::asiolink::IOAddress& getLocalAddr() const {
  288. return (local_addr_);
  289. }
  290. /// @brief Sets local UDP (and soon TCP) port.
  291. ///
  292. /// This sets a local port, i.e. destination port for recently received
  293. /// packet or a source port for to be transmitted packet.
  294. ///
  295. /// @param local specifies local port
  296. void setLocalPort(uint16_t local) {
  297. local_port_ = local;
  298. }
  299. /// @brief Returns local UDP (and soon TCP) port.
  300. ///
  301. /// This sets a local port, i.e. destination port for recently received
  302. /// packet or a source port for to be transmitted packet.
  303. ///
  304. /// @return local port
  305. uint16_t getLocalPort() const {
  306. return (local_port_);
  307. }
  308. /// @brief Sets remote UDP (and soon TCP) port.
  309. ///
  310. /// This sets a remote port, i.e. source port for recently received
  311. /// packet or a destination port for to be transmitted packet.
  312. ///
  313. /// @param remote specifies remote port
  314. void setRemotePort(uint16_t remote) {
  315. remote_port_ = remote;
  316. }
  317. /// @brief Returns remote port.
  318. ///
  319. /// @return remote port
  320. uint16_t getRemotePort() const {
  321. return (remote_port_);
  322. }
  323. /// @brief Sets interface index.
  324. ///
  325. /// @param ifindex specifies interface index.
  326. void setIndex(uint32_t ifindex) {
  327. ifindex_ = ifindex;
  328. };
  329. /// @brief Returns interface index.
  330. ///
  331. /// @return interface index
  332. uint32_t getIndex() const {
  333. return (ifindex_);
  334. };
  335. /// @brief Returns interface name.
  336. ///
  337. /// Returns interface name over which packet was received or is
  338. /// going to be transmitted.
  339. ///
  340. /// @return interface name
  341. std::string getIface() const { return (iface_); };
  342. /// @brief Sets interface name.
  343. ///
  344. /// Sets interface name over which packet was received or is
  345. /// going to be transmitted.
  346. ///
  347. /// @return interface name
  348. void setIface(const std::string& iface ) { iface_ = iface; };
  349. /// @brief Sets remote hardware address.
  350. ///
  351. /// Sets hardware address (MAC) from an existing HWAddr structure.
  352. /// The remote address is a destination address for outgoing
  353. /// packet and source address for incoming packet. When this
  354. /// is an outgoing packet, this address will be used to
  355. /// construct the link layer header.
  356. ///
  357. /// @param hw_addr structure representing HW address.
  358. ///
  359. /// @throw BadValue if addr is null
  360. void setRemoteHWAddr(const HWAddrPtr& hw_addr);
  361. /// @brief Sets remote hardware address.
  362. ///
  363. /// Sets the destination hardware (MAC) address for the outgoing packet
  364. /// or source HW address for the incoming packet. When this
  365. /// is an outgoing packet this address will be used to construct
  366. /// the link layer header.
  367. ///
  368. /// @note mac_addr must be a buffer of at least hlen bytes.
  369. ///
  370. /// In a typical case, hlen field would be redundant, as it could
  371. /// be extracted from mac_addr.size(). However, the difference is
  372. /// when running on exotic hardware, like Infiniband, that had
  373. /// MAC addresses 20 bytes long. In that case, hlen is set to zero
  374. /// in DHCPv4.
  375. ///
  376. /// @param htype hardware type (will be sent in htype field)
  377. /// @param hlen hardware length (will be sent in hlen field)
  378. /// @param hw_addr pointer to hardware address
  379. void setRemoteHWAddr(const uint8_t htype, const uint8_t hlen,
  380. const std::vector<uint8_t>& hw_addr);
  381. /// @brief Returns the remote HW address obtained from raw sockets.
  382. ///
  383. /// @return remote HW address.
  384. HWAddrPtr getRemoteHWAddr() const {
  385. return (remote_hwaddr_);
  386. }
  387. /// @brief Returns MAC address.
  388. ///
  389. /// The difference between this method and getRemoteHWAddr() is that
  390. /// getRemoteHWAddr() returns only what was obtained from raw sockets.
  391. /// This method is more generic and can attempt to obtain MAC from
  392. /// varied sources: raw sockets, client-id, link-local IPv6 address,
  393. /// and various relay options.
  394. ///
  395. /// @note Technically the proper term for this information is a link layer
  396. /// address, but it is frequently referred to MAC or hardware address.
  397. /// Since we're calling the feature "MAC addresses in DHCPv6", we decided
  398. /// to keep the name of getMAC().
  399. ///
  400. /// hw_addr_src takes a combination of bit values specified in
  401. /// HWADDR_SOURCE_* constants.
  402. ///
  403. /// @param hw_addr_src a bitmask that specifies hardware address source
  404. HWAddrPtr getMAC(uint32_t hw_addr_src);
  405. /// @brief Virtual desctructor.
  406. ///
  407. /// There is nothing to clean up here, but since there are virtual methods,
  408. /// we define virtual destructor to ensure that derived classes will have
  409. /// a virtual one, too.
  410. virtual ~Pkt() {
  411. }
  412. /// @brief Classes this packet belongs to.
  413. ///
  414. /// This field is public, so the code outside of Pkt4 or Pkt6 class can
  415. /// iterate over existing classes. Having it public also solves the problem
  416. /// of returned reference lifetime. It is preferred to use @ref inClass and
  417. /// @ref addClass should be used to operate on this field.
  418. ClientClasses classes_;
  419. /// @brief Collection of options present in this message.
  420. ///
  421. /// @warning This public member is accessed by derived
  422. /// classes directly. One of such derived classes is
  423. /// @ref perfdhcp::PerfPkt6. The impact on derived clasess'
  424. /// behavior must be taken into consideration before making
  425. /// changes to this member such as access scope restriction or
  426. /// data format change etc.
  427. isc::dhcp::OptionCollection options_;
  428. protected:
  429. /// @brief Attempts to obtain MAC address from source link-local
  430. /// IPv6 address
  431. ///
  432. /// This method is called from getMAC(HWADDR_SOURCE_IPV6_LINK_LOCAL)
  433. /// and should not be called directly. It is not 100% reliable.
  434. /// The source IPv6 address does not necessarily have to be link-local
  435. /// (may be global or ULA) and even if it's link-local, it doesn't
  436. /// necessarily be based on EUI-64. For example, Windows supports
  437. /// RFC4941, which randomized IID part of the link-local address.
  438. /// If this method fails, it will return NULL.
  439. ///
  440. /// For direct message, it attempts to use remote_addr_ field. For relayed
  441. /// message, it uses peer-addr of the first relay.
  442. ///
  443. /// @note This is a pure virtual method and must be implemented in
  444. /// the derived classes. The @c Pkt6 class have respective implementation.
  445. /// This method is not applicable to DHCPv4.
  446. ///
  447. /// @return hardware address (or NULL)
  448. virtual HWAddrPtr getMACFromSrcLinkLocalAddr() = 0;
  449. /// @brief Attempts to obtain MAC address from relay option
  450. /// client-linklayer-addr
  451. ///
  452. /// This method is called from getMAC(HWADDR_SOURCE_CLIENT_ADDR_RELAY_OPTION)
  453. /// and should not be called directly. It will extract the client's
  454. /// MAC/Hardware address from option client_linklayer_addr (RFC6939)
  455. /// inserted by the relay agent closest to the client.
  456. /// If this method fails, it will return NULL.
  457. ///
  458. /// @note This is a pure virtual method and must be implemented in
  459. /// the derived classes. The @c Pkt6 class have respective implementation.
  460. /// This method is not applicable to DHCPv4.
  461. ///
  462. /// @return hardware address (or NULL)
  463. virtual HWAddrPtr getMACFromIPv6RelayOpt() = 0;
  464. /// @brief Attempts to obtain MAC address from DUID-LL or DUID-LLT.
  465. ///
  466. /// This method is called from getMAC(HWADDR_SOURCE_DUID) and should not be
  467. /// called directly. It will attempt to extract MAC address information
  468. /// from DUID if its type is LLT or LL. If this method fails, it will
  469. /// return NULL.
  470. ///
  471. /// @note This is a pure virtual method and must be implemented in
  472. /// the derived classes. The @c Pkt6 class have respective implementation.
  473. /// This method is not applicable to DHCPv4.
  474. ///
  475. /// @return hardware address (or NULL)
  476. virtual HWAddrPtr getMACFromDUID() = 0;
  477. /// @brief Attempts to obtain MAC address from remote-id relay option.
  478. ///
  479. /// This method is called from getMAC(HWADDR_SOURCE_REMOTE_ID) and should not be
  480. /// called directly. It will attempt to extract MAC address information
  481. /// from remote-id option inserted by a relay agent closest to the client.
  482. /// If this method fails, it will return NULL.
  483. ///
  484. /// @note This is a pure virtual method and must be implemented in
  485. /// the derived classes. The @c Pkt6 class have respective implementation.
  486. /// This method is not applicable to DHCPv4.
  487. ///
  488. /// @return hardware address (or NULL)
  489. virtual HWAddrPtr getMACFromRemoteIdRelayOption() = 0;
  490. /// @brief Attempts to convert IPv6 address into MAC.
  491. ///
  492. /// Utility method that attempts to convert link-local IPv6 address to the
  493. /// MAC address. That works only for link-local IPv6 addresses that are
  494. /// based on EUI-64.
  495. ///
  496. /// @note This method uses hardware type of the interface the packet was
  497. /// received on. If you have multiple access technologies in your network
  498. /// (e.g. client connected to WiFi that relayed the traffic to the server
  499. /// over Ethernet), hardware type may be invalid.
  500. ///
  501. /// @param addr IPv6 address to be converted
  502. /// @return hardware address (or NULL)
  503. HWAddrPtr
  504. getMACFromIPv6(const isc::asiolink::IOAddress& addr);
  505. /// @brief Attempts to extract MAC/Hardware address from DOCSIS options
  506. /// inserted by the modem itself.
  507. ///
  508. /// This is a generic mechanism for extracting hardware address from the
  509. /// DOCSIS options.
  510. ///
  511. /// @note This is a pure virtual method and must be implemented in
  512. /// the derived classes. The @c Pkt6 class have respective implementation.
  513. /// This method is currently not implemented in DHCPv4.
  514. ///
  515. /// @return hardware address (if necessary DOCSIS suboptions are present)
  516. virtual HWAddrPtr getMACFromDocsisModem() = 0;
  517. /// @brief Attempts to extract MAC/Hardware address from DOCSIS options
  518. /// inserted by the CMTS (the relay agent)
  519. ///
  520. /// This is a generic mechanism for extracting hardware address from the
  521. /// DOCSIS options.
  522. ///
  523. /// @note This is a pure virtual method and must be implemented in
  524. /// the derived classes. The @c Pkt6 class have respective implementation.
  525. /// This method is currently not implemented in DHCPv4.
  526. ///
  527. /// @return hardware address (if necessary DOCSIS suboptions are present)
  528. virtual HWAddrPtr getMACFromDocsisCMTS() = 0;
  529. /// Transaction-id (32 bits for v4, 24 bits for v6)
  530. uint32_t transid_;
  531. /// Name of the network interface the packet was received/to be sent over.
  532. std::string iface_;
  533. /// @brief Interface index.
  534. ///
  535. /// Each network interface has assigned an unique ifindex.
  536. /// It is a functional equivalent of a name, but sometimes more useful, e.g.
  537. /// when using odd systems that allow spaces in interface names.
  538. int ifindex_;
  539. /// @brief Local IP (v4 or v6) address.
  540. ///
  541. /// Specifies local IPv4 or IPv6 address. It is a destination address for
  542. /// received packet, and a source address if it packet is being transmitted.
  543. isc::asiolink::IOAddress local_addr_;
  544. /// @brief Remote IP address.
  545. ///
  546. /// Specifies local IPv4 or IPv6 address. It is source address for received
  547. /// packet and a destination address for packet being transmitted.
  548. isc::asiolink::IOAddress remote_addr_;
  549. /// local TDP or UDP port
  550. uint16_t local_port_;
  551. /// remote TCP or UDP port
  552. uint16_t remote_port_;
  553. /// Output buffer (used during message transmission)
  554. ///
  555. /// @warning This protected member is accessed by derived
  556. /// classes directly. One of such derived classes is
  557. /// @ref perfdhcp::PerfPkt6. The impact on derived clasess'
  558. /// behavior must be taken into consideration before making
  559. /// changes to this member such as access scope restriction or
  560. /// data format change etc.
  561. isc::util::OutputBuffer buffer_out_;
  562. /// packet timestamp
  563. boost::posix_time::ptime timestamp_;
  564. // remote HW address (src if receiving packet, dst if sending packet)
  565. HWAddrPtr remote_hwaddr_;
  566. /// A callback to be called to unpack options from the packet.
  567. UnpackOptionsCallback callback_;
  568. private:
  569. /// @brief Generic method that validates and sets HW address.
  570. ///
  571. /// This is a generic method used by all modifiers of this class
  572. /// which set class members representing HW address.
  573. ///
  574. /// @param htype hardware type.
  575. /// @param hlen hardware length.
  576. /// @param hw_addr pointer to actual hardware address.
  577. /// @param [out] storage pointer to a class member to be modified.
  578. ///
  579. /// @trow isc::OutOfRange if invalid HW address specified.
  580. virtual void setHWAddrMember(const uint8_t htype, const uint8_t hlen,
  581. const std::vector<uint8_t>& hw_addr,
  582. HWAddrPtr& storage);
  583. };
  584. }; // namespace isc::dhcp
  585. }; // namespace isc
  586. #endif