Commit Graph

3025 Commits

Author SHA1 Message Date
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
Petro Karashchenko 075738cf14 net/ip: print ip addresses using ip4_addrN macro
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-08-19 13:28:21 -03:00
zhanghongyu 3bd495c09d icmp: add SOCK_RAW type support
Since ICMPv6 has added SOCK_RAW, a SOCK_RAW related implementation has also
been added for ICMP.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-08-19 22:04:22 +08:00
zhanghongyu 26c9f47ecc ipv6_setsockopt: remove redundant logic
Synchronize code differences from internal repositories to the community

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-08-18 16:47:56 -03:00
xucheng5 bcfb4decb0 socketcan : fixed CAN ID cast error
args can_id for recv_filter doesn't work properly

Signed-off-by: xucheng5 <xucheng5@xiaomi.com>
2023-08-19 01:31:34 +08:00
Bowen Wang 5bc32727b4 rpmsg_sockif: block poll shoud not set POLLERR
Support poll rpmsg socket fd with block mode

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2023-08-19 01:30:18 +08:00
wangyingdong 8f6f601ec1 net/local:Add peek support for pipe and MSG_PEEK support for local socket
fifo peek example:
struct pipe_peek_s peek_buf;
peek_buf.len = len;
peek_buf.data = buf;
ret = file_ioctl(filep, PIPEIOC_PEEK,(unsigned long)((uintptr_t)&peek_buf));

Signed-off-by: wangyingdong <wangyingdong@xiaomi.com>
2023-08-15 23:58:45 +08:00
Zhe Weng d3bca3c2cf net: Add FIOC_FILEPATH ioctl support for ICMP(v6)/RPMsg/Usrsock sockets
Example of /proc/PID/group/fd in this case:

FD  OFLAGS  TYPE POS       PATH
3   3       9    0         icmp:[dev eth0, id 1, flg 1]
4   3       9    0         icmp6:[dev eth0, id 2, flg 1]
5   3       9    0         rpmsg:[ap:[test:0]<->remote] # server side
5   3       9    0         rpmsg:[remote<->ap:[test:0]] # client side

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-08-15 15:00:59 +08:00
Zhe Weng 8e8d86a7bb net/ioctl: Add default print for sockets without FIOC_FILEPATH support
Example of /proc/PID/group/fd in this case:

FD  OFLAGS  TYPE POS       PATH
17  67      9    0         socket:[domain 16, type 2, proto 0]

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-08-15 15:00:59 +08:00
liqinhui 719191ac72 net/local: Return an error when write the too big packet.
Verification:
  Write a packet, the length is bigger than CONFIG_DEV_FIFO_SIZE.
  The return value should be -1, and the errno is EMSGSIZE.
Signed-off-by: liqinhui <liqinhui@xiaomi.com>
2023-08-14 23:46:08 +08:00
liqinhui 2d0df3b5f2 net/local: Fix the error return length when read the bigger packet.
Verifiction:
  Write a bigger packet and read the packet using a smaller buffer.
  The return length of reading should be the length of smaller buffer.

Signed-off-by: liqinhui <liqinhui@xiaomi.com>
2023-08-14 21:11:30 +08:00
liqinhui 8631e0c6b5 net/tcp: Fix the sack byte aligment error.
The error log is as follows:
  tcp/tcp_send_buffered.c:376:57: runtime error: member access within misaligned
  address 0x10075942 for type 'struct tcp_sack_s', which requires 4 byte alignment

Signed-off-by: liqinhui <liqinhui@xiaomi.com>
2023-08-14 20:46:09 +08:00
Zhe Weng d98bfc3e49 net/icmpv6: Fix `icmpv6_neighbor` for link-local address
The netdev of link-local address cannot be auto decided, and the link-local address should always be reguarded as address on local network.

The problem we met:
When using `icmpv6_autoconfig` with multiple netdev, the `icmpv6_neighbor` may take out wrong netdev with ip address already set, then it may send solicitation with wrong address (`dev->d_ipv6draddr`) on wrong device, and regard the link-local address as conflict (because `dev->d_ipv6draddr` exists on this network).

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-08-11 02:00:39 +08:00
hujun5 34dcd1c50a net: remove [enter|leave]_critical_section and sched_[un]lock
Signed-off-by: hujun5 <hujun5@xiaomi.com>
2023-08-10 12:24:30 +03:00
Zhe Weng c2ba0dfd6c net/netdev: Simplify handling of SIOCSIFMTU
The call of netdev_ifr_dev is already simplified by commit fd53db56b6

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-08-09 18:29:26 +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
zhangyuan21 114d641f4a net: add poll lock for local socket poll
net_lock/unlock is a big lock and repleace it to internal pool lock
to avoid the priority inversion problem.

Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2023-08-08 08:43:18 +02:00
Zhe Weng 817a43de4d net: Add FIOC_FILEPATH ioctl support for tcp/udp/local sockets
Example of /proc/PID/group/fd, which prints the file path:

FD  OFLAGS  TYPE POS       PATH
0   3       1    0         /dev/console
1   3       1    0         /dev/console
2   3       1    0         /dev/console
3   3       9    0         udp:[0.0.0.0:10197<->114.118.7.163:123, tx 0/16384, rx 0/16384, flg 1]
4   1027    9    0         tcp:[0.0.0.0:23<->0.0.0.0:0, tx 0/16384, rx 0/16384 + ofo 0, st 01, flg 31]
5   67      9    0         local:[md:ap]

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-08-07 08:08:37 -07: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
ligd 0383377d78 rpmsg_socket: rpmsg_socket_ns_bound() with lock
Signed-off-by: ligd <liguiding1@xiaomi.com>
2023-08-03 08:01:31 -07:00
ligd 17010ff811 rpmsg_socket: move nameid outof user define space
Signed-off-by: ligd <liguiding1@xiaomi.com>
2023-08-03 08:01:31 -07:00
wangchen 5c798dd297 inet/inet_sockif.c:In tcp protocol, Add random ports during the listening phase, if no ports are bound
In tcp protocol, if no ports are bound, Add random ports during the listening phase

libuvtestcase:
TEST_IMPL(tcp_listen_without_bind) {
int r;
uv_tcp_t server;

r = uv_tcp_init(uv_default_loop(), &server);
ASSERT(r == 0);
r = uv_listen((uv_stream_t*)&server, 128, NULL);
ASSERT(r == 0);

MAKE_VALGRIND_HAPPY();
return 0;
}

