Commit graph

6489 commits

Author SHA1 Message Date
Andrey Dodonov
15ead53ad9 net: lib: http: call socket poll for http_client send
If we couldn't send all (or any data) via the socket,
invoke poll instead of blindly retrying and flooding the socket.
Respect timeout through http_client_req

Signed-off-by: Andrey Dodonov <Andrey.Dodonov@endress.com>
2024-07-09 14:04:29 +02:00
Benjamin Bigler
1db356e35c net: mgmt: Fix build error when event direct enabled without event info
If CONFIG_NET_MGMT_EVENT_DIRECT is enabled and CONFIG_NET_MGMT_EVENT_INFO
disabled it does not build because mgmt_push_event writes to non existing
struct members

Signed-off-by: Benjamin Bigler <benjamin.bigler@securiton.ch>
2024-07-09 11:49:47 +02:00
Benjamin Bigler
06a725c1c8 net: mgmt: prevent event_work_handler from blocking
Fix system workqueue block caused by mgmt_event_work_handler
when CONFIG_NET_MGMT_EVENT_SYSTEM_WORKQUEUE is enabled.

Signed-off-by: Benjamin Bigler <benjamin.bigler@securiton.ch>
2024-07-09 11:49:47 +02:00
Pieter De Gendt
0e9a6ee802 net: buf: Add const to net_buf API
Some public API functions do not modify the net_buf instances and can
declare these arguments as const.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2024-07-08 16:02:39 +02:00
Robert Lubos
4625fa713f net: mqtt: Fix possible socket leak with websocket transport
In case underlying TCP/TLS connection is already down, the
websocket_disconnect() call is expected to fail, as it involves
communication. Therefore, mqtt_client_websocket_disconnect() should not
quit early in such cases, as it could lead to an underlying socket leak.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-07-05 12:29:33 +02:00
Alberto Escolar Piedras
1df86af309 Revert "net: sockets: move poll implementation to zvfs"
This reverts commit 93973e2ead.

PR #73978 introduced a regression.
Unfortunately this PR cannot be reverted without reverting also
Let's revert both PRs to stabilize main again towards the 3.7 release.

For more details on the issue see
https://github.com/zephyrproject-rtos/zephyr/issues/75205

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2024-07-03 15:03:05 -04:00
Alberto Escolar Piedras
14e4de6415 Revert "net: sockets: move select() implementation to zvfs"
This reverts commit 49ac1912b2.

PR #73978 introduced a regression.
Unfortunately this PR cannot be reverted without reverting also
Let's revert both PRs to stabilize main again towards the 3.7 release.

For more details on the issue see
https://github.com/zephyrproject-rtos/zephyr/issues/75205

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2024-07-03 15:03:05 -04:00
Jukka Rissanen
c77b818679 net: ipv6-pe: Verify that hmac calculation was ok
Make sure to check return values of mbedtls hmac APIs so that
the digest is calculated properly.

Fixes #75259
Fixes #75260
Fixes #75261

Coverity-CID: 366271
Coverity-CID: 366277
Coverify-CID: 366279

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-07-03 15:25:58 +02:00
Jukka Rissanen
9647db8808 net: dns: Avoid superfluous error message
If we have configured the DNS dispatcher to be only as a
responder but receive a query response, or if we are only
as a resolver but receive a query, then the dispatcher just
ignores the packet and returns -ENOENT.

Unfortunately we print an error message in this case

[00:10:18.818,000] <err> net_dns_dispatcher: DNS recv error (-2)

which is totally unnecessary and causes confusion so do not
print an error message in this case.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-07-02 14:11:15 +02:00
Benjamin Cabé
1f0c22eb01 net: ptp: fix incorrect req_timestamp decoding
Removed incorrect use of ntoh to decode Delay_Req timestamp

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2024-07-01 18:13:42 +02:00
Benjamin Cabé
a89a5ee52d net: ptp: fix offset check by adding missing int64_t cast
Add cast to NSEC_PER_SEC macro to correctly check offset.
Prior to this commit, the would eval to true incorrectly.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2024-07-01 18:13:42 +02:00
Jukka Rissanen
0cfd963ddc net: wifi: shell: Avoid using sscanf
The sscanf() is not available for minimal libc so it cannot be used.
Use the net_bytes_from_str() that is provided for this purposes.

