105 static inline bool toBool(std::string value) {
106 if (value ==
"true") {
108 }
else if (value ==
"false") {
112 "\"false\" or \"true\", got \"" << value <<
"\"");
1166 uint16_t option_code = 0);
1268 uint16_t index = 0);
1338 const uint16_t sub_option_code,
1406 return (reg_exp_str_);
1411 std::string reg_exp_str_;
1414 std::regex reg_exp_;
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.
EvalBadLabel is thrown when a label can't be found.
EvalBadLabel(const char *file, size_t line, const char *what)
EvalBadStack is thrown when more or less parameters are on the stack than expected.
EvalBadStack(const char *file, size_t line, const char *what)
EvalTypeError is thrown when a value on the stack has a content with an unexpected type.
EvalTypeError(const char *file, size_t line, const char *what)
Universe
defines option universe DHCPv4 or DHCPv6
Base class for classes representing DHCP messages.
Token that represents logical and operator.
virtual unsigned evaluate(Pkt &pkt, ValueStack &values)
Logical and.
TokenAnd()
Constructor (does nothing)
Token that represents unconditional branch.
virtual unsigned evaluate(Pkt &pkt, ValueStack &values)
Only return the target.
TokenBranch(const unsigned target)
Constructor.
unsigned getTarget() const
Returns branchtarget.
Token that represents concat operator (concatenates two other tokens)
TokenConcat()
Constructor (does nothing)
virtual unsigned evaluate(Pkt &pkt, ValueStack &values)
Concatenate two values.
Token that represents equality operator (compares two other tokens)
virtual unsigned evaluate(Pkt &pkt, ValueStack &values)
Compare two values.
TokenEqual()
Constructor (does nothing)
Token representing a constant string in hexadecimal format.
std::string value_
Constant value.
virtual unsigned evaluate(Pkt &pkt, ValueStack &values)
Token evaluation (puts value of the constant string on the stack after decoding or an empty string if...
TokenHexString(const std::string &str)
Value is set during token construction.
Token that represents an alternative.
TokenIfElse()
Constructor (does nothing)
virtual unsigned evaluate(Pkt &pkt, ValueStack &values)
Alternative.
Token representing a 16 bit integer as a string.
virtual unsigned evaluate(Pkt &pkt, ValueStack &values)
Token evaluation (puts value of the string on the stack after decoding)
TokenInt16ToText()
Constructor (does nothing)
Token representing a 32 bit integer as a string.
TokenInt32ToText()
Constructor (does nothing)
virtual unsigned evaluate(Pkt &pkt, ValueStack &values)
Token evaluation (puts value of the string on the stack after decoding)
Token representing an 8 bit integer as a string.
virtual unsigned evaluate(Pkt &pkt, ValueStack &values)
Token evaluation (puts value of the string on the stack after decoding)
TokenInt8ToText()
Constructor (does nothing)
Token representing an unsigned 32 bit integer.
TokenInteger(const uint32_t value)
Integer value set during construction.
uint32_t getInteger() const
Returns integer value.
uint32_t int_value_
value as integer (stored for testing only)
Token representing an IP address as a string.
virtual unsigned evaluate(Pkt &pkt, ValueStack &values)
Token evaluation (puts value of the string on the stack after decoding)
TokenIpAddressToText()
Constructor (does nothing)
Token representing an IP address as a constant string.
std::string value_
< Constant value (empty string if the IP address cannot be converted)
TokenIpAddress(const std::string &addr)
Value is set during token construction.
virtual unsigned evaluate(Pkt &pkt, ValueStack &values)
Token evaluation (puts value of the constant string on the stack after decoding)
virtual unsigned evaluate(Pkt &pkt, ValueStack &values)
Does nothing.
virtual unsigned getLabel() const
Returns label.
TokenLabel(const unsigned label)
Constructor.
Token representing a constant lower case string.
TokenLowerCase()
Constructor (does nothing)
virtual unsigned evaluate(Pkt &pkt, ValueStack &values)
Token evaluation (puts value of the evaluated string expression converted to lower case on the stack)
Token that represents regular expression (regex) matching.
virtual unsigned evaluate(Pkt &pkt, ValueStack &values)
Match regular expression.
const std::string & getRegExp() const
Returns regular expression.
TokenMatch(const std::string ®_exp)
Constructor.
Token that represents client class membership.
const ClientClass & getClientClass() const
Returns client class name.
ClientClass client_class_
The client class name.
virtual unsigned evaluate(Pkt &pkt, ValueStack &values)
Token evaluation (check if client_class_ was added to packet client classes)
TokenMember(const std::string &client_class)
Constructor.
Token that represents logical negation operator.
TokenNot()
Constructor (does nothing)
virtual unsigned evaluate(Pkt &pkt, ValueStack &values)
Logical negation.
Token that represents a value of an option.
uint16_t getCode() const
Returns option-code.
RepresentationType getRepresentation() const
Returns representation-type.
virtual OptionPtr getOption(Pkt &pkt)
Attempts to retrieve an option.
RepresentationType representation_type_
Representation type.
uint16_t option_code_
Code of the option to be extracted.
RepresentationType
Token representation type.
TokenOption(const uint16_t option_code, const RepresentationType &rep_type)
Constructor that takes an option code as a parameter.
virtual unsigned evaluate(Pkt &pkt, ValueStack &values)
Evaluates the values of the option.
virtual std::string pushFailure(ValueStack &values)
Auxiliary method that puts string representing a failure.
Token that represents logical or operator.
virtual unsigned evaluate(Pkt &pkt, ValueStack &values)
Logical or.
TokenOr()
Constructor (does nothing)
Token that represents fields of a DHCPv4 packet.
FieldType getType()
Returns field type.
virtual unsigned evaluate(Pkt &pkt, ValueStack &values)
Gets a value from the specified packet.
FieldType
enum value that determines the field.
@ CIADDR
ciaddr (IPv4 address)
@ HLEN
hlen (hardware address length)
@ HTYPE
htype (hardware address type)
@ GIADDR
giaddr (IPv4 address)
@ CHADDR
chaddr field (up to 16 bytes link-layer address)
@ YIADDR
yiaddr (IPv4 address)
@ SIADDR
siaddr (IPv4 address)
@ TRANSID
transaction-id (xid)
@ MSGTYPE
message type (not really a field, content of option 53)
TokenPkt4(const FieldType type)
Constructor (does nothing)
Token that represents fields of DHCPv6 packet.
virtual unsigned evaluate(Pkt &pkt, ValueStack &values)
Gets a value of the specified packet.
TokenPkt6(const FieldType type)
Constructor (does nothing)
FieldType
enum value that determines the field.
@ TRANSID
transaction id (integer but manipulated as a string)
FieldType getType()
Returns field type.
Token that represents meta data of a DHCP packet.
MetadataType
enum value that determines the field.
@ DST
destination (IP address)
@ IFACE
interface name (string)
virtual unsigned evaluate(Pkt &pkt, ValueStack &values)
Gets a value from the specified packet.
MetadataType getType()
Returns metadata type.
TokenPkt(const MetadataType type)
Constructor (does nothing)
Token that represents pop and branch if false.
TokenPopAndBranchFalse(const unsigned target)
Constructor.
virtual unsigned evaluate(Pkt &pkt, ValueStack &values)
Pops the top of stack which must be "false" or "true".
Token that represents pop or branch if false.
virtual unsigned evaluate(Pkt &pkt, ValueStack &values)
Looks at the top of stack which must be "false" or "true".
TokenPopOrBranchFalse(const unsigned target)
Constructor.
Token that represents pop or branch if true.
TokenPopOrBranchTrue(const unsigned target)
Constructor.
virtual unsigned evaluate(Pkt &pkt, ValueStack &values)
Looks at the top of stack which must be "false" or "true".
Represents a sub-option inserted by the DHCPv4 relay.
virtual OptionPtr getOption(Pkt &pkt)
Attempts to obtain specified sub-option of option 82 from the packet.
TokenRelay4Option(const uint16_t option_code, const RepresentationType &rep_type)
Constructor for extracting sub-option from RAI (option 82)
Token that represents a value of a field within a DHCPv6 relay encapsulation.
FieldType type_
field to get
FieldType
enum value that determines the field.
@ LINKADDR
Link address field (IPv6 address)
@ PEERADDR
Peer address field (IPv6 address)
virtual unsigned evaluate(Pkt &pkt, ValueStack &values)
Extracts the specified field from the requested relay.
int8_t nest_level_
Specifies field of the DHCPv6 relay option to get.
FieldType getType()
Returns field type.
TokenRelay6Field(const int8_t nest_level, const FieldType type)
Constructor that takes a nesting level and field type as parameters.
int8_t getNest() const
Returns nest-level.
Token that represents a value of an option within a DHCPv6 relay encapsulation.
int8_t nest_level_
nesting level of the relay block to use
int8_t getNest() const
Returns nest-level.
virtual OptionPtr getOption(Pkt &pkt)
Attempts to obtain specified option from the specified relay block.
TokenRelay6Option(const int8_t nest_level, const uint16_t option_code, const RepresentationType &rep_type)
Constructor that takes a nesting level and an option code as parameters.
TokenSplit()
Constructor (does nothing)
virtual unsigned evaluate(Pkt &pkt, ValueStack &values)
Extract a field from a delimited string.
The order where Token subtypes are declared should be:
std::string value_
Constant value.
TokenString(const std::string &str)
Value is set during token construction.
virtual unsigned evaluate(Pkt &pkt, ValueStack &values)
Token evaluation (puts value of the constant string on the stack)
Token that represents sub-options in DHCPv4 and DHCPv6.
virtual unsigned evaluate(Pkt &pkt, ValueStack &values)
This is a method for evaluating a packet.
uint16_t sub_option_code_
Code of the sub-option to be extracted.
uint16_t getSubCode() const
Returns sub-option-code.
TokenSubOption(const uint16_t option_code, const uint16_t sub_option_code, const RepresentationType &rep_type)
Constructor that takes an option and sub-option codes as parameter.
virtual OptionPtr getSubOption(const OptionPtr &parent)
Attempts to retrieve a sub-option.
Token that represents the substring operator (returns a portion of the supplied string)
virtual unsigned evaluate(Pkt &pkt, ValueStack &values)
Extract a substring from a string.
TokenSubstring()
Constructor (does nothing)
Token that converts to hexadecimal string.
virtual unsigned evaluate(Pkt &pkt, ValueStack &values)
Convert a binary value to its hexadecimal string representation.
TokenToHexString()
Constructor (does nothing)
Token representing a 16 bit unsigned integer as a string.
virtual unsigned evaluate(Pkt &pkt, ValueStack &values)
Token evaluation (puts value of the string on the stack after decoding)
TokenUInt16ToText()
Constructor (does nothing)
Token representing a 32 bit unsigned integer as a string.
TokenUInt32ToText()
Constructor (does nothing)
virtual unsigned evaluate(Pkt &pkt, ValueStack &values)
Token evaluation (puts value of the string on the stack after decoding)
Token representing an 8 bit unsigned integer as a string.
virtual unsigned evaluate(Pkt &pkt, ValueStack &values)
Token evaluation (puts value of the string on the stack after decoding)
TokenUInt8ToText()
Constructor (does nothing)
Token representing a constant upper case string.
virtual unsigned evaluate(Pkt &pkt, ValueStack &values)
Token evaluation (puts value of the evaluated string expression converted to upper case on the stack)
TokenUpperCase()
Constructor (does nothing)
Token that represents vendor class options in DHCPv4 and DHCPv6.
TokenVendorClass(Option::Universe u, uint32_t vendor_id, RepresentationType repr)
This constructor is used to access fields.
uint16_t getDataIndex() const
Returns data index.
virtual unsigned evaluate(Pkt &pkt, ValueStack &values)
This is a method for evaluating a packet.
uint16_t index_
Data chunk index.
Token that represents vendor options in DHCPv4 and DHCPv6.
Option::Universe universe_
Universe (V4 or V6)
uint32_t vendor_id_
Enterprise-id value.
FieldType field_
Specifies which field should be accessed.
uint32_t getVendorId() const
Returns enterprise-id.
virtual unsigned evaluate(Pkt &pkt, ValueStack &values)
This is a method for evaluating a packet.
TokenVendor(Option::Universe u, uint32_t vendor_id, FieldType field)
Constructor used for accessing a field.
virtual OptionPtr getOption(Pkt &pkt)
Attempts to get a suboption.
FieldType
Specifies a field of the vendor option.
@ DATA
data chunk, used in derived vendor-class only
@ EXISTS
vendor[123].exists
@ ENTERPRISE_ID
enterprise-id field (vendor-info, vendor-class)
@ SUBOPTION
If this token fetches a suboption, not a field.
FieldType getField() const
Returns field.
Base class for all tokens.
virtual unsigned getLabel() const
Return the label of this token.
virtual ~Token()
Virtual destructor.
static bool toBool(std::string value)
Coverts a (string) value to a boolean.
virtual unsigned evaluate(Pkt &pkt, ValueStack &values)=0
This is a generic method for evaluating a packet.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
std::string ClientClass
Defines a single class name.
boost::shared_ptr< Token > TokenPtr
Pointer to a single Token.
boost::shared_ptr< Expression > ExpressionPtr
std::vector< TokenPtr > Expression
This is a structure that holds an expression converted to RPN.
boost::shared_ptr< Option > OptionPtr
std::stack< std::string > ValueStack
Evaluated values are stored as a stack of strings.
Defines the logger used by the top-level component of kea-lfc.