Commit Graph

82 Commits

Author SHA1 Message Date
yinshengkai 9852428953 fs: procfs add poll support
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2023-12-26 19:23:13 -08:00
Zhe Weng 7f421a46ca net/procfs: Support printing multiple IPv6 address per netdev
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-11-07 19:30:36 +08:00
xuxin19 7a9d3c03e4 cmake:complete missing changes during reforming for net
Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2023-09-13 21:51:20 +08:00
Petro Karashchenko 1b0baa8337 nuttx: use lib_free for memory de-allocation after strdup or asprintf
The memory allocated with strdup and asprintf is done via lib_malloc
so we need to use lib_free to deallocate memory otherwise the assertion
"Free memory from the wrong heap" is hit with flat mode and user separated
heap enabled mode.

Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-08-08 11:58:29 -03:00
Zhe Weng 194d0cdec9 net/procfs: Simplify logic for tcp/udp stats
By:
1. Take out net_ip_binding_laddr/raddr macro
2. INET6_ADDRSTRLEN is long enough for all address buffer and no need to
   add 0 to the end of buffer since inet_ntop will do so

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-08-07 08:08:37 -07:00
Zhe Weng 075eb6a6d2 net/udp: Change conn->readahead to I/O buffer chain
When using IOB queue to store readahead data, we use one IOB for each
UDP packet. Then if the packets are very small, like 10Bytes per packet,
we'll use ~1600 IOBs just for 16KB recv buffer size, which is wasteful
and dangerous. So change conn->readahead to a single IOB chain like TCP.

Benefits:
- Using memory and IOBs more efficiently (small packets are common in
  UDP)

Side effects:
- UDP recv buffer size may count the overhead
- A little bit drop in performance (<1%, more seek & copy)

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-07-18 10:51:45 +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
Xiang Xiao 74e2b75857 net: Simplify the tcp/udp existence check
Replace defined(CONFIG_NET_TCP) && !defined(CONFIG_NET_TCP_NO_STACK) with NET_TCP_HAVE_STACK
Replace defined(CONFIG_NET_UDP) && !defined(CONFIG_NET_UDP_NO_STACK) with NET_UDP_HAVE_STACK

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-05-03 17:40:00 +03:00
wangchen d197ca9967 net/procfs: Support to show MTU in netdev statistics
Usage:
ifconfig (interfacename)
example:
ifconfig eth0
eth0	Link encap:Ethernet HWaddr 42:d3:59:ad:5a:2f at RUNNING mtu 1500
	inet addr:10.0.1.2 DRaddr:10.0.1.1 Mask:255.255.255.0
	inet6 addr: fe80::40d3:59ff:fead:5a2f/64
	inet6 DRaddr: ::/64

Signed-off-by: wangchen <wangchen41@xiaomi.com>
2023-04-28 09:45:21 +08:00
Xiang Xiao c6d210289f procfs: remove procfs_ from procfs_operations variables
to aglin the naming style with other implementation

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-04-22 03:33:50 -04:00
Xiang Xiao 149cafe450 procfs: Add g_ prefix to all procfs_operations
to conform the coding style

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-04-22 03:33:50 -04:00
chao an 4a8cd8ca0c net/procfs: fix visual studio Compiler Error C2057
D:\archer\code\nuttx\net\procfs\net_tcp.c(63,15): error C2057: expected constant expression

Compiler error C2057:
The context requires a constant expression, an expression whose value is known at compile time.

Reference:
https://learn.microsoft.com/en-us/cpp/error-messages/compiler-errors-1/compiler-error-c2057?view=msvc-170

Signed-off-by: chao an <anchao@xiaomi.com>
2023-02-09 20:11:55 +08:00
chao an 3a0fdb019d nuttx: replace all ARRAY_SIZE()/ARRAYSIZE() to nitems()
Signed-off-by: chao an <anchao@xiaomi.com>
2023-02-09 20:05:44 +08:00
Xiang Xiao fd0d6a9bf5 compiler.h: Add _ between format|printf|syslog|scanf|strftime and like
align with other macro naming style

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-12-21 01:05:19 +02:00
chao an 98724477e7 net/procfs: fix runtime error AddressSanitizer(global-buffer-overflow)
NuttShell (NSH) NuttX-10.3.0
ap> ifconfig
=================================================================
Program received signal SIGSEGV, Segmentation fault.
==3920365==ERROR: AddressSanitizer: global-buffer-overflow on address 0x57fb4f2a at pc 0x57177067 bp 0xf1ffebb8 sp 0xf1ffeba8
READ of size 1 at 0x57fb4f2a thread T0

