Commit graph

5605 commits

Author SHA1 Message Date
Jukka Rissanen def4a7ec12 net: gptp: Remove VLAN support
The gPTP is not suppose to be run on top of VLAN and the
earlier support was just for testing purposes. Remove VLAN
support now after the VLAN overhaul.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-03-28 09:41:38 +00:00
Jukka Rissanen 3a67c6d8f5 net: arp: Enhance debug prints by printing interface index
Print also network interface index together with the pointer value
in order to get more useful information what is going on in the system.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-03-28 09:41:38 +00:00
Jukka Rissanen 0e6341cc22 net: ethernet: Enhance debug prints by printing ifindex
Network interface index number is useful to see in
debug messages so print it.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-03-28 09:41:38 +00:00
Jukka Rissanen 0de1a75f91 net: shell: Print multicast join status for iface cmd
Print information whether a multicast address is properly
joined to a multicast group when print addresses using
"net iface" command.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-03-28 09:41:38 +00:00
Jukka Rissanen 999c169d9d net: shell: Print VLAN name instead of interface type
As the interface type is always Virtual, no need to print it.
Print instead the name of the network interface as it is more
useful to the user.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-03-28 09:41:38 +00:00
Jukka Rissanen eb11a8af1c net: shell: Refactor VLAN configuration prints
Rework the way VLAN configuration is printed out.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-03-28 09:41:38 +00:00
Jukka Rissanen 092f7f7666 net: virtual: Do not try to send data if interface is down
Make sure the interface is up before trying to send data to
lower level interface.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-03-28 09:41:38 +00:00
Jukka Rissanen e9994c8af8 net: virtual: Force LAA bit for link address
Make sure LAA (locally administred address) bit is set for the
generated link address.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-03-28 09:41:38 +00:00
Jukka Rissanen 63081bd7da net: if: We can only rejoin mcast groups for native IP stack
No point trying to join multicast groups if the network interface
is offloaded one.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-03-28 09:41:38 +00:00
Jukka Rissanen e3f1271fb9 net: if: Join all unjoined solicited node multicast groups
If an IPv6 address was added to the interface while the
interface was down, its solicited node multicast address
is not joined properly and IPv6 communication will to
other hosts will fail. So make sure to rejoin all the
solicited node multicast groups that were joined already
when the network inteface is going up.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-03-28 09:41:38 +00:00
Jukka Rissanen 493c1c1f01 net: if: Add debug print when interface is taken up
Add debug information to print when the network L2 enable
callback is called and fails. Useful to see this information
as at that point the interface goes down.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-03-28 09:41:38 +00:00
Jukka Rissanen a96a2f8d09 net: if: Start IPv6 DAD when interface comes up
Start any pending IPv6 DAD timers when interface comes up.
If IPv6 addresses have been added to the network interface when
it was down, the addresses would never work properly if the DAD
is not done.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-03-28 09:41:38 +00:00
Jukka Rissanen b5bdc1fa6b net: if: Enhance debug prints when adding IP address to iface
Instead of printing just a network interface pointer, print
also the interface index so debugging is a bit faster as no
lookup from interface listing is needed.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-03-28 09:41:38 +00:00
Jukka Rissanen ff01324c9b net: if: Remove VLAN count checks
No need to do the checks any more because user has specified
the VLAN count and so many VLAN virtual interface are already
created.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-03-28 09:41:38 +00:00
Jukka Rissanen 2058d8f139 net: ethernet: VLAN overhaul and refactoring
Re-implement the VLAN support inside the network stack.
All the user facing APIs stay as is but internally the VLANs
are implemented using the L2 virtual interfaces.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-03-28 09:41:38 +00:00
Jukka Rissanen 42356b6d5c net: wifi: shell: Avoid declaring variables after case statement
Some compilers have trouble parsing variables directly after a case
statement.

Fixes: #70792

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-03-27 16:26:45 -05:00
Jukka Rissanen d7c9d67a9c net: Use always zephyr/posix/fcntl.h
Changing remaining users of fcntl.h to use the include from our own
POSIX file so that the values in there are consistent in all parts
of the sources.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-03-27 13:40:13 -05:00
Jukka Rissanen 873af2ee98 net: sockets: Use only Zephyr POSIX headers
Use only Zephyr specific POSIX header files so that the whole
system is getting values from the same files. There was an issue with
native_sim run of tests/net/socket/af_packet which had O_BLOCKING set
to 0x4000 from include/zephyr/posix/fcntl.h, but then the file
subsys/net/lib/socket/sockets.c was having O_BLOCKING set to 0x0800
because different header files were used.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-03-27 13:40:13 -05:00
Jukka Rissanen 1b07425ead net: websocket: Use zsock_ API calls
Use zsock_ API calls so that we do not need to enable POSIX_API.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-03-27 13:40:13 -05:00
Jukka Rissanen de52f8924f net: socks: Remove socket selection
Currently the socks library does not use sockets so there
is no need to select socket symbols.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-03-27 13:40:13 -05:00
Jukka Rissanen 79585d5355 net: tftp: Use zsock_ API functions
The library should be using internal socket API functions
so that we do not need to depend on POSIX_API inside the
network stack.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-03-27 13:40:13 -05:00
Jukka Rissanen e6e6bb4242 net: socket: Create zsock_fcntl and fsock_ioctl functions
Have special wrappers for zsock_fcntl and zsock_ioctl functions
so that gcc warning can be avoided.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-03-27 13:40:13 -05:00
Jukka Rissanen 3eeb0f0c7f net: sockets: Deprecate CONFIG_NET_SOCKETS_POSIX_NAMES
The CONFIG_NET_SOCKETS_POSIX_NAMES option is marked as deprecated in
favor of using normal POSIX socket API includes found under the
include/zephyr/posix directory. If you want to use BSD socket API calls,
you need to select POSIX_API and use the socket headers found in the
POSIX subsystem. If you do not want to or cannot enable POSIX_API,
then you must use zsock_ prefix when working with BSD socket calls.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-03-27 13:40:13 -05:00
Pisit Sawangvonganan e145eb9201 net: wifi: shell: adopt getopt_state for safer optarg access
By using `getopt_state` to access `optarg`, offering a better alternative
to direct global `optarg` access.

This approach mitigates the risks associated with concurrent access to
the global variable.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-03-27 14:33:51 +00:00
Pisit Sawangvonganan a6865c4191 net: wifi: shell: apply struct option as static const
This change marks each instance of the `struct option` as `static const`.

The rationale is that `struct option` is a read-only variable.
By using `static const`, we ensure immutability, leading to usage of only
the `.rodata` section and a reduction in the `.data` area.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-03-27 14:33:51 +00:00
Pisit Sawangvonganan d9c6d30c25 net: wifi: shell: streamlined local variable initializations
This commit simplifies the access to structure members and omits
unnecessary variable initializations.

Specific adjustments include:
- Moving from pointer-based access (`(&regd)->chan_info`) to
  direct structure member access (`regd.chan_info`).
- Removing explicit initializations where not required.
- Removing excess backslashes '\' before '%' in the format string.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-03-27 14:33:51 +00:00
Jukka Rissanen d1ef9167da net: if: Make sure no other interface has same name
When setting a name to a network interface, verify that no other
interface has the same name as that would make very difficult to
select an interface by a name.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-03-27 14:32:34 +00:00
Reto Schneider 8918247f37 net: buf_simple: Add support for 40 bit data type
This enables pulling and pushing values in 40 bit format.

Signed-off-by: Reto Schneider <reto.schneider@husqvarnagroup.com>
2024-03-26 19:32:27 -04:00
Reto Schneider 9b2312d055 net: buf: Fix cloning of zero-sized buffers
For zero sized buffers, instead of pointing to a buffer, net_buf->__buf
is NULL. For this reason, when cloning a buffer, the code needs to check
__buf before dereferencing it.

Signed-off-by: Reto Schneider <reto.schneider@husqvarnagroup.com>
2024-03-26 19:31:21 -04:00
Ravi Dondaputi 73ed81ccce net: wifi: shell: Support BSSID configuration
Add support for BSSID configuration in connect call.

Signed-off-by: Ravi Dondaputi <ravi.dondaputi@nordicsemi.no>
2024-03-26 11:13:21 -05:00
Ravi Dondaputi 8256d02d3a net: wifi: shell: Use getopt API for connect options
Use getopt API to process the arguments passed with connect
command.

Signed-off-by: Ravi Dondaputi <ravi.dondaputi@nordicsemi.no>
2024-03-26 11:13:21 -05:00
Jukka Rissanen 9fb8d511e1 net: if: Set default interface name if needed
If the driver does not set the interface name, then set
a default name for it.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-03-26 12:01:51 -04:00
Marco Argiolas 2f35d11bfe net: lib: lwm2m: block 0 resets prev block transfer for same resource
As stated in "[RFC7959], Section 2.5":
   "The Block1 Option provides no way for a single endpoint to perform
   multiple concurrently proceeding block-wise request payload transfer
   (e.g., PUT or POST) operations to the same resource.  Starting a new
   block-wise sequence of requests to the same resource (before an old
   sequence from the same endpoint was finished) simply overwrites the
   context the server may still be keeping."

Signed-off-by: Marco Argiolas <marco.argiolas@ftpsolutions.com.au>
2024-03-26 09:38:55 +00:00
Marco Argiolas 215782aa5c net: lib: lwm2m: fix function parameter for SW management object
Fix build error.

Signed-off-by: Marco Argiolas <marco.argiolas@ftpsolutions.com.au>
2024-03-26 09:38:55 +00:00
Jukka Rissanen 280391ded8 net: ipip: Refactor the IP tunneling support
Refactor the IP tunneling support as the input callback was removed
in previous commit. The data will flow through the recv callback now
as expected.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-03-25 17:07:43 +01:00
Jukka Rissanen 2c1f10b60e net: virtual: Remove the input callback as obsolete
The input callback was an unfortunate idea which just complicated
how the packet flows through virtual interfaces so removing it.
The data is passed normally through the recv callback from now on.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-03-25 17:07:43 +01:00
Jukka Rissanen f61453de10 net: virtual: Add statistics collection
Collect statistics of sent/received network packets for the
virtual interface.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-03-25 17:07:43 +01:00
Jukka Rissanen ce8c618b6b net: virtual: Fix the virtual L2 receive function
The function needs to loop through the virtual interfaces
tied to this physical interface.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-03-25 17:07:43 +01:00
Kapil Bhatt c1e29cc107 net: wifi: Add channel validity check for AP mode
Channel is mandatory for AP mode. It is processed only
if its less than or equal to three characters. Otherwise
we need to throw error for channel in AP mode.

Signed-off-by: Kapil Bhatt <kapil.bhatt@nordicsemi.no>
2024-03-25 16:18:18 +01:00
Reto Schneider 9dd87a7194 net: buf: Support copying of user data
This functionality is useful on the following scenario:

1) The first buffer in a net_pkt contains user data which is relevant
   for the (whole) net_pkt.
2) When inserting a new buffer in front of the net_pkt, the (previously)
   first buffer (and its user data) are no longer accessible via
   net_pkt->buffer.
3) net_buf_user_data_copy() allows to simply copy the user data from the
   old to the new first  buffer.

Signed-off-by: Reto Schneider <reto.schneider@husqvarnagroup.com>
2024-03-25 09:32:48 +01:00
Jukka Rissanen 09abd850d9 net: shell: Do not print DHCPv4 info if IPv4 is not available
If the network interface does not enable IPv4, then it is pointless
to print DHCPv4 information when invoking "iface" shell command.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-03-22 21:00:37 -05:00
Robert Lubos 7207f35758 net: tcp: Fix ACK check in LAST_ACK state
The final ACK check during passive close was wrong - we should not
compare its SEQ number with the ACK number we've sent last, but rather
compare the ACK number it acknowledges matches our current SEQ number on
the connection. This ensures, that the ACK received is really
acknowledging the FIN packet we've sent from our side, and is not just
some earlier retransmission. Currently the latter could be the case, and
we've closed the connection prematurely. In result, when the real "final
ACK" arrived, the TCP stack replied with RST.

Subsequently, we should increment the SEQ number on the connection after
sending FIN packet, so that we are able to identify final ACK correctly,
just as it's done in active close cases.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-03-22 15:56:50 -05:00
Kapil Bhatt e25c68be5d net: wifi: Set default values of dwell time
Dwell time Active or Passive is optional in wifi scan.
If user don't set the Dwell time value, it will be set
as 0. We are adding a range check in scan extensions
for dwell time. So need to set default values.

