Kea  1.5.0
network.h
Go to the documentation of this file.
1 // Copyright (C) 2017-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 NETWORK_H
8 #define NETWORK_H
9 
10 #include <asiolink/io_address.h>
11 #include <cc/cfg_to_element.h>
12 #include <cc/data.h>
13 #include <cc/stamped_element.h>
14 #include <cc/user_context.h>
15 #include <dhcp/classify.h>
16 #include <dhcp/option.h>
17 #include <dhcpsrv/cfg_option.h>
18 #include <dhcpsrv/cfg_4o6.h>
19 #include <dhcpsrv/triplet.h>
20 #include <boost/shared_ptr.hpp>
21 #include <boost/weak_ptr.hpp>
22 #include <cstdint>
23 #include <string>
24 
25 namespace isc {
26 namespace dhcp {
27 
29 typedef std::vector<isc::asiolink::IOAddress> IOAddressList;
30 
49 class Network : public virtual isc::data::StampedElement,
50  public virtual isc::data::UserContext,
52 public:
59  class RelayInfo {
60  public:
61 
66  void addAddress(const asiolink::IOAddress& addr);
67 
71  const IOAddressList& getAddresses() const;
72 
76  bool hasAddresses() const;
77 
81  bool containsAddress(const asiolink::IOAddress& addr) const;
82 
83  private:
85  IOAddressList addresses_;
86  };
87 
88 
91  typedef enum {
92 
96 
101 
105 
112  HR_ALL
114 
116  typedef boost::shared_ptr<Network::RelayInfo> RelayInfoPtr;
117 
120  : iface_name_(), client_class_(""), t1_(), t2_(), valid_(),
122  }
123 
127  virtual ~Network() { };
128 
137  void setIface(const std::string& iface_name) {
138  iface_name_ = iface_name;
139  }
140 
145  std::string getIface() const {
146  return (iface_name_);
147  };
148 
168  void setRelayInfo(const RelayInfo& relay) {
169  relay_ = relay;
170  }
171 
178  const RelayInfo& getRelayInfo() const {
179  return (relay_);
180  }
181 
186  void addRelayAddress(const asiolink::IOAddress& addr);
187 
191  const IOAddressList& getRelayAddresses() const;
192 
196  bool hasRelays() const;
197 
202  bool hasRelayAddress(const asiolink::IOAddress& address) const;
203 
218  virtual bool
219  clientSupported(const isc::dhcp::ClientClasses& client_classes) const;
220 
224  void allowClientClass(const isc::dhcp::ClientClass& class_name);
225 
229  void requireClientClass(const isc::dhcp::ClientClass& class_name);
230 
233 
241  return (client_class_);
242  }
243 
246  return (valid_);
247  }
248 
252  void setValid(const Triplet<uint32_t>& valid) {
253  valid_ = valid;
254  }
255 
258  return (t1_);
259  }
260 
264  void setT1(const Triplet<uint32_t>& t1) {
265  t1_ = t1;
266  }
267 
270  return (t2_);
271  }
272 
276  void setT2(const Triplet<uint32_t>& t2) {
277  t2_ = t2;
278  }
279 
288  HRMode
290  return (host_reservation_mode_);
291  }
292 
299  host_reservation_mode_ = mode;
300  }
301 
304  return (cfg_option_);
305  }
306 
310  return (cfg_option_);
311  }
312 
316  virtual data::ElementPtr toElement() const;
317 
318 protected:
319 
321  std::string iface_name_;
322 
327 
334 
340 
343 
346 
349 
354 
357 };
358 
360 typedef boost::shared_ptr<Network> NetworkPtr;
361 
363 typedef boost::weak_ptr<Network> WeakNetworkPtr;
364 
366 class Network4 : public Network {
367 public:
368 
371  : Network(), match_client_id_(true), authoritative_(false) {
372  }
373 
378  bool getMatchClientId() const {
379  return (match_client_id_);
380  }
381 
387  void setMatchClientId(const bool match) {
388  match_client_id_ = match;
389  }
390 
396  bool getAuthoritative() const {
397  return (authoritative_);
398  }
399 
405  void setAuthoritative(const bool authoritative) {
406  authoritative_ = authoritative;
407  }
408 
412  virtual data::ElementPtr toElement() const;
413 
418  virtual asiolink::IOAddress getServerId() const;
419 
420 private:
421 
424  bool match_client_id_;
425 
427  bool authoritative_;
428 };
429 
431 class Network6 : public Network {
432 public:
433 
436  : Network(), preferred_(0), interface_id_(), rapid_commit_(false) {
437  }
438 
443  return (preferred_);
444  }
445 
449  void setPreferred(const Triplet<uint32_t>& preferred) {
450  preferred_ = preferred;
451  }
452 
457  return (interface_id_);
458  }
459 
463  void setInterfaceId(const OptionPtr& ifaceid) {
464  interface_id_ = ifaceid;
465  }
466 
471  bool getRapidCommit() const {
472  return (rapid_commit_);
473  }
474 
479  void setRapidCommit(const bool rapid_commit) {
480  rapid_commit_ = rapid_commit;
481  };
482 
486  virtual data::ElementPtr toElement() const;
487 
488 private:
489 
491  Triplet<uint32_t> preferred_;
492 
494  OptionPtr interface_id_;
495 
501  bool rapid_commit_;
502 };
503 
504 } // end of namespace isc::dhcp
505 } // end of namespace isc
506 
507 #endif // NETWORK_H
isc::dhcp::Network::getIface
std::string getIface() const
Returns name of the local interface for which this network is selected.
Definition: network.h:145
isc::dhcp::ConstCfgOptionPtr
boost::shared_ptr< const CfgOption > ConstCfgOptionPtr
Const pointer.
Definition: cfg_option.h:500
isc::dhcp::Network::setIface
void setIface(const std::string &iface_name)
Sets local name of the interface for which this network is selected.
Definition: network.h:137
isc::dhcp::Network6::toElement
virtual data::ElementPtr toElement() const
Unparses network object.
Definition: network.cc:220
user_context.h
isc::dhcp::Network6::setRapidCommit
void setRapidCommit(const bool rapid_commit)
Enables or disables Rapid Commit option support for the subnet.
Definition: network.h:479
isc::dhcp::Network6::setPreferred
void setPreferred(const Triplet< uint32_t > &preferred)
Sets new preferred lifetime for a network.
Definition: network.h:449
isc::dhcp::Network::getClientClass
const isc::dhcp::ClientClass & getClientClass() const
returns the client class
Definition: network.h:240
isc::dhcp::Network::getCfgOption
ConstCfgOptionPtr getCfgOption() const
Returns const pointer to the option data configuration for this subnet.
Definition: network.h:309
stamped_element.h
isc::dhcp::Network::t1_
Triplet< uint32_t > t1_
a Triplet (min/default/max) holding allowed renew timer values
Definition: network.h:342
isc::dhcp::Network::host_reservation_mode_
HRMode host_reservation_mode_
Specifies host reservation mode.
Definition: network.h:353
io_address.h
isc::dhcp::Network::RelayInfo::hasAddresses
bool hasAddresses() const
Indicates whether or not the address list has entries.
Definition: network.cc:32
isc::data::CfgToElement
Abstract class for configuration Cfg_* classes.
Definition: cfg_to_element.h:29
isc::dhcp::Network::setValid
void setValid(const Triplet< uint32_t > &valid)
Sets new valid lifetime for a network.
Definition: network.h:252
classify.h
Defines elements for storing the names of client classes.
isc::data::UserContext
Base class for user context.
Definition: user_context.h:22
isc::dhcp::Network::HR_OUT_OF_POOL
@ HR_OUT_OF_POOL
Only out-of-pool reservations is allowed.
Definition: network.h:100
isc::dhcp::Network::getT1
Triplet< uint32_t > getT1() const
Returns T1 (renew timer), expressed in seconds.
Definition: network.h:257
isc::dhcp::Network::RelayInfo::getAddresses
const IOAddressList & getAddresses() const
Returns const reference to the list of addresses.
Definition: network.cc:49
isc::dhcp::Network::setHostReservationMode
void setHostReservationMode(HRMode mode)
Sets host reservation mode.
Definition: network.h:298
isc::dhcp::Network::required_classes_
ClientClasses required_classes_
Required classes.
Definition: network.h:339
isc::dhcp::Network::addRelayAddress
void addRelayAddress(const asiolink::IOAddress &addr)
Adds an address to the list addresses in the network's relay info.
Definition: network.cc:54
isc::dhcp::Network4::setMatchClientId
void setMatchClientId(const bool match)
Sets the flag indicating if the client identifier should be used to identify the client's lease.
Definition: network.h:387
isc::dhcp::Network::valid_
Triplet< uint32_t > valid_
a Triplet (min/default/max) holding allowed valid lifetime values
Definition: network.h:348
isc::dhcp::Network::HR_GLOBAL
@ HR_GLOBAL
Only global reservations are allowed.
Definition: network.h:104
isc::dhcp::Network::RelayInfo::containsAddress
bool containsAddress(const asiolink::IOAddress &addr) const
Checks the address list for the given address.
Definition: network.cc:37
isc::dhcp::Network::RelayInfoPtr
boost::shared_ptr< Network::RelayInfo > RelayInfoPtr
Pointer to the RelayInfo structure.
Definition: network.h:116
isc::dhcp::CfgOption
Represents option data configuration for the DHCP server.
Definition: cfg_option.h:248
isc::dhcp::Network4::toElement
virtual data::ElementPtr toElement() const
Unparses network object.
Definition: network.cc:192
isc::dhcp::Network::toElement
virtual data::ElementPtr toElement() const
Unparses network object.
Definition: network.cc:102
isc::dhcp::Network::setT2
void setT2(const Triplet< uint32_t > &t2)
Sets new rebind timer for a network.
Definition: network.h:276
isc::dhcp::Network::allowClientClass
void allowClientClass(const isc::dhcp::ClientClass &class_name)
Sets the supported class to class class_name.
Definition: network.cc:85
isc::dhcp::Network::cfg_option_
CfgOptionPtr cfg_option_
Pointer to the option data configuration for this subnet.
Definition: network.h:356
isc
Defines the logger used by the top-level component of kea-dhcp-ddns.
Definition: agent_parser.cc:144
isc::dhcp::Network6
Specialization of the Network object for DHCPv6 case.
Definition: network.h:431
isc::dhcp::Network6::Network6
Network6()
Constructor.
Definition: network.h:435
isc::data::StampedElement
This class represents configuration element which is associated with the modification timestamp.
Definition: stamped_element.h:31
isc::dhcp::Network4::getAuthoritative
bool getAuthoritative() const
Returns the flag indicating if requests for unknown IP addresses should be rejected with DHCPNAK inst...
Definition: network.h:396
isc::dhcp::Network::getRequiredClasses
const isc::dhcp::ClientClasses & getRequiredClasses() const
Returns classes which are required to be evaluated.
Definition: network.cc:97
cfg_option.h
isc::dhcp::Network::t2_
Triplet< uint32_t > t2_
a Triplet (min/default/max) holding allowed rebind timer values
Definition: network.h:345
isc::dhcp::Network::clientSupported
virtual bool clientSupported(const isc::dhcp::ClientClasses &client_classes) const
Checks whether this network supports client that belongs to specified classes.
Definition: network.cc:74
isc::dhcp::Network::HR_ALL
@ HR_ALL
Both out-of-pool and in-pool reservations are allowed.
Definition: network.h:112
isc::dhcp::Network::getValid
Triplet< uint32_t > getValid() const
Return valid-lifetime for addresses in that prefix.
Definition: network.h:245
isc::dhcp::Network::relay_
RelayInfo relay_
Relay information.
Definition: network.h:326
isc::dhcp::Network4::getServerId
virtual asiolink::IOAddress getServerId() const
Returns binary representation of the dhcp-server-identifier option (54).
Definition: network.cc:205
isc::dhcp::Network::getHostReservationMode
HRMode getHostReservationMode() const
Specifies what type of Host Reservations are supported.
Definition: network.h:289
isc::dhcp::Network::getRelayAddresses
const IOAddressList & getRelayAddresses() const
Returns the list of relay addresses from the network's relay info.
Definition: network.cc:69
isc::dhcp::Network::HR_DISABLED
@ HR_DISABLED
None - host reservation is disabled.
Definition: network.h:95
triplet.h
isc::dhcp::Network::hasRelays
bool hasRelays() const
Indicates if network's relay info has relay addresses.
Definition: network.cc:59
cfg_4o6.h
cfg_to_element.h
isc::dhcp::Network::setT1
void setT1(const Triplet< uint32_t > &t1)
Sets new renew timer for a network.
Definition: network.h:264
isc::dhcp::Network::iface_name_
std::string iface_name_
Holds interface name for which this network is selected.
Definition: network.h:321
isc::dhcp::Network::RelayInfo
Holds optional information about relay.
Definition: network.h:59
isc::dhcp::Network6::getPreferred
Triplet< uint32_t > getPreferred() const
Returns preferred lifetime (in seconds)
Definition: network.h:442
isc::dhcp::Network::getCfgOption
CfgOptionPtr getCfgOption()
Returns pointer to the option data configuration for this subnet.
Definition: network.h:303
isc::dhcp::WeakNetworkPtr
boost::weak_ptr< Network > WeakNetworkPtr
Weak pointer to the Network object.
Definition: network.h:363
isc::dhcp::ClientClass
std::string ClientClass
Defines a single class name.
Definition: classify.h:37
isc::dhcp::Network::client_class_
ClientClass client_class_
Optional definition of a client class.
Definition: network.h:333
isc::dhcp::Network6::getInterfaceId
OptionPtr getInterfaceId() const
Returns interface-id value (if specified)
Definition: network.h:456
isc::dhcp::Network::HRMode
HRMode
Specifies allowed host reservation mode.
Definition: network.h:91
data.h
isc::dhcp::OptionPtr
boost::shared_ptr< Option > OptionPtr
Definition: option.h:37
isc::dhcp::Network4::Network4
Network4()
Constructor.
Definition: network.h:370
isc::dhcp::Network::setRelayInfo
void setRelayInfo(const RelayInfo &relay)
Sets information about relay.
Definition: network.h:168
isc::dhcp::Network4::getMatchClientId
bool getMatchClientId() const
Returns the flag indicating if the client identifiers should be used to identify the client's lease.
Definition: network.h:378
isc::dhcp::CfgOptionPtr
boost::shared_ptr< CfgOption > CfgOptionPtr
Non-const pointer.
Definition: cfg_option.h:497
isc::data::ElementPtr
boost::shared_ptr< Element > ElementPtr
Definition: data.h:20
isc::dhcp::Network::getT2
Triplet< uint32_t > getT2() const
Returns T2 (rebind timer), expressed in seconds.
Definition: network.h:269
isc::dhcp::Network6::setInterfaceId
void setInterfaceId(const OptionPtr &ifaceid)
sets interface-id option (if defined)
Definition: network.h:463
isc::dhcp::Network
Common interface representing a network to which the DHCP clients are connected.
Definition: network.h:51
option.h
isc::dhcp::Network4
Specialization of the Network object for DHCPv4 case.
Definition: network.h:366
isc::dhcp::Network6::getRapidCommit
bool getRapidCommit() const
Returns boolean value indicating that the Rapid Commit option is supported or unsupported for the sub...
Definition: network.h:471
isc::dhcp::Network::~Network
virtual ~Network()
Virtual destructor.
Definition: network.h:127
isc::dhcp::Network::Network
Network()
Constructor.
Definition: network.h:119
isc::dhcp::Network4::setAuthoritative
void setAuthoritative(const bool authoritative)
Sets the flag indicating if requests for unknown IP addresses should be rejected with DHCPNAK instead...
Definition: network.h:405
isc::dhcp::Network::RelayInfo::addAddress
void addAddress(const asiolink::IOAddress &addr)
Adds an address to the list of addresses.
Definition: network.cc:22
isc::dhcp::IOAddressList
std::vector< isc::asiolink::IOAddress > IOAddressList
List of IOAddresses.
Definition: network.h:29
isc::dhcp::Network::requireClientClass
void requireClientClass(const isc::dhcp::ClientClass &class_name)
Adds class class_name to classes required to be evaluated.
Definition: network.cc:90
isc::dhcp::Triplet< uint32_t >
isc::dhcp::Network::hasRelayAddress
bool hasRelayAddress(const asiolink::IOAddress &address) const
Tests if the network's relay info contains the given address.
Definition: network.cc:64
isc::dhcp::ClientClasses
Container for storing client class names.
Definition: classify.h:43
isc::dhcp::NetworkPtr
boost::shared_ptr< Network > NetworkPtr
Pointer to the Network object.
Definition: network.h:360
isc::dhcp::Network::getRelayInfo
const RelayInfo & getRelayInfo() const
Returns const reference to relay information.
Definition: network.h:178