dhcp4_srv.h 31 KB
 Tomek Mrugalski committed May 21, 2014 1 // Copyright (C) 2011-2014 Internet Systems Consortium, Inc. ("ISC")  Tomek Mrugalski committed Nov 27, 2011 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 // // Permission to use, copy, modify, and/or distribute this software for any // purpose with or without fee is hereby granted, provided that the above // copyright notice and this permission notice appear in all copies. // // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR // PERFORMANCE OF THIS SOFTWARE. #ifndef DHCPV4_SRV_H #define DHCPV4_SRV_H  Tomek Mrugalski committed Dec 05, 2011 18 #include  Tomek Mrugalski committed Nov 27, 2011 19 20 #include #include  Thomas Markwalder committed Feb 19, 2014 21 #include  Marcin Siodelski committed Aug 28, 2013 22 #include  Marcin Siodelski committed Sep 09, 2013 23 #include  Marcin Siodelski committed Sep 02, 2013 24 #include  Thomas Markwalder committed Feb 13, 2014 25 #include  Tomek Mrugalski committed Dec 31, 2012 26 27 #include #include  Tomek Mrugalski committed Jul 15, 2013 28 #include  Tomek Mrugalski committed May 21, 2014 29 #include  Stephen Morris committed Nov 16, 2012 30 31 32  #include  Tomek Mrugalski committed Nov 27, 2011 33 #include  Marcin Siodelski committed Sep 03, 2013 34 #include  Tomek Mrugalski committed Nov 27, 2011 35 36 37  namespace isc { namespace dhcp {  Tomek Mrugalski committed Dec 31, 2012 38   Marcin Siodelski committed Sep 03, 2013 39 40 41 42 43 44 45 /// @brief Exception thrown when DHCID computation failed. class DhcidComputeError : public isc::Exception { public: DhcidComputeError(const char* file, size_t line, const char* what) : isc::Exception(file, line, what) { }; };  Tomek Mrugalski committed Nov 27, 2011 46 47 48 49 50 51 52 53 /// @brief DHCPv4 server service. /// /// This singleton class represents DHCPv4 server. It contains all /// top-level methods and routines necessary for server operation. /// In particular, it instantiates IfaceMgr, loads or generates DUID /// that is going to be used as server-identifier, receives incoming /// packets, processes them, manages leases assignment and generates /// appropriate responses.  Tomek Mrugalski committed Jun 08, 2012 54 55 /// /// This class does not support any controlling mechanisms directly.  Stephen Morris committed Dec 10, 2012 56 /// See the derived \ref ControlledDhcpv4Srv class for support for  Tomek Mrugalski committed Jun 08, 2012 57 58 59 60 /// command and configuration updates over msgq. /// /// For detailed explanation or relations between main(), ControlledDhcpv4Srv, /// Dhcpv4Srv and other classes, see \ref dhcpv4Session.  Tomek Mrugalski committed May 21, 2014 61 class Dhcpv4Srv : public Daemon {  Tomek Mrugalski committed Nov 27, 2011 62   Marcin Siodelski committed May 22, 2013 63 public:  Tomek Mrugalski committed Dec 31, 2012 64 65 66 67 68 69 70 71  /// @brief defines if certain option may, must or must not appear typedef enum { FORBIDDEN, MANDATORY, OPTIONAL } RequirementLevel;  Tomek Mrugalski committed Nov 27, 2011 72 73  /// @brief Default constructor. ///  Stephen Morris committed Sep 12, 2012 74  /// Instantiates necessary services, required to run DHCPv4 server.  Tomek Mrugalski committed Nov 27, 2011 75 76  /// In particular, creates IfaceMgr that will be responsible for /// network interaction. Will instantiate lease manager, and load  Tomek Mrugalski committed Dec 12, 2011 77 78  /// old or create new DUID. It is possible to specify alternate /// port on which DHCPv4 server will listen on. That is mostly useful  Marcin Siodelski committed Apr 29, 2013 79 80  /// for testing purposes. The Last two arguments of the constructor /// should be left at default values for normal server operation.  Marcin Siodelski committed Apr 30, 2013 81 82 83  /// They should be set to 'false' when creating an instance of this /// class for unit testing because features they enable require /// root privileges.  Tomek Mrugalski committed Dec 12, 2011 84 85  /// /// @param port specifies port number to listen on  Marcin Siodelski committed Apr 04, 2013 86  /// @param use_bcast configure sockets to support broadcast messages.  Marcin Siodelski committed Apr 30, 2013 87 88  /// @param direct_response_desired specifies if it is desired to /// use direct V4 traffic.  Tomek Mrugalski committed Dec 31, 2012 89  Dhcpv4Srv(uint16_t port = DHCP4_SERVER_PORT,  Marcin Siodelski committed Apr 29, 2013 90 91  const bool use_bcast = true, const bool direct_response_desired = true);  Tomek Mrugalski committed Nov 27, 2011 92   Stephen Morris committed Sep 12, 2012 93  /// @brief Destructor. Used during DHCPv4 service shutdown.  Mukund Sivaraman committed Jul 24, 2013 94  virtual ~Dhcpv4Srv();  Tomek Mrugalski committed Nov 27, 2011 95 96 97 98 99 100 101 102 103 104 105  /// @brief Main server processing loop. /// /// Main server processing loop. Receives incoming packets, verifies /// their correctness, generates appropriate answer (if needed) and /// transmits respones. /// /// @return true, if being shut down gracefully, fail if experienced /// critical error. bool run();  Tomek Mrugalski committed Jun 08, 2012 106  /// @brief Instructs the server to shut down.  Tomek Mrugalski committed May 30, 2012 107 108  void shutdown();  Stephen Morris committed Sep 06, 2012 109 110 111 112 113  /// @brief Return textual type of packet received by server /// /// Returns the name of valid packet received by the server (e.g. DISCOVER). /// If the packet is unknown - or if it is a valid DHCP packet but not one /// expected to be received by the server (such as an OFFER), the string  Stephen Morris committed Sep 12, 2012 114  /// "UNKNOWN" is returned. This method is used in debug messages.  Stephen Morris committed Sep 06, 2012 115 116 117 118  /// /// As the operation of the method does not depend on any server state, it /// is declared static. ///  Tomek Mrugalski committed Dec 31, 2012 119 120  /// @todo: This should be named static Pkt4::getName() ///  Stephen Morris committed Sep 06, 2012 121 122 123 124 125 126 127  /// @param type DHCPv4 packet type /// /// @return Pointer to "const" string containing the packet name. /// Note that this string is statically allocated and MUST NOT /// be freed by the caller. static const char* serverReceivedPacketName(uint8_t type);  Marcin Siodelski committed Jul 11, 2013 128 129 130 131 132 133 134 135 136 137 138 139  /// /// @name Public accessors returning values required to (re)open sockets. /// /// These accessors must be public because sockets are reopened from the /// static configuration callback handler. This callback handler invokes /// @c ControlledDhcpv4Srv::openActiveSockets which requires parameters /// which has to be retrieved from the @c ControlledDhcpv4Srv object. /// They are retrieved using these public functions //@{ /// /// @brief Get UDP port on which server should listen. ///  Marcin Siodelski committed Jul 19, 2013 140 141 142  /// Typically, server listens on UDP port number 67. Other ports are used /// for testing purposes only. ///  Marcin Siodelski committed Jul 11, 2013 143 144 145 146 147 148 149 150 151 152 153 154 155 156  /// @return UDP port on which server should listen. uint16_t getPort() const { return (port_); } /// @brief Return bool value indicating that broadcast flags should be set /// on sockets. /// /// @return A bool value indicating that broadcast should be used (if true). bool useBroadcast() const { return (use_bcast_); } //@}  Marcin Siodelski committed Jul 19, 2013 157 158 159 160 161 162 163 164 165 166 167  /// @brief Open sockets which are marked as active in @c CfgMgr. /// /// This function reopens sockets according to the current settings in the /// Configuration Manager. It holds the list of the interfaces which server /// should listen on. This function will open sockets on these interfaces /// only. This function is not exception safe. /// /// @param port UDP port on which server should listen. /// @param use_bcast should broadcast flags be set on the sockets. static void openActiveSockets(const uint16_t port, const bool use_bcast);  Thomas Markwalder committed Feb 13, 2014 168 169 170 171 172 173 174 175 176  /// @brief Starts DHCP_DDNS client IO if DDNS updates are enabled. /// /// If updates are enabled, it Instructs the D2ClientMgr singleton to /// enter send mode. If D2ClientMgr encounters errors it may throw /// D2ClientErrors. This method does not catch exceptions. void startD2(); /// @brief Implements the error handler for DHCP_DDNS IO errors ///  Marcin Siodelski committed Jul 02, 2014 177  /// Invoked when a NameChangeRequest send to kea-dhcp-ddns completes with  Thomas Markwalder committed Feb 13, 2014 178 179 180 181 182 183 184 185 186 187 188 189 190 191  /// a failed status. These are communications errors, not data related /// failures. /// /// This method logs the failure and then suspends all further updates. /// Updating can only be restored by reconfiguration or restarting the /// server. There is currently no retry logic so the first IO error that /// occurs will suspend updates. /// @todo We may wish to make this more robust or sophisticated. /// /// @param result Result code of the send operation. /// @param ncr NameChangeRequest which failed to send. virtual void d2ClientErrorHandler(const dhcp_ddns:: NameChangeSender::Result result, dhcp_ddns::NameChangeRequestPtr& ncr);  Tomek Mrugalski committed Nov 27, 2011 192 protected:  Tomek Mrugalski committed Dec 31, 2012 193   Marcin Siodelski committed Feb 06, 2014 194 195 196 197 198 199 200  /// @name Functions filtering and sanity-checking received messages. /// /// @todo These functions are supposed to be moved to a new class which /// will manage different rules for accepting and rejecting messages. /// Perhaps ticket #3116 is a good opportunity to do it. /// //@{  Marcin Siodelski committed Feb 03, 2014 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241  /// @brief Checks whether received message should be processed or discarded. /// /// This function checks whether received message should be processed or /// discarded. It should be called on the beginning of message processing /// (just after the message has been decoded). This message calls a number /// of other functions which check whether message should be processed, /// using different criteria. /// /// This function should be extended when new criteria for accepting /// received message have to be implemented. This function is meant to /// aggregate all early filtering checks on the received message. By having /// a single function like this, we are avoiding bloat of the server's main /// loop. /// /// @warning This function should remain exception safe. /// /// @param query Received message. /// /// @return true if the message should be further processed, or false if /// the message should be discarded. bool accept(const Pkt4Ptr& query) const; /// @brief Check if a message sent by directly connected client should be /// accepted or discared. /// /// This function checks if the received message is from directly connected /// client. If it is, it checks that it should be processed or discarded. /// /// Note that this function doesn't validate all addresses being carried in /// the message. The primary purpose of this function is to filter out /// direct messages in the local network for which there is no suitable /// subnet configured. For example, this function accepts unicast messages /// because unicasts may be used by clients located in remote networks to /// to renew existing leases. If their notion of address is wrong, the /// server will have to sent a NAK, instead of dropping the message. /// Detailed validation of such messages is performed at later stage of /// processing. /// /// This function accepts the following messages: /// - all valid relayed messages, /// - all unicast messages,  Marcin Siodelski committed Jul 15, 2014 242 243 244  /// - all broadcast messages except DHCPINFORM received on the interface /// for which the suitable subnet exists (is configured). /// - all DHCPINFORM messages with source address or ciaddr set.  Marcin Siodelski committed Feb 03, 2014 245  ///  Marcin Siodelski committed Feb 06, 2014 246  /// @param query Message sent by a client.  Marcin Siodelski committed Feb 03, 2014 247 248 249  /// /// @return true if message is accepted for further processing, false /// otherwise.  Marcin Siodelski committed Feb 06, 2014 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270  bool acceptDirectRequest(const Pkt4Ptr& query) const; /// @brief Check if received message type is valid for the server to /// process. /// /// This function checks that the received message type belongs to the range /// of types regonized by the server and that the message of this type /// should be processed by the server. /// /// The messages types accepted for processing are: /// - Discover /// - Request /// - Release /// - Decline /// - Inform /// /// @param query Message sent by a client. /// /// @return true if message is accepted for further processing, false /// otherwise. bool acceptMessageType(const Pkt4Ptr& query) const;  Marcin Siodelski committed Feb 03, 2014 271   Marcin Siodelski committed Jan 13, 2014 272 273 274 275 276 277 278 279 280 281 282 283 284 285  /// @brief Verifies if the server id belongs to our server. /// /// This function checks if the server identifier carried in the specified /// DHCPv4 message belongs to this server. If the server identifier option /// is absent or the value carried by this option is equal to one of the /// server identifiers used by the server, the true is returned. If the /// server identifier option is present, but it doesn't match any server /// identifier used by this server, the false value is returned. /// /// @param pkt DHCPv4 message which server identifier is to be checked. /// /// @return true, if the server identifier is absent or matches one of the /// server identifiers that the server is using; false otherwise. bool acceptServerId(const Pkt4Ptr& pkt) const;  Marcin Siodelski committed Feb 06, 2014 286  //@}  Marcin Siodelski committed Jan 13, 2014 287   Tomek Mrugalski committed Dec 31, 2012 288 289 290 291 292 293 294 295  /// @brief verifies if specified packet meets RFC requirements /// /// Checks if mandatory option is really there, that forbidden option /// is not there, and that client-id or server-id appears only once. /// /// @param pkt packet to be checked /// @param serverid expectation regarding server-id option /// @throw RFCViolation if any issues are detected  Marcin Siodelski committed Jan 03, 2014 296  static void sanityCheck(const Pkt4Ptr& pkt, RequirementLevel serverid);  Tomek Mrugalski committed Dec 31, 2012 297   Tomek Mrugalski committed Nov 27, 2011 298 299 300 301 302 303  /// @brief Processes incoming DISCOVER and returns response. /// /// Processes received DISCOVER message and verifies that its sender /// should be served. In particular, a lease is selected and sent /// as an offer to a client if it should be served. ///  Tomek Mrugalski committed Feb 03, 2012 304  /// @param discover DISCOVER message received from client  Tomek Mrugalski committed Nov 27, 2011 305 306  /// /// @return OFFER message or NULL  Tomek Mrugalski committed Feb 03, 2012 307  Pkt4Ptr processDiscover(Pkt4Ptr& discover);  Tomek Mrugalski committed Nov 27, 2011 308 309 310 311 312  /// @brief Processes incoming REQUEST and returns REPLY response. /// /// Processes incoming REQUEST message and verifies that its sender /// should be served. In particular, verifies that requested lease  Tomek Mrugalski committed Dec 12, 2011 313  /// is valid, not expired, not reserved, not used by other client and  Tomek Mrugalski committed Nov 27, 2011 314 315  /// that requesting client is allowed to use it. ///  Stephen Morris committed Sep 12, 2012 316  /// Returns ACK message, NAK message, or NULL  Tomek Mrugalski committed Nov 27, 2011 317 318 319  /// /// @param request a message received from client ///  Stephen Morris committed Sep 12, 2012 320  /// @return ACK or NAK message  Tomek Mrugalski committed Feb 03, 2012 321  Pkt4Ptr processRequest(Pkt4Ptr& request);  Tomek Mrugalski committed Nov 27, 2011 322 323 324 325 326 327 328  /// @brief Stub function that will handle incoming RELEASE messages. /// /// In DHCPv4, server does not respond to RELEASE messages, therefore /// this function does not return anything. /// /// @param release message received from client  Tomek Mrugalski committed Feb 03, 2012 329  void processRelease(Pkt4Ptr& release);  Tomek Mrugalski committed Nov 27, 2011 330 331 332 333  /// @brief Stub function that will handle incoming DHCPDECLINE messages. /// /// @param decline message received from client  Tomek Mrugalski committed Feb 03, 2012 334  void processDecline(Pkt4Ptr& decline);  Tomek Mrugalski committed Nov 27, 2011 335 336 337  /// @brief Stub function that will handle incoming INFORM messages. ///  Tomek Mrugalski committed Feb 03, 2012 338  /// @param inform message received from client  Tomek Mrugalski committed Feb 03, 2012 339  Pkt4Ptr processInform(Pkt4Ptr& inform);  Tomek Mrugalski committed Nov 27, 2011 340   Tomek Mrugalski committed Dec 21, 2011 341 342 343 344 345 346 347  /// @brief Copies default parameters from client's to server's message /// /// Some fields are copied from client's message into server's response, /// e.g. client HW address, number of hops, transaction-id etc. /// /// @param question any message sent by client /// @param answer any message server is going to send as response  Tomek Mrugalski committed Feb 03, 2012 348  void copyDefaultFields(const Pkt4Ptr& question, Pkt4Ptr& answer);  Tomek Mrugalski committed Dec 23, 2011 349 350 351 352  /// @brief Appends options requested by client. /// /// This method assigns options that were requested by client  Tomek Mrugalski committed Dec 29, 2011 353  /// (sent in PRL) or are enforced by server.  Tomek Mrugalski committed Dec 23, 2011 354  ///  Marcin Siodelski committed Jan 15, 2013 355  /// @param question DISCOVER or REQUEST message from a client.  Tomek Mrugalski committed Dec 23, 2011 356  /// @param msg outgoing message (options will be added here)  Marcin Siodelski committed Jan 15, 2013 357  void appendRequestedOptions(const Pkt4Ptr& question, Pkt4Ptr& msg);  Tomek Mrugalski committed Dec 23, 2011 358   Marcin Siodelski committed Oct 22, 2013 359 360 361 362 363 364 365 366 367  /// @brief Appends requested vendor options as requested by client. /// /// This method is similar to \ref appendRequestedOptions(), but uses /// vendor options. The major difference is that vendor-options use /// its own option spaces (there may be more than one distinct set of vendor /// options, each with unique vendor-id). Vendor options are requested /// using separate options within their respective vendor-option spaces. /// /// @param question DISCOVER or REQUEST message from a client.  Tomek Mrugalski committed Jan 03, 2014 368  /// @param answer outgoing message (options will be added here)  Marcin Siodelski committed Oct 22, 2013 369 370  void appendRequestedVendorOptions(const Pkt4Ptr& question, Pkt4Ptr& answer);  Tomek Mrugalski committed Dec 23, 2011 371 372 373 374 375 376  /// @brief Assigns a lease and appends corresponding options /// /// This method chooses the most appropriate lease for reqesting /// client and assigning it. Options corresponding to the lease /// are added to specific message. ///  Tomek Mrugalski committed Dec 31, 2012 377 378 379 380  /// @param question DISCOVER or REQUEST message from client /// @param answer OFFER or ACK/NAK message (lease options will be added here) void assignLease(const Pkt4Ptr& question, Pkt4Ptr& answer);  Marcin Siodelski committed Jan 22, 2013 381 382 383 384 385 386 387 388 389 390 391 392 393  /// @brief Append basic options if they are not present. /// /// This function adds the following basic options if they /// are not yet added to the message: /// - Subnet Mask, /// - Router, /// - Name Server, /// - Domain Name. /// /// @param question DISCOVER or REQUEST message from a client. /// @param msg the message to add options to. void appendBasicOptions(const Pkt4Ptr& question, Pkt4Ptr& msg);  Marcin Siodelski committed Aug 28, 2013 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425  /// @brief Processes Client FQDN and Hostname Options sent by a client. /// /// Client may send Client FQDN or Hostname option to communicate its name /// to the server. Server may use this name to perform DNS update for the /// lease being assigned to a client. If server takes responsibility for /// updating DNS for a client it may communicate it by sending the Client /// FQDN or Hostname %Option back to the client. Server select a different /// name than requested by a client to update DNS. In such case, the server /// stores this different name in its response. /// /// Client should not send both Client FQDN and Hostname options. However, /// if client sends both options, server should prefer Client FQDN option /// and ignore the Hostname option. If Client FQDN option is not present, /// the Hostname option is processed. /// /// The Client FQDN %Option is processed by this function as described in /// RFC4702. /// /// In response to a Hostname %Option sent by a client, the server may send /// Hostname option with the same or different hostname. If different /// hostname is sent, it is an indication to the client that server has /// overridden the client's preferred name and will rather use this /// different name to update DNS. However, since Hostname option doesn't /// carry an information whether DNS update will be carried by the server /// or not, the client is responsible for checking whether DNS update /// has been performed. /// /// After successful processing options stored in the first parameter, /// this function may add Client FQDN or Hostname option to the response /// message. In some cases, server may cease to add any options to the /// response, i.e. when server doesn't support DNS updates. ///  Marcin Siodelski committed Nov 20, 2013 426 427 428  /// This function does not throw. It simply logs the debug message if the /// processing of the FQDN or Hostname failed. ///  Marcin Siodelski committed Aug 28, 2013 429 430 431 432  /// @param query A DISCOVER or REQUEST message from a cient. /// @param [out] answer A response message to be sent to a client. void processClientName(const Pkt4Ptr& query, Pkt4Ptr& answer);  Tomek Mrugalski committed Feb 18, 2014 433 434 435 436 437 438 439 440  /// @brief this is a prefix added to the contend of vendor-class option /// /// If incoming packet has a vendor class option, its content is /// prepended with this prefix and then interpreted as a class. /// For example, a packet that sends vendor class with value of "FOO" /// will cause the packet to be assigned to class VENDOR_CLASS_FOO. static const std::string VENDOR_CLASS_PREFIX;  Marcin Siodelski committed Aug 28, 2013 441 442 443 private: /// @brief Process Client FQDN %Option sent by a client. ///  Marcin Siodelski committed Nov 19, 2013 444 445 446 447 448 449  /// This function is called by the @c Dhcpv4Srv::processClientName when /// the client has sent the FQDN option in its message to the server. /// It comprises the actual logic to parse the FQDN option and prepare /// the FQDN option to be sent back to the client in the server's /// response. ///  Marcin Siodelski committed Aug 28, 2013 450  /// @param fqdn An DHCPv4 Client FQDN %Option sent by a client.  Marcin Siodelski committed Aug 28, 2013 451  /// @param [out] answer A response message to be sent to a client.  Marcin Siodelski committed Aug 28, 2013 452 453  void processClientFqdnOption(const Option4ClientFqdnPtr& fqdn, Pkt4Ptr& answer);  Marcin Siodelski committed Aug 28, 2013 454 455 456  /// @brief Process Hostname %Option sent by a client. ///  Marcin Siodelski committed Nov 20, 2013 457 458 459 460 461 462  /// This function is called by the @c DHcpv4Srv::processClientName when /// the client has sent the Hostname option in its message to the server. /// It comprises the actual logic to parse the Hostname option and /// prepare the Hostname option to be sent back to the client in the /// server's response. ///  Thomas Markwalder committed Feb 19, 2014 463  /// @param opt_hostname An @c OptionString object encapsulating the Hostname  Marcin Siodelski committed Sep 09, 2013 464  /// %Option.  Marcin Siodelski committed Aug 28, 2013 465  /// @param [out] answer A response message to be sent to a client.  Thomas Markwalder committed Feb 19, 2014 466  void processHostnameOption(const OptionStringPtr& opt_hostname,  Marcin Siodelski committed Sep 09, 2013 467  Pkt4Ptr& answer);  Marcin Siodelski committed Aug 28, 2013 468 469  protected:  Marcin Siodelski committed Sep 03, 2013 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487  /// @brief Creates NameChangeRequests which correspond to the lease /// which has been acquired. /// /// If this function is called whe an existing lease is renewed, it /// may generate NameChangeRequest to remove existing DNS entries which /// correspond to the old lease instance. This function may cease to /// generate NameChangeRequests if the notion of the client's FQDN hasn't /// changed between an old and new lease. /// /// @param lease A pointer to the new lease which has been acquired. /// @param old_lease A pointer to the instance of the old lease which has /// been replaced by the new lease passed in the first argument. The NULL /// value indicates that the new lease has been allocated, rather than /// lease being renewed. void createNameChangeRequests(const Lease4Ptr& lease, const Lease4Ptr& old_lease);  Marcin Siodelski committed Sep 09, 2013 488 489  /// @brief Creates the NameChangeRequest and adds to the queue for /// processing.  Marcin Siodelski committed Sep 05, 2013 490  ///  Thomas Markwalder committed Feb 14, 2014 491 492 493  /// This creates the @c isc::dhcp_ddns::NameChangeRequest; emits a /// the debug message which indicates whether the request being added is /// to remove DNS entry or add a new entry; and then sends the request  Marcin Siodelski committed Jul 02, 2014 494  /// to the D2ClientMgr for transmission to kea-dhcp-ddns.  Marcin Siodelski committed Sep 05, 2013 495  ///  Marcin Siodelski committed Sep 09, 2013 496  /// @param chg_type A type of the NameChangeRequest (ADD or REMOVE).  Marcin Siodelski committed Sep 10, 2013 497 498  /// @param lease A lease for which the NameChangeRequest is created and /// queued.  Marcin Siodelski committed Sep 09, 2013 499 500  void queueNameChangeRequest(const isc::dhcp_ddns::NameChangeType chg_type, const Lease4Ptr& lease);  Marcin Siodelski committed Sep 05, 2013 501   Tomek Mrugalski committed Dec 31, 2012 502 503 504 505 506  /// @brief Attempts to renew received addresses /// /// Attempts to renew existing lease. This typically includes finding a lease that /// corresponds to the received address. If no such lease is found, a status code /// response is generated.  Tomek Mrugalski committed Dec 23, 2011 507  ///  Tomek Mrugalski committed Dec 31, 2012 508 509 510  /// @param renew client's message asking for renew /// @param reply server's response (ACK or NAK) void renewLease(const Pkt4Ptr& renew, Pkt4Ptr& reply);  Tomek Mrugalski committed Dec 23, 2011 511   Tomek Mrugalski committed Dec 21, 2011 512 513  /// @brief Appends default options to a message ///  Marcin Siodelski committed Jan 03, 2014 514 515 516 517  /// Currently it is only a Message Type option. This function does not add /// the Server Identifier option as this option must be added using /// @c Dhcpv4Srv::appendServerID. ///  Marcin Siodelski committed Jan 09, 2014 518  ///  Tomek Mrugalski committed Dec 21, 2011 519 520  /// @param msg message object (options will be added to it) /// @param msg_type specifies message type  Tomek Mrugalski committed Feb 03, 2012 521  void appendDefaultOptions(Pkt4Ptr& msg, uint8_t msg_type);  Tomek Mrugalski committed Dec 21, 2011 522   Marcin Siodelski committed Jan 03, 2014 523 524  /// @brief Adds server identifier option to the server's response. ///  Marcin Siodelski committed Jan 07, 2014 525  /// This method adds a server identifier to the DHCPv4 message. It epxects  Marcin Siodelski committed Jan 03, 2014 526 527 528 529 530 531 532 533 534 535 536  /// that the local (source) address is set for this message. If address is /// not set, it will throw an exception. This method also expects that the /// server identifier option is not present in the specified message. /// Otherwise, it will throw an exception on attempt to add a duplicate /// server identifier option. /// /// @note This method doesn't throw exceptions by itself but the underlying /// classes being used my throw. The reason for this method to not sanity /// check the specified message is that it is meant to be called internally /// by the @c Dhcpv4Srv class. ///  Marcin Siodelski committed Jan 09, 2014 537 538 539  /// @note This method is static because it is not dependent on the class /// state. ///  Marcin Siodelski committed Jan 03, 2014 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559  /// @param [out] response DHCPv4 message to which the server identifier /// option should be added. static void appendServerID(const Pkt4Ptr& response); /// @brief Set IP/UDP and interface parameters for the DHCPv4 response. /// /// This method sets the following parameters for the DHCPv4 message being /// sent to a client: /// - client unicast or a broadcast address, /// - client or relay port, /// - server address, /// - server port, /// - name and index of the interface which is to be used to send the /// message. /// /// Internally it calls the @c Dhcpv4Srv::adjustRemoteAddr to figure /// out the destination address (client unicast address or broadcast /// address). /// /// The destination port is always DHCPv4 client (68) or relay (67) port,  Marcin Siodelski committed Jan 08, 2014 560  /// depending if the response will be sent directly to a client.  Marcin Siodelski committed Jan 03, 2014 561 562 563 564 565 566 567 568 569 570  /// /// The source port is always set to DHCPv4 server port (67). /// /// The interface selected for the response is always the same as the /// one through which the query has been received. /// /// The source address for the response is the IPv4 address assigned to /// the interface being used to send the response. This function uses /// @c IfaceMgr to get the socket bound to the IPv4 address on the /// particular interface.  Marcin Siodelski committed Jan 09, 2014 571 572 573  /// /// @note This method is static because it is not dependent on the class /// state.  Marcin Siodelski committed Jan 03, 2014 574 575  static void adjustIfaceData(const Pkt4Ptr& query, const Pkt4Ptr& response);  Marcin Siodelski committed May 21, 2013 576 577 578 579 580 581 582 583 584 585 586 587 588  /// @brief Sets remote addresses for outgoing packet. /// /// This method sets the local and remote addresses on outgoing packet. /// The addresses being set depend on the following conditions: /// - has incoming packet been relayed, /// - is direct response to a client without address supported, /// - type of the outgoing packet, /// - broadcast flag set in the incoming packet. /// /// @warning This method does not check whether provided packet pointers /// are valid. Make sure that pointers are correct before calling this /// function. ///  Marcin Siodelski committed Jan 09, 2014 589 590 591  /// @note This method is static because it is not dependent on the class /// state. ///  Marcin Siodelski committed May 21, 2013 592  /// @param question instance of a packet received by a server.  Marcin Siodelski committed Jan 09, 2014 593 594 595 596  /// @param [out] response response packet which addresses are to be /// adjusted. static void adjustRemoteAddr(const Pkt4Ptr& question, const Pkt4Ptr& response);  Marcin Siodelski committed May 21, 2013 597   Tomek Mrugalski committed Jan 14, 2013 598 599 600 601 602 603 604  /// @brief converts server-id to text /// Converts content of server-id option to a text representation, e.g. /// "192.0.2.1" /// /// @param opt option that contains server-id /// @return string representation static std::string srvidToString(const OptionPtr& opt);  Tomek Mrugalski committed Nov 27, 2011 605   Marcin Siodelski committed Sep 03, 2013 606  /// @brief Computes DHCID from a lease.  Marcin Siodelski committed Sep 02, 2013 607  ///  Marcin Siodelski committed Nov 19, 2013 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622  /// This method creates an object which represents DHCID. The DHCID value /// is computed as described in RFC4701. The section 3.3. of RFC4701 /// specifies the DHCID RR Identifier Type codes: /// - 0x0000 The 1 octet htype followed by glen octets of chaddr /// - 0x0001 The data octets from the DHCPv4 client's Client Identifier /// option. /// - 0x0002 The client's DUID. /// /// Currently this function supports first two of these identifiers. /// The 0x0001 is preferred over the 0x0000 - if the client identifier /// option is present, the former is used. If the client identifier /// is absent, the latter is used. /// /// @todo Implement support for 0x0002 DHCID identifier type. ///  Marcin Siodelski committed Sep 03, 2013 623  /// @param lease A pointer to the structure describing a lease.  Marcin Siodelski committed Sep 02, 2013 624  /// @return An object encapsulating DHCID to be used for DNS updates.  Marcin Siodelski committed Nov 19, 2013 625  /// @throw DhcidComputeError If the computation of the DHCID failed.  Marcin Siodelski committed Sep 03, 2013 626  static isc::dhcp_ddns::D2Dhcid computeDhcid(const Lease4Ptr& lease);  Marcin Siodelski committed Sep 02, 2013 627   Tomek Mrugalski committed Dec 31, 2012 628 629 630 631  /// @brief Selects a subnet for a given client's packet. /// /// @param question client's message /// @return selected subnet (or NULL if no suitable subnet was found)  Marcin Siodelski committed Feb 03, 2014 632  isc::dhcp::Subnet4Ptr selectSubnet(const Pkt4Ptr& question) const;  Tomek Mrugalski committed Dec 31, 2012 633   Tomek Mrugalski committed Nov 27, 2011 634 635  /// indicates if shutdown is in progress. Setting it to true will /// initiate server shutdown procedure.  Tomek Mrugalski committed Dec 12, 2011 636  volatile bool shutdown_;  Tomek Mrugalski committed Dec 31, 2012 637   Tomek Mrugalski committed Jul 15, 2013 638 639 640 641 642 643 644 645 646 647 648 649  /// @brief dummy wrapper around IfaceMgr::receive4 /// /// This method is useful for testing purposes, where its replacement /// simulates reception of a packet. For that purpose it is protected. virtual Pkt4Ptr receivePacket(int timeout); /// @brief dummy wrapper around IfaceMgr::send() /// /// This method is useful for testing purposes, where its replacement /// simulates transmission of a packet. For that purpose it is protected. virtual void sendPacket(const Pkt4Ptr& pkt);  Marcin Siodelski committed Oct 04, 2013 650 651 652 653 654 655 656 657 658 659 660 661  /// @brief Implements a callback function to parse options in the message. /// /// @param buf a A buffer holding options in on-wire format. /// @param option_space A name of the option space which holds definitions /// of to be used to parse options in the packets. /// @param [out] options A reference to the collection where parsed options /// will be stored. /// @return An offset to the first byte after last parsed option. size_t unpackOptions(const OptionBuffer& buf, const std::string& option_space, isc::dhcp::OptionCollection& options);  Tomek Mrugalski committed Dec 31, 2013 662 663 664 665 666 667 668  /// @brief Assigns incoming packet to zero or more classes. /// /// @note For now, the client classification is very simple. It just uses /// content of the vendor-class-identifier option as a class. The resulting /// class will be stored in packet (see @ref isc::dhcp::Pkt4::classes_ and /// @ref isc::dhcp::Pkt4::inClass). ///  Tomek Mrugalski committed Dec 30, 2013 669 670 671 672 673 674 675 676 677 678 679 680  /// @param pkt packet to be classified void classifyPacket(const Pkt4Ptr& pkt); /// @brief Performs packet processing specific to a class /// /// This processing is a likely candidate to be pushed into hooks. /// /// @param query incoming client's packet /// @param rsp server's response /// @return true if successful, false otherwise (will prevent sending response) bool classSpecificProcessing(const Pkt4Ptr& query, const Pkt4Ptr& rsp);  Marcin Siodelski committed May 22, 2013 681 private:  Tomek Mrugalski committed Dec 31, 2012 682 683  /// @brief Constructs netmask option based on subnet4  Tomek Mrugalski committed Jan 08, 2013 684  /// @param subnet subnet for which the netmask will be calculated  Tomek Mrugalski committed Dec 31, 2012 685 686 687 688  /// /// @return Option that contains netmask information static OptionPtr getNetmaskOption(const Subnet4Ptr& subnet);  Marcin Siodelski committed Nov 29, 2013 689 690 691 692 693 694 695 696 697  /// @brief Implements the error handler for socket open failure. /// /// This callback function is installed on the @c isc::dhcp::IfaceMgr /// when IPv4 sockets are being open. When socket fails to open for /// any reason, this function is called. It simply logs the error message. /// /// @param errmsg An error message containing a cause of the failure. static void ifaceMgrSocket4ErrorHandler(const std::string& errmsg);  Tomek Mrugalski committed Dec 31, 2012 698 699 700 701 702 703  /// @brief Allocation Engine. /// Pointer to the allocation engine that we are currently using /// It must be a pointer, because we will support changing engines /// during normal operation (e.g. to use different allocators) boost::shared_ptr alloc_engine_;  Marcin Siodelski committed Jul 11, 2013 704 705 706  uint16_t port_; ///< UDP port number on which server listens. bool use_bcast_; ///< Should broadcast be enabled on sockets (if true).  Tomek Mrugalski committed Jul 15, 2013 707 708 709 710  /// Indexes for registered hook points int hook_index_pkt4_receive_; int hook_index_subnet4_select_; int hook_index_pkt4_send_;  Tomek Mrugalski committed Nov 27, 2011 711 712 713 714 715 716 }; }; // namespace isc::dhcp }; // namespace isc #endif // DHCP4_SRV_H