Kea 2.7.5
isc::dhcp::TokenVendor Class Reference

Token that represents vendor options in DHCPv4 and DHCPv6. More...

#include <token.h>

+ Inheritance diagram for isc::dhcp::TokenVendor:

Public Types

enum  FieldType : int { SUBOPTION , ENTERPRISE_ID , EXISTS , DATA }
 Specifies a field of the vendor option. More...
 
- Public Types inherited from isc::dhcp::TokenOption
enum  RepresentationType { TEXTUAL , HEXADECIMAL , EXISTS }
 Token representation type. More...
 

Public Member Functions

 TokenVendor (Option::Universe u, uint32_t vendor_id, FieldType field)
 Constructor used for accessing a field.
 
 TokenVendor (Option::Universe u, uint32_t vendor_id, RepresentationType repr, uint16_t option_code=0)
 Constructor used for accessing an option.
 
virtual unsigned evaluate (Pkt &pkt, ValueStack &values)
 This is a method for evaluating a packet.
 
FieldType getField () const
 Returns field.
 
uint32_t getVendorId () const
 Returns enterprise-id.
 
- Public Member Functions inherited from isc::dhcp::TokenOption
 TokenOption (const uint16_t option_code, const RepresentationType &rep_type)
 Constructor that takes an option code as a parameter.
 
uint16_t getCode () const
 Returns option-code.
 
RepresentationType getRepresentation () const
 Returns representation-type.
 
- Public Member Functions inherited from isc::dhcp::Token
virtual ~Token ()
 Virtual destructor.
 
virtual unsigned getLabel () const
 Return the label of this token.
 

Protected Member Functions

virtual OptionPtr getOption (Pkt &pkt)
 Attempts to get a suboption.
 
- Protected Member Functions inherited from isc::dhcp::TokenOption
virtual std::string pushFailure (ValueStack &values)
 Auxiliary method that puts string representing a failure.
 

Protected Attributes

FieldType field_
 Specifies which field should be accessed.
 
Option::Universe universe_
 Universe (V4 or V6)
 
uint32_t vendor_id_
 Enterprise-id value.
 
- Protected Attributes inherited from isc::dhcp::TokenOption
uint16_t option_code_
 Code of the option to be extracted.
 
RepresentationType representation_type_
 Representation type.
 

Additional Inherited Members

- Static Public Member Functions inherited from isc::dhcp::Token
static bool toBool (std::string value)
 Coverts a (string) value to a boolean.
 

Detailed Description

Token that represents vendor options in DHCPv4 and DHCPv6.

It covers vendor independent vendor information option (125, DHCPv4) and vendor option (17, DHCPv6). Since both of those options may have suboptions, this class is derived from TokenOption and leverages its ability to operate on sub-options. It also adds additional capabilities. In particular, it allows retrieving enterprise-id.

It can represent the following expressions: vendor[4491].exists - if vendor option with enterprise-id = 4491 exists vendor[*].exists - if any vendor option exists vendor.enterprise - returns enterprise-id from vendor option vendor[4491].option[1].exists - check if suboption 1 exists for vendor 4491 vendor[4491].option[1].hex - return content of suboption 1 for vendor 4491

Definition at line 1136 of file token.h.

Member Enumeration Documentation

◆ FieldType

Specifies a field of the vendor option.

Enumerator
SUBOPTION 

If this token fetches a suboption, not a field.

ENTERPRISE_ID 

enterprise-id field (vendor-info, vendor-class)

EXISTS 

vendor[123].exists

DATA 

data chunk, used in derived vendor-class only

Definition at line 1140 of file token.h.

Constructor & Destructor Documentation

◆ TokenVendor() [1/2]

TokenVendor::TokenVendor ( Option::Universe u,
uint32_t vendor_id,
FieldType field )

Constructor used for accessing a field.

Parameters
uuniverse (either V4 or V6)
vendor_idspecifies enterprise-id (0 means any)
fieldspecifies which field should be returned

Definition at line 1171 of file token.cc.

References isc::dhcp::TokenOption::EXISTS, EXISTS, field_, and isc::dhcp::TokenOption::representation_type_.

◆ TokenVendor() [2/2]

TokenVendor::TokenVendor ( Option::Universe u,
uint32_t vendor_id,
RepresentationType repr,
uint16_t option_code = 0 )

Constructor used for accessing an option.

This constructor is used for accessing suboptions. In general option_code is mandatory, except when repr is EXISTS. For option_code = 0 and repr = EXISTS, the token will return true if the whole option exists, not suboptions.

