335 Commits

Author SHA1 Message Date
zhanghongyu
d5d6b65213 Revert "net: limit TCP and UDP send/recv buffer usage with throttled IOB"
This reverts commit fa652f9c24.

When testing iperf on boards such as ESP32-C6, ESP32-C3, and ESP32,
blocking issues are encountered, so the patch is reverted.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2026-01-23 14:40:06 -03:00
zhanghongyu
fa652f9c24 net: limit TCP and UDP send/recv buffer usage with throttled IOB
The main content of this submission is to limit both the TX/RX buffers
of TCP/UDP to throttled IOBs, avoiding impacts on the sending and
receiving of control-type messages.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2026-01-21 20:06:47 +08:00
daichuan
d2dde8a29a net/netdev: modify for hardware checksum offload
Implementation of main hardware verification and uninstallation functions

Signed-off-by: daichuan <daichuan@xiaomi.com>
2026-01-19 23:22:46 +08:00
zhanghongyu
0dc0b94380 net/ipv4: check whether the length of the ipv4 option is correct
This patch adds validation for IPv4 option lengths during packet processing
to prevent malformed packets from causing undefined behavior. The new
ipv4_check_opt() function verifies that option lengths are within valid
bounds before processing them.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2026-01-15 16:14:19 -03:00
zhanghongyu
8f41613374 net: replace net_sem*wait with conn_dev_sem*wait to simplify code logic
optimize the current code format according to the previous net_xxx_wait
implementation to reduce multiple calls of similar code

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2026-01-02 07:48:06 -03:00
zhanghongyu
efd8e1be2b net/ieee802154: replace net_lock with conn_lock and conn_lock_dev
decouple lock dependencies from other modules.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2026-01-02 07:48:06 -03:00
zhanghongyu
92b3357182 net/bluetooth: replace net_lock with conn_lock and conn_lock_dev
decouple lock dependencies from other modules.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2026-01-02 07:48:06 -03:00
zhanghongyu
2f3b8255e0 devif_poll.c: inline the small or single caller function
reduce stack operations to lower CPU loading.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2026-01-02 00:04:16 +08:00
zhanghongyu
c481374fb8 devif_poll: only call the corresponding xxx_poll when there is data to be sent
reduce the execution consumption of irrelevant code

testing the TX rates of TCP and UDP based on the Infineon board can
increase them by 13%.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2026-01-02 00:04:16 +08:00
zhanghongyu
a0b847bf1b net/devif_callback: change flags type from uint16_t to uint32_t
increase the size of the flag to prepare for precise xxx_POLL.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2026-01-02 00:04:16 +08:00
wenquan1
5b52ab13c8 net/arp: support queue iob when arp_out failed
arp_out will replace the dev->d_iob to arp request if the iob destination
address is not exist in arp table, this mechanism cause this iob lost
result in first received ping no response or first synack retransmit.
to fix this bug, we queue the iob if arp_out failed, allocate a new
iob to send arp request, after the arp request completed, then we retry
send the queue iob packet.

Signed-off-by: wenquan1 <wenquan1@xiaomi.com>
2026-01-01 17:03:29 +08:00
wenquan1
559c6855f3 net/ipv4: Drop ipv4 packet total length bigger than the actual transmitted data
Derived from RFC 791 s3.1 p13 Internet Header Format.

Signed-off-by: wenquan1 <wenquan1@xiaomi.com>
2026-01-01 16:55:52 +08:00
wenquan1
424a924f65 net/ipv6: Drop IP packet shorter than length in IP header
If the length of received ip packet is shorter than length in ip header, drop it.

Signed-off-by: wenquan1 <wenquan1@xiaomi.com>
2025-12-30 11:28:38 +08:00
wenquan1
c0fa2cae3d net/tcp: fix conn->work use after free in worker queue list
in multi-core cpu, tcp_free and tcp_timer_expiry->tcp_timer will work in parallel, after tcp_free call work_cancle, tcp->timer will call tcp_update_timer to re-add work to worker queue, then tcp_free free conn, in this condition, it will result use after free.

Signed-off-by: wenquan1 <wenquan1@xiaomi.com>
2025-12-29 22:42:49 +08:00
zhanghongyu
6addf24fa2 net/tcp: replace TCP_CLOSE with TCP_ABORT
since we added TCP_TXCLOSE and TCP_RXCLOSE, only RST-like exception
flows now trigger TCP_CLOSE events, so replace the remaining
TCP_CLOSE with TCP_ABORT.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2025-12-29 19:22:23 +08:00
zhanghongyu
fa47ab7bd2 net/tcp: add TCP_RXCLOSE to handle rx is shutdown
notify the local waiting recv process; otherwise, after the peer TX
is closed, the wait of the recv process will continue to wait.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2025-12-29 19:22:23 +08:00
zhanghongyu
2ad01e2aab net/tcp: support recv packet in the TCP_FIN_WAIT_1/2 state
shutdown should send TCP_FIN packet.

