Kea 1.5.0
dhcp4_srv.h
Go to the documentation of this file.
1// Copyright (C) 2011-2018 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#ifndef DHCPV4_SRV_H
8#define DHCPV4_SRV_H
9
10#include <asiolink/io_service.h>
11#include <dhcp/dhcp4.h>
12#include <dhcp/pkt4.h>
13#include <dhcp/option.h>
14#include <dhcp/option_string.h>
16#include <dhcp/option_custom.h>
17#include <dhcp_ddns/ncr_msg.h>
19#include <dhcpsrv/cfg_option.h>
23#include <dhcpsrv/subnet.h>
25#include <process/daemon.h>
26
27#include <boost/noncopyable.hpp>
28
29#include <functional>
30#include <iostream>
31#include <queue>
32
33// Undefine the macro OPTIONAL which is defined in some operating
34// systems but conflicts with a member of the RequirementLevel enum in
35// the server class.
36
37#ifdef OPTIONAL
38#undef OPTIONAL
39#endif
40
41namespace isc {
42namespace dhcp {
43
64public:
77 Dhcpv4Exchange(const AllocEnginePtr& alloc_engine, const Pkt4Ptr& query,
78 const Subnet4Ptr& subnet);
79
86 void initResponse();
87
91 void initResponse4o6();
92
94 Pkt4Ptr getQuery() const {
95 return (query_);
96 }
97
102 return (resp_);
103 }
104
107 resp_.reset();
108 }
109
112 return (context_);
113 }
114
117 return (cfg_option_list_);
118 }
119
122 return (cfg_option_list_);
123 }
124
128
131
132private:
133
143 void copyDefaultFields();
144
154 void copyDefaultOptions();
155
162 void setHostIdentifiers();
163
165 AllocEnginePtr alloc_engine_;
167 Pkt4Ptr query_;
169 Pkt4Ptr resp_;
175 CfgOptionList cfg_option_list_;
176};
177
179typedef boost::shared_ptr<Dhcpv4Exchange> Dhcpv4ExchangePtr;
180
181
195private:
196
198 asiolink::IOServicePtr io_service_;
199
200public:
201
203 typedef enum {
208
226 Dhcpv4Srv(uint16_t port = DHCP4_SERVER_PORT,
227 const bool use_bcast = true,
228 const bool direct_response_desired = true);
229
231 virtual ~Dhcpv4Srv();
232
235 return (io_service_);
236 }
237
240 return (network_state_);
241 }
242
245 static std::string getVersion(bool extended);
246
253 bool run();
254
260 void run_one();
261
270 void processPacket(Pkt4Ptr& query, Pkt4Ptr& rsp,
271 bool allow_packet_park = true);
272
273
275 void shutdown();
276
280
281
288 uint16_t getPort() const {
289 return (port_);
290 }
291
296 bool useBroadcast() const {
297 return (use_bcast_);
298 }
300
306 void startD2();
307
313 void stopD2();
314
329 virtual void d2ClientErrorHandler(const dhcp_ddns::
330 NameChangeSender::Result result,
332
334 void discardPackets();
335
336protected:
337
344
345
365 bool accept(const Pkt4Ptr& query) const;
366
394 bool acceptDirectRequest(const Pkt4Ptr& query) const;
395
414 bool acceptMessageType(const Pkt4Ptr& query) const;
415
429 bool acceptServerId(const Pkt4Ptr& pkt) const;
431
440 static void sanityCheck(const Pkt4Ptr& query, RequirementLevel serverid);
441
452
468
478
489
496
504
513
525
540 void assignLease(Dhcpv4Exchange& ex);
541
554
567
606
613 static const std::string VENDOR_CLASS_PREFIX;
614
615private:
626 void processClientFqdnOption(Dhcpv4Exchange& ex);
627
659 void processHostnameOption(Dhcpv4Exchange& ex);
660
674 void declineLease(const Lease4Ptr& lease, const Pkt4Ptr& decline,
676
677protected:
678
693 void createNameChangeRequests(const Lease4Ptr& lease,
694 const Lease4Ptr& old_lease);
695
704 void renewLease(const Pkt4Ptr& renew, Pkt4Ptr& reply);
705
724 static void appendServerID(Dhcpv4Exchange& ex);
725
730 static uint16_t checkRelayPort(const Dhcpv4Exchange& ex);
731
765 static void adjustIfaceData(Dhcpv4Exchange& ex);
766
785 static void adjustRemoteAddr(Dhcpv4Exchange& ex);
786
793 static std::string srvidToString(const OptionPtr& opt);
794
807 bool& drop,
808 bool sanity_only = false) const;
809
822 bool& drop,
823 bool sanity_only = false) const;
824
827 volatile bool shutdown_;
828
833 virtual Pkt4Ptr receivePacket(int timeout);
834
839 virtual void sendPacket(const Pkt4Ptr& pkt);
840
851 void classifyPacket(const Pkt4Ptr& pkt);
852
853public:
854
865 static void evaluateClasses(const Pkt4Ptr& pkt, bool depend_on_known);
866
867protected:
868
880
890 void deferredUnpack(Pkt4Ptr& query);
891
898 Pkt4Ptr& query, Pkt4Ptr& rsp);
899
905 Pkt4Ptr& rsp);
906
911 boost::shared_ptr<AllocEngine> alloc_engine_;
912
913private:
914
921 void classifyByVendor(const Pkt4Ptr& pkt);
922
928 static OptionPtr getNetmaskOption(const Subnet4Ptr& subnet);
929
930 uint16_t port_;
931 bool use_bcast_;
932
933protected:
934
938
939public:
941
944 static void processStatsReceived(const Pkt4Ptr& query);
945
948 static void processStatsSent(const Pkt4Ptr& response);
949
952 static int getHookIndexBuffer4Receive();
953
956 static int getHookIndexPkt4Receive();
957
960 static int getHookIndexSubnet4Select();
961
964 static int getHookIndexLease4Release();
965
968 static int getHookIndexPkt4Send();
969
972 static int getHookIndexBuffer4Send();
973
976 static int getHookIndexLease4Decline();
977};
978
979}; // namespace isc::dhcp
980}; // namespace isc
981
982#endif // DHCP4_SRV_H
boost::shared_ptr< ClientContext4 > ClientContext4Ptr
Pointer to the ClientContext4.
DHCPv4 message exchange.
Definition: dhcp4_srv.h:63
AllocEngine::ClientContext4Ptr getContext() const
Returns the copy of the context for the Allocation engine.
Definition: dhcp4_srv.h:111
void deleteResponse()
Removes the response message by resetting the pointer to NULL.
Definition: dhcp4_srv.h:106
const CfgOptionList & getCfgOptionList() const
Returns the configured option list (const version)
Definition: dhcp4_srv.h:121
Pkt4Ptr getQuery() const
Returns the pointer to the query from the client.
Definition: dhcp4_srv.h:94
void initResponse()
Initializes the instance of the response message.
Definition: dhcp4_srv.cc:193
void setReservedMessageFields()
Sets reserved values of siaddr, sname and file in the server's response.
Definition: dhcp4_srv.cc:420
CfgOptionList & getCfgOptionList()
Returns the configured option list (non-const version)
Definition: dhcp4_srv.h:116
Pkt4Ptr getResponse() const
Returns the pointer to the server's response.
Definition: dhcp4_srv.h:101
void initResponse4o6()
Initializes the DHCPv6 part of the response message.
Definition: dhcp4_srv.cc:219
void setReservedClientClasses()
Assigns classes retrieved from host reservation database.
Definition: dhcp4_srv.cc:409
DHCPv4 server service.
Definition: dhcp4_srv.h:194
void declineLease(const Lease4Ptr &lease, const Pkt4Ptr &decline, AllocEngine::ClientContext4Ptr &context)
Marks lease as declined.
Definition: dhcp4_srv.cc:2858
void classifyPacket(const Pkt4Ptr &pkt)
Assigns incoming packet to zero or more classes.
Definition: dhcp4_srv.cc:3255
void appendRequestedVendorOptions(Dhcpv4Exchange &ex)
Appends requested vendor options as requested by client.
Definition: dhcp4_srv.cc:1452
static void adjustIfaceData(Dhcpv4Exchange &ex)
Set IP/UDP and interface parameters for the DHCPv4 response.
Definition: dhcp4_srv.cc:2267
void run_one()
Main server processing step.
Definition: dhcp4_srv.cc:753
static uint16_t checkRelayPort(const Dhcpv4Exchange &ex)
Check if the relay port RAI sub-option was set in the query.
Definition: dhcp4_srv.cc:2254
bool acceptDirectRequest(const Pkt4Ptr &query) const
Check if a message sent by directly connected client should be accepted or discarded.
Definition: dhcp4_srv.cc:3011
virtual ~Dhcpv4Srv()
Destructor. Used during DHCPv4 service shutdown.
Definition: dhcp4_srv.cc:482
virtual Pkt4Ptr receivePacket(int timeout)
dummy wrapper around IfaceMgr::receive4
Definition: dhcp4_srv.cc:721
static void appendServerID(Dhcpv4Exchange &ex)
Adds server identifier option to the server's response.
Definition: dhcp4_srv.cc:1283
void shutdown()
Instructs the server to shut down.
Definition: dhcp4_srv.cc:511
void startD2()
Starts DHCP_DDNS client IO if DDNS updates are enabled.
Definition: dhcp4_srv.cc:3465
bool accept(const Pkt4Ptr &query) const
Checks whether received message should be processed or discarded.
Definition: dhcp4_srv.cc:2983
static int getHookIndexBuffer4Receive()
Returns the index for "buffer4_receive" hook point.
Definition: dhcp4_srv.cc:3603
Pkt4Ptr processRequest(Pkt4Ptr &request, AllocEngine::ClientContext4Ptr &context)
Processes incoming REQUEST and returns REPLY response.
Definition: dhcp4_srv.cc:2607
static void processStatsReceived(const Pkt4Ptr &query)
Class methods for DHCPv4-over-DHCPv6 handler.
Definition: dhcp4_srv.cc:3528
static int getHookIndexPkt4Send()
Returns the index for "pkt4_send" hook point.
Definition: dhcp4_srv.cc:3619
void processDecline(Pkt4Ptr &decline, AllocEngine::ClientContext4Ptr &context)
Process incoming DHCPDECLINE messages.
Definition: dhcp4_srv.cc:2784
static void evaluateClasses(const Pkt4Ptr &pkt, bool depend_on_known)
Evaluate classes.
Definition: dhcp4_srv.cc:3266
static int getHookIndexSubnet4Select()
Returns the index for "subnet4_select" hook point.
Definition: dhcp4_srv.cc:3611
static void processStatsSent(const Pkt4Ptr &response)
Updates statistics for transmitted packets.
Definition: dhcp4_srv.cc:3577
static int getHookIndexLease4Release()
Returns the index for "lease4_release" hook point.
Definition: dhcp4_srv.cc:3615
static void adjustRemoteAddr(Dhcpv4Exchange &ex)
Sets remote addresses for outgoing packet.
Definition: dhcp4_srv.cc:2348
static int getHookIndexPkt4Receive()
Returns the index for "pkt4_receive" hook point.
Definition: dhcp4_srv.cc:3607
void assignLease(Dhcpv4Exchange &ex)
Assigns a lease and appends corresponding options.
Definition: dhcp4_srv.cc:1864
asiolink::IOServicePtr & getIOService()
Returns pointer to the IO service used by the server.
Definition: dhcp4_srv.h:234
void setFixedFields(Dhcpv4Exchange &ex)
Sets fixed fields of the outgoing packet.
Definition: dhcp4_srv.cc:2445
void appendBasicOptions(Dhcpv4Exchange &ex)
Append basic options if they are not present.
Definition: dhcp4_srv.cc:1540
void processClientName(Dhcpv4Exchange &ex)
Processes Client FQDN and Hostname Options sent by a client.
Definition: dhcp4_srv.cc:1586
boost::shared_ptr< AllocEngine > alloc_engine_
Allocation Engine.
Definition: dhcp4_srv.h:911
void requiredClassify(Dhcpv4Exchange &ex)
Assigns incoming packet to zero or more classes (required pass).
Definition: dhcp4_srv.cc:3314
void createNameChangeRequests(const Lease4Ptr &lease, const Lease4Ptr &old_lease)
Creates NameChangeRequests which correspond to the lease which has been acquired.
Definition: dhcp4_srv.cc:1844
static std::string srvidToString(const OptionPtr &opt)
converts server-id to text Converts content of server-id option to a text representation,...
Definition: dhcp4_srv.cc:1263
bool acceptServerId(const Pkt4Ptr &pkt) const
Verifies if the server id belongs to our server.
Definition: dhcp4_srv.cc:3105
static const std::string VENDOR_CLASS_PREFIX
this is a prefix added to the content of vendor-class option
Definition: dhcp4_srv.h:613
Pkt4Ptr processInform(Pkt4Ptr &inform)
Processes incoming DHCPINFORM messages.
Definition: dhcp4_srv.cc:2934
void classifyByVendor(const Pkt4Ptr &pkt)
Assign class using vendor-class-identifier option.
Definition: dhcp4_srv.cc:3243
void appendRequestedOptions(Dhcpv4Exchange &ex)
Appends options requested by client.
Definition: dhcp4_srv.cc:1381
NetworkStatePtr & getNetworkState()
Returns pointer to the network state used by the server.
Definition: dhcp4_srv.h:239
static std::string getVersion(bool extended)
returns Kea version on stdout and exit.
Definition: dhcp4_srv.cc:3501
isc::dhcp::Subnet4Ptr selectSubnet4o6(const Pkt4Ptr &query, bool &drop, bool sanity_only=false) const
Selects a subnet for a given client's DHCP4o6 packet.
Definition: dhcp4_srv.cc:603
void buildCfgOptionList(Dhcpv4Exchange &ex)
Build the configured option list.
Definition: dhcp4_srv.cc:1308
volatile bool shutdown_
indicates if shutdown is in progress.
Definition: dhcp4_srv.h:827
bool useBroadcast() const
Return bool value indicating that broadcast flags should be set on sockets.
Definition: dhcp4_srv.h:296
NetworkStatePtr network_state_
Holds information about disabled DHCP service and/or disabled subnet/network scopes.
Definition: dhcp4_srv.h:937
void renewLease(const Pkt4Ptr &renew, Pkt4Ptr &reply)
Attempts to renew received addresses.
isc::dhcp::Subnet4Ptr selectSubnet(const Pkt4Ptr &query, bool &drop, bool sanity_only=false) const
Selects a subnet for a given client's packet.
Definition: dhcp4_srv.cc:517
virtual void d2ClientErrorHandler(const dhcp_ddns::NameChangeSender::Result result, dhcp_ddns::NameChangeRequestPtr &ncr)
Implements the error handler for DHCP_DDNS IO errors.
Definition: dhcp4_srv.cc:3486
virtual void sendPacket(const Pkt4Ptr &pkt)
dummy wrapper around IfaceMgr::send()
Definition: dhcp4_srv.cc:726
static int getHookIndexBuffer4Send()
Returns the index for "buffer4_send" hook point.
Definition: dhcp4_srv.cc:3623
void stopD2()
Stops DHCP_DDNS client IO if DDNS updates are enabled.
Definition: dhcp4_srv.cc:3477
uint16_t getPort() const
Get UDP port on which server should listen.
Definition: dhcp4_srv.h:288
bool acceptMessageType(const Pkt4Ptr &query) const
Check if received message type is valid for the server to process.
Definition: dhcp4_srv.cc:3049
static void sanityCheck(const Pkt4Ptr &query, RequirementLevel serverid)
Verifies if specified packet meets RFC requirements.
Definition: dhcp4_srv.cc:3202
void processPacket(Pkt4Ptr &query, Pkt4Ptr &rsp, bool allow_packet_park=true)
Process a single incoming DHCPv4 packet.
Definition: dhcp4_srv.cc:844
void discardPackets()
Discard all in-progress packets.
Definition: dhcp4_srv.cc:3631
static int getHookIndexLease4Decline()
Returns the index for "lease4_decline" hook point.
Definition: dhcp4_srv.cc:3627
void processRelease(Pkt4Ptr &release, AllocEngine::ClientContext4Ptr &context)
Processes incoming DHCPRELEASE messages.
Definition: dhcp4_srv.cc:2669
bool run()
Main server processing loop.
Definition: dhcp4_srv.cc:731
void processPacketPktSend(hooks::CalloutHandlePtr &callout_handle, Pkt4Ptr &query, Pkt4Ptr &rsp)
Executes pkt4_send callout.
Definition: dhcp4_srv.cc:1132
Pkt4Ptr processDiscover(Pkt4Ptr &discover)
Processes incoming DISCOVER and returns response.
Definition: dhcp4_srv.cc:2548
RequirementLevel
defines if certain option may, must or must not appear
Definition: dhcp4_srv.h:203
void processPacketBufferSend(hooks::CalloutHandlePtr &callout_handle, Pkt4Ptr &rsp)
Executes buffer4_send callout and sends the response.
Definition: dhcp4_srv.cc:1190
void deferredUnpack(Pkt4Ptr &query)
Perform deferred option unpacking.
Definition: dhcp4_srv.cc:3406
Base class for all services.
Definition: daemon.h:49
Defines the D2ClientMgr class.
boost::shared_ptr< NameChangeRequest > NameChangeRequestPtr
Defines a pointer to a NameChangeRequest.
Definition: ncr_msg.h:214
boost::shared_ptr< Dhcpv4Exchange > Dhcpv4ExchangePtr
Type representing the pointer to the Dhcpv4Exchange.
Definition: dhcp4_srv.h:179
boost::shared_ptr< Subnet4 > Subnet4Ptr
A pointer to a Subnet4 object.
Definition: subnet.h:464
boost::shared_ptr< Pkt4 > Pkt4Ptr
A pointer to Pkt4 object.
Definition: pkt4.h:546
boost::shared_ptr< AllocEngine > AllocEnginePtr
A pointer to the AllocEngine object.
boost::shared_ptr< NetworkState > NetworkStatePtr
Pointer to the NetworkState object.
boost::shared_ptr< Lease4 > Lease4Ptr
Pointer to a Lease4 structure.
Definition: lease.h:248
boost::shared_ptr< Option > OptionPtr
Definition: option.h:38
std::list< ConstCfgOptionPtr > CfgOptionList
Const pointer list.
Definition: cfg_option.h:503
boost::shared_ptr< CalloutHandle > CalloutHandlePtr
A shared pointer to a CalloutHandle object.
Defines the logger used by the top-level component of kea-dhcp-ddns.
This file provides the classes needed to embody, compose, and decompose DNS update requests that are ...