Signed-off-by: wangchen <wangchen41@xiaomi.com>
2023-08-03 03:24:23 -07:00
wangchen d528d2c410 net/local/local_sockif.c:add local_getpeername function implementation
this testcast
TEST_IMPL(udp_send_unix) {
  /* Test that "uv_udp_send()" supports sending over
     a "sockaddr_un" address. */
  struct sockaddr_un addr;
  uv_udp_t handle;
  uv_udp_send_t req;
  uv_loop_t* loop;
  uv_buf_t buf = uv_buf_init("PING", 4);
  int fd;
  int r;

  loop = uv_default_loop();

  memset(&addr, 0, sizeof addr);
  addr.sun_family = AF_UNIX;
  ASSERT(strlen(TEST_PIPENAME) < sizeof(addr.sun_path));
  memcpy(addr.sun_path, TEST_PIPENAME, strlen(TEST_PIPENAME));

  fd = socket(AF_UNIX, SOCK_STREAM, 0);
  ASSERT(fd >= 0);

  unlink(TEST_PIPENAME);
  ASSERT(0 == bind(fd, (const struct sockaddr*)&addr, sizeof addr));
  ASSERT(0 == listen(fd, 1));

  r = uv_udp_init(loop, &handle);
  ASSERT(r == 0);
  r = uv_udp_open(&handle, fd);
  ASSERT(r == 0);
  uv_run(loop, UV_RUN_DEFAULT);

  r = uv_udp_send(&req,
                  &handle,
                  &buf,
                  1,
                  (const struct sockaddr*) &addr,
                  NULL);
  ASSERT(r == 0);

  uv_close((uv_handle_t*)&handle, NULL);
  uv_run(loop, UV_RUN_DEFAULT);
  close(fd);
  unlink(TEST_PIPENAME);

  MAKE_VALGRIND_HAPPY();
  return 0;
}

Signed-off-by: wangchen <wangchen41@xiaomi.com>
2023-08-03 03:23:17 -07:00
wangchen b10d6be17a net:Add check for address binding
Signed-off-by: wangchen <wangchen41@xiaomi.com>
2023-08-03 03:16:31 -07:00
wangchen 14202651b2 net:Resolve udp disconnection, status not synchronized error
libuvtestcase:
TEST_IMPL(udp_connect) {
  RETURN_SKIP(
      "IBMi PASE's UDP connection can not be disconnected with AF_UNSPEC.");
  uv_udp_send_t req;
  struct sockaddr_in ext_addr;
  struct sockaddr_in tmp_addr;
  int r;
  int addrlen;

  close_cb_called = 0;
  cl_send_cb_called = 0;
  sv_recv_cb_called = 0;

  ASSERT(0 == uv_ip4_addr("[0.0.0.0](http://0.0.0.0/)", TEST_PORT, &lo_addr));

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

  r = uv_udp_bind(&server, (const struct sockaddr*) &lo_addr, 0);
  ASSERT(r == 0);

  r = uv_udp_recv_start(&server, alloc_cb, sv_recv_cb);
  ASSERT(r == 0);

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

  buf = uv_buf_init("EXIT", 4);

  /* connect() to INADDR_ANY fails on Windows wih WSAEADDRNOTAVAIL */
  ASSERT_EQ(0, uv_ip4_addr("[0.0.0.0](http://0.0.0.0/)", TEST_PORT, &tmp_addr));
  r = uv_udp_connect(&client, (const struct sockaddr*) &tmp_addr);
  ASSERT_EQ(r, UV_EADDRNOTAVAIL);
  ASSERT_EQ(r, 0);
  r = uv_udp_connect(&client, NULL);
  ASSERT_EQ(r, 0);

  ASSERT(0 == uv_ip4_addr("[8.8.8.8](http://8.8.8.8/)", TEST_PORT, &ext_addr));
  ASSERT(0 == uv_ip4_addr("[127.0.0.1](http://127.0.0.1/)", TEST_PORT, &lo_addr));

  r = uv_udp_connect(&client, (const struct sockaddr*) &lo_addr);
  ASSERT(r == 0);
  r = uv_udp_connect(&client, (const struct sockaddr*) &ext_addr);
  ASSERT(r == UV_EISCONN);

  addrlen = sizeof(tmp_addr);
  r = uv_udp_getpeername(&client, (struct sockaddr*) &tmp_addr, &addrlen);
  ASSERT(r == 0);

  /* To send messages in connected UDP sockets addr must be NULL */
  r = uv_udp_try_send(&client, &buf, 1, (const struct sockaddr*) &lo_addr);
  ASSERT(r == UV_EISCONN);
  r = uv_udp_try_send(&client, &buf, 1, NULL);
  ASSERT(r == 4);
  r = uv_udp_try_send(&client, &buf, 1, (const struct sockaddr*) &ext_addr);
  ASSERT(r == UV_EISCONN);

  r = uv_udp_connect(&client, NULL);
  ASSERT(r == 0);
  r = uv_udp_connect(&client, NULL);
  ASSERT(r == UV_ENOTCONN);

  addrlen = sizeof(tmp_addr);
  r = uv_udp_getpeername(&client, (struct sockaddr*) &tmp_addr, &addrlen);
  ASSERT(r == UV_ENOTCONN);

  /* To send messages in disconnected UDP sockets addr must be set */
  r = uv_udp_try_send(&client, &buf, 1, (const struct sockaddr*) &lo_addr);
  ASSERT(r == 4);
  r = uv_udp_try_send(&client, &buf, 1, NULL);
  ASSERT(r == UV_EDESTADDRREQ);

  r = uv_udp_connect(&client, (const struct sockaddr*) &lo_addr);
  ASSERT(r == 0);
  r = uv_udp_send(&req,
                  &client,
                  &buf,
                  1,
                  (const struct sockaddr*) &lo_addr,
                  cl_send_cb);
  ASSERT(r == UV_EISCONN);
  r = uv_udp_send(&req, &client, &buf, 1, NULL, cl_send_cb);
  ASSERT(r == 0);

  uv_run(uv_default_loop(), UV_RUN_DEFAULT);

  ASSERT(close_cb_called == 2);
  ASSERT(sv_recv_cb_called == 4);
  ASSERT(cl_send_cb_called == 2);

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

  MAKE_VALGRIND_HAPPY();
  return 0;
}

