diff options
author | Razvan Becheriu <razvan@isc.org> | 2021-03-12 20:57:36 +0100 |
---|---|---|
committer | Razvan Becheriu <razvan@isc.org> | 2021-05-05 19:12:17 +0200 |
commit | 263fcbaa3cc543eac495b20ea9f68a950275208c (patch) | |
tree | c0067cc30a9e04f01637aac7788bfe62c74398c7 /src/lib/eval/token.cc | |
parent | [#1680] consistent order of parameters in hook points (diff) | |
download | kea-263fcbaa3cc543eac495b20ea9f68a950275208c.tar.xz kea-263fcbaa3cc543eac495b20ea9f68a950275208c.zip |
[#1680] added addrtotext operator to eval parser
Diffstat (limited to 'src/lib/eval/token.cc')
-rw-r--r-- | src/lib/eval/token.cc | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/lib/eval/token.cc b/src/lib/eval/token.cc index ab42ac0dfe..cc131e57f1 100644 --- a/src/lib/eval/token.cc +++ b/src/lib/eval/token.cc @@ -103,6 +103,36 @@ TokenIpAddress::evaluate(Pkt& /*pkt*/, ValueStack& values) { .arg(toHex(value_)); } +void +TokenIpAddressToText::evaluate(Pkt& /*pkt*/, ValueStack& values) { + if (values.size() == 0) { + isc_throw(EvalBadStack, "Incorrect empty stack."); + } + + string op = values.top(); + values.pop(); + + uint8_t size = op.size(); + + if ((size != sizeof(uint32_t)) && (size != INET_ADDRSTRLEN)) { + isc_throw(EvalTypeError, "Can not convert to valid address."); + } + + std::vector<uint8_t> binary(op.begin(), op.end()); + + if (size == sizeof(uint32_t)) { + op = asiolink::IOAddress::fromBytes(AF_INET, binary.data()).toText(); + } else { + op = asiolink::IOAddress::fromBytes(AF_INET6, binary.data()).toText(); + } + + values.push(op); + + // Log what we pushed + LOG_DEBUG(eval_logger, EVAL_DBG_STACK, EVAL_DEBUG_IPADDRESSTOTEXT) + .arg(op); +} + OptionPtr TokenOption::getOption(Pkt& pkt) { return (pkt.getOption(option_code_)); |