Commit Graph

2907 Commits

Author SHA1 Message Date
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
liqinhui
3f08f32486 net: allow icmpv6 and udp to find the dev by the ifindex with s_boundto.
In order to support the dhcpv6c.

Signed-off-by: liqinhui <liqinhui@xiaomi.com>
2023-10-11 23:34:01 +08:00
Xiang Xiao
21beb284bc net/usersock: Return -ENOSUPP directly if domain isn't equal to PF_INET/PF_INET6
regression by https://github.com/apache/nuttx/pull/9647

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-10-09 18:04:29 -04:00
liqinhui
8014f51cc1 net/local: Allow the local udp socketpair function to use the local_release_fifos interface.
Signed-off-by: liqinhui <liqinhui@xiaomi.com>
2023-09-27 19:28:02 +08:00
Petteri Aimonen
bedcc5fc04 Add CONFIG_NET_ICMPv6_ROUTER_LIFETIME
Allows setting the advertised route lifetime, and also to set
it to 0 for advertising only the prefix.

From RFC4861:

   A router might want to send Router Advertisements without advertising
   itself as a default router.  For instance, a router might advertise
   prefixes for stateless address autoconfiguration while not wishing to
   forward packets.  Such a router sets the Router Lifetime field in
   outgoing advertisements to zero.
2023-09-27 00:51:20 +08:00
ligd
00c0801743 local socket: fix accept used after free
==1729315==ERROR: AddressSanitizer: heap-use-after-free on address 0xf0501d60 at pc 0x032ffe43 bp 0xef4ed158 sp 0xef4ed148
READ of size 2 at 0xf0501d60 thread T0
    #0 0x32ffe42 in nxsem_wait semaphore/sem_wait.c:94
    #1 0x3548cf5 in _net_timedwait utils/net_lock.c:97
    #2 0x3548f48 in net_sem_timedwait utils/net_lock.c:236
    #3 0x3548f8c in net_sem_wait utils/net_lock.c:318
    #4 0x350124d in local_accept local/local_accept.c:246
    #5 0x3492719 in psock_accept socket/accept.c:149
    #6 0x3492bcc in accept4 socket/accept.c:280
    #7 0x662dc04 in accept net/lib_accept.c:50
    #8 0x55c81ab in kvdb_loop kvdb/server.c:415
    #9 0x55c860a in kvdbd_main kvdb/server.c:458
    #10 0x33d968b in nxtask_startup sched/task_startup.c:70
    #11 0x32ec039 in nxtask_start task/task_start.c:134
    #12 0x34109be in pre_start sim/sim_initialstate.c:52

0xf0501d60 is located 288 bytes inside of 420-byte region [0xf0501c40,0xf0501de4)
freed by thread T0 here:
    #0 0xf7aa6a3f in __interceptor_free ../../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:127
    #1 0x73aa06e in host_free sim/posix/sim_hostmemory.c:192
    #2 0x34131d6 in mm_free sim/sim_heap.c:230
    #3 0x3409388 in free umm_heap/umm_free.c:49
    #4 0x35631f3 in local_free local/local_conn.c:225
    #5 0x3563f75 in local_release local/local_release.c:129
    #6 0x34f5a32 in local_close local/local_sockif.c:785
    #7 0x3496ee8 in psock_close socket/net_close.c:102
    #8 0x36500bc in sock_file_close socket/socket.c:115
    #9 0x3635f6c in file_close vfs/fs_close.c:74
    #10 0x3632439 in nx_close_from_tcb inode/fs_files.c:670
    #11 0x36324f3 in nx_close inode/fs_files.c:697
    #12 0x3632557 in close inode/fs_files.c:735
    #13 0x55be289 in property_set_ kvdb/client.c:210
    #14 0x55c0309 in property_set_int32_ kvdb/common.c:226
    #15 0x55c03f5 in property_set_int32_oneway kvdb/common.c:236

