esp-idf icon indicating copy to clipboard operation
esp-idf copied to clipboard

Static ip address of IPV6 (IDFGH-11369)

Open ElieSKickMaker opened this issue 2 years ago • 8 comments

Answers checklist.

  • [X] I have read the documentation ESP-IDF Programming Guide and the issue is not addressed there.
  • [X] I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
  • [X] I have searched the issue tracker for a similar issue and not found a similar issue.

IDF version.

V4.4.1

Operating System used.

Windows

How did you build your project?

Command line with Make

If you are using Windows, please specify command line type.

None

What is the expected behavior?

Is it possible to have a static address on IPV6 ?
On the example with ipv4 it's using esp_netif_set_ip_info but the structure esp_netif_ip_info_t is only for ipv4. For IPV6 the strucutre is esp_netif_ip6_info_t;

What is the actual behavior?

Not working

Steps to reproduce.

Code not working :

/* stop DHCP client*/
		ESP_ERROR_CHECK(esp_netif_dhcpc_stop(eth_netif)) ;

        #if CONFIG_IPV6_STATIC
        ESP_LOGI(TAG, "Set IPV6 static address:%s", CONFIG_IPV6_STATIC_ADDR);
        /* assign a static IP to the ETH network interface */
        esp_netif_ip6_info_t static_ipv6;
        memset(&static_ipv6, 0x00, sizeof(static_ipv6)) ;
        ip6addr_aton(CONFIG_IPV6_STATIC_ADDR, &static_ipv6.ip);
        ESP_ERROR_CHECK(esp_netif_set_ip_info(eth_netif, &static_ipv6)) ;  
        /* assign a static DNS to the ETH network interface */
       
        esp_netif_dns_info_t dns_info;
        ip6addr_aton(CONFIG_IPV6_STATIC_DNS_ADDR, &static_ipv6.ip);
                      dns_info.ip.type = IPADDR_TYPE_V6;
        ESP_ERROR_CHECK(esp_netif_set_dns_info(eth_netif, ESP_NETIF_DNS_MAIN, &dns_info)); 

Build or installation Logs.

No response

More Information.

No response

ElieSKickMaker avatar Nov 02 '23 10:11 ElieSKickMaker

Hello @espressif-abhikroy , do you need more informations to provide any help ? Thansk you

ghost avatar Nov 13 '23 09:11 ghost

To be able to add an ipv6 address to a esp-netif try using

esp_err_t esp_netif_add_ip6_address(esp_netif_t *esp_netif, const ip_event_add_ip6_t *addr);

abhik-roy85 avatar Nov 13 '23 10:11 abhik-roy85

Hello @espressif-abhikroy , Thanks for your help but I've also tested it and I get an error, "Invalid static ip" :

`#define CONFIG_IPV6_STATIC_ADDR "2001:861:3a00:be40::2791:fa50"`

esp_netif_ip6_info_t ip6_addr = { 0 };
        ip6addr_aton(CONFIG_IPV6_STATIC_ADDR, &ip6_addr.ip);
        ESP_ERROR_CHECK(netif_add_ip6_address(eth_netif, (ip6_addr_t *)&ip6_addr.ip, 0));

        esp_netif_dns_info_t dns_info;
        ip6addr_aton(CONFIG_IPV6_STATIC_DNS_ADDR, &dns_info.ip.u_addr.ip6.addr);
        dns_info.ip.type = IPADDR_TYPE_V6;
        ESP_ERROR_CHECK(esp_netif_set_dns_info(eth_netif, ESP_NETIF_DNS_MAIN, &dns_info)); 

image

image

this error is in the file esp_netif\esp_netif_handlers.c and it's the return of the function

esp_netif_is_valid_static_ip

it's normal because it's only checking if it's an ip4 format or not ...

ghost avatar Nov 13 '23 13:11 ghost

Hi @ElieSKickMaker, Please try replacing the following code

esp_netif_ip6_info_t ip6_addr = { 0 };
        ip6addr_aton(CONFIG_IPV6_STATIC_ADDR, &ip6_addr.ip);
        ESP_ERROR_CHECK(netif_add_ip6_address(eth_netif, (ip6_addr_t *)&ip6_addr.ip, 0));

with

    esp_netif_ip6_info_t ip6_addr = { 0 };
    ip6addr_aton(CONFIG_IPV6_STATIC_ADDR, (ip6_addr_t *)&ip6_addr.ip);
    struct netif *lwip_netif = esp_netif_get_netif_impl(eth_netif);

    ESP_ERROR_CHECK(netif_add_ip6_address(lwip_netif, (ip6_addr_t *)&ip6_addr.ip, 0));

netif_add_ip6_address() is an lwip api and doesn't accept esp_netif.

You will also need to include

#include "lwip/netif.h"
#include "esp_netif_net_stack.h"

abhik-roy85 avatar Nov 14 '23 08:11 abhik-roy85

esp_err_t esp_netif_add_ip6_address(esp_netif_t *esp_netif, const esp_ip6_addr_t addr, bool preferred) 
esp_err_t esp_netif_remove_ip6_address(esp_netif_t *esp_netif, const esp_ip6_addr_t *addr)

has beed added to master.

abhik-roy85 avatar Feb 05 '24 09:02 abhik-roy85

It's not in de documentation (yet) (5.2.2). That's probably because it's mentioned in a private header (esp_netif_private.h). Please amend.

eriksl avatar Jun 18 '24 09:06 eriksl

It's not in de documentation (yet) (5.2.2). That's probably because it's mentioned in a private header (esp_netif_private.h). Please amend.

@espressif-abhikroy Any update for above comment? I think 325a8d7a6ea67c7bea1f99bc39d2dcd38780c1bc needs backport to stable releases to fix this issue.

AxelLin avatar Jul 31 '24 01:07 AxelLin

Thanks for pointing that out. I'm currently working on backporting the changes from 325a8d7 to the stable releases. I'll keep you updated on the progress.

abhik-roy85 avatar Jul 31 '24 11:07 abhik-roy85

It's not in de documentation (yet) (5.2.2). That's probably because it's mentioned in a private header (esp_netif_private.h). Please amend.

v5.2 fix: 8809589cf74a6d0f7ed27ae84dd44a834bcfc5c8

AxelLin avatar Nov 05 '24 07:11 AxelLin