Kea 2.7.1
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, Subnet6Ptr& subnet);
176
185
194
202
210
220
228
230 void shutdown() override;
231
235
236
243 uint16_t getServerPort() const {
244 return (server_port_);
245 }
247
253 void startD2();
254
260 void stopD2();
261
276 virtual void d2ClientErrorHandler(const dhcp_ddns::
277 NameChangeSender::Result result,
278 dhcp_ddns::NameChangeRequestPtr& ncr);
279
283 void discardPackets();
284
289 void initContext0(const Pkt6Ptr& query,
291
299 bool earlyGHRLookup(const Pkt6Ptr& query,
301
311
312protected:
313
321
330 bool testServerID(const Pkt6Ptr& pkt);
331
342 bool testUnicast(const Pkt6Ptr& pkt) const;
343
352 bool sanityCheck(const Pkt6Ptr& pkt);
353
363 void sanityCheck(const Pkt6Ptr& pkt, RequirementLevel clientid,
364 RequirementLevel serverid);
365
371 void sanityCheckDUID(const OptionPtr& opt, const std::string& opt_name);
372
388
401
408
421
446
453
465
472
482 void processDhcp4Query(const Pkt6Ptr& dhcp4_query);
483
489 isc::dhcp::Subnet6Ptr selectSubnet(const Pkt6Ptr& question, bool& drop);
490
507 Option6IAPtr ia);
508
521 OptionPtr assignIA_PD(const Pkt6Ptr& query,
523 boost::shared_ptr<Option6IA> ia);
524
538 OptionPtr extendIA_NA(const Pkt6Ptr& query,
540 Option6IAPtr ia);
541
595 OptionPtr extendIA_PD(const Pkt6Ptr& query,
597 Option6IAPtr ia);
598
617 OptionPtr releaseIA_NA(const DuidPtr& duid, const Pkt6Ptr& query,
618 int& general_status,
619 boost::shared_ptr<Option6IA> ia,
620 Lease6Ptr& old_lease);
621
635 OptionPtr releaseIA_PD(const DuidPtr& duid, const Pkt6Ptr& query,
636 int& general_status,
637 boost::shared_ptr<Option6IA> ia,
638 Lease6Ptr& old_lease);
639
649 void copyClientOptions(const Pkt6Ptr& question, Pkt6Ptr& answer);
650
659 void buildCfgOptionList(const Pkt6Ptr& question,
661 CfgOptionList& co_list);
662
672 void appendDefaultOptions(const Pkt6Ptr& question, Pkt6Ptr& answer,
673 const CfgOptionList& co_list);
674
683 void appendRequestedOptions(const Pkt6Ptr& question, Pkt6Ptr& answer,
684 const CfgOptionList& co_list);
685
695 void appendRequestedVendorOptions(const Pkt6Ptr& question, Pkt6Ptr& answer,
697 const CfgOptionList& co_list);
698
709 void assignLeases(const Pkt6Ptr& question, Pkt6Ptr& answer,
711
756 void processClientFqdn(const Pkt6Ptr& question, const Pkt6Ptr& answer,
758
778 void createNameChangeRequests(const Pkt6Ptr& answer,
780
792 void extendLeases(const Pkt6Ptr& query, Pkt6Ptr& reply,
794
820 void setTeeTimes(uint32_t preferred_lft, const Subnet6Ptr& subnet, Option6IAPtr& resp);
821
832 void releaseLeases(const Pkt6Ptr& release, Pkt6Ptr& reply,
834
841 static std::string duidToString(const OptionPtr& opt);
842
847 virtual Pkt6Ptr receivePacket(int timeout);
848
853 virtual void sendPacket(const Pkt6Ptr& pkt);
854
865 void classifyPacket(const Pkt6Ptr& pkt);
866
877 void evaluateClasses(const Pkt6Ptr& pkt, bool depend_on_known);
878
885 static void removeDependentEvaluatedClasses(const Pkt6Ptr& pkt);
886
891 void setReservedClientClasses(const Pkt6Ptr& pkt,
892 const AllocEngine::ClientContext6& ctx);
893
905 const AllocEngine::ClientContext6& ctx);
906
919
927 static HWAddrPtr getMAC(const Pkt6Ptr& pkt);
928
937 void processRSOO(const Pkt6Ptr& query, const Pkt6Ptr& rsp);
938
957 void initContext(AllocEngine::ClientContext6& ctx, bool& drop);
958
965 static const std::string VENDOR_CLASS_PREFIX;
966
977 bool declineLeases(const Pkt6Ptr& decline, Pkt6Ptr& reply,
979
994 declineIA(const Pkt6Ptr& decline, const DuidPtr& duid, int& general_status,
995 boost::shared_ptr<Option6IA> ia, Lease6Collection& new_leases);
996
1013 bool declineLease(const Pkt6Ptr& decline, const Lease6Ptr lease,
1014 boost::shared_ptr<Option6IA> ia_rsp);
1015
1021 void setStatusCode(boost::shared_ptr<Option6IA>& container,
1022 const OptionPtr& status);
1023
1058 //
1059 void checkDynamicSubnetChange(const Pkt6Ptr& question, Pkt6Ptr& answer,
1061 const Subnet6Ptr orig_subnet);
1062public:
1063
1065
1070 static uint16_t checkRelaySourcePort(const Pkt6Ptr& query);
1071
1072private:
1073
1079 void classifyByVendor(const Pkt6Ptr& pkt);
1080
1097 void updateReservedFqdn(AllocEngine::ClientContext6& ctx,
1098 const Pkt6Ptr& answer);
1099
1142 void generateFqdn(const Pkt6Ptr& answer,
1144
1147 static void processStatsReceived(const Pkt6Ptr& query);
1148
1156 bool requestedInORO(const Pkt6Ptr& query, const uint16_t code) const;
1157
1164 static std::tuple<bool, uint32_t> parkingLimitExceeded(std::string const& hook_label);
1165
1166protected:
1169
1172
1173public:
1174
1176
1179 static void processStatsSent(const Pkt6Ptr& response);
1180
1183 static int getHookIndexBuffer6Send();
1184
1190 Pkt6Ptr& rsp);
1191
1197 std::list<std::list<std::string>> jsonPathsToRedact() const final override;
1198
1199protected:
1200
1203
1206 volatile bool shutdown_;
1207
1214 void processPacketPktSend(hooks::CalloutHandlePtr& callout_handle,
1215 Pkt6Ptr& query, Pkt6Ptr& rsp, Subnet6Ptr& subnet);
1216
1222
1225 std::queue<isc::dhcp_ddns::NameChangeRequest> name_change_reqs_;
1226
1230
1233};
1234
1235} // namespace dhcp
1236} // namespace isc
1237
1238#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:1225
void shutdown() override
Instructs the server to shut down.
Definition dhcp6_srv.cc:310
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:743
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:718
OptionPtr extendIA_PD(const Pkt6Ptr &query, AllocEngine::ClientContext6 &ctx, Option6IAPtr ia)
Extends lifetime of the prefix.
void sendResponseNoThrow(hooks::CalloutHandlePtr &callout_handle, Pkt6Ptr query, Pkt6Ptr &rsp, Subnet6Ptr &subnet)
Process an unparked DHCPv6 packet and sends the response.
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 processLocalizedQuery6AndSendResponse(Pkt6Ptr query, AllocEngine::ClientContext6 &ctx)
Process a localized incoming DHCPv6 query.
int run()
Main server processing loop.
Definition dhcp6_srv.cc:598
void setPacketStatisticsDefaults()
This function sets statistics related to DHCPv6 packets processing to their initial values.
Definition dhcp6_srv.cc:261
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:1221
virtual void sendPacket(const Pkt6Ptr &pkt)
dummy wrapper around IfaceMgr::send()
Definition dhcp6_srv.cc:319
bool testServerID(const Pkt6Ptr &pkt)
Compare received server id with our server id.
Definition dhcp6_srv.cc:324
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.
Definition dhcp6_srv.h:243
void runOne()
Main server processing step.
Definition dhcp6_srv.cc:640
virtual Pkt6Ptr receivePacket(int timeout)
dummy wrapper around IfaceMgr::receive6
Definition dhcp6_srv.cc:315
void processPacketBufferSend(hooks::CalloutHandlePtr &callout_handle, Pkt6Ptr &rsp)
Executes buffer6_send callout and sends the response.
void requiredClassify(const Pkt6Ptr &pkt, AllocEngine::ClientContext6 &ctx)
Assigns incoming packet to zero or more classes (required pass).
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:965
OptionPtr serverid_
Server DUID (to be sent in server-identifier option)
Definition dhcp6_srv.h:1202
void checkDynamicSubnetChange(const Pkt6Ptr &question, Pkt6Ptr &answer, AllocEngine::ClientContext6 &ctx, const Subnet6Ptr orig_subnet)
Iterates over new leases, update stale DNS entries.
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:732
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:442
void initContext0(const Pkt6Ptr &query, AllocEngine::ClientContext6 &ctx)
Initialize client context (first part).
Definition dhcp6_srv.cc:429
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:271
void setTeeTimes(uint32_t preferred_lft, const Subnet6Ptr &subnet, Option6IAPtr &resp)
Sets the T1 and T2 timers in the outbound IA.
void initContext(AllocEngine::ClientContext6 &ctx, bool &drop)
Initializes client context for specified packet.
Definition dhcp6_srv.cc:506
Pkt6Ptr processRequest(AllocEngine::ClientContext6 &ctx)
Processes incoming Request and returns Reply response.
NetworkStatePtr network_state_
Holds information about disabled DHCP service and/or disabled subnet/network scopes.
Definition dhcp6_srv.h:1229
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:346
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 processPacketPktSend(hooks::CalloutHandlePtr &callout_handle, Pkt6Ptr &query, Pkt6Ptr &rsp, Subnet6Ptr &subnet)
Executes pkt6_send callout.
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:217
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:367
Pkt6Ptr processDhcp6Query(Pkt6Ptr query)
Process a single incoming DHCPv6 query.
Definition dhcp6_srv.cc:964
void processDhcp6QueryAndSendResponse(Pkt6Ptr query)
Process a single incoming DHCPv6 query.
Definition dhcp6_srv.cc:944
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:1171
CBControlDHCPv6Ptr cb_control_
Controls access to the configuration backends.
Definition dhcp6_srv.h:1232
volatile bool shutdown_
Indicates if shutdown is in progress.
Definition dhcp6_srv.h:1206
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....
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:1168
isc::dhcp::Subnet6Ptr selectSubnet(const Pkt6Ptr &question, bool &drop)
Selects a subnet for a given client's packet.
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< 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< Subnet6 > Subnet6Ptr
A pointer to a Subnet6 object.
Definition subnet.h:623
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:809
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.