Kea  2.3.5-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 
61  ClientClassDef(const ClientClassDef& rhs);
62 
64  virtual ~ClientClassDef();
65 
67  std::string getName() const;
68 
72  void setName(const std::string& name);
73 
75  const ExpressionPtr& getMatchExpr() const;
76 
80  void setMatchExpr(const ExpressionPtr& match_expr);
81 
83  std::string getTest() const;
84 
88  void setTest(const std::string& test);
89 
91  bool getRequired() const;
92 
96  void setRequired(bool required);
97 
99  bool getDependOnKnown() const;
100 
104  void setDependOnKnown(bool depend_on_known);
105 
107  const CfgOptionDefPtr& getCfgOptionDef() const;
108 
112  void setCfgOptionDef(const CfgOptionDefPtr& cfg_option_def);
113 
115  const CfgOptionPtr& getCfgOption() const;
116 
120  void setCfgOption(const CfgOptionPtr& cfg_option);
121 
127  bool dependOnClass(const std::string& name) const;
128 
134  bool equals(const ClientClassDef& other) const;
135 
141  bool operator==(const ClientClassDef& other) const {
142  return (equals(other));
143  }
144 
150  bool operator!=(const ClientClassDef& other) const {
151  return (!(equals(other)));
152  }
153 
155  friend std::ostream& operator<<(std::ostream& os, const ClientClassDef& x);
156 
160  return (next_server_);
161  }
162 
166  void setNextServer(const asiolink::IOAddress& addr) {
167  next_server_ = addr;
168  }
169 
173  void setSname(const std::string& sname) {
174  sname_ = sname;
175  }
176 
179  const std::string& getSname() const {
180  return (sname_);
181  }
182 
186  void setFilename(const std::string& filename) {
187  filename_ = filename;
188  }
189 
192  const std::string& getFilename() const {
193  return (filename_);
194  }
195 
200  return (valid_);
201  }
202 
206  void setValid(const util::Triplet<uint32_t>& valid) {
207  valid_ = valid;
208  }
209 
214  return (preferred_);
215  }
216 
220  void setPreferred(const util::Triplet<uint32_t>& preferred) {
221  preferred_ = preferred;
222  }
223 
229  virtual void test(PktPtr pkt, const ExpressionPtr& expr_ptr);
230 
234  virtual isc::data::ElementPtr toElement() const;
235 
236 private:
238  std::string name_;
239 
242  ExpressionPtr match_expr_;
243 
246  std::string test_;
247 
252  bool required_;
253 
262  bool depend_on_known_;
263 
265  CfgOptionDefPtr cfg_option_def_;
266 
268  CfgOptionPtr cfg_option_;
269 
273  asiolink::IOAddress next_server_;
274 
279  std::string sname_;
280 
285  std::string filename_;
286 
289 
291  util::Triplet<uint32_t> preferred_;
292 };
293 
295 public:
301  TemplateClientClassDef(const std::string& name, const ExpressionPtr& match_expr,
302  const CfgOptionPtr& options = CfgOptionPtr());
303 
309  virtual void test(PktPtr pkt, const ExpressionPtr& expr_ptr) override;
310 
314  virtual isc::data::ElementPtr toElement() const override;
315 
323  static const std::string SPAWN_CLASS_PREFIX;
324 };
325 
327 typedef boost::shared_ptr<ClientClassDef> ClientClassDefPtr;
328 
330 typedef std::unordered_map<std::string, ClientClassDefPtr> ClientClassDefMap;
331 
333 typedef boost::shared_ptr<ClientClassDefMap> ClientClassDefMapPtr;
334 
336 typedef std::vector<ClientClassDefPtr> ClientClassDefList;
337 
339 typedef boost::shared_ptr<ClientClassDefList> ClientClassDefListPtr;
340 
343 
344 public:
347 
349 
352 
372  void addClass(const std::string& name, const ExpressionPtr& match_expr,
373  const std::string& test, bool required, bool depend_on_known,
374  const CfgOptionPtr& options,
377  asiolink::IOAddress next_server = asiolink::IOAddress("0.0.0.0"),
378  const std::string& sname = std::string(),
379  const std::string& filename = std::string(),
382  bool is_template = false);
383 
390  void addClass(ClientClassDefPtr& class_def);
391 
398  ClientClassDefPtr findClass(const std::string& name) const;
399 
406  void removeClass(const std::string& name);
407 
411  void removeClass(const uint64_t id);
412 
416  const ClientClassDefListPtr& getClasses() const;
417 
421  bool empty() const;
422 
430  bool dependOnClass(const std::string& name, std::string& dependent_class) const;
431 
437  bool equals(const ClientClassDictionary& other) const;
438 
443  void initMatchExpr(uint16_t family);
444 
449  void createOptions(const CfgOptionDefPtr& cfg_option_def);
450 
456  bool operator==(const ClientClassDictionary& other) const {
457  return (equals(other));
458  }
459 
465  bool operator!=(const ClientClassDictionary& other) const {
466  return (!equals(other));
467  }
468 
473  ClientClassDictionary& operator=(const ClientClassDictionary& rhs);
474 
478  virtual isc::data::ElementPtr toElement() const;
479 
480 private:
481 
483  ClientClassDefMapPtr map_;
484 
486  ClientClassDefListPtr list_;
487 };
488 
490 typedef boost::shared_ptr<ClientClassDictionary> ClientClassDictionaryPtr;
491 
494 extern std::list<std::string> builtinNames;
495 
498 extern std::list<std::string> builtinPrefixes;
499 
504 bool isClientClassBuiltIn(const ClientClass& client_class);
505 
517 bool isClientClassDefined(ClientClassDictionaryPtr& class_dictionary,
518  bool& depend_on_known,
519  const ClientClass& client_class);
520 
521 } // namespace isc::dhcp
522 } // namespace isc
523 
524 #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:745
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
The prefixes used to check if a class is BuiltIn class.
boost::shared_ptr< isc::dhcp::Pkt > PktPtr
A pointer to either Pkt4 or Pkt6 packet.
Definition: pkt.h:853
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.
static const std::string SPAWN_CLASS_PREFIX
This is a prefix added to the spawned class name.
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:42
boost::shared_ptr< Expression > ExpressionPtr
Definition: token.h:30
const std::string & getSname() const
returns server-hostname value