17 #include <boost/lexical_cast.hpp> 40 .arg(
'\'' + value_ +
'\'');
45 if ((str.size() < 3) ||
47 ((str[1] !=
'x') && (str[1] !=
'X'))) {
50 string digits = str.substr(2);
53 vector<uint8_t> binary;
58 if ((digits.length() % 2) != 0) {
59 digits = digits.insert(0,
"0");
67 value_.resize(binary.size());
68 memmove(&
value_[0], &binary[0], binary.size());
83 vector<uint8_t> binary;
92 value_.resize(binary.size());
93 memmove(&
value_[0], &binary[0], binary.size());
117 opt_str = opt->toString();
119 std::vector<uint8_t> binary = opt->toBinary();
120 opt_str.resize(binary.size());
121 if (!binary.empty()) {
122 memmove(&opt_str[0], &binary[0], binary.size());
133 values.push(opt_str);
141 .arg(
toHex(opt_str));
145 .arg(
'\'' + opt_str +
'\'');
181 Pkt6& pkt6 = dynamic_cast<Pkt6&>(pkt);
187 uint8_t nesting_level = static_cast<uint8_t>(
nest_level_);
191 if (nesting_level < 0) {
195 static_cast<uint8_t>(nesting_level)));
206 }
catch (
const std::bad_cast&) {
216 vector<uint8_t> binary;
218 bool is_binary =
true;
219 bool print_hex =
true;
240 value = EvalContext::fromUint32(static_cast<uint32_t>(const_cast<Pkt&>(pkt).len()));
247 << static_cast<int>(type_) );
251 value.resize(binary.size());
252 if (!binary.empty()) {
253 memmove(&value[0], &binary[0], binary.size());
261 .arg(print_hex ?
toHex(value) : value);
267 vector<uint8_t> binary;
274 const Pkt4& pkt4 = dynamic_cast<const Pkt4&>(pkt);
283 "Packet does not have hardware address");
285 binary = hwaddr->hwaddr_;
311 value = EvalContext::fromUint32(pkt4.
getHlen());
317 value = EvalContext::fromUint32(pkt4.
getHtype());
321 value = EvalContext::fromUint32(pkt4.
getType());
322 type_str =
"msgtype";
325 value = EvalContext::fromUint32(pkt4.
getTransid());
326 type_str =
"transid";
331 << static_cast<int>(type_) );
334 }
catch (
const std::bad_cast&) {
338 if (!binary.empty()) {
339 value.resize(binary.size());
340 memmove(&value[0], &binary[0], binary.size());
359 const Pkt6& pkt6 = dynamic_cast<const Pkt6&>(pkt);
364 value = EvalContext::fromUint32(pkt6.
getType());
365 type_str =
"msgtype";
370 value = EvalContext::fromUint32(pkt6.
getTransid());
371 type_str =
"transid";
376 << static_cast<int>(type_) );
379 }
catch (
const std::bad_cast&) {
394 vector<uint8_t> binary;
399 const Pkt6& pkt6 = dynamic_cast<const Pkt6&>(pkt);
407 if (nesting_level < 0) {
411 relay_level = static_cast<uint8_t>(nesting_level);
417 type_str =
"linkaddr";
421 type_str =
"peeraddr";
436 }
catch (
const std::bad_cast&) {
441 value.resize(binary.size());
442 if (!binary.empty()) {
443 memmove(&value[0], &binary[0], binary.size());
457 if (values.size() < 2) {
459 "2 values for == operator, got " << values.size());
462 string op1 = values.top();
464 string op2 = values.top();
470 values.push(
"false");
476 .arg(
'\'' + values.top() +
'\'');
482 if (values.size() < 3) {
484 "3 values for substring operator, got " << values.size());
487 string len_str = values.top();
489 string start_str = values.top();
491 string string_str = values.top();
495 if (string_str.empty()) {
514 start_pos = boost::lexical_cast<int>(start_str);
515 }
catch (
const boost::bad_lexical_cast&) {
517 <<
"' for the starting position of the substring " 518 <<
"couldn't be converted to an integer.");
521 if (len_str ==
"all") {
522 length = string_str.length();
524 length = boost::lexical_cast<int>(len_str);
526 }
catch (
const boost::bad_lexical_cast&) {
528 <<
"' for the length of the substring " 529 <<
"couldn't be converted to an integer.");
532 const int string_length = string_str.length();
535 if ((start_pos < -string_length) || (start_pos >= string_length)) {
542 .arg(
toHex(string_str))
551 start_pos = string_length + start_pos;
556 if (length <= start_pos){
565 values.push(string_str.substr(start_pos, length));
571 .arg(
toHex(string_str))
572 .arg(
toHex(values.top()));
578 if (values.size() < 2) {
580 "2 values for concat, got " << values.size());
583 string op1 = values.top();
585 string op2 = values.top();
589 values.push(op2 + op1);
595 .arg(
toHex(values.top()));
601 if (values.size() < 3) {
603 "3 values for ifelse, got " << values.size());
606 string iffalse = values.top();
608 string iftrue = values.top();
610 string cond = values.top();
617 values.push(iffalse);
623 .arg(
'\'' + cond +
'\'')
628 .arg(
'\'' +cond +
'\'')
630 .arg(
toHex(iffalse));
636 if (values.size() < 2) {
638 "2 values for hexstring, got " << values.size());
641 string separator = values.top();
643 string binary = values.top();
649 for (
size_t i = 0; i < binary.size(); ++i) {
655 tmp << setw(2) << setfill(
'0')
656 << (static_cast<unsigned>(binary[i]) & 0xff);
658 values.push(tmp.str());
670 if (values.size() == 0) {
674 string op = values.top();
681 values.push(
"false");
686 .arg(
'\'' + op +
'\'')
687 .arg(
'\'' + values.top() +
'\'');
693 if (values.size() < 2) {
695 "2 values for and operator, got " << values.size());
698 string op1 = values.top();
701 string op2 = values.top();
708 values.push(
"false");
713 .arg(
'\'' + op1 +
'\'')
714 .arg(
'\'' + op2 +
'\'')
715 .arg(
'\'' + values.top() +
'\'');
721 if (values.size() < 2) {
723 "2 values for or operator, got " << values.size());
726 string op1 = values.top();
729 string op2 = values.top();
736 values.push(
"false");
741 .arg(
'\'' + op1 +
'\'')
742 .arg(
'\'' + op2 +
'\'')
743 .arg(
'\'' + values.top() +
'\'');
751 values.push(
"false");
757 .arg(
'\'' + values.top() +
'\'');
761 uint16_t option_code)
762 :
TokenOption(option_code, repr), universe_(u), vendor_id_(vendor_id),
763 field_(option_code ? SUBOPTION : EXISTS)
798 OptionVendorPtr vendor = boost::dynamic_pointer_cast<OptionVendor>(opt);
814 .arg(vendor->getVendorId())
823 string txt(
sizeof(uint32_t), 0);
824 uint32_t value = htonl(vendor->getVendorId());
825 memcpy(&txt[0], &value,
sizeof(uint32_t));
828 .arg(vendor->getVendorId())
842 .arg(vendor->getVendorId())
921 .arg(vendor->getVendorId())
930 string txt(
sizeof(uint32_t), 0);
931 uint32_t value = htonl(vendor->getVendorId());
932 memcpy(&txt[0], &value,
sizeof(uint32_t));
935 .arg(vendor->getVendorId())
948 .arg(vendor->getVendorId())
954 size_t max = vendor->getTuplesNum();
960 .arg(vendor->getVendorId())
969 string txt(buf.begin(), buf.end());
data chunk, used in derived vendor-class only
boost::shared_ptr< OptionVendorClass > OptionVendorClassPtr
Defines a pointer to the OptionVendorClass.
void evaluate(Pkt &pkt, ValueStack &values)
Logical negation.
uint32_t vendor_id_
Enterprise-id value.
virtual OptionPtr getOption(Pkt &pkt)
Attempts to get a suboption.
uint8_t getHlen() const
Returns hlen field.
HWAddrPtr getHWAddr() const
returns hardware address information
void evaluate(Pkt &pkt, ValueStack &values)
Alternative.
The order where Token subtypes are declared should be:
uint8_t getHtype() const
Returns htype field.
const isc::asiolink::IOAddress & getRelay6LinkAddress(uint8_t relay_level) const
return the link address field from a relay option
uint16_t getDataIndex() const
Returns data index.
bool inClass(const isc::dhcp::ClientClass &client_class)
Checks whether a client belongs to a given class.
void evaluate(Pkt &pkt, ValueStack &values)
Gets a value from the specified packet.
std::string value_
< Constant value (empty string if the IP address cannot be converted)
boost::shared_ptr< HWAddr > HWAddrPtr
Shared pointer to a hardware address structure.
std::vector< uint8_t > Buffer
Defines a type of the data buffer used to hold the opaque data.
const isc::asiolink::IOAddress & getCiaddr() const
Returns ciaddr field.
uint16_t option_code_
Code of the option to be extracted.
If this token fetches a suboption, not a field.
FieldType type_
field to get
void evaluate(Pkt &pkt, ValueStack &values)
Gets a value of the specified packet.
Base class for classes representing DHCP messages.
void evaluate(Pkt &pkt, ValueStack &values)
Token evaluation (check if client_class_ was added to packet client classes)
boost::shared_ptr< Option > OptionPtr
Universe
defines option universe DHCPv4 or DHCPv6
Represents a DHCPv6 packet.
const isc::asiolink::IOAddress & getSiaddr() const
Returns siaddr field.
FieldType
Specifies a field of the vendor option.
OptionPtr getRelayOption(uint16_t option_code, uint8_t nesting_level)
Returns option inserted by relay.
ClientClass client_class_
The client class name.
Link address field (IPv6 address)
void evaluate(Pkt &pkt, ValueStack &values)
Extracts the specified field from the requested relay.
const isc::asiolink::IOAddress & getRelay6PeerAddress(uint8_t relay_level) const
return the peer address field from a relay option
std::string getIface() const
Returns interface name.
isc::log::Logger eval_logger("eval")
Eval Logger.
FieldType getField() const
Returns field.
std::vector< RelayInfo > relay_info_
Relay information.
TokenRelay4Option(const uint16_t option_code, const RepresentationType &rep_type)
Constructor for extracting sub-option from RAI (option 82)
virtual OptionPtr getOption(Pkt &pkt)
Attempts to obtain specified option from the specified relay block.
virtual OptionPtr getOption(Pkt &pkt)
Attempts to retrieve an option.
void evaluate(Pkt &pkt, ValueStack &values)
This is a method for evaluating a packet.
const isc::asiolink::IOAddress & getYiaddr() const
Returns yiaddr field.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Option::Universe universe_
Universe (V4 or V6)
enterprise-id field (vendor-info, vendor-class)
void decodeHex(const string &input, vector< uint8_t > &result)
Decode a text encoded in the base16 ('hex') format into the original data.
TokenInteger(const uint32_t value)
Integer value set during construction.
std::stack< std::string > ValueStack
Evaluated values are stored as a stack of strings.
uint8_t getType() const
Returns DHCP message type (e.g.
std::string value_
Constant value.
Evaluation context, an interface to the expression evaluation.
static bool toBool(std::string value)
Coverts a (string) value to a boolean.
std::vector< uint8_t > toBytes() const
Return address as set of bytes.
void evaluate(Pkt &pkt, ValueStack &values)
Extract a substring from a string.
chaddr field (up to 16 bytes link-layer address)
Token that represents a value of an option.
htype (hardware address type)
virtual OptionPtr getOption(Pkt &pkt)
Attempts to obtain specified sub-option of option 82 from the packet.
virtual std::string pushFailure(ValueStack &values)
Auxiliary method that puts string representing a failure.
message type (not really a field, content of option 53)
void evaluate(Pkt &pkt, ValueStack &values)
Logical and.
void evaluate(Pkt &pkt, ValueStack &values)
Token evaluation (puts value of the constant string on the stack after decoding or an empty string if...
const isc::asiolink::IOAddress & getGiaddr() const
Returns giaddr field.
void evaluate(Pkt &pkt, ValueStack &values)
Concatenate two values.
void evaluate(Pkt &pkt, ValueStack &values)
Gets a value from the specified packet.
const isc::asiolink::IOAddress & getRemoteAddr() const
Returns remote IP address.
TokenVendor(Option::Universe u, uint32_t vendor_id, FieldType field)
Constructor used for accessing a field.
string encodeHex(const vector< uint8_t > &binary)
Encode binary data in the base16 ('hex') format.
void evaluate(Pkt &pkt, ValueStack &values)
Token evaluation (puts value of the constant string on the stack after decoding)
Represents DHCPv4 packet.
void evaluate(Pkt &pkt, ValueStack &values)
Compare two values.
RepresentationType
Token representation type.
EvalBadStack is thrown when more or less parameters are on the stack than expected.
const Buffer & getData() const
Returns a reference to the buffer holding tuple data.
Peer address field (IPv6 address)
RepresentationType representation_type_
Representation type.
OptionPtr getOption(const uint16_t type)
Returns the first option of specified type.
void evaluate(Pkt &pkt, ValueStack &values)
Convert a binary value to its hexadecimal string representation.
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
Represents a single instance of the opaque data preceded by length.
virtual uint8_t getType() const
Returns message type (e.g.
std::string toHex(std::string value)
Encode in hexadecimal inline.
A generic exception that is thrown if a parameter given to a method would refer to or modify out-of-r...
uint32_t getVendorId() const
Returns enterprise-id.
void evaluate(Pkt &pkt, ValueStack &values)
Token evaluation (puts value of the constant string on the stack)
EvalTypeError is thrown when a value on the stack has a content with an unexpected type.
uint16_t index_
Data chunk index.
void evaluate(Pkt &pkt, ValueStack &values)
Logical or.
TokenIpAddress(const std::string &addr)
Value is set during token construction.
virtual void evaluate(Pkt &pkt, ValueStack &values)
This is a method for evaluating a packet.
TokenHexString(const std::string &str)
Value is set during token construction.
int8_t nest_level_
nesting level of the relay block to use
The IOAddress class represents an IP addresses (version agnostic)
const isc::asiolink::IOAddress & getLocalAddr() const
Returns local IP address.
boost::shared_ptr< OptionVendor > OptionVendorPtr
Pointer to a vendor option.
int8_t nest_level_
Specifies field of the DHCPv6 relay option to get.
void evaluate(Pkt &pkt, ValueStack &values)
Evaluates the values of the option.
uint32_t getTransid() const
Returns value of transaction-id field.
hlen (hardware address length)
TokenVendorClass(Option::Universe u, uint32_t vendor_id, RepresentationType repr)
This constructor is used to access fields.
transaction id (integer but manipulated as a string)
Token that represents vendor options in DHCPv4 and DHCPv6.
FieldType field_
Specifies which field should be accessed.