...................
| #10 0xf7ac4339 in __asan::__asan_report_load1 (addr=1476087594) at ../../../../../src/libsanitizer/asan/asan_rtl.cpp:117
| #11 0x57177067 in strncmp (cs=0x57fb4f2a "", ct=0x582d36e0 "stat", nb=4) at string/lib_strncmp.c:40
| #12 0x57f3b467 in netprocfs_opendir (relpath=0x57fb4f26 "net", dir=0xf1ffed80) at procfs/net_procfs.c:398
| #13 0x572b3ae1 in procfs_opendir (mountpt=0xf4602c20, relpath=0x57fb4f26 "net", dir=0xf1ffed80) at procfs/fs_procfs.c:625
| #14 0x572879ff in open_mountpoint (inode=0xf4602c20, relpath=0x57fb4f26 "net", dir=0xf1ffed80) at vfs/fs_dir.c:127
...................

Signed-off-by: chao an <anchao@xiaomi.com>
2022-09-27 09:41:55 +08:00
chao an f286012c0d net/procfs: disable tcp/udp proc node if no stack available
Signed-off-by: chao an <anchao@xiaomi.com>
2022-09-19 15:45:19 +08:00
chao an d10cd8d585 net/procfs: add udp profs support
add proc node /proc/net/udp to show the active udp connections from procfs

nuttx style:

server> cat /proc/net/udp
UDP sl     local_address          remote_address     flg   txsz   rxsz  (IPv4)
  1:          0.0.0.0:  5285    192.168.31.22:  7779   9      0   1041
  2:          0.0.0.0:  5286    192.168.31.22:  7779   9      0   1041
  3:          0.0.0.0:  5287    192.168.31.22:  7779   9      0   1041

linux kernel:
https://www.kernel.org/doc/Documentation/networking/proc_net_tcp.txt

Signed-off-by: chao an <anchao@xiaomi.com>
2022-09-09 19:33:46 +08:00
chao an 7190e56a14 net/procfs: add tcp profs support
add proc node /proc/net/tcp to show the active tcp connections from procfs

nuttx style:

server> cat /proc/net/tcp
TCP sl  st flg ref tmr uack nrt   rxsz local_address           remote_address
     1: 04  61   1  12    0   0   1024          0.0.0.0:4855      192.168.31.22:5001
     2: 04  61   1  12    0   0   1024          0.0.0.0:4856      192.168.31.22:5001
     3: 04  61   1   9    0   0      0                      :::4853   fe80::b27b:25ff:fe28:4011:8789
     4: 04  61   1   3    3   0      0                      :::4854   fe80::b27b:25ff:fe28:4011:8789

linux kernel:
https://www.kernel.org/doc/Documentation/networking/proc_net_tcp.txt

Signed-off-by: chao an <anchao@xiaomi.com>
2022-09-09 19:33:46 +08:00
chao an b6e76966b9 net/procfs: interface index should begin from 1
Signed-off-by: chao an <anchao@xiaomi.com>
2022-09-08 18:09:43 +09:00
chao an 4068b2eccc net/procfs: add entry mapping table
add entry mapping table to simplify new component registration

Signed-off-by: chao an <anchao@xiaomi.com>
2022-09-08 09:03:34 +08:00
Huang Qi e4e3208180 Replace all strncpy with strlcpy for safety
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2022-08-25 13:38:36 +08:00
Jiuzhu Dong fe17f747a7 fs/directory: move private directory information to filesystem
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
2022-08-09 23:30:01 +08:00
Jiuzhu Dong 90db4daca9 fs/directory: update readdir interface for all filesystem
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
2022-08-09 23:30:01 +08:00
Peter van der Perk 013a562478 Net thread-safe ntoa functions
Apply suggestions from code review

