Some offloaded ifaces have an L2, but lack support for
net_l2->send. This edge case is not handled by
net_if_send_data, resulting in a NULL dereference under
rare circumstances.
This patch expands the offloaded iface guard in
net_if_send_data to handle this edge case.
Signed-off-by: Georges Oates_Larsen <georges.larsen@nordicsemi.no>
Fixes issues with net_ptp_time arithmetic where second
overflow/underflow would not be handled properly.
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
Offset should be *subtracted* from current clock value, not added.
This was causing clock to accumulate error instead of actually
"converging".
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
For 2.4GHz and 6GHz bands, while counting the channels in configured
range, start of the range is being counted twice. Correct this
by advancing the index by 1 while counting channels in range.
Signed-off-by: Ravi Dondaputi <ravi.dondaputi@nordicsemi.no>
Parse the more flag in coap_get_block2_option(), so that the function
can be used not only with requests but also with replies (where the more
flag should not be ignored).
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
The block number in block1/2 options can be encoded on up to 20 bits
according to RFC 7959, therefore the underlying type used in helper
functions to retrieve the block number should be large enough to hold
the result. Therefore, replace the container for block number with
uint32_t instead of uint8_t.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
This is related to change in commit dacb3dbfeb
("iterable_sections: move to specific header")
Until now iterable sections APIs have been part of the toolchain
(common) headers. They are not strictly related to a toolchain, they
just rely on linker providing support for sections. Most files relied on
indirect includes to access the API, now, it is included as needed.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
When LwM2M engine is requested to stop,
emit the disconnected event unconditionally.
There is really no reason to skip the event
on network error, or if we have never been registered.
Fixes#76422
Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
Allow an application to add a Block2 option to an initial request for a
resource. For any subsequent requests as part of a blockwise transfer,
drop the application-added Block2 option since the coap_client must
append a Block2 option with updated NUM and SZX fields based on the
server response.
Signed-off-by: Matt Rodgers <mrodgers@witekio.com>
Improve buffer handling logic to use local variables extensively.
This change reduces the number of pointer dereferences, which leads
to more efficient runtime and helps reduce the code size.
Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
Improve buffer handling logic to use local variables extensively.
This change reduces the number of pointer dereferences, which leads
to more efficient runtime and helps reduce the code size.
Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
Windows TCP stack has a peculiar behavior - when running iperf, it will
fill out the RX window almost entirely, but will not set PSH flag on
packets. In result, our stack would delay the ACK and thus window
update, affecting throughputs heavily.
In order to avoid that, keep track of the most recent window size
reported to the peer, and reduce it when receiving new data. In case the
RX window, as seen from the peer perspective, drops below certain
threshold, and the real RX window is currently empty, send an ACK
immediately when updating window, so that peer can continue
with sending data.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
If IPv6 is not enabled for a given network interface, then there
is no need to try to join IPv6 multicast groups as it will just
cause an error print which is pointless in this case.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
While routing between interfaces source Link-Local L2 address is set
for a packet. However, it should not be done for some of the interfaces.
This commit adds helper function to check this condition in runtime.
Signed-off-by: Konrad Derda <konrad.derda@nordicsemi.no>
When packet is routed between interfaces new routing entry is added
to the table. This should not be done for interfaces that do not
support Neighbor Discovery protocol as they are not keep potential
neighbors in the common table.
Signed-off-by: Konrad Derda <konrad.derda@nordicsemi.no>
adds filesystem as a resource for the http_server which serves static
(gzipped) files from a filesystem to the client.
Signed-off-by: Gerhard Jörges <joerges@metratec.com>
The Association permit bit shall be set to zero if the coordinator does
not accept association requests.
Not accepting association request ist not a reason to filter the
beacons from this coordinator during network scan. It is still a
network, just one you cannot associate with.
Signed-off-by: Fabian Pflug <fabian.pflug@grandcentrix.net>
Limit the coap payload size passed up to the application callback to the
block size, when a block transfer is in progress and the current payload
is not the final block.
If the current payload is not part of a block transfer, or is the final
block of a transfer, then the full payload can be passed to the
application to avoid having to make another request over the network for
data that has already been received.
This avoids a problem raised in issue #76089, where a payload longer
than CONFIG_COAP_CLIENT_MESSAGE_SIZE causes the same data to be passed
to the application callback twice (once in the large packet, and once in
the next block which must have an offset that is a multiple of the block
size).
Signed-off-by: Matt Rodgers <mrodgers@witekio.com>
Use the MSG_TRUNC flag to check the total length of UDP packets
receieved by the coap_client, and hence check if the receive buffer
contains the whole message, or if it is truncated.
If the message is truncated, then use a blockwise transfer to fetch the
rest of the data.
This is related to issue #76089.
Signed-off-by: Matt Rodgers <mrodgers@witekio.com>
Due to the introduction of `shell_xxx_impl` wrapper functions in
PR #75340, we can minimize caller overhead by eliminating direct
`color` parameter passing.
This is achieved by using `shell_print_impl`, `shell_error_impl`,
`shell_info_impl` and `shell_warn_impl` instead of `shell_fprintf`.
Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
Packets are routed between OT and Zephyr net stacks.
For IPv4 these packets are managed by NAT64 by default.
Signed-off-by: Marcin Gasiorek <marcin.gasiorek@nordicsemi.no>
This commit reduces `#if / #endif` pairs by leveraging the
`IS_ENABLED` macro:
- Removed `#ifdef / #endif` around `NET_L2_DECLARE_PUBLIC` in `net_l2.h`,
enabling compilation without affecting link time if the configuration
is unavailable.
`set_default_name` function:
- Replaced multiple `if` statements with `else if` to use the last `else`
without indirectly checking `name[0] == '\0'`.
- Since `snprintk` guarantees null-termination if `sizeof(name) > 0`,
the `-1` subtraction is unnecessary, eliminating the need for
zero initialization in `char name[CONFIG_NET_INTERFACE_NAME_LEN + 1];`.
Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
Fixes: #72363
The existing function to set the postfix is converting postfix
string to hexadecimal. Adding a new function to handle a use case
where the provided postfix should be used as is without any conversion.
Signed-off-by: Vineeta S Narkhede <VineetaSNarkhede@Eaton.com>
Most set functions have a get function as well, add the missing
function to get the set gateway IPv4 address.
Signed-off-by: Bas van Loon <basvanloon@betronic.nl>
If we receive multiple DNS servers via DHCP only the first one is used,
regardless of CONFIG_DNS_RESOLVER_MAX_SERVERS constant.
Parse DHCP option and save addresses that fit
Signed-off-by: Andrey Dodonov <Andrey.Dodonov@endress.com>
Several refactors and improvements for `net_bytes_from_str` as follows:
- Replaced manual hex digit checks with `isxdigit()`.
- Changed variable `i` from unsigned int to size_t for consistency with
the `strlen()` return type.
- Added `src_len` to store the result of `strlen(src)` to avoid
multiple calls to `strlen` in the `for-loop`.
- Ensured casting to `unsigned char` before passing to `isxdigit()` to
prevent undefined behavior.
- Explicitly cast the result of `strtol()` to `uint8_t` to match
the buffer type.
Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
In case POLLIN is set, and no new application data has been detected,
the ztls_poll_update_ctx() should only return -EAGAIN if no other events
are available for the socket. Otherwise, the function may end up
busy-looping, in case for example POLLOUT is also monitored for the
socket.
Current check verifying that was wrong, as it caused to function to
return -EAGAIN even if some other events could've been reported for the
socket.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Fix the NM iface type check error, should use (1 << WIFI_TYPE_STA),
instead of WIFI_TYPE_STA. Same for WIFI_TYPE_SAP.
Signed-off-by: Maochen Wang <maochen.wang@nxp.com>
Changes include:
- Introducing a local `ctx` variable to replace multiple
`sock_ctx[i]` references.
- Using a local `revents` variable to simplify repeated
`sock_fds[i].revents` checks.
- Consolidating conditional checks for socket events
(ZSOCK_POLLERR, ZSOCK_POLLNVAL, and ZSOCK_POLLHUP) as they are
individual bit definitions, allowing them to be checked simultaneously.
Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
In the send_ipv4_fragment function, if net_pkt_get_data returns
fail, a tx_pkts slab leak will occur. If leak exceeds the
maximum number CONFIG_NET_PKT_TX_COUNT of tx_pkts slab, tx_ptks
will be used up, and the related modules(dhcp, ping and so on)
of net cannot alloc tx_pkt slab, and will sleep and can not
return successfully until available slab.
dhcp work or ping work cannot be executed beacause can't alloc
memory, and ping command cannot return, console also fails to
input commands, and the console hang problem occurs.
Signed-off-by: Gaofeng Zhang <gaofeng.zhang@nxp.com>
When IPv6 packet is received, there is a check of the packet's source
address to verify that it is not interface's non-tentative address.
This commit moves this check to the later stages of processing as
packets that can be routed are dropped in the early stage otherwise.
Signed-off-by: Konrad Derda <konrad.derda@nordicsemi.no>
If the packet was routed between interfaces by IPv6 module it should
not be looped back but has to be passed to the destination interface
instead.
Signed-off-by: Konrad Derda <konrad.derda@nordicsemi.no>
When a packet's transmission is prepared and Neighbor Solicitation is
sent its souce address is always the same as of a packet awaiting -
also for packets routed from an other interface.
Quote from the RFC:
If the source address of the packet prompting the solicitation is the
same as one of the addresses assigned to the outgoing interface, that
address SHOULD be placed in the IP Source Address of the outgoing
solicitation. Otherwise, any one of the addresses assigned to the
interface should be used.
This commit fixes the behavior.
Signed-off-by: Konrad Derda <konrad.derda@nordicsemi.no>
Before packet is routed there is a check verifying if the destination
address is not the device's one. However, the check should be limited
to the packet's original interface. Otherwise, packet cannot be routed
if it is destined for an other interface of the device.
Signed-off-by: Konrad Derda <konrad.derda@nordicsemi.no>
Enable hostname verification in DTLS handshake when server URI contains
valid hostname.
When URI is given just as IP address, don't fill up the
ctx->desthosname or enable hostname verification.
Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
The memory allocation for socketpairs is not conformant to the new
MEM_POOL_ADD_SIZE_ mechanism for allocating heap memory.
Specifically CONFIG_NET_SOCKETPAIR_HEAP can not be selected unless
the user has specified CONFIG_HEAP_MEM_POOL_SIZE. We should be
using MEM_POOL_ADD_SIZE_ to add to the heap if the user wants to
use it for socketpair allocation.
Additionally increase the size of pre-allocated sockets to 8 from 1
to support larger devices by default, taking into consideration the
required socketpairs and buffer sizes when using
WIFI_NM_WPA_SUPPLICANT.
Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>
Introduce a more generic mutex for protecting coap_client structure.
This allows to avoid a certain race condition when sending consecutive
CoAP requests. The case was, that when a CoAP receive thread notified
the application that a complete response was received, and the
application wanted to send another request from the application thread,
the consecutive call to coap_client_req() might've failed if the
application thread has higher priority than the CoAP receive thread
because of the request context cleanup is done after calling the
application callback.
Having a mutex, which is locked while processing the response, and when
attempting to send a new request allows to synchronize threads as
expected.
As this new mutex seemed redundant with the more specialized send_mutex
already present in the coap_client, the latter was removed (i. e.
transmission is also protected with the new mutex).
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>