Unable to retrieve multiple host reservations for the same IP with reservation-get
Attempting to retrieve multiple host reservations for the same IP address with reservation-get
fails with this error:
{
"result": 1,
"text": "multiple records were found in the database where only one was expected for query SELECT h.host_id, h.dhcp_identifier, h.dhcp_identifier_type, h.dhcp4_subnet_id, h.dhcp6_subnet_id, h.ipv4_address, h.hostname, h.dhcp4_client_classes, h.dhcp6_client_classes, h.user_context, h.dhcp4_next_server, h.dhcp4_server_hostname, h.dhcp4_boot_file_name, h.auth_key, o.option_id, o.code, o.value, o.formatted_value, o.space, o.persistent, o.user_context FROM hosts AS h LEFT JOIN dhcp4_options AS o ON h.host_id = o.host_id WHERE h.dhcp4_subnet_id = ? AND h.ipv4_address = ? ORDER BY h.host_id, o.option_id"
}
To recreate, Consider this simple Kea configuration
{
"Dhcp4": {
"ip-reservations-unique": false,
"control-socket": {
"socket-type": "unix",
"socket-name": "/tmp/kea4-ctrl-socket"
},
"hosts-database": {
"type": "mysql",
"name": "kea",
"user": "kea",
"password": "kea",
},
"reservations-global": false,
"reservations-in-subnet": false,
"hooks-libraries": [
{
"library": "/usr/local/kea/2.3.5/lib/kea/hooks/libdhcp_host_cmds.so"
}
],
"subnet4": [
{
"subnet": "192.0.2.0/24",
"id": 1
}
]
}
}
Using the reservation-add
API call from the host_cmds hook you can add multiple reservations for the same IP address if "ip-reservations-unique": false,
is set in the Kea configuration:
{"command": "reservation-add","arguments": {"reservation": {"subnet-id": 1,"hw-address": "99:99:99:99:99:01","ip-address": "192.0.2.181"}}}
{"command": "reservation-add","arguments": {"reservation": {"subnet-id": 1,"circuit-id": "'1234'","ip-address": "192.0.2.181"}}}
Then try to retrieve the hosts using the reservation-get
API call from the host_cmds hook:
{"command": "reservation-get","arguments": {"ip-address": "192.0.2.181","subnet-id": 1},"service": ["dhcp4"]}
which will result in the aforementioned error.
It should be noted that there are other calls that are able to retrieve the reservations such as reservation-get-by-id
and reservation-get-page
.