30      match_expr_(match_expr), additional_(false), depend_on_known_(false),
 
   32      valid_(), preferred_() {
 
   36        isc_throw(BadValue, 
"Client Class name cannot be blank");
 
 
   49      match_expr_(
ExpressionPtr()), test_(rhs.test_), additional_(rhs.additional_),
 
   50      depend_on_known_(rhs.depend_on_known_), cfg_option_(new 
CfgOption()),
 
   51      next_server_(rhs.next_server_), sname_(rhs.sname_),
 
   52      filename_(rhs.filename_), valid_(rhs.valid_), preferred_(rhs.preferred_),
 
   53      offer_lft_(rhs.offer_lft_) {
 
   55    if (rhs.match_expr_) {
 
   56        match_expr_.reset(new Expression());
 
   57        *match_expr_ = *rhs.match_expr_;
 
   60    if (rhs.cfg_option_def_) {
 
   61        cfg_option_def_.reset(new CfgOptionDef());
 
   62        rhs.cfg_option_def_->copyTo(*cfg_option_def_);
 
   65    if (rhs.cfg_option_) {
 
   66        rhs.cfg_option_->copyTo(*cfg_option_);
 
 
   90    match_expr_ = match_expr;
 
 
  105    return (additional_);
 
 
  110    additional_ = additional;
 
 
  115    return (depend_on_known_);
 
 
  120    depend_on_known_ = depend_on_known;
 
 
  125    return (cfg_option_def_);
 
 
  130    cfg_option_def_ = cfg_option_def;
 
 
  135    return (cfg_option_);
 
 
  140    cfg_option_ = cfg_option;
 
 
  150            .arg(pkt->getLabel())
 
  152            .arg(status ? 
"true" : 
"false");
 
  159            .arg(pkt->getLabel())
 
 
  179        if (!subclass.empty()) {
 
  181                .arg(pkt->getLabel())
 
  189            pkt->addSubClass(
getName(), value);
 
  193            .arg(pkt->getLabel())
 
 
  206    return ((name_ == other.name_) &&
 
  207        ((!match_expr_ && !other.match_expr_) ||
 
  208        (match_expr_ && other.match_expr_ &&
 
  209         (*match_expr_ == *other.match_expr_))) &&
 
  210        ((!cfg_option_ && !other.cfg_option_) ||
 
  211        (cfg_option_ && other.cfg_option_ &&
 
  212         (*cfg_option_ == *other.cfg_option_))) &&
 
  213        ((!cfg_option_def_ && !other.cfg_option_def_) ||
 
  214        (cfg_option_def_ && other.cfg_option_def_ &&
 
  215         (*cfg_option_def_ == *other.cfg_option_def_))) &&
 
  216            (additional_ == other.additional_) &&
 
  217            (depend_on_known_ == other.depend_on_known_) &&
 
  218            (next_server_ == other.next_server_) &&
 
  219            (sname_ == other.sname_) &&
 
  220            (filename_ == other.filename_));
 
 
  232    if (!test_.empty()) {
 
  240    if (cfg_option_def_ && (family == AF_INET)) {
 
  241        result->set(
"option-def", cfg_option_def_->toElement());
 
  242        result->set(
"option-data", cfg_option_->toElement(cfg_option_def_));
 
  245        result->set(
"option-data", cfg_option_->toElement());
 
  248    if (family == AF_INET) {
 
  258        if (!offer_lft_.unspecified()) {
 
  259            result->set(
"offer-lifetime",
 
  265        if (!preferred_.unspecified()) {
 
  266            result->set(
"preferred-lifetime",
 
  270        if (preferred_.getMin() < preferred_.get()) {
 
  271            result->set(
"min-preferred-lifetime",
 
  275        if (preferred_.getMax() > preferred_.get()) {
 
  276            result->set(
"max-preferred-lifetime",
 
  282    if (!valid_.unspecified()) {
 
  283        result->set(
"valid-lifetime",
 
  286        if (valid_.getMin() < valid_.get()) {
 
  287            result->set(
"min-valid-lifetime",
 
  291        if (valid_.getMax() > valid_.get()) {
 
  292            result->set(
"max-valid-lifetime",
 
 
  303    auto const& 
test = result->get(
"test");
 
  305        result->set(
"template-test", 
test);
 
  306        result->remove(
"test");
 
 
  314    os << 
"ClientClassDef:" << x.
getName();
 
 
  326    for (
auto const& cclass : *rhs.list_) {
 
  327        ClientClassDefPtr copy(new ClientClassDef(*cclass));
 
 
  338                                const std::string& 
test,
 
  340                                bool depend_on_known,
 
  345                                const std::string& sname,
 
  346                                const std::string& filename,
 
  357    cclass->setTest(
test);
 
  358    cclass->setAdditional(additional);
 
  359    cclass->setDependOnKnown(depend_on_known);
 
  360    cclass->setCfgOptionDef(cfg_option_def);
 
  361    cclass->setContext(user_context),
 
  362    cclass->setNextServer(next_server);
 
  363    cclass->setSname(sname);
 
  364    cclass->setFilename(filename);
 
  365    cclass->setValid(valid);
 
  366    cclass->setPreferred(preferred);
 
  367    cclass->setOfferLft(offer_lft);
 
 
  375                            " - class definition cannot be null");
 
  380                  << class_def->getName() << 
" has already been defined");
 
  383    list_->push_back(class_def);
 
  384    (*map_)[class_def->getName()] = class_def;
 
 
  389    ClientClassDefMap::iterator it = map_->find(name);
 
  390    if (it != map_->end()) {
 
 
  399    for (ClientClassDefList::iterator this_class = list_->begin();
 
  400         this_class != list_->end(); ++this_class) {
 
  401        if ((*this_class)->getName() == name) {
 
  402            list_->erase(this_class);
 
 
  415    for (ClientClassDefList::iterator this_class = list_->begin();
 
  416         this_class != list_->end(); ++this_class) {
 
  417        if ((*this_class)->getId() == 
id) {
 
  418            map_->erase((*this_class)->getName());
 
  419            list_->erase(this_class);
 
 
  432    return (list_->empty());
 
 
  437                                     std::string& dependent_class)
 const {
 
  440    for (
auto const& this_class : *list_) {
 
  442            if (this_class->dependOnClass(name)) {
 
  443                dependent_class = this_class->getName();
 
  447            if (this_class->getName() == name) {
 
 
  457    if (list_->size() != other.list_->size()) {
 
  461    ClientClassDefList::const_iterator this_class = list_->cbegin();
 
  462    ClientClassDefList::const_iterator other_class = other.list_->cbegin();
 
  463    while (this_class != list_->cend() &&
 
  464           other_class != other.list_->cend()) {
 
  465        if (!*this_class || !*other_class ||
 
  466            **this_class != **other_class) {
 
 
  479    std::queue<ExpressionPtr> expressions;
 
  480    for (
auto const& c : *list_) {
 
  481        if (!c->getTest().empty()) {
 
  490            expressions.push(match_expr);
 
  495    for (
auto const& c : *list_) {
 
  496        if (!c->getTest().empty()) {
 
  497            c->setMatchExpr(expressions.front());
 
 
  505    for (
auto const& c : *list_) {
 
  508        if (!class_options || class_options->empty()) {
 
  515        if (!c->getCfgOptionDef()) {
 
  516            class_options->createOptions(external_defs);
 
  526            c->getCfgOptionDef()->copyTo(*composite_defs);
 
  533            external_defs->copyTo(*external_defs_copy);
 
  534            composite_defs->merge(*external_defs_copy);
 
  538            class_options->createOptions(composite_defs);
 
 
  545    for (
auto const& c : *list_) {
 
  548            class_options->encapsulate();
 
 
  557    for (
auto const& this_class : *list_) {
 
  558        result->add(this_class->toElement());
 
 
  568        for (
auto const& cclass : *rhs.list_) {
 
 
  577std::list<std::string>
 
  585    "ALL", 
"KNOWN", 
"UNKNOWN", 
"BOOTP" 
 
  594std::list<std::string>
 
  596    "VENDOR_CLASS_", 
"HA_", 
"AFTER_", 
"EXTERNAL_" 
 
  602        if (client_class == bn) {
 
  608        if (client_class.size() <= bt.size()) {
 
  611        auto mis = std::mismatch(bt.cbegin(), bt.cend(), client_class.cbegin());
 
  612        if (mis.first == bt.cend()) {
 
 
  622                     bool& depend_on_known,
 
  627        if ((client_class == 
"KNOWN") || (client_class == 
"UNKNOWN")) {
 
  628            depend_on_known = 
true;
 
  637        if (def->getDependOnKnown()) {
 
  638            depend_on_known = 
true;
 
 
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
This is a base class for exceptions thrown from the DNS library module.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
The IOAddress class represents an IP addresses (version agnostic)
static ElementPtr create(const Position &pos=ZERO_POSITION())
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
static ElementPtr createList(const Position &pos=ZERO_POSITION())
Creates an empty ListElement type ElementPtr.
StampedElement()
Constructor.
uint16_t getFamily() const
Returns address family.
static CfgMgr & instance()
returns a single instance of Configuration Manager
Represents option definitions used by the DHCP server.
Represents option data configuration for the DHCP server.
Embodies a single client class definition.
void setAdditional(bool additional)
Sets the only if additional flag.
bool equals(const ClientClassDef &other) const
Compares two ClientClassDef objects for equality.
void setCfgOption(const CfgOptionPtr &cfg_option)
Sets the class's option collection.
void setName(const std::string &name)
Sets the class's name.
bool dependOnClass(const std::string &name) const
Checks direct dependency.
bool getDependOnKnown() const
Fetches the depend on known flag aka use host flag.
virtual void test(PktPtr pkt, const ExpressionPtr &expr_ptr)
Test method which checks if the packet belongs to the class.
const CfgOptionDefPtr & getCfgOptionDef() const
Fetches the class's option definitions.
ClientClassDef(const std::string &name, const ExpressionPtr &match_expr, const CfgOptionPtr &options=CfgOptionPtr())
Constructor.
const ExpressionPtr & getMatchExpr() const
Fetches the class's match expression.
void setCfgOptionDef(const CfgOptionDefPtr &cfg_option_def)
Sets the class's option definition collection.
virtual ~ClientClassDef()
Destructor.
std::string getName() const
Fetches the class's name.
const CfgOptionPtr & getCfgOption() const
Fetches the class's option collection.
void setMatchExpr(const ExpressionPtr &match_expr)
Sets the class's match expression.
void setTest(const std::string &test)
Sets the class's original match expression.
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
std::string getTest() const
Fetches the class's original match expression.
bool getAdditional() const
Fetches the only if additional flag.
void setDependOnKnown(bool depend_on_known)
Sets the depend on known flag aka use host flag.
Maintains a list of ClientClassDef's.
void addClass(const std::string &name, const ExpressionPtr &match_expr, const std::string &test, bool additional, bool depend_on_known, const CfgOptionPtr &options, CfgOptionDefPtr defs=CfgOptionDefPtr(), isc::data::ConstElementPtr user_context=isc::data::ConstElementPtr(), asiolink::IOAddress next_server=asiolink::IOAddress("0.0.0.0"), const std::string &sname=std::string(), const std::string &filename=std::string(), const util::Triplet< uint32_t > &valid=util::Triplet< uint32_t >(), const util::Triplet< uint32_t > &preferred=util::Triplet< uint32_t >(), bool is_template=false, const util::Optional< uint32_t > &offer_lft=util::Optional< uint32_t >())
Adds a new class to the list.
ClientClassDefPtr findClass(const std::string &name) const
Fetches the class definition for a given class name.
bool equals(const ClientClassDictionary &other) const
Compares two ClientClassDictionary objects for equality.
void removeClass(const std::string &name)
Removes a given class definition from the dictionary.
bool empty() const
Checks if the class dictionary is empty.
bool dependOnClass(const std::string &name, std::string &dependent_class) const
Checks direct dependency.
ClientClassDictionary()
Constructor.
const ClientClassDefListPtr & getClasses() const
Fetches the dictionary's list of classes.
ClientClassDictionary & operator=(const ClientClassDictionary &rhs)
Copy assignment operator.
~ClientClassDictionary()
Destructor.
void encapsulateOptions() const
Iterates over the classes in the dictionary and encapsulates suboptions.
void createOptions(const CfgOptionDefPtr &cfg_option_def)
Iterates over the classes in the dictionary and recreates the options.
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
void initMatchExpr(uint16_t family)
Iterates over the classes in the dictionary and ensures that that match expressions are initialized.
Error that occurs when an attempt is made to add a duplicate class to a class dictionary.
Parser for a logical expression.
void parse(ExpressionPtr &expression, isc::data::ConstElementPtr expression_cfg, uint16_t family, isc::eval::EvalContext::CheckDefined check_defined=isc::eval::EvalContext::acceptAll, isc::eval::EvalContext::ParserType parser_type=isc::eval::EvalContext::PARSER_BOOL)
Parses an expression configuration element into an Expression.
static const std::string SPAWN_CLASS_PREFIX
This is a prefix added to the spawned class name.
TemplateClientClassDef(const std::string &name, const ExpressionPtr &match_expr, const CfgOptionPtr &options=CfgOptionPtr())
Constructor.
virtual void test(PktPtr pkt, const ExpressionPtr &expr_ptr) override
Test method which checks if the packet belongs to the class.
virtual isc::data::ElementPtr toElement() const override
Unparse a configuration object.
ParserType
Specifies what type of expression the parser is expected to see.
@ PARSER_BOOL
expression is expected to evaluate to bool
@ PARSER_STRING
expression is expected to evaluate to string
static bool acceptAll(const ClientClass &client_class)
Accept all client class names.
A template representing an optional value.
This template specifies a parameter value.
Defines classes for storing client class definitions.
Parsers for client class definitions.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
#define LOG_ERROR(LOGGER, MESSAGE)
Macro to conveniently test error output and log it.
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
A wrapper interface for the ASIO library.
std::ostream & operator<<(std::ostream &os, const IOAddress &address)
Insert the IOAddress as a string into stream.
ElementPtr copy(ConstElementPtr from, int level)
Copy the data up to a nesting level.
boost::shared_ptr< const Element > ConstElementPtr
boost::shared_ptr< Element > ElementPtr
isc::log::Logger dhcpsrv_logger("dhcpsrv")
DHCP server library Logger.
boost::shared_ptr< isc::dhcp::Pkt > PktPtr
A pointer to either Pkt4 or Pkt6 packet.
std::string ClientClass
Defines a single class name.
std::vector< ClientClassDefPtr > ClientClassDefList
Defines a list of ClientClassDefPtr's, using insert order.
boost::shared_ptr< CfgOption > CfgOptionPtr
Non-const pointer.
const isc::log::MessageID DHCPSRV_EVAL_ERROR
boost::shared_ptr< CfgOptionDef > CfgOptionDefPtr
Non-const pointer.
const isc::log::MessageID DHCPSRV_TEMPLATE_EVAL_RESULT
boost::shared_ptr< ClientClassDef > ClientClassDefPtr
a pointer to an ClientClassDef
std::string evaluateString(const Expression &expr, Pkt &pkt)
Evaluate a RPN expression for a v4 or v6 packet and return a string value.
std::list< std::string > builtinPrefixes
The prefixes used to check if a class is BuiltIn class.
const int DHCPSRV_DBG_TRACE_DETAIL
Additional information.
const isc::log::MessageID DHCPSRV_TEMPLATE_EVAL_ERROR
boost::shared_ptr< Expression > ExpressionPtr
boost::shared_ptr< ClientClassDictionary > ClientClassDictionaryPtr
Defines a pointer to a ClientClassDictionary.
boost::shared_ptr< ClientClassDefList > ClientClassDefListPtr
Defines a pointer to a ClientClassDefList.
bool evaluateBool(const Expression &expr, Pkt &pkt)
Evaluate a RPN expression for a v4 or v6 packet and return a true or false decision.
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 isClientClassBuiltIn(const ClientClass &client_class)
Check if a client class name is builtin.
bool dependOnClass(const TokenPtr &token, const std::string &name)
Checks dependency on a token.
std::list< std::string > builtinNames
List of classes for which test expressions cannot be defined.
std::unordered_map< std::string, ClientClassDefPtr > ClientClassDefMap
Defines a map of ClientClassDef's, keyed by the class name.
const isc::log::MessageID DHCPSRV_EVAL_RESULT
Defines the logger used by the top-level component of kea-lfc.
Abstract class for configuration Cfg_* classes.
Base class for user context.
void contextToElement(data::ElementPtr map) const
Merge unparse a user_context object.