Signed-off-by: ligd <liguiding1@xiaomi.com>
2023-09-24 10:42:35 +08:00
wanggang26
d827ee5ffc refine: set file mode when oflags contains O_CREAT
Signed-off-by: wanggang26 <wanggang26@xiaomi.com>
2023-09-23 15:20:51 +08:00
wanggang26
e930476b4b enable O_CLOEXEC explicit
Signed-off-by: wanggang26 <wanggang26@xiaomi.com>
2023-09-22 13:51:00 +08:00
SPRESENSE
a35ba1e7bc net: Create fallback option for usrsock
Changed implementation to use the Kernel network stack when
usrsock daemon returns an error.

This change allows the Kernel network stack to be used instead
of UsrSock when opening a Socket at a time when a VPN configured
with TUN is enabled.
2023-09-21 01:08:11 +08:00
SPRESENSE
011d45e956 net/usrsock: Can enable TCP/UDP IP stack with Usrsock enabled
Some use cases, such as VPN, use both the device's network
stack with the Usrsock daemon and the Kernel's network stack.
Therefore, remove NET_TCP_NO_STACK/NET_UDP_NO_STACK select
from Usrsock's Kconfig.
2023-09-21 01:08:11 +08:00
zhanghongyu
55d5006462 tcp_ofosegs: prepare iob to reset io_offset
The previous iob_trimhead added dev->iob->io_offset, so if the
input frame is not merged into the ofo segment, we need to reset
dev->iob->io_offset so that the subsequent tcp_send can properly
assemble packets.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-09-20 14:32:16 +08:00
zhanghongyu
1389a686ba tcp: fix coverity warning for tcp_timer
use after free when the number of retransmissions reached the maximum.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-09-19 09:37:20 +08:00
ligd
c9bc6b1ad5 rpmsg socket: add return value check.
Signed-off-by: ligd <liguiding1@xiaomi.com>
2023-09-19 09:33:30 +08:00
chao an
5026a96cfa nxstyle: cleanup UTF-8 Unicode to ASCII
Signed-off-by: chao an <anchao@xiaomi.com>
2023-09-18 11:54:17 -04:00
yintao
89329dff3b net/rpmsg: set conn->backlog=-1 only when socket listening
Signed-off-by: yintao <yintao@xiaomi.com>
2023-09-18 20:58:30 +08:00
Petro Karashchenko
c241644f08 net/can: add missing FAR specifier
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-09-16 14:17:47 +08:00
Petro Karashchenko
5bee23da07 net/can: Add FAR specifier and fix nxstyle issues
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-09-16 14:17:47 +08:00
Zhe Weng
33c3abb706 net/tcp: Stop monitor in tcp_free
We may just free some TCP connections before monitor stopped, e.g.
sacrificie a TCP conn in `tcp_alloc` will just call `tcp_free` and reuse
the connection.  But we noticed that the TCP monitor is not released in
`tcp_free` because it is mounted on `conn->connevents` instead of
`conn->sconn.list` while `tcp_free` only release the latter.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-09-14 22:55:10 +08:00
zhanghongyu
2c39cfefef psock_tcp_cansend: return EWOULDBLOCK when send buffer is full
with nonblocking sockets, POLLOUT is returned when the application
calls poll even if the send buffer is full

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-09-14 14:50:45 +03: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
7c422381ca net/tcp: Set SO_ERROR for poll error in setup
Normally, `SO_ERROR` for disconn events will be set by `tcp_poll_eventhandler`, but when the socket is closed before poll, we should also set the `SO_ERROR`.

On Linux, `tcp_poll` returns `EPOLLERR` event when `sk->sk_err` has value but doesn't let `poll` fail (doesn't set `errno`). https://github.com/torvalds/linux/blob/v6.5/net/ipv4/tcp.c#L594-L596
Note: `sk->sk_err` can be get by socket option `SO_ERROR` on Linux, so `POLLERR` will always be together with `SO_ERROR`.

Common libs like curl may try to read `SO_ERROR` on `POLLERR`.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-09-14 14:32:56 +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
chao an
8767a84e13 net/arp: arp should depends on MM_IOB
Implementation of arp depends on MM_IOB

Signed-off-by: chao an <anchao@xiaomi.com>
2023-09-12 16:24:52 +08:00
xucheng5
30bb3086be socketcan/recv : fixed recv filter not work in special case
can recv filter doesn't work when there is any CAN data already
buffered in a read-ahead buffer

