On 2022-04-24 20:01 +02, Ibrahim Khalifa <i...@trukonsult.se> wrote:
> Hi,
>
> I ran into an issue with dhcpleased when trying to do pxeboot and automatic 
> installation when using DHCP Relay on Cisco ASA.
>
> The problem is when dhcpleased starts for the first time after bsd.rd
> is loaded there is no hostname set for the server yet. Dhcpleased will
> set option 12 in it’s discover request but set the length to 0. As per
> the RFC the minimum length for the host name is 1. The assumption here
> is that sending option 12 with a zero length would be treated the same
> as it not being set. However Cisco ASA will block such package with
> error ”option 12 is malformed.”.
>
> It can be argued on which view on this is the most correct, but as it
> is now at least Cisco ASA blocks it as malformed. The attached patch
> will not set option 12 if the host name is empty. It works for me,
> both in the above scenario but also when host name is set. Someone
> with better insight in the depth of dhcpleased might know if this
> could be done in a more elegant way.
>
> Best regards,
>
> //Ibo
>
>

very good catch.

There is no need for strlen(3), we just want to know if hostname is the
empty string, i.e. starts with '\0'.

Btw. fun thing, I tested this by moving /etc/myname out of the way and
the dhcp server on my CPE just echos the empty hostname back. dhcpleased
refuses the lease because the hostname option is invalid :D

OK?

diff --git frontend.c frontend.c
index 58c6153793f..cb22bcad32e 100644
--- frontend.c
+++ frontend.c
@@ -971,7 +971,8 @@ build_packet(uint8_t message_type, char *if_name, uint32_t 
xid,
 #endif /* SMALL */
        {
                if (gethostname(dhcp_hostname + 2,
-                   sizeof(dhcp_hostname) - 2) == 0) {
+                   sizeof(dhcp_hostname) - 2) == 0 &&
+                   dhcp_hostname[2] != '\0') {
                        if ((c = strchr(dhcp_hostname + 2, '.')) != NULL)
                                *c = '\0';
                        dhcp_hostname[1] = strlen(dhcp_hostname + 2);


-- 
I'm not entirely sure you are real.

Reply via email to