Commit Graph

165 Commits

Author SHA1 Message Date
zhanghongyu 5b24917bb9 usb_cdcmbim: add mbim device driver
./build.sh sim:usbdev -j12
sudo gdb nuttx/nuttx -ex "source nuttx/tools/gdb/__init__.py"

below command to create mbim NIC on host
nsh> conn 3

NuttX's MBIM device implementation adds an additional MBIM network
card to the NuttX system, which can debug the data communication with
the host, but this network card is unnecessary and needs to be removed
when the business actually uses this driver, And the cdcncm_receive
method needs to be re-implemented.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2024-08-22 01:56:26 +08: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
liqinhui 05b101134a net:Support jumbo frame prealloc the iob for the ICMP/UDP/TCP.
For the ICMP, UDP and TCP, pre-alloc an iob for a jumbo frame.

Signed-off-by: liqinhui <liqinhui@xiaomi.com>
2024-06-02 09:31:37 -03:00
meijian 93beeeeab0 [tcp/udp] fix port generation not in range
(port % max + min)may overflow uint16

Signed-off-by: meijian <meijian@xiaomi.com>
2024-04-09 23:35:55 +08:00
wangchen b446a002db net:add customizable default max & min port
add customizable default max & min port

Signed-off-by: wangchen <wangchen41@xiaomi.com>
2024-04-09 23:35:55 +08:00
Yanfeng Liu 3bd35487f0 docs/comments: add simple document and fix typo
This patch adds simple document for the shared memory file system.
with typos fix in a other places.

Signed-off-by: Yanfeng Liu <yfliu2008@qq.com>
2024-03-03 01:55:07 +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
Alan Carvalho de Assis 4741ef7ca7 net: Fix RNDIS compilation error
The minimum value to CONFIG_NET_LL_GUARDSIZE work
with USB RNDIS support is 50.
2023-10-16 08:55:21 +08:00
Xiang Xiao 90f8315432 arch: Remove up_netinitialize
since this api change to xxx_netinitialize

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-08-20 14:33:17 +03:00
Zhe Weng 1072b5b564 net: Limit max value for Send/Recv bufsize
There're some apps trying to set too large SO_SNDBUF and SO_RCVBUF, which may use all IOBs in one socket and block all other network traffic.

Note:
Linux silently limits SO_SNDBUF to be less than `sysctl_wmem_max`, so we can also do this limit without returning any error.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-07-05 13:57:08 +08:00
Michael Jung 2e27698d6c SLIP: Switch to poll based design
This is a refactored version of the SLIP network driver.  Updates
include:

1. The original design started two kernel threads per SLIP device.
   The refactored version uses file_poll to essentially be driven
   by the UART RX and TX interrupts and pushes work to the low
   priority work queue.

2. The SLIP byte un-/stuffing is more efficient now, using memcpy
   instead of handling each byte individually.

3. The switch of the old SLIP driver to IOBs caused buffer overwrites
   if packets were sent that would not fit into a single IOB.  This is
   fixed now.

Signed-off-by: Michael Jung <michael.jung@secore.ly>
2023-05-26 19:57:57 -03:00
chao an 2eb9abc3d8 net/can: fix can mssage corruption if enable NET_TIMESTAMP
Timestamp location in can message has changed,
In the original logic timestamp is saved at the end of the data segment:

io_data
   -------------------------------------------------
   |         CAN message            |  Time Stamp  |
   -------------------------------------------------
   |<---------------     io_len   ---------------->|

In the new structure timestamps will reuse NET_LL_GUARDSIZE to isolate CAN messages:
io_data       io_offset
   -------------------------------------------------
   |  Time Stamp  |         CAN message            |
   -------------------------------------------------
                  |<--------    io_len   --------->|

This PR will:
1. Increase NET_LL_GUARDSIZE to 16 (sizeof(struct timeval)) if NET_CAN && NET_TIMESTAMP are enabled
2. Apply timestamp to adapt to the new structure