Signed-off-by: xucheng5 <xucheng5@xiaomi.com>
2023-09-11 19:29:47 +08:00
wangming9
21c30f80af net/local: fix build error on CONFIG_DEBUG_OPTLEVEL="-O3"
Summary
The following compilation error occurs after configuring CONFIG_DEBUG_OPTLEVEL="-O3"
CC:  local/local_fifo.c In file included from local/local_fifo.c:25:
In function 'local_format_name',
    inlined from 'local_cs_name' at local/local_fifo.c:101:3,
    inlined from 'local_create_fifos' at local/local_fifo.c:431:3:
local/local_fifo.c:84:16: error: '%x' directive output may be truncated writing between 1 and 8 bytes into a region of size between 5 and 112 [-Werror=format-truncation=]
   84 |                CONFIG_NET_LOCAL_VFS_PATH "/%s%s%" PRIx32,
      |                ^~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: wangming9 <wangming9@xiaomi.com>
2023-09-09 17:08:23 +03:00
xucheng5
b756a7c3a9 socketcan : support error frame filter
add error mask for CAN_RAW_ERR_FILTER

Signed-off-by: xucheng5 <xucheng5@xiaomi.com>
2023-09-08 21:14:09 +03:00
zhangjun21
a5f133a15f MLD: add byte order conversion for ipv6 address printing
Signed-off-by: zhangjun21 <zhangjun21@xiaomi.com>
2023-09-09 00:23:35 +08:00
Bowen Wang
49dbe7e177 rpmsg_sockif: add recvlock for conn->sendsize in connect
conn->sendsize is used in rpmsg_socket_ept_cb() and
rpmsg_socket_connect_internal(), the connected event may be missed
as stated below:

1. in rpmsg_socket_connect_internal(), judge conn->sendsize == 0
   and prepare to wait sendsem;
2. interrupt by rptun thread, rpmsg_socket_ept_cb() is called to
   update conn->sendsize and post the sendsem, but the no one wait
   rx sem yet, so not post (see rpmsg_socket_post());
3. return to rpmsg_socket_connect_internal() to wait the sendsem, but
   has miss the connected event.

So add recvlock in rpmsg_socket_connect_internal() also.

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2023-09-09 00:17:36 +08:00
zhanghongyu
03265caa7a inet_sendto: correct error messages and remove the comment
Comment information and printing do not match the actual function.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-09-09 00:16:52 +08:00
Xiang Xiao
7f3a76c290 Replace strlen with sizeof for kconfig string
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-09-02 16:26:23 +03:00
zhanghongyu
3f927b63b7 tcp_input: update tx_unack before reorder_ofosegs
After the sack is enabled and the ofosegs has gap, tcp cannot update the
tx_unacked, so the peer received packets are retransmitted after the
timer timeout.
So update tx_unacked first.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-09-01 12:30:06 +03:00
chao an
7d1763a57c net/assert: remove all unnecessary check for psock/conn
Since inet/socket layer already contains sanity checks, so remove unnecessary lower half checks

Signed-off-by: chao an <anchao@xiaomi.com>
2023-08-30 20:36:49 +08:00
chao an
3cbf13dd1d net/can: correct the return value if unsupported socket type
Signed-off-by: chao an <anchao@xiaomi.com>
2023-08-30 12:27:41 +03:00
chao an
664927c86e mm/alloc: remove all unnecessary cast for alloc
Fix the minor style issue and remove unnecessary cast

Signed-off-by: chao an <anchao@xiaomi.com>
2023-08-30 14:34:20 +08:00
chao an
6340154f97 net/socket/bind: make sure that an address was provided
1. make sure that an address was provided on bind() call
2. correct the return value if bad socket handler

