dhcp4_srv.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. // Copyright (C) 2011-2013 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 DHCPV4_SRV_H
  15. #define DHCPV4_SRV_H
  16. #include <dhcp/dhcp4.h>
  17. #include <dhcp/pkt4.h>
  18. #include <dhcp/option.h>
  19. #include <dhcp/option4_client_fqdn.h>
  20. #include <dhcp/option_custom.h>
  21. #include <dhcp_ddns/ncr_msg.h>
  22. #include <dhcpsrv/subnet.h>
  23. #include <dhcpsrv/alloc_engine.h>
  24. #include <hooks/callout_handle.h>
  25. #include <boost/noncopyable.hpp>
  26. #include <iostream>
  27. #include <queue>
  28. namespace isc {
  29. namespace dhcp {
  30. /// @brief Exception thrown when DHCID computation failed.
  31. class DhcidComputeError : public isc::Exception {
  32. public:
  33. DhcidComputeError(const char* file, size_t line, const char* what) :
  34. isc::Exception(file, line, what) { };
  35. };
  36. /// @brief DHCPv4 server service.
  37. ///
  38. /// This singleton class represents DHCPv4 server. It contains all
  39. /// top-level methods and routines necessary for server operation.
  40. /// In particular, it instantiates IfaceMgr, loads or generates DUID
  41. /// that is going to be used as server-identifier, receives incoming
  42. /// packets, processes them, manages leases assignment and generates
  43. /// appropriate responses.
  44. ///
  45. /// This class does not support any controlling mechanisms directly.
  46. /// See the derived \ref ControlledDhcpv4Srv class for support for
  47. /// command and configuration updates over msgq.
  48. ///
  49. /// For detailed explanation or relations between main(), ControlledDhcpv4Srv,
  50. /// Dhcpv4Srv and other classes, see \ref dhcpv4Session.
  51. class Dhcpv4Srv : public boost::noncopyable {
  52. public:
  53. /// @brief defines if certain option may, must or must not appear
  54. typedef enum {
  55. FORBIDDEN,
  56. MANDATORY,
  57. OPTIONAL
  58. } RequirementLevel;
  59. /// @brief Default constructor.
  60. ///
  61. /// Instantiates necessary services, required to run DHCPv4 server.
  62. /// In particular, creates IfaceMgr that will be responsible for
  63. /// network interaction. Will instantiate lease manager, and load
  64. /// old or create new DUID. It is possible to specify alternate
  65. /// port on which DHCPv4 server will listen on. That is mostly useful
  66. /// for testing purposes. The Last two arguments of the constructor
  67. /// should be left at default values for normal server operation.
  68. /// They should be set to 'false' when creating an instance of this
  69. /// class for unit testing because features they enable require
  70. /// root privileges.
  71. ///
  72. /// @param port specifies port number to listen on
  73. /// @param dbconfig Lease manager configuration string. The default
  74. /// of the "memfile" manager is used for testing.
  75. /// @param use_bcast configure sockets to support broadcast messages.
  76. /// @param direct_response_desired specifies if it is desired to
  77. /// use direct V4 traffic.
  78. Dhcpv4Srv(uint16_t port = DHCP4_SERVER_PORT,
  79. const char* dbconfig = "type=memfile",
  80. const bool use_bcast = true,
  81. const bool direct_response_desired = true);
  82. /// @brief Destructor. Used during DHCPv4 service shutdown.
  83. virtual ~Dhcpv4Srv();
  84. /// @brief Main server processing loop.
  85. ///
  86. /// Main server processing loop. Receives incoming packets, verifies
  87. /// their correctness, generates appropriate answer (if needed) and
  88. /// transmits respones.
  89. ///
  90. /// @return true, if being shut down gracefully, fail if experienced
  91. /// critical error.
  92. bool run();
  93. /// @brief Instructs the server to shut down.
  94. void shutdown();
  95. /// @brief Return textual type of packet received by server
  96. ///
  97. /// Returns the name of valid packet received by the server (e.g. DISCOVER).
  98. /// If the packet is unknown - or if it is a valid DHCP packet but not one
  99. /// expected to be received by the server (such as an OFFER), the string
  100. /// "UNKNOWN" is returned. This method is used in debug messages.
  101. ///
  102. /// As the operation of the method does not depend on any server state, it
  103. /// is declared static.
  104. ///
  105. /// @todo: This should be named static Pkt4::getName()
  106. ///
  107. /// @param type DHCPv4 packet type
  108. ///
  109. /// @return Pointer to "const" string containing the packet name.
  110. /// Note that this string is statically allocated and MUST NOT
  111. /// be freed by the caller.
  112. static const char* serverReceivedPacketName(uint8_t type);
  113. ///
  114. /// @name Public accessors returning values required to (re)open sockets.
  115. ///
  116. /// These accessors must be public because sockets are reopened from the
  117. /// static configuration callback handler. This callback handler invokes
  118. /// @c ControlledDhcpv4Srv::openActiveSockets which requires parameters
  119. /// which has to be retrieved from the @c ControlledDhcpv4Srv object.
  120. /// They are retrieved using these public functions
  121. //@{
  122. ///
  123. /// @brief Get UDP port on which server should listen.
  124. ///
  125. /// Typically, server listens on UDP port number 67. Other ports are used
  126. /// for testing purposes only.
  127. ///
  128. /// @return UDP port on which server should listen.
  129. uint16_t getPort() const {
  130. return (port_);
  131. }
  132. /// @brief Return bool value indicating that broadcast flags should be set
  133. /// on sockets.
  134. ///
  135. /// @return A bool value indicating that broadcast should be used (if true).
  136. bool useBroadcast() const {
  137. return (use_bcast_);
  138. }
  139. //@}
  140. /// @brief Open sockets which are marked as active in @c CfgMgr.
  141. ///
  142. /// This function reopens sockets according to the current settings in the
  143. /// Configuration Manager. It holds the list of the interfaces which server
  144. /// should listen on. This function will open sockets on these interfaces
  145. /// only. This function is not exception safe.
  146. ///
  147. /// @param port UDP port on which server should listen.
  148. /// @param use_bcast should broadcast flags be set on the sockets.
  149. static void openActiveSockets(const uint16_t port, const bool use_bcast);
  150. protected:
  151. /// @brief verifies if specified packet meets RFC requirements
  152. ///
  153. /// Checks if mandatory option is really there, that forbidden option
  154. /// is not there, and that client-id or server-id appears only once.
  155. ///
  156. /// @param pkt packet to be checked
  157. /// @param serverid expectation regarding server-id option
  158. /// @throw RFCViolation if any issues are detected
  159. static void sanityCheck(const Pkt4Ptr& pkt, RequirementLevel serverid);
  160. /// @brief Processes incoming DISCOVER and returns response.
  161. ///
  162. /// Processes received DISCOVER message and verifies that its sender
  163. /// should be served. In particular, a lease is selected and sent
  164. /// as an offer to a client if it should be served.
  165. ///
  166. /// @param discover DISCOVER message received from client
  167. ///
  168. /// @return OFFER message or NULL
  169. Pkt4Ptr processDiscover(Pkt4Ptr& discover);
  170. /// @brief Processes incoming REQUEST and returns REPLY response.
  171. ///
  172. /// Processes incoming REQUEST message and verifies that its sender
  173. /// should be served. In particular, verifies that requested lease
  174. /// is valid, not expired, not reserved, not used by other client and
  175. /// that requesting client is allowed to use it.
  176. ///
  177. /// Returns ACK message, NAK message, or NULL
  178. ///
  179. /// @param request a message received from client
  180. ///
  181. /// @return ACK or NAK message
  182. Pkt4Ptr processRequest(Pkt4Ptr& request);
  183. /// @brief Stub function that will handle incoming RELEASE messages.
  184. ///
  185. /// In DHCPv4, server does not respond to RELEASE messages, therefore
  186. /// this function does not return anything.
  187. ///
  188. /// @param release message received from client
  189. void processRelease(Pkt4Ptr& release);
  190. /// @brief Stub function that will handle incoming DHCPDECLINE messages.
  191. ///
  192. /// @param decline message received from client
  193. void processDecline(Pkt4Ptr& decline);
  194. /// @brief Stub function that will handle incoming INFORM messages.
  195. ///
  196. /// @param inform message received from client
  197. Pkt4Ptr processInform(Pkt4Ptr& inform);
  198. /// @brief Copies default parameters from client's to server's message
  199. ///
  200. /// Some fields are copied from client's message into server's response,
  201. /// e.g. client HW address, number of hops, transaction-id etc.
  202. ///
  203. /// @param question any message sent by client
  204. /// @param answer any message server is going to send as response
  205. void copyDefaultFields(const Pkt4Ptr& question, Pkt4Ptr& answer);
  206. /// @brief Appends options requested by client.
  207. ///
  208. /// This method assigns options that were requested by client
  209. /// (sent in PRL) or are enforced by server.
  210. ///
  211. /// @param question DISCOVER or REQUEST message from a client.
  212. /// @param msg outgoing message (options will be added here)
  213. void appendRequestedOptions(const Pkt4Ptr& question, Pkt4Ptr& msg);
  214. /// @brief Appends requested vendor options as requested by client.
  215. ///
  216. /// This method is similar to \ref appendRequestedOptions(), but uses
  217. /// vendor options. The major difference is that vendor-options use
  218. /// its own option spaces (there may be more than one distinct set of vendor
  219. /// options, each with unique vendor-id). Vendor options are requested
  220. /// using separate options within their respective vendor-option spaces.
  221. ///
  222. /// @param question DISCOVER or REQUEST message from a client.
  223. /// @param msg outgoing message (options will be added here)
  224. void appendRequestedVendorOptions(const Pkt4Ptr& question, Pkt4Ptr& answer);
  225. /// @brief Assigns a lease and appends corresponding options
  226. ///
  227. /// This method chooses the most appropriate lease for reqesting
  228. /// client and assigning it. Options corresponding to the lease
  229. /// are added to specific message.
  230. ///
  231. /// @param question DISCOVER or REQUEST message from client
  232. /// @param answer OFFER or ACK/NAK message (lease options will be added here)
  233. void assignLease(const Pkt4Ptr& question, Pkt4Ptr& answer);
  234. /// @brief Append basic options if they are not present.
  235. ///
  236. /// This function adds the following basic options if they
  237. /// are not yet added to the message:
  238. /// - Subnet Mask,
  239. /// - Router,
  240. /// - Name Server,
  241. /// - Domain Name.
  242. ///
  243. /// @param question DISCOVER or REQUEST message from a client.
  244. /// @param msg the message to add options to.
  245. void appendBasicOptions(const Pkt4Ptr& question, Pkt4Ptr& msg);
  246. /// @brief Processes Client FQDN and Hostname Options sent by a client.
  247. ///
  248. /// Client may send Client FQDN or Hostname option to communicate its name
  249. /// to the server. Server may use this name to perform DNS update for the
  250. /// lease being assigned to a client. If server takes responsibility for
  251. /// updating DNS for a client it may communicate it by sending the Client
  252. /// FQDN or Hostname %Option back to the client. Server select a different
  253. /// name than requested by a client to update DNS. In such case, the server
  254. /// stores this different name in its response.
  255. ///
  256. /// Client should not send both Client FQDN and Hostname options. However,
  257. /// if client sends both options, server should prefer Client FQDN option
  258. /// and ignore the Hostname option. If Client FQDN option is not present,
  259. /// the Hostname option is processed.
  260. ///
  261. /// The Client FQDN %Option is processed by this function as described in
  262. /// RFC4702.
  263. ///
  264. /// In response to a Hostname %Option sent by a client, the server may send
  265. /// Hostname option with the same or different hostname. If different
  266. /// hostname is sent, it is an indication to the client that server has
  267. /// overridden the client's preferred name and will rather use this
  268. /// different name to update DNS. However, since Hostname option doesn't
  269. /// carry an information whether DNS update will be carried by the server
  270. /// or not, the client is responsible for checking whether DNS update
  271. /// has been performed.
  272. ///
  273. /// After successful processing options stored in the first parameter,
  274. /// this function may add Client FQDN or Hostname option to the response
  275. /// message. In some cases, server may cease to add any options to the
  276. /// response, i.e. when server doesn't support DNS updates.
  277. ///
  278. /// This function does not throw. It simply logs the debug message if the
  279. /// processing of the FQDN or Hostname failed.
  280. ///
  281. /// @param query A DISCOVER or REQUEST message from a cient.
  282. /// @param [out] answer A response message to be sent to a client.
  283. void processClientName(const Pkt4Ptr& query, Pkt4Ptr& answer);
  284. private:
  285. /// @brief Process Client FQDN %Option sent by a client.
  286. ///
  287. /// This function is called by the @c Dhcpv4Srv::processClientName when
  288. /// the client has sent the FQDN option in its message to the server.
  289. /// It comprises the actual logic to parse the FQDN option and prepare
  290. /// the FQDN option to be sent back to the client in the server's
  291. /// response.
  292. ///
  293. /// @param fqdn An DHCPv4 Client FQDN %Option sent by a client.
  294. /// @param [out] answer A response message to be sent to a client.
  295. void processClientFqdnOption(const Option4ClientFqdnPtr& fqdn,
  296. Pkt4Ptr& answer);
  297. /// @brief Process Hostname %Option sent by a client.
  298. ///
  299. /// This function is called by the @c DHcpv4Srv::processClientName when
  300. /// the client has sent the Hostname option in its message to the server.
  301. /// It comprises the actual logic to parse the Hostname option and
  302. /// prepare the Hostname option to be sent back to the client in the
  303. /// server's response.
  304. ///
  305. /// @param opt_hostname An @c OptionCustom object encapsulating the Hostname
  306. /// %Option.
  307. /// @param [out] answer A response message to be sent to a client.
  308. void processHostnameOption(const OptionCustomPtr& opt_hostname,
  309. Pkt4Ptr& answer);
  310. protected:
  311. /// @brief Creates NameChangeRequests which correspond to the lease
  312. /// which has been acquired.
  313. ///
  314. /// If this function is called whe an existing lease is renewed, it
  315. /// may generate NameChangeRequest to remove existing DNS entries which
  316. /// correspond to the old lease instance. This function may cease to
  317. /// generate NameChangeRequests if the notion of the client's FQDN hasn't
  318. /// changed between an old and new lease.
  319. ///
  320. /// @param lease A pointer to the new lease which has been acquired.
  321. /// @param old_lease A pointer to the instance of the old lease which has
  322. /// been replaced by the new lease passed in the first argument. The NULL
  323. /// value indicates that the new lease has been allocated, rather than
  324. /// lease being renewed.
  325. void createNameChangeRequests(const Lease4Ptr& lease,
  326. const Lease4Ptr& old_lease);
  327. /// @brief Creates the NameChangeRequest and adds to the queue for
  328. /// processing.
  329. ///
  330. /// This function adds the @c isc::dhcp_ddns::NameChangeRequest to the
  331. /// queue and emits the debug message which indicates whether the request
  332. /// being added is to remove DNS entry or add a new entry. This function
  333. /// is exception free.
  334. ///
  335. /// @param chg_type A type of the NameChangeRequest (ADD or REMOVE).
  336. /// @param lease A lease for which the NameChangeRequest is created and
  337. /// queued.
  338. void queueNameChangeRequest(const isc::dhcp_ddns::NameChangeType chg_type,
  339. const Lease4Ptr& lease);
  340. /// @brief Sends all outstanding NameChangeRequests to b10-dhcp-ddns module.
  341. ///
  342. /// The purpose of this function is to pick all outstanding
  343. /// NameChangeRequests from the FIFO queue and send them to b10-dhcp-ddns
  344. /// module.
  345. ///
  346. /// @todo Currently this function simply removes all requests from the
  347. /// queue but doesn't send them anywhere. In the future, the
  348. /// NameChangeSender will be used to deliver requests to the other module.
  349. void sendNameChangeRequests();
  350. /// @brief Attempts to renew received addresses
  351. ///
  352. /// Attempts to renew existing lease. This typically includes finding a lease that
  353. /// corresponds to the received address. If no such lease is found, a status code
  354. /// response is generated.
  355. ///
  356. /// @param renew client's message asking for renew
  357. /// @param reply server's response (ACK or NAK)
  358. void renewLease(const Pkt4Ptr& renew, Pkt4Ptr& reply);
  359. /// @brief Appends default options to a message
  360. ///
  361. /// Currently it is only a Message Type option. This function does not add
  362. /// the Server Identifier option as this option must be added using
  363. /// @c Dhcpv4Srv::appendServerID.
  364. ///
  365. ///
  366. /// @param msg message object (options will be added to it)
  367. /// @param msg_type specifies message type
  368. void appendDefaultOptions(Pkt4Ptr& msg, uint8_t msg_type);
  369. /// @brief Adds server identifier option to the server's response.
  370. ///
  371. /// This method adds a server identifier to the DHCPv4 message. It epxects
  372. /// that the local (source) address is set for this message. If address is
  373. /// not set, it will throw an exception. This method also expects that the
  374. /// server identifier option is not present in the specified message.
  375. /// Otherwise, it will throw an exception on attempt to add a duplicate
  376. /// server identifier option.
  377. ///
  378. /// @note This method doesn't throw exceptions by itself but the underlying
  379. /// classes being used my throw. The reason for this method to not sanity
  380. /// check the specified message is that it is meant to be called internally
  381. /// by the @c Dhcpv4Srv class.
  382. ///
  383. /// @note This method is static because it is not dependent on the class
  384. /// state.
  385. ///
  386. /// @param [out] response DHCPv4 message to which the server identifier
  387. /// option should be added.
  388. static void appendServerID(const Pkt4Ptr& response);
  389. /// @brief Set IP/UDP and interface parameters for the DHCPv4 response.
  390. ///
  391. /// This method sets the following parameters for the DHCPv4 message being
  392. /// sent to a client:
  393. /// - client unicast or a broadcast address,
  394. /// - client or relay port,
  395. /// - server address,
  396. /// - server port,
  397. /// - name and index of the interface which is to be used to send the
  398. /// message.
  399. ///
  400. /// Internally it calls the @c Dhcpv4Srv::adjustRemoteAddr to figure
  401. /// out the destination address (client unicast address or broadcast
  402. /// address).
  403. ///
  404. /// The destination port is always DHCPv4 client (68) or relay (67) port,
  405. /// depending if the response will be sent directly to a client.
  406. ///
  407. /// The source port is always set to DHCPv4 server port (67).
  408. ///
  409. /// The interface selected for the response is always the same as the
  410. /// one through which the query has been received.
  411. ///
  412. /// The source address for the response is the IPv4 address assigned to
  413. /// the interface being used to send the response. This function uses
  414. /// @c IfaceMgr to get the socket bound to the IPv4 address on the
  415. /// particular interface.
  416. ///
  417. /// @note This method is static because it is not dependent on the class
  418. /// state.
  419. static void adjustIfaceData(const Pkt4Ptr& query, const Pkt4Ptr& response);
  420. /// @brief Sets remote addresses for outgoing packet.
  421. ///
  422. /// This method sets the local and remote addresses on outgoing packet.
  423. /// The addresses being set depend on the following conditions:
  424. /// - has incoming packet been relayed,
  425. /// - is direct response to a client without address supported,
  426. /// - type of the outgoing packet,
  427. /// - broadcast flag set in the incoming packet.
  428. ///
  429. /// @warning This method does not check whether provided packet pointers
  430. /// are valid. Make sure that pointers are correct before calling this
  431. /// function.
  432. ///
  433. /// @note This method is static because it is not dependent on the class
  434. /// state.
  435. ///
  436. /// @param question instance of a packet received by a server.
  437. /// @param [out] response response packet which addresses are to be
  438. /// adjusted.
  439. static void adjustRemoteAddr(const Pkt4Ptr& question,
  440. const Pkt4Ptr& response);
  441. /// @brief converts server-id to text
  442. /// Converts content of server-id option to a text representation, e.g.
  443. /// "192.0.2.1"
  444. ///
  445. /// @param opt option that contains server-id
  446. /// @return string representation
  447. static std::string srvidToString(const OptionPtr& opt);
  448. /// @brief Computes DHCID from a lease.
  449. ///
  450. /// This method creates an object which represents DHCID. The DHCID value
  451. /// is computed as described in RFC4701. The section 3.3. of RFC4701
  452. /// specifies the DHCID RR Identifier Type codes:
  453. /// - 0x0000 The 1 octet htype followed by glen octets of chaddr
  454. /// - 0x0001 The data octets from the DHCPv4 client's Client Identifier
  455. /// option.
  456. /// - 0x0002 The client's DUID.
  457. ///
  458. /// Currently this function supports first two of these identifiers.
  459. /// The 0x0001 is preferred over the 0x0000 - if the client identifier
  460. /// option is present, the former is used. If the client identifier
  461. /// is absent, the latter is used.
  462. ///
  463. /// @todo Implement support for 0x0002 DHCID identifier type.
  464. ///
  465. /// @param lease A pointer to the structure describing a lease.
  466. /// @return An object encapsulating DHCID to be used for DNS updates.
  467. /// @throw DhcidComputeError If the computation of the DHCID failed.
  468. static isc::dhcp_ddns::D2Dhcid computeDhcid(const Lease4Ptr& lease);
  469. /// @brief Selects a subnet for a given client's packet.
  470. ///
  471. /// @param question client's message
  472. /// @return selected subnet (or NULL if no suitable subnet was found)
  473. isc::dhcp::Subnet4Ptr selectSubnet(const Pkt4Ptr& question);
  474. /// indicates if shutdown is in progress. Setting it to true will
  475. /// initiate server shutdown procedure.
  476. volatile bool shutdown_;
  477. /// @brief dummy wrapper around IfaceMgr::receive4
  478. ///
  479. /// This method is useful for testing purposes, where its replacement
  480. /// simulates reception of a packet. For that purpose it is protected.
  481. virtual Pkt4Ptr receivePacket(int timeout);
  482. /// @brief dummy wrapper around IfaceMgr::send()
  483. ///
  484. /// This method is useful for testing purposes, where its replacement
  485. /// simulates transmission of a packet. For that purpose it is protected.
  486. virtual void sendPacket(const Pkt4Ptr& pkt);
  487. /// @brief Implements a callback function to parse options in the message.
  488. ///
  489. /// @param buf a A buffer holding options in on-wire format.
  490. /// @param option_space A name of the option space which holds definitions
  491. /// of to be used to parse options in the packets.
  492. /// @param [out] options A reference to the collection where parsed options
  493. /// will be stored.
  494. /// @return An offset to the first byte after last parsed option.
  495. size_t unpackOptions(const OptionBuffer& buf,
  496. const std::string& option_space,
  497. isc::dhcp::OptionCollection& options);
  498. private:
  499. /// @brief Constructs netmask option based on subnet4
  500. /// @param subnet subnet for which the netmask will be calculated
  501. ///
  502. /// @return Option that contains netmask information
  503. static OptionPtr getNetmaskOption(const Subnet4Ptr& subnet);
  504. /// @brief Implements the error handler for socket open failure.
  505. ///
  506. /// This callback function is installed on the @c isc::dhcp::IfaceMgr
  507. /// when IPv4 sockets are being open. When socket fails to open for
  508. /// any reason, this function is called. It simply logs the error message.
  509. ///
  510. /// @param errmsg An error message containing a cause of the failure.
  511. static void ifaceMgrSocket4ErrorHandler(const std::string& errmsg);
  512. /// @brief Allocation Engine.
  513. /// Pointer to the allocation engine that we are currently using
  514. /// It must be a pointer, because we will support changing engines
  515. /// during normal operation (e.g. to use different allocators)
  516. boost::shared_ptr<AllocEngine> alloc_engine_;
  517. uint16_t port_; ///< UDP port number on which server listens.
  518. bool use_bcast_; ///< Should broadcast be enabled on sockets (if true).
  519. /// Indexes for registered hook points
  520. int hook_index_pkt4_receive_;
  521. int hook_index_subnet4_select_;
  522. int hook_index_pkt4_send_;
  523. protected:
  524. /// Holds a list of @c isc::dhcp_ddns::NameChangeRequest objects which
  525. /// are waiting for sending to b10-dhcp-ddns module.
  526. std::queue<isc::dhcp_ddns::NameChangeRequest> name_change_reqs_;
  527. };
  528. }; // namespace isc::dhcp
  529. }; // namespace isc
  530. #endif // DHCP4_SRV_H