"config-test" API command rejects existing interfaces
Describe the bug
The config-test
Management API command rejects configs which reference interfaces that were only created after kea was started. The command fails with an error message like Failed to select interface: interface 'testintf' doesn't exist in the system
even though the given interface does exist in the system.
To Reproduce
Steps to reproduce, using a dummy interface testintf
that is only created after starting kea:
# ip link show testintf
Device "testintf" does not exist.
# kea-dhcp4 -c <(echo '{"Dhcp4": {"control-socket": {"socket-type": "unix", "socket-name": "/tmp/kea4-ctrl-socket"}}}') &
[1] 38770
2024-05-02 10:59:34.045 INFO [kea-dhcp4.dhcp4/38770.139662307609600] DHCP4_STARTING Kea DHCPv4 server version 2.4.1-git (stable) starting
[...]
2024-05-02 10:59:34.049 INFO [kea-dhcp4.dhcp4/38770.139662307609600] DHCP4_STARTED Kea DHCPv4 server version 2.4.1-git started
# ip link add testintf type dummy && ip link set testintf up
# ip link show testintf
15: testintf: <BROADCAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
link/ether b2:62:e0:9d:82:33 brd ff:ff:ff:ff:ff:ff
# echo '{ "command": "config-test", "arguments": {"Dhcp4": {"interfaces-config": {"interfaces": [ "testintf" ]}, "control-socket": {"socket-type": "unix", "socket-name": "/tmp/kea4-ctrl-socket"}}}}' | socat UNIX:/tmp/kea4-ctrl-socket -
2024-05-02 11:00:11.734 INFO [kea-dhcp4.commands/38770.139662307609600] COMMAND_RECEIVED Received command 'config-test'
2024-05-02 11:00:11.736 INFO [kea-dhcp4.hosts/38770.139662307609600] HOSTS_BACKENDS_REGISTERED the following host backend types are available:
2024-05-02 11:00:11.736 WARN [kea-dhcp4.dhcpsrv/38770.139662307609600] DHCPSRV_MT_DISABLED_QUEUE_CONTROL disabling dhcp queue control when multi-threading is enabled.
2024-05-02 11:00:11.736 WARN [kea-dhcp4.dhcp4/38770.139662307609600] DHCP4_RESERVATIONS_LOOKUP_FIRST_ENABLED Multi-threading is enabled and host reservations lookup is always performed first.
2024-05-02 11:00:11.736 INFO [kea-dhcp4.dhcpsrv/38770.139662307609600] DHCPSRV_CFGMGR_SOCKET_TYPE_SELECT using socket type raw
2024-05-02 11:00:11.736 ERROR [kea-dhcp4.dhcp4/38770.139662307609600] DHCP4_PARSER_FAIL failed to create or run parser for configuration element interfaces-config: Failed to select interface: interface 'testintf' doesn't exist in the system (<wire>:0:90) (<wire>:0:89)
{ "result": 1, "text": "Failed to select interface: interface 'testintf' doesn't exist in the system (<wire>:0:90) (<wire>:0:89)" }
Expected behavior
I expected the config-test
command to accept the configuration because the given interface does exist in the system and the config is valid.
Environment:
- Kea version: 2.4.1
- OS: Fedora 39 x86_64
- Which features were compiled in:
--with-libyang --with-libyang-cpp --with-sysrepo --with-sysrepo-cpp
- No hooks loaded
Additional Information
Note that the server is used in a environment where config-set
API commands are used to reconfigure the server at runtime. Before re-configuring the server, the config is validated using config-test
, which fails right-now for dynamically created interfaces.
For testing purposes I applied the following patch which seems to resolve the problem:
diff --git a/src/lib/dhcpsrv/parsers/ifaces_config_parser.cc b/src/lib/dhcpsrv/parsers/ifaces_config_parser.cc
index c375b403c2..a1e5ac8442 100644
--- a/src/lib/dhcpsrv/parsers/ifaces_config_parser.cc
+++ b/src/lib/dhcpsrv/parsers/ifaces_config_parser.cc
@@ -44,9 +44,13 @@ IfacesConfigParser::parse(const CfgIfacePtr& cfg,
// Check for re-detect before calling parseInterfacesList()
bool re_detect = getBoolean(ifaces_config, "re-detect");
cfg->setReDetect(re_detect);
- if (re_detect && !test_mode_) {
- IfaceMgr::instance().clearIfaces();
- IfaceMgr::instance().detectIfaces();
+ if (re_detect) {
+ if (test_mode_) {
+ IfaceMgr::instance().detectIfaces(true);
+ } else {
+ IfaceMgr::instance().clearIfaces();
+ IfaceMgr::instance().detectIfaces();
+ }
}
bool socket_type_specified = false;