Modify IPv6 functionality compatible with lwip2.1.2

This commit is contained in:
xueyunfei 2019-07-10 03:29:32 -04:00
parent 596209de69
commit f29ff2c552
5 changed files with 29 additions and 12 deletions

@ -1 +1 @@
Subproject commit bafc54f69b671f368d7b996d1668b7bd4be55193
Subproject commit 61d840ff4778f4946c8743f7e412345abcd537f1

View file

@ -740,6 +740,14 @@ esp_err_t tcpip_adapter_set_default_wifi_handlers();
*/
esp_err_t tcpip_adapter_clear_default_wifi_handlers();
/**
* @brief Search nefit index through netif interface
* @param[in] tcpip_if Interface to search for netif index
* @return
* - netif_index on success
* - -1 if an invalid parameter is supplied
*/
int tcpip_adapter_get_netif_index(tcpip_adapter_if_t tcpip_if);
#ifdef __cplusplus
}

View file

@ -29,6 +29,7 @@
#include "lwip/netif.h"
#if LWIP_DNS /* don't build if not configured for use in lwipopts.h */
#include "lwip/dns.h"
#include "lwip/netif.h"
#endif
#include "netif/wlanif.h"
#include "netif/ethernetif.h"
@ -1258,4 +1259,12 @@ bool tcpip_adapter_is_netif_up(tcpip_adapter_if_t tcpip_if)
}
}
int tcpip_adapter_get_netif_index(tcpip_adapter_if_t tcpip_if)
{
if (tcpip_if >= TCPIP_ADAPTER_IF_MAX || esp_netif[tcpip_if] == NULL) {
return -1;
}
return netif_get_index(esp_netif[tcpip_if]);
}
#endif /* CONFIG_TCPIP_LWIP */

View file

@ -71,7 +71,8 @@ menu "Example Configuration"
Multicast socket can bind to default interface, or all interfaces.
config EXAMPLE_MULTICAST_LISTEN_ALL_IF
bool "All interfaces"
bool "All interfaces (IPV4 only)"
depends on !EXAMPLE_IPV6_ONLY
config EXAMPLE_MULTICAST_LISTEN_DEFAULT_IF
bool "Default interface"

View file

@ -170,7 +170,7 @@ err:
static int create_multicast_ipv6_socket()
{
struct sockaddr_in6 saddr = { 0 };
u8_t netif_index = EXAMPLE_INTERFACE;
int netif_index;
struct in6_addr if_inaddr = { 0 };
struct ip6_addr if_ipaddr = { 0 };
struct ipv6_mreq v6imreq = { 0 };
@ -211,6 +211,12 @@ static int create_multicast_ipv6_socket()
}
#endif // LISTEN_ALL_IF
// search for netif index
netif_index = tcpip_adapter_get_netif_index(EXAMPLE_INTERFACE);
if(netif_index < 0) {
ESP_LOGE(V6TAG, "Failed to get netif index");
goto err;
}
// Assign the multicast source interface, via its IP
err = setsockopt(sock, IPPROTO_IPV6, IPV6_MULTICAST_IF, &netif_index,sizeof(uint8_t));
if (err < 0) {
@ -240,14 +246,6 @@ static int create_multicast_ipv6_socket()
// this is also a listening socket, so add it to the multicast
// group for listening...
// Configure source interface
#if LISTEN_ALL_IF
v6imreq.imr_interface.s_addr = IPADDR_ANY;
#else
v6imreq.ipv6mr_interface = EXAMPLE_INTERFACE;
/* inet6_addr_from_ip6addr(&v6imreq.ipv6mr_interface, &if_ipaddr);*/
#endif // LISTEN_ALL_IF
#ifdef CONFIG_EXAMPLE_IPV6
// Configure multicast address to listen to
err = inet6_aton(MULTICAST_IPV6_ADDR, &v6imreq.ipv6mr_multiaddr);
@ -261,7 +259,8 @@ static int create_multicast_ipv6_socket()
if (!ip6_addr_ismulticast(&multi_addr)) {
ESP_LOGW(V6TAG, "Configured IPV6 multicast address '%s' is not a valid multicast address. This will probably not work.", MULTICAST_IPV6_ADDR);
}
// Configure source interface
v6imreq.ipv6mr_interface = (unsigned int)netif_index;
err = setsockopt(sock, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP,
&v6imreq, sizeof(struct ipv6_mreq));
if (err < 0) {