Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: the dhcp client behaviour is not standard compliant for DHCP clients (RFC2131) (IDFGH-5139) #51

Merged
merged 1 commit into from
Sep 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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