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>
The standard does allow for a optional beacon payload, which gets lost
during scan, that could be interesting for the application to access
in the NET_EVENT_IEEE802154_SCAN_RESULT callback.
See section 7.3.1.6 in IEEE Std 802.15.4 for more information about
the beacon payload field. And section 7.3.1 and figure 7-5 about general
beacon frame format.
Signed-off-by: Fabian Pflug <fabian.pflug@grandcentrix.net>
When running dhcp, it was not assigning gateway/router
address to the client devices. It is fixed in this PR.
Signed-off-by: Muhammad Munir <muhammad.munir@zintechnologies.com>
Make sure we are not accessing NULL pointer when checking
if the IPv4 mapping to IPv6 is enabled.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Utilize a code spell-checking tool to scan for and correct spelling errors
in all files within the `subsys/net/lib` directory.
Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
Utilize a code spell-checking tool to scan for and correct spelling errors
in all files within the `subsys/net/l2` directory.
Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
Utilize a code spell-checking tool to scan for and correct spelling errors
in all files within the `subsys/net/lib/lwm2m` directory.
Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
In case no "Connection: close" header is present in the request, the
server should keep the connection open for the client. Hence, after
serving a request, we need to check if the header was present (the
parser sets a flag for it), and only close the connection immediately,
if the client requested it. In case the client remains silent, the
connection will be closed anyway after the inactivity timer kicks in.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Allocating FD before pulling the new connection from the fifo can lead
to busy looping in certain cases. If the application keeps calling
accept() on a listening socket after failing to allocate new FD for the
incoming connection, it'll start busy looping, as will report POLLIN in
such case (as the new connection is still on the queue), but it'll
consistently fail with ENFILE.
This can be avoided by trying to allocate new file descriptor only after
new connection has been pulled from the fifo. That way, if we fail to
allocate the file descriptor, the incoming connection will be dropped,
which seems correct given we don't have enough resources to service it.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
In case there were active connections when restarting the server, it
can't be re-initialized immediately, as binding to the server port will
fail. We need to wait for the TCP connection teardown, as even with
REUSEADDR socket option set, binding will fail if the sockets are not in
TCP TIMED_WAIT state (i. e. connections are active).
Because of this, add a configurable delay when restarting the server.
Additionally, make server initialization failures non-fatal, i. e. try
to restart the server again after the delay if the initialization fails.
It's been observed with Chromium, that it tends to keep connections open
even after closing them on the server side (socket lingers in FIN_WAIT_2
state), so the server re-initialization may fail even with delay, so
it's beneficial in such case to keep retrying the server
re-initialization.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
In case of fatal errors (during poll() or when handling listening
socket), the server operation is restarted. It was missed however, that
sockets opened for the server should be closed in such case.
Additionally, in case there were active client connections, it's needed
to cleanup related resources, otherwise running timers may trigger a
crash.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
In previous batch of fixes it was overlooked that streams are
HTTP2-specific concept. While for HTTP2 we need to track headers reply
state for each individual stream, at HTTP1 level we need to track this
at the client level. Hence, reintroduce respective flags to track
headers reply state, but only for HTTP1.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
As found in PR #75525, we should not modify the polled fd array
in multiple places. Because of this fix, the async version of
the socket service could start to trigger while it is being handled
by the async handler. This basically means that the async version
cannot work as intended so remove its support.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
The information about replied headers or END_OF_STREAM flag are
stream-specific and not general for a client. Hence, need to move them
to the stream context.
For the upgrade case, we need to allocate a new stream now when HTTP1
request /w upgrade field is received. The stream ID in such case is
assumed to be 1 according to RFC.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
In case client decides to send a trailing headers frame, the last data
frame will not carry END_STREAM flag. In result, with current logic
server would not include END_STREAM flag either, causing the connection
to stall. This commit fixes this logic, so that the server replies
accordingly in case END_STREAM flag is present in the trailing headers
frame.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
CONTINUATION frames are tricky, because individual header fields can be
split between HEADERS frame and CONTINUATION frame, or two CONTINUATION
frames. Therefore, some extra logic is needed when header parsing
returns -EAGAIN, as we may need to remove the CONTINUATION frame header
from the stream before proceeding with headers parsing.
This commit implements the above logic and additionally adds more checks
to detect when CONTINUATION frame is expected. Not receiving a
CONTINUATION frame when expect should be treated as a protocol error.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Frame printouts should not be done from the state handlers, but rather
during state transition, otherwise a single frame can be printed several
times as new data arrive. This also simplifies code a bit, as we just
print the frame in a single place, instead of duplicating code.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
There's really no good reason to have an upper bound on the buffer sizes
and this limits testing in some cases, so just remove them.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
In case RST_STREAM frame is received it should not be ignored, but the
corresponding stream should be closed.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
In case priority flag is present in the HTTP2 headers frame header, we
should expect additional priority fields before the actual frame
content.
The stream priority signalling has been deprecated by RFC 9113, however
we should still be able to handle this in case some implementation
(nghttp for instance) sends them.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Data and header frames can contain padding - we need to take this into
account when parsing them, otherwise the stream is broken.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Instead of multiplying function to check header flags, just have a
single one, with flag mask as parameter.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
For HTTP2-specific structures and enums, use "http2_" prefix to clearly
indicate the distinction from the generic HTTP stuff.
Additionally, some structures/enums describing HTTP2 protocol details
had "server" in the name, while in reality they describe nothing
server-specific. Hence, drop the "server" part where applicable.
Remove unused macros.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
* Remove unneeded variable.
* Use system utilities to read big endian numbers instead of parsing
manually.
* Remove `payload` member from the http_frame structure. It's not used
for anything useful, and could actually be misleading, as in case of
large frames, where not entire frame is parsed at once it will point
to incorrect location.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
If newly introduced interface type is unset then return the first Wi-Fi
interface as a fallback, this fixes backward compatibility.
Also, add NM APIs and use them for type checks, rather than directly
using the type enumeration.
Fixes#75332.
Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
pollfd array used with zsock_poll() should not be modified while inside
zsock_poll() function as this could lead to unexpected results. For
instance, k_poll already monitoring some kernel primitive could report
an event, but it will not be processed if the monitored socket file
descriptor in the pollfd array was set to -1. In result,
zsock_poll() may unexpectedly quit prematurely, returning 0 events, even
if it was requested to wait infinitely.
The pollfd arrays used by zsock_poll() (ctx.events) is reinitialized
when the service thread is restarted so modifying it directly when
registering/unregistering service is not really needed. It's enough if
those functions notify the eventfd socket used to restart the services
thread.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
If we couldn't send all (or any data) via the socket,
invoke poll instead of blindly retrying and flooding the socket
Signed-off-by: Andrey Dodonov <Andrey.Dodonov@endress.com>