Signed-off-by: Kapil Bhatt <kapil.bhatt@nordicsemi.no>
2024-03-22 14:26:01 +00:00
Noah Pendleton 38ad4b6d43 net: sockets: tls: Add error log when cert parse fails
Add an error log if there's a failure when attempting to load
certificates during socket connect.

Signed-off-by: Noah Pendleton <noah.pendleton@gmail.com>
2024-03-22 14:49:37 +01:00
Konrad Derda 42e6c1fbc6 net: mdns: add capability of providing records in runtime
Current implementation of mDNS responder does makes it mandatory to have
all the records set at compile time. It is not suited well for applications
that have to publish/unpublish or change records in runtime, e.g. data
received from the network.

Signed-off-by: Konrad Derda <konrad.derda@nordicsemi.no>
2024-03-22 12:41:56 +00:00
Robert Lubos 323f1f81b9 net: dhcpv4_server: Add option to NAK Request from unrecognized client
Zephyr's DHCPv4 server does not implement persistent storage of address
leases. In result, all leases are lost on reboot, which can cause
delays with clients starting in INIT-REBOOT state and thus sending
(potentially several) Requests before attempting full Discover-Request
procedure.
Add option to override RFC defined behavior, which states that if we
don't recognize the client sending the Request, the server shall remain
silent. Enabling that option allows the server to send NAK reply in case
client is not recognized, informing the client it should proceed with
full procedure.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-03-22 10:24:15 +01:00
Robert Lubos fd113b7102 net: dhcpv4_server: Include client ID in server responses
RFC6842 updated RFC2131 in terms of including client ID option in
responses sent from the server. According to that RFC, the server MUST
include the client ID option in Offer/Ack/Nak replies, if it was
provided by the client.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-03-22 10:24:15 +01:00
Robert Lubos 41ffc5fabb net: dhcpv4_server: Improve DHCP Request retransmission handling
In case ACK from the server was lost, we'd not reply Request
retransmissions, as the lease state is already in allocated state on the
server side. Therefore we also need to allow to reply with ACK in such
case.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-03-22 10:24:15 +01:00
Robert Lubos 50e0807c0a net: dhcpv4_server: Increase reserved address timeout
5 seconds turned out to be too short timeout in case retransmissions
kicked in at DHCP level, hence increase the timeout.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-03-22 10:24:15 +01:00
Robert Lubos 239d718bc7 net: ipv6: Introduce separate logger module for IPv6 ND
Debugging IPv6 Neighbor Discovery issues requires to enable full IPv6
logs, which can get bloated given it provides logs for every single
packet. We should be able to focus on IPv6 ND logs only, hence introduce
a separate log module for IPv6 ND.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-03-21 18:00:50 +01:00
Pieter De Gendt e99b5228a1 drivers: ethernet: Introduce ETH_DRIVER_RAW_MODE option
Add a Kconfig symbol to allow building ethernet device driver without
an L2 layer.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2024-03-20 08:05:55 -05:00
Jukka Rissanen 8f4ac0d4ab net: trickle: Rename interval function
The function inteval_timeout() was missing "r", the function
should be called interval_timeout()

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-03-19 15:20:14 -05:00
Savin Weeraratne 816a1381fa net: ipv4: Allow IGMP packets with zero src address
IGMP queries sent out by a proxy querier can have
a source IP address 0.0.0.0
Allow these incoming packets.

Fixes #69917

Signed-off-by: Savin Weeraratne <savin.weeraratne@audinate.com>
2024-03-19 09:47:00 +01:00
Fengming Ye 6a0c38680f net: ipv6: fix link local ping fail with default router
When we receive Router Advertisement with life time,
we will add this as default router, like typing command "net iface"
and has show below
IPv6 default router :
fe80:xxxx::xxxx

When this default router is backend A and
we ping backend B with link local address,
we will use default router A and send echo request
to backend A instead of B, which will receive Redirect and no reply.

Fix it by link local address does not check route.

Signed-off-by: Fengming Ye <frank.ye@nxp.com>
2024-03-19 09:46:49 +01:00
Pieter De Gendt af8ba2a361 net: ethernet: Register multicast monitor for MAC filtering
Register a multicast monitor for ethernet if HW MAC filtering is supported

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2024-03-18 10:14:34 +01:00
Pieter De Gendt 64bc618725 net: ethernet: mgmt: Add HW MAC address filtering
Add an ethernet management API to set or unset HW MAC address filtering.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2024-03-18 10:14:34 +01:00
Pieter De Gendt 63133be42c net: iface: Allow catch-all multicast monitor
Registering a multicast monitor with a NULL interface will receive all
events.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2024-03-18 10:14:34 +01:00
Pieter De Gendt 303c56fbb2 net: ip: Add helper NET_NATIVE_IP kconfig symbol
Introduce a NET_NATIVE_IP symbol similar to IPv4/IPv6 variants.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2024-03-18 10:14:34 +01:00
Robert Lubos cb0a12311b net: tcp: Remove redundant debug logs
Debug logs in helper functions like tcp_unsent_len() or
tcp_window_full() are not very helpful and generate a heavy, unnecessary
log output. Therefore, tcp_unsent_len() will no longer generate log, and
tcp_window_full() will print out a log only when the window is actually
full, which could be an useful information.

Also, reduce the log load during TX, as currently redundant logs were
printed in tcp_out_ext(), tcp_send_process_no_lock() and finally in
tcp_send().

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-03-15 15:30:00 +01:00
Maochen Wang 7b916593ec net: igmp: Fix double unref of igmp packet
If send the igmp packet when lower interface is down, the packet will be
freed twice and show error log. Remove the net_pkt_unref in igmp_send(),
and let the caller free it.

Signed-off-by: Maochen Wang <maochen.wang@nxp.com>
2024-03-15 13:35:16 +01:00
Fengming Ye 10670b7515 net: zperf: multicast support on multi interfaces
Zperf upload multicast always use default interface.
Zperf download multicast cannot receive packets from other than
224.0.0.1 which is default multicast group.

Add zperf upload/download option -I <interface name> for multicast.
So that user can select interface for multicast.
Add join multicast group for zperf download.

Use the "device list" command to get the interface name as
follows:
 "- ua (READY)"  #uAP interface name
 "- ml (READY)"  #STA interface name

Multicast traffic commands:
zperf udp upload -a -I ua 224.0.0.2 5001 10 1470 1M
zperf udp download -I ua 5001 224.0.0.3

Signed-off-by: Fengming Ye <frank.ye@nxp.com>
2024-03-15 13:07:14 +01:00
Carlo Kirchmeier 7bfaca4c58 net: dns: Add DNS cache for improved performance
In order to reduce dns resolve requests when using the dns
resolver an optional cache was introduced. This cache
retains query requests for the TTL duration and therefore
prevents premature refetching of DNS RRs.

Signed-off-by: Carlo Kirchmeier <carlo.kirchmeier@zuehlke.com>
2024-03-15 08:37:29 +00:00
sukrit buddeewong 3ad8d32d18 net: mqtt: Implement ALPN Support for socket mqtt
Implement the ALPN Support for Mqtt Library allow mqtt to have
ability to utilize ALPN for connect to server that support ALPN, such
as AWS IoT Core

Signed-off-by: sukrit buddeewong <sukrit.omu@gmail.com>
2024-03-14 17:04:11 -05:00
Takuya Sasaki 7d1edd1fcb net: context: Fix the ICMP error on raw
This commit applies the issues detected in UDP to recv_raw() as
well. Please refer to the previous commit log for details.

Signed-off-by: Takuya Sasaki <takuya.sasaki@spacecubics.com>
2024-03-14 11:08:59 -05:00
Takuya Sasaki 4f802e1197 net: context: Fix the ICMP error on udp
When receiving a UDP packet, net_conn_input() searches for a
matching connection within `conn_used`.

However, when receiving UDP packets simultaneously from multiple
clients, we may encounter a situation where the connection that was
supposed to be bound cannot be found within `conn_used`, and raise
the ICMP error.

This is because, within recv_udp(), to avoid the failure of
bind_default(), we temporarily remove it from `conn_used` using
net_conn_unregister().

If the context already has a connection handler, it means it's
already registered. In that case, all we have to do is 1) update
the callback registered in the net_context and 2) update the
user_data and remote address and port using net_conn_update().

Fixes #70020

Signed-off-by: Takuya Sasaki <takuya.sasaki@spacecubics.com>
2024-03-14 11:08:59 -05:00
Takuya Sasaki 46ca624be4 net: conn: Add internal function for update connection
This commit adds the new internal function for update the callback,
user data, remote address, and port for a registered connection
handle.

Signed-off-by: Takuya Sasaki <takuya.sasaki@spacecubics.com>
2024-03-14 11:08:59 -05:00
Takuya Sasaki ef18518e91 net: conn: Add static function for changing remote
This commit adds the new static function for change the remote
address and port to connection, and replaces the changing process
for remote address and port in net_conn_register().

Signed-off-by: Takuya Sasaki <takuya.sasaki@spacecubics.com>
2024-03-14 11:08:59 -05:00
Takuya Sasaki 49c6da51ce net: conn: Move net_conn_change_callback() to static
The net_conn_change_callback() is not currently being called by
anyone, so this commit moves to static function, and replaces
the change callback parameter process in net_conn_register().

Signed-off-by: Takuya Sasaki <takuya.sasaki@spacecubics.com>
2024-03-14 11:08:59 -05:00
Stefan Schwendeler 947d4a13c3 net: lwm2m: removes redundant newline for log and shell calls
All the shell and logger calls here already add a newline.

Signed-off-by: Stefan Schwendeler <Stefan.Schwendeler@husqvarnagroup.com>
2024-03-14 11:04:59 -05:00
Daniel Nejezchleb 9d801c4fdc net: tcp: Fix possible deadlock in tcp
The mutex was removed in tcp_recv() where it doesn't seem
to be needed anymore as tcp_conn_search() got
tcp_mutex. In the other areas the tcp_mutex was
narrowed down to protect only the list.

Signed-off-by: Daniel Nejezchleb <dnejezchleb@hwg.cz>
2024-03-14 12:22:08 +01:00
Maochen Wang ebced020ec net: arp: Fix failed to add the arp table in stress test
During stress test with WiFi connect, disconnect, ping and throughput
traffic, ARP table updating failed issue may occur.
In arp_prepare(), if packet allocate failed, should add the arp
entry back to arp_free_entries, to avoid this entry is leak forever.

Signed-off-by: Maochen Wang <maochen.wang@nxp.com>
2024-03-14 12:21:39 +01:00
Fengming Ye c5b2a16dd2 net: zperf: fix download ipv6 bind fail on specific ip address
For command zperf udp download 5001 192.168.10.1,
zperf will bind both ipv4 and ipv6 sockets on ipv4 address.
But bind ipv6 socket will fail, thus command return fail.

Fix it by check ip address when zperf download.
For ipv4 address only bind ipv4 socket.
For ipv6 address only bind ipv6 socket.
For unspecific address bind both ipv4 and ipv6 sockets.

Signed-off-by: Fengming Ye <frank.ye@nxp.com>
2024-03-14 09:47:03 +00:00
Seppo Takalo 8a38ff7161 net: lwm2m: Handle empty URI
On some content-types, it might be impossible to
send strings with size of zero.
Therefore empty URI should also allow cases
where strlen() is zero.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2024-03-13 11:37:54 -05:00
Robert Lubos 53561e3766 net: dns: Fix timeout calculation with DNS retransmissions
With recently introduced DNS retransmission mechanism, a certain bug
could occur when calculating query timeout.

If the time until the final DNS timeout (as indicated by
CONFIG_NET_SOCKETS_DNS_TIMEOUT) was less than 1 millisecond, the actual
millisecond timeout value was rounded down, resulting in 0 ms timeout.
This in order was interpreted as invalid argument by dns_get_addr_info()
function, so in result, instead of reporting query timeout, the function
reported invalid argument error.

Fix this by rounding the millisecond timeout up, instead of down, so
that in any case, if the final timeout is not due, we always provide
non-zero timeout to dns_get_addr_info().

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-03-12 15:13:31 -05:00
Robert Lubos 9e2e234003 net: telnet: Switch TELNET shell backend to use sockets
Rework TELNET shell backend to use socket API for communication and
socket service library for socket monitoring.

