flexible option hook is calculating v6 domain names length incorrectly
Test case is very simple, configuration as follows:
{
"Dhcp6": {
"hooks-libraries": [
{
"library": "/home/wlodek/installed/git-thread/lib/kea/hooks/libdhcp_flex_option.so",
"parameters": {
"options": [
{
"code": 30,
"supersede": "ifelse(relay6[0].peeraddr == 3000::1005, 'ntp.example.com','')"
}
]
}
}
],
"interfaces-config": {
"interfaces": [
"enp0s9"
]
},
"lease-database": {
"type": "memfile"
},
"loggers": [
{
"debuglevel": 99,
"name": "kea-dhcp6",
"output_options": [
{
"output": "/home/wlodek/installed/git-thread/var/log/kea.log"
}
],
"severity": "DEBUG"
}
],
"multi-threading": {
"enable-multi-threading": true,
"packet-queue-size": 16,
"thread-pool-size": 2
},
"option-data": [
{
"code": 30,
"csv-format": true,
"data": "ntp.example.com",
"name": "nisp-domain-name",
"space": "dhcp6"
}
],
"preferred-lifetime": 3000,
"rebind-timer": 2000,
"renew-timer": 1000,
"shared-networks": [],
"subnet6": [
{
"interface": "enp0s9",
"pools": [
{
"pool": "2001:db8:1::1-2001:db8:1::1"
}
],
"subnet": "2001:db8:1::/64"
}
],
"valid-lifetime": 4000
}
}
We have configured option "nisp-domain-name" at global level and in flexible option, with the same value!
And I'm sending two advertise (inside Relay Forward), one message has peeraddr == 3000::1005 other don't. Kea is configured in a way that those two reply messages should be identical, but one of those will have "nisp-domain-name" option added by Kea core, other will have "nisp-domain-name" added by hook.
Result is that hook is adding option with incorrect length calculated. Used forge to find it. attaching capture from test.
logs looks correct
2020-08-06 01:03:46.128 DEBUG [kea-dhcp6.callouts/29307.140183868143360] HOOKS_CALLOUTS_BEGIN begin all callouts for hook pkt6_send
2020-08-06 01:03:46.129 DEBUG [kea-dhcp6.eval/29307.140183868143360] EVAL_DEBUG_RELAY6 Pushing PKT6 relay field peeraddr nest 0 with value 0x30000000000000000000000000001005
2020-08-06 01:03:46.129 DEBUG [kea-dhcp6.eval/29307.140183868143360] EVAL_DEBUG_IPADDRESS Pushing IPAddress 0x30000000000000000000000000001005
2020-08-06 01:03:46.129 DEBUG [kea-dhcp6.eval/29307.140183868143360] EVAL_DEBUG_EQUAL Popping 0x30000000000000000000000000001005 and 0x30000000000000000000000000001005 pushing result 'true'
2020-08-06 01:03:46.129 DEBUG [kea-dhcp6.eval/29307.140183868143360] EVAL_DEBUG_STRING Pushing text string 'ntp.example.com'
2020-08-06 01:03:46.129 DEBUG [kea-dhcp6.eval/29307.140183868143360] EVAL_DEBUG_STRING Pushing text string ''
2020-08-06 01:03:46.129 DEBUG [kea-dhcp6.eval/29307.140183868143360] EVAL_DEBUG_IFELSE_TRUE Popping 'true' (true) and 0x, leaving 0x6E74702E6578616D706C652E636F6D
2020-08-06 01:03:46.130 DEBUG [kea-dhcp6.flex-option-hooks/29307.140183868143360] FLEX_OPTION_PROCESS_SUPERSEDE Supersedes the value of option code 30 by 'ntp.example.com'
2020-08-06 01:03:46.130 DEBUG [kea-dhcp6.callouts/29307.140183868143360] HOOKS_CALLOUT_CALLED hooks library with index 1 has called a callout on hook pkt6_send that has address 0x7f7f1b41ff30 (callout duration: 1.504 ms)