Signed-off-by: wangchen <wangchen41@xiaomi.com>
2023-08-03 03:12:17 -07:00
wangchen 842b6b88d3 net/udp:add check of the ip packet length
Signed-off-by: wangchen <wangchen41@xiaomi.com>
2023-08-03 00:15:28 -07:00
wangchen 44442a655e inet/ipv4_setsockopt.c:fix libuv udp option error
Signed-off-by: wangchen <wangchen41@xiaomi.com>
2023-08-02 22:54:13 -07:00
wangchen bdf82d2087 net/tcp: Return -EINVAL if bind is called more than once
Signed-off-by: wangchen <wangchen41@xiaomi.com>
2023-08-02 22:48:07 -07:00
wangyingdong 032a456c83 net/local:Add support for MSG_DONTWAIT to SOCK_STREAM
Signed-off-by: wangyingdong <wangyingdong@xiaomi.com>
2023-08-01 22:55:40 -07:00
Petro Karashchenko 6621dc016b net/udp: remove FAR from non-pointer variables
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-07-31 18:56:40 -07:00
dongjiuzhu1 44b08d3a67 net/rpmsg: read receiving data after unbind
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2023-07-29 07:04:43 -07:00
dongjiuzhu1 9a22741e32 net/rpmsg: get credentials between client and server
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2023-07-28 07:40:00 -07:00
wangyingdong 5ac8c71663 net/ipfrag:Fixed ref not initializing warning issue
CC: libssh/src/auth.c
1ipfrag/ipv4_frag.c: In function 'ipv4_fragout':
ipfrag/ipv4_frag.c:224:7: error: 'ref' may be used uninitialized in this function [-Werror-maybe-uninitialized]
      224 |      lmemcpy(ipv4, ref, iphdrlen);
ipfrag/ipv4_frag.c:364:26: note: 'ref' was declared here
      364 |   FAR struct ipv4_hdr_s *ref;
CC: tls/task initinfo c

Signed-off-by: wangyingdong <wangyingdong@xiaomi.com>
2023-07-26 08:36:04 -03:00
chao an 49dec5b48c cmake/build: fix build break on cmake
Signed-off-by: chao an <anchao@xiaomi.com>
2023-07-25 15:00:10 +02:00
Zhe Weng 9fd26195d1 net/setsockopt: Add IP_TTL support
We have IPV6_UNICAST_HOPS and IPV6_MULTICAST_HOPS in ipv6_setsockopt,
but only IP_MULTICAST_TTL in ipv4_setsockopt. So add IP_TTL support.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-07-24 09:46:37 -07:00
wangchen bde91a2abd inet:fix libuvtest udp multicast error
Signed-off-by: wangchen <wangchen41@xiaomi.com>
2023-07-24 09:46:37 -07:00
chao an 9004a49431 net/local: forward threshold ioctl() to pipe
Signed-off-by: chao an <anchao@xiaomi.com>
2023-07-22 11:39:28 +08: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
Zhe Weng 4b7604cf81 net: Rename tcp_dataconcat to net_iob_concat
Allow other protocols like UDP to use concat logic.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-07-18 10:51:45 +08:00
zhanghongyu 3db1654b80 net/local: remove client from server.lc_waiters when client close
if client is a noblocking socket, user can do close when server has not yet
invoke accept interface, so we need remove this socket from server.lc_waiters.
avoid server socket access the freed memory.

==936564==ERROR: AddressSanitizer: heap-use-after-free on address 0xf23071c8 at pc 0x58eaac3b bp 0xf0b9e218 sp 0xf0b9e208
READ of size 4 at 0xf23071c8 thread T0
    #0 0x58eaac3a in dq_remfirst queue/dq_remfirst.c:45
    #1 0x58fd1efe in local_accept local/local_accept.c:141
    #2 0x58f66df6 in psock_accept socket/accept.c:149
    #3 0x58f672a4 in accept4 socket/accept.c:280
    #4 0x5be9ee0c in accept net/lib_accept.c:50
    #5 0x592d6a5d in uv__accept libuv/src/unix/core.c:502
    #6 0x5930d83b in uv__server_io libuv/src/unix/stream.c:550
    #7 0x592efbde in uv__io_poll libuv/src/unix/posix-poll.c:335
    #8 0x592d649a in uv_run libuv/src/unix/core.c:387
    #9 0x5a7180f7 in service_schedule_loop service/common/service_loop.c:146
    #10 0x591f300b in pthread_startup pthread/pthread_create.c:59
    #11 0x5be8134f in pthread_start pthread/pthread_create.c:139
    #12 0x58ee2762 in pre_start sim/sim_initialstate.c:53

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-07-17 09:01:36 +02:00
Xiang Xiao abfe082a6f Kconfig: Simplify the conditional default statement
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-07-16 14:39:20 -03:00
wangyingdong a7926405ca net/udp: Fix the bug of overwriting when the udp recv buffer is full
Signed-off-by: wangyingdong <wangyingdong@xiaomi.com>
2023-07-14 07:53:37 +02:00
yintao 7544b68aa9 net/local: Support the abstract path to connect
Signed-off-by: yintao <yintao@xiaomi.com>
2023-07-14 09:57:24 +08:00
wangyingdong 57bf3e1fea net: Add msg_peek support for udp and tcp
Signed-off-by: wangyingdong <wangyingdong@xiaomi.com>
2023-07-13 19:40:04 +08:00
Zhe Weng 4ffd2cc84c net/nat: Fix compiler warning
We found warning of "%x" mismatch with "in_addr_t" on some platforms.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-07-12 19:29:14 +08:00
liqinhui a7a47621fa net/local: Support the socketpair interface of local udp socket.
Add the proccessing logic of udp socketpair, and modify the
logic of sending and receiving for udp socketpair.

Verification:
 - Use the socketpair interface to create a pair of local udp sockets,
   and perform read and write operations.

Signed-off-by: liqinhui <liqinhui@xiaomi.com>
2023-07-12 03:31:43 +08:00
simbit18 9681c52517 Fix nuttx coding style
Remove TABs
Fix indentation
2023-07-11 23:32:17 +08:00
zhanghongyu 3538d1b313 netlink: add some definition
In order to support the compilation of third-party library, we encounter
some situations where the macro is not defined, refer to the common
implementation of other systems and add relevant definitions.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-07-08 11:12:41 -03: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
Petro Karashchenko 3fe371f60f nuttx: replace getpid() with nxsched_getpid() in kernel code
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-07-07 17:39:39 -03:00
chao an 6a4495e3b7 net/local: fix build warning on GCC 12.2.0
In file included from local/local_fifo.c:25:
In function ‘local_format_name’,
    inlined from ‘local_hd_name’ at local/local_fifo.c:132:3,
    inlined from ‘local_open_receiver’ at local/local_fifo.c:661:3:
local/local_fifo.c:77:16: warning: ‘%s’ directive output may be truncated writing up to 107 bytes into a region of size 100 [-Wformat-truncation=]
   77 |                CONFIG_NET_LOCAL_VFS_PATH "/%s%s", inpath, suffix);
      |                ^~~~~~~~~~~~~~~~~~~~~~~~~
local/local_fifo.c: In function ‘local_open_receiver’:
local/local_fifo.c:82:44: note: format string is defined here
   82 |                CONFIG_NET_LOCAL_VFS_PATH "/%s%s%" PRIx32,
      |                                            ^~
In function ‘local_format_name’,
    inlined from ‘local_hd_name’ at local/local_fifo.c:132:3,
    inlined from ‘local_open_receiver’ at local/local_fifo.c:661:3:
