17#include <boost/lexical_cast.hpp>
23#include <boost/algorithm/string.hpp>
24#include <boost/algorithm/string/classification.hpp>
25#include <boost/algorithm/string/split.hpp>
47 .arg(
'\'' +
value_ +
'\'');
52 if ((
str.size() < 3) ||
54 ((
str[1] !=
'x') && (
str[1] !=
'X'))) {
57 string digits =
str.substr(2);
60 vector<uint8_t> binary;
65 if ((digits.length() % 2) != 0) {
66 digits = digits.insert(0,
"0");
74 value_.resize(binary.size());
75 memmove(&value_[0], &binary[0], binary.size());
91 if (values.size() == 0) {
95 string op = values.top();
98 string result(boost::algorithm::to_lower_copy(op));
104 .arg(
'\'' + op +
'\'')
105 .arg(
'\'' +
result +
'\'');
110 if (values.size() == 0) {
114 string op = values.top();
117 string result(boost::algorithm::to_upper_copy(op));
123 .arg(
'\'' + op +
'\'')
124 .arg(
'\'' +
result +
'\'');
129 vector<uint8_t> binary;
138 value_.resize(binary.size());
139 memmove(&
value_[0], &binary[0], binary.size());
155 if (values.size() == 0) {
159 string op = values.top();
160 size_t size = op.size();
168 if ((size != V4ADDRESS_LEN) && (size != V6ADDRESS_LEN)) {
172 std::vector<uint8_t> binary(op.begin(), op.end());
174 if (size == V4ADDRESS_LEN) {
190 if (values.size() == 0) {
194 string op = values.top();
195 size_t size = op.size();
203 if (size !=
sizeof(int8_t)) {
208 tmp << static_cast<int32_t>(*(
reinterpret_cast<const int8_t*
>(op.data())));
220 if (values.size() == 0) {
224 string op = values.top();
225 size_t size = op.size();
233 if (size !=
sizeof(int16_t)) {
238 int16_t value =
static_cast<int16_t
>(
readUint16(
const_cast<const char*
>(op.data()), size));
251 if (values.size() == 0) {
255 string op = values.top();
256 size_t size = op.size();
264 if (size !=
sizeof(int32_t)) {
269 int32_t value =
static_cast<int32_t
>(
readUint32(
const_cast<const char*
>(op.data()), size));
282 if (values.size() == 0) {
286 string op = values.top();
287 size_t size = op.size();
295 if (size !=
sizeof(uint8_t)) {
300 tmp << static_cast<uint32_t>(*(
reinterpret_cast<const uint8_t*
>(op.data())));
312 if (values.size() == 0) {
316 string op = values.top();
317 size_t size = op.size();
325 if (size !=
sizeof(uint16_t)) {
330 uint16_t value =
readUint16(
const_cast<const char*
>(op.data()), size);
343 if (values.size() == 0) {
347 string op = values.top();
348 size_t size = op.size();
356 if (size !=
sizeof(uint32_t)) {
361 uint32_t value =
readUint32(
const_cast<const char*
>(op.data()), size);
383 opt_str = opt->toString();
385 std::vector<uint8_t> binary = opt->toBinary();
386 opt_str.resize(binary.size());
387 if (!binary.empty()) {
388 memmove(&opt_str[0], &binary[0], binary.size());
399 values.push(opt_str);
408 .arg(
toHex(opt_str));
413 .arg(
'\'' + opt_str +
'\'');
447 Pkt6& pkt6 =
dynamic_cast<Pkt6&
>(pkt);
453 uint8_t nesting_level =
static_cast<uint8_t
>(
nest_level_);
457 if (nesting_level < 0) {
461 static_cast<uint8_t
>(nesting_level)));
472 }
catch (
const std::bad_cast&) {
481 vector<uint8_t> binary;
483 bool is_binary =
true;
484 bool print_hex =
true;
515 value.resize(binary.size());
516 if (!binary.empty()) {
517 memmove(&value[0], &binary[0], binary.size());
526 .arg(print_hex ?
toHex(value) : value);
531 vector<uint8_t> binary;
538 const Pkt4& pkt4 =
dynamic_cast<const Pkt4&
>(pkt);
547 "Packet does not have hardware address");
549 binary = hwaddr->hwaddr_;
581 type_str =
"msgtype";
585 type_str =
"transid";
591 }
catch (
const std::bad_cast&) {
595 if (!binary.empty()) {
596 value.resize(binary.size());
597 memmove(&value[0], &binary[0], binary.size());
616 const Pkt6& pkt6 =
dynamic_cast<const Pkt6&
>(pkt);
622 type_str =
"msgtype";
628 type_str =
"transid";
635 }
catch (
const std::bad_cast&) {
650 vector<uint8_t> binary;
655 const Pkt6& pkt6 =
dynamic_cast<const Pkt6&
>(pkt);
663 if (nesting_level < 0) {
667 relay_level =
static_cast<uint8_t
>(nesting_level);
673 type_str =
"linkaddr";
677 type_str =
"peeraddr";
693 }
catch (
const std::bad_cast&) {
698 value.resize(binary.size());
699 if (!binary.empty()) {
700 memmove(&value[0], &binary[0], binary.size());
714 if (values.size() < 2) {
716 "2 values for == operator, got " << values.size());
719 string op1 = values.top();
721 string op2 = values.top();
727 values.push(
"false");
734 .arg(
'\'' + values.top() +
'\'');
739 if (values.size() < 3) {
741 "3 values for substring operator, got " << values.size());
744 string len_str = values.top();
746 string start_str = values.top();
748 string string_str = values.top();
752 if (string_str.empty()) {
772 start_pos = boost::lexical_cast<int>(start_str);
773 }
catch (
const boost::bad_lexical_cast&) {
775 <<
"' for the starting position of the substring "
776 <<
"couldn't be converted to an integer.");
779 if (len_str ==
"all") {
780 length = string_str.length();
782 length = boost::lexical_cast<int>(len_str);
784 }
catch (
const boost::bad_lexical_cast&) {
786 <<
"' for the length of the substring "
787 <<
"couldn't be converted to an integer.");
790 const int string_length = string_str.length();
793 if ((start_pos < -string_length) || (start_pos >= string_length)) {
801 .arg(
toHex(string_str))
810 start_pos = string_length + start_pos;
815 if (length <= start_pos){
824 values.push(string_str.substr(start_pos, length));
831 .arg(
toHex(string_str))
832 .arg(
toHex(values.top()));
837 if (values.size() < 3) {
839 "3 values for split operator, got " << values.size());
843 string field_str = values.top();
845 string delim_str = values.top();
847 string string_str = values.top();
851 if (string_str.empty()) {
868 field = boost::lexical_cast<int>(field_str);
869 }
catch (
const boost::bad_lexical_cast&) {
871 <<
"' for the field field for split "
872 <<
"couldn't be converted to an integer.");
876 if (delim_str.empty()) {
877 values.push(string_str);
885 .arg(
toHex(values.top()));
890 std::vector<std::string> fields;
891 boost::split(fields, string_str, boost::is_any_of(delim_str),
892 boost::algorithm::token_compress_off);
895 if (field < 1 || field > fields.size()) {
910 values.push(fields[field - 1]);
918 .arg(
toHex(values.top()));
923 if (values.size() < 2) {
925 "2 values for concat, got " << values.size());
928 string op1 = values.top();
930 string op2 = values.top();
934 values.push(op2 + op1);
941 .arg(
toHex(values.top()));
946 if (values.size() < 3) {
948 "3 values for ifelse, got " << values.size());
951 string iffalse = values.top();
953 string iftrue = values.top();
955 string cond = values.top();
962 values.push(iffalse);
969 .arg(
'\'' + cond +
'\'')
975 .arg(
'\'' +cond +
'\'')
977 .arg(
toHex(iffalse));
983 if (values.size() < 2) {
985 "2 values for hexstring, got " << values.size());
988 string separator = values.top();
990 string binary = values.top();
996 for (
size_t i = 0; i < binary.size(); ++i) {
1002 tmp << setw(2) << setfill(
'0')
1003 << (
static_cast<unsigned>(binary[i]) & 0xff);
1005 values.push(tmp.str());
1017 if (values.size() == 0) {
1021 string op = values.top();
1026 values.push(
"true");
1028 values.push(
"false");
1034 .arg(
'\'' + op +
'\'')
1035 .arg(
'\'' + values.top() +
'\'');
1040 if (values.size() < 2) {
1042 "2 values for and operator, got " << values.size());
1045 string op1 = values.top();
1048 string op2 = values.top();
1053 values.push(
"true");
1055 values.push(
"false");
1061 .arg(
'\'' + op1 +
'\'')
1062 .arg(
'\'' + op2 +
'\'')
1063 .arg(
'\'' + values.top() +
'\'');
1068 if (values.size() < 2) {
1070 "2 values for or operator, got " << values.size());
1073 string op1 = values.top();
1076 string op2 = values.top();
1081 values.push(
"true");
1083 values.push(
"false");
1089 .arg(
'\'' + op1 +
'\'')
1090 .arg(
'\'' + op2 +
'\'')
1091 .arg(
'\'' + values.top() +
'\'');
1097 values.push(
"true");
1099 values.push(
"false");
1106 .arg(
'\'' + values.top() +
'\'');
1110 uint16_t option_code)
1144 OptionVendorPtr vendor = boost::dynamic_pointer_cast<OptionVendor>(opt);
1162 .arg(vendor->getVendorId())
1171 string txt(
sizeof(uint32_t), 0);
1172 uint32_t value = htonl(vendor->getVendorId());
1173 memcpy(&txt[0], &value,
sizeof(uint32_t));
1177 .arg(vendor->getVendorId())
1192 .arg(vendor->getVendorId())
1194 values.push(
"true");
1271 .arg(vendor->getVendorId())
1280 string txt(
sizeof(uint32_t), 0);
1281 uint32_t value = htonl(vendor->getVendorId());
1282 memcpy(&txt[0], &value,
sizeof(uint32_t));
1286 .arg(vendor->getVendorId())
1300 .arg(vendor->getVendorId())
1302 values.push(
"true");
1306 size_t max = vendor->getTuplesNum();
1313 .arg(vendor->getVendorId())
1322 string txt(buf.begin(), buf.end());
1370 txt = sub->toString();
1372 std::vector<uint8_t> binary = sub->toBinary();
1373 txt.resize(binary.size());
1374 if (!binary.empty()) {
1375 memmove(&txt[0], &binary[0], binary.size());
1401 .arg(
'\'' + txt +
'\'');
when the call the UDPServer carries on at the same position As a result
A generic exception that is thrown if a parameter given to a method would refer to or modify out-of-r...
The IOAddress class represents an IP addresses (version agnostic)
std::string toText() const
Convert the address to a string.
std::vector< uint8_t > toBytes() const
Return address as set of bytes.
static IOAddress fromBytes(short family, const uint8_t *data)
Creates an address from over wire data.
EvalBadStack is thrown when more or less parameters are on the stack than expected.
EvalTypeError is thrown when a value on the stack has a content with an unexpected type.
Represents a single instance of the opaque data preceded by length.
const Buffer & getData() const
Returns a reference to the buffer holding tuple data.
std::vector< uint8_t > Buffer
Defines a type of the data buffer used to hold the opaque data.
Universe
defines option universe DHCPv4 or DHCPv6
Represents DHCPv4 packet.
const isc::asiolink::IOAddress & getSiaddr() const
Returns siaddr field.
const isc::asiolink::IOAddress & getYiaddr() const
Returns yiaddr field.
const isc::asiolink::IOAddress & getGiaddr() const
Returns giaddr field.
const isc::asiolink::IOAddress & getCiaddr() const
Returns ciaddr field.
HWAddrPtr getHWAddr() const
returns hardware address information
uint8_t getHlen() const
Returns hlen field.
uint8_t getType() const
Returns DHCP message type (e.g.
uint8_t getHtype() const
Returns htype field.
Represents a DHCPv6 packet.
OptionPtr getRelayOption(uint16_t option_code, uint8_t nesting_level)
Returns option inserted by relay.
const isc::asiolink::IOAddress & getRelay6PeerAddress(uint8_t relay_level) const
return the peer address field from a relay option
const isc::asiolink::IOAddress & getRelay6LinkAddress(uint8_t relay_level) const
return the link address field from a relay option
std::vector< RelayInfo > relay_info_
Relay information.
virtual uint8_t getType() const
Returns message type (e.g.
Base class for classes representing DHCP messages.
const isc::asiolink::IOAddress & getLocalAddr() const
Returns local IP address.
const isc::asiolink::IOAddress & getRemoteAddr() const
Returns remote IP address.
uint32_t getTransid() const
Returns value of transaction-id field.
std::string getIface() const
Returns interface name.
OptionPtr getOption(const uint16_t type)
Returns the first option of specified type.
bool inClass(const isc::dhcp::ClientClass &client_class)
Checks whether a client belongs to a given class.
virtual std::string getLabel() const
Returns text representation primary packet identifiers.
void evaluate(Pkt &pkt, ValueStack &values)
Logical and.
void evaluate(Pkt &pkt, ValueStack &values)
Concatenate two values.
void evaluate(Pkt &pkt, ValueStack &values)
Compare two values.
void evaluate(Pkt &pkt, ValueStack &values)
Token evaluation (puts value of the constant string on the stack after decoding or an empty string if...
std::string value_
Constant value.
TokenHexString(const std::string &str)
Value is set during token construction.
void evaluate(Pkt &pkt, ValueStack &values)
Alternative.
void evaluate(Pkt &pkt, ValueStack &values)
Token evaluation (puts value of the string on the stack after decoding)
void evaluate(Pkt &pkt, ValueStack &values)
Token evaluation (puts value of the string on the stack after decoding)
void evaluate(Pkt &pkt, ValueStack &values)
Token evaluation (puts value of the string on the stack after decoding)
TokenInteger(const uint32_t value)
Integer value set during construction.
uint32_t int_value_
value as integer (stored for testing only)
void evaluate(Pkt &pkt, ValueStack &values)
Token evaluation (puts value of the string on the stack after decoding)
void evaluate(Pkt &pkt, ValueStack &values)
Token evaluation (puts value of the constant string on the stack after decoding)
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.
void evaluate(Pkt &pkt, ValueStack &values)
Token evaluation (puts value of the evaluated string expression converted to lower case on the stack)
ClientClass client_class_
The client class name.
void evaluate(Pkt &pkt, ValueStack &values)
Token evaluation (check if client_class_ was added to packet client classes)
void evaluate(Pkt &pkt, ValueStack &values)
Logical negation.
Token that represents a value of an option.
virtual OptionPtr getOption(Pkt &pkt)
Attempts to retrieve an option.
void evaluate(Pkt &pkt, ValueStack &values)
Evaluates the values of the 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 std::string pushFailure(ValueStack &values)
Auxiliary method that puts string representing a failure.
void evaluate(Pkt &pkt, ValueStack &values)
Logical or.
@ 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)
void evaluate(Pkt &pkt, ValueStack &values)
Gets a value from the specified packet.
void evaluate(Pkt &pkt, ValueStack &values)
Gets a value of the specified packet.
@ TRANSID
transaction id (integer but manipulated as a string)
@ DST
destination (IP address)
@ IFACE
interface name (string)
void evaluate(Pkt &pkt, ValueStack &values)
Gets a value from the specified packet.
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
void evaluate(Pkt &pkt, ValueStack &values)
Extracts the specified field from the requested relay.
@ LINKADDR
Link address field (IPv6 address)
@ PEERADDR
Peer address field (IPv6 address)
int8_t nest_level_
Specifies field of the DHCPv6 relay option to get.
int8_t nest_level_
nesting level of the relay block to use
virtual OptionPtr getOption(Pkt &pkt)
Attempts to obtain specified option from the specified relay block.
void 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.
void evaluate(Pkt &pkt, ValueStack &values)
Token evaluation (puts value of the constant string on the stack)
virtual void 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.
virtual OptionPtr getSubOption(const OptionPtr &parent)
Attempts to retrieve a sub-option.
void evaluate(Pkt &pkt, ValueStack &values)
Extract a substring from a string.
void evaluate(Pkt &pkt, ValueStack &values)
Convert a binary value to its hexadecimal string representation.
void evaluate(Pkt &pkt, ValueStack &values)
Token evaluation (puts value of the string on the stack after decoding)
void evaluate(Pkt &pkt, ValueStack &values)
Token evaluation (puts value of the string on the stack after decoding)
void evaluate(Pkt &pkt, ValueStack &values)
Token evaluation (puts value of the string on the stack after decoding)
void evaluate(Pkt &pkt, ValueStack &values)
Token evaluation (puts value of the evaluated string expression converted to upper case on the stack)
TokenVendorClass(Option::Universe u, uint32_t vendor_id, RepresentationType repr)
This constructor is used to access fields.
uint16_t getDataIndex() const
Returns data index.
uint16_t index_
Data chunk index.
void evaluate(Pkt &pkt, ValueStack &values)
This is a method for evaluating a packet.
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.
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.
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.
virtual void evaluate(Pkt &pkt, ValueStack &values)
This is a method for evaluating a packet.
FieldType getField() const
Returns field.
static bool toBool(std::string value)
Coverts a (string) value to a boolean.
Evaluation context, an interface to the expression evaluation.
static std::string fromUint32(const uint32_t integer)
Converts unsigned 32bit integer to string representation.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
boost::shared_ptr< OptionVendor > OptionVendorPtr
Pointer to a vendor option.
const isc::log::MessageID EVAL_DEBUG_RELAY6_RANGE
const isc::log::MessageID EVAL_DEBUG_UCASE
const isc::log::MessageID EVAL_DEBUG_UINT32TOTEXT
const isc::log::MessageID EVAL_DEBUG_UINT16TOTEXT
const isc::log::MessageID EVAL_DEBUG_SPLIT_EMPTY
const isc::log::MessageID EVAL_DEBUG_VENDOR_CLASS_EXISTS
const isc::log::MessageID EVAL_DEBUG_VENDOR_CLASS_DATA_NOT_FOUND
const isc::log::MessageID EVAL_DEBUG_PKT
const isc::log::MessageID EVAL_DEBUG_HEXSTRING
const isc::log::MessageID EVAL_DEBUG_TOHEXSTRING
const isc::log::MessageID EVAL_DEBUG_VENDOR_CLASS_DATA
const isc::log::MessageID EVAL_DEBUG_SPLIT_FIELD_OUT_OF_RANGE
const isc::log::MessageID EVAL_DEBUG_INT32TOTEXT
const isc::log::MessageID EVAL_DEBUG_OPTION
const isc::log::MessageID EVAL_DEBUG_SUBSTRING
const isc::log::MessageID EVAL_DEBUG_PKT6
const isc::log::MessageID EVAL_DEBUG_RELAY6
const isc::log::MessageID EVAL_DEBUG_OR
const isc::log::MessageID EVAL_DEBUG_SUB_OPTION_NO_OPTION
const isc::log::MessageID EVAL_DEBUG_INT8TOTEXT
const isc::log::MessageID EVAL_DEBUG_VENDOR_ENTERPRISE_ID
boost::shared_ptr< HWAddr > HWAddrPtr
Shared pointer to a hardware address structure.
const isc::log::MessageID EVAL_DEBUG_STRING
const isc::log::MessageID EVAL_DEBUG_VENDOR_ENTERPRISE_ID_MISMATCH
const isc::log::MessageID EVAL_DEBUG_SUB_OPTION
const isc::log::MessageID EVAL_DEBUG_SPLIT
const isc::log::MessageID EVAL_DEBUG_PKT4
const isc::log::MessageID EVAL_DEBUG_INT16TOTEXT
isc::log::Logger eval_logger("eval")
Eval Logger.
const isc::log::MessageID EVAL_DEBUG_CONCAT
const isc::log::MessageID EVAL_DEBUG_VENDOR_CLASS_ENTERPRISE_ID_MISMATCH
const isc::log::MessageID EVAL_DEBUG_VENDOR_EXISTS
const isc::log::MessageID EVAL_DEBUG_VENDOR_NO_OPTION
const isc::log::MessageID EVAL_DEBUG_LCASE
boost::shared_ptr< OptionVendorClass > OptionVendorClassPtr
Defines a pointer to the OptionVendorClass.
const isc::log::MessageID EVAL_DEBUG_IPADDRESS
const isc::log::MessageID EVAL_DEBUG_AND
const isc::log::MessageID EVAL_DEBUG_VENDOR_CLASS_NO_OPTION
const isc::log::MessageID EVAL_DEBUG_VENDOR_CLASS_ENTERPRISE_ID
const isc::log::MessageID EVAL_DEBUG_UINT8TOTEXT
const isc::log::MessageID EVAL_DEBUG_EQUAL
const isc::log::MessageID EVAL_DEBUG_IPADDRESSTOTEXT
const isc::log::MessageID EVAL_DEBUG_SPLIT_DELIM_EMPTY
const isc::log::MessageID EVAL_DEBUG_MEMBER
const isc::log::MessageID EVAL_DEBUG_IFELSE_TRUE
const isc::log::MessageID EVAL_DEBUG_NOT
boost::shared_ptr< Option > OptionPtr
const isc::log::MessageID EVAL_DEBUG_SUBSTRING_RANGE
std::stack< std::string > ValueStack
Evaluated values are stored as a stack of strings.
const isc::log::MessageID EVAL_DEBUG_IFELSE_FALSE
const isc::log::MessageID EVAL_DEBUG_SUBSTRING_EMPTY
void decodeHex(const string &encoded_str, vector< uint8_t > &output)
Decode a base16 encoded string into binary data.
string encodeHex(const vector< uint8_t > &binary)
Encode binary data in the base16 format.
std::string toHex(std::string value)
Encode in hexadecimal inline.
uint16_t readUint16(void const *const buffer, size_t const length)
uint16_t wrapper over readUint.
uint32_t readUint32(void const *const buffer, size_t const length)
uint32_t wrapper over readUint.
std::string toHex(std::string value)
Encode in hexadecimal inline.