Kea  2.3.2-git
dhcp6_srv.h
Go to the documentation of this file.
1 // Copyright (C) 2011-2022 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>
18 #include <dhcp/option_definition.h>
19 #include <dhcp_ddns/ncr_msg.h>
20 #include <dhcp/pkt6.h>
21 #include <dhcpsrv/alloc_engine.h>
23 #include <dhcpsrv/cb_ctl_dhcp6.h>
24 #include <dhcpsrv/cfg_option.h>
25 #include <dhcpsrv/d2_client_mgr.h>
26 #include <dhcpsrv/network_state.h>
27 #include <dhcpsrv/subnet.h>
28 #include <hooks/callout_handle.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 
43 namespace isc {
44 namespace dhcp {
45 
49 public:
50  DHCPv6DiscardMessageError(const char* file, size_t line, const char* what) :
51  isc::Exception(file, line, what) { };
52 };
53 
66 class Dhcpv6Srv : public process::Daemon {
67 private:
68 
70  asiolink::IOServicePtr io_service_;
71 
72 public:
74  typedef enum {
77  OPTIONAL
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 
116  return (network_state_);
117  }
118 
125  return (cb_control_);
126  }
127 
130  static std::string getVersion(bool extended);
131 
135  OptionPtr getServerID() { return serverid_; }
136 
143  int run();
144 
150  void run_one();
151 
158  void processPacketAndSendResponse(Pkt6Ptr& query);
159 
166  void processPacketAndSendResponseNoThrow(Pkt6Ptr& query);
167 
173  void sendResponseNoThrow(hooks::CalloutHandlePtr& callout_handle,
174  Pkt6Ptr& query, Pkt6Ptr& rsp);
175 
183  void processPacket(Pkt6Ptr& query, Pkt6Ptr& rsp);
184 
191  void processDhcp6Query(Pkt6Ptr& query, Pkt6Ptr& rsp);
192 
200  void processDhcp6QueryAndSendResponse(Pkt6Ptr& query, Pkt6Ptr& rsp);
201 
203  void shutdown() override;
204 
208 
209  uint16_t getServerPort() const {
217  return (server_port_);
218  }
220 
226  void startD2();
227 
233  void stopD2();
234 
249  virtual void d2ClientErrorHandler(const dhcp_ddns::
250  NameChangeSender::Result result,
252 
256  void discardPackets();
257 
265  bool earlyGHRLookup(const Pkt6Ptr& query,
267 
276  static void setHostIdentifiers(AllocEngine::ClientContext6& ctx);
277 
278 protected:
279 
286  void setPacketStatisticsDefaults();
287 
296  bool testServerID(const Pkt6Ptr& pkt);
297 
308  bool testUnicast(const Pkt6Ptr& pkt) const;
309 
318  bool sanityCheck(const Pkt6Ptr& pkt);
319 
329  void sanityCheck(const Pkt6Ptr& pkt, RequirementLevel clientid,
330  RequirementLevel serverid);
331 
337  void sanityCheckDUID(const OptionPtr& opt, const std::string& opt_name);
338 
353  Pkt6Ptr processSolicit(AllocEngine::ClientContext6& ctx);
354 
366  Pkt6Ptr processRequest(AllocEngine::ClientContext6& ctx);
367 
373  Pkt6Ptr processRenew(AllocEngine::ClientContext6& ctx);
374 
386  Pkt6Ptr processRebind(AllocEngine::ClientContext6& ctx);
387 
411  Pkt6Ptr processConfirm(AllocEngine::ClientContext6& ctx);
412 
418  Pkt6Ptr processRelease(AllocEngine::ClientContext6& ctx);
419 
430  Pkt6Ptr processDecline(AllocEngine::ClientContext6& ctx);
431 
437  Pkt6Ptr processInfRequest(AllocEngine::ClientContext6& ctx);
438 
448  void processDhcp4Query(const Pkt6Ptr& dhcp4_query);
449 
455  isc::dhcp::Subnet6Ptr selectSubnet(const Pkt6Ptr& question, bool& drop);
456 
471  OptionPtr assignIA_NA(const isc::dhcp::Pkt6Ptr& query,
473  Option6IAPtr ia);
474 
487  OptionPtr assignIA_PD(const Pkt6Ptr& query,
489  boost::shared_ptr<Option6IA> ia);
490 
504  OptionPtr extendIA_NA(const Pkt6Ptr& query,
506  Option6IAPtr ia);
507 
561  OptionPtr extendIA_PD(const Pkt6Ptr& query,
563  Option6IAPtr ia);
564 
583  OptionPtr releaseIA_NA(const DuidPtr& duid, const Pkt6Ptr& query,
584  int& general_status,
585  boost::shared_ptr<Option6IA> ia,
586  Lease6Ptr& old_lease);
587 
601  OptionPtr releaseIA_PD(const DuidPtr& duid, const Pkt6Ptr& query,
602  int& general_status,
603  boost::shared_ptr<Option6IA> ia,
604  Lease6Ptr& old_lease);
605 
615  void copyClientOptions(const Pkt6Ptr& question, Pkt6Ptr& answer);
616 
625  void buildCfgOptionList(const Pkt6Ptr& question,
627  CfgOptionList& co_list);
628 
638  void appendDefaultOptions(const Pkt6Ptr& question, Pkt6Ptr& answer,
639  const CfgOptionList& co_list);
640 
649  void appendRequestedOptions(const Pkt6Ptr& question, Pkt6Ptr& answer,
650  const CfgOptionList& co_list);
651 
661  void appendRequestedVendorOptions(const Pkt6Ptr& question, Pkt6Ptr& answer,
663  const CfgOptionList& co_list);
664 
675  void assignLeases(const Pkt6Ptr& question, Pkt6Ptr& answer,
677 
722  void processClientFqdn(const Pkt6Ptr& question, const Pkt6Ptr& answer,
724 
744  void createNameChangeRequests(const Pkt6Ptr& answer,
746 
758  void extendLeases(const Pkt6Ptr& query, Pkt6Ptr& reply,
760 
786  void setTeeTimes(uint32_t preferred_lft, const Subnet6Ptr& subnet, Option6IAPtr& resp);
787 
798  void releaseLeases(const Pkt6Ptr& release, Pkt6Ptr& reply,
800 
807  static std::string duidToString(const OptionPtr& opt);
808 
813  virtual Pkt6Ptr receivePacket(int timeout);
814 
819  virtual void sendPacket(const Pkt6Ptr& pkt);
820 
831  void classifyPacket(const Pkt6Ptr& pkt);
832 
843  void evaluateClasses(const Pkt6Ptr& pkt, bool depend_on_known);
844 
851  static void removeDependentEvaluatedClasses(const Pkt6Ptr& pkt);
852 
857  void setReservedClientClasses(const Pkt6Ptr& pkt,
858  const AllocEngine::ClientContext6& ctx);
859 
870  void conditionallySetReservedClientClasses(const Pkt6Ptr& pkt,
871  const AllocEngine::ClientContext6& ctx);
872 
884  void requiredClassify(const Pkt6Ptr& pkt, AllocEngine::ClientContext6& ctx);
885 
893  static HWAddrPtr getMAC(const Pkt6Ptr& pkt);
894 
903  void processRSOO(const Pkt6Ptr& query, const Pkt6Ptr& rsp);
904 
925  void initContext(const Pkt6Ptr& pkt,
927  bool& drop);
928 
935  static const std::string VENDOR_CLASS_PREFIX;
936 
947  bool declineLeases(const Pkt6Ptr& decline, Pkt6Ptr& reply,
949 
963  OptionPtr
964  declineIA(const Pkt6Ptr& decline, const DuidPtr& duid, int& general_status,
965  boost::shared_ptr<Option6IA> ia, Lease6Collection& new_leases);
966 
983  bool declineLease(const Pkt6Ptr& decline, const Lease6Ptr lease,
984  boost::shared_ptr<Option6IA> ia_rsp);
985 
991  void setStatusCode(boost::shared_ptr<Option6IA>& container,
992  const OptionPtr& status);
993 
1028  //
1029  void checkDynamicSubnetChange(const Pkt6Ptr& question, Pkt6Ptr& answer,
1031  const Subnet6Ptr orig_subnet);
1032 public:
1033 
1035 
1040  static uint16_t checkRelaySourcePort(const Pkt6Ptr& query);
1041 
1042 private:
1043 
1049  void classifyByVendor(const Pkt6Ptr& pkt);
1050 
1067  void updateReservedFqdn(AllocEngine::ClientContext6& ctx,
1068  const Pkt6Ptr& answer);
1069 
1112  void generateFqdn(const Pkt6Ptr& answer,
1114 
1117  static void processStatsReceived(const Pkt6Ptr& query);
1118 
1126  bool requestedInORO(const Pkt6Ptr& query, const uint16_t code) const;
1127 
1128 protected:
1130  uint16_t server_port_;
1131 
1133  uint16_t client_port_;
1134 
1135 public:
1136 
1138 
1141  static void processStatsSent(const Pkt6Ptr& response);
1142 
1145  static int getHookIndexBuffer6Send();
1146 
1151  void processPacketBufferSend(hooks::CalloutHandlePtr& callout_handle,
1152  Pkt6Ptr& rsp);
1153 
1159  std::list<std::list<std::string>> jsonPathsToRedact() const final override;
1160 
1161 protected:
1162 
1164  OptionPtr serverid_;
1165 
1168  volatile bool shutdown_;
1169 
1175  void processPacketPktSend(hooks::CalloutHandlePtr& callout_handle,
1176  Pkt6Ptr& query, Pkt6Ptr& rsp);
1177 
1182  boost::shared_ptr<AllocEngine> alloc_engine_;
1183 
1186  std::queue<isc::dhcp_ddns::NameChangeRequest> name_change_reqs_;
1187 
1190  NetworkStatePtr network_state_;
1191 
1193  CBControlDHCPv6Ptr cb_control_;
1194 };
1195 
1196 } // namespace dhcp
1197 } // namespace isc
1198 
1199 #endif // DHCP6_SRV_H
uint16_t server_port_
UDP port number on which server listens.
Definition: dhcp6_srv.h:1130
boost::shared_ptr< DUID > DuidPtr
Definition: duid.h:20
boost::shared_ptr< HWAddr > HWAddrPtr
Shared pointer to a hardware address structure.
Definition: hwaddr.h:154
CBControlDHCPv6Ptr getCBControl() const
Returns an object which controls access to the configuration backends.
Definition: dhcp6_srv.h:124
boost::shared_ptr< Option > OptionPtr
Definition: option.h:36
STL namespace.
boost::shared_ptr< NameChangeRequest > NameChangeRequestPtr
Defines a pointer to a NameChangeRequest.
Definition: ncr_msg.h:212
DHCPv6DiscardMessageError(const char *file, size_t line, const char *what)
Definition: dhcp6_srv.h:50
boost::shared_ptr< CBControlDHCPv6 > CBControlDHCPv6Ptr
Definition: cb_ctl_dhcp6.h:45
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
NetworkStatePtr & getNetworkState()
Returns pointer to the network state used by the server.
Definition: dhcp6_srv.h:115
boost::shared_ptr< Option6IA > Option6IAPtr
A pointer to the Option6IA object.
Definition: option6_ia.h:17
boost::shared_ptr< Pkt6 > Pkt6Ptr
A pointer to Pkt6 packet.
Definition: pkt6.h:28
OptionPtr getServerID()
Returns server-identifier option.
Definition: dhcp6_srv.h:135
std::list< ConstCfgOptionPtr > CfgOptionList
Const pointer list.
Definition: cfg_option.h:751
RequirementLevel
defines if certain option may, must or must not appear
Definition: dhcp6_srv.h:74
Context information for the DHCPv6 leases allocation.
Definition: alloc_engine.h:459
std::vector< Lease6Ptr > Lease6Collection
A collection of IPv6 leases.
Definition: lease.h:661
uint16_t client_port_
UDP port number to which server sends all responses.
Definition: dhcp6_srv.h:1133
This is a base class for exceptions thrown from the DNS library module.
Defines the logger used by the top-level component of kea-lfc.
This exception is thrown when DHCP server hits the error which should result in discarding the messag...
Definition: dhcp6_srv.h:48
boost::shared_ptr< CalloutHandle > CalloutHandlePtr
A shared pointer to a CalloutHandle object.
asiolink::IOServicePtr & getIOService()
Returns pointer to the IO service used by the server.
Definition: dhcp6_srv.h:110
boost::shared_ptr< NetworkState > NetworkStatePtr
Pointer to the NetworkState object.
Base class for all services.
Definition: daemon.h:48
boost::shared_ptr< Subnet6 > Subnet6Ptr
A pointer to a Subnet6 object.
Definition: subnet.h:672
bool inTestMode() const
Checks if the server is running in unit test mode.
Definition: dhcp6_srv.h:105
DHCPv4 and DHCPv6 allocation engine.
Definition: alloc_engine.h:63
boost::shared_ptr< Lease6 > Lease6Ptr
Pointer to a Lease6 structure.
Definition: lease.h:503
This file provides the classes needed to embody, compose, and decompose DNS update requests that are ...
Defines the D2ClientMgr class.
static const std::string VENDOR_CLASS_PREFIX
this is a prefix added to the content of vendor-class option
Definition: dhcp6_srv.h:935
DHCPv6 server service.
Definition: dhcp6_srv.h:66