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

Add RFC 7710 support in the dhcp stack (IDFGH-973) #3308

Closed
wants to merge 2 commits into from

Conversation

plasger-ebv
Copy link

These commits add support for rfc 7710 (captive portal) to the dhcp-stack.

@CLAassistant
Copy link

CLAassistant commented Apr 15, 2019

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@github-actions github-actions bot changed the title Add RFC 7710 support in the dhcp stack Add RFC 7710 support in the dhcp stack (IDFGH-973) Apr 15, 2019
@cgiles
Copy link

cgiles commented Jan 17, 2020

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 !

@freakyxue
Copy link
Collaborator

hi @cgiles
We could potentially expand the example to have an option for using this. Although from my research it seems like the support for this feature among Android/iOS

@freakyxue
Copy link
Collaborator

hi @cgiles @plasger-ebv
from my research it seems like the support for this feature among Android/iOS is not there, so it probably won't be very useful (yet).

0xFEEDC0DE64 pushed a commit to 0xFEEDC0DE64/esp-idf that referenced this pull request May 5, 2021
@joecjdi
Copy link

joecjdi commented Sep 10, 2021

Looks like Android 11 supports RFC 7710... would be great to see support added to ESP-IDF!

@david-cermak
Copy link
Collaborator

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.
The update in IDF is very simple:

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 add_captive_portal.h located directly in our main component):

  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\"")

@espressif-bot espressif-bot added Status: In Progress Work is in progress Status: Reviewing Issue is being reviewed and removed Status: In Progress Work is in progress labels Jul 19, 2022
@espressif-bot espressif-bot added Resolution: NA Issue resolution is unavailable Status: Done Issue is done internally Resolution: Done Issue is done internally and removed Status: Reviewing Issue is being reviewed Resolution: NA Issue resolution is unavailable labels Jul 29, 2022
espressif-bot pushed a commit that referenced this pull request Jul 29, 2022
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
@Alvin1Zhang
Copy link
Collaborator

Changes merged with b5d13b9, thanks for your contribution again.

boborjan2 pushed a commit to boborjan2/esp-idf that referenced this pull request Sep 19, 2022
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
boborjan2 pushed a commit to boborjan2/esp-idf that referenced this pull request Oct 23, 2022
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
@Alson-tang
Copy link

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

boborjan2 pushed a commit to boborjan2/esp-idf that referenced this pull request Dec 12, 2022
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
boborjan2 pushed a commit to boborjan2/esp-idf that referenced this pull request Feb 9, 2023
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Done Issue is done internally Status: Done Issue is done internally
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants