Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiple IPv4 netmasks per interface #68419

Conversation

jukkar
Copy link
Member

@jukkar jukkar commented Feb 1, 2024

The netmask should be tied to the IPv4 address instead of being global for the network interface.

If there is only one IPv4 address specified to the network interface, nothing changes from user point of view. But if there are more than one IPv4 address / network interface, the netmask must be specified to each address separately.

This means that the net_if_ipv4_get_netmask() and net_if_ipv4_set_netmask() functions should not be used as they will only work reliably if there is only one IPv4 address in the network interface.

Instead new net_if_ipv4_get_netmask_by_addr() and net_if_ipv4_set_netmask_by_addr() should be used instead as they make sure that the netmask is tied to correct IPv4 address in the network interface.

No need to try to rush and try to get this to 3.6, existing functionality works for most of the use cases.

Copy link
Contributor

@rlubos rlubos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks, howerver we should get rid of those now deprecated functions usage within the codebase.
One of the users is recently added DHCPv4 server:
https://github.com/zephyrproject-rtos/zephyr/blob/main/subsys/net/lib/dhcpv4/dhcpv4_server.c#L1234
but in this particular case it should be straightforward fix, just take the netmask for the selected server_addr .

krish2718
krish2718 previously approved these changes Feb 2, 2024
@jukkar jukkar force-pushed the devel/support-multiple-ipv4-netmasks-per-interface branch 2 times, most recently from b780dea to 51052ef Compare February 2, 2024 14:23
@jukkar jukkar force-pushed the devel/support-multiple-ipv4-netmasks-per-interface branch 3 times, most recently from 7dc45fa to ed8ccb1 Compare February 5, 2024 12:29
The netmask should be tied to the IPv4 address instead of being
global for the network interface.

If there is only one IPv4 address specified to the network interface,
nothing changes from user point of view. But if there are more than
one IPv4 address / network interface, the netmask must be specified
to each address separately.

This means that net_if_ipv4_get_netmask() and net_if_ipv4_set_netmask()
functions should not be used as they only work reliably if there is
only one IPv4 address in the network interface.

The new net_if_ipv4_get_netmask_by_addr() and
net_if_ipv4_set_netmask_by_addr() functions should be used as they make
sure that the netmask is tied to correct IPv4 address in the network
interface.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Make sure that the tests work properly when each IPv4 address
in the network interface gets its own netmask.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
This commit deprecates these legacy netmask get/set routines

net_if_ipv4_set_netmask()
net_if_ipv4_set_netmask_by_index()
net_if_ipv4_get_netmask()

as they do not work well if there are multiple IPv4 address
assigned to the network interface.

User should use these functions instead

net_if_ipv4_set_netmask_by_addr()
net_if_ipv4_set_netmask_by_addr_by_index()
net_if_ipv4_get_netmask_by_addr()

as they make sure the netmask it bound to correct IPv4 address.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Make sure that the drivers use the new IPv4 netmask setting API.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Make sure that the samples use the new IPv4 netmask setting API.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Convert various array loops in the net_if.c to use the
ARRAY_FOR_EACH() macro. This makes the code more robust
as we do not need to keep track of the separate define
that tells the array size.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
No need to loop through network interface addresses, just
listen DHCPv4 bound event and use that as a condition to continue.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Convert various networking subsystem files to use ARRAY_FOR_EACH
macro to make the looping more robust.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
@jukkar jukkar force-pushed the devel/support-multiple-ipv4-netmasks-per-interface branch from ed8ccb1 to c2f238c Compare February 5, 2024 17:21
@aescolar aescolar added this to the v3.7.0 milestone Feb 6, 2024
@aescolar
Copy link
Member

aescolar commented Feb 6, 2024

Setting milestone as 3.7 as we are past the RC1 for 3.6. Please correct the milestone if you disagree

@aescolar aescolar added hwmv2-likely-conflict DNM until collab-hwmv2 has been merged and removed hwmv2-likely-conflict DNM until collab-hwmv2 has been merged labels Feb 26, 2024
@carlescufi carlescufi merged commit a943d7f into zephyrproject-rtos:main Mar 3, 2024
29 checks passed
@jukkar jukkar deleted the devel/support-multiple-ipv4-netmasks-per-interface branch March 4, 2024 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants