Kea  2.1.7-git
client_class_def.h
Go to the documentation of this file.
1 // Copyright (C) 2015-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 CLIENT_CLASS_DEF_H
8 #define CLIENT_CLASS_DEF_H
9 
10 #include <cc/cfg_to_element.h>
11 #include <cc/stamped_element.h>
12 #include <cc/user_context.h>
13 #include <dhcpsrv/cfg_option.h>
14 #include <dhcpsrv/cfg_option_def.h>
15 #include <util/triplet.h>
16 #include <eval/token.h>
17 #include <exceptions/exceptions.h>
18 
19 #include <string>
20 #include <unordered_map>
21 #include <list>
22 #include <vector>
23 
36 namespace isc {
37 namespace dhcp {
38 
42 public:
43  DuplicateClientClassDef(const char* file, size_t line, const char* what)
44  : isc::Exception(file, line, what) {}
45 };
46 
49  public data::CfgToElement,
50  public data::StampedElement {
51 public:
57  ClientClassDef(const std::string& name, const ExpressionPtr& match_expr,
58  const CfgOptionPtr& options = CfgOptionPtr());
59 
60 
62  ClientClassDef(const ClientClassDef& rhs);
63 
65  virtual ~ClientClassDef();
66 
68  std::string getName() const;
69 
73  void setName(const std::string& name);
74 
76  const ExpressionPtr& getMatchExpr() const;
77 
81  void setMatchExpr(const ExpressionPtr& match_expr);
82 
84  std::string getTest() const;
85 
89  void setTest(const std::string& test);
90 
92  bool getRequired() const;
93 
97  void setRequired(bool required);
98 
100  bool getDependOnKnown() const;
101 
105  void setDependOnKnown(bool depend_on_known);
106 
108  const CfgOptionDefPtr& getCfgOptionDef() const;
109 
113  void setCfgOptionDef(const CfgOptionDefPtr& cfg_option_def);
114 
116  const CfgOptionPtr& getCfgOption() const;
117 
121  void setCfgOption(const CfgOptionPtr& cfg_option);
122 
128  bool dependOnClass(const std::string& name) const;
129 
135  bool equals(const ClientClassDef& other) const;
136 
142  bool operator==(const ClientClassDef& other) const {
143  return (equals(other));
144  }
145 
151  bool operator!=(const ClientClassDef& other) const {
152  return (!(equals(other)));
153  }
154 
156  friend std::ostream& operator<<(std::ostream& os, const ClientClassDef& x);
157 
161  return (next_server_);
162  }
163 
167  void setNextServer(const asiolink::IOAddress& addr) {
168  next_server_ = addr;
169  }
170 
174  void setSname(const std::string& sname) {
175  sname_ = sname;
176  }
177 
180  const std::string& getSname() const {
181  return (sname_);
182  }
183 
187  void setFilename(const std::string& filename) {
188  filename_ = filename;
189  }
190 
193  const std::string& getFilename() const {
194  return (filename_);
195  }
196 
201  return (valid_);
202  }
203 
207  void setValid(const util::Triplet<uint32_t>& valid) {
208  valid_ = valid;
209  }
210 
215  return (preferred_);
216  }
217 
221  void setPreferred(const util::Triplet<uint32_t>& preferred) {
222  preferred_ = preferred;
223  }
224 
228  virtual isc::data::ElementPtr toElement() const;
229 
230 private:
232  std::string name_;
233 
236  ExpressionPtr match_expr_;
237 
240  std::string test_;
241 
246  bool required_;
247 
256  bool depend_on_known_;
257 
259  CfgOptionDefPtr cfg_option_def_;
260 
262  CfgOptionPtr cfg_option_;
263 
267  asiolink::IOAddress next_server_;
268 
273  std::string sname_;
274 
279  std::string filename_;
280 
283 
285  util::Triplet<uint32_t> preferred_;
286 };
287 
289 typedef boost::shared_ptr<ClientClassDef> ClientClassDefPtr;
290 
292 typedef std::unordered_map<std::string, ClientClassDefPtr> ClientClassDefMap;
293 
295 typedef boost::shared_ptr<ClientClassDefMap> ClientClassDefMapPtr;
296 
298 typedef std::vector<ClientClassDefPtr> ClientClassDefList;
299 
301 typedef boost::shared_ptr<ClientClassDefList> ClientClassDefListPtr;
302 
305 
306 public:
309 
311 
314 
334  void addClass(const std::string& name, const ExpressionPtr& match_expr,
335  const std::string& test, bool required, bool depend_on_known,
336  const CfgOptionPtr& options,
339  asiolink::IOAddress next_server = asiolink::IOAddress("0.0.0.0"),
340  const std::string& sname = std::string(),
341  const std::string& filename = std::string(),
344 
351  void addClass(ClientClassDefPtr& class_def);
352 
359  ClientClassDefPtr findClass(const std::string& name) const;
360 
367  void removeClass(const std::string& name);
368 
372  void removeClass(const uint64_t id);
373 
377  const ClientClassDefListPtr& getClasses() const;
378 
382  bool empty() const;
383 
391  bool dependOnClass(const std::string& name, std::string& dependent_class) const;
392 
398  bool equals(const ClientClassDictionary& other) const;
399 
404  void initMatchExpr(uint16_t family);
405 
410  void createOptions(const CfgOptionDefPtr& cfg_option_def);
411 
417  bool operator==(const ClientClassDictionary& other) const {
418  return (equals(other));
419  }
420 
426  bool operator!=(const ClientClassDictionary& other) const {
427  return (!equals(other));
428  }
429 
434  ClientClassDictionary& operator=(const ClientClassDictionary& rhs);
435 
439  virtual isc::data::ElementPtr toElement() const;
440 
441 private:
442 
444  ClientClassDefMapPtr map_;
445 
447  ClientClassDefListPtr list_;
448 };
449 
451 typedef boost::shared_ptr<ClientClassDictionary> ClientClassDictionaryPtr;
452 
455 extern std::list<std::string> builtinNames;
456 
459 extern std::list<std::string> builtinPrefixes;
460 
465 bool isClientClassBuiltIn(const ClientClass& client_class);
466 
467 
479 bool isClientClassDefined(ClientClassDictionaryPtr& class_dictionary,
480  bool& depend_on_known,
481  const ClientClass& client_class);
482 
483 } // namespace isc::dhcp
484 } // namespace isc
485 
486 #endif // CLIENT_CLASS_DEF_H
This class represents configuration element which is associated with database identifier, modification timestamp and servers.
boost::shared_ptr< CfgOption > CfgOptionPtr
Non-const pointer.
Definition: cfg_option.h:706
bool operator==(const ClientClassDictionary &other) const
Equality operator.
Base class for user context.
Definition: user_context.h:22
std::unordered_map< std::string, ClientClassDefPtr > ClientClassDefMap
Defines a map of ClientClassDef&#39;s, keyed by the class name.
void setFilename(const std::string &filename)
sets the boot-file-name value
boost::shared_ptr< Element > ElementPtr
Definition: data.h:24
const asiolink::IOAddress & getNextServer() const
returns next-server value
void setValid(const util::Triplet< uint32_t > &valid)
Sets new valid lifetime.
boost::shared_ptr< CfgOptionDef > CfgOptionDefPtr
Non-const pointer.
boost::shared_ptr< ClientClassDefMap > ClientClassDefMapPtr
Defines a pointer to a ClientClassDefMap.
Maintains a list of ClientClassDef&#39;s.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
bool isClientClassDefined(ClientClassDictionaryPtr &class_dictionary, bool &depend_on_known, const ClientClass &client_class)
Check if a client class name is already defined, i.e.
bool operator==(const ClientClassDef &other) const
Equality operator.
void setPreferred(const util::Triplet< uint32_t > &preferred)
Sets new preferred lifetime.
DuplicateClientClassDef(const char *file, size_t line, const char *what)
Error that occurs when an attempt is made to add a duplicate class to a class dictionary.
const std::string & getFilename() const
returns boot-file-name value
Abstract class for configuration Cfg_* classes.
boost::shared_ptr< ClientClassDictionary > ClientClassDictionaryPtr
Defines a pointer to a ClientClassDictionary.
Embodies a single client class definition.
util::Triplet< uint32_t > getValid() const
Return valid-lifetime value.
boost::shared_ptr< const Element > ConstElementPtr
Definition: data.h:27
bool dependOnClass(const TokenPtr &token, const std::string &name)
Checks dependency on a token.
Definition: dependency.cc:15
util::Triplet< uint32_t > getPreferred() const
Return preferred-lifetime value.
std::list< std::string > builtinNames
List of classes for which test expressions cannot be defined.
std::list< std::string > builtinPrefixes
List of built-in client class prefixes i.e.
boost::shared_ptr< ClientClassDef > ClientClassDefPtr
a pointer to an ClientClassDef
std::vector< ClientClassDefPtr > ClientClassDefList
Defines a list of ClientClassDefPtr&#39;s, using insert order.
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.
boost::shared_ptr< ClientClassDefList > ClientClassDefListPtr
Defines a pointer to a ClientClassDefList.
void setSname(const std::string &sname)
sets the server-name value
const Name & name_
Definition: dns/message.cc:693
std::ostream & operator<<(std::ostream &os, const OpaqueDataTuple &tuple)
Inserts the OpaqueDataTuple as a string into stream.
bool operator!=(const ClientClassDictionary &other) const
Inequality operator.
bool operator!=(const ClientClassDef &other) const
Inequality operator.
void setNextServer(const asiolink::IOAddress &addr)
sets the next-server value
bool isClientClassBuiltIn(const ClientClass &client_class)
Check if a client class name is builtin.
std::string ClientClass
Defines a single class name.
Definition: classify.h:40
boost::shared_ptr< Expression > ExpressionPtr
Definition: token.h:30
const std::string & getSname() const
returns server-hostname value