[Kea-users] Unable to re-allocate address

Razvan Becheriu razvan at isc.org
Thu Jul 8 14:02:20 UTC 2021


We need to compute the timestamp in Kea so stat we don't need to do multiple selects.
Imagine the scenario:

1. get data from database (including timestamp)
2. if no lease, generate a timestamp and do insert
3. if any further update is necessary, we use the in RAM timestamp to make sure the row is updated only once (in case of multiple processes trying to update the same row - using multiple kea servers sharing the same configuration - multi process). this is the reason why we use 'update ... where timestamp = [X]' in all queries.

If we would generate the timestamp in the database, after performing step 2. we would need an extra step to receive the updated row (to update in RAM timestamp) so that we can use it to do the next update.

Razvan

----- Original Message -----
From: "perl-list" <perl-list at network1.net>
To: "Marcin Siodelski" <marcin at isc.org>
Cc: "Razvan Becheriu" <razvan at isc.org>, "Jeronimo" <jscmenezes at gmail.com>, "kea-users" <Kea-users at lists.isc.org>
Sent: Thursday, July 8, 2021 4:42:32 PM
Subject: Re: [Kea-users] Unable to re-allocate address

What I don't understand is why you didn't just use a straight UTC timestamp in an int or bigint field.  You can add said timestamp right in your sql query as unix_timestamp(now()) which will produce an EPOCH time in the column.  If you need to see it as an actual date/time for some reason, you would then do a from_unixtime(<field>) during your select.  It will show the result in the timezone of the database server.  You can just keep it as an EPOCH all the time unless you need to display it to a user for some reason.  Then you would have no issue with timezone settings and only need to worry about clocks being properly in sync.  Database queries might actually be faster as long as they are all done in EPOCH.

Example:

MariaDB [DB]> select unix_timestamp(now());
+-----------------------+
| unix_timestamp(now()) |
+-----------------------+
|            1625751561 |
+-----------------------+
1 row in set (0.000 sec)

MariaDB [DB]> select from_unixtime(unix_timestamp(now()));
+--------------------------------------+
| from_unixtime(unix_timestamp(now())) |
+--------------------------------------+
| 2021-07-08 09:39:33                  |
+--------------------------------------+
1 row in set (0.000 sec)

MariaDB [DB]> 
  

----- Original Message -----
> From: "Marcin Siodelski" <marcin at isc.org>
> To: "Razvan Becheriu" <razvan at isc.org>, "Jeronimo" <jscmenezes at gmail.com>
> Cc: "kea-users" <Kea-users at lists.isc.org>
> Sent: Thursday, July 8, 2021 7:32:08 AM
> Subject: Re: [Kea-users] Unable to re-allocate address

> Razvan,

> It is correct that the timezone used by Postgres and the timezone used
> by Kea must match, but they don't necessarily have to be UTC.