Additionally, rework the TX part so that non-blocking TX is used when
sending from the system work queue. In case transfer is not possible at
the moment, the TX work is rescheduled instead of blocking the system
work queue.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-03-11 15:09:32 -05:00
Robert Lubos fef58a2a69 net: sockets: Stick to NET_SOCKETS_POLL_MAX limit in socket services
Socket service pollfd count should not exceed the configured
NET_SOCKETS_POLL_MAX limit, as poll() will not be able to monitor
sockets beyond that limit anyway. Adding +1 there prevented the library
from catching the configuration error.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-03-11 15:09:32 -05:00
Jukka Rissanen 7072e75162 net: dhcpv4: Network interface netmask was set too early
When we receive the subnet mask option from the server, we
cannot yet set the netmask to the network interface as the
mask is tied to the IP address we received from the server.
We need to delay the setting of netmask until we have added
the requested IP address to the interface.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-03-08 18:04:35 +01:00
Fin Maaß 0d776d39bb net: dhcpv4: set log backend net ip via option
Adds the option to set the log_backend_net ip via dhcpv4
option 7.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2024-03-08 15:18:30 +00:00
Fin Maaß 6e12b0210f log: net: move log_backend_net_get() to header
This moves the declaration of log_backend_net_get() to
zephyr/logging/log_backend_net.h

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2024-03-08 15:18:30 +00:00
Robert Lubos 9412ad306f net: sockets: packet: Ignore the packet type if LL address is not set
In case the LL address is not set on a packet for any reason, don't try
to access address structure to determine packet type.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-03-08 13:04:45 +00:00
Pieter De Gendt e2f0b92fda net: lib: shell: Fix IPv6 neighbor build
When building net shell without IPv6 native support we can't use neighbor
support.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2024-03-08 10:02:02 +00:00
Chaitanya Tata 0a8cbb6a22 net: mgmt: Handle loops in the linked list
In case the same callback handler is added to the list twice, this can
result in a loop.

Fixes: #69825.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2024-03-08 09:35:04 +01:00
Gang Li 03fce7dd3c net: zperf: Fix multicast data failure to receive server's AckFIN packet
In iperf2, for multicast data, if it is a client, it will not wait for
the server's AckFIN packet. Because the iperf2 server will not send an
AckFIN packet.
So in zperf_upload_fin(), an error will occur when the zperf client
waits for the server's AckFIN packet.
Multicast only send the negative sequence number packet and doesn't
wait for a server ack can fix this issue.

Signed-off-by: Gang Li <gang.li_1@nxp.com>
2024-03-07 16:17:18 -06:00
Pieter De Gendt 0db120abd4 net: lib: shell: iface: Fix when building ethernet without IP support
The count stack variable is also used when CONFIG_NET_L2_ETHERNET_MGMT is
enabled. Make sure it is available.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2024-03-06 15:23:52 -06:00
Jukka Rissanen 5be84131d6 net: dns: Split long resolving to smaller pieces
If getaddrinfo() is called with a long DNS timeout, then split
the timeout to smaller pieces with exponential backoff. Reason
for this is that if a DNS query is lost, then we do not need
to wait for a long time to find it out.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-03-06 13:33:50 +01:00
Chaitanya Tata 6327478429 net: lib: Add debug for sockets total and owner
This helps in figuring out the need for the number of sockets.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2024-03-06 10:20:22 +00:00
Robert Lubos 919cb6f614 net: sockets: tls: Improve sendmsg() support on DTLS sockets
DTLS socket should be able to combine more than one message into a
single datagram when calling sendmsg().

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-03-06 09:13:38 +01:00
Marcin Gasiorek fb99f65fe9 net: ip: Fix for improper offset return by net_pkt_find_offset()
The original packet's link-layer destination and source address can be
stored in separately allocated memory. This allocated memory can be
placed just after pkt data buffers.
In case when `net_pkt_find_offset()` uses condition:
`if (buf->data <= ptr && ptr <= (buf->data + buf->len)) {`
the offset is set outside the packet's buffer and the function returns
incorrect offset instead of error code.
Finally the offset is used to set ll address in cloned packet, and
this can have unexpected behavior (e.g. crash when cursor will be set
to empty memory).

Signed-off-by: Marcin Gasiorek <marcin.gasiorek@nordicsemi.no>
2024-03-05 18:23:24 +00:00
Fin Maaß c148dc15fd net: dhcpv4: add vendor specific option callback
In certain scenarios, it may be necessary to get values of additional
options from the application layer. With this patch, this can be
accomplished by registering a callback with the DHCP client.

This change has been tested using the posix build in qemu.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2024-03-05 10:22:21 -05:00
Florian La Roche e8b843b913 net: shell: keep event_mon_handler compatible to k_thread_entry_t
Nearly all other code places for k_thread_entry_t also keep
unused params in place to stay compatible with k_thread_entry_t.

Signed-off-by: Florian La Roche <Florian.LaRoche@gmail.com>
2024-03-05 14:58:29 +00:00
Sibert Declercq 808f79d863 net: coap: CoAP observe age now correctly wraps around
Fixes two bugs:
* When a notify is executed before any observers are added, the age is
incremented from 0 to 1. When an observer is registered, the age is not 0
as expected, causing the age to be 1 instead of the expected 2
* The check if a message is newer than the last received one is described
in RFC7641, section 3.4. Simply incrementing age will not comply to what
the RFC describes once the value wraps around. This is now fixed

Signed-off-by: Sibert Declercq <sibert.declercq@basalte.be>
2024-03-05 14:34:42 +01:00
Jukka Rissanen a943d7fd53 net: Convert various address loops to use ARRAY_FOR_EACH macro
Convert various networking subsystem files to use ARRAY_FOR_EACH
macro to make the looping more robust.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-03-03 18:58:29 +01:00
Jukka Rissanen 6e7d97dc38 net: if: Convert array loops to use ARRAY_FOR_EACH macro
Convert various array loops in the net_if.c to use the
ARRAY_FOR_EACH() macro. This makes the code more robust
as we do not need to keep track of the separate define
that tells the array size.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-03-03 18:58:29 +01:00
Jukka Rissanen 58b2a3dfd4 net: ipv4: Deprecate the old netmask set/get routines
This commit deprecates these legacy netmask get/set routines

net_if_ipv4_set_netmask()
net_if_ipv4_set_netmask_by_index()
net_if_ipv4_get_netmask()

as they do not work well if there are multiple IPv4 address
assigned to the network interface.

User should use these functions instead

net_if_ipv4_set_netmask_by_addr()
net_if_ipv4_set_netmask_by_addr_by_index()
net_if_ipv4_get_netmask_by_addr()

as they make sure the netmask it bound to correct IPv4 address.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-03-03 18:58:29 +01:00
Jukka Rissanen 1b0f9e865e net: ipv4: Make netmask IPv4 address specific
The netmask should be tied to the IPv4 address instead of being
global for the network interface.

If there is only one IPv4 address specified to the network interface,
nothing changes from user point of view. But if there are more than
one IPv4 address / network interface, the netmask must be specified
to each address separately.

This means that net_if_ipv4_get_netmask() and net_if_ipv4_set_netmask()
functions should not be used as they only work reliably if there is
only one IPv4 address in the network interface.

The new net_if_ipv4_get_netmask_by_addr() and
net_if_ipv4_set_netmask_by_addr() functions should be used as they make
sure that the netmask is tied to correct IPv4 address in the network
interface.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-03-03 18:58:29 +01:00
Florian La Roche d835772f38 net: conn_mgr: set a thread name
Set a thread name for net conn_mgr, so that e.g. thread listings
within the shell are easier to look at.

Signed-off-by: Florian La Roche <Florian.LaRoche@gmail.com>
2024-03-02 15:03:27 +01:00
Tomasz Bursztyka a4af2ac8dc net/ip: Removing useless extra data capability in neighbors
This is not used by anyone, and is unlikely to be useful actually.
Helps to save 4 bytes for each instance of struct net_nbr also (removing
a 2 bytes attributes, which was anyway generating a 4bytes loss due to
structure misalignment).

Removing relevant useless functions related to it as well.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2024-03-01 15:33:53 +01:00
Tomasz Bursztyka a3d7278588 net/ipv6: Enforce MLD to be selected if ND is enabled
As noted in net_if.c:net_if_ipv6_addr_add() IPv6 ND needs MLD.

It is not selected during test, as the combination of ND without DAD/MLD
breaks (something to study/fix further it seems).

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2024-03-01 15:33:53 +01:00
Tomasz Bursztyka 20ccc30273 net/if: Trivial comment fix about all-nodes
s/net_ipv6_mcast_join/net_ipv6_mld_join

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2024-03-01 15:33:53 +01:00
Tomasz Bursztyka 6d718ed480 net/mgmt: Trivial debug output fix about layer
Net MGMT uses layer identifiers that are meaningful only for itself, but
for users it requires a trivial operation to show the real layer value.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2024-03-01 15:33:53 +01:00
Tomasz Bursztyka 48216eff76 net/config: Initialize and add the net mgmt callback at the right time
Net MGMT mask should be fully configured first, prior to be used to
initialize and add the callback.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2024-03-01 15:33:53 +01:00
Tomasz Bursztyka 4d48f066a1 net/shell: Fixing a trivial error code
As for adding an ipv6 address, removing one should return the same error
code when the network interface is not found.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2024-03-01 15:33:53 +01:00
Tomasz Bursztyka 366402a0c7 net/shell: Net shell has no mandatory support for IPv6 MLD
It's an optional support, and it should not select it by default.
Improving information message in case such support is disabled.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2024-03-01 15:33:53 +01:00
Maochen Wang eda7dd1460 net: zperf: Fix wrong throughput in long-duration traffic test
The zperf received or sent bytes length and duration are in 32bits,
if running long-duration zperf test more than 20min, the value will
overflow, and the test result is wrong. Change it to 64bits can fix
this issue.

Signed-off-by: Maochen Wang <maochen.wang@nxp.com>
2024-02-29 11:54:07 +00:00
Maochen Wang e7444dcf42 net: zperf: Fix TOS option not working in zperf
When the zperf command is called with '-S' option which means IP_TOS
for IPv4 and IPV6_TCLASS for IPv6, an error is printed and the
setting does not work. The socket option handling was changed by
commit 77e522a5a243('net: context: Refactor option setters'), but the
callers of option setters were not changed. This causes the IP_TOS
or IPV6_TCLASS option failed to set. The fix is to use uint8_t to
store the value of the -S option.

Signed-off-by: Maochen Wang <maochen.wang@nxp.com>
2024-02-29 11:53:57 +00:00
Pieter De Gendt d9d710e6d3 net: ip: Add iface IPv4/IPv6 multicast foreach handlers
Add helper functions to iterate IPv4/IPv6 multicast addresses.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2024-02-28 13:18:06 -06:00
Fin Maaß bcf90edd1f net: config: use dhcpv4 option for sntp
Allow the use of the NTP server address, set by
dhcpv4 option, by the net_init_clock_via_sntp function.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2024-02-28 18:03:53 +00:00
Fin Maaß 3be6557078 net: dhcpv4: set sntp ip via option
Adds the option to set the ntp address ip via
dhcpv4 option 42 (Network Time Protocol Servers).

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2024-02-28 18:03:53 +00:00
Fin Maaß 2140a4af6a net: lib: sntp_simple: add a function to use with ip address
This adds a function to use sntp_simple with a
ip address directly.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2024-02-28 18:03:53 +00:00
Fin Maaß 78813fa3ad net: ip: add function to set default port
This adds a function, to set the default port
of a sockaddr, if the port had not been set.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2024-02-28 18:03:53 +00:00
Robert Lubos dc52b20705 net: sockets: tls: Return an error on send() after session is closed
It was an overlook to return 0 on TLS send() call, after detecting that
TLS session has been closed by peer, such a behavior is only valid for
recv(). Instead, an error should be returned.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-02-28 18:03:40 +00:00
Jukka Rissanen 28a46c0f60 net: http: client: Return error if waiting timeout
Return error to the caller if no data was received or there
was some other error. Earlier we did not check the error
condition properly.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-02-28 18:02:34 +00:00
Jukka Rissanen 1df8aaeec2 net: ipv6: Allow user to configure the IPv6 MTU size
This makes it possible to set the minimum IPv6 packet size that
can be sent without fragmentation. The default value is 1280 bytes.
This commit allows user to set the IPv6 MTU value within reasonable
limits [1280, 1500].

