lwip: Enable IPV6_ONLY option for UDP sockets (BSD & netconn)

* setsockopt(s, IPV6_ONLY, &one, sizeof(int)) will disable IPV6-only
  mode. Incoming/outgoing IPV4 packets are dropped.

* Otherwise, sockets bound to IPV6_ANY_ADDR can receive unicast packets
  for IPV4 or IPV6.

* sendto() a IPV6-mapped-IPV4 address on a UDP socket works correctly
  (not supported for RAW or TCP sockets.)

* getaddrinfo() option AI_V4MAPPED is implemented.

As well as extending support to TCP & RAW, there is some potential improvement
to dropping incoming packets - the drop happens a bit late in the process and
there is no "ICMP port unreachable" response sent.
This commit is contained in:
Angus Gratton
2017-07-07 19:27:00 +08:00
committed by Angus Gratton
parent 961180617e
commit 04a2cefb26
5 changed files with 67 additions and 11 deletions

View File

@@ -261,7 +261,7 @@ lwip_freeaddrinfo(struct addrinfo *ai)
* @param res pointer to a pointer where to store the result (set to NULL on failure)
* @return 0 on success, non-zero on failure
*
* @todo: implement AI_V4MAPPED, AI_ADDRCONFIG
* @todo: implement AI_ADDRCONFIG
*/
int
lwip_getaddrinfo(const char *nodename, const char *servname,
@@ -330,6 +330,9 @@ lwip_getaddrinfo(const char *nodename, const char *servname,
type = NETCONN_DNS_IPV4;
} else if (ai_family == AF_INET6) {
type = NETCONN_DNS_IPV6;
if (hints->ai_flags & AI_V4MAPPED) {
type = NETCONN_DNS_IPV6_IPV4;
}
}
#endif /* LWIP_IPV4 && LWIP_IPV6 */
err = netconn_gethostbyname_addrtype(nodename, &addr, type);
@@ -346,6 +349,14 @@ lwip_getaddrinfo(const char *nodename, const char *servname,
}
}
#if LWIP_IPV4 && LWIP_IPV6
if (ai_family == AF_INET6 && (hints->ai_flags & AI_V4MAPPED)
&& IP_GET_TYPE(&addr) == IPADDR_TYPE_V4) {
/* Convert native V4 address to a V4-mapped IPV6 address */
ip_addr_make_ip4_mapped_ip6(&addr, &addr);
}
#endif
total_size = sizeof(struct addrinfo) + sizeof(struct sockaddr_storage);
if (nodename != NULL) {
namelen = strlen(nodename);