Merge branch 'bugfix/tw24694_dns_request_no_reply_v3.1' into 'release/v3.1'

lwip: add code for sending gratuitous ARP periodically (backport v3.1)

See merge request idf/esp-idf!3195
This commit is contained in:
Jiang Jiang Jian 2018-09-16 15:18:39 +08:00
commit bfcb673c8e
9 changed files with 78 additions and 0 deletions

View file

@ -128,6 +128,23 @@ config LWIP_ETHARP_TRUST_IP_MAC
So the recommendation is to disable this option. So the recommendation is to disable this option.
Here the LAN peer means the other side to which the ESP station or soft-AP is connected. Here the LAN peer means the other side to which the ESP station or soft-AP is connected.
config ESP_GRATUITOUS_ARP
bool "Send gratuitous ARP periodically"
default y
help
Enable this option allows to send gratuitous ARP periodically.
This option solve the compatibility issues.If the ARP table of the AP is old, and the AP
doesn't send ARP request to update it's ARP table, this will lead to the STA sending IP packet fail.
Thus we send gratuitous ARP periodically to let AP update it's ARP table.
config GARP_TMR_INTERVAL
int "GARP timer interval(seconds)"
default 60
depends on ESP_GRATUITOUS_ARP
help
Set the timer interval for gratuitous ARP. The default value is 60s
config TCPIP_RECVMBOX_SIZE config TCPIP_RECVMBOX_SIZE
int "TCPIP task receive mail box size" int "TCPIP task receive mail box size"
default 32 default 32

View file