Signed-off-by: chao an <anchao@xiaomi.com>
2023-04-27 00:30:58 +08:00
Fotis Panagiotopoulos b6eb3c828c Removed obsolete option NET_ALLOC_CONNS. 2023-02-20 09:06:46 +08:00
luojun1234 ff3733b5b5 Support fragmentation and reassembly
Signed-off-by: luojun1 <luojun1@xiaomi.com>
2023-01-17 14:01:37 +08:00
Zhe Weng cbe4cb2056 net: Add set/getsockopt options compatible with iptables.
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2022-12-28 22:40:53 +08:00
chao an 34d2cde8a8 net/l2/l3/l4: add support of iob offload
1. Add new config CONFIG_NET_LL_GUARDSIZE to isolation of l2 stack,
   which will benefit l3(IP) layer for multi-MAC(l2) implementation,
   especially in some NICs such as celluler net driver.

new configuration options: CONFIG_NET_LL_GUARDSIZE

CONFIG_NET_LL_GUARDSIZE will reserved l2 buffer header size of
network buffer to isolate the L2/L3 (MAC/IP) data on network layer,
which will be beneficial to L3 network layer protocol transparent
transmission and forwarding

------------------------------------------------------------
Layout of frist iob entry:

        iob_data (aligned by CONFIG_IOB_ALIGNMENT)
            |
            |                  io_offset(CONFIG_NET_LL_GUARDSIZE)
            |                                |
            -------------------------------------------------
      iob   |            Reserved            |    io_len    |
            -------------------------------------------------

-------------------------------------------------------------
Layout of different NICs implementation:

        iob_data (aligned by CONFIG_IOB_ALIGNMENT)
            |
            |                 io_offset(CONFIG_NET_LL_GUARDSIZE)
            |                                |
            -------------------------------------------------
 Ethernet   |       Reserved    | ETH_HDRLEN |    io_len    |
            ---------------------------------|---------------
 8021Q      |   Reserved  | ETH_8021Q_HDRLEN |    io_len    |
            ---------------------------------|---------------
 ipforward  |            Reserved            |    io_len    |
            -------------------------------------------------

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

2. Support iob offload to l2 driver to avoid unnecessary memory copy

Support send/receive iob vectors directly between the NICs and l3/l4
stack to avoid unnecessary memory copies, especially on hardware that
supports Scatter/gather, which can greatly improve performance.

new interface to support iob offload:

  ------------------------------------------
  |    IOB version     |     original      |
  |----------------------------------------|
  |  devif_iob_poll()  |   devif_poll()    |
  |       ...          |       ...         |
  ------------------------------------------

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

1> NIC hardware support Scatter/gather transfer

TX:

                tcp_poll()/udp_poll()/pkt_poll()/...(l3|l4)
                           /              \
                          /                \
devif_poll_[l3|l4]_connections()     devif_iob_send() (nocopy:udp/icmp/...)
           /                                   \      (copy:tcp)
          /                                     \
  devif_iob_poll("NIC"_txpoll)                callback() // "NIC"_txpoll
                                                  |
                            dev->d_iob:           |
                                                ---------------         ---------------
                             io_data       iob1 |  |          |    iob3 |  |          |
                                    \           ---------------         ---------------
                                  ---------------  |       --------------- |
                             iob0 |  |          |  |  iob2 |  |          | |
                                  ---------------  |       --------------- |
                                     \             |          /           /
                                        \          |       /           /
                                   ----------------------------------------------
                    NICs io vector |    |    |    |    |    |    |    |    |    |
                                   ----------------------------------------------

RX:

  [tcp|udp|icmp|...]ipv[4|6]_data_handler()(iob_concat/append to readahead)
                    |
                    |
      [tcp|udp|icmp|...]_ipv[4|6]_in()/...
                    |
                    |
          pkt/ipv[4/6]_input()/...
                    |
                    |
     NICs io vector receive(iov_base to each iobs)

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

