As the zsock_recv_dgram() is rather large, remove the inline
keyword from it and let compiler to decide what to do with it.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Print the socket descriptor and interface after bounding it
successfully in order to help to figure out what sockets are
bind to one specific interface.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Restore only the socket descriptor that we marked as -1 after running
the work related to that socket. Earlier we tried to restore the whole
global array of descriptors which could go wrong and is not needed
as we only support synchronous work.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
The variable block_len in function coap_next_block_for_option()
can be used uninitialized in case of empty packet in
coap_packet_get_payload(). Mute the compiler warning with
default value of 0.
Signed-off-by: Dave Lacerte <lacerte.dave@hydroquebec.com>
The RFC1122 section 3.3.6 says we SHOULD drop the packets if L2 address
is brodcast but L3 address is unicast, but we had seen some Wi-Fi access
points in the field not conforming to that, and DHCP offer is dropped
due to this and causes Wi-Fi connectivity issues.
As the RFC saus it's SHOULD and not a MUST, add a config option to allow
such packets, disabled by default.
Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
Tickless mode is refactored to use zvfs_eventfd,
but the Kconfig dependencies were not updated.
Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
The socket service restarts whenever a new socket is registered.
This is triggered via zvfs_eventfd_write(ctx.events[0].fd, 1),
but the restart flag (ctx.events[0].revents) is not properly cleared,
causing unintended repeated restarts and skipped socket processing.
Detecting socket restart is done after the socket fd has processed its
data, so the socket doesn't lose its data. Ensure the socket service
clears its restart flag (ctx.events[0].revents = 0) immediately after
detecting a restart event, preventing unnecessary restarts.
Fixes#81813
Signed-off-by: Dominic Moffat <dom@illysky.com>
The current DNS caching logic is not aware of the IP address version.
If there is a cached address for a query, the caller of
dns_get_addr_info() will receive that address, even if it is not the
same version as the caller requested. For example:
- dns_get_addr_info() is called to resolve an IPv4 address
- the DNS client caches the IPv4 address that was received
- dns_get_addr_info() is called to resolve an IPv6 address
- the DNS client sees that there is a cached IPv4 address for the
given query
- the DNS client does not check that the cached address is of the
requested version (IPv6)
- the cached IPv4 address is returned from dns_get_addr_info()
This changes the DNS client to check IP address version when searching
cached addresses.
Signed-off-by: Noah Olson <noah@wavelynx.com>
The offset in post-write callback is incorrect for TLV format as
the first data block contain TLV header. This fix is replacing
reamaning for offset in opaque context struct and passing it to
post-write and validation callback.
The fix also corrects the offset in pull context as it was pointing
at the end of the block processed data and not on the block context
prior to processing.
Signed-off-by: Dave Lacerte <lacerte.dave@hydroquebec.com>
Since a separate CONFIG_NET_TC_RX_SKIP_FOR_HIGH_PRIO was introduced for
RX TC queues, CONFIG_NET_TC_SKIP_FOR_HIGH_PRIO became ambiguous,
rename it to CONFIG_NET_TC_TX_SKIP_FOR_HIGH_PRIO and deprecate the old
config.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
The family and proto type was not set for the IPv4 autoconf ARP packets.
Since those should be set for all ARP packets, just move the code
outside of the if block.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
There is no need to if-def away the net-stats function since there is a
shim available now.
Signed-off-by: Cla Mattia Galliard <cla-mattia.galliard@zuehlke.com>
lwm2m_gw_handle_req() function logic expects that at least one URI
option was found, therefore add an extra check to return the function
early if that isn't the case.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
If VLAN count is set to 0, then only priority tagged VLAN frames
that have tag value 0 can be received. Also this means that VLAN
interfaces are not created which can save memory if you do not need
to receive any other VLAN frames than those tagged with value 0.
Fixes#84023
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Ensure that all packets are no longer used by ethernet_recv after it was
consumed by the l3-handler.
Signed-off-by: Cla Mattia Galliard <cla-mattia.galliard@zuehlke.com>
`lwm2m_send_message_async` returns critical errors which are not handled in
many cases. The function can return -ENOMEM, -EPERM or other error codes
from functions called.
Signed-off-by: Marc Lasch <marc.lasch@husqvarnagroup.com>
Add a configuration option to skip the rx-queues for high priority packets
analogously to the tx-side.
Signed-off-by: Cla Mattia Galliard <cla-mattia.galliard@zuehlke.com>
To avoid starvation of a traffic class by another, limit the maximum amount
of packets, that can sit in a single traffic-class-fifo to a fraction of
the maximum amount of available packets. In the tx-case also reserve
packets for direct sending, in the case, where
CONFIG_NET_TC_SKIP_FOR_HIGH_PRIO is enabled.
Signed-off-by: Cla Mattia Galliard <cla-mattia.galliard@zuehlke.com>
The event monitor did not handled IPv4 multicast address
addition or deletion information.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
To simplify debugging what event code is missing from the
events shell module, print also event id for the for unknown
events. This way it is a bit easier to figure out what the
unknown event is.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Print Ethernet carrier on/off and VLAN tag enabled/disabled
status when monitoring events.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
The recvmsg() function should not modify the buffer configuration
provided in struct msghdr, such behavior is not specified in the POSIX
function description, nor is it consistent with well-known behavior of
this function in Linux.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
As the CoAP library was refactored to handle response
messages as stated by RFC, the LwM2M message handling was
untouched.
LwM2M Notify handling is relying on response callback
to be called, but as per CoAP RFC an empty Ack is not
actually a response and the callback was not called anymore.
Fix the issue by calling the response callback when
we receive an empty ack for any confirmable response
messages.
This should not affect any handling of CoAP requests.
Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
The conversion from IPv4 string presentation to numeric value
did not check if the individual address value was between 0 and 255
inclusive.
Add also test case for this.
Fixes#84593
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
The scan events are always enabled which means if another software
component requests a scan, then the WiFi shell scan printouts will
also be sent to the shell.
Only enable the network management scan events when a user has
requested a scan.
Signed-off-by: Eric Holmberg <eric.holmberg@northriversystems.co.nz>
Check if NET_DHCPV4_SERVER_OPTION_DNS_ADDRESS is set before using it to
set the DNS option in DHCP responses. This avoids sending a client a DNS
server of 0.0.0.0.
Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
Add a Kconfig option to skip the router DHCP server option. This can be
useful to avoid having the client trying to forward all its traffic to
the embedded device.
Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
Modifying MAC address is allowed only when the interface is not
administratively UP, as it typically involves conveying the MAC address
to the chip firmware, and accepting the MAC address when interface is
administratively UP will not reflect in the actual usage.
So, modify the check to reject MAC address change if the interface is
administratively UP.
Fixes#81486.
Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
If we have received data to the accepted socket, then release
those before removing the accepted socket. This is a rare event
as it requires that we get multiple simultaneous connections
and there is a failure before the socket accept is called by
the application.
For example one such scenario is when HTTP server receives multiple
connection attempts at the same time, and the server poll fails
before socket accept is called. This leads to buffer leak as the
socket close is not called for the accepted socket because the
accepted is not yet created from application point of view.
The solution is to flush the received queue of the accepted socket
before removing the actual accepted socket.
Fixes#84538
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
A _res_fallback parameter to HTTP_SERVICE_DEFINE is added to optionally
specify a fallback resource detail, which will be served if no other
resource matches the URL.
Signed-off-by: Matt Rodgers <mrodgers@witekio.com>
Currently, `CONFIG_OPENTHREAD_LOG_LEVEL` is used to set log level
in OT and register log modules in Zephyr. OpenThread allows 5
levels, causing issues when `OPENTHREAD_LOG_LEVEL_DEBG` is
selected ad we are trying to register modules with unknown lvl.
This commit adds `CONFIG_OPENTHREAD_MODULE_LOG_LEVEL` which is
aligned for Zephyr's log levels.
Signed-off-by: Maciej Baczmanski <maciej.baczmanski@nordicsemi.no>
Do not free the slot when cred buf is NULL.
If the TLS credential storage backend does not have a buffer pointer
to the TLS credential, then the buffer pointer can be NULL.
This may happen with an out-of-tree TLS credential storage backend.
In this case where credential buffer is NULL find_ref_slot retrieves
a new slot, and then tries to free it, causing a crash.
Signed-off-by: Joakim Andersson <joerchan@gmail.com>
Some time ago three Kconfigs dedicated for the child timeouts
configuration were added, but changing them does not apply when
using OpenThread libraries. Added setting these values using
openthread API on openthread start.
Signed-off-by: Kamil Kasperczyk <kamil.kasperczyk@nordicsemi.no>
It seems that this change was solely added to address issues with old
TCP stack, which blindly queued packets intended for TX for potential
further retransmission, expecting that the packet would remain intact
during transmission.
I think this assumption was wrong, as it's natural that lower layers
append respective headers to the packet, and this "header stripping"
behavior was specific for Ethernet L2 only. If an upper layer expects
that the packet would need to be retransmitted at some point, it should
clone it instead.
Therefore, remove the L2 header stripping from the Ethernet L2 to avoid
any potential issues in zero-copy case.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Add new Ethernet driver config option,
ETHERNET_CONFIG_TYPE_EXTRA_TX_PKT_HEADROOM, which allows Ethernet
drivers to inform L2 about the extra net_pkt headroom they need to be
allocated.
This is only supported when CONFIG_NET_L2_ETHERNET_RESERVE_HEADER is
enabled, so that it's possible to fit entire packet into a single
net_buf, which is needed for zero-copy transmission.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
The size calculation for the first buffer, in case extra headroom is
requested, had a bug which could result in a size variable underflow
followed by net_buf exhaustion.
In case the net_buf size was larger than requested size, but smaller
than requested size + headroom, the whole buffer size was subtracted
from the requested size. This however did not take the extra headroom
into account and in effect could result in underflow.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Fixes#84198.
If a '?' character is used as part of a wildcard resource, do not treat
this as the end of the string when comparing with a path from the HTTP
request. Only the path from the HTTP request may be terminated by '?'
(in the case of a request with query parameters).
Signed-off-by: Matt Rodgers <mrodgers@witekio.com>
Packets are forwarded to the native interface or in other words,
the vlan header is simply stripped and ignored. This feature is called
'priority tagging'.
Signed-off-by: Cla Mattia Galliard <cla-mattia.galliard@zuehlke.com>
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
The headroom was not taken into account for variable size data
buffers when CONFIG_NET_L2_ETHERNET_RESERVE_HEADER was enabled.
Add a test case for it to make sure the reserve allocation works
properly.
Fixes#84053
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Empty code was incorrectly matched as a request, fix that.
Align coap_handle_request_len() function to behave as documented in the
API documentation - in case of invalid request code (which is also the
case for empty code) -ENOTSUP Should be returned.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
The algorithm for matching request with response was incorrect, which
could lead to false matches (for example if request had a token, and
piggybacked reply had no token but matching message ID only, that would
still be counted as a match).
This commit fixes it. The request/reply matching is implemented based on
RFC now, with separate conditions for piggybacked/separate responses.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Remove the build assert from NET_L3_REGISTER() macro as that
is causing an issue with llvm. Add runtime check of the handler
pointer value.
subsys/net/l2/ethernet/arp.c:1044:1: error: static_assert expression
is not an integral constant expression
ETH_NET_L3_REGISTER(ARP, NET_ETH_PTYPE_ARP, arp_recv);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/zephyr/net/ethernet.h:1272:2: note: expanded from
macro 'ETH_NET_L3_REGISTER'
NET_L3_REGISTER(&NET_L2_GET_NAME(ETHERNET), name, ptype, handler)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/zephyr/net/net_core.h:190:2: note: expanded from
macro 'NET_L3_REGISTER'
BUILD_ASSERT((_handler) != NULL, "Handler is not defined")
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/zephyr/toolchain/gcc.h:87:51: note: expanded from
macro 'BUILD_ASSERT'
define BUILD_ASSERT(EXPR, MSG...) _Static_assert((EXPR), "" MSG)
^~~~~~
subsys/net/l2/ethernet/arp.c:1044:1: note: cast from 'void *' is not
allowed in a constant expression
include/zephyr/net/ethernet.h:1272:2: note: expanded from
macro 'ETH_NET_L3_REGISTER'
NET_L3_REGISTER(&NET_L2_GET_NAME(ETHERNET), name, ptype, handler)
^
include/zephyr/net/net_core.h:190:29: note: expanded from
macro 'NET_L3_REGISTER'
BUILD_ASSERT((_handler) != NULL, "Handler is not defined")
^
/usr/lib/llvm-14/lib/clang/14.0.0/include/stddef.h:89:16: note: expanded
from macro 'NULL'
define NULL ((void*)0)
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Trust that the protocol type is set correctly by functions
called before this one. We should not set the protocol type
blindly in this generic function.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
The ARP code has set the protocol type of the packet to
0x806, so do not change it when preparing to send to 0x800
which is the IP protocol type. Lets trust the previously
called functions to set the ptype correctly and do not set
it here.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Print more data / debug information for ARP messages.
Also remove unnecessary "&" when printing IPv4 address.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>