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 
113  } HRMode;
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
const isc::dhcp::ClientClass & getClientClass() const
returns the client class
Definition: network.h:240
virtual ~Network()
Virtual destructor.
Definition: network.h:127
bool hasRelayAddress(const asiolink::IOAddress &address) const
Tests if the network's relay info contains the given address.
Definition: network.cc:64
boost::weak_ptr< Network > WeakNetworkPtr
Weak pointer to the Network object.
Definition: network.h:363
This class represents configuration element which is associated with the modification timestamp.
std::vector< isc::asiolink::IOAddress > IOAddressList
List of IOAddresses.
Definition: network.h:29
boost::shared_ptr< CfgOption > CfgOptionPtr
Non-const pointer.
Definition: cfg_option.h:497
Both out-of-pool and in-pool reservations are allowed.
Definition: network.h:112
boost::shared_ptr< Network > NetworkPtr
Pointer to the Network object.
Definition: network.h:360
ClientClasses required_classes_
Required classes.
Definition: network.h:339
const IOAddressList & getAddresses() const
Returns const reference to the list of addresses.
Definition: network.cc:49
HRMode host_reservation_mode_
Specifies host reservation mode.
Definition: network.h:353
Triplet< uint32_t > getT1() const
Returns T1 (renew timer), expressed in seconds.
Definition: network.h:257
Only global reservations are allowed.
Definition: network.h:104
Triplet< uint32_t > t2_
a Triplet (min/default/max) holding allowed rebind timer values
Definition: network.h:345
boost::shared_ptr< Network::RelayInfo > RelayInfoPtr
Pointer to the RelayInfo structure.
Definition: network.h:116
Base class for user context.
Definition: user_context.h:22
boost::shared_ptr< const CfgOption > ConstCfgOptionPtr
Const pointer.
Definition: cfg_option.h:500
void setValid(const Triplet< uint32_t > &valid)
Sets new valid lifetime for a network.
Definition: network.h:252
Defines elements for storing the names of client classes.
Only out-of-pool reservations is allowed.
Definition: network.h:100
boost::shared_ptr< Option > OptionPtr
Definition: option.h:37
HRMode getHostReservationMode() const
Specifies what type of Host Reservations are supported.
Definition: network.h:289
bool hasAddresses() const
Indicates whether or not the address list has entries.
Definition: network.cc:32
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
boost::shared_ptr< Element > ElementPtr
Definition: data.h:20
Network4()
Constructor.
Definition: network.h:370
void setInterfaceId(const OptionPtr &ifaceid)
sets interface-id option (if defined)
Definition: network.h:463
CfgOptionPtr getCfgOption()
Returns pointer to the option data configuration for this subnet.
Definition: network.h:303
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
Network6()
Constructor.
Definition: network.h:435
bool containsAddress(const asiolink::IOAddress &addr) const
Checks the address list for the given address.
Definition: network.cc:37
Specialization of the Network object for DHCPv6 case.
Definition: network.h:431
Holds optional information about relay.
Definition: network.h:59
OptionPtr getInterfaceId() const
Returns interface-id value (if specified)
Definition: network.h:456
const isc::dhcp::ClientClasses & getRequiredClasses() const
Returns classes which are required to be evaluated.
Definition: network.cc:97
void addRelayAddress(const asiolink::IOAddress &addr)
Adds an address to the list addresses in the network's relay info.
Definition: network.cc:54
Represents option data configuration for the DHCP server.
Definition: cfg_option.h:248
Triplet< uint32_t > valid_
a Triplet (min/default/max) holding allowed valid lifetime values
Definition: network.h:348
Abstract class for configuration Cfg_* classes.
bool getRapidCommit() const
Returns boolean value indicating that the Rapid Commit option is supported or unsupported for the sub...
Definition: network.h:471
void allowClientClass(const isc::dhcp::ClientClass &class_name)
Sets the supported class to class class_name.
Definition: network.cc:85
bool getMatchClientId() const
Returns the flag indicating if the client identifiers should be used to identify the client's lease.
Definition: network.h:378
Common interface representing a network to which the DHCP clients are connected.
Definition: network.h:49
virtual data::ElementPtr toElement() const
Unparses network object.
Definition: network.cc:102
Triplet< uint32_t > getT2() const
Returns T2 (rebind timer), expressed in seconds.
Definition: network.h:269
void setPreferred(const Triplet< uint32_t > &preferred)
Sets new preferred lifetime for a network.
Definition: network.h:449
None - host reservation is disabled.
Definition: network.h:95
bool hasRelays() const
Indicates if network's relay info has relay addresses.
Definition: network.cc:59
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
void setIface(const std::string &iface_name)
Sets local name of the interface for which this network is selected.
Definition: network.h:137
Triplet< uint32_t > getValid() const
Return valid-lifetime for addresses in that prefix.
Definition: network.h:245
std::string iface_name_
Holds interface name for which this network is selected.
Definition: network.h:321
HRMode
Specifies allowed host reservation mode.
Definition: network.h:91
bool getAuthoritative() const
Returns the flag indicating if requests for unknown IP addresses should be rejected with DHCPNAK inst...
Definition: network.h:396
Defines the logger used by the top-level component of kea-dhcp-ddns.
ClientClass client_class_
Optional definition of a client class.
Definition: network.h:333
virtual data::ElementPtr toElement() const
Unparses network object.
Definition: network.cc:220
void addAddress(const asiolink::IOAddress &addr)
Adds an address to the list of addresses.
Definition: network.cc:22
Triplet< uint32_t > getPreferred() const
Returns preferred lifetime (in seconds)
Definition: network.h:442
CfgOptionPtr cfg_option_
Pointer to the option data configuration for this subnet.
Definition: network.h:356
void requireClientClass(const isc::dhcp::ClientClass &class_name)
Adds class class_name to classes required to be evaluated.
Definition: network.cc:90
ConstCfgOptionPtr getCfgOption() const
Returns const pointer to the option data configuration for this subnet.
Definition: network.h:309
virtual asiolink::IOAddress getServerId() const
Returns binary representation of the dhcp-server-identifier option (54).
Definition: network.cc:205
const RelayInfo & getRelayInfo() const
Returns const reference to relay information.
Definition: network.h:178
Specialization of the Network object for DHCPv4 case.
Definition: network.h:366
void setHostReservationMode(HRMode mode)
Sets host reservation mode.
Definition: network.h:298
void setRelayInfo(const RelayInfo &relay)
Sets information about relay.
Definition: network.h:168
void setRapidCommit(const bool rapid_commit)
Enables or disables Rapid Commit option support for the subnet.
Definition: network.h:479
std::string ClientClass
Defines a single class name.
Definition: classify.h:37
RelayInfo relay_
Relay information.
Definition: network.h:326
Container for storing client class names.
Definition: classify.h:43
void setT1(const Triplet< uint32_t > &t1)
Sets new renew timer for a network.
Definition: network.h:264
virtual data::ElementPtr toElement() const
Unparses network object.
Definition: network.cc:192
std::string getIface() const
Returns name of the local interface for which this network is selected.
Definition: network.h:145
void setT2(const Triplet< uint32_t > &t2)
Sets new rebind timer for a network.
Definition: network.h:276
const IOAddressList & getRelayAddresses() const
Returns the list of relay addresses from the network's relay info.
Definition: network.cc:69
Network()
Constructor.
Definition: network.h:119
Triplet< uint32_t > t1_
a Triplet (min/default/max) holding allowed renew timer values
Definition: network.h:342