|
94 | 94 | static err_t autoip_arp_announce(struct netif *netif); |
95 | 95 | static void autoip_start_probing(struct netif *netif); |
96 | 96 |
|
| 97 | +/* static variables */ |
| 98 | +static u8_t is_autoip_allocated = 0; /* Set when 'struct autoip' is allocated dynamically and assigned to 'netif' */ |
| 99 | + |
97 | 100 | /** |
98 | 101 | * @ingroup autoip |
99 | 102 | * Set a statically allocated struct autoip to work with. |
@@ -278,6 +281,7 @@ autoip_start(struct netif *netif) |
278 | 281 | ("autoip_start(): could not allocate autoip\n")); |
279 | 282 | return ERR_MEM; |
280 | 283 | } |
| 284 | + is_autoip_allocated = 1; |
281 | 285 | /* store this AutoIP client in the netif */ |
282 | 286 | netif_set_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP, autoip); |
283 | 287 | LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE, ("autoip_start(): allocated autoip")); |
@@ -318,7 +322,7 @@ autoip_start_probing(struct netif *netif) |
318 | 322 | * acquiring and probing address |
319 | 323 | * compliant to RFC 3927 Section 2.2.1 |
320 | 324 | */ |
321 | | - if (autoip->tried_llipaddr > MAX_CONFLICTS) { |
| 325 | + if (autoip->tried_llipaddr >= MAX_CONFLICTS) { |
322 | 326 | autoip->ttw = RATE_LIMIT_INTERVAL * AUTOIP_TICKS_PER_SECOND; |
323 | 327 | } |
324 | 328 | } |
@@ -353,6 +357,16 @@ autoip_stop(struct netif *netif) |
353 | 357 | LWIP_ASSERT_CORE_LOCKED(); |
354 | 358 | if (autoip != NULL) { |
355 | 359 | 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 | + } |
356 | 370 | if (ip4_addr_islinklocal(netif_ip4_addr(netif))) { |
357 | 371 | netif_set_addr(netif, IP4_ADDR_ANY4, IP4_ADDR_ANY4, IP4_ADDR_ANY4); |
358 | 372 | } |
|
0 commit comments