2> CONFIG_IOB_BUFSIZE is greater than MTU:

TX:

"(CONFIG_IOB_BUFSIZE) > (MAX_NETDEV_PKTSIZE + CONFIG_NET_GUARDSIZE + CONFIG_NET_LL_GUARDSIZE)"

                tcp_poll()/udp_poll()/pkt_poll()/...(l3|l4)
                           /              \
                          /                \
devif_poll_[l3|l4]_connections()     devif_iob_send() (nocopy:udp/icmp/...)
           /                                   \      (copy:tcp)
          /                                     \
  devif_iob_poll("NIC"_txpoll)                callback() // "NIC"_txpoll
                                                  |
                                             "NIC"_send()
                          (dev->d_iob->io_data[CONFIG_NET_LL_GUARDSIZE - NET_LL_HDRLEN(dev)])

RX:

  [tcp|udp|icmp|...]ipv[4|6]_data_handler()(iob_concat/append to readahead)
                    |
                    |
      [tcp|udp|icmp|...]_ipv[4|6]_in()/...
                    |
                    |
          pkt/ipv[4/6]_input()/...
                    |
                    |
     NICs io vector receive(iov_base to io_data)

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

3> Compatible with all old flat buffer NICs

TX:
                tcp_poll()/udp_poll()/pkt_poll()/...(l3|l4)
                           /              \
                          /                \
devif_poll_[l3|l4]_connections()     devif_iob_send() (nocopy:udp/icmp/...)
           /                                   \      (copy:tcp)
          /                                     \
  devif_iob_poll(devif_poll_callback())  devif_poll_callback() /* new interface, gather iobs to flat buffer */
       /                                           \
      /                                             \
 devif_poll("NIC"_txpoll)                     "NIC"_send()(dev->d_buf)

RX:

  [tcp|udp|icmp|...]ipv[4|6]_data_handler()(iob_concat/append to readahead)
                    |
                    |
      [tcp|udp|icmp|...]_ipv[4|6]_in()/...
                    |
                    |
               netdev_input()  /* new interface, Scatter/gather flat/iob buffer */
                    |
                    |
          pkt/ipv[4|6]_input()/...
                    |
                    |
    NICs io vector receive(Orignal flat buffer)

3. Iperf passthrough on NuttX simulator:

  -------------------------------------------------
  |  Protocol      | Server | Client |            |
  |-----------------------------------------------|
  |  TCP           |  813   |   834  |  Mbits/sec |
  |  TCP(Offload)  | 1720   |  1100  |  Mbits/sec |
  |  UDP           |   22   |   757  |  Mbits/sec |
  |  UDP(Offload)  |   25   |  1250  |  Mbits/sec |
  -------------------------------------------------

Signed-off-by: chao an <anchao@xiaomi.com>
2022-12-03 11:47:04 +08:00
Zhe Weng b595430578 net: add basic NAT workflow
Add basic functions for NAT (NAPT), remaining some logic unimplemented (UDP, ICMP, port assignment, etc). NAT for TCP can work now (unless port conflicts).
Outbound: LAN ->  Forward  ->  NAT(only if targeting at WAN)  -> WAN
Inbound:  WAN ->  NAT(only from WAN, change dest) -> Forward  -> LAN

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2022-11-11 14:36:55 +08:00
luojun1 ec4af00538 Add Cellular link layer support
1.Add cellular link layer enum definition and register flow
2.Add ioctl flow to set cellular NICs parameters

Signed-off-by: luojun1 <luojun1@xiaomi.com>
Signed-off-by: chao an <anchao@xiaomi.com>
2022-10-15 18:34:07 +08:00
Denis Tolstov e937cfcbce net/slip: Rename and clarify orphaned Kconfig options 2022-07-20 13:17:09 +08:00
JacobCrabill 3ddc019f8e net: Fix typos, update comments in Kconfigs 2022-05-06 08:54:58 +02:00
Alin Jerpelea 990cd877bc drivers: net: exclude BSD components from build
Unless ALLOW_BSD_COMPONENTS is enabled support will not be built

Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>
2022-02-24 22:48:47 +08:00
chao.an 581b67ade3 net: add config to support allocate connect dynamically
add config CONFIG_NET_ALLOC_CONNS to support allocate connect.
Use this feature if the number of connections can not be determined at
compile time. When enabled the stack will be compiled without the static
pre-allocate connection list and all connection instances will be dynamically
allocated from heap at run time.