> Kea creates a timestamp using time() function. The output is in UTC.
> Then the Postgres backend converts it to local time using localtime_r()
> (that's where Kea timezone is used). This value is passed to Postgres,
> and the database uses its (Postgres) timezone setting to convert it back
> to UTC. It is stored in the database internally in UTC. When it is
> fetched, there are no conversions because we use extract(epoch from
> timestamp)::bigint, which returns epoch time in UTC. That's the time
> value that we first created using time() function. You can have any
> timezone set for Kea and Postgres, but they have to match. A special
> case of it would be UTC.

> Overall, I think we need a paragraph in Kea ARM to explain that. We can
> also consider adding some timezone checks when Kea first connects to the
> database.

> Marcin

> On 07.07.2021 20:36, Razvan Becheriu wrote:
> > Hi,

> > Can you check that your system/kea and the database back-end use the
> > same timezone?
> > The timezones should match and should be set to UTC.

> > Thank you,
> > Razvan

> > ------------------------------------------------------------------------
> > *From: *"Jeronimo" <jscmenezes at gmail.com>
> > *To: *"Gordon Ross" <gr306 at cam.ac.uk>
> > *Cc: *Kea-users at lists.isc.org
> > *Sent: *Wednesday, July 7, 2021 8:11:49 PM
> > *Subject: *Re: [Kea-users] Unable to re-allocate address

> > Follow my configuration:

> > kea-dhcp4.conf:

> > {
> > "Dhcp4": {
> > "authoritative": false,
> > "boot-file-name": "",
> > "calculate-tee-times": false,
> > "control-socket": {
> > "socket-name": "/tmp/kea4-ctrl-socket",
> > "socket-type": "unix"
> > },
> > "ddns-generated-prefix": "myhost",
> > "ddns-override-client-update": false,
> > "ddns-override-no-update": false,
> > "ddns-qualifying-suffix": "",
> > "ddns-replace-client-name": "never",
> > "ddns-send-updates": true,
> > "decline-probation-period": 86400,
> > "dhcp-ddns": {
> > "enable-updates": false,
> > "max-queue-size": 1024,
> > "ncr-format": "JSON",
> > "ncr-protocol": "UDP",
> > "sender-ip": "0.0.0.0",
> > "sender-port": 0,
> > "server-ip": "127.0.0.1",
> > "server-port": 53001
> > },
> > "dhcp-queue-control": {
> > "capacity": 64,
> > "enable-queue": false,
> > "queue-type": "kea-ring4"
> > },
> > "dhcp4o6-port": 0,
> > "echo-client-id": true,
> > "expired-leases-processing": {
> > "flush-reclaimed-timer-wait-time": 25,
> > "hold-reclaimed-time": 3600,
> > "max-reclaim-leases": 100,
> > "max-reclaim-time": 250,
> > "reclaim-timer-wait-time": 10,
> > "unwarned-reclaim-cycles": 5
> > },
> > "hooks-libraries": [ ],
> > "host-reservation-identifiers": [ "hw-address", "duid",
> > "circuit-id", "client-id" ],
> > "hostname-char-replacement": "",
> > "hostname-char-set": "[^A-Za-z0-9.-]",
> > "interfaces-config": {
> > "interfaces": [ "ens3" ],
> > "re-detect": true
> > },
> > "lease-database": {
> > "host": "dbhost.localdomin",
> > "name": "dbname",
> > "password": "secret",
> > "port": 5432,
> > "type": "postgresql",
> > "user": "dbuser"
> > },
> > "loggers": [
> > {
> > "debuglevel": 99,
> > "name": "kea-dhcp4",
> > "output_options": [
> > {
> > "output": "/usr/local/var/log/kea-dhcp4.log"
> > }
> > ],
> > "severity": "INFO"
> > }
> > ],
> > "match-client-id": true,
> > "multi-threading": {
> > "enable-multi-threading": false,
> > "packet-queue-size": 64,
> > "thread-pool-size": 0
> > },
> > "next-server": "0.0.0.0",
> > "option-data": [ ],
> > "option-def": [ ],
> > "rebind-timer": 2000,
> > "renew-timer": 1000,
> > "reservation-mode": "all",
> > "sanity-checks": {
> > "lease-checks": "warn"
> > },
> > "server-hostname": "",
> > "server-tag": "",
> > "shared-networks": [ ],
> > "statistic-default-sample-age": 0,
> > "statistic-default-sample-count": 20,
> > "store-extended-info": false,
> > "subnet4": [
> > {
> > "4o6-interface": "",
> > "4o6-interface-id": "",
> > "4o6-subnet": "",
> > "calculate-tee-times": false,
> > "id": 1,
> > "option-data": [ ],
> > "pools": [
> > {
> > "option-data": [ ],
> > "pool": "192.168.0.10-192.168.0.13"
> > }
> > ],
> > "rebind-timer": 2000,
> > "relay": {
> > "ip-addresses": [ ]
> > },
> > "renew-timer": 1000,
> > "reservations": [
> > {
> > "boot-file-name": "",
> > "client-classes": [ ],
> > "hostname": "",
> > "hw-address": "00:50:01:00:01:00",
> > "ip-address": "192.168.0.12",
> > "next-server": "0.0.0.0",
> > "option-data": [ ],
> > "server-hostname": ""
> > }
> > ],
> > "store-extended-info": false,
> > "subnet": "192.168.0.0/24 <http://192.168.0.0/24>",
> > "t1-percent": 0.5,
> > "t2-percent": 0.875,
> > "valid-lifetime": 4000
> > }
> > ],
> > "t1-percent": 0.5,
> > "t2-percent": 0.875,
> > "valid-lifetime": 4000
> > }
> > }


> > Regards,

> > Jerônimo




> > Em qua., 7 de jul. de 2021 às 03:42, Gordon Ross <gr306 at cam.ac.uk
> > <mailto:gr306 at cam.ac.uk>> escreveu:

> > My configuration is very simple. There are no hooks, no HA, no
> > multi-threading, no fancy commands.

> > Postgres version is 12.7

> > Gordon.

> > On 06/07/2021, 19:27, "Marcin Siodelski" <marcin at isc.org
> > <mailto:marcin at isc.org>> wrote:

> > Gordon,

> > Thanks for posting your issue to the Kea users list. I will try to
> > replicate your issue tomorrow with the Postgres lease database
> > backend.

> > It will be super useful if you send me your Kea configuration
> > file. You
> > can sanitize it from any private stuff it may contain. Please
> > send it to
> > me privately if it can't be posted to the mail list.

> > If it is not possible, please describe the major parts of the
> > configuration, e.g. is multi threading on or off, are you using any
> > hooks libraries (e.g. lease cmds?), are you sending any commands
> > to Kea
> > that can possibly modify the lease information?

> > Finally, please provide your Postgres database version.

> > Kind Regards,

> > Marcin Siodelski
> > DHCP Software Engineer,
> > ISC


> > On 06.07.2021 18:28, Gordon Ross wrote:
> > > On the off chance, I tried an upgrade to Kea 1.9.9 and the
> > problem persists.

> > > Gordon.

> > > On 05/07/2021, 16:16, "Kea-users on behalf of Gordon Ross"
> > <kea-users-bounces at lists.isc.org
> > <mailto:kea-users-bounces at lists.isc.org> on behalf of
> > gr306 at cam.ac.uk <mailto:gr306 at cam.ac.uk>> wrote:

> > > I'm running Kea 1.8.2 using the Postgres lease database
> > backend on Ubuntu 20.04 LTS

> > > Devices can get a new IPv4 address fine. But when they try
> > to renew their address, it fails and the logs show:

> > > ALLOC_ENGINE_V4_ALLOC_ERROR [hwtype=1 00:21:55:02:67:14],
> > cid=[01:00:21:55:02:67:14], tid=0x58cd: error during attempt to
> > allocate an IPv4 address: unable to update lease for address
> > 172.18.5.4 as it does not exist

> > > If I delete the entry from the leases table, Kea then
> > happily re-issues the address. (I can perform the DELETE as the Kea
> > DB user so no permissions problems there)

> > > I saw an earlier post about an error in Kea 1.8 & HA, but
> > I'm not running HA at the moment - and I'm on a later version of Kea.

> > > Is this bug still outstanding in 1.8.2?

> > > Thank you,

> > > Gordon
> > > --
> > > Gordon Ross
> > > University of Cambridge

> > > _______________________________________________
> > > ISC funds the development of this software with paid
> > support subscriptions. Contact us at
> > https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.isc.org%2Fcontact%2F&data=04%7C01%7Cgr306%40cam.ac.uk%7Ca279f324acc84a66ab3c08d940abad12%7C49a50445bdfa4b79ade3547b4f3986e9%7C0%7C0%7C637611928779424476%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=eq9EslaePYR9Eju%2FOHp5krzAwc5A70FQoLe4KdFY%2BRo%3D&reserved=0
> > <https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.isc.org%2Fcontact%2F&data=04%7C01%7Cgr306%40cam.ac.uk%7Ca279f324acc84a66ab3c08d940abad12%7C49a50445bdfa4b79ade3547b4f3986e9%7C0%7C0%7C637611928779424476%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=eq9EslaePYR9Eju%2FOHp5krzAwc5A70FQoLe4KdFY%2BRo%3D&reserved=0>
> > for more information.

> > > To unsubscribe visit
> > https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.isc.org%2Fmailman%2Flistinfo%2Fkea-users&data=04%7C01%7Cgr306%40cam.ac.uk%7Ca279f324acc84a66ab3c08d940abad12%7C49a50445bdfa4b79ade3547b4f3986e9%7C0%7C0%7C637611928779424476%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=YHLKNqq5nZhFHWcrtxTNLHtrtGRjHsXGKIZoPwTTLLM%3D&reserved=0
> > <https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.isc.org%2Fmailman%2Flistinfo%2Fkea-users&data=04%7C01%7Cgr306%40cam.ac.uk%7Ca279f324acc84a66ab3c08d940abad12%7C49a50445bdfa4b79ade3547b4f3986e9%7C0%7C0%7C637611928779424476%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=YHLKNqq5nZhFHWcrtxTNLHtrtGRjHsXGKIZoPwTTLLM%3D&reserved=0>.

> > > Kea-users mailing list
> > > Kea-users at lists.isc.org <mailto:Kea-users at lists.isc.org>

> > https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.isc.org%2Fmailman%2Flistinfo%2Fkea-users&data=04%7C01%7Cgr306%40cam.ac.uk%7Ca279f324acc84a66ab3c08d940abad12%7C49a50445bdfa4b79ade3547b4f3986e9%7C0%7C0%7C637611928779424476%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=YHLKNqq5nZhFHWcrtxTNLHtrtGRjHsXGKIZoPwTTLLM%3D&reserved=0
> > <https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.isc.org%2Fmailman%2Flistinfo%2Fkea-users&data=04%7C01%7Cgr306%40cam.ac.uk%7Ca279f324acc84a66ab3c08d940abad12%7C49a50445bdfa4b79ade3547b4f3986e9%7C0%7C0%7C637611928779424476%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=YHLKNqq5nZhFHWcrtxTNLHtrtGRjHsXGKIZoPwTTLLM%3D&reserved=0>

> > > _______________________________________________
> > > ISC funds the development of this software with paid support
> > subscriptions. Contact us at
> > https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.isc.org%2Fcontact%2F&data=04%7C01%7Cgr306%40cam.ac.uk%7Ca279f324acc84a66ab3c08d940abad12%7C49a50445bdfa4b79ade3547b4f3986e9%7C0%7C0%7C637611928779424476%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=eq9EslaePYR9Eju%2FOHp5krzAwc5A70FQoLe4KdFY%2BRo%3D&reserved=0
> > <https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.isc.org%2Fcontact%2F&data=04%7C01%7Cgr306%40cam.ac.uk%7Ca279f324acc84a66ab3c08d940abad12%7C49a50445bdfa4b79ade3547b4f3986e9%7C0%7C0%7C637611928779424476%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=eq9EslaePYR9Eju%2FOHp5krzAwc5A70FQoLe4KdFY%2BRo%3D&reserved=0>
> > for more information.

> > > To unsubscribe visit
> > https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.isc.org%2Fmailman%2Flistinfo%2Fkea-users&data=04%7C01%7Cgr306%40cam.ac.uk%7Ca279f324acc84a66ab3c08d940abad12%7C49a50445bdfa4b79ade3547b4f3986e9%7C0%7C0%7C637611928779424476%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=YHLKNqq5nZhFHWcrtxTNLHtrtGRjHsXGKIZoPwTTLLM%3D&reserved=0
> > <https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.isc.org%2Fmailman%2Flistinfo%2Fkea-users&data=04%7C01%7Cgr306%40cam.ac.uk%7Ca279f324acc84a66ab3c08d940abad12%7C49a50445bdfa4b79ade3547b4f3986e9%7C0%7C0%7C637611928779424476%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=YHLKNqq5nZhFHWcrtxTNLHtrtGRjHsXGKIZoPwTTLLM%3D&reserved=0>.

> > > Kea-users mailing list
> > > Kea-users at lists.isc.org <mailto:Kea-users at lists.isc.org>

> > https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.isc.org%2Fmailman%2Flistinfo%2Fkea-users&data=04%7C01%7Cgr306%40cam.ac.uk%7Ca279f324acc84a66ab3c08d940abad12%7C49a50445bdfa4b79ade3547b4f3986e9%7C0%7C0%7C637611928779424476%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=YHLKNqq5nZhFHWcrtxTNLHtrtGRjHsXGKIZoPwTTLLM%3D&reserved=0
> > <https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.isc.org%2Fmailman%2Flistinfo%2Fkea-users&data=04%7C01%7Cgr306%40cam.ac.uk%7Ca279f324acc84a66ab3c08d940abad12%7C49a50445bdfa4b79ade3547b4f3986e9%7C0%7C0%7C637611928779424476%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=YHLKNqq5nZhFHWcrtxTNLHtrtGRjHsXGKIZoPwTTLLM%3D&reserved=0>



> > _______________________________________________
> > ISC funds the development of this software with paid support
> > subscriptions. Contact us at https://www.isc.org/contact/
> > <https://www.isc.org/contact/> for more information.

> > To unsubscribe visit
> > https://lists.isc.org/mailman/listinfo/kea-users
> > <https://lists.isc.org/mailman/listinfo/kea-users>.

> > Kea-users mailing list
> > Kea-users at lists.isc.org <mailto:Kea-users at lists.isc.org>
> > https://lists.isc.org/mailman/listinfo/kea-users
> > <https://lists.isc.org/mailman/listinfo/kea-users>


> > _______________________________________________
> > ISC funds the development of this software with paid support
> > subscriptions. Contact us at https://www.isc.org/contact/ for more
> > information.

> > To unsubscribe visit https://lists.isc.org/mailman/listinfo/kea-users.

> > Kea-users mailing list
> > Kea-users at lists.isc.org
> > https://lists.isc.org/mailman/listinfo/kea-users

> > _______________________________________________
>> ISC funds the development of this software with paid support subscriptions.
> > Contact us at https://www.isc.org/contact/ for more information.

> > To unsubscribe visit https://lists.isc.org/mailman/listinfo/kea-users.

> > Kea-users mailing list
> > Kea-users at lists.isc.org
> > https://lists.isc.org/mailman/listinfo/kea-users


> _______________________________________________
> ISC funds the development of this software with paid support subscriptions.
> Contact us at https://www.isc.org/contact/ for more information.

> To unsubscribe visit https://lists.isc.org/mailman/listinfo/kea-users.

> Kea-users mailing list
> Kea-users at lists.isc.org
> https://lists.isc.org/mailman/listinfo/kea-users


More information about the Kea-users mailing list