Fixed LWIPStack socket_sendto member to fail if interface IP4/6 version differ from destination adress IP version

pull/10834/head
Tymoteusz Bloch 2019-06-13 16:34:50 +02:00
parent fc645bc3ed
commit b272c5f149
2 changed files with 16 additions and 7 deletions

View File

@ -34,6 +34,7 @@
#include "lwip/dns.h" #include "lwip/dns.h"
#include "lwip/udp.h" #include "lwip/udp.h"
#include "lwip/raw.h" #include "lwip/raw.h"
#include "lwip/netif.h"
#include "lwip/lwip_errno.h" #include "lwip/lwip_errno.h"
#include "lwip-sys/arch/sys_arch.h" #include "lwip-sys/arch/sys_arch.h"
@ -493,7 +494,16 @@ nsapi_size_or_error_t LWIP::socket_sendto(nsapi_socket_t handle, const SocketAdd
if (!convert_mbed_addr_to_lwip(&ip_addr, &addr)) { if (!convert_mbed_addr_to_lwip(&ip_addr, &addr)) {
return NSAPI_ERROR_PARAMETER; return NSAPI_ERROR_PARAMETER;
} }
struct netif *netif_ = netif_get_by_index(s->conn->pcb.ip->netif_idx);
if (!netif_) {
netif_ = &default_interface->netif;
}
if (netif_) {
if ((addr.version == NSAPI_IPv4 && !get_ipv4_addr(netif_)) ||
(addr.version == NSAPI_IPv6 && !get_ipv6_addr(netif_))) {
return NSAPI_ERROR_PARAMETER;
}
}
struct netbuf *buf = netbuf_new(); struct netbuf *buf = netbuf_new();
err_t err = netbuf_ref(buf, data, (u16_t)size); err_t err = netbuf_ref(buf, data, (u16_t)size);

View File

@ -59,9 +59,10 @@ nsapi_error_t LWIP::err_remap(err_t err)
} }
} }
#if LWIP_IPV4
const ip_addr_t *LWIP::get_ipv4_addr(const struct netif *netif) const ip_addr_t *LWIP::get_ipv4_addr(const struct netif *netif)
{ {
#if LWIP_IPV4
if (!netif_is_up(netif)) { if (!netif_is_up(netif)) {
return NULL; return NULL;
} }
@ -69,14 +70,13 @@ const ip_addr_t *LWIP::get_ipv4_addr(const struct netif *netif)
if (!ip4_addr_isany(netif_ip4_addr(netif))) { if (!ip4_addr_isany(netif_ip4_addr(netif))) {
return netif_ip_addr4(netif); return netif_ip_addr4(netif);
} }
#endif
return NULL; return NULL;
} }
#endif
#if LWIP_IPV6
const ip_addr_t *LWIP::get_ipv6_addr(const struct netif *netif) const ip_addr_t *LWIP::get_ipv6_addr(const struct netif *netif)
{ {
#if LWIP_IPV6
if (!netif_is_up(netif)) { if (!netif_is_up(netif)) {
return NULL; return NULL;
} }
@ -87,10 +87,9 @@ const ip_addr_t *LWIP::get_ipv6_addr(const struct netif *netif)
return netif_ip_addr6(netif, i); return netif_ip_addr6(netif, i);
} }
} }
#endif
return NULL; return NULL;
} }
#endif
bool LWIP::is_local_addr(const ip_addr_t *ip_addr) bool LWIP::is_local_addr(const ip_addr_t *ip_addr)
{ {