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_;
Exception(const char *file, size_t line, const char *what)
Constructor for a given type for exceptions with file name and file line number.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
EvalBadLabel(const char *file, size_t line, const char *what)
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.
virtual unsigned evaluate(Pkt &pkt, ValueStack &values)
Logical and.
TokenAnd()
Constructor (does nothing)
virtual unsigned evaluate(Pkt &pkt, ValueStack &values)
Only return the target.
TokenBranch(const unsigned target)
Constructor.
unsigned getTarget() const
Returns branchtarget.
TokenConcat()
Constructor (does nothing)
virtual unsigned evaluate(Pkt &pkt, ValueStack &values)
Concatenate two values.
virtual unsigned evaluate(Pkt &pkt, ValueStack &values)
Compare two values.
TokenEqual()
Constructor (does nothing)
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.
TokenIfElse()
Constructor (does nothing)
virtual unsigned evaluate(Pkt &pkt, ValueStack &values)
Alternative.
virtual unsigned evaluate(Pkt &pkt, ValueStack &values)
Token evaluation (puts value of the string on the stack after decoding)
TokenInt16ToText()
Constructor (does nothing)
TokenInt32ToText()
Constructor (does nothing)
virtual unsigned evaluate(Pkt &pkt, ValueStack &values)
Token evaluation (puts value of the string on the stack after decoding)
virtual unsigned evaluate(Pkt &pkt, ValueStack &values)
Token evaluation (puts value of the string on the stack after decoding)
TokenInt8ToText()
Constructor (does nothing)
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)
virtual unsigned evaluate(Pkt &pkt, ValueStack &values)
Token evaluation (puts value of the string on the stack after decoding)
TokenIpAddressToText()
Constructor (does nothing)
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.
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)
virtual unsigned evaluate(Pkt &pkt, ValueStack &values)
Match regular expression.
const std::string & getRegExp() const
Returns regular expression.
TokenMatch(const std::string ®_exp)
Constructor.
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.
TokenNot()
Constructor (does nothing)
virtual unsigned evaluate(Pkt &pkt, ValueStack &values)
Logical negation.
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.
virtual unsigned evaluate(Pkt &pkt, ValueStack &values)
Logical or.
TokenOr()
Constructor (does nothing)
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)
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.
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)
TokenPopAndBranchFalse(const unsigned target)
Constructor.
virtual unsigned evaluate(Pkt &pkt, ValueStack &values)
Pops the top of stack which must be "false" or "true".
virtual unsigned evaluate(Pkt &pkt, ValueStack &values)
Looks at the top of stack which must be "false" or "true".
TokenPopOrBranchFalse(const unsigned target)
Constructor.
TokenPopOrBranchTrue(const unsigned target)
Constructor.
virtual unsigned evaluate(Pkt &pkt, ValueStack &values)
Looks at the top of stack which must be "false" or "true".
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)
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.
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.
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)
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.
virtual unsigned evaluate(Pkt &pkt, ValueStack &values)
Extract a substring from a string.
TokenSubstring()
Constructor (does nothing)
virtual unsigned evaluate(Pkt &pkt, ValueStack &values)
Convert a binary value to its hexadecimal string representation.
TokenToHexString()
Constructor (does nothing)
virtual unsigned evaluate(Pkt &pkt, ValueStack &values)
Token evaluation (puts value of the string on the stack after decoding)
TokenUInt16ToText()
Constructor (does nothing)
TokenUInt32ToText()
Constructor (does nothing)
virtual unsigned evaluate(Pkt &pkt, ValueStack &values)
Token evaluation (puts value of the string on the stack after decoding)
virtual unsigned evaluate(Pkt &pkt, ValueStack &values)
Token evaluation (puts value of the string on the stack after decoding)
TokenUInt8ToText()
Constructor (does nothing)
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)
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.
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.