When handling packets for inputing into packet-sockets, unconditionally
forward them, so that they may be handled by the rest of the network
stack after.
Signed-off-by: Cla Mattia Galliard <clamattia@gmail.com>
In case FIN packed also acknowledged most recently sent data, not all
ack-related TCP context variables were updated, resulting in invalid SEQ
number values sent in consecutive packets.
Fix this by refactoring the FIN handling in TCP_ESTABLISHED state.
Instead of having a separate block strictly for FIN packet processing,
let the packet be processed by common code responsible for regular
data/ack processing. This should be less error-prone for any future
modifications or not-yet-discovered issues. Only after the common
processing of data/ack is done, we check whether FIN flag was present in
the packet, and mark the connection for closing.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
TCP context cannot operate w/o a TX packet for buffering transmitted
data. So far this net_pkt was allocated at runtime from the common
packet pool, but this created some not-obvious memory requirement on TCP
and could lead to TX packet starvation in case many TCP connections are
open in parallel. Therefore, allocate this packet structure statically,
as a part of the TCP context instead.
This increases the memory requirement of the TCP context by ~64 bytes,
however if that's a concern for the application, the maximum number of
TX packets can be lowered instead. In return, we get a clear separation
between the number of TCP connections opened, and the amount of packets
that can be transmitted.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Add helper function to initialize externally allocated TX packet. It's
especially important to configure net_buf slab for the packet so that
net buffers are allocated from a correct pool for the packet.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Using net_pkt for TCP out-of-order recv queue was an overshot, as the
mechanism mostly used net_buf operations directly anyway. It can be
easily replaced with a direct net_buf pointer, so that it's not longer
needed to hog one net_pkt per TCP context anymore.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
This aims to implement a packet forwarding mechanism between
DNS resolver and applications that install a callback, letting
DNS resolver know that received UDP packet is also required by an
application.
Signed-off-by: Cristian Bulacu <cristian.bulacu@nxp.com>
In case STA + AP mode is enabled, then adjust the defaults to accomodate
the second interface.
Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
TCP somehow ended up with two internal headers with duplicate set of
internal function declarations. As tcp.h looks like a subset of the
tcp_internal.h header, combine the two headers into a single
tcp_internal.h and remove tcp.h. There were some differences in doxygen
API descriptions, so I've used the description that better described the
actual function purpose.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Implement TCP connection backlog for TCP server. The backlog parameter
is already specified by the listen() socket API, however it was never
implemented in Zephyr. It can be useful to limit the number of incoming
connections on the server side, and thus limit the connection flood and
resource shortage.
The backlog is implemented as a atomic counter inside the TCP context.
The counter is initialized on the listen() call (and thus no connection
can be accepted before listen() is called), and then decremented
whenever new connection is initiated. When the application accepts
the incoming connection, it should call the net_tcp_conn_accepted()
API (done automatically for sockets) to inform the TCP layer that the
backlog can be incremented. The backlog value is also incremented back
if the connection is released before the connection was passed to the
application.
For tracking the parent (listening) socket, the 'accepted_conn' pointer
on the client context has been reused. Note, that the pointer used to be
cleared before the accept_cb() call before, to prevent consecutive calls
to the callback, however this was not really needed - the TCP state is
changed anyway, and the accept_cb() is only used in TCP_SYN_RECEIVED
state. The pointer is no cleared when the application accepts the
connection (or the client or the associated parent context is closed).
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
When encoding cached LwM2M 1.1 resources into SenML CBOR, the encoder
currently aborts with -ENOMEM if the number of records (minus
some CBOR delimiter elements) exceeds CONFIG_LWM2M_RW_SENML_CBOR_RECORDS.
This discards all serialized data and prevents any payload from
being sent, leaving the client stuck and caches filling up.
This patch changes the behavior: if some records were already
serialized before the buffer shortage, the CBOR output is finalized
(end marker added) and the partial payload is returned. This allows
the client to send useful data, and the upper layers can react by
reducing batch size.
Impact:
- Preserves forward progress instead of canceling the message
- Avoids cache lock-up
- No changes to the API or success path behavior
Signed-off-by: Marcel Wappler <marcel.wappler@decentlab.com>
Inject packets from AIL to Thread network and vice versa taking into
account packet forwarding security safeguards and multicast forwarding.
Signed-off-by: Cristian Bulacu <cristian.bulacu@nxp.com>
As the linkaddr->addr is no longer a pointer, the original
assert check is not working as it should. So use the length
of the linkaddr to verify that it is > 0.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
This commit adds a work item designated for Border Router message
parsing. A generic message structure has been proposed.
If CONFIG_NET_IPV4 is enabled, border router services will start only
after an IPV4 address has been assigned on the backbone interface.
If border router is initialized before DHCPV4 client has been assigned
an address, initial mDNS IPV4 packets will be dropped, because a source
address cannot be retrieved from that specific backbone interface.
Signed-off-by: Cristian Bulacu <cristian.bulacu@nxp.com>
When next_ping == now, the code scheduled the workqueue for the current
time. On native_sim, this meant that the system workqueue thread was stuck
in an infinite loop because it kept processing the MQTT work over and over
again and the current timestamp could not advance anymore.
I didn't investigate why the yield inside the workqueue didn't help or why
native_sim can't advance time when one of the threads is stuck, but
changing the condition to >= inside mqtt_sn solves this issue.
I discovered this while running zephyr.exe through strace for up to 60
minutes. I guess that the performance overhead makes it more likely for the
workqueue handler to be run while next_ping == now, but I didn't verify
that, because it takes a long time to trigger the bug.
Signed-off-by: Michael Zimmermann <michael.zimmermann@sevenlab.de>
Added PTP solution in core driver. Now only gPTP was supported.
- ethernet_api like get_capabilities and get_ptp_clock
were supported in port driver.
- For TX timestamp, added new dsa_api port_txtstamp for device
to handle. Device driver might put pkt in queue, and reported
timestamp after completing transmitting on hardware.
- For RX timestamp, the timestamp could be given to pkt in tag
driver or device driver.
Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
Supported tagger data and connecting device to tag protocol, so that some
device specific work could be handled.
Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
If we have allocated a TCP connection, and if after that
we get an error like EADDRINUSE, then we must de-allocate
the TCP connection otherwise there is a buffer leak.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
The websocket used mbedtls functions to calculate the
SHA1 needed. Update the code to use PSA crypto calls instead
when the configuration CONFIG_MBEDTLS_PSA_CRYPTO_CLIENT
is enabled.
This can be useful for applications which use TF-M
since it only provides PSA crypto APIs.
Also check the error code from the mbedtls_sha1
call since it can fail and it was not checked before.
Signed-off-by: Georgios Vasilakis <georgios.vasilakis@nordicsemi.no>
DSA is part of Ethernet and will utilize more Ethernet definitions for
more features support. So, it's proper to let DSA header include
Ethernet header with moving some DSA definiton from DSA header to
Ethernet header and adding DSA header including in c files using DSA
definition.
Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
Once running, a socket service could not be reconfigured (i.e. changing
file descriptors and/or events to be polled). This was due to an wrong
check at the end of the thread main loop of socket_service_thread that
evaluated to false as variable ret is zero if trigger_work(), which is
called previously for all returned events, returns successfully.
Signed-off-by: Philipp Finke <philipp_finke@gmx.de>
When an IPv4 packet is received on a dual-stack socket, return
the mapped v4 to v6 address as source address.
Signed-off-by: Cristian Bulacu <cristian.bulacu@nxp.com>
Fixed issue when `sendmsg()` was in use and `CONFIG_NET_IPV6`
and `CONFIG_NET_IPV4_MAPPING_TO_IPV6` were in use, as `dst_addr`
argument of `context_sendto()` was passed NULL,
but also used to determine `sa_family`.
Use msghdr, if available, to determine if v4 to v6 mapping is
present.
Also set `dst_addr` to unmapped value when v4 to v6 mapping is
used.
Signed-off-by: Cristian Bulacu <cristian.bulacu@nxp.com>
If v4 to v6 mapping is used, cmsg_level and cmsg_type should
be compared with IPv6 values even if pkt family if AF_INET.
Signed-off-by: Cristian Bulacu <cristian.bulacu@nxp.com>
Print TCP connection pointer value for debug prints
consistently so that it is easier to find debug prints that
are related to a certain TCP connection.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Print return code on error and remove logging in `sntp_resync_handler`
since it calls `net_init_clock_via_sntp` which already does logging.
Signed-off-by: Jeppe Odgaard <jeppe.odgaard@prevas.dk>
Use the l2_processed-flag to decide whether a network packet needs to be
processed by an L2-handler. This could be used in the future to requeue
packets for later processing by a different traffic class queue.
Signed-off-by: Cla Mattia Galliard <clamattia@gmail.com>
This default value 2 of WIFI_NM_MAX_MANAGED_INTERFACES
ensures WiFi network manager can properly handle both
access point and station interfaces.
Signed-off-by: Muhammad Waleed Badar <walid.badar@gmail.com>
RFC4330 section 10 states:
A client MUST NOT under any conditions use a poll interval less then 15
seconds.
Signed-off-by: Jeppe Odgaard <jeppe.odgaard@prevas.dk>
Used simple vlanX for vlan interface name. What interface the
vlan interface was attached to could be checked by "net iface"
or "net vlan".
Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
There were two problems about vlan interface naming currently.
1. When there were more than 1 vlan interfaces. It's not able to
initialze name for all of them to same name VLAN-<free>.
2. When enabled vlan with tag, the name VLAN-xxx was used.
However we may need to support multiple physical interfaces
in the future. So, it's not able to use same name VLAN-xxx
either for same tag on different physical interfaces.
Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
The `%.*s` format specifier expects an int so cast the size_t parameter
to int.
Fixes an issue spotted in CI for:
west twister -p native_sim/native/64 -s sample.net.dns_resolve.mdns
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
These types are useful for IoT deployments and should be available
thru the resolver interface to get the data. The SRV is especially
useful to find services on the local network when not using a dns-sd
deployment and just something like Avanhi or Bonjour.
Signed-off-by: Charles Hardin <ckhardin@gmail.com>
When resolving SRV records - the label might not be compressed so
the first entry into the net buf is the start of the name and a
period could end up at the start - ie. ".example.local" so only add
a period when the buffer is not empty.
Signed-off-by: Charles Hardin <ckhardin@gmail.com>
The enum will auto increment, so in debug the IP and DATA records are
negative numbers which initially made this look like an error, so just
push the expected good values to be positive numbers in case of a print
or something else would imply these are ok.
Signed-off-by: Charles Hardin <ckhardin@gmail.com>
Previously, the Kconfig option `NET_GPTP_CLOCK_ACCURACY_2_5MS` had a
incorrect description "1.5ms".
Signed-off-by: Jonas Spinner <jonas.spinner@burkert.com>
The loop condition is not the count of the actual tries since the
continue or breaks can occur on the loop and thus a failure count
can falsely match a loop count even when a query is outstanding.
This can be seen when a dual stack resolve is used for IPv4 and IPv6
that has two fds to be used and the interface has only gotten an
IPv6 address. The failures on the IPv4 will indicate a 1 and the break
on the tried attempt on the IPv6 will break the loop on a 1.
Signed-off-by: Charles Hardin <ckhardin@gmail.com>
Suppress many LOG_ERR() messages from LwM2M registry
that are not necessary runtime errors.
Libraries and applications should be able to do following
without causing LOG_ERR to be produced:
* Checking existence of object, resource or resource instance
using lwm2m_engine_get_res(), lwm2m_engine_get_res_inst()
or path_to_objs(). These are only exposed in internal header.
* Delete object instance or resource instance without checking
if it exits.
As there is no public API to check existence of some path,
application is much easier to write in a way that it directly
calls just lwm2m_get...(), lwm2m_set...(), lwm2m_delete...()
and trust the return code of -ENOENT.
Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
UDP multicast uploads did not produce zperf-compatible server stats,
so the client waited for and tried to decode a non-existent reply,
causing “Unexpected response flags” and misleading
“LAST PACKET NOT RECEIVED!!!” output.
This change treats multicast as client-only: after sending
the negative-id FIN it does not wait for or decode server stats,
Instead transmits the FIN a few times to help receivers detect test end.
The shell prints a clear “Statistics (client only)” summary for multicast
and suppresses the error when client stats are valid.
Unicast behavior is unchanged.
Signed-off-by: Kapil Bhatt <kapil.bhatt@nordicsemi.no>
Fix an issue where IPV6_RECVPKTINFO was used instead of IPV6_PKTINFO
when insert_pktinfo was called.
Signed-off-by: Cristian Bulacu <cristian.bulacu@nxp.com>