local/local_fifo.c:76:7: note: ‘snprintf’ output between 12 and 119 bytes into a destination of size 109
   76 |       snprintf(outpath, LOCAL_FULLPATH_LEN - 1,
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   77 |                CONFIG_NET_LOCAL_VFS_PATH "/%s%s", inpath, suffix);
      |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: chao an <anchao@xiaomi.com>
2023-07-06 13:19:21 +08: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
Stuart Ianna 30f8cf541c net/udp: Populate the udp connection structure with the address family.
The udp connection structure contains the field, "domain", which defines which address family it belongs to. Prior to this change, this field was only populated correctly if IPv4 and IPv6 was enabled. As a result, packet information was not processed in udp_recvpktinfo, as expected when the appropriate socket option was enabled.
2023-06-27 14:58:12 +08:00
Stuart Ianna 42abf22eef socket/recvfrom: Fix buffer copy direction when using BUILD_KERNEL.
When using recvfrom, the data should be copied back to the user provided buffer after psock_recvfrom, not before.
2023-06-22 11:56:01 +08:00
zhanghongyu 76fde07d1c netdev: remove ASSERT when ifindex is invalid
There is no control over whether a valid index is input when user use
ioctl to get netdev information, so removing this assertion will allow
ENODEV to be returned.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-06-13 13:32:03 +08:00
Petro Karashchenko 1b801a5bbc style: remove extra spaces and align parameters
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-06-11 12:55:29 +08:00
SPRESENSE 54112ac070 drivers/modem/alt1250: Update alt1250 driver
Updated alt1250 driver with regarding to the following changes.
- Add LTE hibernation feature
- Split source code per module
- Some refactoring
- Some bug fixes
2023-06-08 07:48:17 +02:00
Zhe Weng f71fb738c5 net/icmp: Save poll device in icmp_poll_s
ICMP's conn->dev is changing in icmp_sendmsg, when sending to different
address, or when error occurs (like NETDEV_DOWN). Then the poll callback
cannot be dropped from previous dev in free, because the dev is wrong.

So add dev to struct icmp_poll_s just like struct udp_poll_s.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-06-06 19:33:21 +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
chao an 589d4a9f8e net/semantic/parser: fix compile warning found by sparse
Reference:
https://linux.die.net/man/1/sparse

Signed-off-by: chao an <anchao@xiaomi.com>
2023-05-30 23:00:00 +08:00
chao an c470ef7c9c net/socket: fix kconfig warning
warning: (NET_SOLINGER) selects NET_UDP_NOTIFIER which has unmet direct dependencies
  (NET && NET_UDP && !NET_UDP_NO_STACK && SCHED_WORKQUEUE)

Signed-off-by: chao an <anchao@xiaomi.com>
2023-05-30 16:06:17 +08:00
Zhe Weng 7d1b733202 net/tcp: Add flag for tcp_close to avoid double free
Problem:
When tcp_close_work starts to run in LPWORK, if another event comes and
calls tcp_free before tcp_close_work takes net_lock, the tcp_free will
be called twice and cause double free.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-05-29 13:00:06 +02: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
Ville Juven ac4183e589 socket/send/recv: Copy user parameters to kernel memory (BUILD_KERNEL)
Need to copy the user pointers into kernel memory before calling send/recv,
because devif_poll() and others will fail at once due to wrong mappings.
2023-05-27 03:24:06 +08:00
Ville Juven 4ed4e3ca36 net/socket: Combine send() with sendto()
send() is just a specific flavor of sendto(), thus they can be combined.
2023-05-27 03:24:06 +08:00
simbit18 e4ffce3355 Fix Kconfig style
Remove spaces from Kconfig files
2023-05-23 00:03:25 +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
Petro Karashchenko f79d3860c2 net/icmpv6: fix style issues
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-05-19 02:40:38 +08:00
Petro Karashchenko 40708e0ea7 net/icmpv6: add CODE to function pointer
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-05-19 02:40:38 +08:00
Petro Karashchenko b944886659 net/udp: remove FAR for non-pointer variables
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-05-19 02:40:38 +08:00
Petro Karashchenko c70b7f6b3d nuttx: improve C89 compatibility in common code
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-05-19 02:40:38 +08:00
Xiang Xiao cff40aa34c net: Remove some minor #warning since it compiler specific
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-05-18 15:44:28 +03:00
Xiang Xiao 8d56a9bbcb Remove #warning if the code already return the error code or value
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-05-18 15:44:28 +03:00
liqinhui a9640bad1a net: Add the check that socket domain is equal to bound address type, when do bind.
When do socket bind, if the connection domain is not equal to the bound address type, this will cause the stack-buffer-overflow.

Signed-off-by: liqinhui <liqinhui@xiaomi.com>
2023-05-18 01:08:38 +03:00
liqinhui f61dc72892 net/tcp:Add NewReno congestion control.
- NewReno congestion control algorithm is used to solve the problem
  of network congestion breakdown. NewReno congestion control includes
  slow start, collision avoidance, fast retransmission, and fast
  recovery. The implementation refers to RFC6582 and RFC5681.

- In addition, we optimize the congestion algorithm. In the conflict
  avoidance stage, the maximum congestion window max_cwnd is used to
  limit the excessive growth of cwnd and prevent network jitter
  caused by congestion. Maximum congestion window max_cwnd is updated
  with the current congestion window cwnd and the update weight is
  0.875 when an RTO timeout occurs.

Signed-off-by: liqinhui <liqinhui@xiaomi.com>
2023-05-16 12:35:01 -03:00
chao an 36591af615 net/rpmsg: initialize semaphore count before wait
recvmsg() will incorrectly return 0 if the count of sema before waiting is greater than 0,
This commit will reinitialize the sema count before waiting:

1181 static ssize_t rpmsg_socket_recvmsg(FAR struct socket *psock,
1182                                     FAR struct msghdr *msg, int flags)
1183 {
...
1255   ret = net_sem_timedwait(&conn->recvsem,
1256                       _SO_TIMEOUT(conn->sconn.s_rcvtimeo)); // recvsem.sem_count == 1; return 0
...
1264   if (!conn->recvdata)              // recvdata not consumed; goto else
1265     {
1266       ret = conn->recvlen;
1267     }
1268   else
1269     {
1270       conn->recvdata = NULL;
1271     }
...
1282   return ret;                        // BUGON! incorrectly return 0 to user
1283 }