Fixes #61587

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-02-28 09:41:53 +01:00
Jukka Rissanen 4b82b108c8 net: zperf: Select also sockets API in Kconfig
We select sockets service API in Kconfig but should select also
sockets API so that user does not need to set the sockets API separately.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-02-28 09:40:41 +01:00
Jukka Rissanen bdfcc753c8 net: shell: Print mgmt socket information properly
The "net sockets" command did not print network management
socket information properly but claimed that the socket
was IPv4 one which it is not.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-02-28 09:39:27 +01:00
Jukka Rissanen afa4b4ad1d net: socket: mgmt: Return error for poll
The net_mgmt socket does not support poll() or fcntl(), so
return EOPNOTSUPP error if user tries to use those functions
for AF_NET_MGMT type socket.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-02-28 09:39:27 +01:00
Fin Maaß 1f2a3c46df net: dhcpv4: initialization of option_callbacks list
Initialize sys_slist_t option_callbacks statically.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2024-02-27 14:45:40 +01:00
Fin Maaß 866c804cb8 net: dhcpv4: option callback check value explicitly
Check the value of net_dhcpv4_add_option_callback()
and net_dhcpv4_remove_option_callback() explicitly.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2024-02-27 14:45:40 +01:00
Tomi Fontanilles a738bfa7f4 net: l2: ppp: ipv6cp: add assert to check the link address length
This ensures that the configured link address is
at least as big as the part of it that is used.

Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
2024-02-26 14:43:07 +01:00
Juha Ylinen f38ecb7a09 net: lwm2m: Add API to set multiple resource values
Add new API lwm2m_set_bulk() to set multiple resource values in
one function call.

Signed-off-by: Juha Ylinen <juha.ylinen@nordicsemi.no>
2024-02-26 11:53:29 +00:00
Łukasz Duda 6e31820f4c net: ipv6: nbr: Expose API for reporting neighbor reachability
This commit extends Zephyr's networking API to allow higher layers to
report on neighbor reachability.

Signed-off-by: Łukasz Duda <lukasz.duda@nordicsemi.no>
2024-02-26 11:51:42 +00:00
Robert Lubos 9cb21e695f net: dhcpv4_server: Apply range limits for Kconfig options
Apply ranges to DHCPv4 server timeout Kconfig options, so that it cannot
be set to a negative value by mistake.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-02-26 11:41:35 +00:00
Robert Lubos e28428caae net: dhcpv4_server: Improve declined addresses management
In case conflict is detected (either due to receiving Decline message or
due to ICMP probe getting reply), the conflicting address becomes
blocked for further use.

Although the RFC is not specific about how long should the address be
blocked, it make sense to implement some fallback mechanisms to reuse
blocked addresses in the server, otherwise, after longer period of
operation, it may run out of usable address.

This commit adds a timeout for declined addresses, so that by default
the address is marked back as "free" after 24 hrs (default lease time).
It also implements a mechanism, which allows to re-use the oldest
declined entry in case the server runs out of fresh addresses to assign.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-02-26 11:41:35 +00:00
Pisit Sawangvonganan b6f51edd6c wifi: shell: removed NULL check to net_mgmt callback
Since PR, PR_SHELL, PR_ERROR, PR_INFO, and PR_WARNING already have
an embedded `sh` NULL check, we can remove the change from PR #68809.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-02-26 11:41:03 +00:00
Pisit Sawangvonganan 7b8a9e1818 net: shell: ensure the shell sh is valid before call shell_printf
It is possible that the `sh` was not set before use.
This change adds a NULL check for `sh` in the following macros:
PR, PR_SHELL, PR_ERROR, PR_INFO, and PR_WARNING.
In case `sh` is NULL, the above macros will call `printk` instead.

Fixes #68793

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-02-26 11:41:03 +00:00
Fengming Ye ac8920e342 net: ip: Allow traffic class thread priority customization
Add traffic class priority custom option to customize traffic class
priority base for throughput performace.

Wi-Fi traffic performance depends on cooperation between net threads
and Wi-Fi driver threads. So we want traffic class threads priority
to be more flexible to fit more vendors.

Eg: when traffic class tx thread priority is higher than driver tx
thread, it will consume much more cpu time and send packets until driver
queue full.
When traffic class tx thread priority is lower than driver tx thread,
it will become serial transmition, also affecting throughput.

Signed-off-by: Fengming Ye <frank.ye@nxp.com>
2024-02-26 12:11:19 +01:00
Pisit Sawangvonganan bd94e199e5 net: wifi_utils: fix typo and whitespace adjustment
Corrected 'subsytem' to 'subsystem' and made minor whitespace formatting.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-02-26 12:10:36 +01:00
Pisit Sawangvonganan 0d4961b8d4 net: wifi_utils: reduce valid_5g_chans_20mhz memory footprint
This change reduces the memory footprint by changing the data type of
`valid_5g_chans_20mhz` from `uint16_t` to `uint8_t`.

Additionally, since the maximum channel number for 5GHz Wi-Fi is 177,
it can fit within the `uint8_t` range.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-02-26 12:10:36 +01:00
Fin Maaß 652c2ae1f5 net: dhcpv4: Add vendor class identifier option
Adds the funktion to set the DHCPv4 option 60
(Vendor class identifier) via Kconfig.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2024-02-26 12:05:03 +01:00
Mateusz Karlic bdd09558bb net: shell: ipv4: Add command to set gateway
Add a command `net ipv4 gateway` that allows
setting IPv4 gateway for an interface from net shell.

Signed-off-by: Mateusz Karlic <mkarlic@antmicro.com>
2024-02-26 11:53:56 +01:00
Markus Lassila f033cd5601 net: sockets: tls: Add config for DTLS max fragment length
Add CONFIG_NET_SOCKETS_DTLS_MAX_FRAGMENT_LENGTH for limiting
the Maximum Fragment Length (MFL) for DTLS with Mbed TLS.

This is needed when MBEDTLS_SSL_OUT_CONTENT_LEN and
MBEDTLS_SSL_IN_CONTENT_LEN are set to larger values than the MTU
of the network and IP fragmentation is not supported.

Signed-off-by: Markus Lassila <markus.lassila@nordicsemi.no>
2024-02-26 11:51:25 +01:00
Fin Maaß 7206737450 net: dhcpv4: request options from server
If a option callback is enabled, this option
should also be requested from the DHCPv4 server.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2024-02-26 11:44:45 +01:00
Chaitanya Tata 6c3b0ee5ff wifi: shell: Fix the case for acronym
DFS is an acronym, so, should be capitalized.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2024-02-26 11:41:40 +01:00
Chaitanya Tata 92fe088629 wifi: shell: Fix the header for passive transmission only
This flag indicates that only passive transmissions are allowed in that
channel for that regulatory domain.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2024-02-26 11:41:40 +01:00
Jukka Rissanen c5b0f542f0 net: socket: Start socket service earlier
Make sure that socket service is started earlier than
config library. This is enforced in config libs init.c
but set the default value here too.
The reason for this is that the config library might need
to start dhcpv4 server which needs socket service to work,
so the ordering is important here.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-02-26 11:40:15 +01:00
Jukka Rissanen 3de1f1b5d0 net: if: Check IPv6 pointers properly in hop limit setters/getters
We must make sure that IPv6 configuration pointer is valid
so that the hop limit can be set for a given interface.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-02-26 11:39:50 +01:00
Jukka Rissanen e7b1d6d8aa net: if: Check IPv4 pointers properly in TTL setters/getters
We must make sure that IPv4 configuration pointer is valid
so that the TTL can be set for a given interface.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-02-26 11:39:50 +01:00
Jukka Rissanen dceff4a98f net: if: Init must be called before setting the name
As the interface init function might configure the system
such a way that would affect the naming of the network
interface, we need to call the init before setting the name.
This is mostly needed by Wifi where the Wifi driver needs
to mark its network interface as Wifi interface as by default
the Wifi interface will look like Ethernet one.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-02-26 11:39:25 +01:00
Maochen Wang 11a5904760 net: arp: Fix dead lock caused by arp_mutex
Fix the dead lock between rx_q and tx_q thread.
When tx_q thread prepares to send ARP packet, it might get
the net_if_tx_lock in net_if_tx(), then in net_arp_prepare(),
it will try to get the arp_mutex.
At the same time, if the rx_q thread receives an ARP reply
packet, in arp_update(), it will get the arp_mutex first,
and flush the packets in arp pending_queue and try to get
the net_if_tx_lock. Then the dead lock occurs, two threads
stuck and all the packcets can't be freed.
In arp_update(), taking the net_if_tx_lock first then taking
the arp_mutex can fix this issue.

Signed-off-by: Maochen Wang <maochen.wang@nxp.com>
2024-02-26 11:38:47 +01:00
Jukka Rissanen ea189d5aee net: sockets: Do not start service thread if too little resources
If the CONFIG_NET_SOCKETS_POLL_MAX is smaller than what is needed
for the socket service API to work properly, then we should not
start the service thread as the service API cannot work and might
cause memory overwrite in ctx.events[] array.

Fixes #69233

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-02-25 20:52:18 -05:00
Robert Lubos bc2858ad2d net: lib: coap: Add error check when waking server thread
There's not much to be done in case waking up the server thread with
socketpair send() fails, but at least we can log an error on such event
(to please coverity).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-02-19 19:07:03 +01:00
Jukka Rissanen 7e6813dcf5 net: trickle: Print the abs value using %u
The Imax_abs value should be printed using %u instead of %d
as it can be large and should be printed as positive value.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-02-13 19:36:30 +01:00
Mike Szczys e72ac4b091 net: coap: add TOO_MANY_REQUESTS to return codes
Add COAP_RESPONSE_CODE_TOO_MANY_REQUESTS to coap_header_get_code(). CoAP
4.29 response code for "Too many requests" is defined in coap.h but was
missing from the list of cases, resulting in a 0 being returned instead
of the proper code.

Signed-off-by: Mike Szczys <mike@golioth.io>
2024-02-13 11:14:01 +01:00
Wojciech Slenska 6b1b8157cd wifi: shell: added NULL check to net_mgmt callback
By default variable context.sh is set to NULL. If any net_mgmt
event will be called when the variable has default value, there
will be a system exception.

Signed-off-by: Wojciech Slenska <wsl@trackunit.com>
2024-02-09 16:36:03 -06:00
Robert Lubos 7b6e7d6088 net: ipv6: Improve Neighbor Discovery thread safety
Currently, the only thread-safe part of the IPv6 Neighbor processing
implementation are stale_counter related operation.

Fix this, by extending the mutex protection over all of the module, so
that message handlers, timers and API functions do not interfere with
each other.

As IPv6 Neighbor cache is tightly coupled with the Routing module, use
the same mutex to protect both, neighbor and routing tables, to prevent
deadlocks.

Also, replace the semaphore used with a mutex, as it seems more fit for
this particular job.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-02-09 16:34:34 -06:00
Łukasz Duda 838f33494e net: tcp: Rate-limiting of neighbor reachability hints
This commit implements simple rate-limiting for Neighbor Reachability
Hints in TCP module to prevent the potentially costly process of
frequent neighbor searches in the table, enhancing system performance.

Signed-off-by: Łukasz Duda <lukasz.duda@nordicsemi.no>
2024-02-09 16:26:10 -06:00
Markus Lassila ca7e69523c net: sockets: tls: Timeout DTLS with poll
Changed poll to perform incoming data check with connected
DTLS connections. This allows the CONFIG_NET_SOCKETS_DTLS_TIMEOUT
to timeout the connections to server socket if there is no
incoming data.

Previously, if the remote client closed the DTLS connection without
close notify, the timeout of the ongoing connection only happened
when next connection was taken to the server socket. Depending on
the timeouts, this could prevent the next connection from succeeding.

Signed-off-by: Markus Lassila <markus.lassila@nordicsemi.no>
2024-02-09 10:25:46 -06:00
Kapil Bhatt 2207fedbc8 net: l2: wifi: Fix Print of SSID in WIFI scan result
WIFI scan result shows junk character in SSID because of
the length of ssid is maximum(32 character) which leads
to buffer overflow. It required one character for null
terminator ‘\0’.

Signed-off-by: Kapil Bhatt <kapil.bhatt@nordicsemi.no>
2024-02-08 09:49:10 +00:00
Konrad Derda b324e1e4d8 net: buf: add max allocation size to allocation info
Previously, there was no way to determine maximum number of bytes
that can be allocated using only net_buf structure. This commit
introduces such field.

Moreover, this commit fixes an issue where allocation of less than
maximum number of bytes from a fixed buffer pool would set buffer's
size to this number instead of the whole buffer size.

Signed-off-by: Konrad Derda <konrad.derda@nordicsemi.no>
2024-02-06 12:56:37 +01:00
Manuel Schappacher b5bf5a3cef net: gptp: Use local port identity when forwarding sync messages
As defined in IEEE802.1AS-2020 ch. 10.2.12.2.1, the port identity
of an MDSyncSend structure sent from a port shall be set to the
port identity of the sending port according to and ch. 8.5.2.