Fixes #75029

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-06-28 20:58:50 -04:00
Chaitanya Tata
fbe7e95359 net: sockets_service: Fix thread failure
In case of thread failure, fix the registrations by properly managing
the synchronization i.e. use conditional wait only if thread is being
initialized or will be initialized, else check for success or failure
without waiting for conditional variables.

Fixes #73523.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2024-06-28 21:52:49 +02:00
Jordan Yates
91f8c1aea9 everywhere: replace #if IS_ENABLED() as per docs
Replace `#if IS_ENABLED()` with `#if defined()` as recommended by the
documentation of `IS_ENABLED`.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2024-06-28 07:20:32 -04:00
Pisit Sawangvonganan
cfbe2adabc net: if: remove unused eth_ctx variable
Removed the declaration and assignment of `eth_ctx` variable from
`net_if_get_wifi_sta` and `net_if_get_wifi_sap` functions since
it was not being used.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-06-28 11:37:25 +02:00
Robert Lubos
5442e47dfa net: tcp: Delay ACK if no PSH flag is present
Delay an ACK in case no PSH flag is present in the data packet. as
described in RFC 813. This allows to reduce the number of ACK packets
we send and thus improve the TCP download throughput.

The results achieved on `nucleo_h723zg` board and the zperf sample
are as follows:
Before: 77.14 Mbps
After: 93.14 Mbps

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-06-28 11:34:50 +02:00
Chris Friedt
49ac1912b2 net: sockets: move select() implementation to zvfs
Move the implementation of zsock_select() to zvfs_select(). This
allows other types of file descriptors to also make use of
select() functionality even when the network subsystem is not
enabled.

Additionally, it partially removes a dependency cycle between
posix and networking by moving functionality into a mutual
dependency.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-06-27 09:01:23 -04:00
Chris Friedt
93973e2ead net: sockets: move poll implementation to zvfs
Move the implementation of zsock_poll to zvfs_poll. This allows
other types of file descriptors to also make use of poll()
functionality even when the network subsystem is not enabled.

Additionally, it partially removes a dependency cycle between
posix and networking by moving functionality into a mutual
dependency.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-06-27 09:01:23 -04:00
Adam Wojasinski
3b78e76554 net: lib: ptp: Fix issues raised by static analyzer
Fix minor issues reported by static analysis tool.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-27 08:48:59 -04:00
Robert Lubos
4a47803b0c net: if: Add OpenThread interfaces unique name
OpenThread interfaces were not considered when default interface name
is assigned, so they ended up with a generic "netX" name. Since it
useful to have an option to identify interface easily by name, assign an
unique "threadX" name for OpenThread interfaces, just like it's done for
other interface types.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-06-26 15:32:00 +02:00
Jukka Rissanen
0cac7af4e4 net: dns: Do not fail if cache flush bit is set in class
Mask the DNS_CLASS_FLUSH value when checking if the DNS_CLASS_IN
is set when unpacking a query.

Fixes #74829

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-06-26 09:27:07 -04:00
Robert Lubos
0ca2a3cce0 net: lib: lwm2m: Fix expected block calculation
Coverity reported that a formula used to calculate the next expected
block in case the block size from the request differs our own block size
has a bug. The expression used to calculate the block size diff would
evaluate to an unsigned integer, giving (wrongly) enormous results in
case block size from the request is smaller than the Zephyr's default.

It turns out however, that this formula is no longer needed at all.
Since commit d3081e2f30, Zephyr's LwM2M
implementation will no longer negotiate the block size in case of write
operation, but simply comply with the block size included in the
request. This means that calculating the diff makes no longer sense and
can be safely removed - the next expected block number should be simply
increased by 1.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-06-26 08:59:56 -04:00
Robert Lubos
0528df9a4e net: shell: udp: Check net_pkt_read_u8 result
In case packet read fails for any reason, there's no point proceeding or
printing the byte, just break the loop in such case.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-06-26 08:59:41 -04:00
Robert Lubos
ee451e5cf0 net: sockets: tls: Fix iov_len comparison in sendmsg()
vec->iov_len is of type size_t, so the comparison was always true.
Additionally, doing the memcpy() when iov_len was 0 did not really make
sense, so do it only when the actual length is larger than 0.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-06-26 12:39:51 +02:00
Chris Friedt
9ada52f060 fdtable: replace z_ prefix with zvfs_ for fdtable.h functions
For each of the fdtable.h functions listed below, convert the
z_ prefixed semi-private functions to use the zvfs_ prefix.

