Commit Graph

3156 Commits

Author SHA1 Message Date
wangchen
678164bf4e net_bufpool.c:when timeout value is zero,It don't break netlock
Resolve some timing issues caused by calling net_breaklock to release netlock in the function NET_BUFPOOL_TRYALLOC

Signed-off-by: wangchen <wangchen41@xiaomi.com>
2025-11-10 22:30:37 -05:00
Jukka Laitinen
f4142626b9 net/can/can_recvmsg.c: Cleanup can_readahead
Some checks failed
Build Documentation / build-html (push) Has been cancelled
It is better to remove the iob from the readahead queue first,
and only after that work on the iob.

Signed-off-by: Jukka Laitinen <jukkax@ssrc.tii.ae>
2025-08-26 20:42:01 +08:00
haitomatic
144ac23647 net/can/can_recvmsg.c: Remove IOB trimming as useless, can frames can always fit in one IOB
Signed-off-by: Jukka Laitinen <jukkax@ssrc.tii.ae>
2025-08-26 20:42:01 +08:00
haitomatic
8fc2ad20a7 net/can/can_callback.c: Take the timestamp size into account in "buflen"
In case CONFIG_NET_TIMESTAMP is enabled, subtract the timestamp size from the buflen

Signed-off-by: Jukka Laitinen <jukkax@ssrc.tii.ae>
2025-08-26 20:42:01 +08:00
nuttxs
22560958bc net/arp: reducing unnecessary ARP requests can mitigate
Some checks failed
Build Documentation / build-html (push) Has been cancelled
network congestion and avoid packet delays caused by
waiting for ARP responses

Signed-off-by: nuttxs <zhaoqing.zhang@sony.com>
2025-07-08 12:43:43 -03:00
ligd
230714bd23 local: correct shutdown state when use UDP mode
Signed-off-by: ligd <liguiding1@xiaomi.com>
2025-07-07 23:45:35 +08:00
wangjianyu3
c1aa625bdb net: enable tcp backlog by default
If the NET_TCPBACKLOG configuration is not enabled, no I/O event will be
triggered for the socket file descriptor in poll/epoll. As a result, the
connection will not be accepted, leading to a failure in the TCP handshake.

The problem is that users may not have noticed this configuration,
no event will be received when polling the socket fd.

Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
2025-06-26 09:32:54 -03:00
dongjiuzhu1
a12d21e830 fs/file: unify prefix about file_xxx api, like file_open, file_ioctl
old:
fs_getfilep, fs_putfilep, fs_reffilep
new:
file_get, file_put, file_ref

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2025-06-12 18:12:42 +08:00
dongjiuzhu1
a5485d6c53 net/utils: avoid unalign access g_tcp_connections_buffer
the address is 0x3c270203, cause unaligned access usage Fault
(gdb) p g_tcp_connections
$1 = {pool = 0x3c270203 <g_tcp_connections_buffer> <error: Cannot access memory at address 0x3c270203>,
prealloc = 8, dynalloc = 1, nodesize = -376, sem = {semcount = 32767, flags = 0 '\000',
waitlist = {head = 0x0, tail = 0x0}}, freebuffers = {head = 0x0, tail = 0x0}}

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2025-06-09 08:04:21 -03:00
Matteo Golin
ab756e8dd7 net/tcp: Fix keep-alive implementation
The TCP keep-alive implementation would send the probes and abort the
connection correctly, but without waking up the affected socket and
marking the connection as aborted. This patch from zhhyu7 in #16447
resolves the issue.

Signed-off-by: Matteo Golin <matteo.golin@gmail.com>
2025-05-28 10:18:17 -03:00
raiden00pl
9aab92e3cf net: unify Private Types banners
unify Private Types banners according to NuttX coding standard

Signed-off-by: raiden00pl <raiden00@railab.me>
2025-05-28 10:17:15 +08:00
Lars Kruse
3ce85ca54e style: fix spelling in code comments and strings 2025-05-23 10:48:41 +08:00
Lars Kruse
4568110d63 fix misspelled names in locally scoped code
These misspelled words are used in strictly local scopes.
Renaming these variables should not cause any problems.
2025-05-15 10:12:12 +08:00
nuttxs
da74a5e368 net/tcp/tcp_conn.c: optimize the port conflict detection rules
for tcp_listener(). fixed potential conflict between implicit
binding and port conflict detection.