This commit replaces the port identity before forwarding a sync.

Fixes #68385

Signed-off-by: Manuel Schappacher <manuel.schappacher@hs-offenburg.de>
2024-02-02 22:35:20 +01:00
Jukka Rissanen 692ebf404c net: sockets: Update msg_controllen in recvmsg properly
If recvmsg() does not update control data, then it must
set msg_controllen length to 0 so that the caller can
understand this.

Fixes #68352

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-02-02 11:51:53 -06:00
Robert Lubos 68bc981c52 net: zperf: Fix session leak
In case zperf session was aborted by the user (by for instance stopping
it from shell), or practically in case of any other
communication-related error, the zperf session could end up in a state
other than NULL or COMPLETED, with no way to recover. This made the
session no longer usable and eventually could lead to zperf being not
able to start a new session anymore.

Fix this by introducing zperf_session_reset() function, which resets the
session state back to defaults. The function is called when the zperf
receiver service is stopped.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-02-02 10:31:53 -06:00
Robert Lubos 4ce0352026 net: zperf: Fix TCP receiver start/stop operation
The issues found for UDP receiver were also identified for TCP receiver,
this commit applies practically the same set of changes as in case of
UDP.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-02-02 10:31:53 -06:00
Robert Lubos 139bc4e87e net: zperf: Fix UDP receiver start/stop operation
This commit fixes restarting of UDP receiver service, along with some
other minor cleanups:

* The core issue was udp_server_running flag not being cleared when
  service was stopped. Fix this by introducing udp_receiver_cleanup()
  which does all of the required cleanups when receiver service is
  stopped. The function is called either when the application stopped
  the service with zperf_udp_download_stop(), or when the service was
  stopped due to error.
* net_socket_service_unregister() was not called on
  zperf_udp_download_stop(), but only from the service callback - that
  would not work in case there's no active communication.
* at the same time, net_socket_service_unregister() would be called from
  the service callback in case of errors. Fix this, by making
  udp_recv_data() only return an error, and let the service callback to
  do the cleanup.
* Remove no longer used udp_server_run semaphore
* Remove udp_server_stop - with socket services it seems no longer
  needed.
* zperf_udp_receiver_init() now returns an error, so that we don't
  mark the service as running in case of socket/services error.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-02-02 10:31:53 -06:00
John Johnson 125a2bccaa net: net_pkt: add peer sockaddr member in net_pkt struct
Add sockaddr member in struct net_pkt to store peer address if offloaded
network inteface is used. This enables recvfrom() to fill in src_addr if
socket type is UDP and offloaded interface driver supports it.

Signed-off-by: John Johnson <john.filip.johnson@gmail.com>
2024-02-02 09:42:18 -06:00
Robert Lubos 3c76ff9a8c net: dhcpv4_server: Implement ICMP probing of offered addresses
DHCPv4 server will send an ICMP probe (echo request) for the requested
address before replying with DHCP Offer, unless probing is disabled in
Kconfig.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-02-02 12:42:44 +01:00
Pieter De Gendt 0bc1a2b314 net: lib: coap: Reduce CoAP server stack usage
Declare the CoAP server receiving buffer as static to lower the
stack usage.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2024-02-02 10:51:32 +01:00
Pisit Sawangvonganan 055ac61542 wifi: shell: replace print(...) with PR(...)
Additionally, replace the local print(sh, level, fmt, ...) macros
with PR, PR_ERROR, and PR_WARNING macros.

Then remove the print(sh, level, fmt, ...) macros.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-01-31 15:15:19 -06:00
Pisit Sawangvonganan 81342132fb wifi: shell: refactor to use PR(...) from "net_shell_private.h"
Replaced direct shell_fprintf calls with PR, PR_ERROR, PR_INFO
and PR_WARNING macros.

This change simplifies the code by using predefined macros.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-01-31 15:15:19 -06:00
Pisit Sawangvonganan 10939c7a02 wifi: shell: move "scan_result" variable into context struct
Moved 'scan_result' from a standalone variable into the 'context' struct
to enhance code optimization.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-01-31 15:15:19 -06:00
Pisit Sawangvonganan a8a39231e7 wifi: shell: introduce local 'sh' variable
This commit introduces a local variable 'sh' to store 'context.sh' for
use with the 'shell_fprintf' function.

By doing so, we avoid the repeated dereferencing of 'context.sh',
thereby reducing the code footprint.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-01-31 15:15:19 -06:00
Manuel Schappacher 6fc6b30fb3 net: gptp: Fix double converted byte order of BMCA info steps_removed
Fixes #68320

Signed-off-by: Manuel Schappacher <manuel.schappacher@hs-offenburg.de>
2024-01-31 15:53:06 +00:00
Łukasz Duda 5273af6ba8 net: ipv6: nbr: Add IPv6 reachability confirmation API
This commit introduces a new IPv6 API for positive reachability
confirmation, as specified in RFC 4861, Section 7.3.1. This feature aims
to enhance the effectiveness of the Neighbor Discovery mechanism, by
enabling upper-layer protocols to signal that the connection makes a
"forward progress".

The implementation within TCP serves as a reference. Compliance with
RFC 4861, especially Appendix E.1, was ensured by focusing on reliable
handshake and acknowledgment of new data transmissions.

Though initially integrated with TCP, the API is designed for broader
applicability. For example, it might be used by some UDP-based protocols
that can indicate two-way communication progress.

Signed-off-by: Łukasz Duda <lukasz.duda@nordicsemi.no>
2024-01-31 14:50:53 +01:00
Jukka Rissanen b03c3c0c48 net: socket: Start service thread from initialization function
We cannot always start the service monitor thread statically
because the static threads are started after the application
level. This means that when config library wants to start
dhcpv4 server which uses socket services, there would be a
deadlock. Simplest solution is to start the service thread
directly from socket service init function.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-01-31 12:06:49 +00:00
Robert Lubos a147ac9a47 net: dhcpv4_server: Improve address pool range validation
Not only check if the address pool belongs to the same subnet as the
server, but also that it does not overlap with the server address -
otherwise the server might end up assigning its own address.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-01-31 12:06:23 +00:00
Jordan Yates 9ff1fcf7e7 net: conn_mgr: generic wifi_mgmt connectivity backend
As connectivity backends need to be bound in the same file that the
`net_if` is created in, define a common backend type for WiFi modems.
All WiFi modems should be controllable through the `wifi_mgmt` API, so
there should be no need for dedicated context.

When enabled, the particular implementation to be used is chosen through
`CONNECTIVITY_WIFI_MGMT_IMPL`. For now, the only choice is an
application defined backend.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2024-01-30 18:51:46 -05:00
Chaitanya Tata bff1b7487e wifi: shell: Add band support for STA
For a Wi-Fi station the connect API supports both band and channel
configuration, but for a shell command either channel or band makes
sense, so, overload the channel field to support band.

Rejig the band and channel validation to support all modes.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2024-01-30 18:00:26 +01:00
Øyvind Rønningstad 3ad47d214a lwm2m: Regenerate zcbor files
with zcbor 0.8.1

Signed-off-by: Øyvind Rønningstad <oyvind.ronningstad@nordicsemi.no>
2024-01-30 13:38:51 +01:00
Jordan Yates 1e1d2725a7 net: dns: option to disable auto context init
Adds an option to disable the automatic initialization of the default
dns_context. This lets applications use the default context, while also
managing the `init` and `close` functions.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2024-01-29 20:20:19 -06:00
Jordan Yates e5f4fa0f4a net: dns: function to default initialize context
Adds a function that can be used to initialize a dns context to the
default Kconfig values.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2024-01-29 20:20:19 -06:00
Robert Lubos b8556d0d79 net: icmp: Don't report error on ICMP messages w/o handler
ICMPv4/6 modules print error when ICMP message handling fails, which
includes no message handler registered. This is a bit problematic, as
there are many ICMP messages that Zephyr does not process, and every
time such a message is received, an error log is printed (which wasn't
the case before ICMP rework).

Restore the old behavior (no log on unrecognized ICMP message) by
explicitly filtering out ENOENT error code from printing error. That
way, log will only be printed if an error occured within the actual
message handler.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-01-29 14:57:35 +00:00
Robert Lubos cefc391db3 net: dhcpv6: Move DHCPv6 files to lib directory
For consistency with DHCPv4.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-01-29 13:47:05 +01:00
Robert Lubos 19722aa8e8 net: dhcpv4: Move DHCPv4 files to lib directory
As discussed during DHCPv4 server integration, group DHCPv4 client files
with DHCPv4 server in a single lib directory.

Renamed internal "dhcpv4.h" header to "dhcpv4_internal.h" so that it's
not confused with the public "dhcpv4.h" header.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-01-29 13:47:05 +01:00
Jukka Rissanen 7da14d3129 net: shell: Clarify the name of the virtual interface
The net-shell printed virtual interface name so that it got
the impression it was the network interface name which is not
correct. Now the name is printed as "Virtual name" which is
unambiguous.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-01-29 10:58:33 +00:00
Jukka Rissanen a45d66c478 net: if: Do not join multicast address if IPv6 is not enabled
If IPv6 is not enabled for the interface, then do not try to
join the IPv6 solicited multicast address.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-01-29 10:58:24 +00:00
Fengming Ye f61a0cb1fa net: zperf: fix the calculation ratio between mbps, kbps and bps
The ratio between mbps and kbps, kbps and bps should be 1000, instead of
1024, as common sense.
The wrong ratio will decrease the Zperf throughput result.

Signed-off-by: Fengming Ye <frank.ye@nxp.com>
2024-01-29 10:05:35 +01:00
Jukka Rissanen a1d0764922 net: wifi: Make sure scan band string is null terminated
Make sure that scan band string is properly terminated when
parsing user supplied string.

Fixes: #67944
Coverity-CID: 342930

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-01-26 19:40:16 +01:00
Seppo Takalo 992936300b net: lwm2m: Use CID_SUPPORTED instead of CID_ENABLED
When ENABLED flag is used, we generate 32 byte DTLS
Connection Identifier and include that in our
DTLS Client HELO. This has no benefit as client only
has one connection toward the server, it does not need
any identification.

When SUPPORTED flag is used, we just include
zero length Connection Identifier in the handshake,
which tell server that we support Connection Identifier
and server can generate one for it.
We then use the CID in the packets that we send towards
server, but response packets don't contain any CID.
This gives all the benefit of CID as server is able to
identify us even when NAT mapping have changed.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2024-01-26 12:00:51 -06:00
Sandip Dalvi 4c7eb600c6 net: wifi: add wifi driver version API
Add command to query to WiFi driver/firmware revision. The API is expected
to return the firmware revision and driver version as a string, and can be
used by the user to determine what revision of the WiFi driver is in use.

Signed-off-by: Sandip Dalvi <sandip.dalvi@nxp.com>
2024-01-26 14:29:39 +01:00
Alberto Escolar Piedras 4ff79cb74a subsys/net/lib/lwm2m: Define required source standard macros
Instead of relaying on those macros having been defined
somewhere else let's define them for this file.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2024-01-26 07:48:55 -05:00
Chaitanya Tata c07d648304 wifi: shell: Remove duplicate argument count checks
Now that we are using the shell macro to enforce argument count check,
both mandatory and optional arguments, these additions checks are
unnecessary.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2024-01-25 11:50:59 -05:00
Chaitanya Tata c53a1df138 wifi: shell: ap: Add a command to disconnect a station
The shell commands can be used to disconnect a connected station in AP
mode.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2024-01-25 11:50:59 -05:00
Chaitanya Tata de667a7fae wifi: ap: Add support to disconnect a STA
In AP mode, this can be used to disconnect a connected station.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2024-01-25 11:50:59 -05:00
Øyvind Rønningstad 1bbb0a9ddb lwm2m: Adapt to zcbor 0.8.0
Regenerate from CDDL, update patch, fix references in code.

Signed-off-by: Øyvind Rønningstad <oyvind.ronningstad@nordicsemi.no>
2024-01-25 15:09:16 +00:00
Seppo Takalo ec3ec8cd2a net: lwm2m: Add LWM2M_ON_INIT() macro
Add macro that allows registration of initialization functions that
are called when LwM2M engine starts.

On LwM2M engine starts up, it first executes all initialization
functions in following priority order:
1. LWM2M_PRIO_ENGINE
2. LWM2M_PRIO_CORE, this is where all LwM2M core objects are initialized
3. LWM2M_PRIO_OBJ, this is where all other objects are initialized
4. LwM2M_PRIO_APP, application initialization.