close should send TCP_RST packet when the data in readahead has not been
                                 read and NEW_DATA has arrived.
             send TCP_FIN packet when in other cases.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2025-12-29 19:22:23 +08:00
gaohedong
8638e9ce43 net/devif: fix poll issue when ifdown
When the interface is in a down state, it triggers a poll busy loop issue.

Signed-off-by: gaohedong <gaohedong@xiaomi.com>
2025-12-29 19:18:55 +08:00
wenquan1
0891fa5cfb net/ipv4: Send ICMP Destination Unreachable for unknown protocol
According RFC1122 3.2.2.1, A host SHOULD generate Destination Unreachable messages with code: 2(Protocol Unreachable), when the designated transport protocol is not supported.

Signed-off-by: wenquan1 <wenquan1@xiaomi.com>
2025-12-29 19:15:57 +08:00
zhanghongyu
c8713a1b48 net: protect the older network cards driver's tx and rx process
Add netdev_lock in xxx_input and txavail to adapt to drivers that do not
use upperhalf.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2025-12-29 09:42:18 +08:00
zhanghongyu
02e7ed7cc4 net/can: replace net_lock with conn_lock and conn_lock_dev
Protect can resources through netdev_lock, conn_lock, and can_list_lock

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2025-12-29 09:42:18 +08:00
zhanghongyu
1d91a15820 net/icmp: replace net_lock with conn_lock and conn_lock_dev
Protect icmp resources through netdev_lock, conn_lock, and icmp_list_lock

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2025-12-29 09:42:18 +08:00
zhanghongyu
e431cb00ca net/pkt: replace net_lock with netdev_lock
protect PKT resources through netdev_lock, conn_lock, and pkt_list_lock

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2025-12-29 09:42:18 +08:00
zhanghongyu
9befb8ae4a net/udp: remove net_lock
protect UDP resources through netdev_lock, conn_lock, and udp_list_lock.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2025-12-29 09:42:18 +08:00
zhanghongyu
aba8cd4d86 net/net_initialize: remove the empty functions that are not needed
streamline the code structure

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2025-12-25 09:50:40 +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
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
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
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
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
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
Jukka Laitinen
ef827e88a7 net: Copy out also can cmsg data into the end of packet
This has been broken at some point. Just fix it by copying the can frame and
the cmsg data into IOB, and fix devif_poll to copy out the full data.

The can drivers expect to find the timeout timestamp in the end of the frame.

Signed-off-by: Jukka Laitinen <jukkax@ssrc.tii.ae>
2024-10-16 15:39:11 +08:00
wangchen
48ecb6f922 devif:fix issue about devif_callback being released wrongly,resulting in no access to it
Signed-off-by: wangchen <wangchen41@xiaomi.com>
2024-09-28 16:06:36 +08:00
Alin Jerpelea
67d02a45eb net: migrate to SPDX identifier
Most tools used for compliance and SBOM generation use SPDX identifiers
This change brings us a step closer to an easy SBOM generation.

Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>
2024-09-12 01:08:11 +08:00
daichuan
fe01d7c462 modify for offload checksum and add macro with tcp/icmp/icmpv6/igmp checksum
Signed-off-by: daichuan <daichuan@xiaomi.com>
2024-08-24 20:41:40 +08:00
zhanghongyu
d0aa42c2ca net/devif: devif_send supports negative offset
To enable the pkt_sendmsg interface to send packets containing L2 headers

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2024-07-14 13:20:14 -03:00
Zhe Weng
f7181676b7 net: Support IP packet filter
Add a firewall compatible with Linux's iptables and ip6tables, with chains at similar points in the packet processing path.

NIC ─> ipv[46]_input ┬> ipv[46]_forward ─> [FORWARD] ┬> devif_poll_out ─> NIC
                     │                               │
                     │          ┌>  tcp  ┐           │
                     │          ├>  udp  ┤           │
                     └> [INPUT] ┼> icmp  ┼> [OUTPUT] ┘
                                ├> icmp6 ┤
                                └>  ...  ┘

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2024-06-20 09:43:05 +08:00
Zhe Weng
f3b34c84c2 net/nat: Support IPv6 Masquerading (NAT66)
Notes:
1. This version of NAT66 is a stateful one like NAT44, corresponding to Linux's MASQUERADE target of ip6tables.  We can support stateless NAT66 & NPTv6 later by slightly modify the address & port selection logic (maybe just match the rules and skip the entry find).
2. We're using same flag `IFF_NAT` for both NAT44 & NAT66 to make control easier.  Which means, if we enable NAT, both NAT44 & NAT66 will be enabled.  If we don't want one of them, we can just disable that one in Kconfig.
3. Maybe we can accelerate the checksum adjustment by pre-calculate a difference of checksum, and apply it to each packet, instead of calling `net_chksum_adjust` each time.  Just a thought, maybe do it later.
4. IP fragment segments on NAT66 connections are not supported yet.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2024-04-11 22:23:29 +08:00
Petteri Aimonen
cb161940c2 udp: Add support for SO_TIMESTAMP
Adds support for timestamping received UDP packets, either in
hardware or in kernel. Builds on the existing support of SO_TIMESTAMP
for SocketCAN.

