Kea 3.1.1
dhcp6_srv.h
Go to the documentation of this file.
1// Copyright (C) 2011-2025 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 DHCPV6_SRV_H
8#define DHCPV6_SRV_H
9
10#include <asiolink/io_service.h>
11#include <dhcp/dhcp6.h>
12#include <dhcp/duid.h>
13#include <dhcp/option.h>
14#include <dhcp/option_string.h>
16#include <dhcp/option6_ia.h>
17#include <dhcp/option_custom.h>
19#include <dhcp_ddns/ncr_msg.h>
20#include <dhcp/pkt6.h>
24#include <dhcpsrv/cfg_option.h>
27#include <dhcpsrv/subnet.h>
29#include <process/daemon.h>
30
31#include <functional>
32#include <iostream>
33#include <queue>
34
35// Undefine the macro OPTIONAL which is defined in some operating
36// systems but conflicts with a member of the RequirementLevel enum in
37// the server class.
38
39#ifdef OPTIONAL
40#undef OPTIONAL
41#endif
42
43namespace isc {
44namespace dhcp {
45
49public:
50 DHCPv6DiscardMessageError(const char* file, size_t line, const char* what) :
51 isc::Exception(file, line, what) { }
52};
53
66class Dhcpv6Srv : public process::Daemon {
67private:
68
70 asiolink::IOServicePtr io_service_;
71
72public:
79
81 static const size_t MIN_MAC_LEN = 6;
82
95 Dhcpv6Srv(uint16_t server_port = DHCP6_SERVER_PORT,
96 uint16_t client_port = 0);
97
99 virtual ~Dhcpv6Srv();
100
105 bool inTestMode() const {
106 return (server_port_ == 0);
107 }
108
111 return (io_service_);
112 }
113
118
125 return (cb_control_);
126 }
127
130 static std::string getVersion(bool extended);
131
136
143 int run();
144
150 void runOne();
151
159
167
174 void sendResponseNoThrow(hooks::CalloutHandlePtr& callout_handle,
175 Pkt6Ptr query, Pkt6Ptr& rsp,
176 ConstSubnet6Ptr& subnet);
177
186
195
203
211
221
229
231 void shutdown() override;
232
236
237
244 uint16_t getServerPort() const;
246
252 void startD2();
253
259 void stopD2();
260
275 virtual void d2ClientErrorHandler(const dhcp_ddns::
276 NameChangeSender::Result result,
278
282 void discardPackets();
283
288 void initContext0(const Pkt6Ptr& query,
290
298 bool earlyGHRLookup(const Pkt6Ptr& query,
300
310
311protected:
312
320
329 bool testServerID(const Pkt6Ptr& pkt);
330
341 bool testUnicast(const Pkt6Ptr& pkt) const;
342
351 bool sanityCheck(const Pkt6Ptr& pkt);
352
362 void sanityCheck(const Pkt6Ptr& pkt, RequirementLevel clientid,
363 RequirementLevel serverid);
364
370 void sanityCheckDUID(const OptionPtr& opt, const std::string& opt_name);
371
387
400
407
420
445
452
464
471
481 void processDhcp4Query(const Pkt6Ptr& dhcp4_query);
482
489
495 isc::dhcp::ConstSubnet6Ptr selectSubnet(const Pkt6Ptr& question, bool& drop);
496
513 Option6IAPtr ia);
514
527 OptionPtr assignIA_PD(const Pkt6Ptr& query,
529 boost::shared_ptr<Option6IA> ia);
530
544 OptionPtr extendIA_NA(const Pkt6Ptr& query,
546 Option6IAPtr ia);
547
601 OptionPtr extendIA_PD(const Pkt6Ptr& query,
603 Option6IAPtr ia);
604
623 OptionPtr releaseIA_NA(const DuidPtr& duid, const Pkt6Ptr& query,
624 int& general_status,
625 boost::shared_ptr<Option6IA> ia,
626 Lease6Ptr& old_lease);
627
641 OptionPtr releaseIA_PD(const DuidPtr& duid, const Pkt6Ptr& query,
642 int& general_status,
643 boost::shared_ptr<Option6IA> ia,
644 Lease6Ptr& old_lease);
645
655 void copyClientOptions(const Pkt6Ptr& question, Pkt6Ptr& answer);
656
665 void buildCfgOptionList(const Pkt6Ptr& question,
667 CfgOptionList& co_list);
668
678 void appendDefaultOptions(const Pkt6Ptr& question, Pkt6Ptr& answer,
679 const CfgOptionList& co_list);
680
689 void appendRequestedOptions(const Pkt6Ptr& question, Pkt6Ptr& answer,
690 const CfgOptionList& co_list);
691
701 void appendRequestedVendorOptions(const Pkt6Ptr& question, Pkt6Ptr& answer,
703 const CfgOptionList& co_list);
704
715 void assignLeases(const Pkt6Ptr& question, Pkt6Ptr& answer,
717
762 void processClientFqdn(const Pkt6Ptr& question, const Pkt6Ptr& answer,
764
784 void createNameChangeRequests(const Pkt6Ptr& answer,
786
798 void extendLeases(const Pkt6Ptr& query, Pkt6Ptr& reply,
800
826 void setTeeTimes(uint32_t preferred_lft,
827 const ConstSubnet6Ptr& subnet,
828 Option6IAPtr& resp);
829
840 void releaseLeases(const Pkt6Ptr& release, Pkt6Ptr& reply,
842
849 static std::string duidToString(const OptionPtr& opt);
850
855 virtual Pkt6Ptr receivePacket(int timeout);
856
861 virtual void sendPacket(const Pkt6Ptr& pkt);
862
873 void classifyPacket(const Pkt6Ptr& pkt);
874
885 void evaluateClasses(const Pkt6Ptr& pkt, bool depend_on_known);
886
893 static void removeDependentEvaluatedClasses(const Pkt6Ptr& pkt);
894
899 void setReservedClientClasses(const Pkt6Ptr& pkt,
900 const AllocEngine::ClientContext6& ctx);
901
913 const AllocEngine::ClientContext6& ctx);
914
933
941 static HWAddrPtr getMAC(const Pkt6Ptr& pkt);
942
951 void processRSOO(const Pkt6Ptr& query, const Pkt6Ptr& rsp);
952
971 void initContext(AllocEngine::ClientContext6& ctx, bool& drop);
972
979 static const std::string VENDOR_CLASS_PREFIX;
980
991 bool declineLeases(const Pkt6Ptr& decline, Pkt6Ptr& reply,
993
1007 OptionPtr
1008 declineIA(const Pkt6Ptr& decline, const DuidPtr& duid, int& general_status,
1009 boost::shared_ptr<Option6IA> ia, Lease6Collection& new_leases);
1010
1027 bool declineLease(const Pkt6Ptr& decline, const Lease6Ptr lease,
1028 boost::shared_ptr<Option6IA> ia_rsp);
1029
1035 void setStatusCode(boost::shared_ptr<Option6IA>& container,
1036 const OptionPtr& status);
1037
1072 //
1073 void checkPostAssignmentChanges(const Pkt6Ptr& question, Pkt6Ptr& answer,
1075 const ConstSubnet6Ptr orig_subnet);
1076
1083 const Lease6Ptr& lease);
1084
1085public:
1086
1088
1093 static uint16_t checkRelaySourcePort(const Pkt6Ptr& query);
1094
1095private:
1096
1102 void classifyByVendor(const Pkt6Ptr& pkt);
1103
1120 void updateReservedFqdn(AllocEngine::ClientContext6& ctx,
1121 const Pkt6Ptr& answer);
1122
1165 void generateFqdn(const Pkt6Ptr& answer,
1167
1170 static void processStatsReceived(const Pkt6Ptr& query);
1171
1179 bool requestedInORO(const Pkt6Ptr& query, const uint16_t code) const;
1180
1187 static std::tuple<bool, uint32_t> parkingLimitExceeded(std::string const& hook_label);
1188
1189protected:
1192
1195
1196public:
1197
1199
1202 static void processStatsSent(const Pkt6Ptr& response);
1203
1206 static int getHookIndexBuffer6Send();
1207
1213 Pkt6Ptr& rsp);
1214
1220 std::list<std::list<std::string>> jsonPathsToRedact() const final override;
1221
1222protected:
1223
1226
1229 volatile bool shutdown_;
1230
1237 void processPacketPktSend(hooks::CalloutHandlePtr& callout_handle,
1238 Pkt6Ptr& query, Pkt6Ptr& rsp,
1239 ConstSubnet6Ptr& subnet);
1240
1245 boost::shared_ptr<AllocEngine> alloc_engine_;
1246
1249 std::queue<isc::dhcp_ddns::NameChangeRequest> name_change_reqs_;
1250
1254
1257};
1258
1259} // namespace dhcp
1260} // namespace isc
1261
1262#endif // DHCP6_SRV_H
Exception(const char *file, size_t line, const char *what)
Constructor for a given type for exceptions with file name and file line number.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
DHCPv4 and DHCPv6 allocation engine.
DHCPv6DiscardMessageError(const char *file, size_t line, const char *what)
Definition dhcp6_srv.h:50
std::queue< isc::dhcp_ddns::NameChangeRequest > name_change_reqs_
Holds a list of isc::dhcp_ddns::NameChangeRequest objects, which are waiting for sending to kea-dhcp-...
Definition dhcp6_srv.h:1249
void shutdown() override
Instructs the server to shut down.
Definition dhcp6_srv.cc:361
RequirementLevel
defines if certain option may, must or must not appear
Definition dhcp6_srv.h:74
OptionPtr getServerID()
Returns server-identifier option.
Definition dhcp6_srv.h:135
Pkt6Ptr processPacket(Pkt6Ptr query)
Process a single incoming DHCPv6 packet.
Definition dhcp6_srv.cc:809
Pkt6Ptr processLocalizedQuery6(AllocEngine::ClientContext6 &ctx)
Process a localized incoming DHCPv6 query.
void processPacketAndSendResponseNoThrow(Pkt6Ptr query)
Process a single incoming DHCPv6 packet and sends the response.
Definition dhcp6_srv.cc:784
OptionPtr extendIA_PD(const Pkt6Ptr &query, AllocEngine::ClientContext6 &ctx, Option6IAPtr ia)
Extends lifetime of the prefix.
void setReservedClientClasses(const Pkt6Ptr &pkt, const AllocEngine::ClientContext6 &ctx)
Assigns classes retrieved from host reservation database.
Pkt6Ptr processDecline(AllocEngine::ClientContext6 &ctx)
Process incoming Decline message.
void evaluateClasses(const Pkt6Ptr &pkt, bool depend_on_known)
Evaluate classes.
Pkt6Ptr processRenew(AllocEngine::ClientContext6 &ctx)
Processes incoming Renew message.
static void processStatsSent(const Pkt6Ptr &response)
Updates statistics for transmitted packets.
void evaluateAdditionalClasses(const Pkt6Ptr &pkt, AllocEngine::ClientContext6 &ctx)
Evaluates classes in the additional classes lists.
void processLocalizedQuery6AndSendResponse(Pkt6Ptr query, AllocEngine::ClientContext6 &ctx)
Process a localized incoming DHCPv6 query.
int run()
Main server processing loop.
Definition dhcp6_srv.cc:649
void setPacketStatisticsDefaults()
This function sets statistics related to DHCPv6 packets processing to their initial values.
Definition dhcp6_srv.cc:307
bool sanityCheck(const Pkt6Ptr &pkt)
Verifies if specified packet meets RFC requirements.
static uint16_t checkRelaySourcePort(const Pkt6Ptr &query)
Used for DHCPv4-over-DHCPv6 too.
void assignLeases(const Pkt6Ptr &question, Pkt6Ptr &answer, AllocEngine::ClientContext6 &ctx)
Assigns leases.
void stopD2()
Stops DHCP_DDNS client IO if DDNS updates are enabled.
void copyClientOptions(const Pkt6Ptr &question, Pkt6Ptr &answer)
Copies required options from client message to server answer.
boost::shared_ptr< AllocEngine > alloc_engine_
Allocation Engine.
Definition dhcp6_srv.h:1245
virtual void sendPacket(const Pkt6Ptr &pkt)
dummy wrapper around IfaceMgr::send()
Definition dhcp6_srv.cc:370
bool testServerID(const Pkt6Ptr &pkt)
Compare received server id with our server id.
Definition dhcp6_srv.cc:375
virtual void d2ClientErrorHandler(const dhcp_ddns::NameChangeSender::Result result, dhcp_ddns::NameChangeRequestPtr &ncr)
Implements the error handler for DHCP_DDNS IO errors.
OptionPtr declineIA(const Pkt6Ptr &decline, const DuidPtr &duid, int &general_status, boost::shared_ptr< Option6IA > ia, Lease6Collection &new_leases)
Declines leases in a single IA_NA option.
uint16_t getServerPort() const
Get UDP port on which server should listen.
void runOne()
Main server processing step.
Definition dhcp6_srv.cc:706
virtual Pkt6Ptr receivePacket(int timeout)
dummy wrapper around IfaceMgr::receive6
Definition dhcp6_srv.cc:366
void processPacketBufferSend(hooks::CalloutHandlePtr &callout_handle, Pkt6Ptr &rsp)
Executes buffer6_send callout and sends the response.
OptionPtr releaseIA_NA(const DuidPtr &duid, const Pkt6Ptr &query, int &general_status, boost::shared_ptr< Option6IA > ia, Lease6Ptr &old_lease)
Releases specific IA_NA option.
void buildCfgOptionList(const Pkt6Ptr &question, AllocEngine::ClientContext6 &ctx, CfgOptionList &co_list)
Build the configured option list.
void appendDefaultOptions(const Pkt6Ptr &question, Pkt6Ptr &answer, const CfgOptionList &co_list)
Appends default options to server's answer.
OptionPtr assignIA_NA(const isc::dhcp::Pkt6Ptr &query, AllocEngine::ClientContext6 &ctx, Option6IAPtr ia)
Processes IA_NA option (and assigns addresses if necessary).
static const std::string VENDOR_CLASS_PREFIX
this is a prefix added to the content of vendor-class option
Definition dhcp6_srv.h:979
OptionPtr serverid_
Server DUID (to be sent in server-identifier option)
Definition dhcp6_srv.h:1225
void setTeeTimes(uint32_t preferred_lft, const ConstSubnet6Ptr &subnet, Option6IAPtr &resp)
Sets the T1 and T2 timers in the outbound IA.
void conditionallySetReservedClientClasses(const Pkt6Ptr &pkt, const AllocEngine::ClientContext6 &ctx)
Assigns classes retrieved from host reservation database if they haven't been yet set.
void processPacketAndSendResponse(Pkt6Ptr query)
Process a single incoming DHCPv6 packet and sends the response.
Definition dhcp6_srv.cc:798
OptionPtr releaseIA_PD(const DuidPtr &duid, const Pkt6Ptr &query, int &general_status, boost::shared_ptr< Option6IA > ia, Lease6Ptr &old_lease)
Releases specific IA_PD option.
void processDhcp4Query(const Pkt6Ptr &dhcp4_query)
Processes incoming DHCPv4-query message.
Pkt6Ptr processRebind(AllocEngine::ClientContext6 &ctx)
Processes incoming Rebind message.
bool earlyGHRLookup(const Pkt6Ptr &query, AllocEngine::ClientContext6 &ctx)
Initialize client context and perform early global reservations lookup.
Definition dhcp6_srv.cc:493
void initContext0(const Pkt6Ptr &query, AllocEngine::ClientContext6 &ctx)
Initialize client context (first part).
Definition dhcp6_srv.cc:480
static const size_t MIN_MAC_LEN
Minimum length of a MAC address to be used in DUID generation.
Definition dhcp6_srv.h:81
NetworkStatePtr & getNetworkState()
Returns pointer to the network state used by the server.
Definition dhcp6_srv.h:115
virtual ~Dhcpv6Srv()
Destructor. Used during DHCPv6 service shutdown.
Definition dhcp6_srv.cc:317
void initContext(AllocEngine::ClientContext6 &ctx, bool &drop)
Initializes client context for specified packet.
Definition dhcp6_srv.cc:557
Pkt6Ptr processRequest(AllocEngine::ClientContext6 &ctx)
Processes incoming Request and returns Reply response.
void sendResponseNoThrow(hooks::CalloutHandlePtr &callout_handle, Pkt6Ptr query, Pkt6Ptr &rsp, ConstSubnet6Ptr &subnet)
Process an unparked DHCPv6 packet and sends the response.
NetworkStatePtr network_state_
Holds information about disabled DHCP service and/or disabled subnet/network scopes.
Definition dhcp6_srv.h:1253
std::list< std::list< std::string > > jsonPathsToRedact() const final override
Return a list of all paths that contain passwords or secrets for kea-dhcp6.
CBControlDHCPv6Ptr getCBControl() const
Returns an object which controls access to the configuration backends.
Definition dhcp6_srv.h:124
OptionPtr assignIA_PD(const Pkt6Ptr &query, AllocEngine::ClientContext6 &ctx, boost::shared_ptr< Option6IA > ia)
Processes IA_PD option (and assigns prefixes if necessary).
bool testUnicast(const Pkt6Ptr &pkt) const
Check if the message can be sent to unicast.
Definition dhcp6_srv.cc:397
Pkt6Ptr processRelease(AllocEngine::ClientContext6 &ctx)
Process incoming Release message.
void processClientFqdn(const Pkt6Ptr &question, const Pkt6Ptr &answer, AllocEngine::ClientContext6 &ctx)
Processes Client FQDN Option.
void setStatusCode(boost::shared_ptr< Option6IA > &container, const OptionPtr &status)
A simple utility method that sets the status code.
static int getHookIndexBuffer6Send()
Returns the index of the buffer6_send hook.
void classifyPacket(const Pkt6Ptr &pkt)
Assigns incoming packet to zero or more classes.
static HWAddrPtr getMAC(const Pkt6Ptr &pkt)
Attempts to get a MAC/hardware address using configured sources.
Dhcpv6Srv(uint16_t server_port=DHCP6_SERVER_PORT, uint16_t client_port=0)
Default constructor.
Definition dhcp6_srv.cc:262
bool declineLeases(const Pkt6Ptr &decline, Pkt6Ptr &reply, AllocEngine::ClientContext6 &ctx)
Attempts to decline all leases in specified Decline message.
void releaseLeases(const Pkt6Ptr &release, Pkt6Ptr &reply, AllocEngine::ClientContext6 &ctx)
Attempts to release received addresses.
void extendLeases(const Pkt6Ptr &query, Pkt6Ptr &reply, AllocEngine::ClientContext6 &ctx)
Attempts to extend the lifetime of IAs.
void processRSOO(const Pkt6Ptr &query, const Pkt6Ptr &rsp)
Processes Relay-supplied options, if present.
static std::string getVersion(bool extended)
returns Kea version on stdout and exit.
Pkt6Ptr processAddrRegInform(AllocEngine::ClientContext6 &ctx)
Processes incoming Addr-reg-inform message.
OptionPtr extendIA_NA(const Pkt6Ptr &query, AllocEngine::ClientContext6 &ctx, Option6IAPtr ia)
Extends lifetime of the specific IA_NA option.
Pkt6Ptr processConfirm(AllocEngine::ClientContext6 &ctx)
Processes incoming Confirm message and returns Reply.
void sanityCheckDUID(const OptionPtr &opt, const std::string &opt_name)
verifies if received DUID option (client-id or server-id) is sane
static void setHostIdentifiers(AllocEngine::ClientContext6 &ctx)
Set host identifiers within a context.
Definition dhcp6_srv.cc:418
void processPacketPktSend(hooks::CalloutHandlePtr &callout_handle, Pkt6Ptr &query, Pkt6Ptr &rsp, ConstSubnet6Ptr &subnet)
Executes pkt6_send callout.
Pkt6Ptr processDhcp6Query(Pkt6Ptr query)
Process a single incoming DHCPv6 query.
void processDhcp6QueryAndSendResponse(Pkt6Ptr query)
Process a single incoming DHCPv6 query.
asiolink::IOServicePtr & getIOService()
Returns pointer to the IO service used by the server.
Definition dhcp6_srv.h:110
void appendRequestedOptions(const Pkt6Ptr &question, Pkt6Ptr &answer, const CfgOptionList &co_list)
Appends requested options to server's answer.
uint16_t client_port_
UDP port number to which server sends all responses.
Definition dhcp6_srv.h:1194
CBControlDHCPv6Ptr cb_control_
Controls access to the configuration backends.
Definition dhcp6_srv.h:1256
isc::dhcp::ConstSubnet6Ptr selectSubnet(const Pkt6Ptr &question, bool &drop)
Selects a subnet for a given client's packet.
volatile bool shutdown_
Indicates if shutdown is in progress.
Definition dhcp6_srv.h:1229
void checkPostAssignmentChanges(const Pkt6Ptr &question, Pkt6Ptr &answer, AllocEngine::ClientContext6 &ctx, const ConstSubnet6Ptr orig_subnet)
Iterates over new leases, update stale DNS entries.
Pkt6Ptr processSolicit(AllocEngine::ClientContext6 &ctx)
Processes incoming Solicit and returns response.
bool inTestMode() const
Checks if the server is running in unit test mode.
Definition dhcp6_srv.h:105
void startD2()
Starts DHCP_DDNS client IO if DDNS updates are enabled.
static std::string duidToString(const OptionPtr &opt)
converts DUID to text Converts content of DUID option to a text representation, e....
OptionPtr getPDExclude(const AllocEngine::ClientContext6 &ctx, const Lease6Ptr &lease)
Return the PD exclude option to include.
static void removeDependentEvaluatedClasses(const Pkt6Ptr &pkt)
Removed evaluated client classes.
void createNameChangeRequests(const Pkt6Ptr &answer, AllocEngine::ClientContext6 &ctx)
Creates a number of isc::dhcp_ddns::NameChangeRequest objects based on the DHCPv6 Client FQDN Option.
Pkt6Ptr processInfRequest(AllocEngine::ClientContext6 &ctx)
Processes incoming Information-request message.
uint16_t server_port_
UDP port number on which server listens.
Definition dhcp6_srv.h:1191
void appendRequestedVendorOptions(const Pkt6Ptr &question, Pkt6Ptr &answer, AllocEngine::ClientContext6 &ctx, const CfgOptionList &co_list)
Appends requested vendor options to server's answer.
bool declineLease(const Pkt6Ptr &decline, const Lease6Ptr lease, boost::shared_ptr< Option6IA > ia_rsp)
Declines specific IPv6 lease.
void discardPackets()
Discards parked packets Clears the packet parking lots of all packets.
Base class for all services.
Definition daemon.h:48
Defines the D2ClientMgr class.
boost::shared_ptr< NameChangeRequest > NameChangeRequestPtr
Defines a pointer to a NameChangeRequest.
Definition ncr_msg.h:241
boost::shared_ptr< const Subnet6 > ConstSubnet6Ptr
A const pointer to a Subnet6 object.
Definition subnet.h:623
boost::shared_ptr< DUID > DuidPtr
Definition duid.h:136
boost::shared_ptr< Lease6 > Lease6Ptr
Pointer to a Lease6 structure.
Definition lease.h:528
std::vector< Lease6Ptr > Lease6Collection
A collection of IPv6 leases.
Definition lease.h:693
boost::shared_ptr< Option6IA > Option6IAPtr
A pointer to the Option6IA object.
Definition option6_ia.h:20
boost::shared_ptr< HWAddr > HWAddrPtr
Shared pointer to a hardware address structure.
Definition hwaddr.h:154
boost::shared_ptr< NetworkState > NetworkStatePtr
Pointer to the NetworkState object.
boost::shared_ptr< CBControlDHCPv6 > CBControlDHCPv6Ptr
boost::shared_ptr< Pkt6 > Pkt6Ptr
A pointer to Pkt6 packet.
Definition pkt6.h:31
boost::shared_ptr< Option > OptionPtr
Definition option.h:37
std::list< ConstCfgOptionPtr > CfgOptionList
Const pointer list.
Definition cfg_option.h:979
boost::shared_ptr< CalloutHandle > CalloutHandlePtr
A shared pointer to a CalloutHandle object.
Defines the logger used by the top-level component of kea-lfc.
This file provides the classes needed to embody, compose, and decompose DNS update requests that are ...
Context information for the DHCPv6 leases allocation.