Add a default heap reservation for gettaddrinfo(), enough for a single
function call in a default configuration on 64-bit platform.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
There are some poorly compliant mdns responders on the network
that will respond with zero counts on the answers and the additional
records (in addition to the qdcount). So, this removes the checks
in the unpack method since this is a "valid" DNS packet but the
logic is already partially handled in the dns_read code already.
An example packet can be seen in this decode
0000 33 33 00 00 00 fb 9a f8 c3 0c 07 0b 86 dd 60 07 33............`.
0010 c4 e4 00 14 11 ff fe 80 00 00 00 00 00 00 98 f8 ................
0020 c3 ff fe 0c 07 0b ff 02 00 00 00 00 00 00 00 00 ................
0030 00 00 00 00 00 fb 14 e9 14 e9 00 14 f1 64 00 00 .............d..
0040 84 00 00 00 00 00 00 00 00 00 ..........
User Datagram Protocol, Src Port: 5353, Dst Port: 5353
Source Port: 5353
Destination Port: 5353
Length: 20
Checksum: 0xf164 [unverified]
[Checksum Status: Unverified]
[Stream index: 2]
[Stream Packet Number: 1]
[Timestamps]
UDP payload (12 bytes)
Multicast Domain Name System (response)
Transaction ID: 0x0000
Flags: 0x8400 Standard query response, No error
1... .... .... .... = Response: Message is a response
.000 0... .... .... = Opcode: Standard query (0)
.... .1.. .... .... = Authoritative: Server is an authority
for domain
.... ..0. .... .... = Truncated: Message is not truncated
.... ...0 .... .... = Recursion desired: Don't do query recursively
.... .... 0... .... = Recursion available: Server can't do
recursive queries
.... .... .0.. .... = Z: reserved (0)
.... .... ..0. .... = Answer authenticated: Answer/authority
portion was not authenticated by the server
.... .... ...0 .... = Non-authenticated data: Unacceptable
.... .... .... 0000 = Reply code: No error (0)
Questions: 0
Answer RRs: 0
Authority RRs: 0
Additional RRs: 0
Signed-off-by: Charles Hardin <ckhardin@gmail.com>
When running just the test mqtt_sn_client::test_mqtt_sn_wait_suback on
native_sim, the current timestamp is still 0. That caused the test to fail,
because 0 is used as an indicator, that the message has never been sent,
thus sending it every time process_work is executed.
Instead of adding additional variables and complexity, the code now simply
treats now==0 special and waits 1ms until doing anything.
Signed-off-by: Michael Zimmermann <michael.zimmermann@sevenlab.de>
- The paho client does that, too.
- This allows running single tests, because they don't rely on previous
ones having incremented the msg_id a certain number of times.
- The variable already existed in the client struct, but wasn't used. I
guess it was intended that way but never implemented.
Signed-off-by: Michael Zimmermann <michael.zimmermann@sevenlab.de>
Making the assumption, that mqtt_sn_connect does not process any incoming
data allows for this to be a very simple, additional API function instead
of adding more complexity to the connect function. This also means that the
user has to re-add predefined topics upon reconnects which don't reuse the
old session though.
Signed-off-by: Michael Zimmermann <michael.zimmermann@sevenlab.de>
Commit 48897a9090 fixed the address
mapping for dual-stack sockets when sendmsg() was used, however the same
similar issue appears (cannot check for AF_INET family for mapped
addresses as those are AF_INET6) for regular sendto() calls.
Therefore, for the sendto() case, where dst_addr is specified, check if
the address is mapped with net_ipv6_addr_is_v4_mapped() function as
well.
This also fixes another bug in sendmsg() case, where msghdr->msg_name
could've been dereferenced even if it was NULL (for example in case
of a connected socket).
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
It is easier to debug things when both the relative and absolute
TCP seq and ack numbers are printed in debug prints.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Use the socket eof flag to determine whether the receive
callback should be installed. If the receive cb is not installed,
then the socket cannot receive any data.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
This PR includes OpenThread's NAT64 header file when
NAT64_TRANSLATOR is enabled. This is done to avoid compile
warnings when OT NAT64 API is used.
Signed-off-by: Cristian Bulacu <cristian.bulacu@nxp.com>
Ethernet TX should not handle bridge forwarding. The bridge layer
had already handled forwarding.
Current code is causing duplicated TX if sending is via bridge
interface, or causing needless TX on other bridge ports if sending
is via one bridge port.
Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
There were several problems of pkt management during forwarding.
1. No need to do net_pkt_ref/net_pkt_unref around net_if_queue_tx.
2. Finally when completed forwarding, there was a net_pkt_unref for
pkt using cloning. However it also applied to pkt not using
cloning. This was causing pkt was released before sending.
3. Whether pkt cloning used or not, should not be decided by bridge
interfaces count. It's should be decided by interface count to
forward.
An example was sending pkt via bridge interface. If there were
two interfaces attached to bridge, cloning was needed but current
code won't.
Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
- Initialize platform requirements and start OpenThread DHCP6_PD
feature.
- Added initialization logic for DNS upstream resolver.
OTBR message data structure has been updated to store a user data
structure, if needed.
- Added SRP server initialization call.
Signed-off-by: Cristian Bulacu <cristian.bulacu@nxp.com>
GCC gave the following warning:
mqtt_sn_transport_udp.c: In function ‘tp_udp_init’:
mqtt_sn_transport_udp.c:117:9: warning: ‘memcpy’ forming offset [12, 105]
is out of the bounds [0, 12] of object ‘mreqn’ with type ‘struct ip_mreqn’
[-Warray-bounds=]
117 | memcpy(&mreqn.imr_multiaddr, &udp->bcaddr.data[2], si...
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mqtt_sn_transport_udp.c:48:25: note: ‘mreqn’ declared here
48 | struct ip_mreqn mreqn;
| ^~~~~
And it turns out that it's right. The original code looks like it tries to
copy the IP address to imr_multiaddr in a way that works for both v4 and
v6. It ignores, that bcaddr.data may be way larger than even a v6 addr,
because it's a buffer that's big enough to hold many other structs as well.
Not only that, IP_ADD_MEMBERSHIP is for IPv4 only and imr_multiaddr can
only hold an IPv4 address anyway.
This modifies the code to have separate code paths for v4 and v6 and call
the correct APIs. This also gets rid of the memcpy, since it can be a
simple struct assignment now.
Signed-off-by: Michael Zimmermann <michael.zimmermann@sevenlab.de>
dns_unpack_query() no longer prepends the unpacked query with extra dot,
therefore LLMNR responder needs to be aligned with this change when
parsing result and preparing response.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
dns_unpack_query() no longer prepends the unpacked query with extra dot,
therefore mDNS responder needs to be aligned with this change when
parsing result and preparing response.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
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>