#1092606 kea-dhcp4-server: When configured to use MySQL/MariaDB on localhost, uses hardcoded (wrong) socket location.

Package:
kea-dhcp4-server
Source:
kea-dhcp4-server
Description:
IPv4 DHCP server
Submitter:
Eric Towers
Date:
2025-01-09 17:24:02 UTC
Severity:
normal
#1092606#5
Date:
2025-01-09 17:21:57 UTC
From:
To:
Dear Maintainer,

The DHCP4 server is configured to use MySQL (actually MariaDB) on
localhost for the lease database.  When starting the kea-dhcp4-server unit, the following error is produced:
    INFO  DHCPSRV_MYSQL_DB opening MySQL lease database: name=kea_dhcp password=***** port=3306 type=mysql universe=4 user=kea_dhcp_user
    ERROR [...] DHCP4_CONFIG_LOAD_FAIL configuration error using file: /etc/kea/kea-dhcp4.conf,
    reason: Unable to open database: Can't connect to local server through socket '/run/mysqld/mysqld.sock'

First, when configured to use a network database, why is this trying to
use the socket?

Second, if it is trying to use the socket, why is it not
parsing /etc/mysql/my.cnf to find
    socket = /mnt/tera/mariadb/mysqld.sock
?  (The socket file has been moved to reside with the database files on
the RAID array.)

Third, I don't see that I can configure Kea to the location of the socket file.

Comment:  It might be a good idea to add to the comment block in the default
kea-dhcp4.conf about adding a dependency to the kea-dhcp-server unit on the
mysql (or mariadb) unit to avoid a boot race condition.

Comment:  While the Department of Redundancy Department appreciates that
every config file in /etc/kea starts with "kea", this is redundant; the
leading "kea-" could be removed, improving typeability and readability
in this directory.

Comment:  The Kea config files appear to be JSON.  Vim would highlight
these files correctly (especially useful, given the levels of nesting)
if they had the JSON extension.  I note, however, Vim *hates* // comments
in JSON files...

Verifying that maridb is listening:
    netstat -tlnp

    Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
    tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      1256/mariadbd
    [...]

Alternate representations of localhost:
We change the "Dhcp4": "lease-database": "host" line in kea-dhcp4.conf to
    "host": "",
which is a Kea configuration idiomatic alias for localhost.  No change.

Workaround:
We change the "Dhcp4": "lease-database": "host" line in kea-dhcp4.conf to
    "host": "127.0.0.1",
and this works.

What should be happening:
    * Least: When the "lease-database" "host" is set to "" or "localhost",
      kea-dhcp4-server actually finds the database server running locally,
      the same way it finds that server when "host" is set to "127.0.0.1".
    * Better: In /etc/kea/kea-dhcp4.conf, I could set the "socket-type" and
      "socket" for the MySQL/MariaDB socket file, so I wouldn't have to use
      the network socket.
    * Best: Kea would parse the /etc/mysql/my.cfg for the socket location
      when the "lease-database" is "mysql" and the "host" is "localhost" or
      "".