Implementation uses CLOCK_REALTIME for timestamping to match the
behavior of Linux. This could be made configurable in future if needed.
2023-11-18 03:10:29 -08:00
Zhe Weng
2b9633e652 net: Support multiple IPv6 address per netdev
Note that user-space related code, like procfs and lifreq related ioctl commands, are not touched in this commit.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-11-07 19:30:36 +08:00
zhanghongyu
114b8323d6 devif_callback: modify the code logic to conform to the comment
The previous logic will caused some tcp flow errors.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-09-14 18:21:32 +08:00
Zhe Weng
d44e19d115 mm/iob: Add support for increasing length in iob_update_pktlen
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-08-22 16:34:21 +09:00
xucheng5
e8a2df4f80 devif/devif_poll : d_len must positive before invoke callback
Signed-off-by: xucheng5 <xucheng5@xiaomi.com>
2023-08-21 13:04:15 +08:00
chao an
6ee9ec7656 build: add initial cmake build system
1. Update all CMakeLists.txt to adapt to new layout
2. Fix cmake build break
3. Update all new file license
4. Fully compatible with current compilation environment(use configure.sh or cmake as you choose)

------------------

How to test

From within nuttx/. Configure:

cmake -B build -DBOARD_CONFIG=sim/nsh -GNinja
cmake -B build -DBOARD_CONFIG=sim:nsh -GNinja
cmake -B build -DBOARD_CONFIG=sabre-6quad/smp -GNinja
cmake -B build -DBOARD_CONFIG=lm3s6965-ek/qemu-flat -GNinja

(or full path in custom board) :
cmake -B build -DBOARD_CONFIG=$PWD/boards/sim/sim/sim/configs/nsh -GNinja

This uses ninja generator (install with sudo apt install ninja-build). To build:

$ cmake --build build

menuconfig:

$ cmake --build build -t menuconfig

--------------------------

2. cmake/build: reformat the cmake style by cmake-format

https://github.com/cheshirekow/cmake_format

$ pip install cmakelang

$ for i in `find -name CMakeLists.txt`;do cmake-format $i -o $i;done
$ for i in `find -name *\.cmake`;do cmake-format $i -o $i;done

Co-authored-by: Matias N <matias@protobits.dev>
Signed-off-by: chao an <anchao@xiaomi.com>
2023-07-08 13:50:48 +08:00
Fotis Panagiotopoulos
3c54d82d81 net: Fix task block when devif_send fails.
When a task needs to send data, a callback is allocated and the
transmission is happening in a worker task through devif_send.
Synchronization between the two tasks (sender & worker) is
achieved by a semaphore.

If devif_send fails, this semaphore was never posted, leaving
the sending task blocked indefinitely. This commit fixes this
by checking the return code of netif_send, and posting this
semaphore in case of failure.

Polling then stops, and execution is resumed on the sending
task.
2023-06-01 17:05:54 +08:00
Xiang Xiao
7990f90915 Indent the define statement by two spaces
follow the code style convention

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-05-21 09:52:08 -03:00
wangchen
2e6d0815b2 nuttx/net:Support to PMTUD
RFC 1191
When a router is unable to forward a datagram because it exceeds the
   MTU of the next-hop network and its Don't Fragment bit is set, the
   router is required to return an ICMP Destination Unreachable message
   to the source of the datagram, with the Code indicating
   "fragmentation needed and DF set".  To support the Path MTU Discovery
   technique specified in this memo, the router MUST include the MTU of
   that next-hop network in the low-order 16 bits of the ICMP header
   field that is labelled "unused" in the ICMP specification [7].  The
   high-order 16 bits remain unused, and MUST be set to zero.  Thus, the
   message has the following format:

       0                   1                   2                   3
       0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      |   Type = 3    |   Code = 4    |           Checksum            |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      |           unused = 0          |         Next-Hop MTU          |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      |      Internet Header + 64 bits of Original Datagram Data      |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
RFC 1185
Packet Too Big Message

       0                   1                   2                   3
       0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      |     Type      |     Code      |          Checksum             |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      |                             MTU                               |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      |                    As much of invoking packet                 |
      +               as will fit without the ICMPv6 packet           +
      |                       exceeding 576 octets                    |

   IPv6 Fields:

   Destination Address

                  Copied from the Source Address field of the invoking
                  packet.

   ICMPv6 Fields:

   Type           2

   Code           0

   MTU            The Maximum Transmission Unit of the next-hop link.

   Description

   A Packet Too Big MUST be sent by a router in response to a packet
   that it cannot forward because the packet is larger than the MTU of
   the outgoing link.  The information in this message is used as part
   of the Path MTU Discovery process [RFC-1191].

Signed-off-by: wangchen <wangchen41@xiaomi.com>
2023-05-12 10:21:52 -03:00
Zhe Weng
0e018308a3 net/pkt: Add readahead queue for pkt, call input for tx on sim
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-03-08 23:09:25 +02:00