Merge branch 'bugfix/tw16287_tcp_send_succeed_after_station_disconnect' into 'master'

In STA mode, tcp_send cannot catch err after disconnect station

See merge request !1540
This commit is contained in:
Jiang Jiang Jian 2017-11-27 21:30:46 +08:00
commit a83fbd3364
2 changed files with 35 additions and 15 deletions

View file

@ -115,6 +115,23 @@ ip4_set_default_multicast_netif(struct netif* default_multicast_netif)
#endif /* LWIP_MULTICAST_TX_OPTIONS */ #endif /* LWIP_MULTICAST_TX_OPTIONS */
#ifdef LWIP_HOOK_IP4_ROUTE_SRC #ifdef LWIP_HOOK_IP4_ROUTE_SRC
bool ip4_netif_exist(const ip4_addr_t *src, const ip4_addr_t *dest)
{
struct netif *netif = NULL;
for (netif = netif_list; netif != NULL; netif = netif->next) {
/* is the netif up, does it have a link and a valid address? */
if (netif_is_up(netif) && netif_is_link_up(netif) && !ip4_addr_isany_val(*netif_ip4_addr(netif))) {
/* source netif and dest netif match? */
if (ip4_addr_netcmp(src, netif_ip4_addr(netif), netif_ip4_netmask(netif)) || ip4_addr_netcmp(dest, netif_ip4_addr(netif), netif_ip4_netmask(netif))) {
/* return false when both netif don't match */
return true;
}
}
}
return false;
}
/** /**
* Source based IPv4 routing hook function. This function works only * Source based IPv4 routing hook function. This function works only
* when destination IP is broadcast IP. * when destination IP is broadcast IP.
@ -122,24 +139,23 @@ ip4_set_default_multicast_netif(struct netif* default_multicast_netif)
struct netif * struct netif *
ip4_route_src_hook(const ip4_addr_t *dest, const ip4_addr_t *src) ip4_route_src_hook(const ip4_addr_t *dest, const ip4_addr_t *src)
{ {
struct netif *netif = NULL; struct netif *netif = NULL;
/* destination IP is broadcast IP? */ /* destination IP is broadcast IP? */
if ((src != NULL) && (dest->addr == IPADDR_BROADCAST)) { if ((src != NULL) && (dest->addr == IPADDR_BROADCAST)) {
/* iterate through netifs */ /* iterate through netifs */
for (netif = netif_list; netif != NULL; netif = netif->next) { for (netif = netif_list; netif != NULL; netif = netif->next) {
/* is the netif up, does it have a link and a valid address? */ /* is the netif up, does it have a link and a valid address? */
if (netif_is_up(netif) && netif_is_link_up(netif) && !ip4_addr_isany_val(*netif_ip4_addr(netif))) { if (netif_is_up(netif) && netif_is_link_up(netif) && !ip4_addr_isany_val(*netif_ip4_addr(netif))) {
/* source IP matches? */ /* source IP matches? */
if (ip4_addr_cmp(src, netif_ip4_addr(netif))) { if (ip4_addr_cmp(src, netif_ip4_addr(netif))) {
/* return netif on which to forward IP packet */ /* return netif on which to forward IP packet */
return netif; return netif;
}
} }
} }
} }
}
return netif; return netif;
} }
/** /**
@ -150,12 +166,16 @@ struct netif *
ip4_route_src(const ip4_addr_t *dest, const ip4_addr_t *src) ip4_route_src(const ip4_addr_t *dest, const ip4_addr_t *src)
{ {
if (src != NULL) { if (src != NULL) {
if (!ip4_addr_isany(src) && (ip4_netif_exist(src,dest) == false)) {
return NULL;
}
/* when src==NULL, the hook is called from ip4_route(dest) */ /* when src==NULL, the hook is called from ip4_route(dest) */
struct netif *netif = LWIP_HOOK_IP4_ROUTE_SRC(dest, src); struct netif *netif = LWIP_HOOK_IP4_ROUTE_SRC(dest, src);
if (netif != NULL) { if (netif != NULL) {
return netif; return netif;
} }
} }
return ip4_route(dest); return ip4_route(dest);
} }
#endif /* LWIP_HOOK_IP4_ROUTE_SRC */ #endif /* LWIP_HOOK_IP4_ROUTE_SRC */

View file

@ -1071,7 +1071,7 @@ tcp_output(struct tcp_pcb *pcb)
} }
#endif /* TCP_OVERSIZE_DBGCHECK */ #endif /* TCP_OVERSIZE_DBGCHECK */
err = tcp_output_segment(seg, pcb); err = tcp_output_segment(seg, pcb);
if ((err != ERR_OK) && (err != ERR_RTE)) { if (err != ERR_OK) {
/* segment could not be sent, for whatever reason */ /* segment could not be sent, for whatever reason */
pcb->flags |= TF_NAGLEMEMERR; pcb->flags |= TF_NAGLEMEMERR;
return err; return err;