Skip to content

Commit

Permalink
fix: the dhcp client behaviour is not standard compliant for DHCP cli…
Browse files Browse the repository at this point in the history
…ents (RFC2131) (IDFGH-5139)
  • Loading branch information
1e1 committed Jul 29, 2021
1 parent 66355f6 commit f927b9f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
8 changes: 8 additions & 0 deletions glue-lwip/arduino/lwipopts.h
Original file line number Diff line number Diff line change
Expand Up @@ -3579,6 +3579,14 @@ extern void lwip_hook_dhcp_parse_option(struct netif *netif, struct dhcp *dhcp,
int msg_type, int option, int option_len, struct pbuf *pbuf,
int option_value_offset);

#if LWIP_FEATURES
#define LWIP_HOOK_DHCP_APPEND_OPTIONS(netif, dhcp, state, msg, msg_type, option_len_ptr) \
lwip_hook_dhcp_amend_options(netif, dhcp, state, msg, msg_type, option_len_ptr)

extern void lwip_hook_dhcp_amend_options(struct netif *netif, struct dhcp *dhcp, int state, struct dhcp_msg *msg,
int msg_type, int *option_len_ptr);
#endif

/*
--------------------------------------------------
------------------ SNTP options ------------------
Expand Down
29 changes: 29 additions & 0 deletions glue-lwip/lwip-git.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ author: d. gauchard
#include "glue.h"
#include "uprint.h"
#include "lwip-helper.h"
#include "lwip/prot/dhcp.h"

#include "lwipopts.h"
#include "lwip/err.h"
Expand Down Expand Up @@ -196,6 +197,7 @@ err_glue_t esp2glue_dhcp_start (int netif_idx)
// calls netif_sta_status_callback() - if applicable (STA)
netif_set_up(&netif_git[netif_idx]);

#if LWIP_NETIF_HOSTNAME
// Update to latest esp hostname before starting dhcp client,
// because this name is provided to the dhcp server.
// Until proven wrong, dhcp client is the only code
Expand All @@ -205,6 +207,7 @@ err_glue_t esp2glue_dhcp_start (int netif_idx)
// XXX to check: is wifi_station_get_hostname()
// returning a const pointer once _set_hostname is called?
netif_git[netif_idx].hostname = wifi_station_get_hostname();
#endif

err_t err = dhcp_start(&netif_git[netif_idx]);
#if LWIP_IPV6 && LWIP_IPV6_DHCP6_STATELESS
Expand Down Expand Up @@ -352,7 +355,9 @@ static void netif_init_common (struct netif* netif)
netif->ip6_autoconfig_enabled = 1;
#endif

#if LWIP_NETIF_HOSTNAME
netif->hostname = wifi_station_get_hostname();
#endif
netif->chksum_flags = NETIF_CHECKSUM_ENABLE_ALL;
// netif->mtu given by glue
}
Expand Down Expand Up @@ -409,7 +414,9 @@ void esp2glue_netif_update (int netif_idx, uint32_t ip, uint32_t mask, uint32_t
netif->flags &= ~NETIF_FLAG_UP;

netif->mtu = mtu;
#if LWIP_NETIF_HOSTNAME
netif->hostname = wifi_station_get_hostname();
#endif
ip4_addr_t aip = { ip }, amask = { mask }, agw = { gw };
netif_set_addr(&netif_git[netif_idx], &aip, &amask, &agw);
esp2glue_netif_set_up1down0(netif_idx, 1);
Expand Down Expand Up @@ -569,4 +576,26 @@ void lwip_hook_dhcp_parse_option(struct netif *netif, struct dhcp *dhcp, int sta
uprint(DBG "unhandled dhcp option in lwip_hook_dhcp_parse_option()\n");
}

void lwip_hook_dhcp_amend_options(struct netif *netif, struct dhcp *dhcp, int state, struct dhcp_msg *msg,
int msg_type, int *option_len_ptr);

void lwip_hook_dhcp_amend_options(struct netif *netif, struct dhcp *dhcp, int state, struct dhcp_msg *msg,
int msg_type, int *option_len_ptr)
{
// amend default Client-Identifier
// {intf.id} {intf.mac} => {01}:{AA:BB:CC:11:22:33}
{
size_t i;

msg->options[(*option_len_ptr)++] = DHCP_OPTION_CLIENT_ID;
msg->options[(*option_len_ptr)++] = 1 + netif->hwaddr_len;
msg->options[(*option_len_ptr)++] = 0x01;

for (i = 0; i < netif->hwaddr_len; ++i) {
msg->options[(*option_len_ptr)++] = netif->hwaddr[i];
}
}
}


#endif // ARDUINO
1 change: 1 addition & 0 deletions makefiles/Makefile.defs
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ OD = $(TOOLS)objdump
BUILD ?= build
BUILD_FLAGS += -Wall -Wextra -c -Os -g -free -fipa-pta -Wpointer-arith -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -falign-functions=4 -MMD -ffunction-sections -fdata-sections
BUILD_DEFINES = -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ -DLWIP_OPEN_SRC -DLWIP_BUILD -DUSE_OPTIMIZE_PRINTF -DTARGET=$(target) -D$(DEFINE_TARGET)=1 -DTCP_MSS=$(TCP_MSS) -DLWIP_FEATURES=$(LWIP_FEATURES) -DLWIP_IPV6=$(LWIP_IPV6)
BUILD_DEFINES += -DLWIP_NETIF_HOSTNAME=$(LWIP_FEATURES) -DESP_DHCP=$(LWIP_FEATURES)

0 comments on commit f927b9f

Please sign in to comment.