Signed-off-by: chao an <anchao@xiaomi.com>
2023-08-29 19:42:36 +08:00
chao an
baabf4bbf3 net/local: fix visual studio Compiler Error C2057
expected constant expression
The context requires a constant expression, an expression whose value is known at compile time.
The compiler must know the size of a type at compile time in order to allocate space for an instance of that type.

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-08-29 09:45:44 +08:00
zhanghongyu
32b1af3008 tcp_send_buffered: change Not connected message level from error to warning
Non-blocking sockets are almost never in the connected state when app try to
get result of connect success through poll, to avoid confusion because of
this error print, so downgrade the print level to warning.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-08-25 20:38:59 +03:00
wangchen
99ee94728a net:add IP_MULTICAST_IF & IPV6_MULTICAST_IF function implementation
refer to https://man7.org/linux/man-pages/man7/ip.7.html
IP_MULTICAST_IF (since Linux 1.2)
              Set the local device for a multicast socket.  The argument
              for setsockopt(2) is an ip_mreqn or (since Linux 3.5)
              ip_mreq structure similar to IP_ADD_MEMBERSHIP, or an
              in_addr structure.  (The kernel determines which structure
              is being passed based on the size passed in optlen.)  For
              getsockopt(2), the argument is an in_addr structure.
refer to https://man7.org/linux/man-pages/man7/ipv6.7.html
IPV6_MULTICAST_IF
              Set the device for outgoing multicast packets on the
              socket.  This is allowed only for SOCK_DGRAM and SOCK_RAW
              socket.  The argument is a pointer to an interface index
              (see netdevice(7)) in an integer.
testcase1:
TEST_IMPL(udp_multicast_interface) {
/* TODO(gengjiawen): Fix test on QEMU. */
  RETURN_SKIP("Test does not currently work in QEMU");

  int r;
  uv_udp_send_t req;
  uv_buf_t buf;
  struct sockaddr_in addr;
  struct sockaddr_in baddr;

  close_cb_called = 0;
  sv_send_cb_called = 0;
  ASSERT(0 == uv_ip4_addr("239.255.0.1", TEST_PORT, &addr));

  r = uv_udp_init(uv_default_loop(), &server);
  ASSERT(r == 0);

  ASSERT(0 == uv_ip4_addr("0.0.0.0", 0, &baddr));
  r = uv_udp_bind(&server, (const struct sockaddr*)&baddr, 0);
  ASSERT(r == 0);

  r = uv_udp_set_multicast_interface(&server, "0.0.0.0");
  ASSERT(r == 0);

  /* server sends "PING" */
  buf = uv_buf_init("PING", 4);
  r = uv_udp_send(&req,
                  &server,
                  &buf,
                  1,
                  (const struct sockaddr*)&addr,
                  sv_send_cb);
  ASSERT(r == 0);

  ASSERT(close_cb_called == 0);
  ASSERT(sv_send_cb_called == 0);

  /* run the loop till all events are processed */
  uv_run(uv_default_loop(), UV_RUN_DEFAULT);

  ASSERT(sv_send_cb_called == 1);
  ASSERT(close_cb_called == 1);

  ASSERT(client.send_queue_size == 0);
  ASSERT(server.send_queue_size == 0);

  MAKE_VALGRIND_HAPPY();
  return 0;
}
testcase2:
TEST_IMPL(udp_multicast_interface6) {
/* TODO(gengjiawen): Fix test on QEMU. */
  RETURN_SKIP("Test does not currently work in QEMU");

  int r;
  uv_udp_send_t req;
  uv_buf_t buf;
  struct sockaddr_in6 addr;
  struct sockaddr_in6 baddr;

  if (!can_ipv6())
    RETURN_SKIP("IPv6 not supported");

  close_cb_called = 0;
  sv_send_cb_called = 0;

  ASSERT(0 == uv_ip6_addr("::1", TEST_PORT, &addr));

  r = uv_udp_init(uv_default_loop(), &server);
  ASSERT(r == 0);

  ASSERT(0 == uv_ip6_addr("::", 0, &baddr));
  r = uv_udp_bind(&server, (const struct sockaddr*)&baddr, 0);
  ASSERT(r == 0);

  r = uv_udp_set_multicast_interface(&server, "::1%lo0");
  r = uv_udp_set_multicast_interface(&server, NULL);
  ASSERT(r == 0);

  /* server sends "PING" */
  buf = uv_buf_init("PING", 4);
  r = uv_udp_send(&req,
                  &server,
                  &buf,
                  1,
                  (const struct sockaddr*)&addr,
                  sv_send_cb);
  ASSERT(r == 0);

  ASSERT(close_cb_called == 0);
  ASSERT(sv_send_cb_called == 0);

  /* run the loop till all events are processed */
  uv_run(uv_default_loop(), UV_RUN_DEFAULT);

  ASSERT(sv_send_cb_called == 1);
  ASSERT(close_cb_called == 1);

  MAKE_VALGRIND_HAPPY();
  return 0;
}

