HTTP 1.1 server has two ways of indicating the message body length -
either by providing the Content Length header, or by closing the
connection when the entire body has been transmitted.
The second method didn't work with Zephyr's HTTP client implementation,
as EOF on a socket was treated as an error condition. Therefore, if no
Content Length was provided by the server, such transfers would always
end up with ECONNRESET error.
In order to fix this, we need to notify the parser about the EOF on a
socket when connection is closed. It is the parser role to determine
whether the EOF was expected in current state (by marking end of message
flag) or not (by setting an error).
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Update the socket_service_thread function signature to match the expected
k_thread_entry_t type:
typedef void (*k_thread_entry_t)(void *p1, void *p2, void *p3);
Signed-off-by: Tim Pambor <tim.pambor@codewrights.de>
In coap_well_known_core_get(), move the null check for 'resource' before
applying pointer arithmetic ('resource + 1') to avoid undefined behavior
when 'resource == NULL'.
Signed-off-by: Gaetan Perrot <gaetan.perrot@spacecubics.com>
Socket dispatcher (and offloaded implementations in tests) register
fd as ZVFS_MODE_IFSOCK therefore they should register a close2(
function instead of close().
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
socketpair fd regsiters ZVFS_MODE_IFSOCK therefore it should register a
close2() function instead of close().
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
In case address mode in a packet is none, the address pointer within mhr
struct will not be set. Therefore, the pointer should not be used before
address mode is verified inside ieee802154_check_dst_addr().
This was reported by UBSAN:
subsys/net/l2/ieee802154ieee802154.c:296:41: runtime error: member
access within null pointer of type 'struct ieee802154_address_field'
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Cast uint8_t variable to uint32_t explicitly to avoid implicit cast to
int, and thus potentially undefined behavior, reported by UBSAN:
net_pkt.c:1946:17: runtime error: left shift of 239 by 24 places
cannot be represented in type 'int'
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
In order to avoid alignment issues when casting void pointers to
in(6)_addr structures, create a properly aligned copy of the ip(v6)
address on stack.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
In order to prevent an overflow warning from UBSAN when bitshifting,
cast to uint64_t first before shifting, and then back to uint32_t.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
As struct sockaddr have now alignment of 4 bytes, net_ipaddr_copy()
gives the following error if used for sockaddr:
error: alignment 1 of ‘struct <anonymous>’ is less than 4
[-Werror=packed-not-aligned]
Just use memcpy() instead, net_ipaddr_copy() was intended to use with IP
addresses, not socket related structs.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Rework the IPv4-related code to avoid casting. Use raw variants of
IPv4-related functions whenever possible (especially on the critical
data path).
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
To address the misaligned access issues reported by UBSAN, introduce raw
variant of certain IPv4 functions used in the critical data path of the
network stack, operating on plain uint8_t buffers in stead of IPv4
address struct.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Rework the rest of the IPv6-related code to avoid casting. Use raw
variants of IPv6-related functions whenever possible (especially on the
critical data path). For the routing case, use a copy of the address to
avoid massive rework of the routing module.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
IPv6 Neighbor Discovery interfaces modules like neighbor or routing
tables - converting them to raw variants seems futile. Therefore, for
IPv6 ND case, copy the raw IP address from the packet into the in6_addr
structure, and then pass it to respective functions. Performance
overhead should not be a big problem in such case as those actions are
only performed if a respective ND packet is received.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Refactor local functions to work with byte buffers instead of struct
in6_addr and use switch to use raw variants of functions operating on
IPv6 addresses.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
To address the misaligned access issues reported by UBSAN, introduce raw
variant of certain IPv6 functions used in the critical data path of the
network stack, operating on plain uint8_t buffers in stead of IPv6
address struct.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
According to RFC 793, ch 3.9 Event Processing,
after the connection is sync-ed with seqnum of both sides then,
1. drop any received segment if the ACK bit is off.
2. validate the acknum like this:
SND.UNA =< SEG.ACK =< SND.NXT
The ACK validation is done before entering the state-machine, so
remove the flags <ACK> check in the state-machine processing.
Signed-off-by: Shrek Wang <inet_eman@outlook.com>
htons() takes uint16_t as argument. Add the 'u' suffix to the
TTL constants to ensure the correct unsigned type is used and to avoid
undefined behavior if these functions are implemented as macros using
bit shifts.
Signed-off-by: Tim Pambor <tim.pambor@codewrights.de>
Verify if the block number isn't negative before processing it, to
prevent potentially undefined behavior. This was reported by the
undefined behavior sanitizer.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Use UNALIGNED_MEMBER_ADDR when getting the address of possibly
unaligned structures members instead of attempting to directly
get the address as an offset.
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
Use UNALIGNED_MEMBER_ADDR when getting the address of possibly
unaligned structures members instead of attempting to directly
get the address as an offset.
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
Use UNALIGNED_MEMBER_ADDR when getting the address of possibly
unaligned structures members instead of attempting to directly
get the address as an offset.
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
Use UNALIGNED_MEMBER_ADDR when getting the address of possibly
unaligned structures members instead of attempting to directly
get the address as an offset.
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
Use UNALIGNED_MEMBER_ADDR when getting the address of possibly
unaligned structures members instead of attempting to directly
get the address as an offset.
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
zperf should only return 'Kbps'. There are still two left-overs
from converting shell prints to 'Kbps'.
Align all prints to make it easier for scripting and parsing
content from console output.
Signed-off-by: Daniel Schultz <d.schultz@phytec.de>
POLLHUP event may be returned even if there is still data to read
and POLLIN is set. To ensure all data is consumed, check for
POLLHUP after handling POLLIN.
https://man7.org/linux/man-pages/man2/poll.2.html
Signed-off-by: Juha Ylinen <juha.ylinen@nordicsemi.no>
The NET_EVENT_WIFI_SIGNAL_CHANGE was not added to net mgmt event queue
so that no scan was triggered, which caused roaming fail. The event
NET_EVENT_WIFI_SIGNAL_CHANGE was dropped because it was not enabled in
WIFI_SHELL_MGMT_EVENTS. After adding NET_EVENT_WIFI_SIGNAL_CHANGE, the
roaming works as expected.
Same issue found on event NET_EVENT_WIFI_NEIGHBOR_REP_COMP for 11k
roaming. Add this event to WIFI_SHELL_MGMT_EVENTS, too.
Signed-off-by: Hui Bai <hui.bai@nxp.com>
Commit 3c47f91be4 introduced alignment
validation in K_MEM_SLAB_DEFINE macros.
A couple PTP message slabs wer using alignment 8, while the size of
the elements wasn't a multiple of 8, causing a static assertion
failure.
Fix by changing the alignment from 8 to 4 bytes.
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Like other API in DNS cache, `dns_cache_remove` should check arguements
return -EINVAL if any of them is NULL.
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Since the addition of deinit operation in device, init and deinit have
been within each device, rendering their init entry's init function
useless.
In order to save ROM space, let's remove the init function from
init entry altogether, and introduce a new object called "service"
which owns an init function to go along with SYS_INIT/SYS_INIT_NAMED.
Signed-off-by: Tomasz Bursztyka <tobu@bang-olufsen.dk>
Earlier we had socketpair to pass wifi event information from
wpa_supplicant side to zephyr adaption layer. This is now replaced
by k_fifo to save some RAM.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
In case a new notification is triggered while the previous one is still
active (i.e. not acknowledged), the LwM2M engine will start busy
looping, as the new notification is still valid (and supposed to be sent
after the previous one is done), but it's not sent in the current
iteration. The busy looping might prevent the system from receiving the
acknowledgment for the previous one, resulting in unresponsive system.
Fix this, by delaying the new notification timestamp a bit in such case,
so that the new notification will be scheduled for later instead of
trying to send it again right away.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
While it was possible to specify Greater Than / Less Than / Step
observe attributes for a resource, they were not taken into
consideration when evaluating notification criteria. This commit adds
support for checking if the resource value meets the value criteria
specified by gt/lt/st attributes.
Note that gt/lt attributes are thresholds - notification should only
sent if the resource value crosses them.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Update the value stored in the notification registry whenever
notification is sent (for those resources that have gt/lt/st attributes
assigned).
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Greater than, Less than and Step attributes require to track the last
notified value of a resource/resource instance in order to be able to
apply the specific thershold/step rules that the attributes define.
Therefore, implement a simple registry of the last notified values. When
one of the gt/lt/st attributes is configured on a resource/resource
instance, a registry entry is allocated for respective resource.
Whenever a notification is sent (either as a reply to Observe message,
or proactively) the registry is updated for the notified resources.
The stored resource values have been unified as "double" variables, to
avoid implementation complexity of having to support different
integer/floating point resource types.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
gt/lt/st attributes can only be applied to numerical resources according
to LwM2M specification (and common sense), hence verify that when
attributes are assigned.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Print information which DNS servers were added by DHCP when
listing DNS servers in "net dns" command. This helps debugging
DNS server issues.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Remember which DNS server was added by a source like DHCPv4 or v6
message. This will allow system to remove DNS servers that were added by
that source. Then when stopping for example DHCP, we can remove those
specific DNS servers and not leaving DNS servers hanging in the system.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
When reading and printing hosname or domain name from DHCP options, we need
to skip the leftover bytes that do not fit into the provided buffers.
Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
The fallback to Bootstrap on a Registration Failure might not be desirable
for some applications. This change makes the default behavior configure
through Kconfig.
An alternative to configure "Bootstrap on Registration Failure" would be to
set the server object resource id 16 at runtime. However, this is tedious
and error-prone, as it will be reset when the server object is deleted and
might have to be set at different locations in the client code.
Signed-off-by: Marc Lasch <marc.lasch@husqvarnagroup.com>
The ISO C function time() should not depend on POSIX and this was
corrected recently via the common libc time() implementation.
Remove this dependency from the network subsystem where it has
been unduly needed for some time.
Similarly, XSI_SINGLE_PROCESS was a dependency for time() via
picolibc, because the time() implementation in picolibc relies
on the POSIX gettimeofday() call.
However, since Zephyr's common libc time() implementation no longer
depends on that, it can be removed as a dependency in the network
subsystem as well.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Allows application code to control allocation of buffers of optional
resources.
Y value, Z value, min range value, max range value resources are
optional.
Signed-off-by: Nick Ward <nix.ward@gmail.com>