Implicit binding automatically allocates an interface address during
connection,but port conflict detection occurs before binding/connecting.
This can cause issues when creating multiple TCP connections in succession.
If the first connection uses a random port via implicit binding, subsequent
connections might reuse the same port under current filtering rules,
leading to connect() failures.

Signed-off-by: nuttxs <zhaoqing.zhang@sony.com>
2025-04-24 14:10:27 +08:00
Carlos Sanchez
dd53c34722 net/netdev: Change SIOCSCANBITRATE to require interface down.
Previously, SIOCSCANBITRATE brought the iterface up to ensure changes
where immediately applied. This was confusing, see
https://lists.apache.org/thread/g8d0m6yp7noywhroby5br4hxt3r4og2c
Now SIOCSCANBITRATE fails is interface is up.
All existing SocketCAN drivers updated.

Signed-off-by: Carlos Sanchez <carlossanchez@geotab.com>
2025-04-15 01:59:57 +08:00
Laczen JMS
e83d31bee9 net/udp: correct icmp(v6) response from udp_input
Ensure that the correct icmp(v6) response is generated from udb_input.

Signed-off-by: Laczen JMS <laczenjms@gmail.com>
2025-03-17 09:57:50 +01:00
Javier Casas
9c04b9ed4a net/can: Fix NULL dereference for I/O Block
In a recent patch the socketcan timestamp generation was moved
to add it also when there is an active reader (previously the timestamp
was only added before storing the CAN frame in the read-ahead list).

It was working fine but I realized that the can_callback function is
also called when sending frames. In this case, the IO block is not allocated
yet and the code breaks.

This PR is to only generate the timestamp if the IO block is not NULL
(reading path) and skip it when it is NULL (sending path)

Signed-off-by: Javier Casas <javiercasas@geotab.com>
2025-03-13 09:37:55 +01:00
Laczen JMS
96eb5e7819 net: sixlowpan icmpv6 return from udp_input
When a udp frame is processed without a listener a icmp frame is
returned indicating that there is no listener. The PR enables
sending this icmpv6 response over sixlowpan.

Signed-off-by: Laczen JMS <laczenjms@gmail.com>
2025-03-13 12:29:48 +08:00
Javier Casas
73f9ef00e2 net/can: fix timestamp
Fix timestamp in socket CAN. Right now the timestamp is only generated
if there is no reader and the frame is stored in the read ahead list.
This is solved by moving the timestamp generation before the code flow
branch.

Signed-off-by: Javier Casas <javiercasas@geotab.com>
2025-03-07 12:31:40 -03:00
zhanghongyu
7f0a670bde net/socket/getsockopt: move the options check to the upper layer
check parameters at the top level to avoid errors when assigning
values in si_getsockopt.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2025-03-04 09:29:06 +01:00
Laczen JMS
34aa17b7a0 sixlowpan: improve tcp support.
Update the handling of tcp packets over sixlowpan. `tcp_ipv6_input()`
can update the dev->d_iob. Assigning ipv6 to IPv6BUF makes sure that
the correct buffer is used.

Signed-off-by: Laczen JMS <laczenjms@gmail.com>
2025-02-22 07:58:26 -03:00
Laczen JMS
31270a8479 net: fix ipv6_input for 6lowpan
6lowpan response for tcp and icmp was mssing because of wrong evaluation
of `dev->d_lltype`.

Signed-off-by: Laczen JMS <laczenjms@gmail.com>
2025-02-12 10:19:50 -03:00
Javier Casas
52dbfda355 bug fix: can_datahandler wrong return value
can_datahandler returns an unsigned value that represent the
number of bytes actually bufffered, but the call to iob_tryadd_queue
returns a negative value when it fails so that value can't be used as
can_datahandler return value because it is interpreted as unsigned so
a big number is wrongly returned when iob_tryadd_queue fails.

The fix is just setting the return value to zero when iob_tryadd_queue
fails, reflecting the actual meaning that no bytes have been buffered.
2025-01-30 11:37:29 -03:00
Javier Casas
d52ff33e78 net/can/: add statistics for recv, sent and drop
Add support for network statistics for CAN.
It includes counters for receive, sent
and drop frames.

