40bool flex_id_apply_to_leases =
false;
42bool flex_id_ignore_iaid =
false;
43bool flex_id_cid_as_rfc4361_duid =
false;
59 }
catch (
const std::exception& ex) {
62 "expression: [" << expr <<
"] error: " << ex.what() );
67 const bool apply_to_leases,
68 const bool ignore_iaid,
69 const bool cid_as_rfc4361_duid ) {
71 flex_id_apply_to_leases = apply_to_leases;
75 flex_id_ignore_iaid = ignore_iaid;
76 flex_id_cid_as_rfc4361_duid = cid_as_rfc4361_duid;
80 flex_id_apply_to_leases =
false;
82 flex_id_ignore_iaid =
false;
83 flex_id_cid_as_rfc4361_duid =
false;
93template<
typename PacketType>
95 PacketType& pkt, std::vector<uint8_t>&
id) {
106 .arg(value).arg(value.size());
109 .arg(
dumpAsHex(value)).arg(value.size());
113 id.resize(value.size());
115 std::copy(value.begin(), value.end(),
id.begin());
149 if (flex_id_expr.empty()) {
157 std::vector<uint8_t> id;
190 if (!flex_id_apply_to_leases || flex_id_expr.empty()) {
202 std::vector<uint8_t> id;
211 handle.
setContext(
"client_identifier", client_id);
216 if (flex_id_cid_as_rfc4361_duid) {
218 buf.assign({ 0xFF, 0, 0, 0, 0 });
225 buf.insert(buf.end(),
id.begin(),
id.end());
227 pkt->addOption(new_client_id);
253 if (!flex_id_apply_to_leases) {
261 std::vector<uint8_t> id;
279 handle.
getContext(
"client_identifier", old_client_id);
291 response->addOption(old_client_id);
293 ClientId client_id(old_client_id->getData());
315 if (flex_id_expr.empty()) {
323 std::vector<uint8_t> id;
360 if (flex_id_ignore_iaid) {
361 uint32_t iana_count = 0;
362 uint32_t iapd_count = 0;
363 for (
auto const& opt : pkt->options_) {
364 switch (opt.second->getType()) {
377 if (iana_count > 1) {
381 if (iapd_count > 1) {
385 uint32_t iana_iaid = 0;
386 uint32_t iapd_iaid = 0;
387 if (iana_count == 1) {
388 for (
auto const& opt : pkt->options_) {
389 switch (opt.second->getType()) {
391 auto iana = boost::dynamic_pointer_cast<Option6IA>(opt.second);
392 iana_iaid = iana->getIAID();
403 if (iapd_count == 1) {
404 for (
auto const& opt : pkt->options_) {
405 switch (opt.second->getType()) {
407 auto iapd = boost::dynamic_pointer_cast<Option6IA>(opt.second);
408 iapd_iaid = iapd->getIAID();
421 if (!flex_id_apply_to_leases || flex_id_expr.empty()) {
429 std::vector<uint8_t> id;
448 buf.insert(buf.end(),
id.begin(),
id.end());
450 pkt->addOption(new_duid);
479 if (flex_id_ignore_iaid) {
480 uint32_t iana_count = 0;
481 uint32_t iapd_count = 0;
484 if (iana_count == 1) {
485 for (
auto const& opt : response->options_) {
486 switch (opt.second->getType()) {
488 auto iana = boost::dynamic_pointer_cast<Option6IA>(opt.second);
489 uint32_t iana_iaid = 0;
491 iana->setIAID(iana_iaid);
497 if (iapd_count == 1) {
498 for (
auto const& opt : response->options_) {
499 switch (opt.second->getType()) {
501 auto iapd = boost::dynamic_pointer_cast<Option6IA>(opt.second);
502 uint32_t iapd_iaid = 0;
504 iapd->setIAID(iapd_iaid);
514 if (!flex_id_apply_to_leases) {
522 std::vector<uint8_t> id;
547 response->addOption(old_duid);
549 DUID duid(old_duid->getData());
int host4_identifier(CalloutHandle &handle)
This callout is called at the "host4_identifier" hook.
int pkt6_send(CalloutHandle &handle)
This callout is called at "pkt6_send" hook point.
int pkt4_send(CalloutHandle &handle)
This callout is called at "pkt4_send" hook point.
int pkt4_receive(CalloutHandle &handle)
This callout is called at "pkt4_receive" hook point.
int pkt6_receive(CalloutHandle &handle)
This callout is called at "pkt6_receive" hook point.
int host6_identifier(CalloutHandle &handle)
This callout is called at the "host6_identifier" hook.
CalloutNextStep
Specifies allowed next steps.
@ NEXT_STEP_DROP
drop the packet
@ NEXT_STEP_SKIP
skip the next processing step
A generic exception that is thrown if a function is called in a prohibited way.
A generic exception that is thrown when an unexpected error condition occurs.
Holds Client identifier or client IPv4 address.
Holds DUID (DHCPv6 Unique Identifier).
IdentifierType
Type of the host identifier.
@ IDENT_FLEX
Flexible host identifier.
std::string toText() const
Returns textual representation of the identifier (e.g.
Evaluation context, an interface to the expression evaluation.
bool parseString(const std::string &str, ParserType type=PARSER_BOOL)
Run the parser on the string specified.
@ PARSER_STRING
expression is expected to evaluate to string
isc::dhcp::Expression expression_
Parsed expression (output tokens are stored here).
Per-packet callout handle.
void getContext(const std::string &name, T &value) const
Get context.
void setContext(const std::string &name, T value)
Set context.
CalloutNextStep getStatus() const
Returns the next processing step.
void getArgument(const std::string &name, T &value) const
Get argument.
void setArgument(const std::string &name, T value)
Set argument.
No such callout context item.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
const isc::log::MessageID FLEX_ID_IGNORE_IAID_NOT_APPLIED_ON_PD
const isc::log::MessageID FLEX_ID_IGNORE_IAID_NOT_APPLIED_ON_NA
const isc::log::MessageID FLEX_ID_IGNORE_IAID_APPLIED_ON_PD
const isc::log::MessageID FLEX_ID_EXPRESSION_HEX
const isc::log::MessageID FLEX_ID_RESTORE_CLIENT_ID
const isc::log::MessageID FLEX_ID_EXPRESSION_EVALUATED
const isc::log::MessageID FLEX_ID_RESTORE_DUID
const isc::log::MessageID FLEX_ID_IGNORE_IAID_APPLIED_ON_NA
const isc::log::MessageID FLEX_ID_USED_AS_CLIENT_ID
const isc::log::MessageID FLEX_ID_EXPRESSION_EVALUATED_NP
const isc::log::MessageID FLEX_ID_USED_AS_DUID
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
@ DHO_DHCP_CLIENT_IDENTIFIER
boost::shared_ptr< Pkt4 > Pkt4Ptr
A pointer to Pkt4 object.
std::string evaluateString(const Expression &expr, Pkt &pkt)
Evaluate a RPN expression for a v4 or v6 packet and return a string value.
boost::shared_ptr< Pkt6 > Pkt6Ptr
A pointer to Pkt6 packet.
std::vector< uint8_t > OptionBuffer
buffer types used in DHCP code.
std::vector< TokenPtr > Expression
This is a structure that holds an expression converted to RPN.
boost::shared_ptr< Option > OptionPtr
void storeConfiguration(bool v6, const std::string &expr, const bool apply_to_leases, const bool ignore_iaid, const bool cid_as_rfc4361_duid)
Stores expression.
void retrieveFlexId(CalloutHandle &callout_handle, const Expression &expression, PacketType &pkt, std::vector< uint8_t > &id)
Retrieves flexible identifier from the context or computes it.
isc::log::Logger flex_id_logger("flex-id-hooks")
Flexible Identifier Logger.
void clearConfiguration()
Clears stored configuration.
void parseAndStoreExpression(bool v6, const std::string &expr)
Parses expression provided as text.
const int DBGLVL_TRACE_BASIC
Trace basic operations.
string dumpAsHex(const uint8_t *data, size_t length)
Dumps a buffer of bytes as a string of hexadecimal digits.
bool isPrintable(const string &content)
Check if a string is printable.
Defines the logger used by the top-level component of kea-lfc.