Kea 2.7.5
dhcp6_srv.h
Go to the documentation of this file.
1// Copyright (C) 2011-2024 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,
277 dhcp_ddns::NameChangeRequestPtr& ncr);
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
488 isc::dhcp::ConstSubnet6Ptr selectSubnet(const Pkt6Ptr& question, bool& drop);
489
506 Option6IAPtr ia);
507
520 OptionPtr assignIA_PD(const Pkt6Ptr& query,
522 boost::shared_ptr<Option6IA> ia);
523
537 OptionPtr extendIA_NA(const Pkt6Ptr& query,
539 Option6IAPtr ia);
540
594 OptionPtr extendIA_PD(const Pkt6Ptr& query,
596 Option6IAPtr ia);
597
616 OptionPtr releaseIA_NA(const DuidPtr& duid, const Pkt6Ptr& query,
617 int& general_status,
618 boost::shared_ptr<Option6IA> ia,
619 Lease6Ptr& old_lease);
620
634 OptionPtr releaseIA_PD(const DuidPtr& duid, const Pkt6Ptr& query,
635 int& general_status,
636 boost::shared_ptr<Option6IA> ia,
637 Lease6Ptr& old_lease);
638
648 void copyClientOptions(const Pkt6Ptr& question, Pkt6Ptr& answer);
649
658 void buildCfgOptionList(const Pkt6Ptr& question,
660 CfgOptionList& co_list);
661
671 void appendDefaultOptions(const Pkt6Ptr& question, Pkt6Ptr& answer,
672 const CfgOptionList& co_list);
673
682 void appendRequestedOptions(const Pkt6Ptr& question, Pkt6Ptr& answer,
683 const CfgOptionList& co_list);
684
694 void appendRequestedVendorOptions(const Pkt6Ptr& question, Pkt6Ptr& answer,
696 const CfgOptionList& co_list);
697
708 void assignLeases(const Pkt6Ptr& question, Pkt6Ptr& answer,
710
755 void processClientFqdn(const Pkt6Ptr& question, const Pkt6Ptr& answer,
757
777 void createNameChangeRequests(const Pkt6Ptr& answer,
779
791 void extendLeases(const Pkt6Ptr& query, Pkt6Ptr& reply,
793
819 void setTeeTimes(uint32_t preferred_lft,
820 const ConstSubnet6Ptr& subnet,
821 Option6IAPtr& resp);
822
833 void releaseLeases(const Pkt6Ptr& release, Pkt6Ptr& reply,
835
842 static std::string duidToString(const OptionPtr& opt);
843
848 virtual Pkt6Ptr receivePacket(int timeout);
849
854 virtual void sendPacket(const Pkt6Ptr& pkt);
855
866 void classifyPacket(const Pkt6Ptr& pkt);
867
878 void evaluateClasses(const Pkt6Ptr& pkt, bool depend_on_known);
879
886 static void removeDependentEvaluatedClasses(const Pkt6Ptr& pkt);
887
892 void setReservedClientClasses(const Pkt6Ptr& pkt,
893 const AllocEngine::ClientContext6& ctx);
894
906 const AllocEngine::ClientContext6& ctx);
907
926
934 static HWAddrPtr getMAC(const Pkt6Ptr& pkt);
935
944 void processRSOO(const Pkt6Ptr& query, const Pkt6Ptr& rsp);
945
964 void initContext(AllocEngine::ClientContext6& ctx, bool& drop);
965
972 static const std::string VENDOR_CLASS_PREFIX;
973
984 bool declineLeases(const Pkt6Ptr& decline, Pkt6Ptr& reply,
986
1000 OptionPtr
1001 declineIA(const Pkt6Ptr& decline, const DuidPtr& duid, int& general_status,
1002 boost::shared_ptr<Option6IA> ia, Lease6Collection& new_leases);
1003
1020 bool declineLease(const Pkt6Ptr& decline, const Lease6Ptr lease,
1021 boost::shared_ptr<Option6IA> ia_rsp);
1022
1028 void setStatusCode(boost::shared_ptr<Option6IA>& container,
1029 const OptionPtr& status);
1030
1065 //
1066 void checkDynamicSubnetChange(const Pkt6Ptr& question, Pkt6Ptr& answer,
1068 const ConstSubnet6Ptr orig_subnet);
1069
1076 const Lease6Ptr& lease);
1077
1078public:
1079
1081
1086 static uint16_t checkRelaySourcePort(const Pkt6Ptr& query);
1087
1088private:
1089
1095 void classifyByVendor(const Pkt6Ptr& pkt);
1096
1113 void updateReservedFqdn(AllocEngine::ClientContext6& ctx,
1114 const Pkt6Ptr& answer);
1115
1158 void generateFqdn(const Pkt6Ptr& answer,
1160
1163 static void processStatsReceived(const Pkt6Ptr& query);
1164
1172 bool requestedInORO(const Pkt6Ptr& query, const uint16_t code) const;
1173
1180 static std::tuple<bool, uint32_t> parkingLimitExceeded(std::string const& hook_label);
1181
1182protected:
1185
1188
1189public:
1190
1192
1195 static void processStatsSent(const Pkt6Ptr& response);
1196
1199 static int getHookIndexBuffer6Send();
1200
1206 Pkt6Ptr& rsp);
1207
1213 std::list<std::list<std::string>> jsonPathsToRedact() const final override;
1214
1215protected:
1216
1219
1222 volatile bool shutdown_;
1223
1230 void processPacketPktSend(hooks::CalloutHandlePtr& callout_handle,
1231 Pkt6Ptr& query, Pkt6Ptr& rsp,
1232 ConstSubnet6Ptr& subnet);
1233
1239
1242 std::queue<isc::dhcp_ddns::NameChangeRequest> name_change_reqs_;
1243
1247
1250};
1251
1252} // namespace dhcp
1253} // namespace isc
1254
1255#endif // DHCP6_SRV_H
This is a base class for exceptions thrown from the DNS library module.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
DHCPv4 and DHCPv6 allocation engine.
This exception is thrown when DHCP server hits the error which should result in discarding the messag...
Definition dhcp6_srv.h:48
DHCPv6DiscardMessageError(const char *file, size_t line, const char *what)
Definition dhcp6_srv.h:50
DHCPv6 server service.
Definition dhcp6_srv.h:66
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:1242
void shutdown() override
Instructs the server to shut down.
Definition dhcp6_srv.cc:355
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:804
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:779
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:643
void setPacketStatisticsDefaults()
This function sets statistics related to DHCPv6 packets processing to their initial values.
Definition dhcp6_srv.cc:301
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:1238
virtual void sendPacket(const Pkt6Ptr &pkt)
dummy wrapper around IfaceMgr::send()
Definition dhcp6_srv.cc:364
bool testServerID(const Pkt6Ptr &pkt)
Compare received server id with our server id.
Definition dhcp6_srv.cc:369
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:701
virtual Pkt6Ptr receivePacket(int timeout)
dummy wrapper around IfaceMgr::receive6
Definition dhcp6_srv.cc:360
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:972
OptionPtr serverid_
Server DUID (to be sent in server-identifier option)
Definition dhcp6_srv.h:1218
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 checkDynamicSubnetChange(const Pkt6Ptr &question, Pkt6Ptr &answer, AllocEngine::ClientContext6 &ctx, const ConstSubnet6Ptr orig_subnet)
Iterates over new leases, update stale DNS entries.
void processPacketAndSendResponse(Pkt6Ptr query)
Process a single incoming DHCPv6 packet and sends the response.
Definition dhcp6_srv.cc:793
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:487
void initContext0(const Pkt6Ptr &query, AllocEngine::ClientContext6 &ctx)
Initialize client context (first part).
Definition dhcp6_srv.cc:474
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:311
void initContext(AllocEngine::ClientContext6 &ctx, bool &drop)
Initializes client context for specified packet.
Definition dhcp6_srv.cc:551
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:1246
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:391
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:256
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.
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:412
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:1187
CBControlDHCPv6Ptr cb_control_
Controls access to the configuration backends.
Definition dhcp6_srv.h:1249
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:1222
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:1184
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< 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:508
std::vector< Lease6Ptr > Lease6Collection
A collection of IPv6 leases.
Definition lease.h:673
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:838
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.