Now on the initialization phase, we could rely that certain objects have
already been registered.
For example custom objects can register callbacks to core objects.
On application phase, we can initialize sensor objects and register
their callbacks because objects have already been initialized.

This LWM2M_ON_INIT() should replace all use of SYS_INIT()
with the default CONFIG_KERNEL_INIT_PRIORITY_DEFAULT.

Priority order is actually just alphabetical order of names, so
the order is set on a linkin phase, and we don't need any
runtime checking for it.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2024-01-24 10:44:28 +01:00
Vivekananda Uppunda 7eb0aa0468 net: wifi_shell: Remove TX-Injection and Promiscuous mode from Wi-Fi mode
Remove TX-Injection and Promiscuous mode setting from Wi-Fi mode shell
command. These commands are being moved to ethernet l2 layer

Signed-off-by: Vivekananda Uppunda <vivekananda.uppunda@nordicsemi.no>
2024-01-24 00:08:38 -05:00
Vivekananda Uppunda db4bf8d409 net: l2: ethernet: bring in TX-Injection mode to l2 ethernet
This set of changes brings in raw packet tx injection mode
feature to ethernet and removes it from being a Wi-Fi only feature.

It was earlier envisaged as Wi-Fi net management feature only.

Signed-off-by: Vivekananda Uppunda <vivekananda.uppunda@nordicsemi.no>
2024-01-24 00:08:38 -05:00
Seppo Takalo bf872870ea net: lwm2m: Fix segfault on failed bootstrap
If bootstrap fails, RD client will call lwm2m_engine_stop()
which will close the context.
The socket loop, however still contains a call to
hint_socket_state(context, NULL) which has a null pointer now.

Fix the segfault by allowing nullpointer on hint_socket_state().

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2024-01-22 17:25:02 +00:00
Robert Lubos 2c70c5d74a net: shell: Implement DHCPv4 server shell commands
Implement DHCPv4 shell module, which allows to start/stop DHCPv4 server
operation, and print server status (address leases).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-01-19 10:15:23 +00:00
Robert Lubos 3bc50871bc net: socket_services: Increase default stack size for DHCPv4 server
Increase socket services thread default stack size when DHCPv4 server is
enabled, as it uses synchronous processing.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-01-19 10:15:23 +00:00
Robert Lubos 1e08bbd543 net: dhcpv4: Implement DHCPv4 server
Add basic socket-based implementation of DHCPv4 sever.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-01-19 10:15:23 +00:00
Robert Lubos db80ed3e8d net: if: Add function to obtain IPv4 netmask
Add a helper function to obtain IPv4 netmask configured on an interface.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-01-19 10:15:23 +00:00
Robert Lubos 1d14f13d75 net: arp: Make arp_update() function externally visible
So that it's possible to register ARP entries manually. Needed for DHCP
server implementation, which in unicast mode needs to reply to an IP
address that is not registered on the peer interface yet (hence no ARP
reply will be sent). It's needed to add an ARP entry manually in that
case, as hardware address is already known at that point.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-01-19 10:15:23 +00:00
Juha Ylinen 9eee8d2be5 net: lwm2m: Allow send operations when sleeping
Add new kconfig CONFIG_LWM2M_QUEUE_MODE_NO_MSG_BUFFERING.

When enabled and device is sleeping, Reqistration Update
message is skipped and messages from send operation and
notifications are sent right away.

Reqistration update message is also skipped when
lwm2m_engine resumes from pause state.

Signed-off-by: Juha Ylinen <juha.ylinen@nordicsemi.no>
2024-01-19 09:48:46 +01:00
Bjarki Arge Andreasen 52be26a8e3 net: l2: ppp: Patch carrier lost and L2 enable/disable
L2 PPP is not able to handle the carrier being lost gracefully,
nor is it able to gracefully close the PPP connection when
net_if_down() is called.

This patch refactors the L2 PPP module to use the carrier state
to either properly close or simply terminate the PPP connection.

Additionally, it ensures that the PPP session is closed properly
before calling ppp->stop().

Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
2024-01-19 09:47:33 +01:00
Kapil Bhatt c22ce801e7 net: wifi_shell: Add help for maximum channels in scan
Add a line for scan's -c parameter which specify
to take care of maximum channels.

Signed-off-by: Kapil Bhatt <kapil.bhatt@nordicsemi.no>
2024-01-19 09:44:22 +01:00
Markus Lassila 681330aaf0 net: sockets: tls: Fix crashes in get DTLS CID socket options
Get TLS_DTLS_CID_STATUS and TLS_DTLS_PEER_CID_VALUE utilize
mbedtls_ssl_get_peer_cid, which expects that mbedtls_ssl_setup
has been done.

Signed-off-by: Markus Lassila <markus.lassila@nordicsemi.no>
2024-01-19 09:41:34 +01:00
Jukka Rissanen 5a933299bb net: socket: Change the printf modifier to print size_t correctly
The argument is size_t, so change the printf modifier to %zd
to avoid warning prints.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-01-18 20:13:31 +01:00
Jukka Rissanen 84ff0e8cdf net: socket: Allow user to tweak service dispatcher thread priority
User is able to tweak the socket service dispatcher thread
priority in order to get better performance from the system
if needed. By default the dispatcher thread runs in lowest
application thread priority (K_LOWEST_APPLICATION_THREAD_PRIO).

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-01-18 20:13:31 +01:00
Jukka Rissanen 38cacc7f63 net: shell: Make the thread name longer for sockets command
The thread name output field was a bit too short in "net sockets"
command, so make it 25 char long.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-01-18 20:13:31 +01:00
Jukka Rissanen d3bfef8399 net: shell: Do not crash if no sockets are found
The "net sockets" command was not checking if there is any
sockets in the system before trying to access them.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-01-18 20:13:31 +01:00
Jukka Rissanen 1e8cbd5d43 net: zperf: Convert UDP receiver to use socket services
Use socket services API for UDP receiver.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-01-18 20:13:31 +01:00
Jukka Rissanen 07823f7710 net: zperf: Convert TCP receiver to use socket services
Use socket services API for TCP receiver.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-01-18 20:13:31 +01:00
Chaitanya Tata df6d4e7717 wifi: shell: Log errors for validation
Handy in giving feedback to the user rather than silent failure.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2024-01-18 10:55:45 +01:00
Chaitanya Tata c9363a9c71 wifi: shell: Fix the channel extraction
The channel extraction from string directly uses the end variable with
limited data type, this causes issue if an invalid channel that exceeds
the data is given as an input e.g., 300, which would end up as a valid
channel 44.

Use an intermediate variable with type that can hold all possible
combinations (valid and invalid) and only after validation assign that
to the end type.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2024-01-18 10:55:45 +01:00
Chaitanya Tata 2f88df9cef wifi: shell: Add channel validation
Validate the channel for both STA and AP modes.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2024-01-18 10:55:45 +01:00
Chaitanya Tata 2f99379dd5 wifi: utils: Move channel helpers to public API
These can be used for channel validation outside the utils.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2024-01-18 10:55:45 +01:00
Chaitanya Tata c6f2152348 wifi: shell: Add a sanity check for MFP
For none and WPA-PSK MFP isn't applicable, it was only introduced in
WPA2-PSK (RSN) and later.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2024-01-18 10:55:45 +01:00
Chaitanya Tata 4a1847eb22 wifi: shell: Make channel mandatory for AP
For starting an AP mode, channel is mandatory, so, fix the arguments and
the help text.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2024-01-18 10:55:45 +01:00
Ajay Parida 4d854a193e net: mgmt: Print correct TWT teardown status message
Print success message for TWT teardown successful case.

Signed-off-by: Ajay Parida <ajay.parida@nordicsemi.no>
2024-01-17 16:11:37 +00:00
Jukka Rissanen 3a37c5d987 net: shell: Require float printf support from libc
Various network shell commands like ping need floating
point support from libc so select the CONFIG_REQUIRES_FLOAT_PRINTF
option for it.

Fixes #67601

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-01-17 16:09:17 +00:00
Markus Swarowsky 11175c3ad3 tf-m: Change NS include path for TF-M 2.0.0
The place where TF-M places its non-secure api header files has changed
Therefore changing it for for all applications that use it.

Signed-off-by: Markus Swarowsky <markus.swarowsky@nordicsemi.no>
2024-01-17 16:52:52 +01:00
Gerhard Jörges 2a0e5e93f3 logging: net: update hostname
This commit adds a function that updates the hostname displayed by the
net backend. It is called by the network stack when the hostname is
updated.

Signed-off-by: Gerhard Jörges <joerges@metratec.com>
2024-01-17 14:42:58 +01:00
Gerhard Jörges 72a51c7ec4 net: add set hostname function
This commit adds a function to set the hostname on runtime.

Signed-off-by: Gerhard Jörges <joerges@metratec.com>
2024-01-17 14:42:58 +01:00
Jukka Rissanen 16a54f251a net: sockets: Refactor accept() to support objcore better
If user has not supplied address pointer when calling accept(),
then we would not be able to figure out the used socket domain
properly. But as there is now SO_DOMAIN option supported, use
that to get the correct socket domain.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-01-17 09:55:40 +01:00
Jukka Rissanen 298ab2c95d net: socket: Add support for SO_DOMAIN option
The getsockopt() will return the address domain of the given
socket like AF_INET or AF_INET6.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-01-17 09:55:40 +01:00
Ibe Van de Veire ba5bcb14ba net: ip: igmp: removed compiler warning when igmpv3 is enabled
Made the definition of in_addr all_routers conditional to remove
compiler warning:
warning: 'all_routers' defined but not used [-Wunused-const-variable=]
The warning occurs when igmpv3 is enabled.

Signed-off-by: Ibe Van de Veire <ibe.vandeveire@basalte.be>
2024-01-17 09:55:28 +01:00
Chaitanya Tata dc9d5d9321 wifi: shell: Fix typo in comparison
The length should be 3 for WMM not 4.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2024-01-16 14:25:37 -05:00
Konrad Derda a5b868d94a net: buf: add function to match buffer's content with a given data
This commit adds a new function the net_buf's API that allow an user
to match the net_buf's content with a data without copying it to a
temporary buffer.

Signed-off-by: Konrad Derda <konrad.derda@nordicsemi.no>
2024-01-16 09:40:04 -06:00
Jukka Rissanen 6033161216 net: shell: Avoid gcc warning print with string catenation
gcc prints this warning message

'strncat' specified bound 1 equals source length [-Wstringop-overflow=]
   58 |                 strncat(fd, "C", 1);

There was no error in the code but avoid the warning by not using
strncat().

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-01-16 10:00:45 +01:00
Jukka Rissanen f5e95852ce net: shell: Add sockets services prints
The socket services users to "net sockets" command.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-01-16 10:00:45 +01:00
Jukka Rissanen eff5d02872 net: sockets: Create a socket service API
The socket service provides a similar functionality as what
initd provides in Linux. It listens user registered sockets
for any activity and then launches a k_work for it. This way
each application does not need to create a thread to listen
a blocking socket.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-01-16 10:00:45 +01:00
Mirko Covizzi 998e839d67 net: sockets: prevent null pointer dereference
According to the POSIX specification, null pointer
is a valid value for the `address` argument
of the `accept` function.
This commit adds a check to prevent a null pointer
dereference inside `z_impl_zsock_accept`.

Signed-off-by: Mirko Covizzi <mirko.covizzi@nordicsemi.no>
2024-01-15 15:11:57 +01:00
Manuel Schappacher bff6054cb8 net: gptp: Always use GM PRIO root system id for announce messages
A problem occurred while running PTP on a multi-port target
(RENESAS RZT2M) with two ports enabled. Announce messages on the
switched devices master port always contained local clock information
instead information from received on the slave port from the better
GM clock. Depending on the BMCA config this turned into having more
than one GM in the system.

Sending always the locally stored GM information helped to overcome
this issue.

Signed-off-by: Manuel Schappacher <manuel.schappacher@hs-offenburg.de>
2024-01-15 09:57:34 +01:00
Ajay Parida fc959fce47 net: shell: Early wake up for TWT power save
Provision of configurable parameter for generating unblock event
ahead of TWT slot. Host application depending upon latencies can
configure this to wakeup rpu ahead of the TWT slot.

