Skip to content

Commit c1f1b2a

Browse files
authored
Merge pull request #11339 from sathishm6/topic/pr-bct-auto-ip-fix
mbed-os/LwIP changes and fixes in auto-IP for Bonjour Conformance Test
2 parents a884c7c + a4aeee9 commit c1f1b2a

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

features/lwipstack/lwip/src/core/ipv4/lwip_autoip.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@
9494
static err_t autoip_arp_announce(struct netif *netif);
9595
static void autoip_start_probing(struct netif *netif);
9696

97+
/* static variables */
98+
static u8_t is_autoip_allocated = 0; /* Set when 'struct autoip' is allocated dynamically and assigned to 'netif' */
99+
97100
/**
98101
* @ingroup autoip
99102
* Set a statically allocated struct autoip to work with.
@@ -278,6 +281,7 @@ autoip_start(struct netif *netif)
278281
("autoip_start(): could not allocate autoip\n"));
279282
return ERR_MEM;
280283
}
284+
is_autoip_allocated = 1;
281285
/* store this AutoIP client in the netif */
282286
netif_set_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP, autoip);
283287
LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE, ("autoip_start(): allocated autoip"));
@@ -318,7 +322,7 @@ autoip_start_probing(struct netif *netif)
318322
* acquiring and probing address
319323
* compliant to RFC 3927 Section 2.2.1
320324
*/
321-
if (autoip->tried_llipaddr > MAX_CONFLICTS) {
325+
if (autoip->tried_llipaddr >= MAX_CONFLICTS) {
322326
autoip->ttw = RATE_LIMIT_INTERVAL * AUTOIP_TICKS_PER_SECOND;
323327
}
324328
}
@@ -353,6 +357,16 @@ autoip_stop(struct netif *netif)
353357
LWIP_ASSERT_CORE_LOCKED();
354358
if (autoip != NULL) {
355359
autoip->state = AUTOIP_STATE_OFF;
360+
/* If autoip is dynamically allocated in start, free autoip structure and reset autoip index in netif */
361+
if (is_autoip_allocated) {
362+
/* Reset the auto IP index and then free autoip structure */
363+
netif_set_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP, NULL);
364+
mem_free(autoip);
365+
autoip = NULL;
366+
is_autoip_allocated = 0;
367+
} else {
368+
autoip->tried_llipaddr = 0;
369+
}
356370
if (ip4_addr_islinklocal(netif_ip4_addr(netif))) {
357371
netif_set_addr(netif, IP4_ADDR_ANY4, IP4_ADDR_ANY4, IP4_ADDR_ANY4);
358372
}

features/lwipstack/lwipopts.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,13 @@
5757
#define BOTH_ADDR_TIMEOUT 0
5858
#endif
5959

60+
// Configurable DHCP timeout. DHCP timeout can be configured for specific usecase requirement.
61+
#ifdef MBED_CONF_LWIP_DHCP_TIMEOUT
62+
#define DHCP_TIMEOUT (MBED_CONF_LWIP_DHCP_TIMEOUT)
63+
#else
6064
#define DHCP_TIMEOUT 60
65+
#endif
66+
6167
#define LINK_TIMEOUT 60
6268

6369
#define PREF_IPV4 1

0 commit comments

Comments
 (0)