ZVFS stands for Zephyr Virtual File System and
is intended to be a common library used by the C library,
POSIX API, Networking, Filesystem, and other areas.

There are already a few functions in fdtable.h that use the
zvfs_ prefix, so this change is mostly about unifying them in
a way that uses a suitable prefix ("namespace") so that it can
be considered a public API.

- z_alloc_fd
- z_fdtable_call_ioctl
- z_finalize_fd
- z_finalize_typed_fd
- z_free_fd
- z_get_fd_obj
- z_get_fd_obj_and_vtable
- z_get_obj_lock_and_cond
- z_reserve_fd

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-06-26 12:33:02 +02:00
Andreas Ålgård
eb4c76a6ec net: lib: dhcpv4_server: Fix client ID bug
First byte of client ID should be htype, followed by the client address.
See: https://datatracker.ietf.org/doc/html/rfc1533#section-9.12

Signed-off-by: Andreas Ålgård <aal@ixys.no>
2024-06-26 05:58:49 -04:00
Robert Lubos
0aeecbbbfb net: tcp: Fix peer pointer use in net_tcp_endpoint_copy()
net_tcp_endpoint_copy() used wrong pointer to copy peer address.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-06-26 05:58:36 -04:00
Robert Lubos
f3dbd38a77 net: tcp: Conditionally compile entire tcpv4/6_init_isn()
Partial conditional compilation within tcpv4/6_init_isn() caused
errors in coverity, as hash variable seemed to be used w/o
initialization.

As those functions are not really used at all if
CONFIG_NET_TCP_ISN_RFC6528 is disabled, we can just conditionally
compile entire functions to avoid confusion.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-06-26 05:58:36 -04:00
Pisit Sawangvonganan
1e03106d75 net: ip: fix typo
Utilize a code spell-checking tool to scan for and correct spelling errors
in all files within the `subsys/net/ip` directory.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-06-25 21:19:00 -04:00
Robert Lubos
ddf9e67169 net: lib: sockets: net_mgmt: Add note about thread priorities
Add a note about the thread priority requirements in the help string of
the Kconfig option enabling net_mgmt sockets.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-06-25 10:25:37 -04:00
Lingao Meng
302422ad9d everywhere: replace double words
import os
import re

common_words = set([
    'about', 'after', 'all', 'also', 'an', 'and',
     'any', 'are', 'as', 'at',
    'be', 'because', 'but', 'by', 'can', 'come',
    'could', 'day', 'do', 'even',
    'first', 'for', 'get', 'give', 'go', 'has',
    'have', 'he', 'her',
    'him', 'his', 'how', 'I', 'in', 'into', 'it',
    'its', 'just',
    'know', 'like', 'look', 'make', 'man', 'many',
    'me', 'more', 'my', 'new',
    'no', 'not', 'now', 'of', 'one', 'only', 'or',
    'other', 'our', 'out',
    'over', 'people', 'say', 'see', 'she', 'so',
    'some', 'take', 'tell', 'than',
    'their', 'them', 'then', 'there', 'these',
    'they', 'think',
    'this', 'time', 'two', 'up', 'use', 'very',
    'want', 'was', 'way',
    'we', 'well', 'what', 'when', 'which', 'who',
    'will', 'with', 'would',
    'year', 'you', 'your'
])

valid_extensions = set([
    'c', 'h', 'yaml', 'cmake', 'conf', 'txt', 'overlay',
    'rst', 'dtsi',
    'Kconfig', 'dts', 'defconfig', 'yml', 'ld', 'sh', 'py',
    'soc', 'cfg'
])

