There are two ways in the current implementation to join a network,
either with an association request or a via MLME-SET(macShortAddress) to
rejoin a previously associated network.
The coordinator address needs to be valid in the rejoin case. It can be
lost, for example if the device power cycles. This commit fixes that gap
with new MLME GET/SET for:
- macCoordShortAddress
- macCoordExtendedAddress
Signed-off-by: Simon Piriou <spiriou31@gmail.com>
Trying to remove filter with NOT_ASSOCIATED parameter results in noisy
warning logs in most of the radio drivers. It's safe to ignore it as
this is an invalid operation.
Signed-off-by: Simon Piriou <spiriou31@gmail.com>
Introduce BUILD_ASSERT checks in the UDP transport implementation to
ensure the configured maximum address size is large enough for the
enabled IP families.
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
Add guidelines in Kconfig explaining the minimum required
MQTT_SN_LIB_MAX_ADDR_SIZE for UDP transport and IPv4 and or IPv6. Also
explain when this value might need to be changed.
Use these values to provide a sane default for IPv4 and IPv6.
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
Verify that the interface index, converted to array index,
does not exceed the preallocated string array for dynamic index
completion.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
As explained in the comment in the code, both structs have the same
offsets for it's fields, but sockaddr_in is smaller, hence it can
confuse static analyzer, giving warnings about potential out-of-bound
access. Therefore, cast to sockaddr_in6 instead to avoid the warning.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
It's been periodically reported that the default connect timeout shared
with regular TCP sockets (3 seconds) is not enough for the TLS handshake
to complete. Therefore, it'd make sense to increase the default value
for TLS sockets specifically. However currently the option is used by
both TCP and TLS connections, which makes this impractical.
Therefore, introduce a separate CONFIG_NET_SOCKETS_TLS_CONNECT_TIMEOUT
Kconfig option for TLS sockets specifically, and set the default to 10
seconds. For samples/tests that modified the old option for TLS-specific
purpose, update the new option value as well.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
In case a handshake timed out on a blocking accept() call, the TLS
socket would return EAGAIN error which is ambiguous and not intuitive.
Report ETIMEDOUT instead.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
On IPv6, IPPROTO_IPV6 needs to be replaced by IPPROTO_IP and
IP_MULTICAST_TTL by IPV6_MULTICAST_HOPS.
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
On IPv6, the host is subscribed to a few multicast addresses by default.
Reusing such an address for MQTT-SN leads to an EALREADY error. Ignore
this error instead of returning. Do the same for IPv4 for consistency,
and because it could happen if the multicast address has already been
added manually from another part of the code, although this is really a
corner case.
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
The current allocated buffer for storing the IP address is not always
large enough to hold an IPv6 address. Instead of using a hard-coded
value, use NET_INET6_ADDRSTRLEN, which covers all cases, including
possible mapped IPv4 addresses.
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
errno returns a positive value, while the API specifies that a negative
value is returned in case of error. Therefore replaces "return errno" by
"return -errno".
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
There is an issue with AF_PACKET sockets bound to ieee802154 l2 iface.
The socket keeps track of the iface link_addr with a sockaddr_ll_ptr
structure, with sll_addr pointing to the iface link_addr address, and
sll_halen being a copy of the iface link_addr length.
The iface link address for ieee802154 can change during association
between extended address (8 bytes) and short address (2 bytes). The
iface link_addr s correctly updated, but the sll_halen of already bound
sockets is not, as it's a out of sync local copy.
This commit fixes#99711 by replacing all the sll_halen usage for
AF_PACKET socket with the iface link_addr length directly on recv and
send paths.
Signed-off-by: Simon Piriou <spiriou31@gmail.com>
When calling net_hostname_set() from C++, you will hit compile
errors if you attempt to use a const char *. Since the internals
of net_hostname_set() just uses memcpy(), we should pass in the
new hostname as a const char * to better support C++.
Tested using samples/cpp/hello_world, with an added call to
net_hostname_set().
Signed-off-by: Andrew Kontra <andrew@legatoxp.com>
A few debug logs in TCP code relied on a fact that IP address offset is
the same in struct sockaddr_in and sockaddr_in6. However, the logs
casted the address to struct sockaddr_in, which is smaller than
sockaddr_in6, causing theoretical out-of-bounds access warnings in IPv6
case. Fix this by casting to struct sockaddr_in6 instead.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Make SNTP resynchronization asynchronous, so that it doesn't block the
system work queue while waiting for response.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Move the code responsible for setting clocks into a helper function,
as it'll be reused with asynchronous resynchronization.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Previously, the LCP MRU option sent by the peer was ignored.
This could result in the interface MTU remaining at the default (1500),
even if the peer requested a smaller MRU, potentially leading to packet
loss. This commit adds parsing for the peer's MRU option and updates the
network interface MTU accordingly.
Signed-off-by: Nik Schewtschuk <nik@schew.dev>
WS_MAGIC is a constant string and when calculating lengths for copying
we always exclude the NULL terminator. In result, using strncpy() for
copying can generate a warning about truncated string, as WS_MAGIC will
always be truncated from the NULL terminator. Therefore replace
strncpy() with memcpy() as it seems more appropriate for this case.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
This commit deinitializes platform modules when external network
interface is brought down. It also delets the multicast routes that are
added for OpenThread interface.
Signed-off-by: Cristian Bulacu <cristian.bulacu@nxp.com>
Zephyr subsystems' headers should not duplicate C library prototypes
(in this case strdup(), which is either ISO C23 or a POSIX extension to
the C library <string.h>).
Instead they should request those prototypes from the C library.
By now Zephyr only requires ISO C17, but many C libraries will have
strdup() and expose it also when the POSIX extensions prototypes are
requested, so let's request these prototype from the C library by
setting the feature test macro _POSIX_C_SOURCE to version 2008.09
which includes it.
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
As the loop unpacking the DNS name from records checks the current
label length on each iteration, it's also needed to update the remaining
buffer length on each iteration, otherwise the buffer length checks
doesn't work as expected.
Additionally, the remaining buffer checks while technically worked, they
were conceptually wrong and unintuitive. The buf->data pointer doesn't
move, so comparing against this pointer when adding new labels doesn't
make sense. It's more intuitive to simply compare the label size vs
the remaining buffer space.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
If a thread was sleeping in poll(), monitoring POLLIN only, it should
still be notified if an asynchronous connection, triggered by
non-blocking connect(), failed. Currently that's not the case.
In result the application would never know whether the connection
was successful or not and would be stuck with a disconnected socket
that would not report anything with poll().
This was not an issue if POLLOUT was monitored as well, because POLLOUT
sets up a connect semaphore that was reset in case of errors. POLLIN
however only monitors the recv fifo, which was not waken up in such
case.
Fix this by canceling any pending waits on recv fifo and recv
condition variable.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Do not enable network compatibility mode flag for network tests
so that we will get better coverage of the wrong network APIs
used.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Use the underlaying zsock_ prefixed fcntl macros instead of the
POSIX_API fcntl renames.
After d45cd6716b and this, we do not
anymore use fcntl directly but use the underlaying Zephyr APIs.
So, let's also remove this include.
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
The BMCA comparator ptp_btca_ds_cmp() did not follow the IEEE1588
ranking order: priority fields handled only the “greater” case, causing
valid winners to fall through to the clockIdentity tie-breaker and
resulting in incorrect grandmaster selection. This also caused the
state transition from TIME_TRANSMITTER to GRAND_MASTER to be missed.
Fixes: #99562Fixes: #99566
Signed-off-by: Peter Büchler <peter.buechler@gmail.com>
Some CID-related symbols were prefixed but not updated in sockets_tls.c
as that configuration was not built by the tests/net/all test suite,
hence easy to miss.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Since we are using sys_getopt now we do not need to pull unistd.h
for anything amore.
Let's remove it.
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
sys_getopt has now its global status variables prefixed with sys_getopt_
Let's fix the use here. Note this worked as Zephyr's POSIX_C_LIB_EXT
keeps a replica of these variables without the prefix.
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
There is no openthread_instance so the assert will always fail so
remove it to prevent compilation issue.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Since 820cd34dbb these net components
use ZVFS_EVENTFD directly instead of thru EVENTFD.
So, let's select ZVFS_EVENTFD directly instead of indirectly
thru EVENTFD.
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
Summary:
As Zephyr getopt is not really compatible with Posix getopt, rename
Zephyr getopt to sys_getopt.
Background:
Zephyr getopt module was introduced in #31356 to be used by the shell.
Zephyr's getopt is not the standard one. It has multiple APIs which make
it more suited for a system like Zephyr where different components may
want to use it for different purposes. Including APIs to init it,
get and set its internal state etc.
Several Zephyr modules (shell, net, wifi, ztest) use this getopt with
these special APIs. The getopt module is bundled in the POSIX
compatibility API subsystem (CONFIG_POSIX_C_LIB_EXT).
Problem description:
As it is not the standard getopt(), no C library can possibly provide
a Zephyr compatible version (even if such C library were to provide a
standard getopt()). As it is bundled in Zephyr's POSIX API in
CONFIG_POSIX_C_LIB_EXT), multiple components that depend on it are
selecting CONFIG_POSIX_C_LIB_EXT. Zephyr core components should not
depend on the POSIX API in this way.
Changes done in this commit:
Rename the getopt*() APIs to sys_getopt*() and move them into a module
under lib/utils with its own Kconfig option to enable it.
Zephyr's users are changed to use this new component.
The POSIX subsystem can continue providing getopt() by calling the new
sys_getopt() and in that way retain backwards compatibility for external
users.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Compliance checker complains
TYPO_SPELLING: 'in in' may be misspelled - perhaps 'is in'?
for code like this
static struct net_sockaddr_in in_addr_my = {
so change the variable to ipv4_addr_my. Similar change is
done for IPv6 variables for consistency.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Do not include Posix header files inside network stack as we should
not depend on Posix symbols in net stack.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Rename network symbols i.e., add net_, NET_ or ZSOCK_ prefixes
to those network symbols that can be found in Posix or libc.
This way we can avoid circular dependency issues.
Add also a compatibility header file that allows user to continue
use various network APIs without adding either net_, NET_ or ZSOCK_
prefixes.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Set Log Level to Info when the HTTP socket reports ENETDOWN,
instead of logging an error each time the network is down.
Signed-off-by: Joel Schaller <joel.schaller16@gmail.com>
When clock accuracy is 1KHz or lower, udp_upload rate has
much lower accuracy. eg. 20M rate has 60M actual throughput.
It's because any packet_duration less than 1000us will be
treated as 1 tick. In this case rate cannot control throughput.
Add clock compensate when time clock is lower than 1KHz to fix it.
In every 10 ticks or longer delta time, calculate packets sent
actual number and expected number, and then compensate ticks.
And add compensate ticks to delay ticks count.
If we cannot compensate a minus ticks as delay cannot be negative,
add it to next compensate period.
If compensate sum ticks is lower than -1000, it means current rate
is higher than low level capability. So no need to compensate
in remaining traffic.
Signed-off-by: Fengming Ye <frank.ye@nxp.com>
Kconfig makes sure the NET_PKT_TIMESTAMP_STACK_SIZE with default value
1024 when NET_PKT_TIMESTAMP_THREAD is enabled.
Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
This commit adds a new Kconfig option NET_LINK_ADDR_CUSTOM_LENGTH
that allows to set custom link layer address length if your link layer
technology is not supported directly. If this option is set to a value
greater than 0, that value is used as link layer address length.
Signed-off-by: Jani Hirsimäki <jani.hirsimaki@nordicsemi.no>