Signed-off-by: chao an <anchao@xiaomi.com>
2023-05-16 17:15:42 +08:00
zhanghongyu 62076fb7b9 ipv6_setsockopt: Merge similarity logic
modify the assignment logic to make it easier to extend new options later

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-05-15 16:48:18 +08:00
zhanghongyu c9a843bdca ipv6: support SOL_IPV6 options IPV6_UNICAST_HOPS and IPV6_MULTICAST_HOPS
Added simple support for IPV6_UNICAST_HOPS and IPV6_UNICAST_HOPS, the application can configure the ttl parameters of the socket in user mode.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-05-13 22:34:21 +08:00
zhanghongyu 1def5da221 net: move ttl field into socket_conn_s struct
move ttl filed from udp_conn_s to socket_conn_s structure to make it more than just control udp.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-05-13 12:39:53 +08: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
Tiago Medicci Serrano 4f4a00ab1f net/local: fix blocking local sockets
Commit 4d6a8663fa made pipes and
named pipes block when opening for O_WRONLY or O_RDONLY. Local
sockets, however, require `local_open_client_tx` to be non-blocking
to enable the server side to prevent the server side from blocking.
If set otherwise, it would deadly block. This commit sets the FIFO
as non-blocking temporarily, open the TX side and, if originally
blocking - restores it to that state.
2023-05-11 11:39:00 +08:00
zhanghongyu 91e13c47ae net: remove conn-related casts
remove redundant casts associated with psock

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-05-10 19:32:09 -03:00
zhanghongyu e0816ff050 in.h: add SOL_IPV6 protocol-level socket option IPV6_RECVHOPLIMIT
added IPV6_RECVHOPLIMIT support so that fd of SOCK_RAW ICMPV6 can obtain ttl
information, some network related tools use this feature.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-05-10 18:00:15 +08:00
Ville Juven 1e9560e1e5 net/net_cmsg.c: Fix warning about using void* arithmetics
utils/net_cmsg.c: In function 'cmsg_append':
utils/net_cmsg.c:82:23: error: pointer of type 'void *' used in arithmetic [-Werror=pointer-arith]
   82 |   msg->msg_control    += cmsgspace;
      |                       ^~
cc1: all warnings being treated as errors

