diff --git a/components/esp_netif/include/esp_netif_defaults.h b/components/esp_netif/include/esp_netif_defaults.h index 7ef65260d4..edcc2a8d08 100644 --- a/components/esp_netif/include/esp_netif_defaults.h +++ b/components/esp_netif/include/esp_netif_defaults.h @@ -25,9 +25,15 @@ extern "C" { // Macros to assemble master configs with partial configs from netif, stack and driver // +#ifdef CONFIG_LWIP_ESP_MLDV6_REPORT +#define ESP_NETIF_DEFAULT_MLDV6_REPORT_FLAGS (ESP_NETIF_FLAG_MLDV6_REPORT) +#else +#define ESP_NETIF_DEFAULT_MLDV6_REPORT_FLAGS (0) +#endif + #define ESP_NETIF_INHERENT_DEFAULT_WIFI_STA() \ { \ - .flags = (esp_netif_flags_t)(ESP_NETIF_DHCP_CLIENT | ESP_NETIF_FLAG_GARP | ESP_NETIF_FLAG_EVENT_IP_MODIFIED), \ + .flags = (esp_netif_flags_t)(ESP_NETIF_DHCP_CLIENT | ESP_NETIF_FLAG_GARP | ESP_NETIF_DEFAULT_MLDV6_REPORT_FLAGS | ESP_NETIF_FLAG_EVENT_IP_MODIFIED), \ ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_EMPTY(mac) \ ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_EMPTY(ip_info) \ .get_ip_event = IP_EVENT_STA_GOT_IP, \ diff --git a/components/esp_netif/include/esp_netif_types.h b/components/esp_netif/include/esp_netif_types.h index 349fd72c36..4e3c0cdb54 100644 --- a/components/esp_netif/include/esp_netif_types.h +++ b/components/esp_netif/include/esp_netif_types.h @@ -141,6 +141,7 @@ typedef enum esp_netif_flags { ESP_NETIF_FLAG_EVENT_IP_MODIFIED = 1 << 4, ESP_NETIF_FLAG_IS_PPP = 1 << 5, ESP_NETIF_FLAG_IS_SLIP = 1 << 6, + ESP_NETIF_FLAG_MLDV6_REPORT = 1 << 7, } esp_netif_flags_t; typedef enum esp_netif_ip_event_type { diff --git a/components/esp_netif/lwip/esp_netif_lwip.c b/components/esp_netif/lwip/esp_netif_lwip.c index bf7f92233c..c3db13c5d5 100644 --- a/components/esp_netif/lwip/esp_netif_lwip.c +++ b/components/esp_netif/lwip/esp_netif_lwip.c @@ -27,6 +27,8 @@ #include "lwip/dhcp.h" #include "lwip/ip_addr.h" #include "lwip/ip6_addr.h" +#include "lwip/mld6.h" +#include "lwip/prot/mld6.h" #include "lwip/nd6.h" #include "lwip/priv/tcpip_priv.h" #include "lwip/netif.h" @@ -123,6 +125,12 @@ static void esp_netif_api_cb(void *api_msg) } + +#if LWIP_IPV6 +static void netif_set_mldv6_flag(struct netif *netif); +static void netif_unset_mldv6_flag(struct netif *netif); +#endif /* LWIP_IPV6 */ + /** * @brief Initiates a tcpip remote call if called from another task * or calls the function directly if executed from lwip task @@ -526,6 +534,11 @@ static void esp_netif_lwip_remove(esp_netif_t *esp_netif) if (netif_is_up(esp_netif->lwip_netif)) { netif_set_down(esp_netif->lwip_netif); } +#if ESP_MLDV6_REPORT && LWIP_IPV6 + if (esp_netif->flags & ESP_NETIF_FLAG_MLDV6_REPORT) { + netif_unset_mldv6_flag(esp_netif->lwip_netif); + } +#endif netif_remove(esp_netif->lwip_netif); } } @@ -1302,6 +1315,11 @@ static esp_err_t esp_netif_down_api(esp_netif_api_msg_t *msg) esp_netif_reset_ip_info(esp_netif); } #if CONFIG_LWIP_IPV6 +#if ESP_MLDV6_REPORT + if (esp_netif->flags & ESP_NETIF_FLAG_MLDV6_REPORT) { + netif_unset_mldv6_flag(esp_netif->lwip_netif); + } +#endif for(int8_t i = 0 ;i < LWIP_IPV6_NUM_ADDRESSES ;i++) { netif_ip6_addr_set(lwip_netif, i, IP6_ADDR_ANY6); netif_ip6_addr_set_valid_life(lwip_netif, i, 0); @@ -1577,6 +1595,34 @@ esp_err_t esp_netif_get_dns_info(esp_netif_t *esp_netif, esp_netif_dns_type_t ty } #if CONFIG_LWIP_IPV6 + +#ifdef CONFIG_LWIP_MLDV6_TMR_INTERVAL + +static void netif_send_mldv6(void *arg) +{ + struct netif *netif = arg; + if (!netif_is_up(netif)) { + return; + } + mld6_report_groups(netif); + sys_timeout(CONFIG_LWIP_MLDV6_TMR_INTERVAL*1000, netif_send_mldv6, netif); +} + +static void netif_set_mldv6_flag(struct netif *netif) +{ + if (!netif_is_up(netif)) { + return; + } + sys_timeout(CONFIG_LWIP_MLDV6_TMR_INTERVAL*1000, netif_send_mldv6, netif); +} + +static void netif_unset_mldv6_flag(struct netif *netif) +{ + sys_untimeout(netif_send_mldv6, netif); +} + +#endif + esp_ip6_addr_type_t esp_netif_ip6_get_addr_type(esp_ip6_addr_t* ip6_addr) { ip6_addr_t* lwip_ip6_info = (ip6_addr_t*)ip6_addr; @@ -1606,6 +1652,7 @@ static void esp_netif_nd6_cb(struct netif *p_netif, uint8_t ip_index) esp_netif_ip6_info_t ip6_info; ip6_addr_t lwip_ip6_info; + esp_netif_t *esp_netif = p_netif->state; //notify event ip_event_got_ip6_t evt = { .esp_netif = p_netif->state, .if_index = -1, .ip_index = ip_index }; @@ -1617,6 +1664,13 @@ static void esp_netif_nd6_cb(struct netif *p_netif, uint8_t ip_index) ip6_info.ip.zone = 0; // zero out zone, as not used in lwip #endif /* LWIP_IPV6_SCOPES */ + if (esp_netif->flags&ESP_NETIF_FLAG_MLDV6_REPORT) { +#if ESP_MLDV6_REPORT + netif_set_mldv6_flag(p_netif); +#else + ESP_LOGW(TAG,"CONFIG_LWIP_ESP_MLDV6_REPORT not enabled, but esp-netif configured with ESP_NETIF_FLAG_MLDV6_REPORT"); +#endif + } memcpy(&evt.ip6_info, &ip6_info, sizeof(esp_netif_ip6_info_t)); int ret = esp_event_send_internal(IP_EVENT, IP_EVENT_GOT_IP6, &evt, sizeof(evt), 0); if (ESP_OK != ret) { diff --git a/components/lwip/Kconfig b/components/lwip/Kconfig index 21c5334f6b..593e96a7c7 100644 --- a/components/lwip/Kconfig +++ b/components/lwip/Kconfig @@ -214,6 +214,24 @@ menu "LWIP" help Set the timer interval for gratuitous ARP. The default value is 60s + config LWIP_ESP_MLDV6_REPORT + bool "Send mldv6 report periodically" + depends on LWIP_IPV6 + default y + help + Enable this option allows to send mldv6 report periodically. + + This option solve the issue that failed to receive multicast data. + Some routers fail to forward multicast packets. + To solve this problem, send multicast mdlv6 report to routers regularly. + + config LWIP_MLDV6_TMR_INTERVAL + int "mldv6 report timer interval(seconds)" + default 40 + depends on LWIP_ESP_MLDV6_REPORT + help + Set the timer interval for mldv6 report. The default value is 40s + config LWIP_TCPIP_RECVMBOX_SIZE int "TCPIP task receive mail box size" default 32 diff --git a/components/lwip/apps/dhcpserver/dhcpserver.c b/components/lwip/apps/dhcpserver/dhcpserver.c index a5ff880fba..282dedebba 100644 --- a/components/lwip/apps/dhcpserver/dhcpserver.c +++ b/components/lwip/apps/dhcpserver/dhcpserver.c @@ -65,38 +65,16 @@ #define IS_INVALID_SUBNET_MASK(x) (((x-1) | x) != 0xFFFFFFFF) +#define IP_CLASS_HOST_NUM(mask) (0xffffffff & ~mask) /* Notes: -* 1. Class a address range 0.0.0.0~127.255.255.255. - * 2. Class b address range 128.0.0.0~191.255.255.255. - * 3. Class c address range 192.0.0.0~223.255.255.255. + * CIDR eliminates the traditional Class A, Class B and Class C addresses. */ -#define IS_VALID_CLASSA_SUBNET_MASK(mask) (mask >= 0xFF000000 && mask <= 0xFFFE0000) -#define IS_VALID_CLASSB_SUBNET_MASK(mask) (mask >= 0xFFFF0000 && mask <= 0xFFFFFE00) -#define IS_VALID_CLASSC_SUBNET_MASK(mask) (mask >= 0xFFFFFF00 && mask <= 0xFFFFFFFC) -#define IP_CLASS_HOST_NUM(mask) (0xffffffff & ~mask) -#define DHCP_CHECK_SUBNET_MASK_IP(mask, ip) \ +#define DHCP_CHECK_SUBNET_MASK_IP(mask) \ do { \ if (IS_INVALID_SUBNET_MASK(mask)) { \ DHCPS_LOG("dhcps: Illegal subnet mask.\n"); \ return ERR_ARG; \ - } else { \ - if (IP_CLASSA(ip)) { \ - if(!IS_VALID_CLASSA_SUBNET_MASK(mask)) { \ - DHCPS_LOG("dhcps: The subnet mask does not match the A address.\n"); \ - return ERR_ARG; \ - } \ - } else if (IP_CLASSB(ip)) { \ - if(!IS_VALID_CLASSB_SUBNET_MASK(mask)) { \ - DHCPS_LOG("dhcps: The subnet mask does not match the B address.\n"); \ - return ERR_ARG; \ - } \ - } else if (IP_CLASSC(ip)) { \ - if(!IS_VALID_CLASSC_SUBNET_MASK(mask)) { \ - DHCPS_LOG("dhcps: The subnet mask does not match the C address.\n"); \ - return ERR_ARG; \ - } \ - } \ } \ } while (0) @@ -1207,7 +1185,7 @@ err_t dhcps_start(struct netif *netif, ip4_addr_t ip) IP4_ADDR(&broadcast_dhcps, 255, 255, 255, 255); server_address.addr = ip.addr; - DHCP_CHECK_SUBNET_MASK_IP(htonl(s_dhcps_mask.addr), htonl(server_address.addr)); + DHCP_CHECK_SUBNET_MASK_IP(htonl(s_dhcps_mask.addr)); dhcps_poll_set(server_address.addr); client_address_plus.addr = dhcps_poll.start_ip.addr; diff --git a/components/lwip/lwip b/components/lwip/lwip index a7abf28e02..6bb132e379 160000 --- a/components/lwip/lwip +++ b/components/lwip/lwip @@ -1 +1 @@ -Subproject commit a7abf28e02282b32479f4bbaf2d90f09d2a60f4c +Subproject commit 6bb132e3797d5449a923804c75c57d458920f8ac diff --git a/components/lwip/port/esp32/include/lwipopts.h b/components/lwip/port/esp32/include/lwipopts.h index ad5a9114b0..d0dd9ee0fc 100644 --- a/components/lwip/port/esp32/include/lwipopts.h +++ b/components/lwip/port/esp32/include/lwipopts.h @@ -807,6 +807,16 @@ static inline uint32_t timeout_from_offered(uint32_t lease, uint32_t min) */ #define LWIP_ND6_NUM_NEIGHBORS CONFIG_LWIP_IPV6_ND6_NUM_NEIGHBORS + +/** + * ESP_MLDV6_REPORT==1: This option allows to send mldv6 report periodically. + */ +#ifdef CONFIG_LWIP_ESP_MLDV6_REPORT +#define ESP_MLDV6_REPORT 1 +#else +#define ESP_MLDV6_REPORT 0 +#endif + /* --------------------------------------- ---------- Hook options ---------------