def filter_repeated_words(text):
    # Split the text into lines
    lines = text.split('\n')

    # Combine lines into a single string with unique separator
    combined_text = '/*sep*/'.join(lines)

    # Replace repeated words within a line
    def replace_within_line(match):
        return match.group(1)

    # Regex for matching repeated words within a line
    within_line_pattern =
	re.compile(r'\b(' +
		'|'.join(map(re.escape, common_words)) +
		r')\b\s+\b\1\b')
    combined_text = within_line_pattern.
		sub(replace_within_line, combined_text)

    # Replace repeated words across line boundaries
    def replace_across_lines(match):
        return match.group(1) + match.group(2)

    # Regex for matching repeated words across line boundaries
    across_lines_pattern = re.
		compile(r'\b(' + '|'.join(
			map(re.escape, common_words)) +
			r')\b(\s*[*\/\n\s]*)\b\1\b')
    combined_text = across_lines_pattern.
		sub(replace_across_lines, combined_text)

    # Split the text back into lines
    filtered_text = combined_text.split('/*sep*/')

    return '\n'.join(filtered_text)

def process_file(file_path):
    with open(file_path, 'r', encoding='utf-8') as file:
        text = file.read()

    new_text = filter_repeated_words(text)

    with open(file_path, 'w', encoding='utf-8') as file:
        file.write(new_text)

def process_directory(directory_path):
    for root, dirs, files in os.walk(directory_path):
        dirs[:] = [d for d in dirs if not d.startswith('.')]
        for file in files:
            # Filter out hidden files
            if file.startswith('.'):
                continue
            file_extension = file.split('.')[-1]
            if
	file_extension in valid_extensions:  # 只处理指定后缀的文件
                file_path = os.path.join(root, file)
                print(f"Processed file: {file_path}")
                process_file(file_path)

directory_to_process = "/home/mi/works/github/zephyrproject/zephyr"
process_directory(directory_to_process)

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2024-06-25 06:05:35 -04:00
Jukka Rissanen
c706b9031c net: if: Make sure interface name can contain terminating null
The minimum length for the network interface buffer is 2 so that we
can have terminating null there.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-06-24 14:48:03 -04:00
Jukka Rissanen
8c1834a25a net: dns: mdns_responder: Interface name might miss terminating null
The network interface name that is copied to if_req struct might
be missing terminating null.

Fixes #74795
Coverity-CID: 368797

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-06-24 14:48:03 -04:00
Jukka Rissanen
b1a1a534ff net: websocket: Remove dead code
The zsock_close() is not needed as the fd is always <0 so
the close is never called.

Fixes #74791
Coverity-CID: 366273

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-06-24 14:47:52 -04:00
Robert Lubos
b854d8b466 net: sockets_service: Increase stack size for mDNS responder
Tests showed that mDNS responder needs slightly more stack on certain
platforms, hence increase the default for such case.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-06-24 12:42:16 -04:00
Robert Lubos
027a19a565 net: lib: dns_sd: Fix buffer sizes on query processing
A few issues were identified with DNS_SD segment buffers, making it work
"by chance" (depending on memory layout):

- size check in dns_sd_query_extract() did not take NULL termination
  into account, and in result could overflow provided buffer
- the proto_buf in send_sd_response() can either be used to parse
  protocol or domain, depending on number of segments in the query.
  It should therefore be large enough to hold either.
- Similarily, instance_buf should be able to hold
  DNS_SD_INSTANCE_MAX_SIZE, not DNS_SD_SERVICE_MAX_SIZE.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-06-24 12:42:16 -04:00
Robert Lubos
d9a979f2dc net: lib: dhcpv4: Fix typo in logs
DHCPv4 was misspelled in logs.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-06-24 12:41:38 -04:00
Robert Lubos
cd5e1cd0a5 net: lib: http_server: Fix possible NULL pointer dereference
Fix possible NULL pointer dereference in http_hpack_decode_header().

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-06-24 12:41:22 -04:00
Jukka Rissanen
a0b56dab1a net: dns: llmnr_responder: Fix uinit variable
The family variable was not initialized and could potentially
be left like that. This could only affect error printout.

Fixes #74796
Coverity-CID: 368799

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-06-24 12:41:06 -04:00
Alberto Escolar Piedras
f13196429e subsys/net/lib/http: Set feature macro as required
This file uses strnlen() but the C library
is not require to expose its prototype unless
_POSIX_C_SOURCE is defined.
So let's define it to avoid an implicit function
declaration warning.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2024-06-24 13:01:38 +02:00
Jordan Yates
07870934e3 everywhere: replace double words
Treewide search and replace on a range of double word combinations:
    * `the the`
    * `to to`
    * `if if`
    * `that that`
    * `on on`
    * `is is`
    * `from from`