Using void pointers in arithmetic operations is a GCC extension, it is
not supported by the standard. Because what is the size of a void ?
2023-05-10 17:58:25 +08:00
zhanghongyu e10fda570b udp: change PKTINFO flag to socket_conn_s struct
move the IPPROTO_IP/IPPROTO_IPV6 flag into the socket_conn_s structure to
make it more than just control udp.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-05-09 07:53:56 +02:00
Xiang Xiao 6f6fce95a2 Replace all sprintf with snprintf
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-05-08 09:57:01 +02:00
zhanghongyu 35dee8fdd2 icmpv6: add SOCK_RAW type support
The third-party library we are porting will send and receive ICMPV6 messages
(router_advert / router_solicit / neighbor_advert / neighbor_solicit etc.)
from the user mode itself, so we added the SOCK_RAW related implementation
for ICMPV6.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-05-07 22:43:10 +08:00
zhanghongyu 9f8d418cd1 forward: copy iob when broadcast forward
since iob offload, ipvx_dev_forward will remove d_iob, if there are multiple
devices, d_iob will be NULL when dev_forward is entered second time. and the
device that receives the packet cannot process the packet after forwarding it
so the iob copy is added.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-05-06 03:18:08 +08:00
Zhe Weng 26e2e1e32f net/udp: Remove wrong check in udp_readahead
- Before IOB offload, srcaddr / src_addr_size / ifindex are written into
  IOB by iob_trycopyin, so io_pktlen > 0 is always true, this check is
  correct at that time. (It won't fail with zero-length UDP datagram.)
- After IOB offload, srcaddr / src_addr_size / ifindex are written into
  offset 0, without increasing io_pktlen. So this check will fail with
  zero-length UDP datagram now.
- We need to support zero-length UDP datagram and this check is
  unnecessary at this point.
  - https://stackoverflow.com/questions/5307031/how-to-detect-receipt-of-a-0-length-udp-datagram
  - https://github.com/apache/nuttx/blob/nuttx-12.1.0/net/udp/udp_callback.c#L214

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-05-05 11:25:07 +03:00
zhanghongyu bdb5639274 netlink: convert lltype to device type
adapts to third-party code compilation. in the process of porting ConnMan,
we encounter some situations where the structure is not defined, or the
returned data types do not match the expectations. Refer to the common
implementation of other systems and add relevant definitions.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-05-05 00:19:59 +08:00
zhanghongyu 646c41dced tcp_monitor: start_monitor return OK when connect closed by peer
If TCP_FIN is received before the user calls accept, the later accept will
report an error, then the previously received data cannot be read.

operation flow:
tcp_server_listen -> tcp_client_connect -> tcp_client_send ->
tcp_client_close -> tcp_server_accept(fix this error) -> tcp_server_recv

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-05-04 17:12:52 +03:00
zhanghongyu c288752bef recvmsg: control msg support multi-attribute return
adapts to third-party code compilation. in the process of porting ConnMan,
multiple control message options are enabled, such as IPV6_RECVPKTINFO and
IPV6_RECVHOPLIMIT, so I changed the Filling implementation of the control
message.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-05-04 12:04:11 +02: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
Xiang Xiao 5de49d2939 net: Remove the extra space
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-05-03 15:18:21 +02:00
Xiang Xiao df246461ec net/can: Remove the unnecessary "ret = OK;" in can_getsockopt
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-05-03 15:18:21 +02: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
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
Petro Karashchenko 0a28b2a26e net/bluetooth: fix parameter indentation
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-04-24 09:35:58 -07:00
zhanghongyu 9162800255 tcp_input: drop SYN when no free node in the backlog
Wait for the client to retransmit the ack before trying to allocate the
backlog

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-04-24 01:52:33 +08:00
Zhe Weng 1aceb1d872 net/tcp: Fix clear condition in ofoseg input
We have a case that an http server gives out-of-ordered ACKs, and NuttX client makes `ofoseg`s with length 0, trying to rebuild / put them into `ofosegs` array, which is not intended (no available data and should be skipped). This breaks later logic and finally crashed in `tcp_ofoseg_bufsize` (`ofosegs[i].data` is `NULL`, which should never happen in normal logic).

Note:
- `iob_trimhead` won't return `NULL` when it's applying on normal IOB.
  - Keep `dev->d_iob == NULL` to avoid `iob_trimhead` changed.
- `iob_free_chain` will do nothing when applied to `NULL`.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-04-22 19:26:22 +08:00
zhanghongyu 6c73221dd4 forward: limit the forwarding range of broadcast packets
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-04-22 19:24:46 +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
zhanghongyu 93c3b8f19e tcp: add TCP_MAXSEG support
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-04-22 01:42:47 +08:00
zhanghongyu bd4d7a1b76 tcp: accept conn inherits some properties of listener conn
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-04-22 01:42:47 +08:00
zhanghongyu fdc6dbf176 netlink: add RTM_NEWADDR, RTM_DELADDR and RTM_GETADDR
We have projects that need to sense ip address changes in time,
and set ip address or clear ip address through netlink
so the relevant implementation is added.
The usage and command structure are consistent with linux

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-04-22 01:35:18 +08:00
Zhe Weng 9f8d587b64 net/rpmsg: Set family for rpaddr in ns_bind
The rpmsg addr get from socket accept has rp_family=0, which is not
intended, to avoid wrong logic in other place, set the rp_family
in ns_bind function.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-04-21 13:18:48 +03:00
zhangyuan21 c239d19df0 nuttx: add more dependent header file
Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
2023-04-11 09:13:32 +03:00
Zhe Weng b058f37353 net/tcp: Reply RST when we cannot receive data
According to RFC 2525, Section 2.17:
"When an application closes a connection in such a way that it can no longer read any received data, the TCP SHOULD, per section 4.2.2.13 of RFC 1122, send a RST if there is any unread received data, or if any new data is received."

When our TCP socket is closed (even when the thread has exited), the peer can keep sending data and NuttX keeps replying ACK (we've tried for ~12h). This is not a good behavior (also different from Linux), so send RST instead of ACK for data receiving in FIN_WAIT.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-03-29 09:22:00 -03:00
Zhe Weng 61ff04b9e2 net/inet: Only setup poll for UDP when s_type == SOCK_DGRAM
Problem:
A SOCK_CTRL socket may be led to udp_pollsetup but never reaches
udp_pollteardown, it seems that we shouldn't call udp_pollsetup for
other socket types.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-03-29 09:18:36 -03:00
zhanghongyu ec2b74df77 icmpv6: add RDNSS field support for send route advertise
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-03-17 16:50:37 -03:00
zhanghongyu d9e009cb46 icmpv6: add route advertise RDNSS field handle when icmpv6_input
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-03-17 16:50:37 -03:00
zhangyuan21 fd9792b4bd net: use NXRMUTEX_INITIALIZER for rmutex init
Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
2023-03-15 13:57:08 +01:00
Zhe Weng 7b0d80c94a net/icmpv6: align structs to 2 bytes.
Fix following misaligned errors:

icmpv6/icmpv6_radvertise.c:145:21: runtime error: member access within misaligned address 0x573da9e6 for type 'struct icmpv6_router_advertise_s', which requires 4 byte alignment
0x573da9e6: note: pointer points here
 00 00 00 01 85 00  d6 14 00 00 00 00 01 01  12 8c 25 08 9c f8 04 00  00 00 ff 02 00 00 00 00  00 00
             ^
icmpv6/icmpv6_radvertise.c:167:21: runtime error: member access within misaligned address 0x573da9fe for type 'struct icmpv6_mtu_s', which requires 4 byte alignment
0x573da9fe: note: pointer points here
 af 78 ab 72 00 00  00 00 00 00 00 01 ff 00  00 01 04 00 00 00 ff 02  00 00 00 00 00 00 00 00  00 01
             ^
icmpv6/icmpv6_radvertise.c:176:23: runtime error: member access within misaligned address 0x573daa06 for type 'struct icmpv6_prefixinfo_s', which requires 4 byte alignment
0x573daa06: note: pointer points here
 00 00 05 dc ff 00  00 01 04 00 00 00 ff 02  00 00 00 00 00 00 00 00  00 01 ff 08 9c f8 04 00  00 00
             ^

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-03-10 09:41:02 +01:00
Xiang Xiao 75ecbd4382 net/local: Return the unblock handle correctly in local_accept
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-03-09 09:17:19 +01: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
Xiang Xiao 9f4a15110c net: Finish FIONBIO default action if si_ioctl return OK
Continue the work: https://github.com/apache/nuttx/pull/6976

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-03-07 11:34:35 +02:00
Xiang Xiao 3c3dea5d7a net: Make si_poll callback optional
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-03-06 20:58:27 +02:00
Xiang Xiao c39be172da net: Make si_accept callback optional
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-03-06 20:58:27 +02:00
Xiang Xiao 5dd037c599 net: Make si_connect callback optional
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-03-06 20:58:27 +02:00
Xiang Xiao a97e2523a4 net: Make si_listen callback optional
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-03-06 20:58:27 +02:00
Xiang Xiao 2553b7701c net: Remove the empty si_getpeername implementation
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-03-06 20:58:27 +02:00
Xiang Xiao 9b3715050b net: Make si_getsockname callback optional
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-03-06 20:58:27 +02:00
Xiang Xiao b3c1c55805 net: Make si_bind callback optional
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-03-06 20:58:27 +02:00
Zhe Weng 7111d23ae4 net/arp: Only parse ioctl request for valid cmd.
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-03-06 10:51:12 -03:00
Fotis Panagiotopoulos 5e625b9cdb Performance optimizations in connection allocations. 2023-02-28 14:23:16 +01:00
Xiang Xiao 2c5f653bfd Remove the tail spaces from all files except Documentation
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-02-26 13:24:24 -08:00
Zhe Weng 0069eefd4b net/udp: Add drop count when limited by recv bufsize
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-02-24 14:36:01 +02:00
lilei19 38f64f559d change strcpy to strlcpy
Signed-off-by: lilei19 <lilei19@xiaomi.com>
2023-02-24 12:15:40 +08:00
ligd c4ed55c6df socket: divide errno & s_error
Reference:
https: //man7.org/linux/man-pages/man2/connect.2.html

Signed-off-by: ligd <liguiding1@xiaomi.com>
2023-02-23 16:40:19 +01:00
ligd f9b6255895 local_socket: remove the wrong assertion in local_listen()
if 2 threads call local_alloc() time and then do local_listen()
will meet this assertion

Signed-off-by: ligd <liguiding1@xiaomi.com>
2023-02-23 22:46:48 +08:00
Zhe Weng 31b65844a2 usrsock: Do not return error when conn not found for an event
There might be some cases that we receive an event after socket is closed because of out-of-ordered rpmsg, since it may not cause problem, we may omit the error.
Also change log level to err when returning negated errno, because if we return negated errno, we'll directly trigger RPMSG_ASSERT outside, so we need at least an error message to indicate the reason.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-02-22 01:42:14 +08:00
chao an fcefd16586 net/devif: fix null pointer reference found out by coverity
Signed-off-by: chao an <anchao@xiaomi.com>
2023-02-21 00:44:07 +08:00
Fotis Panagiotopoulos b6eb3c828c Removed obsolete option NET_ALLOC_CONNS. 2023-02-20 09:06:46 +08:00
Fotis Panagiotopoulos b5b7d24ba1 Improvements in CAN connections allocation. 2023-02-20 09:06:46 +08:00
Fotis Panagiotopoulos 9b4d784307 Improvements in sockets allocation. 2023-02-20 09:06:46 +08:00
Fotis Panagiotopoulos cf15d6b63a Improvements in Netlink connections allocation. 2023-02-20 09:06:46 +08:00
Fotis Panagiotopoulos 74bb921a19 Improvements in packet connections allocation. 2023-02-20 09:06:46 +08:00
Fotis Panagiotopoulos 22a82b3f51 Improvements in IEEE 802.15.4 connections allocation. 2023-02-20 09:06:46 +08:00
Fotis Panagiotopoulos c5cc70a8b1 Improvements in Bluetooth connections allocation. 2023-02-20 09:06:46 +08:00
Fotis Panagiotopoulos 90a93a7474 Improvements in ICMPv6 connections allocation. 2023-02-20 09:06:46 +08:00
Fotis Panagiotopoulos 1c07a3a696 Improvements in ICMP connections allocation. 2023-02-20 09:06:46 +08:00
Fotis Panagiotopoulos f207072121 Improvements in usrsock connections allocation. 2023-02-20 09:06:46 +08:00
Fotis Panagiotopoulos 7f3591b9cc Improvements in UDP connections allocation. 2023-02-20 09:06:46 +08:00
Fotis Panagiotopoulos 8f9dfe0be1 Improvements in TCP connections allocation. 2023-02-20 09:06:46 +08:00
Fotis Panagiotopoulos 85ceb7920e Typo fixes. 2023-02-17 11:17:11 -03:00
SPRESENSE 277e0b941a include/sys/socket.h: Add SOCK_CTRL to socket type
SOCK_CTRL is added to provide special control over network drivers
and daemons. Currently, SOCK_DGRAM and SOCK_STREAM perform this control,
but these use socket resources. In the case of usersocket in particular,
this is a waste of the device's limited socket resources.
2023-02-16 12:13:01 +09:00
chao an bd7e521871 net/sendfile: adapt sendfile() to support new driver model
Signed-off-by: chao an <anchao@xiaomi.com>
2023-02-14 11:21:09 +08:00
Xiang Xiao 0ef073573a net: Remove protocol argument from si_setup callback
since the implementor could get the same value from socket::s_proto

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-02-13 22:41:19 +08:00
zhanghongyu a2097cfb71 net: modify find device logic
The priorities for finding a network adapter are as follows:
1. if laddr is not ANY, use laddr to find device;
2. if laddr is ANY, and bound index is not 0, use bound index
   to find device;
3. if laddr is ANY and no device is bound, use raddr to find
   device.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-02-12 01:25:34 +08:00
Zhe Weng aad1a70bc5 net/udp: Support binding to same addr/port if SO_REUSEADDR is specified.
Ref: On Linux, if SO_REUSEADDR(sk_reuse) is set for both sockets, port will not be regarded as inuse. https://github.com/torvalds/linux/blob/v6.1/net/ipv4/udp.c#L146

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-02-10 10:01:08 +01: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 e942a7c55e build/Kconfig: fix warnings detected by kconfiglib
Signed-off-by: chao an <anchao@xiaomi.com>
2023-02-09 20:07:46 +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
Masayuki Ishikawa 3f3e090716 Revert "include/sys/socket.h: Add SOCK_CTRL to socket type"
This reverts commit abba05a934.
2023-02-09 09:13:14 +01:00
SPRESENSE abba05a934 include/sys/socket.h: Add SOCK_CTRL to socket type
SOCK_CTRL is added to provide special control over network drivers
and daemons. Currently, SOCK_DGRAM and SOCK_STREAM perform this control,
but these use socket resources. In the case of usersocket in particular,
this is a waste of the device's limited socket resources.
2023-02-08 20:43:33 +08:00
chao an 1cb11968b7 net/ip: fix compile break if enable NET_LOCAL_SCM
1.
net/slip.c:865:29: warning: unused variable ‘priv’ [-Wunused-variable]
  865 |   FAR struct slip_driver_s *priv =
      |                             ^~~~
net/slip.c: In function ‘slip_rmmac’:
net/slip.c:895:29: warning: unused variable ‘priv’ [-Wunused-variable]
  895 |   FAR struct slip_driver_s *priv =
      |                             ^~~~
2.
local/local_sendmsg.c: In function ‘local_sendmsg’:
local/local_sendmsg.c:423:18: warning: ‘count’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  423 |           return count;
      |                  ^~~~~
local/local_sendmsg.c:131:11: warning: ‘i’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  131 |   while (i-- > 0)
      |          ~^~
local/local_sendmsg.c:71:7: note: ‘i’ was declared here
   71 |   int i;
      |       ^

Signed-off-by: chao an <anchao@xiaomi.com>
2023-02-07 12:46:40 +02:00
chao an e3a6c16944 net/ip: fix compile break if disable NET_TCP
1.
ipfrag/ipv4_frag.c: In function ‘ipv4_fragin’:
ipfrag/ipv4_frag.c:184:22: warning: ‘head’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  184 |   ipv4->len[1] = head->io_pktlen & 0xff;
      |                  ~~~~^~~~~~~~~~~
ipfrag/ipv4_frag.c:123:21: note: ‘head’ was declared here
  123 |   FAR struct iob_s *head;
      |                     ^~~~

2.
devif/ipv6_input.c: In function ‘ipv6_in’:
devif/ipv6_input.c:60:33: error: ‘TCPIPv6BUF’ undeclared (first use in this function); did you mean ‘UDPIPv6BUF’?
   60 | #define PAYLOAD ((FAR uint8_t *)TCPIPv6BUF)
      |                                 ^~~~~~~~~~

3.
nat/ipv4_nat.c: In function ‘ipv4_nat_inbound_icmp’:
nat/ipv4_nat.c:67:30: error: ‘TCP_HDRLEN’ undeclared (first use in this function); did you mean ‘UDP_HDRLEN’?
   67 |   ((proto) == IP_PROTO_TCP ? TCP_HDRLEN : \
      |                              ^~~~~~~~~~
nat/ipv4_nat.c:323:47: note: in expansion of macro ‘L4_HDRLEN’
  323 |             inner_l4hdrlen = MIN(inner_l4len, L4_HDRLEN(inner->proto));
      |                                               ^~~~~~~~~

Signed-off-by: chao an <anchao@xiaomi.com>
2023-02-07 12:46:40 +02:00
zhanghongyu e7d1ba157c usrsock: Don't clear recvfrom available flag
Don't clear available flag if the response indicate there is more data

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-02-04 20:52:56 +09:00
zhanghongyu 01fe37206a usrsock: optimize send case
Don't clear available flag if the response indicate there is more space

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-02-04 20:52:56 +09:00
Zhe Weng d423992988 net/tcp: Regard snd_wnd update as ACKDATA
Receiving an ACK indicating TCP Window Update will not set ACKDATA flag (because tx_unacked is 0) in our TCP stack. Then this ACK won't let us send anything after receiving it, even if it updates snd_wnd. So we need to check whether we can send data immediately when our snd_wnd is updated (especially from 0), otherwise we will only send next data after timer expiry.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-02-03 13:43:39 +02:00
chao an 247b050e5f net/tcp: remove conn check since which can not be NULL
Signed-off-by: chao an <anchao@xiaomi.com>
2023-02-02 13:31:06 +08:00
chao an 4c8d244fae sched/getpid: replace syscall getpid/tid/ppid() to kernel version
NuttX kernel should not use the syscall functions, especially after
enabling CONFIG_SCHED_INSTRUMENTATION_SYSCALL, all system functions
will be traced to backend, which will impact system performance.

Signed-off-by: chao an <anchao@xiaomi.com>
2023-02-02 10:33:01 +08:00
Xiang Xiao d92dc45a80 vfs: Suppoprt F_DUPFD_CLOEXEC and MSG_CMSG_CLOEXEC
https://pubs.opengroup.org/onlinepubs/9699919799/functions/fcntl.html
https://linux.die.net/man/2/recvmsg

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-02-02 01:00:10 +02:00
Gustavo Henrique Nihei e6b204f438 nuttx: Use MIN/MAX definitions from "sys/param.h"
Signed-off-by: Gustavo Henrique Nihei <gustavo.nihei@espressif.com>
2023-02-01 23:47:44 +08:00
chao an 30aa0ee700 net/devif: correct the judgment condition in devif_send()
Regression by:

| commit 7fce145b30
| Author: chao an <anchao@xiaomi.com>
| Date:   Mon Jan 30 21:36:39 2023 +0800
|
|     net/devif: check the net device before use
|
|     Signed-off-by: chao an <anchao@xiaomi.com>

Signed-off-by: chao an <anchao@xiaomi.com>
2023-01-31 22:42:58 +08:00
chao an 7fce145b30 net/devif: check the net device before use
Signed-off-by: chao an <anchao@xiaomi.com>
2023-01-31 18:41:50 +08:00
Zhe Weng c9e52cb283 net: Implement shutdown() for local stream socket
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-01-31 11:15:01 +08:00
Zhe Weng d3dd349649 net: Implement shutdown() for usrsock
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-01-31 11:15:01 +08:00
Zhe Weng 8819eeaf15 net: Implement shutdown() interface and tcp shutdown
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-01-31 11:15:01 +08:00
lilei19 1d8af7e105 add holder for mutex
Signed-off-by: lilei19 <lilei19@xiaomi.com>
2023-01-31 12:08:05 +09:00
Nathan Hartman 6b89b6f945 Remove executable permissions from source files
* arch/arm/src/sama5/sam_flexcom_spi.h,
  arch/risc-v/src/mpfs/mpfs_ihc_sbi.c,
  drivers/usbdev/adb.c,
  libs/libc/math/lib_scalbn.c,
  libs/libc/math/lib_scalbnf.c,
  net/ipfrag/Make.defs,
  net/ipfrag/ipfrag.c,
  net/ipfrag/ipfrag.h,
  net/ipfrag/ipv4_frag.c,
  net/ipfrag/ipv6_frag.c: Remove executable permission.
2023-01-30 20:34:51 -03:00
Zhe Weng be89bcc044 mm/iob: Support negative offset when copyin/out.
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-01-31 00:39:15 +08:00
梁超众 b33474cb11 free TCP rx buffer immediately in tcp_close
Issue:
TCP rx buffer is freed after 4-way handshake with current design.
3 socket's rx buffer might be consumed during ffmpeg switch music procedure,
and this might cause IOB exhausted.

Solution:
free TCP rx buffer immediately in tcp_close to make sure IOB won't be
exhausted.

Signed-off-by: 梁超众 <liangchaozhong@xiaomi.com>
Signed-off-by: chao an <anchao@xiaomi.com>
2023-01-30 11:25:36 +08:00
chao an 98e1f9c36d net/tcp: reuse common api to replace some ip select code
Signed-off-by: chao an <anchao@xiaomi.com>
2023-01-30 11:25:10 +08:00
luojun1 861004725a Fix ICMPv6 RA parsing procedure
Signed-off-by: luojun1 <luojun1@xiaomi.com>
2023-01-29 14:32:59 +08:00
zhanghongyu 3e4e416786 tcp/udp_connect: If the remote addr is ANY, change it to LOOPBACK
Behavior alignment to Linux

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-01-29 13:46:43 +08:00
chao an 85a8249821 Revert "socket:return -EAGAIN if timeout happends in psock_tcp_send"
This reverts commit fbe641a916.

This issue already fixed by below change:

| commit 715785245c
| Author: chao an <anchao@xiaomi.com>
| Date:   Mon Jan 16 12:37:44 2023 +0800
|
|     net/tcp: fix potential busy loop in tcp_send_buffered.c
|
|     if the wrbuffer does not have enough space to send the rest of
|     the data, then the send function will loop infinitely in nonblock
|     mode, add send timeout check to avoid this issue.
|
|     Signed-off-by: chao an <anchao@xiaomi.com>

Signed-off-by: chao an <anchao@xiaomi.com>
2023-01-29 13:46:01 +08:00
zhanghongyu 26286fd19e tcp: modify errno when connect raddr is ANY for ltp
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-01-29 13:45:49 +08:00
zhanghongyu 65e08b750c tcp_reset: check the conn is exist when tcp_reset
tcp_input:
If we didn't find an active connection that expected the packet,
If the SYN flag isn't set,
It is an old packet and we send a RST.
conn is NULL when this case

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-01-29 13:43:44 +08:00
梁超众 5012195bde support ipv4 ToS and ipv6 TrafficClass
Signed-off-by: 梁超众 <liangchaozhong@xiaomi.com>
2023-01-29 13:43:44 +08:00
梁超众 5e0af0ecfd add UDP compile option to avoid build error
The following build error happens when CONFIG_NET_IPv6 is enabled and CONFIG_NET_UDP is not enabled.

inet/ipv6_setsockopt.c:132:19: error: invalid use of undefined type 'struct udp_conn_s'
132 |               conn->flags |= _UDP_FLAG_PKTINFO;
|                   ^~
  inet/ipv6_setsockopt.c:132:30: error: '_UDP_FLAG_PKTINFO' undeclared (first use in this function)
    132 |               conn->flags |= _UDP_FLAG_PKTINFO;
        |                              ^~~~~~~~~~~~~~~~~
  inet/ipv6_setsockopt.c:132:30: note: each undeclared identifier is reported only once for each function it appears in
  inet/ipv6_setsockopt.c:136:19: error: invalid use of undefined type 'struct udp_conn_s'
    136 |               conn->flags &= ~_UDP_FLAG_PKTINFO;

Signed-off-by: 梁超众 <liangchaozhong@xiaomi.com>
2023-01-29 13:43:44 +08:00
zhanghongyu 1857a4a3c8 udp: Ipv4/6 can be bound to the same port
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-01-28 23:28:33 +02:00