-
Notifications
You must be signed in to change notification settings - Fork 7.1k
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
Add RFC 7710 support in the dhcp stack (IDFGH-973) #3308
Conversation
|
Hello, can you provide an example of how to use it ? And would it be possible to adapt it for the arduino mode ? It's not a request just a question if it is feasible or not :) Thanks for your work ! |
hi @cgiles |
hi @cgiles @plasger-ebv |
Looks like Android 11 supports RFC 7710... would be great to see support added to ESP-IDF! |
Hi @plasger-ebv et all, Thanks again for the contribution and the idea of adding additional options to DHCP server messages! Will address this in a more generic way (as provided in other LWIP modules), enabling users to define their own options and append it to various DHCP messages. diff --git a/components/lwip/apps/dhcpserver/dhcpserver.c b/components/lwip/apps/dhcpserver/dhcpserver.c
@@ -19,6 +19,14 @@
#if ESP_DHCPS
+#ifdef LWIP_HOOK_FILENAME
+#include LWIP_HOOK_FILENAME
+#endif
+
+#ifndef LWIP_HOOK_DHCPS_POST_APPEND_OPTS
+#define LWIP_HOOK_DHCPS_POST_APPEND_OPTS(netif, dhcps, state, pp_opts)
+#endif
+
#define BOOTP_BROADCAST 0x8000
#define DHCP_REQUEST 1
@@ -538,6 +546,7 @@ static void send_offer(dhcps_t *dhcps, struct dhcps_msg *m, u16_t len)
end = add_msg_type(&m->options[4], DHCPOFFER);
end = add_offer_options(dhcps, end);
+ LWIP_HOOK_DHCPS_POST_APPEND_OPTS(dhcps->netif, dhcps, DHCPOFFER, &end)
end = add_end(end);
p = dhcps_pbuf_alloc(len);
@@ -615,6 +624,7 @@ static void send_nak(dhcps_t *dhcps, struct dhcps_msg *m, u16_t len)
create_msg(dhcps, m);
end = add_msg_type(&m->options[4], DHCPNAK);
+ LWIP_HOOK_DHCPS_POST_APPEND_OPTS(dhcps->netif, dhcps, DHCPNAK, &end)
end = add_end(end);
p = dhcps_pbuf_alloc(len);
@@ -691,6 +701,7 @@ static void send_ack(dhcps_t *dhcps, struct dhcps_msg *m, u16_t len)
end = add_msg_type(&m->options[4], DHCPACK);
end = add_offer_options(dhcps, end);
+ LWIP_HOOK_DHCPS_POST_APPEND_OPTS(dhcps->netif, dhcps, DHCPACK, &end)
end = add_end(end);
p = dhcps_pbuf_alloc(len); Then, if we'd like to add the captive portal option, we'd just provide the macro definition #define LWIP_HOOK_DHCPS_POST_APPEND_OPTS(netif, dhcp, state, pp_opts) \
if ((state)==DHCPOFFER) { *(pp_opts) = append_captive_portal_uri(*(pp_opts)); }
static inline uint8_t *append_captive_portal_uri(uint8_t *optptr)
{
const static uint8_t DHCP_OPTION_CAPTIVE_PORTAL=160;
const static char CAPTIVE_PORTAL_URI[]="my_uri";
int size = sizeof(CAPTIVE_PORTAL_URI) - 1;
*optptr++ = DHCP_OPTION_CAPTIVE_PORTAL;
*optptr++ = size;
for(int i = 0; i < size; ++i) {
*optptr++ = CAPTIVE_PORTAL_URI[i];
}
return optptr;
} This needs to be added to the build process of lwip component, so includes an adjustment of our project makefile (assuming that the definitions above are provided in a file idf_component_get_property(lwip lwip COMPONENT_LIB)
target_compile_options(${lwip} PRIVATE "-I${PROJECT_DIR}/main")
target_compile_definitions(${lwip} PRIVATE "-DESP_IDF_LWIP_HOOK_FILENAME=\"add_captive_portal.h\"") |
This enables users appending an extra, user defined options in dhcp server messages. Example of adding captive_portal option (160) to dhcp offer message is provided: * Add idf-lwip hook file (project makefile): idf_component_get_property(lwip lwip COMPONENT_LIB) target_compile_options(${lwip} PRIVATE "-I${PROJECT_DIR}/main") target_compile_definitions(${lwip} PRIVATE "-DESP_IDF_LWIP_HOOK_FILENAME=\"add_captive_portal.h\"") * Implement appending (add_captive_portal.h): #pragma once #define LWIP_HOOK_DHCPS_POST_APPEND_OPTS(netif, dhcp, state, pp_opts) \ if ((state)==DHCPOFFER) { *(pp_opts) = append_captive_portal_uri(*(pp_opts)); } static inline uint8_t *append_captive_portal_uri(uint8_t *optptr) { const static uint8_t DHCP_OPTION_CAPTIVE_PORTAL=160; const static char CAPTIVE_PORTAL_URI[]="my_uri"; int size = sizeof(CAPTIVE_PORTAL_URI) - 1; *optptr++ = DHCP_OPTION_CAPTIVE_PORTAL; *optptr++ = size; for(int i = 0; i < size; ++i) { *optptr++ = CAPTIVE_PORTAL_URI[i]; } return optptr; } Merges #3308
Changes merged with b5d13b9, thanks for your contribution again. |
changes by VBn: modified for single instance dhcps of 4.3 (since then you may have multi instances etc) This enables users appending an extra, user defined options in dhcp server messages. Example of adding captive_portal option (160) to dhcp offer message is provided: * Add idf-lwip hook file (project makefile): idf_component_get_property(lwip lwip COMPONENT_LIB) target_compile_options(${lwip} PRIVATE "-I${PROJECT_DIR}/main") target_compile_definitions(${lwip} PRIVATE "-DESP_IDF_LWIP_HOOK_FILENAME=\"add_captive_portal.h\"") * Implement appending (add_captive_portal.h): #pragma once #define LWIP_HOOK_DHCPS_POST_APPEND_OPTS(netif, dhcp, state, pp_opts) \ if ((state)==DHCPOFFER) { *(pp_opts) = append_captive_portal_uri(*(pp_opts)); } static inline uint8_t *append_captive_portal_uri(uint8_t *optptr) { const static uint8_t DHCP_OPTION_CAPTIVE_PORTAL=160; const static char CAPTIVE_PORTAL_URI[]="my_uri"; int size = sizeof(CAPTIVE_PORTAL_URI) - 1; *optptr++ = DHCP_OPTION_CAPTIVE_PORTAL; *optptr++ = size; for(int i = 0; i < size; ++i) { *optptr++ = CAPTIVE_PORTAL_URI[i]; } return optptr; } Merges espressif/esp-idf#3308
changes by VBn: modified for single instance dhcps of 4.3 (since then you may have multi instances etc) This enables users appending an extra, user defined options in dhcp server messages. Example of adding captive_portal option (160) to dhcp offer message is provided: * Add idf-lwip hook file (project makefile): idf_component_get_property(lwip lwip COMPONENT_LIB) target_compile_options(${lwip} PRIVATE "-I${PROJECT_DIR}/main") target_compile_definitions(${lwip} PRIVATE "-DESP_IDF_LWIP_HOOK_FILENAME=\"add_captive_portal.h\"") * Implement appending (add_captive_portal.h): #pragma once #define LWIP_HOOK_DHCPS_POST_APPEND_OPTS(netif, dhcp, state, pp_opts) \ if ((state)==DHCPOFFER) { *(pp_opts) = append_captive_portal_uri(*(pp_opts)); } static inline uint8_t *append_captive_portal_uri(uint8_t *optptr) { const static uint8_t DHCP_OPTION_CAPTIVE_PORTAL=160; const static char CAPTIVE_PORTAL_URI[]="my_uri"; int size = sizeof(CAPTIVE_PORTAL_URI) - 1; *optptr++ = DHCP_OPTION_CAPTIVE_PORTAL; *optptr++ = size; for(int i = 0; i < size; ++i) { *optptr++ = CAPTIVE_PORTAL_URI[i]; } return optptr; } Merges espressif/esp-idf#3308
DHCP option 160 seems an outdated option. The latest option is 114, please refer to https://datatracker.ietf.org/doc/html/draft-ietf-capport-rfc7710bis |
changes by VBn: modified for single instance dhcps of 4.3 (since then you may have multi instances etc) This enables users appending an extra, user defined options in dhcp server messages. Example of adding captive_portal option (160) to dhcp offer message is provided: * Add idf-lwip hook file (project makefile): idf_component_get_property(lwip lwip COMPONENT_LIB) target_compile_options(${lwip} PRIVATE "-I${PROJECT_DIR}/main") target_compile_definitions(${lwip} PRIVATE "-DESP_IDF_LWIP_HOOK_FILENAME=\"add_captive_portal.h\"") * Implement appending (add_captive_portal.h): #pragma once #define LWIP_HOOK_DHCPS_POST_APPEND_OPTS(netif, dhcp, state, pp_opts) \ if ((state)==DHCPOFFER) { *(pp_opts) = append_captive_portal_uri(*(pp_opts)); } static inline uint8_t *append_captive_portal_uri(uint8_t *optptr) { const static uint8_t DHCP_OPTION_CAPTIVE_PORTAL=160; const static char CAPTIVE_PORTAL_URI[]="my_uri"; int size = sizeof(CAPTIVE_PORTAL_URI) - 1; *optptr++ = DHCP_OPTION_CAPTIVE_PORTAL; *optptr++ = size; for(int i = 0; i < size; ++i) { *optptr++ = CAPTIVE_PORTAL_URI[i]; } return optptr; } Merges espressif/esp-idf#3308
changes by VBn: modified for single instance dhcps of 4.3 (since then you may have multi instances etc) This enables users appending an extra, user defined options in dhcp server messages. Example of adding captive_portal option (160) to dhcp offer message is provided: * Add idf-lwip hook file (project makefile): idf_component_get_property(lwip lwip COMPONENT_LIB) target_compile_options(${lwip} PRIVATE "-I${PROJECT_DIR}/main") target_compile_definitions(${lwip} PRIVATE "-DESP_IDF_LWIP_HOOK_FILENAME=\"add_captive_portal.h\"") * Implement appending (add_captive_portal.h): #pragma once #define LWIP_HOOK_DHCPS_POST_APPEND_OPTS(netif, dhcp, state, pp_opts) \ if ((state)==DHCPOFFER) { *(pp_opts) = append_captive_portal_uri(*(pp_opts)); } static inline uint8_t *append_captive_portal_uri(uint8_t *optptr) { const static uint8_t DHCP_OPTION_CAPTIVE_PORTAL=160; const static char CAPTIVE_PORTAL_URI[]="my_uri"; int size = sizeof(CAPTIVE_PORTAL_URI) - 1; *optptr++ = DHCP_OPTION_CAPTIVE_PORTAL; *optptr++ = size; for(int i = 0; i < size; ++i) { *optptr++ = CAPTIVE_PORTAL_URI[i]; } return optptr; } Merges espressif/esp-idf#3308
These commits add support for rfc 7710 (captive portal) to the dhcp-stack.