Signed-off-by: chao.an <anchao@xiaomi.com>
2022-01-01 20:40:02 +08:00
chao.an 7d4502aca6 net/socket: add SO_SNDBUF support
Signed-off-by: chao.an <anchao@xiaomi.com>
2021-07-20 20:24:58 -07:00
chao.an b901f22c27 net/socket: add SO_RCVBUF support
Signed-off-by: chao.an <anchao@xiaomi.com>
2021-07-06 01:44:55 -05:00
ligd 70442d1f9d net/socket_rpmsg: add net socket rpmsg support
Change-Id: Ie23ee4c0052cf2fc66972ea9bc5f11c070fbcf8a
Signed-off-by: chao.an <anchao@xiaomi.com>
2021-03-07 01:45:51 -08:00
Brennan Ashton 68b526b335 tcp: Remove incomplete support for TCP reassembly 2020-12-09 07:25:26 -08:00
David Sidrane e254083a7d net:Add ARCH_PHY_POLLED option 2020-10-01 15:28:51 +08:00
Kazuya Hioki 822061a3d0 net: Fix dupulicated NET_USRSOCK in Kconfig
Reviewed-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
Signed-off-by: Kazuya Hioki <Kazuya.Hioki@sony.com>
2020-07-19 20:05:50 -07:00
Peter van der Perk 55d9e5f7af net: Add SocketCAN support 2020-06-15 08:07:19 -06:00
Alan C. Assis 089a633c76 Fix wrong space instead of TAB 2020-06-15 07:13:21 -06:00
Alan C. Assis 7609b67496 Fix issues reported on PR #1233 2020-06-15 07:13:21 -06:00
Xiang Xiao c85fe67ebc net/loopback: Move g_lo_* global variable to libc/net/
so netdb could reuse these global variable directly

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: Iaa26ddbdaf416f64d43c6e8888a14bbe0c3405eb
2020-03-30 09:47:28 -06:00
YAMAMOTO Takashi f8077022bd Introduce CONFIG_DEFAULT_TASK_STACKSIZE
* The appropriate size of stack varies among archs.
  E.g. for 64-bit sim, 2048 is way too small, especially when the task
  happens to use host OS functionalities.
  I plan to allow an arch provide its own default.

* I plan to use this to replace hardcoded "STACKSIZE = 2048" in APPDIR.
2020-03-26 22:30:13 -05:00
Nathan Hartman a5e643b0cd Fix typos in comments and documentation. 2020-03-16 20:01:11 -06:00
YAMAMOTO Takashi 213c81aebd Fix a typo in kconfig text 2020-03-12 11:38:18 +01:00
Gregory Nutt 3c0b49448a Network Loopback Driver: A configuration option to control packet size.
Historically, the loopback driver used the largest packet size of all enabled link layer protocols.  This permitted packets to be forward via the loopbak device with no major loss of performance.  However, in experimenting with configurations where no other link layer protocols were enabled, this means the loopback packet size was set to the smallest possible size, to the SLIP minimum of 296 bytes.  This resulted in terrible loopback performance.

    This commit adds an option to increase the loopback packet size with the option CONFIG_NET_LOOPBACK_PACKETSIZE.

    The loopback driver packet buffer should be quite large.  The larger the loopback packet buffer, the better will be TCP performance of the loopback transfers.  The Linux loopback device historically used packet buffers of size 16Kb, but that was increased in recent Linux versions to 64Kb.  Those sizes may be excessive for resource constrained MCUs, however.

    The network still enforces the lower limit that is the maximum packet size of all enabled link layer protocols.  But this new option permits the loopback packet size to be increased from that.

    * net/Kconfig:  Adds CONFIG_NET_LOOPBACK_PKTSIZE option
    * include/nuttx/net/netconfig.h:  Assures that the packet size that is used is at least as large as the largest packet size of other link layer protocols.
    * drivers/net/loopback.c:  Use that larger packet size.
    * boards/sim/sim/sim/configs/tcploop/defconfig:  Set the loopback packet size to 1500
