Commit graph

27 commits

Author SHA1 Message Date
Robert Lubos d9a979f2dc net: lib: dhcpv4: Fix typo in logs
DHCPv4 was misspelled in logs.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-06-24 12:41:38 -04:00
Rex Chen dcf42917c5 net: lib: dhcpv4: Add check for input parameter of echo_reply_handler
For station and internal AP coexist case, station connected to
external AP, ping from station to external AP cause cpu hang.

Internal AP dhcpv4 server register handler echo_reply_handler
on icmp handler by net_icmp_init_ctx for dhcp server snoop
feature. Ping also register handler handle_ipv4_echo_reply on
icmp handler for ping cmd. If no external station connect to
internal AP, input parameter ‘user_data’ of function
echo_reply_handler is NULL. When we trigger ping process,
icmp_call_handlers fetch all handlers from icmp handler
if receive any ICMP packet, so echo_reply_handler be called,
but input parameter is NULL, cause CPU hang.
Add input parameters check to fix this issue.

Signed-off-by: Rex Chen <rex.chen_1@nxp.com>
2024-06-18 11:07:09 +02:00
Robert Lubos 0d3a021379 net: dhcpv4: Reset Renewal/Rebinding times on ACK
In case no Renewal/Rebinding times have been provided the server via
DHCP options, we should reset their values on ACK, so that the client
can recalculate the defaults. This is important, as the lease time may
change, so we should recalculate default T1/T2 timeout based on the new
lease time value.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-06-13 17:50:52 +02:00
Robert Lubos 4d4391bf1c net: dhcpv4: Reimplement RENEW/REBIND logic according to RFC2131
DHCP Request retransmission in RENEW and REBIND states was not
compliant with RFC2131.

The retransmission interval should not be calculated as in REQUESTING
state in such case, but rather calculated based on the remaining T2
or lease time (depending on current state).

RFC doesn't also mention any retransmission count limit for those
states. The client should retransmit the REQUEST until T2 or lease
expiry time are reached.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-06-13 17:50:52 +02:00
Robert Lubos 80339ac4ee net: dhcpv4: Add support for conflict detection
In case a conflict was detected on a DHCP-assigned address, send a
Decline message to the server and start over.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-06-10 00:59:28 -07:00
Jordan Yates 0f56974c9d net: lib: dhcpv4: goto INIT on IF down, not RENEWING
When the interface goes down, the safest thing to do is to return to
the INIT state, as there is no guarantee that any state is preserved
upon the interface coming back up again.

This is particularly the case with WiFi.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2024-05-22 21:34:44 -04:00
Robert Lubos f77c7a3d05 net: dhcpv4_server: Fix positive error codes returned
errno values are positive, therefore they should be negated when
assigned as return values for net_dhcpv4_server_start().

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-04-10 07:42:21 -04:00
Fin Maaß a1ea9b7351 net: use appropriate sys_randX_get()
use the appropriate sys_randX_get() instant
of always sys_rand32_get().

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2024-04-05 12:28:46 +02:00
Robert Lubos 323f1f81b9 net: dhcpv4_server: Add option to NAK Request from unrecognized client
Zephyr's DHCPv4 server does not implement persistent storage of address
leases. In result, all leases are lost on reboot, which can cause
delays with clients starting in INIT-REBOOT state and thus sending
(potentially several) Requests before attempting full Discover-Request
procedure.
Add option to override RFC defined behavior, which states that if we
don't recognize the client sending the Request, the server shall remain
silent. Enabling that option allows the server to send NAK reply in case
client is not recognized, informing the client it should proceed with
full procedure.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-03-22 10:24:15 +01:00
Robert Lubos fd113b7102 net: dhcpv4_server: Include client ID in server responses
RFC6842 updated RFC2131 in terms of including client ID option in
responses sent from the server. According to that RFC, the server MUST
include the client ID option in Offer/Ack/Nak replies, if it was
provided by the client.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-03-22 10:24:15 +01:00
Robert Lubos 41ffc5fabb net: dhcpv4_server: Improve DHCP Request retransmission handling
In case ACK from the server was lost, we'd not reply Request
retransmissions, as the lease state is already in allocated state on the
server side. Therefore we also need to allow to reply with ACK in such
case.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-03-22 10:24:15 +01:00
Robert Lubos 50e0807c0a net: dhcpv4_server: Increase reserved address timeout
5 seconds turned out to be too short timeout in case retransmissions
kicked in at DHCP level, hence increase the timeout.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-03-22 10:24:15 +01:00
Jukka Rissanen 7072e75162 net: dhcpv4: Network interface netmask was set too early
When we receive the subnet mask option from the server, we
cannot yet set the netmask to the network interface as the
mask is tied to the IP address we received from the server.
We need to delay the setting of netmask until we have added
the requested IP address to the interface.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-03-08 18:04:35 +01:00
Fin Maaß 0d776d39bb net: dhcpv4: set log backend net ip via option
Adds the option to set the log_backend_net ip via dhcpv4
option 7.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2024-03-08 15:18:30 +00:00
Fin Maaß c148dc15fd net: dhcpv4: add vendor specific option callback
In certain scenarios, it may be necessary to get values of additional
options from the application layer. With this patch, this can be
accomplished by registering a callback with the DHCP client.