Signed-off-by: Ajay Parida <ajay.parida@nordicsemi.no>
2024-01-12 15:56:56 -05:00
Daniel DeGrasse 76f547e763 net: l2: wifi: wifi_utils: Resolve build warning with strncpy function
ARM GCC version 12.2.0 (Zephyr SDK 0.16.4) generates the following build
warning from the strncpy call in "wifi_utils_parse_scan_bands":

warning: '__builtin_strncpy' output truncated before terminating nul
copying as many bytes from a string as its length

To resolve this warning, pass the maximum length of the temporary
parse_str buffer to strncpy. This also has the benefit of correctly null
terminating parse_str, since we already verify the
scan_bands_str is properly null terminated with the strlen() check in
this function. We can therefore remove the line adding a null terminator
to parse_str as well.

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
2024-01-12 12:55:35 +01:00
Ajay Parida 56de0a347e net: mgmt: Provide Regulatory channel info
Updated to provide regulatory channel information along with country
code.

Signed-off-by: Ajay Parida <ajay.parida@nordicsemi.no>
2024-01-12 09:59:19 +01:00
Ajay Parida 3053484dcb net: mgmt: Update app of TWT teardown status
Update user/app status of TWT teardown sessions.

Signed-off-by: Ajay Parida <ajay.parida@nordicsemi.no>
2024-01-11 15:42:50 -06:00
Chaitanya Tata 2ce295b71e wifi: shell: Fix missing case sensitivity
This was missed in earlier that tried to fix all string comparisons to
use case insensitive comparison.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2024-01-11 15:38:42 -06:00
Kapil Bhatt d8c362253d net: wifi_shell: Add example of scan option
Add an example of the scan's -c parameter
to help with understanding.

Signed-off-by: Kapil Bhatt <kapil.bhatt@nordicsemi.no>
2024-01-11 16:14:46 +00:00
Jukka Rissanen b8708ee781 net: tcp: Fix the CONFIG_NET_TCP_RETRY_COUNT help text
The help text was incorrect, we return -ETIMEDOUT instead
of -ECONNRESET when retransmission timeout occurs.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-01-11 10:26:47 -05:00
Chaitanya Tata 918e08fda8 wifi: shell: Add a shell command to list stations
In AP mode maintain the database of connected stations based on the
Wi-Fi management events and dump the list.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2024-01-11 10:03:02 +01:00
Chaitanya Tata 725c13bafb wifi: ap: Add client side events
These are helpful to track clients being added and deleted.
Applications can actions based on these events.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2024-01-11 10:03:02 +01:00
Chaitanya Tata 2703955aee wifi: ap: Add status events
These events communicate the status of AP mode operations (enable or
disable) with few pre-defined enumerations.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2024-01-11 10:03:02 +01:00
Chaitanya Tata 09e1ed039a wifi: Fix duplication
Use a common set of events and then add specific ones as per the
configuration.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2024-01-11 10:03:02 +01:00
Kapil Bhatt 773ebe9c41 net: wifi_shell: Update scan argument shell
Update the example of scan -c argument.
Default value for max channels is set to 3,
So, update the example according to that.
Add closing bracket in -s.

Signed-off-by: Kapil Bhatt <kapil.bhatt@nordicsemi.no>
2024-01-10 20:56:32 -05:00
Kapil Bhatt 3e8dbaf75f net: wifi_utils: Fix max channels allow for scan
Fix the maximum channels allow for scan command
input.

Signed-off-by: Kapil Bhatt <kapil.bhatt@nordicsemi.no>
2024-01-10 20:56:32 -05:00
Simon Walz 38aa4d5169 net: lwm2m: add gateway callback to handle prefixed messages
Adding a callback for handling lwm2m messages with prefixed paths defined
by the gateway object. If CONFIG_LWM2M_GATEWAY_OBJ_SUPPORT is set,
each path is checked for the prefix stored in the object instances of the
gateway object 25. If prefixes match the msg is passed to the gw_msg_cb.

Signed-off-by: Simon Walz <simon.walz@autosen.com>
2024-01-10 18:22:21 +00:00
Jonathan Hamberg 9c1a45cc00 posix: Fix name collision with __bswap
__bswap_ in zephyr/sys/byteorder.h conflicts with __bswap_ in host's
byteswap.h. byteswap.h from host compiler used in posix_native_64 boards
causes a compilation issue.

This commit renames __bswap_ to BSWAP_ to prevent collision.

Before this commit a compilation error can be created by adding #include
<byteswap.h> to samples/net/sockets/echo/src/socket_echo.c

This does not change external API to byteorder.h, but does change
internal implementation which some other source files depend on.

Replaced manual byteswap operations in devmem_service.c with APIs from
byteorder.h which automatically converts to CPU endianess when necessary.

Fixes #44324

