zephyrproject-rtos / zephyr

Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
https://docs.zephyrproject.org
Apache License 2.0
10.67k stars 6.52k forks source link

tcp/ip: ipv6 prefix is not configured by default #77401

Closed hakehuang closed 1 month ago

hakehuang commented 1 month ago

Describe the bug

take sample/net/vlan as example, the ipv6 is null, see below net status log

IPv6 prefixes (max 2):
        <none>

Steps to reproduce

west build -b mimxrt1170_evk/mimxrt1176/cm7
west flash

Expected behavior

the ipv6 prefix shall has a default value, however it is empty. If an IPv6 Global-unicast-address is set, the IPv6-prefix should also be set accordingly.

Impact

ipv6 routing function is implement wrongly.

Logs and console output

Interface ? (0x80000b50) (Virtual) [2]
==================================
Virtual name : VLAN to 1
Attached  : 1 (Ethernet / 0x80000a40)
Link addr : 02:04:9F:D1:36:55
MTU       : 1500
Flags     : NO_AUTO_START,IPv4,IPv6
Device    : VLAN_0 (0x60025758)
VLAN tag  : 100 (0x064)
IPv6 unicast addresses (max 5):
        2001:db8:100::1 manual preferred infinite
        fe80::4:9fff:fed1:3655 autoconf preferred infinite
IPv6 multicast addresses (max 5):
        ff02::1
        ff02::1:ff00:1
        ff02::1:ffd1:3655
**IPv6 prefixes (max 2):
        <none>**
IPv6 hop limit           : 64
IPv6 base reachable time : 30000
IPv6 reachable time      : 32435
IPv6 retransmit timer    : 0
IPv4 unicast addresses (max 1):
        192.168.102.111/255.255.255.0 manual preferred infinite
IPv4 multicast addresses (max 2):

Environment (please complete the following information):

Additional context

a simple trial is add below for samples/net/vlan application

adding below lines, after the

                if (!net_if_ipv6_prefix_add(vlan, &addr6, 64, NET_IPV6_ND_INFINITE_LIFETIME)) {
                        LOG_ERR("Cannot add %s with prefix_len %d to interface %p",
                                        ipv6_addr, 64, vlan);
                        return -EINVAL;
                }

after the

                ifaddr = net_if_ipv6_addr_add(vlan, &addr6,
                                              NET_ADDR_MANUAL, 0);
                if (!ifaddr) {
                        LOG_ERR("Cannot add %s to interface %p",
                                ipv6_addr, vlan);
                        return -EINVAL;
                }

then the net status will show below

Virtual name : VLAN to 1
Attached  : 1 (Ethernet / 0x80000a40)
Link addr : 02:04:9F:20:88:38
MTU       : 1500
Flags     : NO_AUTO_START,IPv4,IPv6
Device    : VLAN_0 (0x60025744)
VLAN tag  : 100 (0x064)
IPv6 unicast addresses (max 5):
        2001:db8:100::1 manual preferred infinite
        fe80::4:9fff:fe20:8838 autoconf preferred infinite
IPv6 multicast addresses (max 5):
        ff02::1
        ff02::1:ff00:1
        ff02::1:ff20:8838
IPv6 prefixes (max 2):
        2001:db8:100::1/64 infinite
IPv6 hop limit           : 64
IPv6 base reachable time : 30000
IPv6 reachable time      : 44682
IPv6 retransmit timer    : 0
IPv4 unicast addresses (max 1):
        192.168.102.111/255.255.255.0 manual preferred infinite
IPv4 multicast addresses (max 2):
        224.0.0.1
IPv4 gateway : 0.0.0.0
hakehuang commented 1 month ago

add @shrek-wang who initially identify this issue

hakehuang commented 1 month ago

this issue is related to #77399

jukkar commented 1 month ago

Usually the prefixes are set when received by router advertisement message. I suppose we can set those manually when adding static addresses. Please send a PR to change the sample.

shrek-wang commented 1 month ago

Without a prefix/mask to the interface, the 'net_data_send()' will go to a different branch in 'net_ipv6_prepare_for_send()'. Because the 2 nodes are in the same VLAN, we expect it to go the 'onlink' branch but it goes to the 'try_send'. That's why we think this makes no much sense and submit the ticket. Will prepare a PR for the sample.

carlescufi commented 1 month ago

@shrek-wang this is a medium-priority issue, so just following-up. Do you still plan to send a PR?

shrek-wang commented 1 month ago

@shrek-wang this is a medium-priority issue, so just following-up. Do you still plan to send a PR?

Yes, will send a PR in a few days. Was busy last week.