This change has been tested using the posix build in qemu.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2024-03-05 10:22:21 -05:00
Jukka Rissanen 1b0f9e865e net: ipv4: Make netmask IPv4 address specific
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>
2024-03-03 18:58:29 +01:00
Fin Maaß 3be6557078 net: dhcpv4: set sntp ip via option
Adds the option to set the ntp address ip via
dhcpv4 option 42 (Network Time Protocol Servers).

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2024-02-28 18:03:53 +00:00
Fin Maaß 1f2a3c46df net: dhcpv4: initialization of option_callbacks list
Initialize sys_slist_t option_callbacks statically.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2024-02-27 14:45:40 +01:00
Fin Maaß 866c804cb8 net: dhcpv4: option callback check value explicitly
Check the value of net_dhcpv4_add_option_callback()
and net_dhcpv4_remove_option_callback() explicitly.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2024-02-27 14:45:40 +01:00
Robert Lubos 9cb21e695f net: dhcpv4_server: Apply range limits for Kconfig options
Apply ranges to DHCPv4 server timeout Kconfig options, so that it cannot
be set to a negative value by mistake.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-02-26 11:41:35 +00:00
Robert Lubos e28428caae net: dhcpv4_server: Improve declined addresses management
In case conflict is detected (either due to receiving Decline message or
due to ICMP probe getting reply), the conflicting address becomes
blocked for further use.

Although the RFC is not specific about how long should the address be
blocked, it make sense to implement some fallback mechanisms to reuse
blocked addresses in the server, otherwise, after longer period of
operation, it may run out of usable address.

This commit adds a timeout for declined addresses, so that by default
the address is marked back as "free" after 24 hrs (default lease time).
It also implements a mechanism, which allows to re-use the oldest
declined entry in case the server runs out of fresh addresses to assign.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-02-26 11:41:35 +00:00
Fin Maaß 652c2ae1f5 net: dhcpv4: Add vendor class identifier option
Adds the funktion to set the DHCPv4 option 60
(Vendor class identifier) via Kconfig.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2024-02-26 12:05:03 +01:00
Fin Maaß 7206737450 net: dhcpv4: request options from server
If a option callback is enabled, this option
should also be requested from the DHCPv4 server.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2024-02-26 11:44:45 +01:00
Robert Lubos 3c76ff9a8c net: dhcpv4_server: Implement ICMP probing of offered addresses
DHCPv4 server will send an ICMP probe (echo request) for the requested
address before replying with DHCP Offer, unless probing is disabled in
Kconfig.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-02-02 12:42:44 +01:00
Robert Lubos a147ac9a47 net: dhcpv4_server: Improve address pool range validation
Not only check if the address pool belongs to the same subnet as the
server, but also that it does not overlap with the server address -
otherwise the server might end up assigning its own address.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-01-31 12:06:23 +00:00
Robert Lubos 19722aa8e8 net: dhcpv4: Move DHCPv4 files to lib directory
As discussed during DHCPv4 server integration, group DHCPv4 client files
with DHCPv4 server in a single lib directory.

Renamed internal "dhcpv4.h" header to "dhcpv4_internal.h" so that it's
not confused with the public "dhcpv4.h" header.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-01-29 13:47:05 +01:00
Robert Lubos 1e08bbd543 net: dhcpv4: Implement DHCPv4 server
Add basic socket-based implementation of DHCPv4 sever.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-01-19 10:15:23 +00:00