host_cmds does not log deletes (double logs adds)
While testing the host_cmds premium hook, it was discovered that only "adds" are logged (and they are logged twice). Even at debug level 99. "deletes" are not logged. This simple DHCP configuration:
{
"Dhcp4": {
"interfaces-config": {
"interfaces": [ "ens256" ]
},
"control-socket":
{
"socket-type": "unix",
"socket-name": "/tmp/kea/kea4-ctrl-socket"
},
"hosts-database":
{
"type": "mysql",
"name": "kea",
"user": "kea",
"password": "kea",
"host": "127.0.0.1"
},
"hooks-libraries": [
{
"library": "/usr/local/kea/2.3.5/lib/kea/hooks/libdhcp_host_cmds.so"
}
],
"valid-lifetime": 300,
"subnet4":
[
{
"subnet": "10.1.2.0/24",
"id": 1,
"option-data": [
{
"code": 54,
"data": "10.1.2.253"
}
]
}
],
"loggers":
[
{
"name": "kea-dhcp4.host-cmds-hooks",
"output_options": [
{
"output": "/tmp/kea/dhcp4-host-cmds-hooks.log",
"maxver": 1
}
],
"severity": "INFO",
"debuglevel": 0
}
]
}
}
is enough to reproduce the issue. Run the add command:sudo su - -c "echo '{\"command\": \"reservation-add\",\"arguments\": {\"reservation\": {\"subnet-id\": 1,\"hw-address\": \"aa:aa:aa:aa:aa:aa\",\"ip-address\": \"10.1.2.100\"}},\"service\": [ \"dhcp4\" ]}' | socat UNIX:/tmp/kea/kea4-ctrl-socket -,ignoreeof | jq ."
. Confirm the host has been added to the database and then run the delete command: sudo su - -c "echo '{\"command\": \"reservation-del\",\"arguments\": {\"subnet-id\": 1,\"ip-address\": \"10.1.2.100\"},\"service\": [ \"dhcp4\" ]}' | socat UNIX:/tmp/kea/kea4-ctrl-socket -,ignoreeof | jq ."
and confirm that the host has been removed from the database. Then check the logs:
2023-03-07 22:11:02.515 INFO [kea-dhcp4.host-cmds-hooks/74090.281473025732624] HOST_CMDS_RESERV_ADD reservation-add command successful (parameters: { "reservation": { "hw-address": "aa:aa:aa:aa:aa:aa", "ip-address": "10.1.2.100", "subnet-id": 1 } })
2023-03-07 22:11:02.516 INFO [kea-dhcp4.host-cmds-hooks/74090.281473025732624] HOST_CMDS_RESERV_ADD reservation-add command successful (parameters: { "reservation": { "hw-address": "aa:aa:aa:aa:aa:aa", "ip-address": "10.1.2.100", "subnet-id": 1 } })
where you will find only two "HOST_CMDS_RESERV_ADD" lines from nearly the exact same moment in time. Nothing is logged at the time of the delete.