Signed-off-by: Jordan Yates <jordan@embeint.com>
2024-06-22 05:40:22 -04:00
Robert Lubos
abc91227b2 net: lib: zperf: Fix socket leak during asynchronous TCP upload
In case of TCP upload error, zperf would leak a socket when running in
asynchronous mode. The upload work have to release the socket it
allocated in any case, regardless of the session result.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-06-21 11:38:11 -04:00
Robert Lubos
5cea38021e net: lib: zperf: Fix socket leak during socket setup
During socket setup, if one of the setsockopt() calls failed, the
function would return an error w/o closing the socket. That's wrong, as
in case of errors the function should clean up any resources it
allocated, the socket file descriptor is lost otherwise and resources
are leaked.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-06-21 11:38:11 -04:00
Robert Lubos
1aca4205b8 net: lib: dns: Fix error code returned when socket creation failed
We should return the errno value in such case, as ret will always be -1
on failure, which might misleading, as it does not give any hint on what
failed.

Also bump the log level of the error message, so the failure is visible
w/o needing to enable debug logs. Such a failure is fatal for the DNS
subsystem, so error level is justified here.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-06-21 08:44:29 -04:00
Robert Lubos
e018281d3b net: lib: dns: Fix DNS dispatcher double net buf unref
The `dns_data` buffer, allocated by the DNS dispatcher was dereferenced
twice - once in registered DNS handler, second time in the dispatcher
itself.

Since the buffer was allocated by the dispatcher, and it's not really
guaranteed that the buffer will be freed in the registered handler (this
depends on the processing outcome, the function may return early w/o
freeing the net buf in case of errors), it makes most sense for the
dispatcher to keep ownership of the buffer. Hence, the registered
handlers will no longer release the buffer provided in any case, and the
dispatcher will free it on exit.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-06-21 08:44:15 -04:00
Maochen Wang
8a37897b5c net: ethernet: Fix EAPol packet length changed wrongly
In ethernet_recv(), it will call ethernet_update_length() to check for
ipv4 or ipv6 packet if it needs to get rid of the padding in the
packets. But for EAPOL packets, no need to do this, which may modify
the packet length of EAP type packet wrongly and leads to EAPoL
packets dropped in supplicant.

Signed-off-by: Maochen Wang <maochen.wang@nxp.com>
2024-06-20 12:47:18 +02:00
Maochen Wang
762169034b net: wifi: split wifi interface into STA and uAP
Split wifi interface into station mode and soft-AP mode, as there may be
station and soft-AP two interfaces that work concurrently.

Signed-off-by: Maochen Wang <maochen.wang@nxp.com>
2024-06-20 12:47:18 +02:00
Henrik Maier
abeae8fd08 net: lib: http_server: Fix dynamic HTTP post zero 0 length reply
Fix issue in http server that a http post
was unable to send a 0 length reply.

Signed-off-by: Henrik Maier <hwmaier@gmail.com>
2024-06-20 08:58:03 +02:00
Chris Friedt
72bd951ac4 net: ptp: do not use a reserved id in global scope
Generally, we should avoid using reserved names in global
contexts.

subsys/net/lib/ptp/clock.c:58:25: \
  error: 'clock' redeclared as different kind of symbol
   58 | static struct ptp_clock clock = { 0 };

/opt/toolchains/zephyr-sdk-0.16.8/arm-zephyr-eabi/picolibc/ \
  include/time.h💯12: \
  note: previous declaration of 'clock' with type 'clock_t(void)' \
  {aka 'long unsigned int(void)'}
  100 | clock_t    clock (void);

subsys/net/lib/ptp/clock.c:58:25: \
  error: 'clock' defined but not used [-Werror=unused-variable]
   58 | static struct ptp_clock clock = { 0 };

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-06-18 19:54:53 -04:00
Yong Cong Sin
624f4a1ec0 net: ieee802154: remove CONFIG_NET_L2_IEEE802154_ACK_REPLY
`CONFIG_NET_L2_IEEE802154_ACK_REPLY` has been deprecated for
more than 2 releases, remove it.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-06-18 14:33:58 -04:00