2020-02-10 22:17:32 -03:00
Gregory Nutt 10721c0826 Kconfig: Move the ARCH_PHY_INTERRUPT option to net/Kconfig and make it
unconditionally selectable.
2020-02-09 00:55:41 +00:00
Xiang Xiao c5b1554d84 Remove NETDEV_LOOPBACK option, NET_LOOPBACK is enough 2020-02-02 08:25:06 -06:00
Xiang Xiao 2d7c072723 Remove duplicated NET_SLIP option from drivers/net/Kconfig 2020-02-02 08:24:50 -06:00
Xiang Xiao 346336bb9e Make the read ahead buffer unselectable
Here is the email loop talk about why it is better to remove the option:
https://groups.google.com/forum/#!topic/nuttx/AaNkS7oU6R0

Change-Id: Ib66c037752149ad4b2787ef447f966c77aa12aad
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2020-01-11 08:24:49 -06:00
Gregory Nutt 9bdde04636 net/Kconfig: Ethernet packet buffer size cannot be permitted to go below 1294 is IPv6 is selected. 2019-08-31 09:08:32 -06:00
Nathan Hartman 68d43d3679 Fix typos. 2019-08-04 14:50:28 -06:00
Xiang Xiao 16850297f3 libs/unistd and other affected files: Hostname support no longer depends on CONFIG_NET since the host name is also useful in the non-network environment. CONFIG_NET_HOSTNAME changed to CONFIG_LIB_HOSTNAME. 2019-01-27 06:56:16 -06:00
Gregory Nutt 09f4dee6bc All network drivers! Change pre-processor logic that selects the high priority work queue or gives preferential treatment to the high priority work. All network logic must run on the low priority work queue! Or suffer the consequences. 2018-11-21 07:57:26 -06:00
Xiang Xiao 77098f8736 Move NETDEV_LATEINIT from drivers/net/Kconfig to net/Kconfig so that we can select NETDEV_LATEINIT without enabling NETDEVICES since the net driver in arch folder may need to initialize later too. 2018-11-12 06:36:26 -06:00
Gregory Nutt 6d93658ff8 Add new configuratin CONFIG_NET_MCASTGROUP. This option is selected automatically if either CONFIG_NET_IGMP or CONFIG_NET_MLD are selected. Most conditional logic based on CONFIG_NET_IGMP replaced with conditioning on CONFIG_NET_MCASTGROUP. 2018-10-31 15:03:51 -06:00
Gregory Nutt dde1e89b8c net/mld: Add basic build structure for Multicast Listener Discovery (MLD). No real MLD logic yet. Only a few hooks to capture and dispatch MLD ICMPv6 packets. 2018-10-31 14:10:19 -06:00
Gregory Nutt a85f0e4cd5 networking: Update some comments to correct the naming used for the link layer. 2018-10-20 06:35:39 -06:00
Xiang Xiao 49548da297 net/Kconfig: Uncomment the prompt of NET_SLIP_PKTSIZE 2018-08-26 14:28:35 -06:00
Gregory Nutt 4a724b1f3c net/: Remove all references to CONFIG_NET_USER_DEVFMT. That feature is now unconditionally enabled. This was done because (1) the feature does not require very much additional memory, and (2) it causes confusion in the configuration due to the additional complexity. And network drivers that fail to zero the device structure interface name field (d_ifname) because calling netdev_register() will, however, get a nasty surprise. 2018-08-14 08:01:52 -06:00