On 9/15/17 2:12 PM, Jason Lixfeld wrote:
> Hello,
>
> I was troubleshooting an issue with host reservations via flex-id and 
> postgresql.
>
> I tracked it down to a difference in how the database was storing 
> identifier_value, vs. how the identifier_expression is configured in the kea 
> config file.
>
> The kea debug shows the generated flex-id:
>
> 2017-09-15 13:32:01.182 DEBUG [kea-dhcp4.packets/631] DHCP4_FLEX_ID flexible 
> identifier generated for incoming packet: 
> flex-id=010972677730312E6C616200040C370201
>
> The kea config identifier_expression is like so:
>
>                 "hooks-libraries": [
>                         {
>                         "library": "/usr/local/lib/hooks/libdhcp_flex_id.so",
>                         "parameters":
>                                 {
>                                 "identifier-expression": 
> "concat(relay4[2].hex,relay4[1].hex)"
>                                 }
>                         }
>                 ],
>
> I set the identifier_value per the how-to 
> (https://kea.isc.org/wiki/HostReservationsHowTo) to match what the kea debug 
> generated for the flex-id:
>
> …
> …
> kea=# \set identifier_value ‘010972677730312e6c616200040c370201'
> …
> …
>
> When I noticed that the reservation was not working, I looked at the postgres 
> query that Kea was making, and it appears as though $3 is prepended with \x :
>
> 2017-09-15 13:32:01.189 EDT [726] kea@kea LOG:  execute 
> get_host_subid4_dhcpid: 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.dhcp4_next_server, h.dhcp4_server_hostname, h.dhcp4_boot_file_name,   
> o.option_id, o.code, o.value, o.formatted_value, o.space, o.persistent FROM 
> hosts AS h LEFT JOIN dhcp4_options AS o ON h.host_id = o.host_id WHERE 
> h.dhcp4_subnet_id = $1 AND h.dhcp_identifier_type = $2    AND 
> h.dhcp_identifier = $3 ORDER BY h.host_id, o.option_id
> 2017-09-15 13:32:01.189 EDT [726] kea@kea DETAIL:  parameters: $1 = '1', $2 = 
> '4', $3 = '\x010972677730312e6c616200040c370201’
>
> Making that query directly of course fails, which is where the issue lies:
>
> 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.dhcp4_next_server, 
> h.dhcp4_server_hostname, h.dhcp4_boot_file_name,   o.option_id, o.code, 
> o.value, o.formatted_value, o.space, o.persistent FROM hosts AS h LEFT JOIN 
> dhcp4_options AS o ON h.host_id = o.host_id WHERE h.dhcp4_subnet_id = '1' AND 
> h.dhcp_identifier_type = '4' AND h.dhcp_identifier = 
> '\x010972677730312e6c616200040c370201' ORDER BY h.host_id, o.option_id;
>
>  host_id | dhcp_identifier | dhcp_identifier_type | dhcp4_subnet_id | 
> dhcp6_subnet_id | ipv4_address | hostname | dhcp4_client_classes | 
> dhcp6_client_classes | dhcp4_next_server | dhcp4_server_hostname | 
> dhcp4_boot_file_name | option_id | code | value | formatted_value | space | 
> persistent
> ---------+-----------------+----------------------+-----------------+-----------------+--------------+----------+----------------------+----------------------+-------------------+-----------------------+----------------------+-----------+------+-------+-----------------+-------+------------
> (0 rows)
>
> If I remove the leading \x from the query, the expected results are presented:
>
> 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.dhcp4_next_server, 
> h.dhcp4_server_hostname, h.dhcp4_boot_file_name,   o.option_id, o.code, 
> o.value, o.formatted_value, o.space, o.persistent FROM hosts AS h LEFT JOIN 
> dhcp4_options AS o ON h.host_id = o.host_id WHERE h.dhcp4_subnet_id = '1' AND 
> h.dhcp_identifier_type = '4' AND h.dhcp_identifier = 
> '010972677730312e6c616200040c370201' ORDER BY h.host_id, o.option_id;
>
>  host_id |                            dhcp_identifier                         
>     | dhcp_identifier_type | dhcp4_subnet_id | dhcp6_subnet_id | ipv4_address 
> | hostname | dhcp4_client_classes | dhcp6_client_classes | dhcp4_next_server 
> | dhcp4_server_hostname | dhcp4_boot_file_name | option_id | code | value | 
> formatted_value | space | persistent
> ---------+------------------------------------------------------------------------+----------------------+-----------------+-----------------+--------------+----------+----------------------+----------------------+-------------------+-----------------------+----------------------+-----------+------+-------+-----------------+-------+------------
>        6 | 
> \x30313039373236373737333033313265366336313632303030343063333730323031 |      
>               4 |               1 |                 |    171966277 |          
> |                      |                      |                   |           
>             | bootfile.efi         |           |      |       |               
>   |       |
> (1 row)
>
> Manually decoding the dhcp_identifier shows the non-prepended value:
>
> kea=# select 
> convert_from('\x30313039373236373737333033313265366336313632303030343063333730323031',
>  'UTF-8');
>             convert_from
> ------------------------------------
>  010972677730312e6c616200040c370201
> (1 row)
>  
> kea=#
>
> So my question is did I misinterpret the instructions (either by cluelessness 
> or oversight) when setting this up, or is this a bug?
>
> Thanks!
> _______________________________________________
> Kea-users mailing list
> [email protected]
> https://lists.isc.org/mailman/listinfo/kea-users
Hello Jason:

We're looking into this for you.  In the meantime you could try
prepending '\x' onto the identifier value you inserted.

Regards,

Thomas Markwalder
ISC Software Engineering
_______________________________________________
Kea-users mailing list
[email protected]
https://lists.isc.org/mailman/listinfo/kea-users

Reply via email to