Signed-off-by: wangchen <wangchen41@xiaomi.com>
2023-08-25 17:16:50 +08:00
Ville Juven
9cd8ea32d1 net/xx/wrbuffer: Do not use SEM_INITIALIZER for buffers
Using the macro places the buffers into .data section which means they
will consume the full buffer size of flash / read only memory as well.

Place the buffers into .bss to avoid this case.
2023-08-25 00:02:07 +08:00
Ville Juven
e163c74b90 rpmsg/rpmsg_sockif.c: Fix printf format for u64 type
Use PRIx64 which defines the width correctly regardless or architecture.

Fixes build error:
rpmsg/rpmsg_sockif.c:610:57: error: format '%llx' expects argument of type 'long long unsigned int', but argument 4 has type 'uint64_t' {aka 'long unsigned int'} [-Werror=format=]
  610 |       snprintf(conn->nameid, sizeof(conn->nameid), ":%llx", g_rpmsg_id++);
      |                                                      ~~~^   ~~~~~~~~~~~~
      |                                                         |             |
      |                                                         |             uint64_t {aka long unsigned int}
      |                                                         long long unsigned int
      |                                                      %lx
2023-08-23 23:36:15 +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
Zhe Weng
efc75de61e net/udp: Fix hybrid dual-stack IPv6/IPv4 socket
- Fix `ip6_map_ipv4addr` and `ip6_get_ipv4addr` macro to work under
  different endianness.
- Use `iob_reserve` instead of `iob_trimhead` in `udp_datahandler`.
  - Because we may set `sockaddr_in6` into IPv4 header, which causes
    `offset` become negative. `iob_reserve` can hold this case while
    `iob_trimhead` cannot.
- Select IPv4 domain in send case.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-08-22 09:09:21 +08:00
liqinhui
0100e8338e net: Fix unreadable error when doing poll operation on tcp socket.
When do poll operation and the tcp connection state is TCP_ALLOCATED, eventset(POLLERR|POLLHUP) is return, causing the libuv poll_multiple_handles to fail.

Verification: Use the libuv test case ` uv_run_tests poll_multiple_handles`.
Signed-off-by: liqinhui <liqinhui@xiaomi.com>
2023-08-21 17:38:00 +08:00
xucheng5
9d3abe8b71 socket can : support ioctl cmd SIOCCANRECOVERY
send CMD to restart controller in state bus-off

Signed-off-by: xucheng5 <xucheng5@xiaomi.com>
2023-08-21 13:18:51 +08: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
wangyingdong
2ce31c442f net/tcp:Added tcp zero window probe timer support
https://www.rfc-editor.org/rfc/rfc1122#page-92

Signed-off-by: wangyingdong <wangyingdong@xiaomi.com>
2023-08-20 19:47:11 -03:00
wangyingdong
adf9e685ab Fix the bug that localsocket fails to send in CONFIG_NET_LOCAL_DGRAM mode because fs adds pipe check (commit 9e06c3e)
Signed-off-by: wangyingdong <wangyingdong@xiaomi.com>
2023-08-20 19:18:18 +03:00
zhanghongyu
5b35c4e5b0 local_recvmsg: do not print error message when errno is EAGAIN
Some programs use EAGAIN to determine whether all data has been read,
so cancel the error print when the error code is EAGAIN.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-08-20 20:19:35 +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
zhanghongyu
1890ec5129 arp_wait: print dest ip address when receive wait timeout
If the arp query times out, the destination ip address is displayed to
help locate the problem

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-08-20 15:44:02 +08:00