Co-authored-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2022-08-02 21:04:19 +08:00
Xiang Xiao 2166c98809 Add printflike and scanflike to all printf/scanf like functions
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-07-18 14:14:36 +03:00
Xiang Xiao a262eebe34 libc: Rename match to fnmatch
specified here:
https://pubs.opengroup.org/onlinepubs/007904875/functions/fnmatch.html

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2021-08-02 08:23:35 -03:00
Xiang Xiao 2e54df0f35 Don't include assert.h from public header file
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2021-06-03 08:36:03 -07:00
Gustavo Henrique Nihei 330eff36d7 sourcefiles: Fix relative path in file header 2021-03-09 23:18:28 +08:00
Alin Jerpelea 37d5c1b0d9 net: Author Gregory Nutt: update licenses to Apache
Gregory Nutt has submitted the SGA and we can migrate the licenses
 to Apache.

Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>
2021-02-20 00:38:18 -08:00
Alin Jerpelea 7dc7ef45f1 net: nxstyle fixes
Nxstyle fixes to pass CI.

Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>
2021-02-20 00:38:18 -08:00
chao.an dbd6e9be16 net/procfs: handle opendir("/proc/net/") correctly
Change-Id: I092bade082ba673b30257add4f869ac5bfa55ca6
Signed-off-by: chao.an <anchao@xiaomi.com>
2020-12-03 05:56:35 -06:00
YAMAMOTO Takashi be76d43e25 net/procfs/netdev_statistics.c: Fix a printf format warning 2020-11-16 08:29:00 -08:00
YAMAMOTO Takashi ba34213222 net/procfs/netdev_statistics.c: Appease nxstyle 2020-11-16 05:46:53 -08:00
Xiang Xiao 2d7f58d165 net/procfs: Support chdir("/proc/net/") correctly
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: I47295019c6054c869545e33258ad3460896e851a
2020-08-03 21:00:18 +01:00
Xiang Xiao 9dff16e0e4 fix nxstyle warning
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: Ieaf325c899d1c349d64dfa15bddcc32afd1fce42
2020-07-10 21:30:02 +01:00
Xiang Xiao cde88cabcc Run codespell -w with the latest dictonary again
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2020-02-23 22:27:46 +01:00
Xiang Xiao 68951e8d72 Remove exra whitespace from files (#189)
* Remove multiple newlines at the end of files
* Remove the whitespace from the end of lines
2020-01-31 09:24:49 -06:00
Xiang Xiao f8bcd58be2 Fix format warn (#96)
* fix warning: format '%x' expects argument of type 'unsigned int', but argument 4 has type 'long unsigned int'
* fix warning: implicit declaration of function 'up_init_exidx'
2020-01-13 16:41:09 -06:00
Gregory Nutt cf5d17f795 tools/nxstyle: Added logic to parse section headers (#90)
* tools/nxstyle:  Added logic to parse section headers (like Included files, Pre-processor Definitions, etc.) and to assure that the section headers are correct for the file type.  Also (1) verify that #include appears only in the 'Included Files' section and that (2) #define only occurs in the Pre-processor definition section.

    Right now, there are several places where that rule is not followed.  I think most of these are acceptable so these failures only generate warnings, not errors.  The warning means that we need to go look at the offending #define or #include and decide if it is a acceptable usage or not.
2020-01-13 18:08:45 +00:00
patacongo 51cbc85535 net/: Run current nxstyle against all .c files under net/. Correct new problems identified by nxstyle. This is primarily a verification of the nxstyle changes (which all look good). (#89)
Co-authored-by: Gregory Nutt <gnutt@nuttx.org>
2020-01-12 21:17:29 +01:00
Xiang Xiao 6a3c2aded6 Fix wait loop and void cast (#24)
* Simplify EINTR/ECANCEL error handling

1. Add semaphore uninterruptible wait function
2 .Replace semaphore wait loop with a single uninterruptible wait
3. Replace all sem_xxx to nxsem_xxx

* Unify the void cast usage

1. Remove void cast for function because many place ignore the returned value witout cast
2. Replace void cast for variable with UNUSED macro
2020-01-02 10:54:43 -06:00
Gregory Nutt 3b275fcf4e net/: Run nxstyle against all C files. 2019-10-25 11:31:42 -06:00
Gregory Nutt 1346f29151 net/: Fix alignment and spacing problems found by tools/nxstyle. 2019-07-02 18:02:23 -06:00
Gregory Nutt f6b00e1966 tools/nxstyle.c: Fix logic error that prevent detecion of '/' and '/=' as operators. net/: Minor updates resulting from testing tools/nxstyle. 2019-03-11 12:48:39 -06:00
Gregory Nutt cacbe062ad Fix a new warning found in build tesing. 2018-12-01 17:27:32 -06:00
Gregory Nutt 41d5e31390 configs/stm32f429i-disco/highpri/defconfig and net/procfs/netdev_statistics.c: Eliminate some warnings found in build testing. 2018-11-25 18:42:39 -06:00
Gregory Nutt a588d64b45 net/procfs/netdev_statistics.c: Fix a error found in build testing. 2018-11-20 08:09:03 -06:00
Gregory Nutt 610c187e96 net/procfs/netdev_statistics.c: Eliminate warning: array subscript is above array bounds. 2018-11-11 14:28:15 -06:00
Gregory Nutt 62e4a41209 net/mld: Add reference counting on the group joins. If there are multiple joins from the same group on this, the don't really leave the group until the matching number of leaves happen. Also add to hooks for the router case: Keep track of the number members NOT on this host. Integrate this with the Leave logic to that the group structure can persist while there no non-local members of the group as well. 2018-11-06 14:46:03 -06:00
Gregory Nutt f58e7976df net/procfs: Add support to provide MLD stats at /proc/net/mld. net/mld: Fix a couple more bugs found in further MLD testing. 2018-11-06 10:42:53 -06:00