From 97b8e88e69d89059cb728da89d49208e596a63d6 Mon Sep 17 00:00:00 2001 From: sg Date: Tue, 19 Jul 2016 22:34:22 +0200 Subject: [PATCH] netif_set_addr(): when removing an address (setting address to ANY), we have to remove it *before* changing netmask/gw to ensure that tcp RST segment can be sent correctly --- src/core/netif.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/core/netif.c b/src/core/netif.c index 4a5b9864..fdf01926 100644 --- a/src/core/netif.c +++ b/src/core/netif.c @@ -305,10 +305,18 @@ void netif_set_addr(struct netif *netif, const ip4_addr_t *ipaddr, const ip4_addr_t *netmask, const ip4_addr_t *gw) { - netif_set_netmask(netif, netmask); - netif_set_gw(netif, gw); - /* set ipaddr last to ensure netmask/gw have been set when status callback is called */ - netif_set_ipaddr(netif, ipaddr); + if (ip4_addr_isany(ipaddr)) { + /* when removing an address, we have to remove it *before* changing netmask/gw + to ensure that tcp RST segment can be sent correctly */ + netif_set_ipaddr(netif, ipaddr); + netif_set_netmask(netif, netmask); + netif_set_gw(netif, gw); + } else { + netif_set_netmask(netif, netmask); + netif_set_gw(netif, gw); + /* set ipaddr last to ensure netmask/gw have been set when status callback is called */ + netif_set_ipaddr(netif, ipaddr); + } } #endif /* LWIP_IPV4*/