Parameters
uuniverse (either V4 or V6)
vendor_idspecifies enterprise-id (0 means any)
reprrepresentation type (hex or exists)
option_codesub-option code

Definition at line 1165 of file token.cc.

Member Function Documentation

◆ evaluate()

unsigned TokenVendor::evaluate ( Pkt & pkt,
ValueStack & values )
virtual

This is a method for evaluating a packet.

Depending on the value of vendor_id, field type, representation and option code, it will attempt to return specified characteristic of the vendor option

If vendor-id is specified, check only option with that particular enterprise-id. If vendor-id is 0, check any vendor option, regardless of its enterprise-id value.

If FieldType is NONE, get specified suboption represented by option_code and represent it as specified by repr.

If FieldType is ENTERPRISE_ID, return value of the enterprise-id field or "" if there's no vendor option.

Exceptions
EvalTypeErrorfor any other FieldType values.

The parameters passed are:

Parameters
pkt- vendor options will be searched for here.
values- the evaluated value will be pushed here.
Returns
0 which means evaluate next token if any.

This is vendor[X].option[Y].exists, let's try to extract the option

Reimplemented from isc::dhcp::TokenOption.

Reimplemented in isc::dhcp::TokenVendorClass.

Definition at line 1190 of file token.cc.

References D6O_VENDOR_OPTS, DATA, isc::dhcp::DHO_VIVSO_SUBOPTIONS, isc::util::encode::encodeHex(), ENTERPRISE_ID, isc::dhcp::EVAL_DBG_STACK, isc::dhcp::EVAL_DEBUG_VENDOR_ENTERPRISE_ID, isc::dhcp::EVAL_DEBUG_VENDOR_ENTERPRISE_ID_MISMATCH, isc::dhcp::EVAL_DEBUG_VENDOR_EXISTS, isc::dhcp::EVAL_DEBUG_VENDOR_NO_OPTION, isc::dhcp::eval_logger, isc::dhcp::TokenOption::evaluate(), EXISTS, field_, isc_throw, LOG_DEBUG, isc::dhcp::TokenOption::pushFailure(), SUBOPTION, universe_, isc::dhcp::Option::V4, isc::dhcp::Option::V6, and vendor_id_.

+ Here is the call graph for this function:

◆ getField()

TokenVendor::FieldType TokenVendor::getField ( ) const

Returns field.

Used in tests only.

Returns
field type.

Definition at line 1185 of file token.cc.

References field_.

◆ getOption()

OptionPtr TokenVendor::getOption ( Pkt & pkt)
protectedvirtual

Attempts to get a suboption.

This method overrides behavior of TokenOption method. It attempts to retrieve the sub-option of the vendor option. Using derived method allows usage of TokenOption routines.

Parameters
pktvendor option will be searched here.
Returns
suboption of the vendor option (if exists)

Reimplemented from isc::dhcp::TokenOption.

Definition at line 1264 of file token.cc.

References D6O_VENDOR_OPTS, isc::dhcp::DHO_VIVSO_SUBOPTIONS, isc::dhcp::TokenOption::option_code_, universe_, isc::dhcp::Option::V4, and isc::dhcp::Option::V6.

◆ getVendorId()

uint32_t TokenVendor::getVendorId ( ) const

Returns enterprise-id.

Used in tests only.

Returns
enterprise-id

Definition at line 1180 of file token.cc.

References vendor_id_.

Member Data Documentation

◆ field_

FieldType isc::dhcp::TokenVendor::field_
protected

Specifies which field should be accessed.

Definition at line 1231 of file token.h.

Referenced by TokenVendor(), isc::dhcp::TokenVendorClass::TokenVendorClass(), evaluate(), isc::dhcp::TokenVendorClass::evaluate(), and getField().

◆ universe_

Option::Universe isc::dhcp::TokenVendor::universe_
protected

Universe (V4 or V6)

We need to remember it, because depending on the universe, the code needs to retrieve either option 125 (DHCPv4) or 17 (DHCPv6).

Definition at line 1222 of file token.h.

Referenced by evaluate(), isc::dhcp::TokenVendorClass::evaluate(), and getOption().

◆ vendor_id_

uint32_t isc::dhcp::TokenVendor::vendor_id_
protected

Enterprise-id value.

Yeah, I know it technically should be called enterprise-id, but that's too long and everyone calls it vendor-id.

Definition at line 1228 of file token.h.

Referenced by evaluate(), isc::dhcp::TokenVendorClass::evaluate(), and getVendorId().


The documentation for this class was generated from the following files: