Kea: isc::dhcp::TokenVendor Class Reference

| Kea 2.2.0

Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
isc::dhcp::TokenVendor Class Reference

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

`#include <token.h>`

Inheritance diagram for isc::dhcp::TokenVendor:
[legend]

## Public Types
enum | FieldType { 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. More...
| TokenVendor (Option::Universe u, uint32_t vendor_id, RepresentationType repr, uint16_t option_code=0)
| Constructor used for accessing an option. More...
virtual void | evaluate (Pkt &pkt, ValueStack &values)
| This is a method for evaluating a packet. More...
FieldType | getField () const
| Returns field. More...
uint32_t | getVendorId () const
| Returns enterprise-id. More...
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. More...
void | evaluate (Pkt &pkt, ValueStack &values)
| Evaluates the values of the option. More...
uint16_t | getCode () const
| Returns option-code. More...
RepresentationType | getRepresentation () const
| Returns representation-type. More...
Public Member Functions inherited from isc::dhcp::Token
virtual | ~Token ()
| Virtual destructor. More...
virtual void | evaluate (Pkt &pkt, ValueStack &values)=0
| This is a generic method for evaluating a packet. More...

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

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

## 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. More...

## 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 1059 of file token.h.

## Member Enumeration Documentation

## ◆ FieldType

enum isc::dhcp::TokenVendor::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 1063 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

  u | universe (either V4 or V6)
  vendor_id | specifies enterprise-id (0 means any)
  field | specifies which field should be returned

Definition at line 1050 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

  u | universe (either V4 or V6)
  vendor_id | specifies enterprise-id (0 means any)
  repr | representation type (hex or exists)
  option_code | sub-option code

Definition at line 1044 of file token.cc.

## Member Function Documentation

## ◆ evaluate()

void 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

  EvalTypeError | for 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.

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 1066 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::dhcp::Pkt::getOption(), 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 1062 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

  pkt | vendor option will be searched here.

Returns
  suboption of the vendor option (if exists)

Reimplemented from isc::dhcp::TokenOption.

Definition at line 1134 of file token.cc.

References D6O_VENDOR_OPTS, isc::dhcp::DHO_VIVSO_SUBOPTIONS, isc::dhcp::Pkt::getOption(), isc::dhcp::TokenOption::option_code_, universe_, isc::dhcp::Option::V4, and isc::dhcp::Option::V6.

Here is the call graph for this function:

## ◆ getVendorId()

uint32_t TokenVendor::getVendorId | ( |  | ) | const

Returns enterprise-id.

Used in tests only.

Returns
  enterprise-id

Definition at line 1058 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 1154 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 1145 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 1151 of file token.h.

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

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

- token.h
- token.cc