This is hard to describe, so I'll try to show it as clearly as I can.

The leases script takes the client id, skips the first digit, then converts
each letter of the already byte encoded string to hexadecimal.

Here's the lease from the isc dhcpd leases file:

lease 192.168.1.26 {
        starts 2 2025/02/11 17:53:02 UTC;
        ends 1 2025/05/12 17:53:02 UTC;
        hardware ethernet 72:f9:a1:9d:ba:05;
        uid 01:72:f9:a1:9d:ba:05;
}

As you can see, the uid is simply the MAC address prepended by "01:" Every
device on my network that provides a uid does this.  The others provide
nothing.

Here's the corresponding output from the script
address,hwaddr,client_id,valid_lifetime,expire,subnet_id,fqdn_fwd,fqdn_rev,hostname,state,user_context
192.168.1.26,72:f9:a1:9d:ba:05,31:3a:37:32:3a:66:39:3a:61:31:3a:39:64:3a:62:61:3a:30,7772400,1747093734,1,0,0,,0,

As you can see, the client_id from the kea script looks nothing like the
uid to which it should correspond. As it turns out, someone did a lot of
work to get this wrong.  After staring at it long enough, I realized what
it was.  Let me show you what it is by decoding each byte for you.
 1  :  7  2  :  f  9  :  a  1  :  9  d  :  b  a  :  0
31:3a:37:32:3a:66:39:3a:61:31:3a:39:64:3a:62:61:3a:30
Look familiar?  For quick reference, here's the UID from the ISC leases
file again 0*1:72:f9:a1:9d:ba:0*5

Now, I think other types of UID/client_id may exist, but at least for this
kind, this worked for me:
106c106
>                 , ':'.join([format((ord(x)),'02x') for x in
v["uid"].encode('utf-8').decode('unicode-escape')[1:-1]])
---
<                 , v["uid"]

Then I get
address,hwaddr,client_id,valid_lifetime,expire,subnet_id,fqdn_fwd,fqdn_rev,hostname,state,user_context
192.168.1.26,72:f9:a1:9d:ba:05,01:72:f9:a1:9d:ba:05,7772400,1747093734,1,0,0,,0,
Please note that this type of UID/client_id is exactly what kea-dhcp4 puts
in the lease file itself, not the kind the script originally generated.

Like I said, someone went to a lot of work to get this wrong, at least for
this UID type.  I believe that this may be appropriate for UIDs that start
with "00" but I don't have any of those to test with, so if you do, this
may break your conversion.

If the github would accept me as a member, I'd create a ticket for this,
but it looks like I'll need some help with that again.
-- 
John Lind
steinhel...@gmail.com
-- 
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@lists.isc.org
https://lists.isc.org/mailman/listinfo/kea-users

Reply via email to