Signed-off-by: Jonathan Hamberg <jonathanhamberg@gmail.com>
2024-01-10 18:13:44 +00:00
Jukka Rissanen 35e1df6bb4 tests: net: tcp: Add support for close callback
Add a function callback that is called when the TCP connection
is closed. This is only available if doing network tests.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-01-09 10:03:08 +01:00
Jukka Rissanen b214207d91 net: tcp: Reschedule FIN timer when entering FIN state
The FIN timer was not set when we entered the FIN_WAIT_1 state.
This could cause issues if we did not receive proper packets
from peer. With this fix, the connection is always terminated
even if peer does not respond.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-01-09 10:03:08 +01:00
Jukka Rissanen 40215e07a3 net: tcp: Install a last ack timer in passive close
If we are in a passive close state, then it is possible that
the ack we are waiting is lost or we do not accept the one peer
sent to us because of some earlier out of memory issue.
So install a timer (using by default the FIN timer value) to
close the connection if the last ack is not received on time.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-01-09 10:03:08 +01:00
Chaitanya Tata 9e6542b0cc wifi: shell: Use case insensitive comparison
The help text uses the capital case as its an acronym, but passing
capital case fails. Also extend that to others as well.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2024-01-05 14:43:21 -05:00
Chaitanya Tata 352ee50af7 wifi: shell: Fix the inconsistency in commands separation
For better readability, below rules will help:

 * Each command should be separated by a newline
 * Each command should end with a full stop (intermediate statements
   shouldn't have full stops)

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2024-01-05 14:43:21 -05:00
Chaitanya Tata 7e7dc76296 wifi: shell: Remove the unnecessary text
The parameters heading is implied and doesn't have the newline, so, just
remove it.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2024-01-05 14:43:21 -05:00
Chaitanya Tata 352f63c909 wifi: shell: Fix the help for reg domain
Separate the two optional parameters and add help.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2024-01-05 14:43:21 -05:00
Chaitanya Tata 467a89e6a4 wifi: shell: Remove the unnecessary text in scan
We are using standard notation to differentiate optional and mandatory,
so, no need for a heading.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2024-01-05 14:43:21 -05:00
Chaitanya Tata 30c492d5de wifi: shell: Fix help for PS command
Clearly mark the args as optional.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2024-01-05 14:43:21 -05:00
Chaitanya Tata 9b55802d98 wifi: shell: Fix optional arg count for connect
Fix an extra optional arg.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2024-01-05 14:43:21 -05:00
Chaitanya Tata 0044640be6 wifi: shell: Fix the arg count for reg domain
Missed accounting for "-f" option.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2024-01-05 14:43:21 -05:00
Juha Ylinen 7c53fa86ff net: lwm2m: Fix deadlock when calling lwm2m_engine_pause()
lwm2m_engine_pause() caused deadlock if it was called within
engine thread.

Remove while loop from lwm2m_engine_resume().

Signed-off-by: Juha Ylinen <juha.ylinen@nordicsemi.no>
2024-01-05 09:06:27 +01:00
Juha Ylinen 85dfe3df14 net: lwm2m: Delay triggering registration update
Add short delay before triggering registration update. This allows
postponing the update from application side if needed.

Signed-off-by: Juha Ylinen <juha.ylinen@nordicsemi.no>
2024-01-05 09:06:27 +01:00
Jukka Rissanen 8d3d48e057 net: ipv6: Check that received src address is not mine
Drop received packet if the source address is the same as
the device address.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-01-03 19:00:33 +00:00
Robert Lubos 898aa9ed9a net: sockets: tls: Align DTLS connect() behavior with regular TLS
DTLS socket is not really connection-less as UDP, as it required the
DTLS handshake to take place before the socket is usable. Therefore,
align the DTLS connect() behavior with regular TLS.
The change is backward compatible. connect() call is still optional for
DTLS socket (the handshake can still take place from send()/recv()) and
a socket option was provided to disable DTLS handshake on connect().

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-01-03 19:00:15 +00:00
Robert Lubos c0d5d2fbd5 net: sockets: tls: Allow handshake during poll()
When using DTLS socket, the application may choose to monitor socket
with poll() before handshake has been complete. This could lead to
potential crash (as the TLS context may have been left uninitialized)
and unexpected POLLIN reports (while handshake was still not complete).
This commit fixes the above - POLLIN will only be reported once
handshake is complete and data is available

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-01-03 19:00:15 +00:00
Robert Lubos 0a1bee48bf net: sockets: tls: Improve POLLERR error reporting
In case a socket error was caused by TLS layer, it was not reported with
POLLERR. This commit fixes this.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-01-03 19:00:15 +00:00
Robert Lubos 5b3b462eed net: sockets: tls: Add flag indicating that session is closed
In case TLS session is closed at the TLS level (and thus recv() reports
0 to the application) a certain race occurs between consecutive recv()
call, and TCP session teardown. As mbedtls_ssl_read() only reports
session close upon receiving CLOSE alert, consecutive non-blocking
recv() calls would report EAGAIN instead of connection closed, if called
before underlying TCP connection was closed.

Fix this, by storing the information that TLS session has ended at TLS
socket level. The new flag will be checked before attempting further
mbed TLS actions, so that connection status is reported correctly.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-01-03 19:00:15 +00:00
Robert Lubos 1dc9028316 net: sockets: tls: Add function to obtain underlying ssl context
For test purposes only. Should not be used in regular applications.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-01-03 19:00:15 +00:00
Jukka Rissanen ec42d825ec net: context: Fix the v4 mapped address handling in sendto
If we receive a IPv4 packet to v4 mapped address, the relevant
net_context is bound to IPv6. This causes issues if we try
to get the family from the context struct in sendto.
Fix this by checking if the destination address is IPv4 but
the socket is bound to IPv6 and v4 mapping is enabled.
If all these criterias are set, then set the family of the
packet separately and do not get it from net_context.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-01-03 12:55:14 +01:00
Jukka Rissanen 8f97c1c2ee net: lib: sockets: Initialize iovec to 0 at start of func
Make sure iovec is initialized to a value so that there
is no possibility that it is accessed uninitialized.

Fixes: #66838
Coverity-CID: 334911

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-01-03 10:19:50 +01:00
Jukka Rissanen 4e5ef76b15 net: lib: mdns_responder: Fix interface count check
The original idea was to check that we have enough network
interfaces in the system. The check needs to verify max IPv4
and IPv6 supported interfaces instead of always checking
IPv6 one.

Fixes: #66843
Coverity-CID: 334899

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-01-03 10:19:38 +01:00
Seppo Takalo dc6e7aa4b1 net: lwm2m: Add transmission state indicator to RX as well
Refactored the socket state indication into its own function
that checks the state of TX queues as well as number of
pending CoAP responses.
Check the state after receiving a packet, as it might
have been a last Ack packet we have been waiting.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-12-27 16:07:59 +00:00
Seppo Takalo 071cad2e76 net: lwm2m: Deprecate lwm2m_get/set_u64
Deprecate lwm2m_set_u64() and lwm2m_get_u64 as only
LWM2M_RES_TYPE_S64 exist. Unsigned variant is not defined.

Technically these might have worked OK, but it is undefined
what happens to large unsigned values when those are
converted to various payload formats (like CBOR) that might
decode numbers differently depending of their signedness.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-12-22 09:54:07 +01:00
Jukka Rissanen 1a0b6745bd net: shell: Print more Ethernet statistics
Various Ethernet error statistics values were not printed
by the shell.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-12-22 09:53:26 +01:00
Jordan Yates 1ef0ec55c9 net: ip: dhcpv4: remove address on interface down
Any received address is no longer valid once the interface goes down.
Leaving the address assigned results in the L4 interface transitioning
through the following on reconnection:
 UP: Interface is connected
 DOWN: Old address is removed by DHCP
 UP: New address is re-added by DHCP

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2023-12-21 09:18:32 +01:00
Jordan Yates 434c93ddfb net: conn_mgr: output events as hex
Networking events are masks of bits, which are almost impossible to read
as decimal, and trivial to read as hex. Also unifies the format string
across multiple outputs for some flash savings.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2023-12-21 09:18:32 +01:00
Jukka Rissanen 19392a6d2b net: ipv4: Drop packet if source address is my address
If we receive a packet where the source address is our own
address, then we should drop it.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-12-21 09:18:24 +01:00
Jukka Rissanen 6d41e68352 net: ipv4: Check localhost for incoming packet
If we receive a packet from non localhost interface, then
drop it if either source or destination address is a localhost
address.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-12-21 09:18:24 +01:00
Seppo Takalo 6161fbdf21 net: lwm2m: Transmission state indications
Allow engine to give hints about ongoing CoAP transmissions.
This information can be used to control various power saving
modes for network interfaces. For example cellular networks might
support release assist indicator.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-12-20 11:57:48 +00:00
Seppo Takalo 0d650ffd26 net: lwm2m: Update TX timestamp on zsock_send()
In slow networks, like Nb-IOT, when using queue mode,
there might be significant delay between the time we
put the packet into a transmission queue and the time
we actually start transmitting.
This might cause QUEUE_RX_OFF state to be triggered earlier
than expected. Remedy the issue by updating the timestamp on the
moment where packet is accepted by zsock_send().

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-12-20 11:57:48 +00:00
Seppo Takalo 01568b573a net: coap: Add API to count number of pending requests
Add coap_pendings_count() that return number of waiting
requests on the pendings array.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-12-20 11:57:48 +00:00
Robert Lubos 9aba4e8f3d net: sockets: tls: Read the actual error on interrupted wait
In case a waiting TLS socket reports an error in the underlying poll
call, try to read the actual error from the socket, instead of blindly
returning -EIO in all cases.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-12-20 11:10:57 +01:00
Johan Hedberg 3fbf12487c kernel: Introduce a way to specify minimum system heap size
There are several subsystems and boards which require a relatively large
system heap (used by k_malloc()) to function properly. This became even
more notable with the recent introduction of the ACPICA library, which
causes ACPI-using boards to require a system heap of up to several
megabytes in size.

Until now, subsystems and boards have tried to solve this by having
Kconfig overlays which modify the default value of HEAP_MEM_POOL_SIZE.
This works ok, except when applications start explicitly setting values
in their prj.conf files:

$ git grep CONFIG_HEAP_MEM_POOL_SIZE= tests samples|wc -l
     157

The vast majority of values set by current sample or test applications
is much too small for subsystems like ACPI, which results in the
application not being able to run on such boards.

To solve this situation, we introduce support for subsystems to specify
their own custom system heap size requirement. Subsystems do
this by defining Kconfig options with the prefix HEAP_MEM_POOL_ADD_SIZE_.
The final value of the system heap is the sum of the custom
minimum requirements, or the value existing HEAP_MEM_POOL_SIZE option,
whichever is greater.

We also introduce a new HEAP_MEM_POOL_IGNORE_MIN Kconfig option which
applications can use to force a lower value than what subsystems have
specficied, however this behavior is disabled by default.

Whenever the minimum is greater than the requested value a CMake warning
will be issued in the build output.

This patch ends up modifying several places outside of kernel code,
since the presence of the system heap is no longer detected using a
non-zero CONFIG_HEAP_MEM_POOL_SIZE value, rather it's now detected using
a new K_HEAP_MEM_POOL_SIZE value that's evaluated at build.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2023-12-20 11:01:42 +01:00
Mario Paja 98336b2811 Revert "net: gptp: Fix announce message len"
This reverts commit 6b644dff67.

Reason: breaks Peer-to-Peer gPTP connection. A better solution should be
found to handle the optional TLV on the announce message (chapter 10.5.1
IEEE 802.1AS-2011)

Signed-off-by: Mario Paja <mario.paja@zal.aero>
2023-12-19 22:51:52 +00:00
Chaitanya Tata 6152e64aa0 wifi: shell: Fix arg count for regulatory domain
Regulatory domain supports both get and set, so, fix the argument
counts.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2023-12-18 17:46:12 +01:00
Robert Lubos b7e3ae2521 net: ipv6_mld: Silently drop MLDv1 queries
Zephyr does not support MLDv1 (which has a shorter header than MLDv2),
and this resulted in log errors being printed on header access if MLDv1
queries were received. Since receiving such packet is not really an
error, just drop it silently.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-12-18 09:28:42 +01:00
Pieter De Gendt 4807ada01e net: lib: coap: Use coap_transmission_parameters in coap_server
Update coap_service_send and coap_resource_send to take an optional
pointer argument to the newly introduced coap_transmission_parameters.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2023-12-18 09:28:25 +01:00
Chaitanya Tata eaba47445a wifi: shell: Display RSSI only for station mode
RSSI makes sense only for modes that have a single peer, so, add a
station mode check.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2023-12-18 09:28:16 +01:00
Chaitanya Tata 9736cc7f29 wifi: shell: Fix AP argument checks and help
AP enable takes the same parameters as connect, so, update the help and
also fix the optional parameter count when security is involved.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2023-12-18 09:28:16 +01:00
Robert Lubos 0c095898fb net: shell: Prevent deadlock with net arp command
In case one of the networking shell backends is enabled, net arp command
could potentially trigger a deadlock, as it locks the ARP mutex before
TCP connection mutex, while TCP stack could do this in reverse order
(for instance when sending ACK or retransmission).

Mitigate this, by forcing a separate TX thread in such case, so that ARP
mutex is no longer accessed with TCP mutex locked.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-12-15 11:42:40 +00:00
Juha Ylinen d09d3d82ef net: lib: coap: Change coap_pending_init()
Replace function parameter 'retries' with pointer to structure
holding coap transmission parameters. This allows setting the
retransmission parameters individually for each pending request.

Add coap transmission parameters to coap_pending structure.

Update migration guide and release notes.

Signed-off-by: Juha Ylinen <juha.ylinen@nordicsemi.no>
2023-12-15 11:41:27 +00:00
Jukka Rissanen b6aea97dc7 net: l2: dummy: Add start/stop API functions
The dummy L2 layer does not implement any L2 functionality
but it does not mean that it should not implement start/stop
functions that are called when the related network interface
is brought up or taken down.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-12-14 14:21:31 +01:00
Jukka Rissanen d8ec9118b4 net: if: Interface stays down if device is not ready
It is pointless to take net interface up if the underlaying
device is not ready. Set also the interface status properly
in this case.

Fixes #65423

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-12-14 14:21:31 +01:00
Daniel DeGrasse 3091ddc4fe net: lib: lwm2m: use correct format specifier for LOG_ERR
Use correct format specifier for LOG_ERR in lwm2m_obj_device.c. The
previously used format specifier of %u was correct for 32 bit systems
but would produce a build warning for 64 bit systems.

Fixes #66441

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
2023-12-14 09:32:43 +01:00
Declan Snyder e913ccc753 net: Add Kconfig for net buf alignment
Add a NET_BUF_ALIGNMENT kconfig to make net buffer alignment configurable.

Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
2023-12-14 09:29:47 +01:00
Jukka Rissanen 477a4a5d34 net: shell: Rename the common.h to be more unique
As the common.h is only meant to be used by the network
shell files, rename it to be more descriptive in order to
avoid possible conflicts with any other common.h file.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-12-13 20:13:39 +01:00
Robert Lubos 8cb4f09a28 net: tcp: Remove pointless recv callback calls
Calling the registered receive callback when releasing TCP context
doesn't make sense, as at that point the application should've already
closed the associated socket (that's one of the conditions for the
context to be released). Therefore, remove the pointless receive
callback call, while keeping the loop to unref any leftover data packets
(although again, I don' think there should be any packets left at that
point, as they're all consumed in tcp_in()).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-12-13 10:39:03 +01:00
Robert Lubos 6b00b537aa net: tcp: Fix deadlock with tcp_conn_close()
While improving thread safety of the TCP stack I've introduced a
possible deadlock scenario, when calling tcp_conn_close() in tcp_in().
This function shall not be called with connection mutex locked, as it
calls registered recv callback internally, which could lead to deadlock
between TCP/socket mutexes.

This commit moves the tcp_conn_close() back where it was originally
called. I've verified that the thread safety is still solid with the
test apps used originally.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-12-13 10:39:03 +01:00
Declan Snyder e4cca5145b net: Add fallback macro for nef_if_mon functions
Add empty macro for net_if_mon functions if they are not otherwise
defined, like the other functions in the net_if.c file have.

Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
2023-12-12 10:58:38 +00:00
Juha Ylinen 69e28939dd net: lib: coap: Add new API to configure retransmission settings
Add new functions to the public CoAP API to configure CoAP packet
retransmission settings. Application may need to re-configure the
settings for example when cellular modem changes connection from
LTE-M to NB-IoT or vice versa.

Signed-off-by: Juha Ylinen <juha.ylinen@nordicsemi.no>
2023-12-12 10:56:29 +01:00
Jukka Rissanen b6d9ed095d net: Move trickle files to lib
The trickle algorithm files are clearly a library so move
them under lib/ directory.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-12-11 10:50:35 +01:00
Robert Lubos 2cc0d31d9f net: tcp: Move TCP Kconfig options to separate file
The number of Kconfig options for the TCP stack grew considerably,
therefore it makes sense to move them to a separate file not to bloat
the Kconfig file with generic networking options.

Take this opportunity to reorder TCP options, so that protocol
parameters (timings/buffer sizes) are not mixed up with optional
protocol features (fast retransmit/congestion avoidance etc.).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-12-11 10:11:10 +01:00
Robert Lubos a150380d65 net: tcp: Implement Keep-alive support
When a TCP connection is established, if there is no data exchange
between the two parties within the set time, the side that enables
TCP Keep-alive will send a TCP probe packet with the same sequence
number as the previous TCP packet. This TCP probe packet is an empty
ACK packet (the specification recommends that it should not contain
any data, but can also contain 1 nonsense byte, such as 0x00.). If
there is no response from the other side after several consecutive
probe packets are sent, it is determined that the tcp connection has
failed, and the connection is closed.

The keep-alive default parameters are aligned with Linux defaults.

Signed-off-by: Horse Ma <mawei@coltsmart.com>
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-12-11 10:11:10 +01:00
Seppo Takalo 005dc60d24 net: lwm2m: Fix pmin handling on tickless
If observed resource was written during the pMin period, it did
not schedule any wake-up event into the future. Notify message would
then only be generated as a result of any other (like Update) event.

Refactor check_notifications() to follow same pattern as retransmit_req().
Return the next event timestamp, which could be now.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2023-12-11 09:57:09 +01:00
Jasper Smit 6003927ac2 net: sntp: Add option for SNTP uncertainty
SNTP response is not analyzed for uncertainty, and no uncertainty is given
to the `struct sntp_time` returned. Fix it with a Kconfig option that adds
optional SNTP uncertainty and timestamp fields in SNTP time struct, and
calculates these when parsing the response.
Adds two helper functions to convert Q16.16/Q32.32 in seconds to `int64_t`
in microseconds to facilitate this.
Also changes combined `lvm` field in `struct sntp_pkt` to bit-fields
`li`, `vn`, and `mode`.

Signed-off-by: Jasper Smit <git@jrhrsmit.nl>
2023-12-08 10:25:46 +00:00
Lingao Meng 786b9a0ad4 Bluetooth: Host: Add const prefix for UUID
Add const prefix for service uuid and char uuid.

Since Service UUID and Char UUID should not change in the service
definition, they are most reasonably defined as rodata, also for
save some ram footprint.

The field `attr->user_data` type is `void *`, as this PR change
all Service UUID to rodata, so there must add (void *) to avoid warning.

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2023-12-07 16:16:43 +00:00
Pieter De Gendt c1204affab net: ip: net_mgmt: Support system work queue and synchronous callbacks
Add Kconfig choice for the user to select how Network Events are
handled. It's own thread, the system work queue or synchronous when
events are emitted.

By default a separate thread is created to be backwards compatible.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2023-12-07 16:15:53 +00:00
Pieter De Gendt 35761f724d net: lib: shell: Add CoAP descriptions to event monitor
Add a description for each CoAP event on L4.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2023-12-07 10:34:39 +00:00
Pieter De Gendt 5182dd24c6 net: lib: coap: Introduce net mgmt events for CoAP
Allow users to register net mgmt events callbacks for CoAP events.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2023-12-07 10:34:39 +00:00
Pieter De Gendt f712441840 Revert "net: lib: coap: Add support for observer event callbacks"
This reverts commit 5227f24815.

The coap observer events will be replaced with net_mgmt events.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2023-12-07 10:34:39 +00:00