40bool flex_id_apply_to_leases =
false;
42bool flex_id_ignore_iaid =
false;
58 }
catch (
const std::exception& ex) {
61 "expression: [" << expr <<
"] error: " << ex.what() );
66 const bool apply_to_leases,
67 const bool ignore_iaid) {
68 flex_id_apply_to_leases = apply_to_leases;
72 flex_id_ignore_iaid = ignore_iaid;
76 flex_id_apply_to_leases =
false;
78 flex_id_ignore_iaid =
false;
88template<
typename PacketType>
90 PacketType& pkt, std::vector<uint8_t>&
id) {
101 .arg(value).arg(value.size());
104 .arg(
dumpAsHex(value)).arg(value.size());
108 id.resize(value.size());
110 std::copy(value.begin(), value.end(),
id.begin());
144 if (flex_id_expr.empty()) {
152 std::vector<uint8_t> id;
185 if (!flex_id_apply_to_leases || flex_id_expr.empty()) {
197 std::vector<uint8_t> id;
206 handle.
setContext(
"client_identifier", client_id);
214 buf.insert(buf.end(),
id.begin(),
id.end());
216 pkt->addOption(new_client_id);
242 if (!flex_id_apply_to_leases) {
250 std::vector<uint8_t> id;
268 handle.
getContext(
"client_identifier", old_client_id);
280 response->addOption(old_client_id);
282 ClientId client_id(old_client_id->getData());
304 if (flex_id_expr.empty()) {
312 std::vector<uint8_t> id;
349 if (flex_id_ignore_iaid) {
350 uint32_t iana_count = 0;
351 uint32_t iapd_count = 0;
352 for (
auto const& opt : pkt->options_) {
353 switch (opt.second->getType()) {
366 if (iana_count > 1) {
370 if (iapd_count > 1) {
374 uint32_t iana_iaid = 0;
375 uint32_t iapd_iaid = 0;
376 if (iana_count == 1) {
377 for (
auto const& opt : pkt->options_) {
378 switch (opt.second->getType()) {
380 auto iana = boost::dynamic_pointer_cast<Option6IA>(opt.second);
381 iana_iaid = iana->getIAID();
392 if (iapd_count == 1) {
393 for (
auto const& opt : pkt->options_) {
394 switch (opt.second->getType()) {
396 auto iapd = boost::dynamic_pointer_cast<Option6IA>(opt.second);
397 iapd_iaid = iapd->getIAID();
410 if (!flex_id_apply_to_leases || flex_id_expr.empty()) {
418 std::vector<uint8_t> id;
437 buf.insert(buf.end(),
id.begin(),
id.end());
439 pkt->addOption(new_duid);
468 if (flex_id_ignore_iaid) {
469 uint32_t iana_count = 0;
470 uint32_t iapd_count = 0;
473 if (iana_count == 1) {
474 for (
auto const& opt : response->options_) {
475 switch (opt.second->getType()) {
477 auto iana = boost::dynamic_pointer_cast<Option6IA>(opt.second);
478 uint32_t iana_iaid = 0;
480 iana->setIAID(iana_iaid);
486 if (iapd_count == 1) {
487 for (
auto const& opt : response->options_) {
488 switch (opt.second->getType()) {
490 auto iapd = boost::dynamic_pointer_cast<Option6IA>(opt.second);
491 uint32_t iapd_iaid = 0;
493 iapd->setIAID(iapd_iaid);
503 if (!flex_id_apply_to_leases) {
511 std::vector<uint8_t> id;
536 response->addOption(old_duid);
538 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 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.
void storeConfiguration(bool v6, const std::string &expr, const bool apply_to_leases, const bool ignore_iaid)
Stores expression.
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.