Signed-off-by: Javier Casas <javiercasas@geotab.com>
2025-01-30 11:37:29 -03:00
chenrun1
99a1f0dc65 inet_sockif:support multiple iov recv
Summary:
  Implement multiple iovlen recvmsg in inet_sockif, only TCP mode
  support at current.

Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2025-01-20 17:12:14 +08:00
Zhe Weng
87a7714103 net: Split msg_iovlen check in recvmsg into each protocol
To prepare for supporting multiple iov in each protocol.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2025-01-20 17:12:14 +08:00
zhanghongyu
70489fe56b net/tcp_timer: remove tcp_callback(TIMEOUT) when accept conn timeout
when accept conn timeout, only accept conn itself should handle the event
(send TCP_RESET), and there is no need to notify the listening conn.
otherwise, the server's poll will return with POLLERR and POLLHUP.
this may cause some applications to execute incorrect logic in the future.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2025-01-10 02:04:37 +08:00
Huang Qi
cfd0cc0d1a Remove duplicate includes across multiple files
This commit cleans up redundant header file includes throughout the codebase.
 The changes include:

 - Removing duplicate #include directives that were present in the same file
 - Consolidating includes that were split across multiple lines unnecessarily
 - Removing unused includes that were no longer needed
 - Fixing some formatting issues with includes

 The changes improve code organization and maintainability by:
 - Reducing unnecessary dependencies
 - Making include dependencies more explicit
 - Following consistent include patterns
 - Removing dead code

 No functional changes are made - this is purely a code cleanup commit.

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2025-01-09 23:30:23 +08:00
Zhe Weng
3e62be8361 net: Enable dynamic allocation of tcp/udp/ipfwd buffer by default
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2025-01-07 22:00:21 +08:00
Zhe Weng
50b3ab7671 net/bufpool: Call init automatically on alloc
Note: Initialize function of protocols (tcp, udp, pkt, etc.) are kept empty.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2025-01-07 22:00:21 +08:00
Zhe Weng
f702f1705f net/bufpool: Use SEM_INITIALIZER to init sem
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2025-01-07 22:00:21 +08:00
Zhe Weng
3b26c6df51 net/udp: Let cansend return EWOULDBLOCK when send buffer is full
Notes:
1. This commit do the same thing as TCP did: https://github.com/apache/nuttx/pull/10627
2. UDP uses `iob_navail(false)` but TCP uses `iob_navail(true)`, this is because of a problem related to TCP recv window (https://github.com/apache/nuttx/pull/4142), so we don't need to change UDP now.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2025-01-02 23:13:39 +08:00
zhanghongyu
f344a422e8 tcp_input: remove tcp_callback(ABORT) when accept conn recv TCP_RESET
when accept conn receives TCP_RESET, only accept conn itself should handle
the event, and there is no need to notify the listening conn. otherwise,
the server's poll will return with POLLERR and POLLHUP. this may cause
some applications to execute incorrect logic in the future.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2024-12-31 09:43:35 +08:00
zhanghongyu
05f7b7ac97 include/netinet/arp.h: change the type of arp_dev from uint8_t to char
the same variable type in linux is char, in order to avoid modifying
the third-party library code when porting the third-party library code.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2024-12-26 23:29:23 +08:00
Zhe Weng
84d261e3be net: Optimize ipfwd and wrbuffer by buffer pool
To allow dynamic allocation of these structs, performance keeps the same
as the previous implementation.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2024-12-23 16:57:19 -03:00
Zhe Weng
1fe07d0838 net: Add buffer pool to replace connection allocation
Our net socket connection allocations are powerful but redundant
because they're implemented once in each protocol.  This is not good for
further optimizing and extending to other allocations, so maybe we can
add a common implementation for the usage.

Impact:
1. We add a `struct net_bufpool_s` as pool descriptor, which may use a
   little bit more memory than previous implementation (~28Bytes).
2. We share same functions between pools, so code size may shrink under
   some scenarios.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2024-12-23 16:57:19 -03:00
liqinhui
88a300d2e6 net: Remove the DEBUGASSERT of the same event of the same fd in tcp_pollsetup.
In libuv, if the real_timeout in the uv__io_poll is less than 0, the poll logic will be entered directly by the uv__run_timers, which will trigger the ASSERT.
It seems that the situation of first epoll and then poll for the same fd is used in libuv.

Signed-off-by: liqinhui <liqinhui@xiaomi.com>
2024-12-23 19:41:13 +08:00
wangchen
8ea31668ca tcp_recvfrom.c:malloc a new iob to handle psock_send_eventhandler when tcp_recvhandler calls tcp_newdata to clear dev->d_iob
Signed-off-by: wangchen <wangchen41@xiaomi.com>
2024-12-22 19:26:04 +08:00
Zhe Weng
035fdb4951 net: Refresh config dependency of NET_READAHEAD
ICMP(v6) uses IOB queue as readahead, but TCP/UDP don't now.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2024-12-20 20:01:19 +08:00
chao an
4793407b67 net/icmp: fix typo timout -> timeout
Signed-off-by: chao an <anchao@lixiang.com>
2024-12-17 20:48:07 +08:00
meijian
d1786507b6 net/tcp_timer: fix tcp RTO abnormally large after retransmission occurs
when tcp retransmission only double conn->timer in Karn(tcp_timer.c L602), after retransmission in Jacobson
M is is now rtt test will become a negative value.
```
  signed char m;
  m = conn->rto - conn->timer; // M is now rtt test

  /* This is taken directly from VJs original code in his paper */

  m = m - (conn->sa >> 3);
  conn->sa += m;              //conn->sa is a negative value
  if (m < 0)
	{
	  m = -m;
	}

  m = m - (conn->sv >> 2);
  conn->sv += m;
  conn->rto = (conn->sa >> 3) + conn->sv; //rto
```
For example,we lost one ack packet, we will set conn->timer = 6 by backoff,conn->rto still 3.
After retransmission we will Do RTT estimation, then will get
```
conn->sa = 253
conn->rto = 46
```
Then if any packets lost it will wait for a long time before triggering a retransmission.

Test method.
We can reproduce this issue by adding drop ACK packets in tcp_input, and debug conn->rto after Jacobson.

Signed-off-by: meijian <meijian@xiaomi.com>
2024-12-10 22:00:55 +08:00
Zhe Weng
752245aca4 net: Move NET_TCP/UDP_HAVE_STACK to netconfig.h
Now the HAVE_PFINET(6)_SOCKETS depends on NET_TCP/UDP_HAVE_STACK, which
is previously defined in net/ folder and cannot be included.
Considering many places use this check, maybe moving them to netconfig.h
could be better.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2024-11-21 23:07:30 +08:00
meijian
6944a16306 tcp/tls: fix tcp tls bugs
assert: tcp conn and didn't recv ack, tcp_free will assert in L909
and no need to tcp free because tcp close will free by lpwork.

Signed-off-by: meijian <meijian@xiaomi.com>
2024-11-21 00:23:01 +08:00
meijian
3b50bf1782 net/tcp_conn: fix thread_cancel() caused recv/connect/send event used after free
Problem Description:
Problem occurrence when Thread1 creat connect/recv socket and Thread2 cancel Thread1.
1. Thread2 cancel when Thread1 connect event, will cause DEBUGASSERT in devif_callback_free.Because cb in g_cbfreelist.
2. Thread2 cancel when Thread1 recvfrom sem-wait, when the FIN packet input and will trigger tcp_recvhandler and will crash.Becuase some thread stack data was freed.

Signed-off-by: meijian <meijian@xiaomi.com>
2024-11-21 00:23:01 +08:00
wangchen
540036ab60 udp:add tls cleanup protection to protect udp_callback info in psock_udp_recvfrom
Signed-off-by: wangchen <wangchen41@xiaomi.com>
2024-11-20 13:42:58 +08:00
wangchen
b0d8fd9d75 udp:add tls cleanup protection to protect waitsem in udp_txdrain
Signed-off-by: wangchen <wangchen41@xiaomi.com>
2024-11-20 13:42:58 +08:00
chenchuang
0c2ee8b492 fix: remove duplicated statistics of upd.drop
The valule of g_netstats.udp.drop has been increased in net_dataevent() function,
while it is increased in udp_datahandler().
2024-11-18 12:37:57 +08:00
wangjunfeng3
bfdfbc10ab net:Compatible with cellular network cards of lladdr generation
In the context of cellular networks, lladdr should use the interface identifiers from PDN.

Signed-off-by: wangjunfeng3 <wangjunfeng3@xiaomi.com>
2024-11-12 15:17:24 +08:00
zhanghongyu
af6db95fea tcp: fix tcp can not retransmit timely when ACK with TCP_NEWDATA
The current receive data needs to be handled by following
tcp_recvhandler or tcp_data_event. Notify driver to send the
message and marked as rexmit

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2024-11-10 00:39:48 +08:00
Peter van der Perk
faee89b966 net: fix inet #14634 regression
Define wasn't imported by netconfig.h move definitions
2024-11-05 18:36:02 +08:00