39bool flex_id_apply_to_leases =
false;
41bool flex_id_ignore_iaid =
false;
57 }
catch (
const std::exception& ex) {
60 "expression: [" << expr <<
"] error: " << ex.what() );
65 const bool apply_to_leases,
66 const bool ignore_iaid) {
67 flex_id_apply_to_leases = apply_to_leases;
71 flex_id_ignore_iaid = ignore_iaid;
75 flex_id_apply_to_leases =
false;
77 flex_id_ignore_iaid =
false;
87template<
typename PacketType>
89 PacketType& pkt, std::vector<uint8_t>&
id) {
100 .arg(value).arg(value.size());
104 for (
const char& ch : value) {
105 repr << setw(2) << setfill('0') << static_cast<unsigned>(ch);
108 .arg(repr.str()).arg(value.size());
112 id.resize(value.size());
114 std::copy(value.begin(), value.end(),
id.begin());
148 if (flex_id_expr.empty()) {
156 std::vector<uint8_t> id;
189 if (!flex_id_apply_to_leases || flex_id_expr.empty()) {
201 std::vector<uint8_t> id;
210 handle.
setContext(
"client_identifier", client_id);
218 buf.insert(buf.end(),
id.begin(),
id.end());
220 pkt->addOption(new_client_id);
246 if (!flex_id_apply_to_leases) {
254 std::vector<uint8_t> id;
272 handle.
getContext(
"client_identifier", old_client_id);
284 response->addOption(old_client_id);
286 ClientId client_id(old_client_id->getData());
308 if (flex_id_expr.empty()) {
316 std::vector<uint8_t> id;
353 if (flex_id_ignore_iaid) {
354 uint32_t iana_count = 0;
355 uint32_t iapd_count = 0;
356 for (
auto const& opt : pkt->options_) {
357 switch (opt.second->getType()) {
370 if (iana_count > 1) {
374 if (iapd_count > 1) {
378 uint32_t iana_iaid = 0;
379 uint32_t iapd_iaid = 0;
380 if (iana_count == 1) {
381 for (
auto const& opt : pkt->options_) {
382 switch (opt.second->getType()) {
384 auto iana = boost::dynamic_pointer_cast<Option6IA>(opt.second);
385 iana_iaid = iana->getIAID();
396 if (iapd_count == 1) {
397 for (
auto const& opt : pkt->options_) {
398 switch (opt.second->getType()) {
400 auto iapd = boost::dynamic_pointer_cast<Option6IA>(opt.second);
401 iapd_iaid = iapd->getIAID();
414 if (!flex_id_apply_to_leases || flex_id_expr.empty()) {
422 std::vector<uint8_t> id;
441 buf.insert(buf.end(),
id.begin(),
id.end());
443 pkt->addOption(new_duid);
472 if (flex_id_ignore_iaid) {
473 uint32_t iana_count = 0;
474 uint32_t iapd_count = 0;
477 if (iana_count == 1) {
478 for (
auto const& opt : response->options_) {
479 switch (opt.second->getType()) {
481 auto iana = boost::dynamic_pointer_cast<Option6IA>(opt.second);
482 uint32_t iana_iaid = 0;
484 iana->setIAID(iana_iaid);
490 if (iapd_count == 1) {
491 for (
auto const& opt : response->options_) {
492 switch (opt.second->getType()) {
494 auto iapd = boost::dynamic_pointer_cast<Option6IA>(opt.second);
495 uint32_t iapd_iaid = 0;
497 iapd->setIAID(iapd_iaid);
507 if (!flex_id_apply_to_leases) {
515 std::vector<uint8_t> id;
540 response->addOption(old_duid);
542 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_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
#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.
bool isPrintable(const string &content)
Check if a string is printable.
Defines the logger used by the top-level component of kea-lfc.