فهرست منبع

Merge branch 'feat/lwip_dhcps_append_opts' into 'master'

lw-ip/dhcpserver: Support for adding extra opts

Closes IDFGH-973

See merge request espressif/esp-idf!19115
David Čermák 3 سال پیش
والد
کامیت
8d62485a12
2فایلهای تغییر یافته به همراه23 افزوده شده و 0 حذف شده
  1. 11 0
      components/lwip/apps/dhcpserver/dhcpserver.c
  2. 12 0
      docs/en/api-guides/lwip.rst

+ 11 - 0
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);

+ 12 - 0
docs/en/api-guides/lwip.rst

@@ -382,6 +382,18 @@ IP layer features
 
 - IPV4 mapped IPV6 addresses are supported.
 
+Customized lwIP hooks
++++++++++++++++++++++
+
+The original lwIP supports implementing custom compile-time modifications via ``LWIP_HOOK_FILENAME``. This file is already used by the IDF port layer, but IDF users could still include and implement any custom additions via a header file defined by the macro ``ESP_IDF_LWIP_HOOK_FILENAME``. Here is an exmaple of adding a custom hook file to the build process (the hook is called ``my_hook.h`` and located in the project's ``main`` folder):
+
+.. code-block:: cmake
+
+   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=\"my_hook.h\"")
+
+
 Limitations
 ^^^^^^^^^^^
 Calling ``send()`` or ``sendto()`` repeatedly on a UDP socket may eventually fail with ``errno`` equal to ``ENOMEM``. This is a limitation of buffer sizes in the lower layer network interface drivers. If all driver transmit buffers are full then UDP transmission will fail. Applications sending a high volume of UDP datagrams who don't wish for any to be dropped by the sender should check for this error code and re-send the datagram after a short delay.