@ -332,6 +332,16 @@ netif_set_addr(struct netif *netif, const ip4_addr_t *ipaddr, const ip4_addr_t *
#endif /* LWIP_IPV4*/ #endif /* LWIP_IPV4*/
/**
* Set the netif flags for GARP
*/
#if ESP_GRATUITOUS_ARP
void netif_set_garp_flag(struct netif *netif)
{
netif->flags |= NETIF_FLAG_GARP;
}
#endif
/** /**
* Remove a network interface from the list of lwIP netifs. * Remove a network interface from the list of lwIP netifs.
* *

View file

@ -70,6 +70,10 @@
extern void dhcps_coarse_tmr(void); extern void dhcps_coarse_tmr(void);
#endif #endif
#if ESP_GRATUITOUS_ARP
extern void garp_tmr(void);
#endif
/** This array contains all stack-internal cyclic timers. To get the number of /** This array contains all stack-internal cyclic timers. To get the number of
* timers, use LWIP_ARRAYSIZE() */ * timers, use LWIP_ARRAYSIZE() */
const struct lwip_cyclic_timer lwip_cyclic_timers[] = { const struct lwip_cyclic_timer lwip_cyclic_timers[] = {
@ -84,6 +88,9 @@ const struct lwip_cyclic_timer lwip_cyclic_timers[] = {
#endif /* IP_REASSEMBLY */ #endif /* IP_REASSEMBLY */
#if LWIP_ARP #if LWIP_ARP
{ARP_TMR_INTERVAL, HANDLER(etharp_tmr)}, {ARP_TMR_INTERVAL, HANDLER(etharp_tmr)},
#if ESP_GRATUITOUS_ARP
{GARP_TMR_INTERVAL, HANDLER(garp_tmr)},
#endif
#endif /* LWIP_ARP */ #endif /* LWIP_ARP */
#if LWIP_DHCP #if LWIP_DHCP
{DHCP_COARSE_TIMER_MSECS, HANDLER(dhcp_coarse_tmr)}, {DHCP_COARSE_TIMER_MSECS, HANDLER(dhcp_coarse_tmr)},

View file

@ -99,6 +99,11 @@ extern "C" {
* Set by the netif driver in its init function. */ * Set by the netif driver in its init function. */
#define NETIF_FLAG_MLD6 0x40U #define NETIF_FLAG_MLD6 0x40U
#if ESP_GRATUITOUS_ARP
/** If set, the netif will send gratuitous ARP periodically */
#define NETIF_FLAG_GARP 0x80U
#endif
#if LWIP_CHECKSUM_CTRL_PER_NETIF #if LWIP_CHECKSUM_CTRL_PER_NETIF
#define NETIF_CHECKSUM_GEN_IP 0x0001 #define NETIF_CHECKSUM_GEN_IP 0x0001
#define NETIF_CHECKSUM_GEN_UDP 0x0002 #define NETIF_CHECKSUM_GEN_UDP 0x0002
@ -362,6 +367,11 @@ struct netif *netif_add(struct netif *netif,
void netif_set_addr(struct netif *netif, const ip4_addr_t *ipaddr, const ip4_addr_t *netmask, void netif_set_addr(struct netif *netif, const ip4_addr_t *ipaddr, const ip4_addr_t *netmask,
const ip4_addr_t *gw); const ip4_addr_t *gw);
#endif /* LWIP_IPV4 */ #endif /* LWIP_IPV4 */
#if ESP_GRATUITOUS_ARP
void netif_set_garp_flag(struct netif *netif);
#endif
void netif_remove(struct netif * netif); void netif_remove(struct netif * netif);
/* Returns a network interface given its name. The name is of the form /* Returns a network interface given its name. The name is of the form

View file

@ -318,8 +318,12 @@
* The formula expects settings to be either '0' or '1'. * The formula expects settings to be either '0' or '1'.
*/ */
#ifndef MEMP_NUM_SYS_TIMEOUT #ifndef MEMP_NUM_SYS_TIMEOUT
#if ESP_LWIP
#define MEMP_NUM_SYS_TIMEOUT (LWIP_TCP + IP_REASSEMBLY + (LWIP_ARP + (ESP_GRATUITOUS_ARP ? 1 : 0)) + (2*LWIP_DHCP + (ESP_DHCPS_TIMER ? 1 : 0)) + LWIP_AUTOIP + LWIP_IGMP + LWIP_DNS + (PPP_SUPPORT*6*MEMP_NUM_PPP_PCB) + (LWIP_IPV6 ? (1 + LWIP_IPV6_REASS + LWIP_IPV6_MLD) : 0))
#else
#define MEMP_NUM_SYS_TIMEOUT (LWIP_TCP + IP_REASSEMBLY + LWIP_ARP + (2*LWIP_DHCP) + LWIP_AUTOIP + LWIP_IGMP + LWIP_DNS + (PPP_SUPPORT*6*MEMP_NUM_PPP_PCB) + (LWIP_IPV6 ? (1 + LWIP_IPV6_REASS + LWIP_IPV6_MLD) : 0)) #define MEMP_NUM_SYS_TIMEOUT (LWIP_TCP + IP_REASSEMBLY + LWIP_ARP + (2*LWIP_DHCP) + LWIP_AUTOIP + LWIP_IGMP + LWIP_DNS + (PPP_SUPPORT*6*MEMP_NUM_PPP_PCB) + (LWIP_IPV6 ? (1 + LWIP_IPV6_REASS + LWIP_IPV6_MLD) : 0))
#endif #endif
#endif
/** /**
* MEMP_NUM_NETBUF: the number of struct netbufs. * MEMP_NUM_NETBUF: the number of struct netbufs.

View file

@ -102,6 +102,11 @@ struct etharp_q_entry {
}; };
#endif /* ARP_QUEUEING */ #endif /* ARP_QUEUEING */
#if ESP_GRATUITOUS_ARP
#define GARP_TMR_INTERVAL (CONFIG_GARP_TMR_INTERVAL*1000UL)
void garp_tmr(void);
#endif
#define etharp_init() /* Compatibility define, no init needed. */ #define etharp_init() /* Compatibility define, no init needed. */
void etharp_tmr(void); void etharp_tmr(void);
s8_t etharp_find_addr(struct netif *netif, const ip4_addr_t *ipaddr, s8_t etharp_find_addr(struct netif *netif, const ip4_addr_t *ipaddr,

View file

@ -738,6 +738,7 @@
#define ESP_LWIP_LOGI(...) ESP_LOGI("lwip", __VA_ARGS__) #define ESP_LWIP_LOGI(...) ESP_LOGI("lwip", __VA_ARGS__)
#define ESP_PING 1 #define ESP_PING 1
#define ESP_HAS_SELECT 1 #define ESP_HAS_SELECT 1
#define ESP_GRATUITOUS_ARP CONFIG_ESP_GRATUITOUS_ARP
#if CONFIG_LWIP_IRAM_OPTIMIZATION #if CONFIG_LWIP_IRAM_OPTIMIZATION
#define ESP_IRAM_ATTR IRAM_ATTR #define ESP_IRAM_ATTR IRAM_ATTR

View file

@ -52,6 +52,7 @@
#include "lwip/snmp.h" #include "lwip/snmp.h"
#include "lwip/dhcp.h" #include "lwip/dhcp.h"
#include "lwip/autoip.h" #include "lwip/autoip.h"
#include "lwip/netif.h"
#include <string.h> #include <string.h>
@ -129,6 +130,22 @@ static u8_t etharp_cached_entry;
static err_t etharp_request_dst(struct netif *netif, const ip4_addr_t *ipaddr, const struct eth_addr* hw_dst_addr); static err_t etharp_request_dst(struct netif *netif, const ip4_addr_t *ipaddr, const struct eth_addr* hw_dst_addr);
#if ESP_GRATUITOUS_ARP
void garp_tmr(void)
{
struct netif* garp_netif = NULL;
for (garp_netif = netif_list; garp_netif != NULL; garp_netif = garp_netif->next) {
if (netif_is_up(garp_netif) && netif_is_link_up(garp_netif) && !ip4_addr_isany_val(*netif_ip4_addr(garp_netif))) {
if ((garp_netif->flags & NETIF_FLAG_ETHARP) && (garp_netif->flags & NETIF_FLAG_GARP)) {
etharp_gratuitous(garp_netif);
}
}
}
}
#endif
#if ARP_QUEUEING #if ARP_QUEUEING
/** /**

View file

@ -26,6 +26,7 @@
#include "lwip/ip6_addr.h" #include "lwip/ip6_addr.h"
#include "lwip/nd6.h" #include "lwip/nd6.h"
#include "lwip/priv/tcpip_priv.h" #include "lwip/priv/tcpip_priv.h"
#include "lwip/netif.h"
#if LWIP_DNS /* don't build if not configured for use in lwipopts.h */ #if LWIP_DNS /* don't build if not configured for use in lwipopts.h */
#include "lwip/dns.h" #include "lwip/dns.h"
#endif #endif
@ -184,6 +185,12 @@ esp_err_t tcpip_adapter_start(tcpip_adapter_if_t tcpip_if, uint8_t *mac, tcpip_a
netif_init = tcpip_if_to_netif_init_fn(tcpip_if); netif_init = tcpip_if_to_netif_init_fn(tcpip_if);
assert(netif_init != NULL); assert(netif_init != NULL);
netif_add(esp_netif[tcpip_if], &ip_info->ip, &ip_info->netmask, &ip_info->gw, NULL, netif_init, tcpip_input); netif_add(esp_netif[tcpip_if], &ip_info->ip, &ip_info->netmask, &ip_info->gw, NULL, netif_init, tcpip_input);
#if ESP_GRATUITOUS_ARP
if (tcpip_if == TCPIP_ADAPTER_IF_STA || tcpip_if == TCPIP_ADAPTER_IF_ETH) {
netif_set_garp_flag(esp_netif[tcpip_if]);
}
#endif
} }
if (tcpip_if == TCPIP_ADAPTER_IF_AP) { if (tcpip_if == TCPIP_ADAPTER_IF_AP) {