Skip to content

Custom dhcp options #8571

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

Closed
wants to merge 6 commits into from
Closed
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
29 changes: 29 additions & 0 deletions cores/esp8266/LwipDhcpServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ void DhcpServer::send_offer(struct dhcps_msg* m)

end = add_msg_type(&m->options[4], DHCPOFFER);
end = add_offer_options(end);
end = insert_custom_offer_options(end, &m->options[0]);
end = add_end(end);

p = pbuf_alloc(PBUF_TRANSPORT, sizeof(struct dhcps_msg), PBUF_RAM);
Expand Down Expand Up @@ -658,6 +659,7 @@ void DhcpServer::send_ack(struct dhcps_msg* m)

end = add_msg_type(&m->options[4], DHCPACK);
end = add_offer_options(end);
end = insert_custom_offer_options(end, &m->options[0]);
end = add_end(end);

p = pbuf_alloc(PBUF_TRANSPORT, sizeof(struct dhcps_msg), PBUF_RAM);
Expand Down Expand Up @@ -1591,3 +1593,30 @@ uint32 DhcpServer::dhcps_client_update(u8* bssid, struct ipv4_addr* ip)

return pdhcps_pool->ip.addr;
}

void DhcpServer::add_dhcps_custom_options(char *offerContent)
{
isSetCustomOptions = true;
customOptionsContent = offerContent;
}

void DhcpServer::remove_dhcps_custom_options()
{
isSetCustomOptions = false;
}

uint8_t* DhcpServer::insert_custom_offer_options(uint8_t* optptr, uint8_t* optionsStart)
{
if(isSetCustomOptions){
uint16 customOptionsSize = strlen(customOptionsContent);
if((optptr + customOptionsSize - optionsStart) >= 311){
#if DHCPS_DEBUG
os_printf("ERROR: DHCP Custom Options Too Large. Ignoring Custom Options");
#endif
return optptr;
}
memcpy(optptr, customOptionsContent, strlen(customOptionsContent));
optptr += customOptionsSize;
}
return optptr;
}
6 changes: 6 additions & 0 deletions cores/esp8266/LwipDhcpServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ class DhcpServer
bool reset_dhcps_lease_time(void);
uint32 get_dhcps_lease_time(void);
bool add_dhcps_lease(uint8* macaddr);
void add_dhcps_custom_options(char *offerContent);
void remove_dhcps_custom_options(void);
bool isSetCustomOptions;
char *customOptionsContent;


void dhcps_set_dns(int num, const ipv4_addr_t* dns);

Expand All @@ -76,6 +81,7 @@ class DhcpServer
void node_remove_from_list(list_node** phead, list_node* pdelete);
uint8_t* add_msg_type(uint8_t* optptr, uint8_t type);
uint8_t* add_offer_options(uint8_t* optptr);
uint8_t* insert_custom_offer_options(uint8_t* optptr, uint8_t* optionsStart);
uint8_t* add_end(uint8_t* optptr);
void create_msg(struct dhcps_msg* m);
void send_offer(struct dhcps_msg* m);
Expand Down